Fix bitcoin halving countdown and add EUR fetch price
This commit is contained in:
parent
3f49b3ef4e
commit
6dfc15832b
9 changed files with 72 additions and 19 deletions
|
@ -167,8 +167,12 @@ void setupPreferences()
|
|||
void setupWebsocketClients(void *pvParameters)
|
||||
{
|
||||
setupBlockNotify();
|
||||
// setupPriceFetchTask();
|
||||
setupPriceNotify();
|
||||
|
||||
if (preferences.getBool("fetchEurPrice", false)) {
|
||||
setupPriceFetchTask();
|
||||
} else {
|
||||
setupPriceNotify();
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
|
|
@ -120,6 +120,8 @@ void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent, bool forceUpda
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(epdUpdateMutex);
|
||||
|
||||
waitUntilNoneBusy();
|
||||
|
||||
for (uint i = 0; i < NUM_SCREENS; i++)
|
||||
{
|
||||
if (newEpdContent[i].compareTo(currentEpdContent[i]) != 0 || forceUpdate)
|
||||
|
@ -387,7 +389,7 @@ void waitUntilNoneBusy()
|
|||
vTaskDelay(10);
|
||||
if (count == 200)
|
||||
{
|
||||
displays[i].init(0, false);
|
||||
//displays[i].init(0, false);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
else if (count > 205)
|
||||
|
|
|
@ -27,17 +27,17 @@ void taskPriceFetch(void *pvParameters)
|
|||
String payload = http->getString();
|
||||
StaticJsonDocument<96> doc;
|
||||
deserializeJson(doc, payload);
|
||||
usdPrice = doc["bitcoin"]["usd"];
|
||||
eurPrice = doc["bitcoin"]["eur"];
|
||||
// usdPrice = doc["bitcoin"]["usd"];
|
||||
eurPrice = doc["bitcoin"]["eur"].as<uint>();
|
||||
|
||||
setPrice(usdPrice);
|
||||
setPrice(eurPrice);
|
||||
if (workQueue != nullptr && (getCurrentScreen() == SCREEN_BTC_TICKER || getCurrentScreen() == SCREEN_MSCW_TIME || getCurrentScreen() == SCREEN_MARKET_CAP))
|
||||
{
|
||||
WorkItem priceUpdate = {TASK_PRICE_UPDATE, 0};
|
||||
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
|
||||
}
|
||||
|
||||
preferences.putUInt("lastPrice", usdPrice);
|
||||
preferences.putUInt("lastPrice", eurPrice);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -48,14 +48,23 @@ void workerTask(void *pvParameters)
|
|||
{
|
||||
firstIndex = 0;
|
||||
uint price = getPrice();
|
||||
char priceSymbol = '$';
|
||||
if (getCurrentScreen() == SCREEN_BTC_TICKER)
|
||||
{
|
||||
priceString = ("$" + String(price)).c_str();
|
||||
if (preferences.getBool("fetchEurPrice", false)) {
|
||||
priceSymbol = '[';
|
||||
}
|
||||
|
||||
priceString = (priceSymbol + String(price)).c_str();
|
||||
|
||||
if (priceString.length() < (NUM_SCREENS))
|
||||
{
|
||||
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
||||
taskEpdContent[0] = "BTC/USD";
|
||||
if (preferences.getBool("fetchEurPrice", false)) {
|
||||
taskEpdContent[0] = "BTC/EUR";
|
||||
} else {
|
||||
taskEpdContent[0] = "BTC/USD";
|
||||
}
|
||||
firstIndex = 1;
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +163,7 @@ void workerTask(void *pvParameters)
|
|||
taskEpdContent[1] = "HALV/ING";
|
||||
taskEpdContent[(NUM_SCREENS - 5)] = String(years) + "/YRS";
|
||||
taskEpdContent[(NUM_SCREENS - 4)] = String(days) + "/DAYS";
|
||||
taskEpdContent[(NUM_SCREENS - 3)] = String(days) + "/HRS";
|
||||
taskEpdContent[(NUM_SCREENS - 3)] = String(hours) + "/HRS";
|
||||
taskEpdContent[(NUM_SCREENS - 2)] = String(mins) + "/MINS";
|
||||
taskEpdContent[(NUM_SCREENS - 1)] = "TO/GO";
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
|||
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["hostname"] = getMyHostname();
|
||||
root["ip"] = WiFi.localIP();
|
||||
|
||||
|
@ -305,6 +305,19 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
|
||||
settingsChanged = processEpdColorSettings(request);
|
||||
|
||||
if (request->hasParam("fetchEurPrice", true))
|
||||
{
|
||||
AsyncWebParameter *fetchEurPrice = request->getParam("fetchEurPrice", true);
|
||||
|
||||
preferences.putBool("fetchEurPrice", fetchEurPrice->value().toInt());
|
||||
settingsChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
preferences.putBool("fetchEurPrice", 0);
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("ledTestOnPower", true))
|
||||
{
|
||||
AsyncWebParameter *ledTestOnPower = request->getParam("ledTestOnPower", true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue