Skip to content

Commit

Permalink
Merge pull request esprfid#225 from donatmarko/dev-button
Browse files Browse the repository at this point in the history
Implementing open/close button
  • Loading branch information
omersiar authored Jan 18, 2019
2 parents cefee02 + 4af91f4 commit 7d46bf3
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 111 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib_deps =
https://github.com/miguelbalboa/rfid#ea7ee3f3daafd46d0c5b8438ba41147c384a1f0d
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
Time
Bounce2

; boards which GPIO0 and RESET controlled using two NPN transistors as nodemcu devkit (includes wemos d1 mini)
[env:generic]
Expand Down
11 changes: 11 additions & 0 deletions src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ bool ICACHE_FLASH_ATTR loadConfiguration()
digitalWrite(wifipin, LEDoff);
}
}

if (hardware.containsKey("buttonpin"))
{
buttonPin = hardware["buttonpin"];
if (buttonPin != 255)
{
button = Bounce();
button.attach(buttonPin, INPUT_PULLUP);
button.interval(30);
}
}
#ifdef OFFICIALBOARD
setupWiegandReader(5, 4);
#endif
Expand Down
15 changes: 14 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE.
#include <Ticker.h>
#include "Ntp.h"
#include <AsyncMqttClient.h>
#include <Bounce2.h>

//#define DEBUG

Expand Down Expand Up @@ -85,6 +86,7 @@ NtpClient NTP;
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiDisconnectHandler, wifiConnectHandler;
Bounce button;

AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
Expand All @@ -94,6 +96,7 @@ bool wifiFlag = false;
bool configMode = false;
int wmode;
uint8_t wifipin = 255;
uint8_t buttonPin = 255;
#define LEDoff HIGH
#define LEDon LOW

Expand Down Expand Up @@ -223,6 +226,16 @@ void ICACHE_RAM_ATTR loop()
uptime = NTP.getUptimeSec();
previousLoopMillis = currentMillis;

button.update();
if (button.fell())
{
#ifdef DEBUG
Serial.println("Button has been pressed");
#endif
writeLatest("", "(used open/close button)", 1);
activateRelay = true;
}

if (wifipin != 255 && configMode && !wmode)
{
if (!wifiFlag)
Expand Down Expand Up @@ -268,7 +281,7 @@ void ICACHE_RAM_ATTR loop()
#endif
digitalWrite(relayPin, !relayType);
}
activateRelay = false;
activateRelay = false;
}
}
else if (lockType == 0) // momentary relay mode
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.

14 changes: 14 additions & 0 deletions src/websrc/esprfid.htm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ <h6 class="text-muted">Please refer the <a href="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/esprfid/esp-
<input class="form-control input-sm" value="300" placeholder="in Microsecond" id="delay" type="text" name="hightime">
</span>
</div>
<br>
<div class="row form-group">
<label class="col-xs-3">Button Pin<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Choose a pin to have a button with equivalent behaviour to scan a valid card (open/close button)."></i></label>
<span class="col-xs-9 col-md-5">
<select class="form-control input-sm" id="buttonPin">
<option selected="selected" value="255">None</option>
<option value="4">GPIO-4</option>
<option value="5">GPIO-5</option>
<option value="12">GPIO-12</option>
<option value="13">GPIO-13</option>
<option value="14">GPIO-14</option>
</select>
</span>
</div>
<div class="row form-group">
<br>
<br>
Expand Down
5 changes: 4 additions & 1 deletion src/websrc/js/esprfid.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var config = {
"rtype": 1,
"ltype": 0,
"rpin": 4,
"rtime": 400
"rtime": 400,
"buttonpin": 255
},
"general": {
"hostnm": "esp-rfid",
Expand Down Expand Up @@ -128,6 +129,7 @@ function listhardware() {
document.getElementById("typerly").value = config.hardware.rtype;
document.getElementById("delay").value = config.hardware.rtime;
document.getElementById("wifipin").value = config.hardware.wifipin;
document.getElementById("buttonPin").value = config.hardware.buttonpin;
if (isOfficialBoard) {
document.getElementById("readerType").value = 1;
document.getElementById("wg0pin").value = 5;
Expand Down Expand Up @@ -193,6 +195,7 @@ function savehardware() {
config.hardware.rpin = parseInt(document.getElementById("gpiorly").value);
config.hardware.rtime = parseInt(document.getElementById("delay").value);
config.hardware.wifipin = parseInt(document.getElementById("wifipin").value);
config.hardware.buttonpin = parseInt(document.getElementById("buttonPin").value);
uncommited();
}

Expand Down

0 comments on commit 7d46bf3

Please sign in to comment.