t-hmi first working: add touch, sdcard, remove vkbit

This commit is contained in:
cosmicpsyop 2024-05-28 14:29:00 -07:00
parent 3a50f87c31
commit c73a1fe19a
7 changed files with 218 additions and 19 deletions

View File

@ -61,6 +61,7 @@ Every time an stratum job notification is received miner update its current work
- ESP32-C3 Devkit ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/esp32-c3-devkitm-1.html)) - ESP32-C3 Devkit ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/esp32-c3-devkitm-1.html))
- ESP32-C3 Super Mini ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/seeed_xiao_esp32c3.html)) - ESP32-C3 Super Mini ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/seeed_xiao_esp32c3.html))
- Waveshare ESP32-S3-GEEK ([Board Info](https://www.waveshare.com/wiki/ESP32-S3-GEEK)) - Waveshare ESP32-S3-GEEK ([Board Info](https://www.waveshare.com/wiki/ESP32-S3-GEEK))
- LILYGO T-HMI ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oFII4s2)) / Dev support: @cosmicpsyop
\*Affiliate links \*Affiliate links

View File

@ -751,10 +751,11 @@ build_flags =
board_build.arduino.memory_type = qio_opi board_build.arduino.memory_type = qio_opi
lib_deps = lib_deps =
https://github.com/liangyingy/arduino_xpt2046_library
https://github.com/takkaO/OpenFontRender https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2 bblanchon/ArduinoJson@^6.21.2
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
mathertel/OneButton @ ^2.0.3 mathertel/OneButton @ ^2.5.0
arduino-libraries/NTPClient arduino-libraries/NTPClient
bodmer/TFT_eSPI @ ^2.5.31 bodmer/TFT_eSPI @ ^2.5.31
https://github.com/achillhasler/TFT_eTouch https://github.com/achillhasler/TFT_eTouch

View File

