Rebase with last boards incorporations

dev rebase with last changes
This commit is contained in:
BitMaker 2023-09-12 12:57:30 +02:00 committed by GitHub
commit 44535f8a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 3294 additions and 7 deletions

View File

@ -161,6 +161,44 @@ lib_deps =
mathertel/OneButton @ ^2.0.3
arduino-libraries/NTPClient
[env:ESP32-2432S028R]
platform = espressif32
board = esp32dev
monitor_speed = 115200
upload_speed = 921600
;build_type = debug
board_build.partitions = huge_app.csv
build_flags =
-D ESP32_2432S028R=1
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DUSER_SETUP_LOADED=1
-DILI9341_2_DRIVER=1
-DTFT_WIDTH=240
-DTFT_HEIGHT=320
-DTFT_BACKLIGHT_ON=HIGH
-DTFT_MOSI=13
-DTFT_SCLK=14
-DTFT_CS=15
-DTFT_DC=2
-DTFT_RST=12
-DTFT_BL=21
-DTOUCH_CS=33
-DLOAD_GLCD=1
-DLOAD_FONT2=1
-DLOAD_GFXFF=1
-DSMOOTH_FONT=1
-DSPI_FREQUENCY=55000000
-DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000
lib_deps =
https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2
https://github.com/tzapu/WiFiManager.git
mathertel/OneButton @ ^2.0.3
arduino-libraries/NTPClient
bodmer/TFT_eSPI @ ^2.5.31
[env:NerdminerV2-T-Display_V1]
platform = espressif32
board = ttgo-lora32-v1
@ -181,3 +219,4 @@ lib_deps =
https://github.com/tzapu/WiFiManager.git
mathertel/OneButton @ ^2.0.3
https://github.com/arduino-libraries/NTPClient

View File

@ -0,0 +1,10 @@
#ifndef _ESP32_2432S028R
#define _ESP32_2432S028R
#define PIN_BUTTON_1 0
//#define PIN_BUTTON_2 22 // Not used
#define PIN_ENABLE5V 21 // Not used
#define LED_PIN 4 // Red pin
#define LED_PIN_G 17 // Green pin
#endif

View File

