mirror of
https://github.com/btclock/btclock_v3.git
synced 2024-11-19 04:30:02 +01:00
Add market cap in big characters
This commit is contained in:
parent
705f27fda9
commit
b7f0f1014c
@ -95,7 +95,7 @@
|
||||
</script>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="col-sm-3">
|
||||
<div class="h-100 p-3 border bg-light">
|
||||
<h1>Custom text</h1>
|
||||
<form name="customText" id="customTextForm">
|
||||
@ -124,10 +124,10 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="col-sm-5">
|
||||
<div id="output" class="p-3 border bg-light">Loading, please wait...</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="col-sm-4">
|
||||
<div class="h-100 p-3 border bg-light">
|
||||
<h1>Settings</h1>
|
||||
<form method="post" action="/api/settings" name="settings" id="settingsForm">
|
||||
@ -192,13 +192,29 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class=" col-sm-6">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="ledFlashOnUpdate" name="ledFlashOnUpd" value="1">
|
||||
<label class="form-check-label" for="ledFlashOnUpdate">LED flash on new block</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="stealFocusOnBlock" name="stealFocusOnBlock" value="1">
|
||||
<label class="form-check-label" for="stealFocusOnBlock">Steal focus on new block</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="mcapBigChar" name="mcapBigChar" value="1">
|
||||
<label class="form-check-label" for="mcapBigChar">Use big characters for market cap</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="col-sm-6 col-form-label" for="ledBrightness">LED brightness</label>
|
||||
<div class="col-sm-6">
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -49,31 +49,41 @@ void taskPriceUpdate(void *pvParameters)
|
||||
{
|
||||
double supply = getSupplyAtBlock(getBlockHeight());
|
||||
int64_t marketCap = static_cast<std::int64_t>(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];
|
||||
|
@ -30,3 +30,25 @@ double getSupplyAtBlock(uint blockNr) {
|
||||
|
||||
return totalBitcoinInCirculation;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -8,3 +8,4 @@ int modulo(int x,int N);
|
||||
double getSupplyAtBlock(uint blockNr);
|
||||
|
||||
String getMyHostname();
|
||||
std::string formatNumberWithSuffix(int64_t num);
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user