@ -97,6 +97,10 @@ void setup()
mMonitor.NerdStatus = NM_waitingConfig; mMonitor.NerdStatus = NM_waitingConfig;
doLedStuff(0); doLedStuff(0);
#ifdef NERDMINER_T_HMI
extern void t_hmiCheckForSDCardAndMoveToNVM(void);
t_hmiCheckForSDCardAndMoveToNVM();
#endif
/******** INIT WIFI ************/ /******** INIT WIFI ************/
init_WifiManager(); init_WifiManager();
@ -142,6 +146,9 @@ void app_error_fault_handler(void *arg) {
// restart ESP32 // restart ESP32
esp_restart(); esp_restart();
} }
#ifdef NERDMINER_T_HMI
extern uint16_t t_hmiCheckForTouch();
#endif
void loop() { void loop() {
// keep watching the push buttons: // keep watching the push buttons:
@ -153,6 +160,9 @@ void loop() {
button2.tick(); button2.tick();
#endif #endif
#ifdef NERDMINER_T_HMI
t_hmiCheckForTouch();
#endif
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
vTaskDelay(50 / portTICK_PERIOD_MS); vTaskDelay(50 / portTICK_PERIOD_MS);

View File

@ -4,6 +4,7 @@
#define T_HMI_DISPLAY #define T_HMI_DISPLAY
#define PWR_EN_PIN (10) #define PWR_EN_PIN (10)
#define PIN_ENABLE5V PWR_EN_PIN
#define PWR_ON_PIN (14) #define PWR_ON_PIN (14)
#define BAT_ADC_PIN (5) #define BAT_ADC_PIN (5)
#define BUTTON1_PIN (0) #define BUTTON1_PIN (0)
@ -29,11 +30,9 @@
// sd card // sd card
// 1-bit SD MMC // 1-bit SD MMC
#ifdef DEFINE_SDMMC_1BIT
#define SDMMC_CLK (12) #define SDMMC_CLK (12)
#define SDMMC_CMD (11) #define SDMMC_CMD (11)
#define SDMMC_D0 (13) #define SDMMC_D0 (13)
#endif
#ifndef TFT_BL #ifndef TFT_BL
// XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37 // XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37

View File

@ -1,7 +1,8 @@
#include "displayDriver.h" #include "displayDriver.h"
#ifdef T_HMI_DISPLAY #ifdef T_HMI_DISPLAY
#include <FS.h>
#include <xpt2046.h> // https://github.com/liangyingy/arduino_xpt2046_library
#include <TFT_eSPI.h> #include <TFT_eSPI.h>
#include <TFT_eTouch.h> #include <TFT_eTouch.h>
#include "media/images_320_170.h" #include "media/images_320_170.h"
@ -22,15 +23,159 @@ OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
#define TOUCH_ENABLE
SPIClass hSPI(HSPI); //SPIClass hSPI(HSPI);
// TFT_eTouch<TFT_eSPI> touch(tft, ETOUCH_CS, 0xFF, hSPI); // TFT_eTouch<TFT_eSPI> touch(tft, ETOUCH_CS, 0xFF, hSPI);
#ifdef TOUCH_ENABLE
XPT2046 touch = XPT2046(SPI, ETOUCH_CS, TOUCH_IRQ);
#endif
bool showbtcprice = false; bool showbtcprice = false;
extern monitor_data mMonitor; extern monitor_data mMonitor;
extern pool_data pData; extern pool_data pData;
extern DisplayDriver *currentDisplayDriver; extern DisplayDriver *currentDisplayDriver;
/*=============================================*/
#include <FS.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include "drivers/storage/nvMemory.h"
#include "drivers/storage/SDCard.h"
extern nvMemory nvMem;
extern TSettings Settings;
void t_hmiCheckForSDCardAndMoveToNVM(void)
{
// workaround removing use of class SDCard
// SCard SDCrd = SDCard() blows up in SDCard::initSDcard()
// Need to lower frequency to 20000
SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
delay(500);
bool rlst = SD_MMC.begin("/sd", true, false, 20000);
if (!rlst)
{
Serial.println("SD init failed");
Serial.println("➸ No detected SdCard");
}
else
{
Serial.println("SD init success");
Serial.printf("➸ Detected SdCard insert: %.2f GB\r\n", SD_MMC.cardSize() / 1024.0 / 1024.0 / 1024.0);
// SDCrd.SD2nvMemory(&nvMem, &Settings);
if (SD_MMC.exists(JSON_CONFIG_FILE))
{
// The file exists, reading and loading
File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r");
if (configFile)
{
StaticJsonDocument<512> json;
DeserializationError error = deserializeJson(json, configFile);
configFile.close();
Serial.println("SDCard: Loading config file");
if (!error)
{
serializeJsonPretty(json, Serial);
Serial.print('\n');
TSettings *pSettings = &Settings;
pSettings->WifiSSID = json[JSON_KEY_SSID] | pSettings->WifiSSID;
pSettings->WifiPW = json[JSON_KEY_PASW] | pSettings->WifiPW;
pSettings->PoolAddress = json[JSON_KEY_POOLURL] | pSettings->PoolAddress;
strcpy(pSettings->PoolPassword, json[JSON_KEY_POOLPASS] | pSettings->PoolPassword);
strcpy(pSettings->BtcWallet, json[JSON_KEY_WALLETID] | pSettings->BtcWallet);
if (json.containsKey(JSON_KEY_POOLPORT))
pSettings->PoolPort = json[JSON_KEY_POOLPORT].as<int>();
if (json.containsKey(JSON_KEY_TIMEZONE))
pSettings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_KEY_STATS2NV))
pSettings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
nvMem.saveConfig(pSettings);
WiFi.begin(pSettings->WifiSSID, pSettings->WifiPW);
Serial.println("SDCard: Settings transfered to internal memory. Restarting now.");
ESP.restart();
}
else
{
// Error loading JSON data
Serial.println("SDCard: Error parsing config file!");
}
}
else
{
Serial.println("SDCard: Error opening config file!");
}
}
else
{
Serial.println("SDCard: No config file available!");
}
// delay(15000);
SD_MMC.end();
Serial.println("SD close");
}
}
/*=============================================*/
unsigned int lower_switch = 1;
#ifdef TOUCH_ENABLE
extern void switchToNextScreen(void);
unsigned long now = 0;
unsigned long currentTime;
bool debounce() {
if (now) now = millis();
unsigned long currentTime = millis();
if (currentTime - now >= 2000) {
now = 0;
return true;
}
return false;
};
uint16_t t_hmiCheckForTouch()
{
uint16_t touch_x, touch_y, code = 0;
if (touch.pressed()) {
touch_x = touch.RawX();
touch_y = touch.RawY();
// do something with the touch coordinates
/*
Serial.print("Touch coordinates: ");
Serial.print(touch_x);
Serial.print(", ");
Serial.println(touch_y);
*/
// Perform actions based on touch coordinates
/*
if (y < y_min + (y_max - y_min) / 2) {
*/
if (touch_x < 200 + (1700 - 200) / 4) {
// bottom
code = 1;
if (debounce())
lower_switch = 3 - lower_switch;;
} else {
// top
code = 2;
if (debounce())
switchToNextScreen();
}
}
if (code) {
if (code == 1)
Serial.print("Touch bottom\n");
else
Serial.print("Touch top\n");
}
return(code);
}
#endif
uint32_t readAdcVoltage(int pin) { uint32_t readAdcVoltage(int pin) {
esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_characteristics_t adc_chars;
@ -70,12 +215,32 @@ void t_hmiDisplay_Init(void)
Serial.println("Initialise error"); Serial.println("Initialise error");
return; return;
} }
/* XXX - Pass for first version
Serial.println(F("Initialize the touch screen")); Serial.println(F("Initialize the touch screen"));
hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS); #ifdef TOUCH_ENABLE
TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 }; // different approach
touch.setCalibration(calibation); //hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
*/ //TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
//touch.setCalibration(calibation);
// Check if the screen is touched and get the coordinates
/*
if (touch.touched()) {
TS_Point p = touch.getPoint();
Serial.print("Pressure = ");
Serial.print(p.z);
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.print(p.y);
delay(30);
Serial.println();
}
*/
SPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI);
touch.begin(240, 320);
#endif
Serial.println(F("Turn on the LCD backlight")); Serial.println(F("Turn on the LCD backlight"));
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
pinMode(BK_LIGHT_PIN, OUTPUT); pinMode(BK_LIGHT_PIN, OUTPUT);
@ -83,6 +248,7 @@ void t_hmiDisplay_Init(void)
pData.bestDifficulty = "0"; pData.bestDifficulty = "0";
pData.workersHash = "0"; pData.workersHash = "0";
pData.workersCount = 0; pData.workersCount = 0;
lower_switch = 1;
} }
@ -188,7 +354,11 @@ void t_hmiDisplay_MinerScreen(unsigned long mElapsed)
render.setFontSize(10); render.setFontSize(10);
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK); render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
if (lower_switch == 1)
printPoolData(); printPoolData();
else
printMemPoolFees(mElapsed);
// Push prepared background to screen // Push prepared background to screen
background.pushSprite(0, 0); background.pushSprite(0, 0);
} }
@ -226,7 +396,10 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed)
background.setTextColor(0xDEDB, TFT_BLACK); background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF); background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
if (lower_switch == 1)
printMemPoolFees(mElapsed); printMemPoolFees(mElapsed);
else
printPoolData();
// Push prepared background to screen // Push prepared background to screen
background.pushSprite(0, 0); background.pushSprite(0, 0);
} }
@ -286,7 +459,11 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed)
background.setTextColor(TFT_BLACK); background.setTextColor(TFT_BLACK);
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2); background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
if (lower_switch == 1)
printMemPoolFees(mElapsed); printMemPoolFees(mElapsed);
else
printPoolData();
// Push prepared background to screen // Push prepared background to screen
background.pushSprite(0, 0); background.pushSprite(0, 0);
} }
@ -326,7 +503,10 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed)
background.setTextSize(1); background.setTextSize(1);
background.setTextColor(0xDEDB, TFT_BLACK); background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF); background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
if (lower_switch == 1)
printPoolData(); printPoolData();
else
printMemPoolFees(mElapsed);
// Push prepared background to screen // Push prepared background to screen
background.pushSprite(0, 0); background.pushSprite(0, 0);
} }

View File

@ -34,7 +34,9 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false)
} }
iSD_ = &SD; iSD_ = &SD;
#endif // interface type #endif // interface type
#ifndef NERDMINER_T_HMI
initSDcard(); initSDcard();
#endif
} }
SDCard::~SDCard() SDCard::~SDCard()
@ -167,7 +169,14 @@ bool SDCard::initSDcard()
#elif defined (BUILD_SDMMC_1) #elif defined (BUILD_SDMMC_1)
#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes.
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
#ifdef NERDMINER_T_HMI
// Need to lower frequency to 20000
// Should work but blows up in SDCard::initSDcard()
// see temporary workaround t_hmiCheckForSDCardAndMoveToNVM()
cardInitialized_ = iSD_->begin("/sd", true, false, 20000);
#else
cardInitialized_ = iSD_->begin("/sd", true); cardInitialized_ = iSD_->begin("/sd", true);
#endif
Serial.println("SDCard: 1-Bit Mode."); Serial.println("SDCard: 1-Bit Mode.");
} }
#elif defined (BUILD_SDSPI) #elif defined (BUILD_SDSPI)

View File

@ -335,13 +335,12 @@ String getPoolAPIUrl(void) {
else { else {
switch (Settings.PoolPort) { switch (Settings.PoolPort) {
case 3333: case 3333:
if (Settings.PoolAddress == "pool.vkbit.com") if (Settings.PoolAddress == "pool.sethforprivacy.com")
poolAPIUrl = "https://vkbit.com/miner/";
else if (Settings.PoolAddress == "pool.sethforprivacy.com")
poolAPIUrl = "https://pool.sethforprivacy.com/api/client/"; poolAPIUrl = "https://pool.sethforprivacy.com/api/client/";
// Add more cases for other addresses with port 3333 if needed // Add more cases for other addresses with port 3333 if needed
break; break;
case 2018: case 2018:
// Local instance of public-pool.io on Umbrel or Start9
poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/"; poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/";
break; break;
default: default: