Skip to content

Commit

Permalink
LPCD: wakeup check for ISO-14443 cards also with IRQ connected to por…
Browse files Browse the repository at this point in the history
…t-expander

Bugfix for showing wrong loglevel
  • Loading branch information
tueddy committed Nov 4, 2023
1 parent 2070f00 commit 997cd2d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## DEV-branch

* 04.11.2023: LPCD: wakeup check for ISO-14443 cards also with IRQ connected to port-expander
* 04.11.2023: Bugfix for showing wrong loglevel
* 03.11.2023: Web-ui: Fix overlapping info/log after pressing refresh button
* 01.11.2023: Fix folder upload with special chars & playtime formatting
* 31.10.2023: Code Formatting via clang-format #264, thank's to @laszloh & @fschrempf !!
Expand Down
4 changes: 2 additions & 2 deletions src/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ String getLoglevel(const uint8_t logLevel) {
void Log_Println(const char *_logBuffer, const uint8_t _minLogLevel) {
if (SERIAL_LOGLEVEL >= _minLogLevel) {
uint32_t ctime = millis();
static String sLogLevel = getLoglevel(_minLogLevel);
const String sLogLevel = getLoglevel(_minLogLevel);
Serial.printf("%s [%u] ", sLogLevel.c_str(), ctime);
Serial.println(_logBuffer);
Log_RingBuffer->printf("%s [%u] ", sLogLevel.c_str(), ctime);
Expand All @@ -49,7 +49,7 @@ void Log_Print(const char *_logBuffer, const uint8_t _minLogLevel, bool printTim
if (SERIAL_LOGLEVEL >= _minLogLevel) {
if (printTimestamp) {
uint32_t ctime = millis();
static String sLogLevel = getLoglevel(_minLogLevel);
const String sLogLevel = getLoglevel(_minLogLevel);
Serial.printf("%s [%u] ", sLogLevel.c_str(), ctime);
Serial.print(_logBuffer);
Log_RingBuffer->printf("%s [%u] ", sLogLevel.c_str(), ctime);
Expand Down
25 changes: 25 additions & 0 deletions src/RfidPn5180.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Rfid.h"
#include "System.h"

#include <Wire.h>
#include <driver/gpio.h>
#include <esp_task_wdt.h>
#include <freertos/task.h>
Expand All @@ -35,6 +36,10 @@

extern unsigned long Rfid_LastRfidCheckTimestamp;

#if (defined(PORT_EXPANDER_ENABLE) && (RFID_IRQ > 99))
extern TwoWire i2cBusTwo;
#endif

#ifdef RFID_READER_TYPE_PN5180
static void Rfid_Task(void *parameter);
TaskHandle_t rfidTaskHandle;
Expand All @@ -60,6 +65,22 @@ void Rfid_Init(void) {
if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) {
Rfid_WakeupCheck();
}

// wakeup-check if IRQ is connected to port-expander, signal arrives as pushbutton
#if (defined(PORT_EXPANDER_ENABLE) && (RFID_IRQ > 99))
if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT0) {
// read IRQ state from port-expander
i2cBusTwo.begin(ext_IIC_DATA, ext_IIC_CLK);
delay(50);
Port_Init();
uint8_t irqState = Port_Read(RFID_IRQ);
if (irqState == LOW) {
Log_Println("Wakeup caused by low power card-detection on port-expander", LOGLEVEL_NOTICE);
Rfid_WakeupCheck();
}
}
#endif

// disable pin hold from deep sleep
gpio_deep_sleep_hold_dis();
gpio_hold_dis(gpio_num_t(RFID_CS)); // NSS
Expand Down Expand Up @@ -379,6 +400,10 @@ void Rfid_WakeupCheck(void) {
#if (RFID_IRQ >= 0 && RFID_IRQ <= MAX_GPIO)
// configure wakeup pin for deep-sleep wake-up, use ext1. For a real GPIO only, not PE
esp_sleep_enable_ext1_wakeup((1ULL << (RFID_IRQ)), ESP_EXT1_WAKEUP_ALL_LOW);
#endif
#if (defined(PORT_EXPANDER_ENABLE) && (RFID_IRQ > 99))
// reset IRQ state on port-expander
Port_Exit();
#endif
// freeze pin states in deep sleep
gpio_hold_en(gpio_num_t(RFID_CS)); // CS/NSS
Expand Down
6 changes: 3 additions & 3 deletions src/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void handleGetSettings(AsyncWebServerRequest *request);
static void handlePostSettings(AsyncWebServerRequest *request, JsonVariant &json);

static void onWebsocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
static void settingsToJSON(JsonObject obj, String section);
static void settingsToJSON(JsonObject obj, const String section);
static bool JSONToSettings(JsonObject obj);
static void webserverStart(void);

Expand Down Expand Up @@ -693,7 +693,7 @@ bool JSONToSettings(JsonObject doc) {
}

// process settings to JSON object
static void settingsToJSON(JsonObject obj, String section) {
static void settingsToJSON(JsonObject obj, const String section) {
if ((section == "") || (section == "current")) {
// current values
JsonObject curObj = obj.createNestedObject("current");
Expand Down Expand Up @@ -1590,7 +1590,7 @@ void handlePostWiFiConfig(AsyncWebServerRequest *request, JsonVariant &json) {
}
}

static bool tagIdToJSON(String tagId, JsonObject entry) {
static bool tagIdToJSON(const String tagId, JsonObject entry) {
String s = gPrefsRfid.getString(tagId.c_str(), "-1"); // Try to lookup rfidId in NVS
if (!s.compareTo("-1")) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/revision.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#include "gitrevision.h"
constexpr const char softwareRevision[] = "Software-revision: 20231103-1";
constexpr const char softwareRevision[] = "Software-revision: 20231104-1";

0 comments on commit 997cd2d

Please sign in to comment.