From 4cda081d05e76351cce434b9d6a14298bedb8dcd Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Thu, 28 Nov 2024 18:22:07 +0100 Subject: [PATCH] Add suffix compact mode, added extra zap notify settings, WebUI cleanup --- .forgejo/workflows/push.yaml | 2 +- data | 2 +- dependencies.lock | 2 +- lib/btclock/data_handler.cpp | 40 +++++++++++++++++++++++++---- lib/btclock/data_handler.hpp | 3 ++- partition.csv | 6 ++--- platformio.ini | 4 +-- src/lib/defaults.hpp | 3 +++ src/lib/epd.cpp | 2 +- src/lib/led_handler.cpp | 4 +-- src/lib/nostr_notify.cpp | 5 +++- src/lib/screen_handler.cpp | 5 +++- src/lib/webserver.cpp | 7 ++++- test/test_datahandler/test_main.cpp | 16 ++++++++++++ 14 files changed, 81 insertions(+), 20 deletions(-) diff --git a/.forgejo/workflows/push.yaml b/.forgejo/workflows/push.yaml index b48a34e..5121d24 100644 --- a/.forgejo/workflows/push.yaml +++ b/.forgejo/workflows/push.yaml @@ -116,7 +116,7 @@ jobs: 0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \ 0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \ 0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \ - 0x369000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin + 0x370000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin # Adjust the offset for littlefs or other files as needed for the original case fi diff --git a/data b/data index d74e9da..de99a22 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d74e9dab60772ef11f9b033cfe982d216a9c95ee +Subproject commit de99a221d688949da0d95e2f9df2da5ba77f5c0d diff --git a/dependencies.lock b/dependencies.lock index 2cb885d..c338e6c 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -4,6 +4,6 @@ dependencies: source: type: idf version: 4.4.7 -manifest_hash: 841ba2a95f4b32d39636bf4fdf07c48a2052f71c9728a5b7f263083a3b430a4f +manifest_hash: cd2f3ee15e776d949eb4ea4eddc8f39b30c2a7905050850eed01ab4928143cff target: esp32s3 version: 1.0.0 diff --git a/lib/btclock/data_handler.cpp b/lib/btclock/data_handler.cpp index 3209811..c1f1d1f 100644 --- a/lib/btclock/data_handler.cpp +++ b/lib/btclock/data_handler.cpp @@ -67,7 +67,7 @@ char getCurrencyChar(const std::string& input) return CURRENCY_USD; // Assuming USD is the default for unknown inputs } -std::array parsePriceData(std::uint32_t price, char currencySymbol, bool useSuffixFormat, bool mowMode) +std::array parsePriceData(std::uint32_t price, char currencySymbol, bool useSuffixFormat, bool mowMode, bool shareDot) { std::array ret; std::string priceString; @@ -80,7 +80,7 @@ std::array parsePriceData(std::uint32_t price, char cu priceString = getCurrencySymbol(currencySymbol) + std::to_string(price); } std::uint32_t firstIndex = 0; - if (priceString.length() < (NUM_SCREENS)) + if ((shareDot && priceString.length() <= (NUM_SCREENS)) || priceString.length() < (NUM_SCREENS)) { priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); @@ -89,11 +89,41 @@ std::array parsePriceData(std::uint32_t price, char cu firstIndex = 1; } - - for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) + + if (shareDot) { - ret[i] = priceString[i]; + std::vector tempArray; + size_t dotPosition = priceString.find('.'); + if (dotPosition != std::string::npos && dotPosition > 0) + { + for (size_t i = 0; i < priceString.length(); ++i) + { + if (i == dotPosition - 1) + { + tempArray.push_back(std::string(1, priceString[i]) + "."); + ++i; // Skip the dot in the next iteration + } + else + { + tempArray.push_back(std::string(1, priceString[i])); + } + } + + // Copy from tempArray to ret + for (std::uint32_t i = firstIndex; i < NUM_SCREENS && i - firstIndex < tempArray.size(); ++i) + { + ret[i] = tempArray[i - firstIndex]; + } + } } + else + { + for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) + { + ret[i] = std::string(1, priceString[i]); + } + } + return ret; } diff --git a/lib/btclock/data_handler.hpp b/lib/btclock/data_handler.hpp index f8e237c..4dda86b 100644 --- a/lib/btclock/data_handler.hpp +++ b/lib/btclock/data_handler.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "utils.hpp" @@ -19,7 +20,7 @@ const std::string CURRENCY_CODE_JPY = "JPY"; const std::string CURRENCY_CODE_AUD = "AUD"; const std::string CURRENCY_CODE_CAD = "CAD"; -std::array parsePriceData(std::uint32_t price, char currency, bool useSuffixFormat = false, bool mowMode = false); +std::array parsePriceData(std::uint32_t price, char currency, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false); std::array parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol); std::array parseBlockHeight(std::uint32_t blockHeight); std::array parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks); diff --git a/partition.csv b/partition.csv index 318b4f0..778b9f2 100644 --- a/partition.csv +++ b/partition.csv @@ -1,7 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 36K, 20K, otadata, data, ota, 56K, 8K, -app0, app, ota_0, 64K, 1740K, -app1, app, ota_1, , 1740K, -spiffs, data, spiffs, , 400K, +app0, app, ota_0, 64K, 1760K, +app1, app, ota_1, , 1760K, +spiffs, data, spiffs, , 410K, coredump, data, coredump,, 64K, diff --git a/platformio.ini b/platformio.ini index 021a03d..7b0d229 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,9 +33,9 @@ build_unflags = -fno-exceptions lib_deps = https://github.com/joltwallet/esp_littlefs.git - bblanchon/ArduinoJson@^7.2.0 + bblanchon/ArduinoJson@^7.2.1 mathieucarbou/ESPAsyncWebServer @ 3.3.23 - adafruit/Adafruit BusIO@^1.16.1 + adafruit/Adafruit BusIO@^1.16.2 adafruit/Adafruit MCP23017 Arduino Library@^2.3.2 adafruit/Adafruit NeoPixel@^1.12.3 https://github.com/dsbaars/universal_pin diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index c665b3b..8af3b5b 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -19,6 +19,7 @@ #define DEFAULT_OWN_DATA_SOURCE true #define DEFAULT_STAGING_SOURCE false #define DEFAULT_MOW_MODE false +#define DEFAULT_SUFFIX_SHARE_DOT false #define DEFAULT_V2_SOURCE_CURRENCY CURRENCY_USD @@ -57,6 +58,8 @@ #define DEFAULT_ZAP_NOTIFY_ENABLED false #define DEFAULT_ZAP_NOTIFY_PUBKEY "b5127a08cf33616274800a4387881a9f98e04b9c37116e92de5250498635c422" +#define DEFAULT_LED_FLASH_ON_ZAP true +#define DEFAULT_FL_FLASH_ON_ZAP true #define DEFAULT_HTTP_AUTH_ENABLED false #define DEFAULT_HTTP_AUTH_USERNAME "btclock" diff --git a/src/lib/epd.cpp b/src/lib/epd.cpp index eac002c..1c04725 100644 --- a/src/lib/epd.cpp +++ b/src/lib/epd.cpp @@ -534,7 +534,7 @@ void showChars(const uint dispNum, const String &chars, bool partial, int16_t dotDescent = dotGlyph->yOffset; // Draw the dot with adjusted y-position - displays[dispNum].setCursor(x, y + dotDescent + dotGlyph->height); + displays[dispNum].setCursor(x, y + dotDescent + dotGlyph->height + 8); displays[dispNum].print(c); } else { // For other characters, use the original y-position diff --git a/src/lib/led_handler.cpp b/src/lib/led_handler.cpp index 4f882e0..338c3c3 100644 --- a/src/lib/led_handler.cpp +++ b/src/lib/led_handler.cpp @@ -285,7 +285,7 @@ void ledTask(void *parameter) #ifdef HAS_FRONTLIGHT bool frontlightWasOn = false; - if (preferences.getBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE)) + if (preferences.getBool("flFlashOnZap", DEFAULT_FL_FLASH_ON_ZAP)) { if (frontlightOn) { @@ -307,7 +307,7 @@ void ledTask(void *parameter) // blinkDelayTwoColor(250, 3, pixels.Color(142, 48, 235), // pixels.Color(169, 21, 255)); #ifdef HAS_FRONTLIGHT - if (preferences.getBool("flFlashOnUpd", DEFAULT_FL_FLASH_ON_UPDATE)) + if (preferences.getBool("flFlashOnZap", DEFAULT_FL_FLASH_ON_ZAP)) { vTaskDelay(pdMS_TO_TICKS(10)); if (frontlightWasOn) diff --git a/src/lib/nostr_notify.cpp b/src/lib/nostr_notify.cpp index 237eabe..bad593d 100644 --- a/src/lib/nostr_notify.cpp +++ b/src/lib/nostr_notify.cpp @@ -252,7 +252,10 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event) setEpdContent(textEpdContent); vTaskDelay(pdMS_TO_TICKS(315 * NUM_SCREENS) + pdMS_TO_TICKS(250)); - queueLedEffect(LED_EFFECT_NOSTR_ZAP); + if (preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP)) + { + queueLedEffect(LED_EFFECT_NOSTR_ZAP); + } if (timerPeriod > 0) { esp_timer_start_periodic(screenRotateTimer, diff --git a/src/lib/screen_handler.cpp b/src/lib/screen_handler.cpp index 47ac609..1f2b4a4 100644 --- a/src/lib/screen_handler.cpp +++ b/src/lib/screen_handler.cpp @@ -41,7 +41,10 @@ void workerTask(void *pvParameters) { uint price = getPrice(currency); if (getCurrentScreen() == SCREEN_BTC_TICKER) { - taskEpdContent = parsePriceData(price, currency, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE), preferences.getBool("mowMode", DEFAULT_MOW_MODE)); + taskEpdContent = parsePriceData(price, currency, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE), + preferences.getBool("mowMode", DEFAULT_MOW_MODE), + preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT) + ); } else if (getCurrentScreen() == SCREEN_SATS_PER_CURRENCY) { taskEpdContent = parseSatsPerCurrency(price, currency, preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); } else { diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index c4ad256..777fe0b 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -546,7 +546,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) "mdnsEnabled", "otaEnabled", "stealFocus", "mcapBigChar", "useSatsSymbol", "useBlkCountdown", "suffixPrice", "disableLeds", "ownDataSource", - "mowMode", + "mowMode", "suffixShareDot", "flAlwaysOn", "flDisable", "flFlashOnUpd", "mempoolSecure", "useNostr", "bitaxeEnabled", "nostrZapNotify", "stagingSource", "httpAuthEnabled"}; @@ -689,6 +689,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["suffixPrice"] = preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE); root["disableLeds"] = preferences.getBool("disableLeds", DEFAULT_DISABLE_LEDS); root["mowMode"] = preferences.getBool("mowMode", DEFAULT_MOW_MODE); + root["suffixShareDot"] = preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT); root["hostnamePrefix"] = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX); root["hostname"] = getMyHostname(); @@ -703,6 +704,8 @@ 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["gitReleaseUrl"] = preferences.getString("gitReleaseUrl", DEFAULT_GIT_RELEASE_URL); root["bitaxeEnabled"] = preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED); @@ -719,6 +722,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request) 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["flFlashOnZap"] = preferences.getBool("flFlashOnZap", DEFAULT_FL_FLASH_ON_ZAP); + root["hasLightLevel"] = hasLightLevel(); root["luxLightToggle"] = preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE); #else diff --git a/test/test_datahandler/test_main.cpp b/test/test_datahandler/test_main.cpp index 218408c..f2ad64c 100644 --- a/test/test_datahandler/test_main.cpp +++ b/test/test_datahandler/test_main.cpp @@ -113,6 +113,21 @@ void test_PriceSuffixModeMow(void) TEST_ASSERT_EQUAL_STRING_MESSAGE("M", output[NUM_SCREENS - 1].c_str(), joined.c_str()); } +void test_PriceSuffixModeMowCompact(void) +{ + std::array output = parsePriceData(93000, '$', true, true, true); + + std::string joined = joinArrayWithBrackets(output); + + TEST_ASSERT_EQUAL_STRING("BTC/USD", output[0].c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("$", output[NUM_SCREENS - 6].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("0.", output[NUM_SCREENS - 5].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 4].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("9", output[NUM_SCREENS - 3].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("3", output[NUM_SCREENS - 2].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("M", output[NUM_SCREENS - 1].c_str(), joined.c_str()); +} + void test_McapLowerUsd(void) { std::array output = parseMarketCap(810000, 26000, '$', true); @@ -232,6 +247,7 @@ int runUnityTests(void) RUN_TEST(test_Mcap1TrillionJpySmallChars); RUN_TEST(test_PriceSuffixMode); RUN_TEST(test_PriceSuffixModeMow); + RUN_TEST(test_PriceSuffixModeMowCompact); return UNITY_END(); }