Skip to content

Commit

Permalink
Merge branch 'pr/420' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BitMaker-hub committed Jun 10, 2024
2 parents 3cf36a4 + c77aea6 commit 2ea20ab
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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))
- LILYGO T-HMI ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oFII4s2)) / Dev support: @cosmicpsyop

\*Affiliate links

Expand Down
15 changes: 8 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,14 @@ build_flags =
-include $PROJECT_LIBDEPS_DIR/$PIOENV/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h

board_build.arduino.memory_type = qio_opi
lib_deps =
https://github.com/takkaO/OpenFontRender#v1.2
bblanchon/ArduinoJson@^6.21.5
https://github.com/tzapu/WiFiManager.git#v2.0.17
mathertel/OneButton@^2.5.0
arduino-libraries/NTPClient@^3.2.1
bodmer/TFT_eSPI@^2.5.43
lib_deps =
https://github.com/liangyingy/arduino_xpt2046_library
https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
mathertel/OneButton @ ^2.5.0
arduino-libraries/NTPClient
bodmer/TFT_eSPI @ ^2.5.31
https://github.com/achillhasler/TFT_eTouch
lib_ignore =
HANSOLOminerv2
Expand Down
19 changes: 17 additions & 2 deletions src/NerdMinerV2.ino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "drivers/storage/SDCard.h"
#include "timeconst.h"

#ifdef TOUCH_ENABLE
#include "TouchHandler.h"
#endif

//3 seconds WDT
#define WDT_TIMEOUT 3
//15 minutes WDT for miner task
Expand All @@ -28,6 +32,10 @@
OneButton button2(PIN_BUTTON_2);
#endif

#ifdef TOUCH_ENABLE
extern TouchHandler touchHandler;
#endif

extern monitor_data mMonitor;

#ifdef SD_ID
Expand Down Expand Up @@ -100,7 +108,11 @@ void setup()
/******** SHOW LED INIT STATUS (devices without screen) *****/
mMonitor.NerdStatus = NM_waitingConfig;
doLedStuff(0);


#ifdef SDMMC_1BIT_FIX
SDCrd.initSDcard();
#endif

/******** INIT WIFI ************/
init_WifiManager();

Expand Down Expand Up @@ -160,7 +172,10 @@ void loop() {
#ifdef PIN_BUTTON_2
button2.tick();
#endif


#ifdef TOUCH_ENABLE
touchHandler.isTouched();
#endif
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code

vTaskDelay(50 / portTICK_PERIOD_MS);
Expand Down
73 changes: 73 additions & 0 deletions src/TouchHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

#include "drivers/devices/device.h"
#ifdef TOUCH_ENABLE
#include "TouchHandler.h"



TouchHandler::~TouchHandler() {
}

TouchHandler::TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi)
: tft(tft), csPin(csPin), irqPin(irqPin), spi(spi), lastTouchTime(0),
screenSwitchCallback(nullptr), screenSwitchAltCallback(nullptr), touch(spi, csPin, irqPin) {

}

void TouchHandler::begin(uint16_t xres, uint16_t yres) {
spi.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI);
touch.begin(xres, yres);
}

void TouchHandler::setScreenSwitchCallback(void (*callback)()) {
screenSwitchCallback = callback;
}

void TouchHandler::setScreenSwitchAltCallback(void (*callback)()) {
screenSwitchAltCallback = callback;
}


uint16_t TouchHandler::isTouched() {
// XXX - move touch_x, touch_y to private and min_x, min_y,max_x, max_y
uint16_t touch_x, touch_y, code = 0;

if (touch.pressed()) {
touch_x = touch.RawX();
touch_y = touch.RawY();

// Perform actions based on touch coordinates
// if (y < y_min + (y_max - y_min) / 4) {
if (touch_x < 200 + (1700 - 200) / 4) {
// bottom
code = 1;
if (debounce() && screenSwitchAltCallback) {
screenSwitchAltCallback();
}
} else {
// top
code = 2;
if (debounce() && screenSwitchCallback) {
screenSwitchCallback();
}
}

if (code) {
if (code == 1)
Serial.print("Touch bottom\n");
else
Serial.print("Touch top\n");
}
}
return code;
}

