From 8e71f29d10e19bc2f26b2acd3cafae3fca56b445 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Thu, 11 Jul 2024 14:08:37 +0200 Subject: [PATCH] Use constants for setting default values, bring back wifi config portal timeout setting --- data | 2 +- src/lib/block_notify.cpp | 12 ++++----- src/lib/config.cpp | 37 +++++++++++++-------------- src/lib/config.hpp | 7 +----- src/lib/defaults.hpp | 43 ++++++++++++++++++++++++++++++++ src/lib/led_handler.cpp | 22 ++++++++-------- src/lib/ota.cpp | 2 +- src/lib/price_notify.cpp | 6 ++--- src/lib/screen_handler.cpp | 16 ++++++------ src/lib/shared.hpp | 2 ++ src/lib/webserver.cpp | 51 +++++++++++++++++++------------------- src/main.cpp | 8 +++--- 12 files changed, 122 insertions(+), 86 deletions(-) create mode 100644 src/lib/defaults.hpp diff --git a/data b/data index 124c810..2363d98 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 124c810e291a0c642da619f3c00109240c7a061a +Subproject commit 2363d98965bb1fdbfdf5d130b41732f5b864e2d0 diff --git a/src/lib/block_notify.cpp b/src/lib/block_notify.cpp index 2ef4268..c775b7d 100644 --- a/src/lib/block_notify.cpp +++ b/src/lib/block_notify.cpp @@ -89,7 +89,7 @@ void setupBlockNotify() xQueueSend(workQueue, &blockUpdate, portMAX_DELAY); } - if (!preferences.getBool("fetchEurPrice", false) && preferences.getBool("ownDataSource", true)) + if (!preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) { return; } @@ -97,7 +97,7 @@ void setupBlockNotify() // std::strcpy(wsServer, String("wss://" + mempoolInstance + // "/api/v1/ws").c_str()); - const String protocol = preferences.getBool("mempoolSecure", true) ? "wss" : "ws"; + const String protocol = preferences.getBool("mempoolSecure", DEFAULT_MEMPOOL_SECURE) ? "wss" : "ws"; String mempoolUri = protocol + "://" + preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE) + "/api/v1/ws"; @@ -185,7 +185,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) // xTaskNotifyGive(blockUpdateTaskHandle); if (getCurrentScreen() != SCREEN_BLOCK_HEIGHT && - preferences.getBool("stealFocus", false)) + preferences.getBool("stealFocus", DEFAULT_STEAL_FOCUS)) { uint64_t timerPeriod = 0; if (isTimerActive()) @@ -203,7 +203,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) vTaskDelay(pdMS_TO_TICKS(315*NUM_SCREENS)); // Extra delay because of screen switching } - if (preferences.getBool("ledFlashOnUpd", false)) + if (preferences.getBool("ledFlashOnUpd", DEFAULT_LED_FLASH_ON_UPD)) { vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated queueLedEffect(LED_FLASH_BLOCK_NOTIFY); @@ -300,9 +300,9 @@ int getBlockFetch() // Get current block height through regular API HTTPClient http; - const String protocol = preferences.getBool("mempoolSecure", true) ? "https" : "http"; + const String protocol = preferences.getBool("mempoolSecure", DEFAULT_MEMPOOL_SECURE) ? "https" : "http"; - if (preferences.getBool("mempoolSecure", true)) + if (preferences.getBool("mempoolSecure", DEFAULT_MEMPOOL_SECURE)) http.begin(client, protocol + "://" + mempoolInstance + "/api/blocks/tip/height"); else http.begin(protocol + "://" + mempoolInstance + "/api/blocks/tip/height"); diff --git a/src/lib/config.cpp b/src/lib/config.cpp index a6fdf86..0b96689 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -24,7 +24,7 @@ void setup() setupHardware(); setupDisplays(); - if (preferences.getBool("ledTestOnPower", true)) + if (preferences.getBool("ledTestOnPower", DEFAULT_LED_TEST_ON_POWER)) { queueLedEffect(LED_POWER_TEST); } @@ -75,7 +75,7 @@ void setup() waitUntilNoneBusy(); #ifdef HAS_FRONTLIGHT - if (!preferences.getBool("flAlwaysOn", false)) + if (!preferences.getBool("flAlwaysOn", DEFAULT_FL_ALWAYS_ON)) { frontlightFadeOutAll(preferences.getUInt("flEffectDelay"), true); flArray.allOFF(); @@ -91,24 +91,21 @@ void tryImprovSetup() WiFi.setAutoConnect(true); WiFi.setAutoReconnect(true); WiFi.begin(); - if (preferences.getInt("txPower", 0)) + if (preferences.getInt("txPower", DEFAULT_TX_POWER)) { if (WiFi.setTxPower( - static_cast(preferences.getInt("txPower", 0)))) + static_cast(preferences.getInt("txPower", DEFAULT_TX_POWER)))) { Serial.printf("WiFi max tx power set to %d\n", - preferences.getInt("txPower", 0)); + preferences.getInt("txPower", DEFAULT_TX_POWER)); } } - // if (!preferences.getBool("wifiConfigured", false)) + // if (!preferences.getBool("wifiConfigured", DEFAULT_WIFI_CONFIGURED) { queueLedEffect(LED_EFFECT_WIFI_WAIT_FOR_CONFIG); - uint8_t x_buffer[16]; - uint8_t x_position = 0; - bool buttonPress = false; { std::lock_guard lockMcp(mcpMutex); @@ -128,7 +125,7 @@ void tryImprovSetup() String(mac[5], 16) + String(mac[1], 16)) .substring(2, 10); - // wm.setConfigPortalTimeout(preferences.getUInt("wpTimeout", 600)); + wm.setConfigPortalTimeout(preferences.getUInt("wpTimeout", DEFAULT_WP_TIMEOUT)); wm.setWiFiAutoReconnect(false); wm.setDebugOutput(false); wm.setConfigPortalBlocking(true); @@ -228,13 +225,13 @@ void tryImprovSetup() void syncTime() { - configTime(preferences.getInt("gmtOffset", TIME_OFFSET_SECONDS), 0, + configTime(preferences.getInt("gmtOffset", DEFAULT_TIME_OFFSET_SECONDS), 0, NTP_SERVER); struct tm timeinfo; while (!getLocalTime(&timeinfo)) { - configTime(preferences.getInt("gmtOffset", TIME_OFFSET_SECONDS), 0, + configTime(preferences.getInt("gmtOffset", DEFAULT_TIME_OFFSET_SECONDS), 0, NTP_SERVER); delay(500); Serial.println(F("Retry set time")); @@ -249,8 +246,8 @@ void setupPreferences() setFgColor(preferences.getUInt("fgColor", DEFAULT_FG_COLOR)); setBgColor(preferences.getUInt("bgColor", DEFAULT_BG_COLOR)); - setBlockHeight(preferences.getUInt("blockHeight", 816000)); - setPrice(preferences.getUInt("lastPrice", 30000)); + setBlockHeight(preferences.getUInt("blockHeight", INITIAL_BLOCK_HEIGHT)); + setPrice(preferences.getUInt("lastPrice", INITIAL_LAST_PRICE)); screenNameMap[SCREEN_BLOCK_HEIGHT] = "Block Height"; screenNameMap[SCREEN_BLOCK_FEE_RATE] = "Block Fee Rate"; @@ -265,7 +262,7 @@ void setupWebsocketClients(void *pvParameters) { setupBlockNotify(); - if (preferences.getBool("fetchEurPrice", false)) + if (preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE)) { setupPriceFetchTask(); } @@ -287,7 +284,7 @@ void setupTimers() void finishSetup() { - if (preferences.getBool("ledStatus", false)) + if (preferences.getBool("ledStatus", DEFAULT_LED_STATUS)) { restoreLedState(); } @@ -711,7 +708,7 @@ String getMyHostname() // WiFi.macAddress(mac); esp_efuse_mac_get_default(mac); char hostname[15]; - String hostnamePrefix = preferences.getString("hostnamePrefix", "btclock"); + String hostnamePrefix = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX); snprintf(hostname, sizeof(hostname), "%s-%02x%02x%02x", hostnamePrefix, mac[3], mac[4], mac[5]); return hostname; @@ -734,16 +731,16 @@ void setupFrontlight() if (!preferences.isKey("flMaxBrightness")) { - preferences.putUInt("flMaxBrightness", 2048); + preferences.putUInt("flMaxBrightness", DEFAULT_FL_MAX_BRIGHTNESS); } if (!preferences.isKey("flEffectDelay")) { - preferences.putUInt("flEffectDelay", 15); + preferences.putUInt("flEffectDelay", DEFAULT_FL_EFFECT_DELAY); } if (!preferences.isKey("flFlashOnUpd")) { - preferences.putBool("flFlashOnUpd", false); + preferences.putBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE); } } diff --git a/src/lib/config.hpp b/src/lib/config.hpp index bcfb0dc..c9c3199 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -26,17 +26,12 @@ #endif #define NTP_SERVER "pool.ntp.org" -#define DEFAULT_MEMPOOL_INSTANCE "mempool.space" -#define TIME_OFFSET_SECONDS 3600 +#define DEFAULT_TIME_OFFSET_SECONDS 3600 #define USER_AGENT "BTClock/3.0" #ifndef MCP_DEV_ADDR #define MCP_DEV_ADDR 0x20 #endif -#define DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE 30 -#define DEFAULT_MINUTES_FULL_REFRESH 60 -#define DEFAULT_FG_COLOR GxEPD_WHITE -#define DEFAULT_BG_COLOR GxEPD_BLACK void setup(); void syncTime(); diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp new file mode 100644 index 0000000..510ab61 --- /dev/null +++ b/src/lib/defaults.hpp @@ -0,0 +1,43 @@ +#define INITIAL_BLOCK_HEIGHT 851500 +#define INITIAL_LAST_PRICE 50000 +#define DEFAULT_TX_POWER 0 + +#define DEFAULT_MEMPOOL_SECURE true +#define DEFAULT_LED_TEST_ON_POWER true +#define DEFAULT_LED_FLASH_ON_UPD false +#define DEFAULT_LED_BRIGHTNESS 128 +#define DEFAULT_STEAL_FOCUS false +#define DEFAULT_MCAP_BIG_CHAR true +#define DEFAULT_MDNS_ENABLED true +#define DEFAULT_OTA_ENABLED true +#define DEFAULT_FETCH_EUR_PRICE false +#define DEFAULT_USE_SATS_SYMBOL false +#define DEFAULT_USE_BLOCK_COUNTDOWN true +#define DEFAULT_SUFFIX_PRICE false +#define DEFAULT_DISABLE_LEDS false +#define DEFAULT_OWN_DATA_SOURCE true + +#define DEFAULT_TIME_OFFSET_SECONDS 3600 + +#define DEFAULT_HOSTNAME_PREFIX "btclock" +#define DEFAULT_MEMPOOL_INSTANCE "mempool.space" + +#define DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE 30 +#define DEFAULT_MINUTES_FULL_REFRESH 60 + +#define DEFAULT_FG_COLOR GxEPD_WHITE +#define DEFAULT_BG_COLOR GxEPD_BLACK + +#define DEFAULT_WP_TIMEOUT 15*60 + +#define DEFAULT_FL_MAX_BRIGHTNESS 2048 +#define DEFAULT_FL_EFFECT_DELAY 15 + +#define DEFAULT_LUX_LIGHT_TOGGLE 128 +#define DEFAULT_FL_ALWAYS_ON false +#define DEFAULT_FL_FLASH_ON_UPDATE false + +#define DEFAULT_LED_STATUS false +#define DEFAULT_TIMER_ACTIVE true +#define DEFAULT_TIMER_SECONDS 1800 +#define DEFAULT_CURRENT_SCREEN 0 diff --git a/src/lib/led_handler.cpp b/src/lib/led_handler.cpp index 43e5182..a1d06fa 100644 --- a/src/lib/led_handler.cpp +++ b/src/lib/led_handler.cpp @@ -209,7 +209,7 @@ void ledTask(void *parameter) pdPASS) { - if (preferences.getBool("disableLeds", false)) + if (preferences.getBool("disableLeds", DEFAULT_DISABLE_LEDS)) { continue; } @@ -221,7 +221,9 @@ void ledTask(void *parameter) { oldLights[i] = pixels.getPixelColor(i); } - + #ifdef HAS_FRONTLIGHT + uint flDelayTime = preferences.getUInt("flEffectDelay"); + #endif switch (ledTaskParams) { case LED_POWER_TEST: @@ -274,32 +276,32 @@ void ledTask(void *parameter) #ifdef HAS_FRONTLIGHT bool frontlightWasOn = false; - if (preferences.getBool("flFlashOnUpd", false)) + if (preferences.getBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE)) { if (frontlightOn) { frontlightWasOn = true; - frontlightFadeOutAll(1); + frontlightFadeOutAll(flDelayTime, true); } else { - frontlightFadeInAll(1); + frontlightFadeInAll(flDelayTime, true); } } #endif blinkDelayTwoColor(250, 3, pixels.Color(224, 67, 0), pixels.Color(8, 2, 0)); #ifdef HAS_FRONTLIGHT - if (preferences.getBool("flFlashOnUpd", false)) + if (preferences.getBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE)) { vTaskDelay(pdMS_TO_TICKS(10)); if (frontlightWasOn) { - frontlightFadeInAll(1); + frontlightFadeInAll(flDelayTime, true); } else { - frontlightFadeOutAll(1); + frontlightFadeOutAll(flDelayTime, true); } } #endif @@ -397,11 +399,11 @@ void ledTask(void *parameter) void setupLeds() { pixels.begin(); - pixels.setBrightness(preferences.getUInt("ledBrightness", 128)); + pixels.setBrightness(preferences.getUInt("ledBrightness", DEFAULT_LED_BRIGHTNESS)); pixels.clear(); pixels.show(); setupLedTask(); - if (preferences.getBool("ledTestOnPower", true)) + if (preferences.getBool("ledTestOnPower", DEFAULT_LED_TEST_ON_POWER)) { while (!ledTaskQueue) { diff --git a/src/lib/ota.cpp b/src/lib/ota.cpp index 373271b..c457a01 100644 --- a/src/lib/ota.cpp +++ b/src/lib/ota.cpp @@ -4,7 +4,7 @@ TaskHandle_t taskOtaHandle = NULL; bool isOtaUpdating = false; void setupOTA() { - if (preferences.getBool("otaEnabled", true)) { + if (preferences.getBool("otaEnabled", DEFAULT_OTA_ENABLED)) { ArduinoOTA.onStart(onOTAStart); ArduinoOTA.onProgress(onOTAProgress); diff --git a/src/lib/price_notify.cpp b/src/lib/price_notify.cpp index 0a07f39..18f36ad 100644 --- a/src/lib/price_notify.cpp +++ b/src/lib/price_notify.cpp @@ -43,9 +43,7 @@ bool priceNotifyInit = false; void setupPriceNotify() { - // currentPrice = preferences.get("lastPrice", 30000); - - if (preferences.getBool("ownDataSource", true)) + if (preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) { config = {.uri = wsOwnServerPrice, .user_agent = USER_AGENT}; @@ -76,7 +74,7 @@ void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base, break; case WEBSOCKET_EVENT_DATA: onWebsocketPriceMessage(data); - if (preferences.getBool("ownDataSource", true)) + if (preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) { onWebsocketBlockMessage(data); } diff --git a/src/lib/screen_handler.cpp b/src/lib/screen_handler.cpp index d0fa761..85ecda5 100644 --- a/src/lib/screen_handler.cpp +++ b/src/lib/screen_handler.cpp @@ -30,17 +30,17 @@ void workerTask(void *pvParameters) { case TASK_PRICE_UPDATE: { uint price = getPrice(); char priceSymbol = '$'; - if (preferences.getBool("fetchEurPrice", false)) { + if (preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE)) { priceSymbol = '['; } if (getCurrentScreen() == SCREEN_BTC_TICKER) { - taskEpdContent = parsePriceData(price, priceSymbol, preferences.getBool("suffixPrice", false)); + taskEpdContent = parsePriceData(price, priceSymbol, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE)); } else if (getCurrentScreen() == SCREEN_MSCW_TIME) { - taskEpdContent = parseSatsPerCurrency(price, priceSymbol, preferences.getBool("useSatsSymbol", false)); + taskEpdContent = parseSatsPerCurrency(price, priceSymbol, preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); } else { taskEpdContent = parseMarketCap(getBlockHeight(), price, priceSymbol, - preferences.getBool("mcapBigChar", true)); + preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR)); } setEpdContent(taskEpdContent); @@ -57,7 +57,7 @@ void workerTask(void *pvParameters) { if (getCurrentScreen() != SCREEN_HALVING_COUNTDOWN) { taskEpdContent = parseBlockHeight(getBlockHeight()); } else { - taskEpdContent = parseHalvingCountdown(getBlockHeight(), preferences.getBool("useBlkCountdown", true)); + taskEpdContent = parseHalvingCountdown(getBlockHeight(), preferences.getBool("useBlkCountdown", DEFAULT_USE_BLOCK_COUNTDOWN)); } if (getCurrentScreen() == SCREEN_HALVING_COUNTDOWN || @@ -147,7 +147,7 @@ void setupTasks() { &taskScreenRotateTaskHandle); waitUntilNoneBusy(); - setCurrentScreen(preferences.getUInt("currentScreen", 0)); + setCurrentScreen(preferences.getUInt("currentScreen", DEFAULT_CURRENT_SCREEN)); } void setupTimeUpdateTimer(void *pvParameters) { @@ -180,7 +180,7 @@ void setupScreenRotateTimer(void *pvParameters) { esp_timer_create(&screenRotateTimerConfig, &screenRotateTimer); - if (preferences.getBool("timerActive", true)) { + if (preferences.getBool("timerActive", DEFAULT_TIMER_ACTIVE)) { esp_timer_start_periodic(screenRotateTimer, getTimerSeconds() * usPerSecond); } @@ -188,7 +188,7 @@ void setupScreenRotateTimer(void *pvParameters) { vTaskDelete(NULL); } -uint getTimerSeconds() { return preferences.getUInt("timerSeconds", 1800); } +uint getTimerSeconds() { return preferences.getUInt("timerSeconds", DEFAULT_TIMER_SECONDS); } bool isTimerActive() { return esp_timer_is_active(screenRotateTimer); } diff --git a/src/lib/shared.hpp b/src/lib/shared.hpp index 65e1009..60cfbd1 100644 --- a/src/lib/shared.hpp +++ b/src/lib/shared.hpp @@ -11,6 +11,8 @@ #include #include +#include "defaults.hpp" + extern Adafruit_MCP23X17 mcp1; #ifdef IS_BTCLOCK_S3 extern Adafruit_MCP23X17 mcp2; diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index e7b923a..432de65 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -69,7 +69,7 @@ void setupWebserver() // server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET, // onApiLightsSetColor); - if (preferences.getBool("otaEnabled", true)) + if (preferences.getBool("otaEnabled", DEFAULT_OTA_ENABLED)) { server.on("/upload/firmware", HTTP_POST, onFirmwareUpdate, asyncFirmwareUpdateHandler); server.on("/upload/webui", HTTP_POST, onFirmwareUpdate, asyncWebuiUpdateHandler); @@ -94,7 +94,7 @@ void setupWebserver() server.begin(); - if (preferences.getBool("mdnsEnabled", true)) + if (preferences.getBool("mdnsEnabled", DEFAULT_MDNS_ENABLED)) { if (!MDNS.begin(getMyHostname())) { @@ -454,7 +454,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) } } - String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness", "flEffectDelay", "luxLightToggle"}; + String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness", "flEffectDelay", "luxLightToggle", "wpTimeout"}; for (String setting : uintSettings) { @@ -572,39 +572,38 @@ void onApiSettingsGet(AsyncWebServerRequest *request) "minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE); root["fullRefreshMin"] = preferences.getUInt("fullRefreshMin", DEFAULT_MINUTES_FULL_REFRESH); - root["wpTimeout"] = preferences.getUInt("wpTimeout", 600); - root["tzOffset"] = preferences.getInt("gmtOffset", TIME_OFFSET_SECONDS) / 60; - // root["useBitcoinNode"] = preferences.getBool("useNode", false); + root["wpTimeout"] = preferences.getUInt("wpTimeout", DEFAULT_WP_TIMEOUT); + root["tzOffset"] = preferences.getInt("gmtOffset", DEFAULT_TIME_OFFSET_SECONDS) / 60; root["mempoolInstance"] = preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE); - root["mempoolSecure"] = preferences.getBool("mempoolSecure", true); - root["ledTestOnPower"] = preferences.getBool("ledTestOnPower", true); - root["ledFlashOnUpd"] = preferences.getBool("ledFlashOnUpd", false); - root["ledBrightness"] = preferences.getUInt("ledBrightness", 128); - root["stealFocus"] = preferences.getBool("stealFocus", false); - root["mcapBigChar"] = preferences.getBool("mcapBigChar", true); - root["mdnsEnabled"] = preferences.getBool("mdnsEnabled", true); - root["otaEnabled"] = preferences.getBool("otaEnabled", true); - root["fetchEurPrice"] = preferences.getBool("fetchEurPrice", false); - root["useSatsSymbol"] = preferences.getBool("useSatsSymbol", false); - root["useBlkCountdown"] = preferences.getBool("useBlkCountdown", true); - root["suffixPrice"] = preferences.getBool("suffixPrice", false); - root["disableLeds"] = preferences.getBool("disableLeds", false); + root["mempoolSecure"] = preferences.getBool("mempoolSecure", DEFAULT_MEMPOOL_SECURE); + root["ledTestOnPower"] = preferences.getBool("ledTestOnPower", DEFAULT_LED_TEST_ON_POWER); + root["ledFlashOnUpd"] = preferences.getBool("ledFlashOnUpd", DEFAULT_LED_FLASH_ON_UPD); + root["ledBrightness"] = preferences.getUInt("ledBrightness", DEFAULT_LED_BRIGHTNESS); + root["stealFocus"] = preferences.getBool("stealFocus", DEFAULT_STEAL_FOCUS); + root["mcapBigChar"] = preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR); + root["mdnsEnabled"] = preferences.getBool("mdnsEnabled", DEFAULT_MDNS_ENABLED); + root["otaEnabled"] = preferences.getBool("otaEnabled", DEFAULT_OTA_ENABLED); + root["fetchEurPrice"] = preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE); + root["useSatsSymbol"] = preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL); + root["useBlkCountdown"] = preferences.getBool("useBlkCountdown", DEFAULT_USE_BLOCK_COUNTDOWN); + root["suffixPrice"] = preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE); + root["disableLeds"] = preferences.getBool("disableLeds", DEFAULT_DISABLE_LEDS); - root["hostnamePrefix"] = preferences.getString("hostnamePrefix", "btclock"); + root["hostnamePrefix"] = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX); root["hostname"] = getMyHostname(); root["ip"] = WiFi.localIP(); root["txPower"] = WiFi.getTxPower(); - root["ownDataSource"] = preferences.getBool("ownDataSource", true); + root["ownDataSource"] = preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE); #ifdef HAS_FRONTLIGHT root["hasFrontlight"] = true; - root["flMaxBrightness"] = preferences.getUInt("flMaxBrightness", 2048); - root["flAlwaysOn"] = preferences.getBool("flAlwaysOn", false); - root["flEffectDelay"] = preferences.getUInt("flEffectDelay"); - root["flFlashOnUpd"] = preferences.getBool("flFlashOnUpd", false); + root["flMaxBrightness"] = preferences.getUInt("flMaxBrightness", DEFAULT_FL_MAX_BRIGHTNESS); + root["flAlwaysOn"] = preferences.getBool("flAlwaysOn", DEFAULT_FL_ALWAYS_ON); + root["flEffectDelay"] = preferences.getUInt("flEffectDelay", DEFAULT_FL_EFFECT_DELAY); + root["flFlashOnUpd"] = preferences.getBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE); root["hasLightLevel"] = hasLightLevel(); - root["luxLightToggle"] = preferences.getUInt("luxLightToggle", 128); + root["luxLightToggle"] = preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE); #else root["hasFrontlight"] = false; root["hasLightLevel"] = false; diff --git a/src/main.cpp b/src/main.cpp index 6c1a21f..0106eab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,7 @@ extern "C" void app_main() if (!getIsOTAUpdating()) { #ifdef HAS_FRONTLIGHT - if (preferences.getUInt("luxLightToggle", 128) != 0) + if (preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) != 0) { if (hasLightLevel() && getLightLevel() == 0) { @@ -56,11 +56,11 @@ extern "C" void app_main() frontlightFadeOutAll(); } } - else if (hasLightLevel() && getLightLevel() < preferences.getUInt("luxLightToggle", 128) && !frontlightIsOn()) + else if (hasLightLevel() && getLightLevel() < preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) && !frontlightIsOn()) { frontlightFadeInAll(); } - else if (frontlightIsOn() && getLightLevel() > preferences.getUInt("luxLightToggle", 128)) + else if (frontlightIsOn() && getLightLevel() > preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE)) { frontlightFadeOutAll(); } @@ -91,7 +91,7 @@ extern "C" void app_main() Serial.println(F("Connection restored, reset timer.")); } - if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", false) && !isPriceNotifyConnected()) + if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && !isPriceNotifyConnected()) { priceNotifyLostConnection++; Serial.println(F("Lost price data connection..."));