Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous relay operation mode (#148) #218

Merged
merged 2 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bool ICACHE_FLASH_ATTR loadConfiguration()
int ntpinter = ntp["interval"];
timeZone = ntp["timezone"];
activateTime = hardware["rtime"];
lockType = hardware["ltype"];
relayType = hardware["rtype"];
#ifndef OFFICIALBOARD
relayPin = hardware["rpin"];
Expand Down
67 changes: 49 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ char *muser = NULL;
char *mpas = NULL;
int mport;

int lockType;
int relayType;
unsigned long activateTime;
int timeZone;
Expand Down Expand Up @@ -244,31 +245,61 @@ void ICACHE_RAM_ATTR loop()
rfidloop();
}

if (activateRelay)
// Continuous relay mode
if (lockType == 1)
{
if (activateRelay)
{
// currently OFF, need to switch ON
if (digitalRead(relayPin) == !relayType)
{
#ifdef DEBUG
Serial.print("mili : ");
Serial.println(millis());
Serial.println("activating relay now");
Serial.print("mili : ");
Serial.println(millis());
Serial.println("activating relay now");
#endif
digitalWrite(relayPin, relayType);
previousMillis = millis();
activateRelay = false;
deactivateRelay = true;
digitalWrite(relayPin, relayType);
}
else // currently ON, need to switch OFF
{
#ifdef DEBUG
Serial.print("mili : ");
Serial.println(millis());
Serial.println("deactivating relay now");
#endif
digitalWrite(relayPin, !relayType);
}
activateRelay = false;
}
}
else if ((currentMillis - previousMillis >= activateTime) && (deactivateRelay))
else if (lockType == 0) // momentary relay mode
{
if (activateRelay)
{
#ifdef DEBUG
Serial.print("mili : ");
Serial.println(millis());
Serial.println("activating relay now");
#endif
digitalWrite(relayPin, relayType);
previousMillis = millis();
activateRelay = false;
deactivateRelay = true;
}
else if ((currentMillis - previousMillis >= activateTime) && (deactivateRelay))
{
#ifdef DEBUG
Serial.println(currentMillis);
Serial.println(previousMillis);
Serial.println(activateTime);
Serial.println(activateRelay);
Serial.println("deactivate relay after this");
Serial.print("mili : ");
Serial.println(millis());
Serial.println(currentMillis);
Serial.println(previousMillis);
Serial.println(activateTime);
Serial.println(activateRelay);
Serial.println("deactivate relay after this");
Serial.print("mili : ");
Serial.println(millis());
#endif
digitalWrite(relayPin, !relayType);
deactivateRelay = false;
digitalWrite(relayPin, !relayType);
deactivateRelay = false;
}
}

if (formatreq)
Expand Down
16 changes: 8 additions & 8 deletions src/webh/esprfid.htm.gz.h

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/webh/esprfid.js.gz.h

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/webh/index.html.gz.h

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions src/webh/required.css.gz.h

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions src/webh/required.js.gz.h

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions src/websrc/esprfid.htm
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,25 @@ <h6 class="text-muted">Please refer the <a href="https://github.com/esprfid/esp-
</select>
</span>
<span class="col-xs-3">
<button id="testb" type="button" class="btn btn-primary btn-xs" onclick="testRelay()">Test</button><i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="left" data-content="Test previous relay setting. Keep in mind that this is actually triggers the relay."></i>
</span>
<button id="testb" type="button" class="btn btn-primary btn-xs" onclick="testRelay()">Test</button><i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="left" data-content="Test previous relay setting. Keep in mind that this is actually triggers the relay."></i>
</span>
</div>
<div class="row form-group">
<label class="col-xs-3">Lock Type<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Use momentary method for door lock counterparts, and the continuous one for electromagnetic locks."></i></label>
<span class="col-xs-9 col-md-5">
<select class="form-control input-sm" id="lockType" onchange="handleLock();">
<option selected="selected" value="0">Momentary</option>
<option value="1">Continuous</option>
</select>
</span>
</div>
<div class="row form-group" id="activateTimeForm">
<label class="col-xs-3">Activate Time<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Relay Toggle time in Microseconds, usually 300ms is enough for the most electric door locks"></i></label>
<span class="col-xs-9 col-md-5">
<input class="form-control input-sm" value="300" placeholder="in Microsecond" id="delay" type="text" name="hightime">
</span>
<input class="form-control input-sm" value="300" placeholder="in Microsecond" id="delay" type="text" name="hightime">
</span>
</div>
<div class="row form-group">
<br>
<br>
<div class="col-xs-9 col-md-8">
Expand Down
25 changes: 19 additions & 6 deletions src/websrc/js/esprfid.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var config = {
"rfidgain": 32,
"wifipin": 255,
"rtype": 1,
"ltype": 0,
"rpin": 4,
"rtime": 400
},
Expand Down Expand Up @@ -113,7 +114,17 @@ function handleReader() {
}
}

function handleLock() {
var lType = parseInt(document.getElementById("lockType").value);
if (lType === 0) {
document.getElementById("activateTimeForm").style.display = "block";
} else if (lType === 1) {
document.getElementById("activateTimeForm").style.display = "none";
}
}

function listhardware() {
document.getElementById("lockType").value = config.hardware.ltype;
document.getElementById("typerly").value = config.hardware.rtype;
document.getElementById("delay").value = config.hardware.rtime;
document.getElementById("wifipin").value = config.hardware.wifipin;
Expand All @@ -128,14 +139,15 @@ function listhardware() {
document.getElementById("readerType").disabled = true;
}
else {
document.getElementById("readerType").value = config.hardware.readerType;
document.getElementById("wg0pin").value = config.hardware.wgd0pin;
document.getElementById("wg1pin").value = config.hardware.wgd1pin;
document.getElementById("gpioss").value = config.hardware.sspin;
document.getElementById("gain").value = config.hardware.rfidgain;
document.getElementById("gpiorly").value = config.hardware.rpin;
document.getElementById("readerType").value = config.hardware.readerType;
document.getElementById("wg0pin").value = config.hardware.wgd0pin;
document.getElementById("wg1pin").value = config.hardware.wgd1pin;
document.getElementById("gpioss").value = config.hardware.sspin;
document.getElementById("gain").value = config.hardware.rfidgain;
document.getElementById("gpiorly").value = config.hardware.rpin;
}
handleReader();
handleLock();
}


Expand Down Expand Up @@ -177,6 +189,7 @@ function savehardware() {
config.hardware.sspin = parseInt(document.getElementById("gpioss").value);
config.hardware.rfidgain = parseInt(document.getElementById("gain").value);
config.hardware.rtype = parseInt(document.getElementById("typerly").value);
config.hardware.ltype = parseInt(document.getElementById("lockType").value);
config.hardware.rpin = parseInt(document.getElementById("gpiorly").value);
config.hardware.rtime = parseInt(document.getElementById("delay").value);
config.hardware.wifipin = parseInt(document.getElementById("wifipin").value);
Expand Down