bool TouchHandler::debounce() {
unsigned long currentTime = millis();
if (currentTime - lastTouchTime >= 2000) {
lastTouchTime = currentTime;
return true;
}
return false;
}
#endif
31 changes: 31 additions & 0 deletions src/TouchHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef _TOUCHHANDLER_H_
#define _TOUCHHANDLER_H_
#ifdef TOUCH_ENABLE
#include <TFT_eSPI.h> // TFT display library
#include <xpt2046.h> // https://github.com/liangyingy/arduino_xpt2046_library


class TouchHandler {
public:
TouchHandler();
~TouchHandler();
TouchHandler(TFT_eSPI& tft, uint8_t csPin, uint8_t irqPin, SPIClass& spi);
void begin(uint16_t xres, uint16_t yres);
uint16_t isTouched();
void setScreenSwitchCallback(void (*callback)());
void setScreenSwitchAltCallback(void (*callback)());
private:
bool debounce();
TFT_eSPI& tft;
XPT2046 touch;
uint8_t csPin;
uint8_t irqPin;
SPIClass& spi;
unsigned long lastTouchTime;
// unsigned int lower_switch;
void (*screenSwitchCallback)();
void (*screenSwitchAltCallback)();
};
#endif

#endif
6 changes: 4 additions & 2 deletions src/drivers/devices/lilygoT_HMI.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define T_HMI_DISPLAY

#define PWR_EN_PIN (10)
#define PIN_ENABLE5V PWR_EN_PIN
#define PWR_ON_PIN (14)
#define BAT_ADC_PIN (5)
#define BUTTON1_PIN (0)
Expand All @@ -29,12 +30,13 @@

// sd card
// 1-bit SD MMC
#ifdef DEFINE_SDMMC_1BIT
#define SDMMC_CLK (12)
#define SDMMC_CMD (11)
#define SDMMC_D0 (13)
#endif

#define TOUCH_ENABLE (1)
#define SDMMC_1BIT_FIX (1)
#define SD_FREQUENCY (20000)
#ifndef TFT_BL
// XXX - defined in User_Setups/Setup207_LilyGo_T_HMI.h:37
#define TFT_BL (38) // LED back-light
Expand Down
53 changes: 39 additions & 14 deletions src/drivers/displays/t_hmiDisplayDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "displayDriver.h"

#ifdef T_HMI_DISPLAY

#include <FS.h>
#include <xpt2046.h> // https://github.com/liangyingy/arduino_xpt2046_library
#include <TFT_eSPI.h>
#include <TFT_eTouch.h>
#include "media/images_320_170.h"
Expand All @@ -11,7 +12,9 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"

#ifdef TOUCH_ENABLE
#include "TouchHandler.h"
#endif
#include <Arduino.h>
#include <esp_adc_cal.h>

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

#ifdef TOUCH_ENABLE
TouchHandler touchHandler = TouchHandler(tft, ETOUCH_CS, TOUCH_IRQ, SPI);
#endif

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

unsigned int lowerScreen = 1;

extern void switchToNextScreen();
extern monitor_data mMonitor;
extern pool_data pData;
extern DisplayDriver *currentDisplayDriver;

void toggleBottomScreen() { lowerScreen = 3 - lowerScreen; }


uint32_t readAdcVoltage(int pin) {
esp_adc_cal_characteristics_t adc_chars;

Expand Down Expand Up @@ -70,20 +80,21 @@ void t_hmiDisplay_Init(void)
Serial.println("Initialise error");
return;
}
/* XXX - Pass for first version

#ifdef TOUCH_ENABLE
Serial.println(F("Initialize the touch screen"));
hSPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, ETOUCH_CS);
TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
touch.setCalibration(calibation);
*/
touchHandler.begin(HEIGHT, WIDTH);
touchHandler.setScreenSwitchCallback(switchToNextScreen);
touchHandler.setScreenSwitchAltCallback(toggleBottomScreen);
#endif

Serial.println(F("Turn on the LCD backlight"));
pinMode(LED_PIN, OUTPUT);
pinMode(BK_LIGHT_PIN, OUTPUT);
digitalWrite(BK_LIGHT_PIN, BK_LIGHT_LEVEL);
pData.bestDifficulty = "0";
pData.workersHash = "0";
pData.workersCount = 0;

}

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

printPoolData();
if (lowerScreen == 1)
printPoolData();
else
printMemPoolFees(mElapsed);

// Push prepared background to screen
background.pushSprite(0, 0);
}
Expand Down Expand Up @@ -226,7 +241,10 @@ void t_hmiDisplay_ClockScreen(unsigned long mElapsed)
background.setTextColor(0xDEDB, TFT_BLACK);

background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
printMemPoolFees(mElapsed);
if (lowerScreen == 1)
printMemPoolFees(mElapsed);
else
printPoolData();
// Push prepared background to screen
background.pushSprite(0, 0);
}
Expand Down Expand Up @@ -286,7 +304,11 @@ void t_hmiDisplay_GlobalHashScreen(unsigned long mElapsed)
background.setTextColor(TFT_BLACK);
background.drawString(data.remainingBlocks.c_str(), 72, 159, FONT2);

printMemPoolFees(mElapsed);
if (lowerScreen == 1)
printMemPoolFees(mElapsed);
else
printPoolData();

// Push prepared background to screen
background.pushSprite(0, 0);
}
Expand Down Expand Up @@ -326,7 +348,10 @@ void t_hmiDisplay_BTCprice(unsigned long mElapsed)
background.setTextSize(1);
background.setTextColor(0xDEDB, TFT_BLACK);
background.drawString(data.btcPrice.c_str(), 300, 58, GFXFF);
printPoolData();
if (lowerScreen == 1)
printPoolData();
else
printMemPoolFees(mElapsed);
// Push prepared background to screen
background.pushSprite(0, 0);
}
Expand Down
7 changes: 7 additions & 0 deletions src/drivers/storage/SDCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false)
}
iSD_ = &SD;
#endif // interface type
#ifndef SDMMC_1BIT_FIX
initSDcard();
#endif
}

SDCard::~SDCard()
Expand Down Expand Up @@ -187,7 +189,12 @@ bool SDCard::initSDcard()
#elif defined (BUILD_SDMMC_1)
#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes.
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
#ifdef SD_FREQUENCY
// Need to lower frequency to 20000 for proper detection
cardInitialized_ = iSD_->begin("/sd", true, false, SD_FREQUENCY);
#else
cardInitialized_ = iSD_->begin("/sd", true);
#endif
Serial.println("SDCard: 1-Bit Mode.");
}
#elif defined (BUILD_SDSPI)
Expand Down
5 changes: 5 additions & 0 deletions src/drivers/storage/SDCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ class SDCard
bool cardAvailable();
bool cardBusy();
void terminate();
#ifdef SDMMC_1BIT_FIX
bool initSDcard();
private:
#else
private:
bool initSDcard();
#endif
bool cardInitialized_;
bool cardBusy_;
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)
Expand Down
5 changes: 2 additions & 3 deletions src/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,12 @@ String getPoolAPIUrl(void) {
else {
switch (Settings.PoolPort) {
case 3333:
if (Settings.PoolAddress == "pool.vkbit.com")
poolAPIUrl = "https://vkbit.com/miner/";
else if (Settings.PoolAddress == "pool.sethforprivacy.com")
if (Settings.PoolAddress == "pool.sethforprivacy.com")
poolAPIUrl = "https://pool.sethforprivacy.com/api/client/";
// Add more cases for other addresses with port 3333 if needed
break;
case 2018:
// Local instance of public-pool.io on Umbrel or Start9
poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/";
break;
default:
Expand Down

0 comments on commit 2ea20ab

Please sign in to comment.