Clock Miner Screen
- Added new screen - Added Blockheigh - Added BTC price - New button function to change screen
This commit is contained in:
parent
e60e935107
commit
fb489035b6
@ -68,7 +68,7 @@ void setup()
|
||||
|
||||
// Button 2 (GPIO14)
|
||||
button2.setPressTicks(5000);
|
||||
// button2.attachClick();
|
||||
button2.attachClick(changeScreen);
|
||||
// button2.attachDoubleClick([]{Serial.println("Button 2 was double clicked");});
|
||||
button2.attachLongPressStart(reset_configurations);
|
||||
// button2.attachLongPressStop(reset_configurations);
|
||||
|
3406
src/media/images.h
3406
src/media/images.h
File diff suppressed because it is too large
Load Diff
@ -320,6 +320,7 @@ void runMonitor(void *name){
|
||||
Serial.println("[MONITOR] started");
|
||||
|
||||
unsigned long mLastCheck = 0;
|
||||
mMonitor.screen = SCREEN_CLOCK;
|
||||
|
||||
while(1){
|
||||
|
||||
@ -332,6 +333,7 @@ void runMonitor(void *name){
|
||||
|
||||
switch(mMonitor.screen){
|
||||
case SCREEN_MINING: show_MinerScreen(mElapsed); break;
|
||||
case SCREEN_CLOCK: show_ClockScreen(mElapsed); break;
|
||||
}
|
||||
|
||||
//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");
|
||||
}
|
||||
|
||||
// Pause the task for 5000ms
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
// Pause the task for 1000ms
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
135
src/monitor.cpp
135
src/monitor.cpp
@ -5,6 +5,7 @@
|
||||
#include "media/images.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include "HTTPClient.h"
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "mining.h"
|
||||
@ -27,6 +28,8 @@ extern monitor_data mMonitor;
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
|
||||
unsigned int bitcoin_price=0;
|
||||
String current_block = "793261";
|
||||
|
||||
void setup_monitor(void){
|
||||
/******** TIME ZONE SETTING *****/
|
||||
@ -40,16 +43,63 @@ void setup_monitor(void){
|
||||
Serial.println("TimeClient setup done");
|
||||
}
|
||||
|
||||
String printLocalTime(){
|
||||
struct tm timeinfo;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
return "00:00";
|
||||
}
|
||||
char LocalHour[80];
|
||||
strftime (LocalHour, 80, "%H:%M", &timeinfo); //4 digit year, 2 digit month
|
||||
String mystring(LocalHour);
|
||||
return LocalHour;
|
||||
unsigned long mHeightUpdate = 0;
|
||||
|
||||
String getBlockHeight(void){
|
||||
|
||||
if((mHeightUpdate == 0) || (millis() - mHeightUpdate > UPDATE_Height_min * 60 * 1000)){
|
||||
|
||||
if (WiFi.status() != WL_CONNECTED) return current_block;
|
||||
|
||||
HTTPClient http;
|
||||
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;
|
||||
@ -59,12 +109,13 @@ unsigned long initialTime = 0;
|
||||
String getTime(void){
|
||||
|
||||
//Check if need an NTP call to check current time
|
||||
if((mTriggerUpdate == 0) || (millis() - mTriggerUpdate > UPDATE_PERIOD_h * 60 * 1000)){
|
||||
if(WiFi.status() != WL_CONNECTED) return "";
|
||||
timeClient.update(); //NTP call to get current time
|
||||
mTriggerUpdate = millis();
|
||||
initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970)
|
||||
Serial.print("TimeClient NTPupdateTime ");
|
||||
if((mTriggerUpdate == 0) || (millis() - mTriggerUpdate > UPDATE_PERIOD_h * 60 * 60 * 1000)){ //60 sec. * 60 min * 1000ms
|
||||
if(WiFi.status() == WL_CONNECTED) {
|
||||
timeClient.update(); //NTP call to get current time
|
||||
mTriggerUpdate = millis();
|
||||
initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970)
|
||||
Serial.print("TimeClient NTPupdateTime ");
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long elapsedTime = (millis() - mTriggerUpdate) / 1000; // Tiempo transcurrido en segundos
|
||||
@ -82,6 +133,10 @@ String getTime(void){
|
||||
return LocalHour;
|
||||
}
|
||||
|
||||
void changeScreen(void){
|
||||
mMonitor.screen++;
|
||||
if(mMonitor.screen> SCREEN_CLOCK) mMonitor.screen = SCREEN_MINING;
|
||||
}
|
||||
void show_MinerScreen(unsigned long mElapsed){
|
||||
|
||||
//Print background screen
|
||||
@ -145,3 +200,51 @@ void show_MinerScreen(unsigned long mElapsed){
|
||||
//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
|
||||
background.pushSprite(0,0);
|
||||
}
|
@ -11,6 +11,14 @@
|
||||
//Time update period
|
||||
#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{
|
||||
uint8_t screen;
|
||||
bool rotation;
|
||||
@ -28,5 +36,7 @@ typedef struct{
|
||||
|
||||
void setup_monitor(void);
|
||||
void show_MinerScreen(unsigned long mElapsed);
|
||||
void show_ClockScreen(unsigned long mElapsed);
|
||||
void changeScreen(void);
|
||||
|
||||
#endif //MONITOR_API_H
|
Loading…
Reference in New Issue
Block a user