This commit is contained in:
2025-12-12 08:35:20 +01:00
committed by example
parent 356d7de2cf
commit 0ce45a133b
23 changed files with 616 additions and 135 deletions

View File

@@ -1,27 +1,60 @@
#include <SmingCore.h>
#include "FingerPrint.h"
#include "utils.h"
#include "main.h"
HardwareSerial Serial1(UART_ID_1);
NtpClient ntpClient("at.pool.ntp.org", 3600);
void IRAM_ATTR OnFingerInterrupt()
static SimpleTimer procTimer;
volatile uint8_t procTimerLoops = 0;
void OnProcTimer()
{
// LOW = FINGER, HIGH = NO FINGER
bool status = digitalRead(FINGER_DETECT_PIN);
const bool finger = !digitalRead(FINGER_DETECT_PIN);
const bool unlocked = !digitalRead(SAFELOCK_DETECT_PIN);
const bool opened = digitalRead(DOOR_DETECT_PIN);
static Debounce Finger(finger);
static Debounce Unlocked(unlocked);
static Debounce Opened(opened);
g_Main.OnFingerInterrupt(!status);
int8_t fingerEdge = Finger.debounce(finger);
if(fingerEdge)
g_Main.OnFinger(fingerEdge & 1);
int8_t unlockedEdge = Unlocked.debounce(unlocked);
if(unlockedEdge)
g_Main.OnLock(unlockedEdge & 1);
int8_t openedEdge = Finger.debounce(opened);
if(openedEdge)
g_Main.OnDoor(openedEdge & 1);
procTimerLoops++;
if(procTimerLoops > 25) // 250ms
procTimer.stop();
}
void IRAM_ATTR OnLevelChangeISR()
{
procTimerLoops = 0;
procTimer.start();
}
void ready()
{
debugf("READY!");
gpio_pin_wakeup_enable(GPIO_ID_PIN(FINGER_DETECT_PIN), GPIO_PIN_INTR_LOLEVEL);
g_Main.Init(Serial);
attachInterrupt(FINGER_DETECT_PIN, OnFingerInterrupt, CHANGE);
gpio_pin_wakeup_enable(GPIO_ID_PIN(FINGER_DETECT_PIN), GPIO_PIN_INTR_LOLEVEL);
gpio_pin_wakeup_enable(GPIO_ID_PIN(SAFELOCK_DETECT_PIN), GPIO_PIN_INTR_LOLEVEL);
gpio_pin_wakeup_enable(GPIO_ID_PIN(DOOR_DETECT_PIN), GPIO_PIN_INTR_HILEVEL);
attachInterrupt(FINGER_DETECT_PIN, OnLevelChangeISR, CHANGE);
attachInterrupt(SAFELOCK_DETECT_PIN, OnLevelChangeISR, CHANGE);
attachInterrupt(DOOR_DETECT_PIN, OnLevelChangeISR, CHANGE);
procTimer.initializeMs<10>(OnProcTimer);
}
void init()
@@ -45,7 +78,7 @@ void init()
pinMode(FINGER_DETECT_PIN, INPUT);
pinMode(SAFELOCK_DETECT_PIN, INPUT);
pinMode(DOOR_DETECT_PIN, INPUT);
pinMode(DOOR_DETECT_PIN, INPUT_PULLUP);
// mount spiffs
spiffs_mount();