@ -16,6 +16,10 @@ DisplayDriver *currentDisplayDriver = &amoledDisplayDriver;
DisplayDriver *currentDisplayDriver = &dongleDisplayDriver;
#endif
#ifdef ESP32_2432S028R
DisplayDriver *currentDisplayDriver = &esp32_2432S028RDriver;
#endif
#ifdef T_QT_DISPLAY
DisplayDriver *currentDisplayDriver = &t_qtDisplayDriver;
#endif
@ -24,6 +28,7 @@ DisplayDriver *currentDisplayDriver = &t_qtDisplayDriver;
DisplayDriver *currentDisplayDriver = &tDisplayV1Driver;
#endif
// Initialize the display
void initDisplay()
{

View File

@ -0,0 +1,352 @@
#include "../drivers.h"
#ifdef ESP32_2432S028R
#include <TFT_eSPI.h>
#include "media/images_320_170.h"
#include "media/images_bottom_320_70.h"
#include "media/myFonts.h"
#include "media/Free_Fonts.h"
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#define WIDTH 340
#define HEIGHT 240
OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
extern monitor_data mMonitor;
extern pool_data pData;
void esp32_2432S028R_Init(void)
{
tft.init();
tft.setRotation(1);
tft.setSwapBytes(true); // Swap the colour byte order when rendering
//background.createSprite(WIDTH, HEIGHT); // Background Sprite
background.setSwapBytes(true);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(0.9); // Espaciado entre texto
// Load the font and check it can be read OK
// if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) {
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers)))
{
Serial.println("Initialise error");
return;
}
pinMode(LED_PIN, OUTPUT);
pData.bestDifficulty = "0";
pData.workersHash = "0";
pData.workersCount = 0;
}
void esp32_2432S028R_AlternateScreenState(void)
{
int screen_state = digitalRead(TFT_BL);
Serial.println("Switching display state");
digitalWrite(TFT_BL, !screen_state);
}
void esp32_2432S028R_AlternateRotation(void)
{
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
}
void printPoolData(){
pData = updatePoolData();
background.createSprite(320,70); //Background Sprite
background.setSwapBytes(true);
background.pushImage(0, 0, 320, 70, bottonPoolScreen);
//background.setTextDatum(MC_DATUM);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(1);
render.setFontSize(24);
render.cdrawString(String(pData.workersCount).c_str(), 160, 35, TFT_BLACK);
render.setFontSize(18);
render.setAlignment(Align::BottomRight);
render.drawString(pData.workersHash.c_str(), 293, 51, TFT_BLACK);
render.setAlignment(Align::TopLeft);
render.cdrawString(pData.bestDifficulty.c_str(), 50, 34, TFT_BLACK);
background.pushSprite(0,170);
background.deleteSprite();
}
void esp32_2432S028R_MinerScreen(unsigned long mElapsed)
{
mining_data data = getMiningData(mElapsed);
// Create background sprite to print data at once
background.createSprite(initWidth,initHeight); //Background Sprite
background.setColorDepth(16);
background.setSwapBytes(true);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(0.9);
//Print background screen
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
// Hashrate
render.setFontSize(35);
render.setCursor(19, 118);
render.setFontColor(TFT_BLACK);
render.rdrawString(data.currentHashRate.c_str(), 118, 114, TFT_BLACK);
// Total hashes
render.setFontSize(18);
render.rdrawString(data.totalMHashes.c_str(), 268, 138, TFT_BLACK);
// Block templates
render.setFontSize(18);
render.drawString(data.templates.c_str(), 186, 20, 0xDEDB);
// Best diff
render.drawString(data.bestDiff.c_str(), 186, 48, 0xDEDB);
// 32Bit shares
render.setFontSize(18);
render.drawString(data.completedShares.c_str(), 186, 76, 0xDEDB);
// Hores
render.setFontSize(14);
render.rdrawString(data.timeMining.c_str(), 315, 104, 0xDEDB);
// Valid Blocks
render.setFontSize(24);
render.drawString(data.valids.c_str(), 285, 56, 0xDEDB);
// Print Temp
render.setFontSize(10);
render.rdrawString(data.temp.c_str(), 239, 1, TFT_BLACK);
render.setFontSize(4);
render.rdrawString(String(0).c_str(), 244, 3, TFT_BLACK);
// Print Hour
render.setFontSize(10);
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
// Push prepared background to screen
background.pushSprite(0, 0);
// Delete sprite to free the memory heap
background.deleteSprite();
#ifdef ESP32_2432S028R
printPoolData();
#endif
#ifdef DEBUG_MEMORY
// Print heap
printheap();
#endif
}
void esp32_2432S028R_ClockScreen(unsigned long mElapsed)
{
clock_data data = getClockData(mElapsed);
// Create background sprite to print data at once
background.createSprite(initWidth,initHeight); //Background Sprite
background.setColorDepth(16);
background.setSwapBytes(true);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(0.9);
// Print background screen
background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen);
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
// Hashrate
render.setFontSize(25);
render.setCursor(19, 122);
render.setFontColor(TFT_BLACK);
render.rdrawString(data.currentHashRate.c_str(), 94, 129, TFT_BLACK);
// Print BTC Price
background.setFreeFont(FSSB9);
background.setTextSize(1);
background.setTextDatum(TL_DATUM);
background.setTextColor(TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 202, 3, GFXFF);
// Print BlockHeight
render.setFontSize(18);
render.rdrawString(data.blockHeight.c_str(), 254, 140, TFT_BLACK);
// Print Hour
background.setFreeFont(FF23);
background.setTextSize(2);
background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
// Push prepared background to screen
background.pushSprite(0, 0);
// Delete sprite to free the memory heap
background.deleteSprite();
#ifdef ESP32_2432S028R
printPoolData();
#endif
#ifdef DEBUG_MEMORY
// Print heap
printheap();
#endif
}
void esp32_2432S028R_GlobalHashScreen(unsigned long mElapsed)
{
coin_data data = getCoinData(mElapsed);
// Create background sprite to print data at once
background.createSprite(initWidth,initHeight); //Background Sprite
background.setColorDepth(16);
background.setSwapBytes(true);
render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
render.setLineSpaceRatio(0.9);
// Print background screen
background.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen);
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
// Print BTC Price
background.setFreeFont(FSSB9);
background.setTextSize(1);
background.setTextDatum(TL_DATUM);
background.setTextColor(TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 198, 3, GFXFF);
// Print Hour
background.setFreeFont(FSSB9);
background.setTextSize(1);
background.setTextDatum(TL_DATUM);
background.setTextColor(TFT_BLACK);
background.drawString(data.currentTime.c_str(), 268, 3, GFXFF);
// Print Last Pool Block
background.setFreeFont(FSS9);
background.setTextDatum(TR_DATUM);
background.setTextColor(0x9C92);
background.drawString(data.halfHourFee.c_str(), 302, 52, GFXFF);
// Print Difficulty
background.setFreeFont(FSS9);
background.setTextDatum(TR_DATUM);
background.setTextColor(0x9C92);
background.drawString(data.netwrokDifficulty.c_str(), 302, 88, GFXFF);
// Print Global Hashrate
render.setFontSize(17);
render.rdrawString(data.globalHashRate.c_str(), 274, 145, TFT_BLACK);
// Print BlockHeight
render.setFontSize(28);
render.rdrawString(data.blockHeight.c_str(), 140, 104, 0xDEDB);
// Draw percentage rectangle
int x2 = 2 + (138 * data.progressPercent / 100);
background.fillRect(2, 149, x2, 168, 0xDEDB);
// Print Remaining BLocks
background.setTextFont(FONT2);
background.setTextSize(1);
background.setTextDatum(MC_DATUM);
background.setTextColor(TFT_BLACK);
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
// Push prepared background to screen
background.pushSprite(0, 0);
// Delete sprite to free the memory heap
background.deleteSprite();
#ifdef ESP32_2432S028R
printPoolData();
#endif
#ifdef DEBUG_MEMORY
// Print heap
printheap();
#endif
}
void esp32_2432S028R_LoadingScreen(void)
{
tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 33, initWidth, initHeight, initScreen);
tft.setTextColor(TFT_BLACK);
tft.drawString(CURRENT_VERSION, 24, 147, FONT2);
delay(2000);
tft.fillScreen(TFT_BLACK);
}
void esp32_2432S028R_SetupScreen(void)
{
tft.pushImage(0, 33, setupModeWidth, setupModeHeight, setupModeScreen);
}
void esp32_2432S028R_AnimateCurrentScreen(unsigned long frame)
{
}
// Variables para controlar el parpadeo con millis()
unsigned long previousMillis = 0;
void esp32_2432S028R_DoLedStuff(unsigned long frame)
{
unsigned long currentMillis = millis();
switch (mMonitor.NerdStatus)
{
case NM_waitingConfig:
digitalWrite(LED_PIN, HIGH); // LED encendido de forma continua
break;
case NM_Connecting:
if (currentMillis - previousMillis >= 500)
{ // 0.5sec blink
previousMillis = currentMillis;
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED
}
break;
case NM_hashing:
if (currentMillis - previousMillis >= 100)
{ // 0.1sec blink
previousMillis = currentMillis;
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED
}
break;
}
}
CyclicScreenFunction esp32_2432S028RCyclicScreens[] = {esp32_2432S028R_MinerScreen, esp32_2432S028R_ClockScreen, esp32_2432S028R_GlobalHashScreen};
DisplayDriver esp32_2432S028RDriver = {
esp32_2432S028R_Init,
esp32_2432S028R_AlternateScreenState,
esp32_2432S028R_AlternateRotation,
esp32_2432S028R_LoadingScreen,
esp32_2432S028R_SetupScreen,
esp32_2432S028RCyclicScreens,
esp32_2432S028R_AnimateCurrentScreen,
esp32_2432S028R_DoLedStuff,
SCREENS_ARRAY_SIZE(esp32_2432S028RCyclicScreens),
0,
WIDTH,
HEIGHT};
#endif

