add lock control via GPIO
This commit is contained in:
@@ -42,6 +42,7 @@ file(GLOB SRCFILES
|
|||||||
PresenceDetection.cpp
|
PresenceDetection.cpp
|
||||||
PreferencesKeys.h
|
PreferencesKeys.h
|
||||||
SpiffsCookie.cpp
|
SpiffsCookie.cpp
|
||||||
|
Gpio.cpp
|
||||||
Version.h
|
Version.h
|
||||||
include/RTOS.h
|
include/RTOS.h
|
||||||
lib/ESP32_BLE_Arduino-1.0.1/src/*.cpp
|
lib/ESP32_BLE_Arduino-1.0.1/src/*.cpp
|
||||||
|
|||||||
46
Gpio.cpp
Normal file
46
Gpio.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include <esp32-hal.h>
|
||||||
|
#include "Gpio.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Pins.h"
|
||||||
|
|
||||||
|
Gpio* Gpio::_inst = nullptr;
|
||||||
|
NukiWrapper* Gpio::_nuki = nullptr;
|
||||||
|
unsigned long Gpio::_lockedTs = 0;
|
||||||
|
const uint Gpio::_debounceTime = 1000;
|
||||||
|
|
||||||
|
void Gpio::init(NukiWrapper* nuki)
|
||||||
|
{
|
||||||
|
_nuki = nuki;
|
||||||
|
|
||||||
|
pinMode(TRIGGER_LOCK_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(TRIGGER_UNLOCK_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(TRIGGER_UNLATCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
attachInterrupt(TRIGGER_LOCK_PIN, isrLock, FALLING);
|
||||||
|
attachInterrupt(TRIGGER_UNLOCK_PIN, isrUnlock, FALLING);
|
||||||
|
attachInterrupt(TRIGGER_UNLATCH_PIN, isrUnlatch, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gpio::isrLock()
|
||||||
|
{
|
||||||
|
if(millis() < _lockedTs) return;
|
||||||
|
_nuki->lock();
|
||||||
|
_lockedTs = millis() + _debounceTime;
|
||||||
|
Serial.println(F("Lock via GPIO"));;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gpio::isrUnlock()
|
||||||
|
{
|
||||||
|
if(millis() < _lockedTs) return;
|
||||||
|
_nuki->unlock();
|
||||||
|
_lockedTs = millis() + _debounceTime;
|
||||||
|
Serial.println(F("Unlock via GPIO"));;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gpio::isrUnlatch()
|
||||||
|
{
|
||||||
|
if(millis() < _lockedTs) return;
|
||||||
|
_nuki->unlatch();
|
||||||
|
_lockedTs = millis() + _debounceTime;
|
||||||
|
Serial.println(F("Unlatch via GPIO"));;
|
||||||
|
}
|
||||||
22
Gpio.h
Normal file
22
Gpio.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "NukiWrapper.h"
|
||||||
|
|
||||||
|
class Gpio
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Gpio() = delete;
|
||||||
|
static void init(NukiWrapper* nuki);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const uint _debounceTime;
|
||||||
|
|
||||||
|
static void IRAM_ATTR isrLock();
|
||||||
|
static void IRAM_ATTR isrUnlock();
|
||||||
|
static void IRAM_ATTR isrUnlatch();
|
||||||
|
|
||||||
|
static Gpio* _inst;
|
||||||
|
static NukiWrapper* _nuki;
|
||||||
|
static unsigned long _lockedTs;
|
||||||
|
};
|
||||||
@@ -134,6 +134,21 @@ void NukiWrapper::update()
|
|||||||
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(NukiLock::KeyTurnerState));
|
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(NukiLock::KeyTurnerState));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NukiWrapper::lock()
|
||||||
|
{
|
||||||
|
_nextLockAction = NukiLock::LockAction::Lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NukiWrapper::unlock()
|
||||||
|
{
|
||||||
|
_nextLockAction = NukiLock::LockAction::Unlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NukiWrapper::unlatch()
|
||||||
|
{
|
||||||
|
_nextLockAction = NukiLock::LockAction::Unlatch;
|
||||||
|
}
|
||||||
|
|
||||||
void NukiWrapper::setPin(const uint16_t pin)
|
void NukiWrapper::setPin(const uint16_t pin)
|
||||||
{
|
{
|
||||||
_nukiLock.saveSecurityPincode(pin);
|
_nukiLock.saveSecurityPincode(pin);
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void setPin(const uint16_t pin);
|
void lock();
|
||||||
|
void unlock();
|
||||||
|
void unlatch();
|
||||||
|
|
||||||
|
void setPin(const uint16_t pin);
|
||||||
void unpair();
|
void unpair();
|
||||||
|
|
||||||
void disableHASS();
|
void disableHASS();
|
||||||
|
|||||||
3
Pins.h
3
Pins.h
@@ -3,3 +3,6 @@
|
|||||||
#define NETWORK_SELECT 26
|
#define NETWORK_SELECT 26
|
||||||
#define ETHERNET_CS_PIN 5
|
#define ETHERNET_CS_PIN 5
|
||||||
#define ETHERNET_RESET_PIN 33
|
#define ETHERNET_RESET_PIN 33
|
||||||
|
#define TRIGGER_LOCK_PIN 32
|
||||||
|
#define TRIGGER_UNLOCK_PIN 33
|
||||||
|
#define TRIGGER_UNLATCH_PIN 27
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define preference_cred_user "crdusr"
|
#define preference_cred_user "crdusr"
|
||||||
#define preference_cred_password "crdpass"
|
#define preference_cred_password "crdpass"
|
||||||
#define preference_publish_authdata "pubauth"
|
#define preference_publish_authdata "pubauth"
|
||||||
|
#define preference_gpio_locking_enabled "gpiolck"
|
||||||
#define preference_presence_detection_timeout "prdtimeout"
|
#define preference_presence_detection_timeout "prdtimeout"
|
||||||
#define preference_has_mac_saved "hasmac"
|
#define preference_has_mac_saved "hasmac"
|
||||||
#define preference_has_mac_byte_0 "macb0"
|
#define preference_has_mac_byte_0 "macb0"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define nuki_hub_version "4.6"
|
#define nuki_hub_version "4.7"
|
||||||
@@ -274,6 +274,11 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putBool(preference_publish_authdata, (value == "1"));
|
_preferences->putBool(preference_publish_authdata, (value == "1"));
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "GPLCK")
|
||||||
|
{
|
||||||
|
_preferences->putBool(preference_gpio_locking_enabled, (value == "1"));
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "LOCKENA")
|
else if(key == "LOCKENA")
|
||||||
{
|
{
|
||||||
_preferences->putBool(preference_lock_enabled, (value == "1"));
|
_preferences->putBool(preference_lock_enabled, (value == "1"));
|
||||||
@@ -544,6 +549,7 @@ void WebCfgServer::buildNukiConfigHtml(String &response)
|
|||||||
printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10);
|
printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10);
|
||||||
printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10);
|
printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10);
|
||||||
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
||||||
|
printCheckBox(response, "GPLCK", "Enable control via GPIO", _preferences->getBool(preference_gpio_locking_enabled));
|
||||||
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
||||||
response.concat("</table>");
|
response.concat("</table>");
|
||||||
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
||||||
|
|||||||
8
main.cpp
8
main.cpp
@@ -9,6 +9,7 @@
|
|||||||
#include "hardware/W5500EthServer.h"
|
#include "hardware/W5500EthServer.h"
|
||||||
#include "hardware/WifiEthServer.h"
|
#include "hardware/WifiEthServer.h"
|
||||||
#include "NukiOpenerWrapper.h"
|
#include "NukiOpenerWrapper.h"
|
||||||
|
#include "Gpio.h"
|
||||||
|
|
||||||
NetworkLock* network = nullptr;
|
NetworkLock* network = nullptr;
|
||||||
NetworkOpener* networkOpener = nullptr;
|
NetworkOpener* networkOpener = nullptr;
|
||||||
@@ -31,8 +32,6 @@ void networkTask(void *pvParameters)
|
|||||||
networkOpener->update();
|
networkOpener->update();
|
||||||
webCfgServer->update();
|
webCfgServer->update();
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|
||||||
// Serial.print(F("#### ")); Serial.println(uxTaskGetStackHighWaterMark(NULL));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +169,11 @@ void setup()
|
|||||||
{
|
{
|
||||||
nuki = new NukiWrapper("NukiHub", deviceId, bleScanner, network, preferences);
|
nuki = new NukiWrapper("NukiHub", deviceId, bleScanner, network, preferences);
|
||||||
nuki->initialize();
|
nuki->initialize();
|
||||||
|
|
||||||
|
if(preferences->getBool(preference_gpio_locking_enabled))
|
||||||
|
{
|
||||||
|
Gpio::init(nuki);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openerEnabled = preferences->getBool(preference_opener_enabled);
|
openerEnabled = preferences->getBool(preference_opener_enabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user