From 132aa835cd8492900b9af9bc89f6cd1e25ad4635 Mon Sep 17 00:00:00 2001 From: kdmukai Date: Mon, 9 Dec 2024 15:58:39 -0600 Subject: [PATCH 1/6] Mow Units no rounding! --- lib/btclock/data_handler.cpp | 11 +++++++++-- lib/btclock/utils.cpp | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/btclock/data_handler.cpp b/lib/btclock/data_handler.cpp index b489bb8..eaf4538 100644 --- a/lib/btclock/data_handler.cpp +++ b/lib/btclock/data_handler.cpp @@ -73,7 +73,7 @@ std::array parsePriceData(std::uint32_t price, char cu std::string priceString; if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat) { - int numScreens = shareDot && !mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; + int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode); } else @@ -85,7 +85,14 @@ std::array parsePriceData(std::uint32_t price, char cu { priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - ret[0] = "BTC/" + getCurrencyCode(currencySymbol); + if (mowMode) + { + ret[0] = "MOW/UNITS"; + } + else + { + ret[0] = "BTC/" + getCurrencyCode(currencySymbol); + } firstIndex = 1; diff --git a/lib/btclock/utils.cpp b/lib/btclock/utils.cpp index 9056d14..45dfdd2 100644 --- a/lib/btclock/utils.cpp +++ b/lib/btclock/utils.cpp @@ -1,4 +1,5 @@ #include "utils.hpp" +#include int modulo(int x, int N) { @@ -83,14 +84,31 @@ std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters, bool mo } // Add suffix - int len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix); + int len; + + // Mow Mode always uses string truncation to avoid rounding + std::string mowAsString = std::to_string(numDouble); + if (mowMode) { + // Default to one decimal place + len = snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2).c_str(), suffix); + } + else + { + len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix); + } // If there's room, add more decimal places if (len < numCharacters) { int restLen = mowMode ? numCharacters - len : numCharacters - len - 1; - - snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix); + + if (mowMode) { + snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2 + restLen).c_str(), suffix); + } + else + { + snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix); + } } return result; From 9ada991ab15f7aa90060c8692da8554852617d7b Mon Sep 17 00:00:00 2001 From: kdmukai Date: Mon, 9 Dec 2024 16:05:55 -0600 Subject: [PATCH 2/6] Update utils.cpp --- lib/btclock/utils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/btclock/utils.cpp b/lib/btclock/utils.cpp index 45dfdd2..0e19962 100644 --- a/lib/btclock/utils.cpp +++ b/lib/btclock/utils.cpp @@ -1,5 +1,4 @@ #include "utils.hpp" -#include int modulo(int x, int N) { From 2a116d97ed88333296949c6b84529bbb303827f3 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 10 Dec 2024 15:13:17 +0100 Subject: [PATCH 3/6] Add frontlight off when dark setting --- data | 2 +- src/lib/defaults.hpp | 2 ++ src/lib/webserver.cpp | 4 +++- src/main.cpp | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/data b/data index f0fa58b..25e91b2 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit f0fa58b5ea60f695aeaae9ddd7138cbb3686e96a +Subproject commit 25e91b2086936e7c6ef09e917c6efd371293fd7e diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index 8af3b5b..ada5531 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -45,6 +45,8 @@ #define DEFAULT_FL_EFFECT_DELAY 15 #define DEFAULT_LUX_LIGHT_TOGGLE 128 +#define DEFAULT_FL_OFF_WHEN_DARK true + #define DEFAULT_FL_ALWAYS_ON false #define DEFAULT_FL_FLASH_ON_UPDATE false diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 777fe0b..b901379 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", "suffixShareDot", + "mowMode", "suffixShareDot", "flOffWhenDark", "flAlwaysOn", "flDisable", "flFlashOnUpd", "mempoolSecure", "useNostr", "bitaxeEnabled", "nostrZapNotify", "stagingSource", "httpAuthEnabled"}; @@ -726,6 +726,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["hasLightLevel"] = hasLightLevel(); root["luxLightToggle"] = preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE); + root["flOffWhenDark"] = preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK); + #else root["hasFrontlight"] = false; root["hasLightLevel"] = false; diff --git a/src/main.cpp b/src/main.cpp index 908f155..b9d2ae7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,7 @@ extern "C" void app_main() if (hasLightLevel()) { if (preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) != 0) { - if (hasLightLevel() && getLightLevel() <= 2) + if (hasLightLevel() && getLightLevel() <= 1 && preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK)) { if (frontlightIsOn()) { frontlightFadeOutAll(); From dbf2c53083c05187d5e6f152d5e2ba32a3fd16a1 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 10 Dec 2024 15:18:04 +0100 Subject: [PATCH 4/6] Adapted tests for Mow Units --- test/test_datahandler/test_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_datahandler/test_main.cpp b/test/test_datahandler/test_main.cpp index b09c9b1..24118e4 100644 --- a/test/test_datahandler/test_main.cpp +++ b/test/test_datahandler/test_main.cpp @@ -143,7 +143,7 @@ void test_PriceSuffixModeCompact2(void) void test_PriceSuffixModeMow(void) { - std::array output = parsePriceData(93000, '$', true, true); + std::array output = parsePriceData(93600, '$', true, true); std::string joined = joinArrayWithBrackets(output); @@ -158,11 +158,11 @@ void test_PriceSuffixModeMow(void) void test_PriceSuffixModeMowCompact(void) { - std::array output = parsePriceData(93000, '$', true, true, true); + std::array output = parsePriceData(93600, '$', true, true, true); std::string joined = joinArrayWithBrackets(output); - TEST_ASSERT_EQUAL_STRING_MESSAGE("BTC/USD", output[0].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING_MESSAGE("MOW/UNITS", output[0].c_str(), joined.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()); From 34b77ea1056e2d7fa8c3df0795b666c6b2d07d84 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Thu, 12 Dec 2024 23:12:59 +0100 Subject: [PATCH 5/6] Update WebUI --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 25e91b2..653a39d 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 25e91b2086936e7c6ef09e917c6efd371293fd7e +Subproject commit 653a39d0a339bcf3ac3365eacd2e5e8136ecf4c6 From 4a52fc0bf22c050a440eca7aa885cf18bcd42f10 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Wed, 18 Dec 2024 00:50:20 +0100 Subject: [PATCH 6/6] Add vertical screen description option --- data | 2 +- src/lib/defaults.hpp | 1 + src/lib/epd.cpp | 6 +++++- src/lib/webserver.cpp | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/data b/data index 653a39d..266a99b 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 653a39d0a339bcf3ac3365eacd2e5e8136ecf4c6 +Subproject commit 266a99be96189bea92e0ef593f930bb92d3b5b20 diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index ada5531..11df69a 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -70,3 +70,4 @@ #define DEFAULT_ACTIVE_CURRENCIES "USD,EUR,JPY" #define DEFAULT_GIT_RELEASE_URL "https://git.btclock.dev/api/v1/repos/btclock/btclock_v3/releases/latest" +#define DEFAULT_VERTICAL_DESC true diff --git a/src/lib/epd.cpp b/src/lib/epd.cpp index 1c04725..986b9cc 100644 --- a/src/lib/epd.cpp +++ b/src/lib/epd.cpp @@ -373,7 +373,11 @@ extern "C" void updateDisplay(void *pvParameters) noexcept void splitText(const uint dispNum, const String &top, const String &bottom, bool partial) { - displays[dispNum].setRotation(2); + if(preferences.getBool("verticalDesc", DEFAULT_VERTICAL_DESC) && dispNum == 0) { + displays[dispNum].setRotation(1); + } else { + displays[dispNum].setRotation(2); + } displays[dispNum].setFont(&FONT_SMALL); displays[dispNum].setTextColor(getFgColor()); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index b901379..11b9024 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -549,6 +549,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) "mowMode", "suffixShareDot", "flOffWhenDark", "flAlwaysOn", "flDisable", "flFlashOnUpd", "mempoolSecure", "useNostr", "bitaxeEnabled", + "verticalDesc", "nostrZapNotify", "stagingSource", "httpAuthEnabled"}; for (String setting : boolSettings) @@ -689,6 +690,8 @@ 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["verticalDesc"] = preferences.getBool("verticalDesc", DEFAULT_VERTICAL_DESC); + root["suffixShareDot"] = preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT); root["hostnamePrefix"] = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX);