forked from btclock/btclock_v3
Improve bitaxe handling code
This commit is contained in:
parent
b8428e1650
commit
b4864b1db6
9 changed files with 183 additions and 45 deletions
|
@ -2,15 +2,15 @@
|
|||
|
||||
TaskHandle_t bitaxeFetchTaskHandle;
|
||||
|
||||
std::string bitaxeHashrate;
|
||||
std::string bitaxeBestDiff;
|
||||
uint64_t bitaxeHashrate;
|
||||
uint64_t bitaxeBestDiff;
|
||||
|
||||
std::string getBitAxeHashRate()
|
||||
uint64_t getBitAxeHashRate()
|
||||
{
|
||||
return bitaxeHashrate;
|
||||
}
|
||||
|
||||
std::string getBitaxeBestDiff()
|
||||
uint64_t getBitaxeBestDiff()
|
||||
{
|
||||
return bitaxeBestDiff;
|
||||
}
|
||||
|
@ -33,8 +33,20 @@ void taskBitaxeFetch(void *pvParameters)
|
|||
String payload = http.getString();
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, payload);
|
||||
bitaxeHashrate = std::to_string(static_cast<int>(std::round(doc["hashRate"].as<float>())));
|
||||
bitaxeBestDiff = doc["bestDiff"].as<std::string>();
|
||||
|
||||
// Convert GH/s to H/s (multiply by 10^9)
|
||||
float hashRateGH = doc["hashRate"].as<float>();
|
||||
bitaxeHashrate = static_cast<uint64_t>(std::round(hashRateGH * std::pow(10, getHashrateMultiplier('G'))));
|
||||
|
||||
// Parse difficulty string and convert to uint64_t
|
||||
std::string diffStr = doc["bestDiff"].as<std::string>();
|
||||
char diffUnit = diffStr[diffStr.length() - 1];
|
||||
if (std::isalpha(diffUnit)) {
|
||||
float diffValue = std::stof(diffStr.substr(0, diffStr.length() - 1));
|
||||
bitaxeBestDiff = static_cast<uint64_t>(std::round(diffValue * std::pow(10, getDifficultyMultiplier(diffUnit))));
|
||||
} else {
|
||||
bitaxeBestDiff = std::stoull(diffStr);
|
||||
}
|
||||
|
||||
if (workQueue != nullptr && (ScreenHandler::getCurrentScreen() == SCREEN_BITAXE_HASHRATE || ScreenHandler::getCurrentScreen() == SCREEN_BITAXE_BESTDIFF))
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <utils.hpp>
|
||||
|
||||
#include "lib/config.hpp"
|
||||
#include "lib/shared.hpp"
|
||||
|
@ -11,5 +12,5 @@ extern TaskHandle_t bitaxeFetchTaskHandle;
|
|||
void setupBitaxeFetchTask();
|
||||
void taskBitaxeFetch(void *pvParameters);
|
||||
|
||||
std::string getBitAxeHashRate();
|
||||
std::string getBitaxeBestDiff();
|
||||
uint64_t getBitAxeHashRate();
|
||||
uint64_t getBitaxeBestDiff();
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
char *wsServer;
|
||||
esp_websocket_client_handle_t blockNotifyClient = NULL;
|
||||
uint currentBlockHeight = 873400;
|
||||
uint blockMedianFee = 1;
|
||||
uint32_t currentBlockHeight = 873400;
|
||||
uint16_t blockMedianFee = 1;
|
||||
bool blockNotifyInit = false;
|
||||
unsigned long int lastBlockUpdate;
|
||||
|
||||
|
@ -179,7 +179,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
|
|||
doc.clear();
|
||||
}
|
||||
|
||||
void processNewBlock(uint newBlockHeight) {
|
||||
void processNewBlock(uint32_t newBlockHeight) {
|
||||
if (newBlockHeight < currentBlockHeight)
|
||||
return;
|
||||
|
||||
|
@ -222,7 +222,7 @@ void processNewBlock(uint newBlockHeight) {
|
|||
}
|
||||
}
|
||||
|
||||
void processNewBlockFee(uint newBlockFee) {
|
||||
void processNewBlockFee(uint16_t newBlockFee) {
|
||||
if (blockMedianFee == newBlockFee)
|
||||
{
|
||||
return;
|
||||
|
@ -238,16 +238,16 @@ void processNewBlockFee(uint newBlockFee) {
|
|||
}
|
||||
}
|
||||
|
||||
uint getBlockHeight() { return currentBlockHeight; }
|
||||
uint32_t getBlockHeight() { return currentBlockHeight; }
|
||||
|
||||
void setBlockHeight(uint newBlockHeight)
|
||||
void setBlockHeight(uint32_t newBlockHeight)
|
||||
{
|
||||
currentBlockHeight = newBlockHeight;
|
||||
}
|
||||
|
||||
uint getBlockMedianFee() { return blockMedianFee; }
|
||||
uint16_t getBlockMedianFee() { return blockMedianFee; }
|
||||
|
||||
void setBlockMedianFee(uint newBlockMedianFee)
|
||||
void setBlockMedianFee(uint16_t newBlockMedianFee)
|
||||
{
|
||||
blockMedianFee = newBlockMedianFee;
|
||||
}
|
||||
|
|
|
@ -22,20 +22,20 @@ void onWebsocketBlockEvent(void *handler_args, esp_event_base_t base,
|
|||
int32_t event_id, void *event_data);
|
||||
void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data);
|
||||
|
||||
void setBlockHeight(uint newBlockHeight);
|
||||
uint getBlockHeight();
|
||||
void setBlockHeight(uint32_t newBlockHeight);
|
||||
uint32_t getBlockHeight();
|
||||
|
||||
void setBlockMedianFee(uint blockMedianFee);
|
||||
uint getBlockMedianFee();
|
||||
void setBlockMedianFee(uint16_t blockMedianFee);
|
||||
uint16_t getBlockMedianFee();
|
||||
|
||||
bool isBlockNotifyConnected();
|
||||
void stopBlockNotify();
|
||||
void restartBlockNotify();
|
||||
|
||||
void processNewBlock(uint newBlockHeight);
|
||||
void processNewBlockFee(uint newBlockFee);
|
||||
void processNewBlock(uint32_t newBlockHeight);
|
||||
void processNewBlockFee(uint16_t newBlockFee);
|
||||
|
||||
bool getBlockNotifyInit();
|
||||
uint getLastBlockUpdate();
|
||||
uint32_t getLastBlockUpdate();
|
||||
int getBlockFetch();
|
||||
void setLastBlockUpdate(uint lastUpdate);
|
||||
void setLastBlockUpdate(uint32_t lastUpdate);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue