From 626877d4ee5ece64976946766cba6ce8a96a158b Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sun, 17 Mar 2024 00:47:59 +0100 Subject: [PATCH] Working row settings, build all targets --- .github/workflows/tagging.yml | 1 + platformio.ini | 2 +- src/main.cpp | 200 +++++++++++++++++++++------------- src/webserver.cpp | 1 + 4 files changed, 128 insertions(+), 76 deletions(-) diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml index 8d50475..4021d6e 100644 --- a/.github/workflows/tagging.yml +++ b/.github/workflows/tagging.yml @@ -28,6 +28,7 @@ jobs: build: needs: prepare + continue-on-error: true strategy: matrix: epd_variant: [213epd, 29epd] diff --git a/platformio.ini b/platformio.ini index fa6c962..22f1f4a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] data_dir = data/build -default_envs = lolin_s2_mini_213epd, lolin_s2_mini_29epd, lolin_s3_mini_213epd +default_envs = lolin_s2_mini_213epd, lolin_s2_mini_29epd, lolin_s3_mini_213epd, lolin_s3_mini_29epd [btclock_base] platform = espressif32 diff --git a/src/main.cpp b/src/main.cpp index b1ef4f4..b510d3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,10 @@ GxEPD2_BW display = EPD_CLASS(4, 2, 3, 1); GxEPD2_BW display = EPD_CLASS(5, 3, 2, 1); #endif +typedef void (*MethodPtr)(String); + +MethodPtr methods[] = { nullptr, updateRow1, updateRow2, updateRow3 }; + WiFiClientSecure client; uint currentPrice = 0; String currentBlock = ""; @@ -89,93 +93,139 @@ void loop() } } - String block = String(getBlock()); - uint tryCount = 0; - while (block.equals("")) - { - block = getBlock(); - Serial.print("Retry block.."); - tryCount++; - Serial.println(tryCount); - delay(1000); - - if (tryCount % 5) - { - WiFi.disconnect(); - WiFi.reconnect(); - - while (WiFi.status() != WL_CONNECTED) - { - Serial.print('.'); - delay(1000); + for (uint i = 1; i <= 3; i++) { + String rowContent = ""; + char keyName[5]; + snprintf(keyName, sizeof(keyName), "row%d", i); + Serial.print(keyName); + Serial.print(" "); + Serial.println(preferences.getUInt(keyName)); + switch (preferences.getUInt(keyName)) { + case LINE_BLOCKHEIGHT: + rowContent = getBlock(); + break; + case LINE_MEMPOOL_FEES: + rowContent = getMempoolFees(); + break; + case LINE_MEMPOOL_FEES_MEDIAN: + rowContent = "NOT IMPL"; + break; + case LINE_HALVING_COUNTDOWN: + rowContent = "NOT IMPL"; + break; + case LINE_SATSPERUNIT: { + uint satsPerDollar = int(round(1 / float(getPrice()) * 10e7)); + rowContent = satsPerDollar; + break; } + case LINE_FIATPRICE: + rowContent = getPrice(); + break; + case LINE_MARKETCAP: + rowContent = "NOT IMPL"; + break; + case LINE_TIME: + rowContent = "NOT IMPL"; + break; + case LINE_DATE: + rowContent = "NOT IMPL"; + break; + default: + rowContent = "DEFAULT"; } + + methods[i](rowContent); } - uint price = getPrice(); - tryCount = 0; - while (price == 0) - { - price = getPrice(); - if (Serial.available()) - Serial.print("Retry price.."); - tryCount++; - if (Serial.available()) - Serial.println(tryCount); - delay(1000); - } + // String block = String(getBlock()); - uint satsPerDollar = int(round(1 / float(price) * 10e7)); + // uint tryCount = 0; + // while (block.equals("")) + // { + // block = getBlock(); + // Serial.print("Retry block.."); + // tryCount++; - String mempoolFees = getMempoolFees(); - tryCount = 0; - while (mempoolFees.equals("")) - { - mempoolFees = getMempoolFees(); - Serial.print("Retry mempoolfees.."); - tryCount++; + // Serial.println(tryCount); + // delay(1000); - Serial.println(tryCount); - delay(1000); - } + // if (tryCount % 5) + // { + // WiFi.disconnect(); + // WiFi.reconnect(); - if (!currentFees.equals(mempoolFees)) - { - updateRow1(mempoolFees); - currentFees = mempoolFees; - Serial.print(F("Fees is now ")); - Serial.println(currentFees); - } - else - { - Serial.println(F("No need to update fees")); - } + // while (WiFi.status() != WL_CONNECTED) + // { + // Serial.print('.'); + // delay(1000); + // } + // } + // } - if (price != currentPrice) - { - updateRow3(String(satsPerDollar)); - currentPrice = price; - Serial.print(F("Price is now ")); - Serial.println(currentPrice); - } - else - { - Serial.println(F("No need to update price")); - } + // uint price = getPrice(); + // tryCount = 0; + // while (price == 0) + // { + // price = getPrice(); + // if (Serial.available()) + // Serial.print("Retry price.."); + // tryCount++; + // if (Serial.available()) + // Serial.println(tryCount); + // delay(1000); + // } - if (!block.equals(currentBlock)) - { - updateRow2(block); - currentBlock = block; - Serial.print(F("Block is now ")); - Serial.println(currentBlock); - } - else - { - Serial.println(F("No need to update block")); - } + // uint satsPerDollar = int(round(1 / float(price) * 10e7)); + + // String mempoolFees = getMempoolFees(); + // tryCount = 0; + // while (mempoolFees.equals("")) + // { + // mempoolFees = getMempoolFees(); + // Serial.print("Retry mempoolfees.."); + // tryCount++; + + // Serial.println(tryCount); + // delay(1000); + // } + + // if (!currentFees.equals(mempoolFees)) + // { + // updateRow1(mempoolFees); + // currentFees = mempoolFees; + // Serial.print(F("Fees is now ")); + // Serial.println(currentFees); + // } + // else + // { + // Serial.println(F("No need to update fees")); + // } + + // if (price != currentPrice) + // { + // updateRow3(String(satsPerDollar)); + // currentPrice = price; + // Serial.print(F("Price is now ")); + // Serial.println(currentPrice); + // } + // else + // { + // Serial.println(F("No need to update price")); + // } + + // if (!block.equals(currentBlock)) + // { + // updateRow2(block); + // currentBlock = block; + // Serial.print(F("Block is now ")); + // Serial.println(currentBlock); + // } + // else + // { + // Serial.println(F("No need to update block")); + // } // updateRows(mempoolFees, block, String(price)); diff --git a/src/webserver.cpp b/src/webserver.cpp index 590b1bf..785de57 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -21,6 +21,7 @@ void setupWebserver() server.serveStatic("/build", LittleFS, "/build"); server.on("/", HTTP_GET, onIndex); + server.onNotFound(onNotFound); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods",