Clock Miner Screen

- Added new screen
- Added Blockheigh
- Added BTC price
- New button function to change screen
This commit is contained in:
BitMaker 2023-06-07 17:07:30 +02:00
parent e60e935107
commit fb489035b6
5 changed files with 3540 additions and 19 deletions

View File

@ -68,7 +68,7 @@ void setup()
// Button 2 (GPIO14) // Button 2 (GPIO14)
button2.setPressTicks(5000); button2.setPressTicks(5000);
// button2.attachClick(); button2.attachClick(changeScreen);
// button2.attachDoubleClick([]{Serial.println("Button 2 was double clicked");}); // button2.attachDoubleClick([]{Serial.println("Button 2 was double clicked");});
button2.attachLongPressStart(reset_configurations); button2.attachLongPressStart(reset_configurations);
// button2.attachLongPressStop(reset_configurations); // button2.attachLongPressStop(reset_configurations);

File diff suppressed because it is too large Load Diff

View File

@ -320,6 +320,7 @@ void runMonitor(void *name){
Serial.println("[MONITOR] started"); Serial.println("[MONITOR] started");
unsigned long mLastCheck = 0; unsigned long mLastCheck = 0;
mMonitor.screen = SCREEN_CLOCK;
while(1){ while(1){
@ -332,6 +333,7 @@ void runMonitor(void *name){
switch(mMonitor.screen){ switch(mMonitor.screen){
case SCREEN_MINING: show_MinerScreen(mElapsed); break; case SCREEN_MINING: show_MinerScreen(mElapsed); break;
case SCREEN_CLOCK: show_ClockScreen(mElapsed); break;
} }
//Monitor state when hashrate is 0.0 //Monitor state when hashrate is 0.0
@ -341,8 +343,8 @@ void runMonitor(void *name){
client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false");
} }
// Pause the task for 5000ms // Pause the task for 1000ms
vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
} }
} }

View File

