|
| 1 | +#include "displayDriver.h" |
| 2 | + |
| 3 | +#ifdef M5STICKCPLUS_DISPLAY |
| 4 | + |
| 5 | +#include <M5StickCPlus.h> |
| 6 | + |
| 7 | +#include "media/images_240_135.h" |
| 8 | +#include "media/myFonts.h" |
| 9 | +#include "media/Free_Fonts.h" |
| 10 | +#include "OpenFontRender.h" |
| 11 | +#include "version.h" |
| 12 | +#include "monitor.h" |
| 13 | +#include "rotation.h" |
| 14 | + |
| 15 | +#define WIDTH 240 |
| 16 | +#define HEIGHT 135 |
| 17 | + |
| 18 | +OpenFontRender render; |
| 19 | +TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h |
| 20 | +TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite |
| 21 | + |
| 22 | +int screen_state = 1; |
| 23 | + |
| 24 | +void m5stickCPlusDriver_Init(void) |
| 25 | +{ |
| 26 | + M5.begin(); |
| 27 | + M5.Axp.ScreenBreath(100); //screen brightness 0 - 100 |
| 28 | + |
| 29 | + tft.init(); |
| 30 | + tft.setRotation(ROTATION_90); |
| 31 | + tft.setSwapBytes(true); // Swap the colour byte order when rendering |
| 32 | + background.createSprite(WIDTH, HEIGHT); // Background Sprite |
| 33 | + background.setSwapBytes(true); |
| 34 | + render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) |
| 35 | + render.setLineSpaceRatio(0.9); // Espaciado entre texto |
| 36 | + |
| 37 | + // Load the font and check it can be read OK |
| 38 | + if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers))) |
| 39 | + { |
| 40 | + Serial.println("Initialise error"); |
| 41 | + while(1); |
| 42 | + return; |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +void m5stickCPlusDriver_AlternateScreenState(void) |
| 47 | +{ |
| 48 | + if (screen_state==1) { |
| 49 | + M5.Lcd.writecommand(ST7789_DISPOFF); |
| 50 | + M5.Axp.ScreenBreath(0); |
| 51 | + screen_state=0; |
| 52 | + } else { |
| 53 | + M5.Lcd.writecommand(ST7789_DISPON); |
| 54 | + M5.Axp.ScreenBreath(100); |
| 55 | + screen_state=1; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +void m5stickCPlusDriver_AlternateRotation(void) |
| 60 | +{ |
| 61 | + tft.setRotation( flipRotation(tft.getRotation()) ); |
| 62 | +} |
| 63 | + |
| 64 | +void m5stickCPlusDriver_MinerScreen(unsigned long mElapsed) |
| 65 | +{ |
| 66 | + mining_data data = getMiningData(mElapsed); |
| 67 | + |
| 68 | + // Print background screen |
| 69 | + background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); |
| 70 | + |
| 71 | + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", |
| 72 | + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); |
| 73 | + |
| 74 | + // Hashrate |
| 75 | + render.setFontSize(30); |
| 76 | + render.setCursor(19, 118); |
| 77 | + render.setFontColor(TFT_BLACK); |
| 78 | + |
| 79 | + render.rdrawString(data.currentHashRate.c_str(), 100, 82, TFT_BLACK); |
| 80 | + // Total hashes |
| 81 | + render.setFontSize(13); |
| 82 | + render.rdrawString(data.totalMHashes.c_str(), 200, 106, TFT_BLACK); |
| 83 | + // Block templates |
| 84 | + render.drawString(data.templates.c_str(), 140, 15, 0xDEDB); |
| 85 | + // Best diff |
| 86 | + render.drawString(data.bestDiff.c_str(), 140, 36, 0xDEDB); |
| 87 | + // 32Bit shares |
| 88 | + render.drawString(data.completedShares.c_str(), 140, 56, 0xDEDB); |
| 89 | + // Hores |
| 90 | + render.setFontSize(9); |
| 91 | + render.rdrawString(data.timeMining.c_str(), 226, 80, 0xDEDB); |
| 92 | + |
| 93 | + // Valid Blocks |
| 94 | + render.setFontSize(19); |
| 95 | + render.drawString(data.valids.c_str(), 212, 42, 0xDEDB); |
| 96 | + |
| 97 | + // Print Temp |
| 98 | + render.setFontSize(8); |
| 99 | + render.rdrawString(data.temp.c_str(), 180, 1, TFT_BLACK); |
| 100 | + |
| 101 | + render.setFontSize(3); |
| 102 | + render.rdrawString(String(0).c_str(), 184, 2, TFT_BLACK); |
| 103 | + |
| 104 | + // Print Hour |
| 105 | + render.setFontSize(8); |
| 106 | + render.rdrawString(data.currentTime.c_str(), 215, 1, TFT_BLACK); |
| 107 | + |
| 108 | + // Push prepared background to screen |
| 109 | + background.pushSprite(0, 0); |
| 110 | +} |
| 111 | + |
| 112 | +void m5stickCPlusDriver_ClockScreen(unsigned long mElapsed) |
| 113 | +{ |
| 114 | + clock_data data = getClockData(mElapsed); |
| 115 | + |
| 116 | + // Print background screen |
| 117 | + background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen); |
| 118 | + |
| 119 | + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", |
| 120 | + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); |
| 121 | + |
| 122 | + // Hashrate |
| 123 | + render.setFontSize(20); |
| 124 | + render.setCursor(19, 122); |
| 125 | + render.setFontColor(TFT_BLACK); |
| 126 | + render.rdrawString(data.currentHashRate.c_str(), 70, 103, TFT_BLACK); |
| 127 | + |
| 128 | + // Print BTC Price |
| 129 | + background.setFreeFont(FSSB9); |
| 130 | + background.setTextSize(1); |
| 131 | + background.setTextDatum(TL_DATUM); |
| 132 | + background.setTextColor(TFT_BLACK); |
| 133 | + background.drawString(data.btcPrice.c_str(), 148, 1, GFXFF); |
| 134 | + |
| 135 | + // Print BlockHeight |
| 136 | + render.setFontSize(14); |
| 137 | + render.rdrawString(data.blockHeight.c_str(), 190, 110, TFT_BLACK); |
| 138 | + |
| 139 | + // Print Hour |
| 140 | + background.setFreeFont(FF22); |
| 141 | + background.setTextSize(2); |
| 142 | + background.setTextColor(TFT_WHITE, TFT_BLACK); |
| 143 | + |
| 144 | + background.drawString(data.currentTime.c_str(), 100, 40, GFXFF); |
| 145 | + |
| 146 | + // Push prepared background to screen |
| 147 | + background.pushSprite(0, 0); |
| 148 | +} |
| 149 | + |
| 150 | +void m5stickCPlusDriver_GlobalHashScreen(unsigned long mElapsed) |
| 151 | +{ |
| 152 | + coin_data data = getCoinData(mElapsed); |
| 153 | + |
| 154 | + // Print background screen |
| 155 | + background.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen); |
| 156 | + |
| 157 | + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", |
| 158 | + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); |
| 159 | + |
| 160 | + // Print BTC Price |
| 161 | + background.setFreeFont(FSSB9); |
| 162 | + background.setTextSize(1); |
| 163 | + background.setTextDatum(TL_DATUM); |
| 164 | + background.setTextColor(TFT_BLACK); |
| 165 | + background.drawString(data.btcPrice.c_str(), 148, 1, GFXFF); |
| 166 | + |
| 167 | + // Print Last Pool Block |
| 168 | + background.setFreeFont(FSS9); |
| 169 | + background.setTextDatum(TR_DATUM); |
| 170 | + background.setTextColor(TFT_WHITE); |
| 171 | + background.drawString(data.halfHourFee.c_str(), 230, 40, GFXFF); |
| 172 | + |
| 173 | + // Print Difficulty |
| 174 | + background.setFreeFont(FSS9); |
| 175 | + background.setTextDatum(TR_DATUM); |
| 176 | + background.setTextColor(TFT_WHITE); |
| 177 | + background.drawString(data.netwrokDifficulty.c_str(), 230, 68, GFXFF); |
| 178 | + |
| 179 | + // Print Global Hashrate |
| 180 | + render.setFontSize(12); |
| 181 | + render.rdrawString(data.globalHashRate.c_str(), 205, 115, TFT_BLACK); |
| 182 | + |
| 183 | + // Print BlockHeight |
| 184 | + render.setFontSize(23); |
| 185 | + render.rdrawString(data.blockHeight.c_str(), 105, 80, TFT_WHITE); |
| 186 | + |
| 187 | + // Draw percentage rectangle |
| 188 | + int x2 = 2 + (138 * data.progressPercent / 100); |
| 189 | + background.fillRect(2, 149, x2, 168, 0xDEDB); |
| 190 | + |
| 191 | + // Print Remaining BLocks |
| 192 | + background.setTextFont(FONT2); |
| 193 | + background.setTextSize(1); |
| 194 | + background.setTextDatum(MC_DATUM); |
| 195 | + background.setTextColor(TFT_BLACK); |
| 196 | + background.drawString(data.remainingBlocks.c_str(), 55, 125, FONT2); |
| 197 | + |
| 198 | + // Push prepared background to screen |
| 199 | + background.pushSprite(0, 0); |
| 200 | +} |
| 201 | + |
| 202 | +void tDisplay_BTCprice(unsigned long mElapsed) |
| 203 | +{ |
| 204 | + clock_data data = getClockData(mElapsed); |
| 205 | + |
| 206 | + // Print background screen |
| 207 | + background.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen); |
| 208 | + |
| 209 | + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", |
| 210 | + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); |
| 211 | + |
| 212 | + // Hashrate |
| 213 | + render.setFontSize(22); |
| 214 | + render.setCursor(19, 122); |
| 215 | + render.setFontColor(TFT_BLACK); |
| 216 | + render.rdrawString(data.currentHashRate.c_str(), 75, 90, TFT_BLACK); |
| 217 | + |
| 218 | + // Print BlockHeight |
| 219 | + render.setFontSize(16); |
| 220 | + render.rdrawString(data.blockHeight.c_str(), 190, 100, TFT_WHITE); |
| 221 | + |
| 222 | + // Print Hour |
| 223 | + background.setFreeFont(FSSB9); |
| 224 | + background.setTextSize(1); |
| 225 | + background.setTextDatum(TL_DATUM); |
| 226 | + background.setTextColor(TFT_BLACK); |
| 227 | + background.drawString(data.currentTime.c_str(), 148, 1, GFXFF); |
| 228 | + |
| 229 | + // Print BTC Price |
| 230 | + background.setFreeFont(FF18); |
| 231 | + background.setTextDatum(TR_DATUM); |
| 232 | + background.setTextSize(2); |
| 233 | + background.setTextColor(TFT_WHITE); |
| 234 | + background.drawString(data.btcPrice.c_str(), 230, 40, GFXFF); |
| 235 | + |
| 236 | + // Push prepared background to screen |
| 237 | + background.pushSprite(0, 0); |
| 238 | +} |
| 239 | + |
| 240 | +void m5stickCPlusDriver_LoadingScreen(void) |
| 241 | +{ |
| 242 | + tft.fillScreen(TFT_BLACK); |
| 243 | + tft.pushImage(0, 0, initWidth, initHeight, initScreen); |
| 244 | + tft.setTextFont(2); |
| 245 | + tft.setTextColor(TFT_BLACK); |
| 246 | + tft.setCursor(20, 110); |
| 247 | + tft.println(CURRENT_VERSION); |
| 248 | +} |
| 249 | + |
| 250 | +void m5stickCPlusDriver_SetupScreen(void) |
| 251 | +{ |
| 252 | + tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen); |
| 253 | +} |
| 254 | + |
| 255 | +void m5stickCPlusDriver_AnimateCurrentScreen(unsigned long frame) |
| 256 | +{ |
| 257 | +} |
| 258 | + |
| 259 | +void m5stickCPlusDriver_DoLedStuff(unsigned long frame) |
| 260 | +{ |
| 261 | +} |
| 262 | + |
| 263 | +CyclicScreenFunction m5stickCPlusDriverCyclicScreens[] = { m5stickCPlusDriver_MinerScreen, m5stickCPlusDriver_ClockScreen, m5stickCPlusDriver_GlobalHashScreen, tDisplay_BTCprice}; |
| 264 | + |
| 265 | +DisplayDriver m5stickCPlusDriver = { |
| 266 | + m5stickCPlusDriver_Init, |
| 267 | + m5stickCPlusDriver_AlternateScreenState, |
| 268 | + m5stickCPlusDriver_AlternateRotation, |
| 269 | + m5stickCPlusDriver_LoadingScreen, |
| 270 | + m5stickCPlusDriver_SetupScreen, |
| 271 | + m5stickCPlusDriverCyclicScreens, |
| 272 | + m5stickCPlusDriver_AnimateCurrentScreen, |
| 273 | + m5stickCPlusDriver_DoLedStuff, |
| 274 | + SCREENS_ARRAY_SIZE(m5stickCPlusDriverCyclicScreens), |
| 275 | + 0, |
| 276 | + WIDTH, |
| 277 | + HEIGHT}; |
| 278 | +#endif |
0 commit comments