Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add driver support for M5Stick-C Plus device. #435

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ lib_ignore =

;--------------------------------------------------------------------

[env:M5Stick-CPlus]
platform = [email protected]
board = m5stick-c
framework = arduino
monitor_filters =
esp32_exception_decoder
time
log2file
;board_build.arduino.memory_type = qio_opi
monitor_speed = 115200
upload_speed = 1500000
# 2 x 4.5MB app, 6.875MB SPIFFS
board_build.partitions = huge_app.csv
build_flags =
-D M5STICK_CPLUS=1
;-D DEBUG_MINING=1
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
m5stack/M5StickCPlus@^0.1.0
lib_ignore =
TFT_eSPI
SD
SD_MMC
rm67162
HANSOLOminerv2

;--------------------------------------------------------------------

[env:wt32-sc01]
platform = [email protected]
board = esp-wrover-kit
Expand Down
10 changes: 10 additions & 0 deletions src/drivers/devices/M5Stick-CPlus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _M5_STICK_CPLUS_H
#define _M5_STICK_CPLUS_H

#define PIN_BUTTON_1 37
#define PIN_BUTTON_2 39
#define LED_PIN 10

#define M5STICKCPLUS_DISPLAY

#endif
2 changes: 2 additions & 0 deletions src/drivers/devices/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "nerdMinerV2.h"
#elif defined(M5STICK_C)
#include "M5Stick-C.h"
#elif defined(M5STICK_CPLUS)
#include "M5Stick-CPlus.h"
#elif defined(DEVKITV1)
#include "esp32DevKit.h"
#elif defined(TDISPLAY)
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/displays/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ DisplayDriver *currentDisplayDriver = &tDisplayV1Driver;
DisplayDriver *currentDisplayDriver = &m5stickCDriver;
#endif

#ifdef M5STICKCPLUS_DISPLAY
DisplayDriver *currentDisplayDriver = &m5stickCPlusDriver;
#endif

#ifdef T_HMI_DISPLAY
DisplayDriver *currentDisplayDriver = &t_hmiDisplayDriver;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/drivers/displays/displayDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern DisplayDriver esp32_2432S028RDriver;
extern DisplayDriver t_qtDisplayDriver;
extern DisplayDriver tDisplayV1Driver;
extern DisplayDriver m5stickCDriver;
extern DisplayDriver m5stickCPlusDriver;
extern DisplayDriver t_hmiDisplayDriver;

#define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
Expand Down
278 changes: 278 additions & 0 deletions src/drivers/displays/m5stickCPlusDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
#include "displayDriver.h"

#ifdef M5STICKCPLUS_DISPLAY

#include <M5StickCPlus.h>

#include "media/images_240_135.h"
#include "media/myFonts.h"
#include "media/Free_Fonts.h"
#include "OpenFontRender.h"
#include "version.h"
#include "monitor.h"
#include "rotation.h"

#define WIDTH 240
#define HEIGHT 135

OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite

int screen_state = 1;

void m5stickCPlusDriver_Init(void)
{
M5.begin();
M5.Axp.ScreenBreath(100); //screen brightness 0 - 100

tft.init();
tft.setRotation(ROTATION_90);
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(DigitalNumbers, sizeof(DigitalNumbers)))
{
Serial.println("Initialise error");
while(1);
return;
}
}

void m5stickCPlusDriver_AlternateScreenState(void)
{
if (screen_state==1) {
M5.Lcd.writecommand(ST7789_DISPOFF);
M5.Axp.ScreenBreath(0);
screen_state=0;
} else {
M5.Lcd.writecommand(ST7789_DISPON);
M5.Axp.ScreenBreath(100);
screen_state=1;
}
}

void m5stickCPlusDriver_AlternateRotation(void)
{
tft.setRotation( flipRotation(tft.getRotation()) );
}

void m5stickCPlusDriver_MinerScreen(unsigned long mElapsed)
{
mining_data data = getMiningData(mElapsed);

// 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(30);
render.setCursor(19, 118);
render.setFontColor(TFT_BLACK);

render.rdrawString(data.currentHashRate.c_str(), 100, 82, TFT_BLACK);
// Total hashes
render.setFontSize(13);
render.rdrawString(data.totalMHashes.c_str(), 200, 106, TFT_BLACK);
// Block templates
render.drawString(data.templates.c_str(), 140, 15, 0xDEDB);
// Best diff
render.drawString(data.bestDiff.c_str(), 140, 36, 0xDEDB);
// 32Bit shares
render.drawString(data.completedShares.c_str(), 140, 56, 0xDEDB);
// Hores
render.setFontSize(9);
render.rdrawString(data.timeMining.c_str(), 226, 80, 0xDEDB);

// Valid Blocks
render.setFontSize(19);
render.drawString(data.valids.c_str(), 212, 42, 0xDEDB);

// Print Temp
render.setFontSize(8);
render.rdrawString(data.temp.c_str(), 180, 1, TFT_BLACK);

render.setFontSize(3);
render.rdrawString(String(0).c_str(), 184, 2, TFT_BLACK);

// Print Hour
render.setFontSize(8);
render.rdrawString(data.currentTime.c_str(), 215, 1, TFT_BLACK);

// Push prepared background to screen
background.pushSprite(0, 0);
}

void m5stickCPlusDriver_ClockScreen(unsigned long mElapsed)
{
clock_data data = getClockData(mElapsed);

// 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(20);
render.setCursor(19, 122);
render.setFontColor(TFT_BLACK);
render.rdrawString(data.currentHashRate.c_str(), 70, 103, 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(), 148, 1, GFXFF);

// Print BlockHeight
render.setFontSize(14);
render.rdrawString(data.blockHeight.c_str(), 190, 110, TFT_BLACK);

// Print Hour
background.setFreeFont(FF22);
background.setTextSize(2);
background.setTextColor(TFT_WHITE, TFT_BLACK);

background.drawString(data.currentTime.c_str(), 100, 40, GFXFF);

// Push prepared background to screen
background.pushSprite(0, 0);
}

void m5stickCPlusDriver_GlobalHashScreen(unsigned long mElapsed)
{
coin_data data = getCoinData(mElapsed);

// 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(), 148, 1, GFXFF);

// Print Last Pool Block
background.setFreeFont(FSS9);
background.setTextDatum(TR_DATUM);
background.setTextColor(TFT_WHITE);
background.drawString(data.halfHourFee.c_str(), 230, 40, GFXFF);

// Print Difficulty
background.setFreeFont(FSS9);
background.setTextDatum(TR_DATUM);
background.setTextColor(TFT_WHITE);
background.drawString(data.netwrokDifficulty.c_str(), 230, 68, GFXFF);

// Print Global Hashrate
render.setFontSize(12);
render.rdrawString(data.globalHashRate.c_str(), 205, 115, TFT_BLACK);

// Print BlockHeight
render.setFontSize(23);
render.rdrawString(data.blockHeight.c_str(), 105, 80, TFT_WHITE);

// 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(), 55, 125, FONT2);

// Push prepared background to screen
background.pushSprite(0, 0);
}

void tDisplay_BTCprice(unsigned long mElapsed)
{
clock_data data = getClockData(mElapsed);

// Print background screen
background.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen);

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(22);
render.setCursor(19, 122);
render.setFontColor(TFT_BLACK);
render.rdrawString(data.currentHashRate.c_str(), 75, 90, TFT_BLACK);

// Print BlockHeight
render.setFontSize(16);
render.rdrawString(data.blockHeight.c_str(), 190, 100, TFT_WHITE);

// Print Hour
background.setFreeFont(FSSB9);
background.setTextSize(1);
background.setTextDatum(TL_DATUM);
background.setTextColor(TFT_BLACK);
background.drawString(data.currentTime.c_str(), 148, 1, GFXFF);

// Print BTC Price
background.setFreeFont(FF18);
background.setTextDatum(TR_DATUM);
background.setTextSize(2);
background.setTextColor(TFT_WHITE);
background.drawString(data.btcPrice.c_str(), 230, 40, GFXFF);

// Push prepared background to screen
background.pushSprite(0, 0);
}

void m5stickCPlusDriver_LoadingScreen(void)
{
tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 0, initWidth, initHeight, initScreen);
tft.setTextFont(2);
tft.setTextColor(TFT_BLACK);
tft.setCursor(20, 110);
tft.println(CURRENT_VERSION);
}

void m5stickCPlusDriver_SetupScreen(void)
{
tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen);
}

void m5stickCPlusDriver_AnimateCurrentScreen(unsigned long frame)
{
}

void m5stickCPlusDriver_DoLedStuff(unsigned long frame)
{
}

CyclicScreenFunction m5stickCPlusDriverCyclicScreens[] = { m5stickCPlusDriver_MinerScreen, m5stickCPlusDriver_ClockScreen, m5stickCPlusDriver_GlobalHashScreen, tDisplay_BTCprice};

DisplayDriver m5stickCPlusDriver = {
m5stickCPlusDriver_Init,
m5stickCPlusDriver_AlternateScreenState,
m5stickCPlusDriver_AlternateRotation,
m5stickCPlusDriver_LoadingScreen,
m5stickCPlusDriver_SetupScreen,
m5stickCPlusDriverCyclicScreens,
m5stickCPlusDriver_AnimateCurrentScreen,
m5stickCPlusDriver_DoLedStuff,
SCREENS_ARRAY_SIZE(m5stickCPlusDriverCyclicScreens),
0,
WIDTH,
HEIGHT};
#endif