@ -5,6 +5,7 @@
#include "media/images.h" #include "media/images.h"
#include "mbedtls/md.h" #include "mbedtls/md.h"
#include "OpenFontRender.h" #include "OpenFontRender.h"
#include "HTTPClient.h"
#include <NTPClient.h> #include <NTPClient.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include "mining.h" #include "mining.h"
@ -27,6 +28,8 @@ extern monitor_data mMonitor;
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
unsigned int bitcoin_price=0;
String current_block = "793261";
void setup_monitor(void){ void setup_monitor(void){
/******** TIME ZONE SETTING *****/ /******** TIME ZONE SETTING *****/
@ -40,16 +43,63 @@ void setup_monitor(void){
Serial.println("TimeClient setup done"); Serial.println("TimeClient setup done");
} }
String printLocalTime(){ unsigned long mHeightUpdate = 0;
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){ String getBlockHeight(void){
Serial.println("Failed to obtain time");
return "00:00"; if((mHeightUpdate == 0) || (millis() - mHeightUpdate > UPDATE_Height_min * 60 * 1000)){
}
char LocalHour[80]; if (WiFi.status() != WL_CONNECTED) return current_block;
strftime (LocalHour, 80, "%H:%M", &timeinfo); //4 digit year, 2 digit month
String mystring(LocalHour); HTTPClient http;
return LocalHour; http.begin(getHeightAPI);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
payload.trim();
current_block = payload;
mHeightUpdate = millis();
}
http.end();
}
return current_block;
}
unsigned long mBTCUpdate = 0;
String getBTCprice(void){
if((mBTCUpdate == 0) || (millis() - mBTCUpdate > UPDATE_BTC_min * 60 * 1000)){
if (WiFi.status() != WL_CONNECTED) return (String(bitcoin_price) + "$");
HTTPClient http;
http.begin(getBTCAPI);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
if (doc.containsKey("bitcoin")) bitcoin_price = doc["bitcoin"]["usd"];
doc.clear();
mBTCUpdate = millis();
}
http.end();
}
return (String(bitcoin_price) + "$");
} }
unsigned long mTriggerUpdate = 0; unsigned long mTriggerUpdate = 0;
@ -59,12 +109,13 @@ unsigned long initialTime = 0;
String getTime(void){ String getTime(void){
//Check if need an NTP call to check current time //Check if need an NTP call to check current time
if((mTriggerUpdate == 0) || (millis() - mTriggerUpdate > UPDATE_PERIOD_h * 60 * 1000)){ if((mTriggerUpdate == 0) || (millis() - mTriggerUpdate > UPDATE_PERIOD_h * 60 * 60 * 1000)){ //60 sec. * 60 min * 1000ms
if(WiFi.status() != WL_CONNECTED) return ""; if(WiFi.status() == WL_CONNECTED) {
timeClient.update(); //NTP call to get current time timeClient.update(); //NTP call to get current time
mTriggerUpdate = millis(); mTriggerUpdate = millis();
initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970) initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970)
Serial.print("TimeClient NTPupdateTime "); Serial.print("TimeClient NTPupdateTime ");
}
} }
unsigned long elapsedTime = (millis() - mTriggerUpdate) / 1000; // Tiempo transcurrido en segundos unsigned long elapsedTime = (millis() - mTriggerUpdate) / 1000; // Tiempo transcurrido en segundos
@ -82,6 +133,10 @@ String getTime(void){
return LocalHour; return LocalHour;
} }
void changeScreen(void){
mMonitor.screen++;
if(mMonitor.screen> SCREEN_CLOCK) mMonitor.screen = SCREEN_MINING;
}
void show_MinerScreen(unsigned long mElapsed){ void show_MinerScreen(unsigned long mElapsed){
//Print background screen //Print background screen
@ -142,6 +197,54 @@ void show_MinerScreen(unsigned long mElapsed){
render.setFontSize(20); render.setFontSize(20);
render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK); render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK);
//Push prepared background to screen
background.pushSprite(0,0);
}
void show_ClockScreen(unsigned long mElapsed){
//Print background screen
background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen);
char CurrentHashrate[10] = {0};
sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed);
//Serial.println("[runMonitor Task] -> Printing results on screen ");
Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n",
shares, totalKHashes, CurrentHashrate);
//Hashrate
render.setFontSize(50);
render.setCursor(19, 122);
render.setFontColor(TFT_BLACK);
render.rdrawString(CurrentHashrate, 94, 129, TFT_BLACK);
//Print BTC Price
//render.setFontSize(22);
//render.drawString(getBTCprice().c_str(), 202, 3, TFT_BLACK);
background.setFreeFont(FSSB9);
background.setTextSize(1);
background.setTextColor(TFT_BLACK);
background.drawString(getBTCprice().c_str(), 202, 3, GFXFF);
//Print BlockHeight
render.setFontSize(36);
render.rdrawString(getBlockHeight().c_str(), 254, 140, TFT_BLACK);
//Print Hour
background.setFreeFont(FF23);
background.setTextSize(2);
background.setTextColor(0xDEDB, TFT_BLACK);
//background.setTexSize(2);
background.drawString(getTime().c_str(), 130, 50, GFXFF);
//render.setFontColor(TFT_WHITE);
//render.setFontSize(110);
//render.rdrawString(getTime().c_str(), 290, 40, TFT_WHITE);
//Push prepared background to screen //Push prepared background to screen
background.pushSprite(0,0); background.pushSprite(0,0);
} }

View File

@ -11,6 +11,14 @@
//Time update period //Time update period
#define UPDATE_PERIOD_h 5 #define UPDATE_PERIOD_h 5
//API BTC price
#define getBTCAPI "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
#define UPDATE_BTC_min 5
//API BTC price
#define getHeightAPI "https://mempool.space/api/blocks/tip/height"
#define UPDATE_Height_min 5
typedef struct{ typedef struct{
uint8_t screen; uint8_t screen;
bool rotation; bool rotation;
@ -28,5 +36,7 @@ typedef struct{
void setup_monitor(void); void setup_monitor(void);
void show_MinerScreen(unsigned long mElapsed); void show_MinerScreen(unsigned long mElapsed);
void show_ClockScreen(unsigned long mElapsed);
void changeScreen(void);
#endif //MONITOR_API_H #endif //MONITOR_API_H