diff --git a/data/src/index.html b/data/src/index.html index 1c276ea..19ce6f7 100644 --- a/data/src/index.html +++ b/data/src/index.html @@ -95,7 +95,7 @@
-
+

Custom text

@@ -124,10 +124,10 @@
-
+
Loading, please wait...
-
+

Settings

@@ -192,13 +192,29 @@
-
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
diff --git a/data/src/js/script.ts b/data/src/js/script.ts index bd44a6b..9523f42 100644 --- a/data/src/js/script.ts +++ b/data/src/js/script.ts @@ -100,6 +100,12 @@ fetch('/api/settings', { if (jsonData.ledFlashOnUpdate) document.getElementById('ledFlashOnUpdate').checked = true; + if (jsonData.stealFocusOnBlock) + document.getElementById('stealFocusOnBlock').checked = true; + + if (jsonData.mcapBigChar) + document.getElementById('mcapBigChar').checked = true; + if (jsonData.useBitcoinNode) document.getElementById('useBitcoinNode').checked = true; diff --git a/src/lib/block_notify.cpp b/src/lib/block_notify.cpp index 6e44993..201b2ba 100644 --- a/src/lib/block_notify.cpp +++ b/src/lib/block_notify.cpp @@ -94,8 +94,12 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data) if (blockUpdateTaskHandle != nullptr) { xTaskNotifyGive(blockUpdateTaskHandle); - if (preferences.getBool("ledFlashOnUpd", false)) { + + if (getCurrentScreen() != SCREEN_BLOCK_HEIGHT && preferences.getBool("stealFocus", true)) { setCurrentScreen(SCREEN_BLOCK_HEIGHT); + } + + if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT && preferences.getBool("ledFlashOnUpd", false)) { vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated queueLedEffect(LED_FLASH_BLOCK_NOTIFY); } diff --git a/src/lib/screen_handler.cpp b/src/lib/screen_handler.cpp index 4d4b05f..71a6213 100644 --- a/src/lib/screen_handler.cpp +++ b/src/lib/screen_handler.cpp @@ -49,31 +49,41 @@ void taskPriceUpdate(void *pvParameters) { double supply = getSupplyAtBlock(getBlockHeight()); int64_t marketCap = static_cast(supply * double(price)); - std::string stringValue = std::to_string(marketCap); - size_t mcLength = stringValue.length(); - size_t leadingSpaces = (3 - mcLength % 3) % 3; - stringValue = std::string(leadingSpaces, ' ') + stringValue; + taskEpdContent[0] = "USD/MCAP"; - uint groups = (mcLength + leadingSpaces) / 3; - - if (groups < NUM_SCREENS) { + if (preferences.getBool("mcapBigChar", true)) { firstIndex = 1; - } - for (int i = firstIndex; i < NUM_SCREENS-groups-1; i++) { - taskEpdContent[i] = ""; - } + priceString = "$" + formatNumberWithSuffix(marketCap); + priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - taskEpdContent[NUM_SCREENS-groups-1] = " $ "; - for (uint i = 0; i < groups; i ++) - { - taskEpdContent[(NUM_SCREENS-groups+i)] = stringValue.substr(i*3, 3).c_str(); + } else { + std::string stringValue = std::to_string(marketCap); + size_t mcLength = stringValue.length(); + size_t leadingSpaces = (3 - mcLength % 3) % 3; + stringValue = std::string(leadingSpaces, ' ') + stringValue; + + uint groups = (mcLength + leadingSpaces) / 3; + + if (groups < NUM_SCREENS) { + firstIndex = 1; + } + + for (int i = firstIndex; i < NUM_SCREENS-groups-1; i++) { + taskEpdContent[i] = ""; + } + + taskEpdContent[NUM_SCREENS-groups-1] = " $ "; + for (uint i = 0; i < groups; i ++) + { + taskEpdContent[(NUM_SCREENS-groups+i)] = stringValue.substr(i*3, 3).c_str(); + } } } - if (getCurrentScreen() != SCREEN_MARKET_CAP) { + if (!(getCurrentScreen() == SCREEN_MARKET_CAP && !preferences.getBool("mcapBigChar", true))) { for (uint i = firstIndex; i < NUM_SCREENS; i++) { taskEpdContent[i] = priceString[i]; diff --git a/src/lib/utils.cpp b/src/lib/utils.cpp index f02dc86..5eaf958 100644 --- a/src/lib/utils.cpp +++ b/src/lib/utils.cpp @@ -29,4 +29,26 @@ double getSupplyAtBlock(uint blockNr) { totalBitcoinInCirculation += (blockNr % halvingInterval) * initialBlockReward * std::pow(0.5, halvingCount); return totalBitcoinInCirculation; -} \ No newline at end of file +} + +std::string formatNumberWithSuffix(int64_t num) { + const long long quadrillion = 1000000000000000LL; + const long long trillion = 1000000000000LL; + const long long billion = 1000000000; + const long long million = 1000000; + const long long thousand = 1000; + + if (num >= quadrillion) { + return std::to_string(num / quadrillion) + "Q"; + } else if (num >= trillion) { + return std::to_string(num / trillion) + "T"; + } else if (num >= billion) { + return std::to_string(num / billion) + "B"; + } else if (num >= million) { + return std::to_string(num / million) + "M"; + } else if (num >= thousand) { + return std::to_string(num / thousand) + "K"; + } else { + return std::to_string(num); + } +} diff --git a/src/lib/utils.hpp b/src/lib/utils.hpp index 951beec..81730e2 100644 --- a/src/lib/utils.hpp +++ b/src/lib/utils.hpp @@ -7,4 +7,5 @@ int modulo(int x,int N); double getSupplyAtBlock(uint blockNr); -String getMyHostname(); \ No newline at end of file +String getMyHostname(); +std::string formatNumberWithSuffix(int64_t num); \ No newline at end of file diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index c1d31da..12a3f00 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -20,8 +20,7 @@ void setupWebserver() } // send event with message "hello!", id current millis // and set reconnect delay to 1 second - client->send("welcome",NULL,millis(),1000); - }); + client->send("welcome",NULL,millis(),1000); }); server.addHandler(&events); server.serveStatic("/css", LittleFS, "/css/"); @@ -95,7 +94,8 @@ StaticJsonDocument<768> getStatusObject() void eventSourceUpdate() { - if (!events.count()) return; + if (!events.count()) + return; StaticJsonDocument<768> root = getStatusObject(); JsonArray data = root.createNestedArray("data"); String epdContent[NUM_SCREENS]; @@ -221,6 +221,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["ledTestOnPower"] = preferences.getBool("ledTestOnPower", true); root["ledFlashOnUpdate"] = preferences.getBool("ledFlashOnUpd", false); root["ledBrightness"] = preferences.getUInt("ledBrightness", 128); + root["stealFocusOnBlock"] = preferences.getBool("stealFocus", true); + root["mcapBigChar"] = preferences.getBool("mcapBigChar", true); #ifdef GIT_REV root["gitRev"] = String(GIT_REV); @@ -284,8 +286,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request) AsyncWebParameter *ledFlashOnUpdate = request->getParam("ledFlashOnUpd", true); preferences.putBool("ledFlashOnUpd", ledFlashOnUpdate->value().toInt()); - Serial.print("Setting led flash on update to "); - Serial.println(ledFlashOnUpdate->value().c_str()); + Serial.printf("Setting led flash on update to %d\r\n", ledFlashOnUpdate->value().toInt()); settingsChanged = true; } else @@ -295,6 +296,36 @@ void onApiSettingsPost(AsyncWebServerRequest *request) settingsChanged = true; } + if (request->hasParam("stealFocusOnBlock", true)) + { + AsyncWebParameter *stealFocusOnBlock = request->getParam("stealFocusOnBlock", true); + + preferences.putBool("stealFocus", stealFocusOnBlock->value().toInt()); + Serial.printf("Setting steal focus on new block to %d\r\n", stealFocusOnBlock->value().toInt()); + settingsChanged = true; + } + else + { + preferences.putBool("stealFocus", 0); + Serial.print("Setting steal focus on new block to false"); + settingsChanged = true; + } + + if (request->hasParam("mcapBigChar", true)) + { + AsyncWebParameter *mcapBigChar = request->getParam("mcapBigChar", true); + + preferences.putBool("mcapBigChar", mcapBigChar->value().toInt()); + Serial.printf("Setting big characters for market cap to %d\r\n", mcapBigChar->value().toInt()); + settingsChanged = true; + } + else + { + preferences.putBool("mcapBigChar", 0); + Serial.print("Setting big characters for market cap to false"); + settingsChanged = true; + } + if (request->hasParam("mempoolInstance", true)) { AsyncWebParameter *mempoolInstance = request->getParam("mempoolInstance", true); @@ -318,7 +349,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request) AsyncWebParameter *fullRefreshMin = request->getParam("fullRefreshMin", true); preferences.putUInt("fullRefreshMin", fullRefreshMin->value().toInt()); - Serial.printf("Set full refresh minutes to %d\r\n",fullRefreshMin->value().toInt()); + Serial.printf("Set full refresh minutes to %d\r\n", fullRefreshMin->value().toInt()); settingsChanged = true; } @@ -357,7 +388,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request) settingsChanged = true; } - if (request->hasParam("minSecPriceUpd", true)) + if (request->hasParam("minSecPriceUpd", true)) { AsyncWebParameter *p = request->getParam("minSecPriceUpd", true); int minSecPriceUpd = p->value().toInt(); @@ -459,7 +490,8 @@ void onNotFound(AsyncWebServerRequest *request) } }; -void eventSourceTask(void *pvParameters) { +void eventSourceTask(void *pvParameters) +{ for (;;) { ulTaskNotifyTake(pdTRUE, portMAX_DELAY);