Skip to content

Commit 2ea20ab

Browse files
committed
Merge branch 'pr/420' into dev
2 parents 3cf36a4 + c77aea6 commit 2ea20ab

10 files changed

+187
-28
lines changed

README.md

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

6566
\*Affiliate links
6667

platformio.ini

+8-7
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,14 @@ build_flags =
759759
-include $PROJECT_LIBDEPS_DIR/$PIOENV/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h
760760

761761
board_build.arduino.memory_type = qio_opi
762-
lib_deps =
763-
https://github.com/takkaO/OpenFontRender#v1.2
764-
bblanchon/ArduinoJson@^6.21.5
765-
https://github.com/tzapu/WiFiManager.git#v2.0.17
766-
mathertel/OneButton@^2.5.0
767-
arduino-libraries/NTPClient@^3.2.1
768-
bodmer/TFT_eSPI@^2.5.43
762+
lib_deps =
763+
https://github.com/liangyingy/arduino_xpt2046_library
764+
https://github.com/takkaO/OpenFontRender
765+
bblanchon/ArduinoJson@^6.21.2
766+
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
767+
mathertel/OneButton @ ^2.5.0
768+
arduino-libraries/NTPClient
769+
bodmer/TFT_eSPI @ ^2.5.31
769770
https://github.com/achillhasler/TFT_eTouch
770771
lib_ignore =
771772
HANSOLOminerv2

src/NerdMinerV2.ino.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "drivers/storage/SDCard.h"
1616
#include "timeconst.h"
1717

18+
#ifdef TOUCH_ENABLE
19+
#include "TouchHandler.h"
20+
#endif
21+
1822
//3 seconds WDT
1923
#define WDT_TIMEOUT 3
2024
//15 minutes WDT for miner task
@@ -28,6 +32,10 @@
2832
OneButton button2(PIN_BUTTON_2);
2933
#endif
3034

35+
#ifdef TOUCH_ENABLE
36+
extern TouchHandler touchHandler;
37+
#endif
38+
3139
extern monitor_data mMonitor;
3240

3341
#ifdef SD_ID
@@ -100,7 +108,11 @@ void setup()
100108
/******** SHOW LED INIT STATUS (devices without screen) *****/
101109
mMonitor.NerdStatus = NM_waitingConfig;
102110
doLedStuff(0);
103-
111+
112+
#ifdef SDMMC_1BIT_FIX
113+
SDCrd.initSDcard();
114+
#endif
115+
104116
/******** INIT WIFI ************/
105117
init_WifiManager();
106118

@@ -160,7 +172,10 @@ void loop() {
160172
#ifdef PIN_BUTTON_2
161173
button2.tick();
162174
#endif
163-
175+
176+
#ifdef TOUCH_ENABLE
177+
touchHandler.isTouched();
178+
#endif
164179
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
165180

166181
vTaskDelay(50 / portTICK_PERIOD_MS);

src/TouchHandler.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
#include "drivers/devices/device.h"
3+
#ifdef TOUCH_ENABLE
4+
#include "TouchHandler.h"
5+
6+
7+
8+
TouchHandler::~TouchHandler() {
9+
}
10+
11+
TouchHandler::TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi)
12+
: tft(tft), csPin(csPin), irqPin(irqPin), spi(spi), lastTouchTime(0),
13+
screenSwitchCallback(nullptr), screenSwitchAltCallback(nullptr), touch(spi, csPin, irqPin) {
14+
15+
}
16+
17+
void TouchHandler::begin(uint16_t xres, uint16_t yres) {
18+
spi.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI);
19+
touch.begin(xres, yres);
20+
}
21+
22+
void TouchHandler::setScreenSwitchCallback(void (*callback)()) {
23+
screenSwitchCallback = callback;
24+
}
25+
26+
void TouchHandler::setScreenSwitchAltCallback(void (*callback)()) {
27+
screenSwitchAltCallback = callback;
28+
}
29+
30+
31+
uint16_t TouchHandler::isTouched() {
32+
// XXX - move touch_x, touch_y to private and min_x, min_y,max_x, max_y
33+
uint16_t touch_x, touch_y, code = 0;
34+
35+
if (touch.pressed()) {
36+
touch_x = touch.RawX();
37+
touch_y = touch.RawY();
38+
39+
// Perform actions based on touch coordinates
40+
// if (y < y_min + (y_max - y_min) / 4) {
41+
if (touch_x < 200 + (1700 - 200) / 4) {
42+
// bottom
43+
code = 1;
44+
if (debounce() && screenSwitchAltCallback) {
45+
screenSwitchAltCallback();
46+
}
47+
} else {
48+
// top
49+
code = 2;
50+
if (debounce() && screenSwitchCallback) {
51+
screenSwitchCallback();
52+
}
53+
}
54+
55+
if (code) {
56+
if (code == 1)
57+
Serial.print("Touch bottom\n");
58+
else
59+
Serial.print("Touch top\n");
60+
}
61+
}
62+
return code;
63+
}
64+
65+
bool TouchHandler::debounce() {
66+
unsigned long currentTime = millis();
67+
if (currentTime - lastTouchTime >= 2000) {
68+
lastTouchTime = currentTime;
69+
return true;
70+
}
71+
return false;
72+
}
73+
#endif

