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
|
@ -71,7 +71,7 @@
|
|||
<div>
|
||||
<p>Uptime: {{#if uptime.h }}{{ uptime.h }}h {{/if}}{{ uptime.m }}m {{ uptime.s }}s</p>
|
||||
<p>
|
||||
Price connection:
|
||||
WS Price connection:
|
||||
<span>
|
||||
{{#if connectionStatus.price}}
|
||||
✅
|
||||
|
@ -80,14 +80,15 @@
|
|||
{{/if}}
|
||||
</span>
|
||||
-
|
||||
Mempool.space connection:
|
||||
WS Mempool.space connection:
|
||||
<span>
|
||||
{{#if connectionStatus.blocks}}
|
||||
✅
|
||||
{{else}}
|
||||
❌
|
||||
{{/if}}
|
||||
</span>
|
||||
</span><br>
|
||||
<small>If you use "Fetch € price" the WS Price connection will show ❌ since it uses another data source.</small>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -262,7 +263,16 @@
|
|||
<label class="form-check-label" for="mdnsEnabled">mDNS (restart required)</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="fetchEurPrice" name="fetchEurPrice" value="1">
|
||||
<label class="form-check-label" for="fetchEurPrice">Fetch € price (restart required)</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<script id="screens-template" type="text/x-handlebars-template">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
|
|
|
@ -5,7 +5,7 @@ Handlebars.registerHelper('splitText', function (aString) {
|
|||
var c = aString.split("/").map((el) => { return "<div class=\"flex-items\">" + el + "</div>"; }).join('');
|
||||
return "<div class=\"splitText\">" + c + "</div>";
|
||||
}
|
||||
if (aString.length > 1) {
|
||||
if (aString.length > 1 && !aString.startsWith("&")) {
|
||||
return "<div class=\"mediumText\">" + aString + "</div>";
|
||||
}
|
||||
if (aString.length == 0 || aString === " ") {
|
||||
|
|
|
@ -23,6 +23,13 @@ let processStatusData = (jsonData) => {
|
|||
var source = document.getElementById("entry-template").innerHTML;
|
||||
var template = Handlebars.compile(source);
|
||||
|
||||
|
||||
let index = jsonData.data.findIndex(d => d === '[');
|
||||
|
||||
if (index !== -1) {
|
||||
jsonData.data[index] = '€';
|
||||
}
|
||||
|
||||
var context = {
|
||||
timerRunning: jsonData.timerRunning,
|
||||
memFreePercent: Math.round(jsonData.espFreeHeap / jsonData.espHeapSize * 100),
|
||||
|
@ -46,7 +53,7 @@ if (!!window.EventSource) {
|
|||
const connectEventSource = () => {
|
||||
let source = new EventSource('/events');
|
||||
|
||||
source.addEventListener('open', (e) => {
|
||||
source.addEventListener('open', (e) => {
|
||||
console.log("Status EventSource Connected");
|
||||
if (e.data) {
|
||||
processStatusData(JSON.parse(e.data));
|
||||
|
@ -128,6 +135,9 @@ fetch('/api/settings', {
|
|||
if (jsonData.ledTestOnPower)
|
||||
document.getElementById('ledTestOnPower').checked = true;
|
||||
|
||||
if (jsonData.fetchEurPrice)
|
||||
document.getElementById('fetchEurPrice').checked = true;
|
||||
|
||||
// let nodeFields = ["rpcHost", "rpcPort", "rpcUser", "tzOffset"];
|
||||
|
||||
// for (let n of nodeFields) {
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
data_dir = data/build
|
||||
|
||||
[env]
|
||||
platform = espressif32
|
||||
framework = arduino, espidf
|
||||
platform = https://github.com/platformio/platform-espressif32.git
|
||||
framework = arduino, espidf
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
monitor_filters = esp32_exception_decoder, colorize
|
||||
|
@ -57,3 +57,8 @@ extends = env:lolin_s3_mini
|
|||
build_flags =
|
||||
${env:lolin_s3_mini.build_flags}
|
||||
-D USE_QR
|
||||
|
||||
[env:lolin_s3_mini_qr_ota]
|
||||
extends = env:lolin_s3_mini_qr
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.23.30
|
|
@ -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…
Reference in a new issue