View File

@ -11,10 +11,13 @@
#include "devices/lilygoS3Amoled.h"
#elif defined(NERMINER_S3_DONGLE)
#include "devices/lilygoS3Dongle.h"
#elif defined(ESP32_2432S028R)
#include "devices/esp322432s028r.h"
#elif defined(NERMINER_T_QT)
#include "devices/lilygoT_QT.h"
#elif defined(NERDMINER_T_DISPLAY_V1)
#include "devices/lilygoV1TDisplay.h"
#else
#error "No device defined"
#endif
@ -48,6 +51,7 @@ extern DisplayDriver noDisplayDriver;
extern DisplayDriver tDisplayDriver;
extern DisplayDriver amoledDisplayDriver;
extern DisplayDriver dongleDisplayDriver;
extern DisplayDriver esp32_2432S028RDriver;
extern DisplayDriver t_qtDisplayDriver;
extern DisplayDriver tDisplayV1Driver;

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
unsigned int bitcoin_price=0;
String current_block = "793261";
global_data gData;
pool_data pData;
void setup_monitor(void){
/******** TIME ZONE SETTING *****/
@ -53,6 +54,7 @@ void updateGlobalData(void){
//Make first API call to get global hash and current difficulty
HTTPClient http;
try {
http.begin(getGlobalHash);
int httpCode = http.GET();
@ -95,7 +97,9 @@ void updateGlobalData(void){
}
http.end();
} catch(...) {
http.end();
}
}
}
@ -108,6 +112,7 @@ String getBlockHeight(void){
if (WiFi.status() != WL_CONNECTED) return current_block;
HTTPClient http;
try {
http.begin(getHeightAPI);
int httpCode = http.GET();
@ -119,9 +124,10 @@ String getBlockHeight(void){
mHeightUpdate = millis();
}
http.end();
} catch(...) {
http.end();
}
}
return current_block;
@ -136,6 +142,7 @@ String getBTCprice(void){
if (WiFi.status() != WL_CONNECTED) return (String(bitcoin_price) + "$");
HTTPClient http;
try {
http.begin(getBTCAPI);
int httpCode = http.GET();
@ -152,7 +159,9 @@ String getBTCprice(void){
}
http.end();
} catch(...) {
http.end();
}
}
return (String(bitcoin_price) + "$");
@ -161,6 +170,8 @@ String getBTCprice(void){
unsigned long mTriggerUpdate = 0;
unsigned long initialMillis = millis();
unsigned long initialTime = 0;
unsigned long mPoolUpdate = 0;
extern char btcString[80];
void getTime(unsigned long* currentHours, unsigned long* currentMinutes, unsigned long* currentSeconds){
@ -275,3 +286,45 @@ coin_data getCoinData(unsigned long mElapsed)
return data;
}
pool_data updatePoolData(void){
//pool_data pData;
if((mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){
if (WiFi.status() != WL_CONNECTED) return pData;
//Make first API call to get global hash and current difficulty
HTTPClient http;
http.setReuse(true);
try {
http.begin(String(getPublicPool)+btcString);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
// Serial.println(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
if (doc.containsKey("workersCount")) pData.workersCount = doc["workersCount"].as<int>();
const JsonArray& workers = doc["workers"].as<JsonArray>();
float totalhashs = 0;
for (const JsonObject& worker : workers) {
totalhashs += worker["hashRate"].as<float>();
}
pData.workersHash = String(totalhashs/1000);
String temp = "";
if (doc.containsKey("bestDifficulty")) {
temp = doc["bestDifficulty"].as<float>();
pData.bestDifficulty = String(temp);
}
doc.clear();
mPoolUpdate = millis();
}
http.end();
} catch(...) {
http.end();
}
}
return pData;
}

View File

@ -26,6 +26,11 @@
#define getFees "https://mempool.space/api/v1/fees/recommended"
#define UPDATE_Global_min 2
//API public-pool.io
// https://public-pool.io:40557/api/client/btcString
#define getPublicPool "https://public-pool.io:40557/api/client/" // +btcString
#define UPDATE_POOL_min 1
#define NEXT_HALVING_EVENT 840000
#define HALVING_BLOCKS 210000
@ -95,11 +100,20 @@ typedef struct {
String remainingBlocks;
}coin_data;
typedef struct{
int workersCount; // Workers count, how many nerdminers using your address
String workersHash; // Workers Total Hash Rate
String bestDifficulty; // Your miners best difficulty
}pool_data;
void setup_monitor(void);
mining_data getMiningData(unsigned long mElapsed);
clock_data getClockData(unsigned long mElapsed);
coin_data getCoinData(unsigned long mElapsed);
pool_data updatePoolData(void);
clock_data_t getClockData_t(unsigned long mElapsed);
#endif //MONITOR_API_H