src/TouchHandler.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef _TOUCHHANDLER_H_
2+
#define _TOUCHHANDLER_H_
3+
#ifdef TOUCH_ENABLE
4+
#include <TFT_eSPI.h> // TFT display library
5+
#include <xpt2046.h> // https://github.com/liangyingy/arduino_xpt2046_library
6+
7+
8+
class TouchHandler {
9+
public:
10+
TouchHandler();
11+
~TouchHandler();
12+
TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi);
13+
void begin(uint16_t xres, uint16_t yres);
14+
uint16_t isTouched();
15+
void setScreenSwitchCallback(void (*callback)());
16+
void setScreenSwitchAltCallback(void (*callback)());
17+
private:
18+
bool debounce();
19+
TFT_eSPI& tft;
20+
XPT2046 touch;
21+
uint8_t csPin;
22+
uint8_t irqPin;
23+
SPIClass& spi;
24+
unsigned long lastTouchTime;
25+
// unsigned int lower_switch;
26+
void (*screenSwitchCallback)();
27+
void (*screenSwitchAltCallback)();
28+
};
29+
#endif
30+
31+
#endif

src/drivers/devices/lilygoT_HMI.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define T_HMI_DISPLAY
55

66
#define PWR_EN_PIN (10)
7+
#define PIN_ENABLE5V PWR_EN_PIN
78
#define PWR_ON_PIN (14)
89
#define BAT_ADC_PIN (5)
910
#define BUTTON1_PIN (0)
@@ -29,12 +30,13 @@
2930

3031
// sd card
3132
// 1-bit SD MMC
32-
#ifdef DEFINE_SDMMC_1BIT
3333
#define SDMMC_CLK (12)
3434
#define SDMMC_CMD (11)
3535
#define SDMMC_D0 (13)
36-
#endif
3736

37+
#define TOUCH_ENABLE (1)
38+
#define SDMMC_1BIT_FIX (1)
39+
#define SD_FREQUENCY (20000)
3840
#ifndef TFT_BL
3941
// XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37
4042
#define TFT_BL (38) // LED back-light

src/drivers/displays/t_hmiDisplayDriver.cpp

+39-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "displayDriver.h"
22

33
#ifdef T_HMI_DISPLAY
4-
4+
#include <FS.h>
5+
#include <xpt2046.h> // https://github.com/liangyingy/arduino_xpt2046_library
56
#include <TFT_eSPI.h>
67
#include <TFT_eTouch.h>
78
#include "media/images_320_170.h"
@@ -11,7 +12,9 @@
1112
#include "version.h"
1213
#include "monitor.h"
1314
#include "OpenFontRender.h"
14-
15+
#ifdef TOUCH_ENABLE
16+
#include "TouchHandler.h"
17+
#endif
1518
#include <Arduino.h>
1619
#include <esp_adc_cal.h>
1720

@@ -22,15 +25,22 @@ OpenFontRender render;
2225
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
2326
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
2427

28+
#ifdef TOUCH_ENABLE
29+
TouchHandler touchHandler = TouchHandler(tft, ETOUCH_CS, TOUCH_IRQ, SPI);
30+
#endif
2531

26-
SPIClass hSPI(HSPI);
27-
// TFT_eTouch<TFT_eSPI> touch(tft, ETOUCH_CS, 0xFF, hSPI);
2832
bool showbtcprice = false;
2933

34+
unsigned int lowerScreen = 1;
35+
36+
extern void switchToNextScreen();
3037
extern monitor_data mMonitor;
3138
extern pool_data pData;
3239
extern DisplayDriver *currentDisplayDriver;
3340

