diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index 00d8bc0..a785561 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -86,6 +86,7 @@ #define DEFAULT_CUSTOM_ENDPOINT "ws-staging.btclock.dev" #define DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL false #define DEFAULT_MOW_MODE false +#define DEFAULT_SCREEN_RESTORE_AFTER_ZAP true // Define data source types enum DataSourceType { diff --git a/src/lib/nostr_notify.cpp b/src/lib/nostr_notify.cpp index dda24e1..5bab443 100644 --- a/src/lib/nostr_notify.cpp +++ b/src/lib/nostr_notify.cpp @@ -10,6 +10,14 @@ boolean nostrIsSubscribing = true; String subIdZap; +void screenRestoreAfterZapCallback(TimerHandle_t xTimer) +{ + Serial.println("Restoring screen after zap"); + int screenBeforeZap = (int)(uintptr_t)pvTimerGetTimerID(xTimer); + ScreenHandler::setCurrentScreen(screenBeforeZap); + xTimerDelete(xTimer, 0); +} + void setupNostrNotify(bool asDatasource, bool zapNotify) { nostr::esp32::ESP32Platform::initNostr(false); @@ -288,12 +296,13 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event) } uint64_t timerPeriod = 0; + int screenBeforeZap = ScreenHandler::getCurrentScreen(); if (isTimerActive()) { // store timer periode before making inactive to prevent artifacts timerPeriod = getTimerSeconds(); esp_timer_stop(screenRotateTimer); - } + } ScreenHandler::setCurrentScreen(SCREEN_CUSTOM); EPDManager::getInstance().setContent(textEpdContent); @@ -306,6 +315,10 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event) { esp_timer_start_periodic(screenRotateTimer, timerPeriod * usPerSecond); + } else if (preferences.getBool("scrnRestoreZap", DEFAULT_SCREEN_RESTORE_AFTER_ZAP)) { + TimerHandle_t screenRestoreAfterZapTimer = xTimerCreate("screenRestoreAfterZap", pdMS_TO_TICKS(getTimerSeconds() * msPerSecond), pdFALSE, (void*)(uintptr_t)screenBeforeZap, screenRestoreAfterZapCallback); + Serial.println("Starting screen restore after zap"); + xTimerStart(screenRestoreAfterZapTimer, 0); } } diff --git a/src/lib/shared.hpp b/src/lib/shared.hpp index 54d48aa..97af754 100644 --- a/src/lib/shared.hpp +++ b/src/lib/shared.hpp @@ -66,6 +66,7 @@ const PROGMEM int screens[SCREEN_COUNT] = { SCREEN_BLOCK_FEE_RATE}; const int usPerSecond = 1000000; const int usPerMinute = 60 * usPerSecond; +const int msPerSecond = 1000; // extern const char *github_root_ca; // extern const char *isrg_root_x1cert; diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 6ee62f9..2d447d6 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -18,7 +18,7 @@ static const char *const PROGMEM boolSettings[] = {"ledTestOnPower", "ledFlashOn "mempoolSecure", "bitaxeEnabled", "miningPoolStats", "verticalDesc", "nostrZapNotify", "httpAuthEnabled", - "enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled"}; + "enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled", "scrnRestoreZap"}; AsyncWebServer server(80); AsyncEventSource events("/events"); @@ -717,6 +717,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["nostrZapNotify"] = preferences.getBool("nostrZapNotify", DEFAULT_ZAP_NOTIFY_ENABLED); root["nostrZapPubkey"] = preferences.getString("nostrZapPubkey", DEFAULT_ZAP_NOTIFY_PUBKEY); root["ledFlashOnZap"] = preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP); + root["scrnRestoreZap"] = preferences.getBool("scrnRestoreZap", DEFAULT_SCREEN_RESTORE_AFTER_ZAP); root["fontName"] = preferences.getString("fontName", DEFAULT_FONT_NAME); root["availableFonts"] = FontNames::getAvailableFonts(); // Custom endpoint settings (only used for CUSTOM_SOURCE)