Add sats symbol option, add countdown in blocks, add decimal point for market cap, add hostname to setup screen
This commit is contained in:
parent
e4a39de5fc
commit
c49b8edcb8
15 changed files with 822 additions and 321 deletions
|
@ -5,7 +5,7 @@ std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char cu
|
|||
std::array<std::string, NUM_SCREENS> ret;
|
||||
std::string priceString;
|
||||
if (std::to_string(price).length() >= NUM_SCREENS) {
|
||||
priceString = formatNumberWithSuffix(price);
|
||||
priceString = formatNumberWithSuffix(price, NUM_SCREENS-2);
|
||||
} else {
|
||||
priceString = currencySymbol + std::to_string(price);
|
||||
}
|
||||
|
@ -32,15 +32,18 @@ std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char cu
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol)
|
||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol)
|
||||
{
|
||||
std::array<std::string, NUM_SCREENS> ret;
|
||||
std::string priceString = std::to_string(int(round(1 / float(price) * 10e7)));
|
||||
std::uint32_t firstIndex = 0;
|
||||
uint insertSatSymbol = NUM_SCREENS - priceString.length() - 1;
|
||||
|
||||
if (priceString.length() < (NUM_SCREENS))
|
||||
{
|
||||
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
||||
|
||||
|
||||
if (currencySymbol == '[')
|
||||
{
|
||||
ret[0] = "SATS/EUR";
|
||||
|
@ -55,6 +58,10 @@ std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, c
|
|||
{
|
||||
ret[i] = priceString[i];
|
||||
}
|
||||
|
||||
if (withSatsSymbol) {
|
||||
ret[insertSatSymbol] = "STS";
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -80,24 +87,43 @@ std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight)
|
||||
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks)
|
||||
{
|
||||
std::array<std::string, NUM_SCREENS> ret;
|
||||
|
||||
const std::uint32_t nextHalvingBlock = 210000 - (blockHeight % 210000);
|
||||
const std::uint32_t minutesToHalving = nextHalvingBlock * 10;
|
||||
|
||||
const int years = floor(minutesToHalving / 525600);
|
||||
const int days = floor((minutesToHalving - (years * 525600)) / (24 * 60));
|
||||
const int hours = floor((minutesToHalving - (years * 525600) - (days * (24 * 60))) / 60);
|
||||
const int mins = floor(minutesToHalving - (years * 525600) - (days * (24 * 60)) - (hours * 60));
|
||||
ret[0] = "BIT/COIN";
|
||||
ret[1] = "HALV/ING";
|
||||
ret[(NUM_SCREENS - 5)] = std::to_string(years) + "/YRS";
|
||||
ret[(NUM_SCREENS - 4)] = std::to_string(days) + "/DAYS";
|
||||
ret[(NUM_SCREENS - 3)] = std::to_string(hours) + "/HRS";
|
||||
ret[(NUM_SCREENS - 2)] = std::to_string(mins) + "/MINS";
|
||||
ret[(NUM_SCREENS - 1)] = "TO/GO";
|
||||
if (asBlocks) {
|
||||
std::string blockNrString = std::to_string(nextHalvingBlock);
|
||||
std::uint32_t firstIndex = 0;
|
||||
|
||||
if (blockNrString.length() < NUM_SCREENS)
|
||||
{
|
||||
blockNrString.insert(blockNrString.begin(), NUM_SCREENS - blockNrString.length(), ' ');
|
||||
ret[0] = "HAL/VING";
|
||||
firstIndex = 1;
|
||||
}
|
||||
|
||||
for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++)
|
||||
{
|
||||
ret[i] = blockNrString[i];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
const int years = floor(minutesToHalving / 525600);
|
||||
const int days = floor((minutesToHalving - (years * 525600)) / (24 * 60));
|
||||
const int hours = floor((minutesToHalving - (years * 525600) - (days * (24 * 60))) / 60);
|
||||
const int mins = floor(minutesToHalving - (years * 525600) - (days * (24 * 60)) - (hours * 60));
|
||||
ret[0] = "BIT/COIN";
|
||||
ret[1] = "HAL/VING";
|
||||
ret[(NUM_SCREENS - 5)] = std::to_string(years) + "/YRS";
|
||||
ret[(NUM_SCREENS - 4)] = std::to_string(days) + "/DAYS";
|
||||
ret[(NUM_SCREENS - 3)] = std::to_string(hours) + "/HRS";
|
||||
ret[(NUM_SCREENS - 2)] = std::to_string(mins) + "/MINS";
|
||||
ret[(NUM_SCREENS - 1)] = "TO/GO";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -120,8 +146,9 @@ std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, s
|
|||
if (bigChars)
|
||||
{
|
||||
firstIndex = 1;
|
||||
|
||||
std::string priceString = currencySymbol + formatNumberWithSuffix(marketCap);
|
||||
// Serial.print("Market cap: ");
|
||||
// Serial.println(marketCap);
|
||||
std::string priceString = currencySymbol + formatNumberWithSuffix(marketCap, (NUM_SCREENS-2));
|
||||
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
||||
|
||||
for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "utils.hpp"
|
||||
|
||||
std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char currencySymbol);
|
||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol);
|
||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol);
|
||||
std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight);
|
||||
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight);
|
||||
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks);
|
||||
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars);
|
|
@ -5,18 +5,21 @@ int modulo(int x, int N)
|
|||
return (x % N + N) % N;
|
||||
}
|
||||
|
||||
double getSupplyAtBlock(std::uint32_t blockNr) {
|
||||
if (blockNr >= 33 * 210000) {
|
||||
double getSupplyAtBlock(std::uint32_t blockNr)
|
||||
{
|
||||
if (blockNr >= 33 * 210000)
|
||||
{
|
||||
return 20999999.9769;
|
||||
}
|
||||
}
|
||||
|
||||
const int initialBlockReward = 50; // Initial block reward
|
||||
const int halvingInterval = 210000; // Number of blocks before halving
|
||||
const int halvingInterval = 210000; // Number of blocks before halving
|
||||
|
||||
int halvingCount = blockNr / halvingInterval;
|
||||
double totalBitcoinInCirculation = 0;
|
||||
|
||||
for (int i = 0; i < halvingCount; ++i) {
|
||||
for (int i = 0; i < halvingCount; ++i)
|
||||
{
|
||||
totalBitcoinInCirculation += halvingInterval * initialBlockReward * std::pow(0.5, i);
|
||||
}
|
||||
|
||||
|
@ -25,24 +28,58 @@ double getSupplyAtBlock(std::uint32_t blockNr) {
|
|||
return totalBitcoinInCirculation;
|
||||
}
|
||||
|
||||
std::string formatNumberWithSuffix(std::uint64_t num) {
|
||||
std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters)
|
||||
{
|
||||
static char result[20]; // Adjust size as needed
|
||||
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);
|
||||
double numDouble = (double)num;
|
||||
int numDigits = (int)log10(num) + 1;
|
||||
char suffix;
|
||||
|
||||
if (num >= quadrillion || numDigits > 15)
|
||||
{
|
||||
numDouble /= quadrillion;
|
||||
suffix = 'Q';
|
||||
}
|
||||
}
|
||||
else if (num >= trillion || numDigits > 12)
|
||||
{
|
||||
numDouble /= trillion;
|
||||
suffix = 'T';
|
||||
}
|
||||
else if (num >= billion || numDigits > 9)
|
||||
{
|
||||
numDouble /= billion;
|
||||
suffix = 'B';
|
||||
}
|
||||
else if (num >= million || numDigits > 6)
|
||||
{
|
||||
numDouble /= million;
|
||||
suffix = 'M';
|
||||
}
|
||||
else if (num >= thousand || numDigits > 3)
|
||||
{
|
||||
numDouble /= thousand;
|
||||
suffix = 'K';
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(result, "%llu", (unsigned long long)num);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Add suffix
|
||||
int len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix);
|
||||
|
||||
// If there's room, add decimal places
|
||||
if (len < numCharacters)
|
||||
{
|
||||
snprintf(result, sizeof(result), "%.*f%c", numCharacters - len - 1, numDouble, suffix);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
|
@ -3,9 +3,11 @@
|
|||
#include <string>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
int modulo(int x,int N);
|
||||
|
||||
double getSupplyAtBlock(std::uint32_t blockNr);
|
||||
|
||||
std::string formatNumberWithSuffix(std::uint64_t num);
|
||||
std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters = 4);
|
Loading…
Add table
Add a link
Reference in a new issue