41+
void toggleBottomScreen() { lowerScreen = 3 - lowerScreen; }
42+
43+
3444
uint32_t readAdcVoltage(int pin) {
3545
esp_adc_cal_characteristics_t adc_chars;
3646

@@ -70,20 +80,21 @@ void t_hmiDisplay_Init(void)
7080
Serial.println("Initialise error");
7181
return;
7282
}
73-
/* XXX - Pass for first version
83+
84+
#ifdef TOUCH_ENABLE
7485
Serial.println(F("Initialize the touch screen"));
75-
hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
76-
TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
77-
touch.setCalibration(calibation);
78-
*/
86+
touchHandler.begin(HEIGHT, WIDTH);
87+
touchHandler.setScreenSwitchCallback(switchToNextScreen);
88+
touchHandler.setScreenSwitchAltCallback(toggleBottomScreen);
89+
#endif
90+
7991
Serial.println(F("Turn on the LCD backlight"));
8092
pinMode(LED_PIN, OUTPUT);
8193
pinMode(BK_LIGHT_PIN, OUTPUT);
8294
digitalWrite(BK_LIGHT_PIN, BK_LIGHT_LEVEL);
8395
pData.bestDifficulty = "0";
8496
pData.workersHash = "0";
8597
pData.workersCount = 0;
86-
8798
}
8899

89100
void t_hmiDisplay_AlternateScreenState(void)
@@ -188,7 +199,11 @@ void t_hmiDisplay_MinerScreen(unsigned long mElapsed)
188199
render.setFontSize(10);
189200
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
190201

191-
printPoolData();
202+
if (lowerScreen == 1)
203+
printPoolData();
204+
else
205+
printMemPoolFees(mElapsed);
206+
192207
// Push prepared background to screen
193208
background.pushSprite(0, 0);
194209
}
@@ -226,7 +241,10 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed)
226241
background.setTextColor(0xDEDB, TFT_BLACK);
227242

228243
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
229-
printMemPoolFees(mElapsed);
244+
if (lowerScreen == 1)
245+
printMemPoolFees(mElapsed);
246+
else
247+
printPoolData();
230248
// Push prepared background to screen
231249
background.pushSprite(0, 0);
232250
}
@@ -286,7 +304,11 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed)
286304
background.setTextColor(TFT_BLACK);
287305
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);
288306

289-
printMemPoolFees(mElapsed);
307+
if (lowerScreen == 1)
308+
printMemPoolFees(mElapsed);
309+
else
310+
printPoolData();
311+
290312
// Push prepared background to screen
291313
background.pushSprite(0, 0);
292314
}
@@ -326,7 +348,10 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed)
326348
background.setTextSize(1);
327349
background.setTextColor(0xDEDB, TFT_BLACK);
328350
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
329-
printPoolData();
351+
if (lowerScreen == 1)
352+
printPoolData();
353+
else
354+
printMemPoolFees(mElapsed);
330355
// Push prepared background to screen
331356
background.pushSprite(0, 0);
332357
}

src/drivers/storage/SDCard.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false)
3434
}
3535
iSD_ = &SD;
3636
#endif // interface type
37+
#ifndef SDMMC_1BIT_FIX
3738
initSDcard();
39+
#endif
3840
}
3941

4042
SDCard::~SDCard()
@@ -187,7 +189,12 @@ bool SDCard::initSDcard()
187189
#elif defined (BUILD_SDMMC_1)
188190
#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes.
189191
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
192+
#ifdef SD_FREQUENCY
193+
// Need to lower frequency to 20000 for proper detection
194+
cardInitialized_ = iSD_->begin("/sd", true, false, SD_FREQUENCY);
195+
#else
190196
cardInitialized_ = iSD_->begin("/sd", true);
197+
#endif
191198
Serial.println("SDCard: 1-Bit Mode.");
192199
}
193200
#elif defined (BUILD_SDSPI)

src/drivers/storage/SDCard.h

+5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ class SDCard
5959
bool cardAvailable();
6060
bool cardBusy();
6161
void terminate();
62+
#ifdef SDMMC_1BIT_FIX
63+
bool initSDcard();
64+
private:
65+
#else
6266
private:
6367
bool initSDcard();
68+
#endif
6469
bool cardInitialized_;
6570
bool cardBusy_;
6671
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)

src/monitor.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,12 @@ String getPoolAPIUrl(void) {
336336
else {
337337
switch (Settings.PoolPort) {
338338
case 3333:
339-
if (Settings.PoolAddress == "pool.vkbit.com")
340-
poolAPIUrl = "https://vkbit.com/miner/";
341-
else if (Settings.PoolAddress == "pool.sethforprivacy.com")
339+
if (Settings.PoolAddress == "pool.sethforprivacy.com")
342340
poolAPIUrl = "https://pool.sethforprivacy.com/api/client/";
343341
// Add more cases for other addresses with port 3333 if needed
344342
break;
345343
case 2018:
344+
// Local instance of public-pool.io on Umbrel or Start9
346345
poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/";
347346
break;
348347
default:

0 commit comments

Comments
 (0)