Merge pull request #154 from BitMaker-hub/dev
Dev merge - Multi device support and refactoring
This commit is contained in:
commit
70bc1d33b9
@ -126,10 +126,19 @@
|
||||
|
||||
//#include <User_Setups/Setup204_ESP32_TouchDown.h> // Setup file for the ESP32 TouchDown based on ILI9488 480 x 320 TFT
|
||||
|
||||
//#include <User_Setups/Setup205_ESP32_TouchDown_S3.h> // Setup file for the ESP32 TouchDown S3 based on ILI9488 480 x 320 TFT
|
||||
//#include <User_Setups/Setup205_ESP32_TouchDown_S3.h> // Setup file for the ESP32 TouchDown S3 based on ILI9488 480 x 320 TFT
|
||||
#ifdef NERDMINERV2
|
||||
#include <User_Setups/Setup206_LilyGo_T_Display_S3.h>
|
||||
#endif
|
||||
|
||||
#ifdef NERMINER_S3_AMOLED
|
||||
#include <User_Setups/Setup206_LilyGo_T_Display_S3.h> //Just a stub. No driver implementation for S3 AMOLED in TFT_eSPI
|
||||
#endif
|
||||
|
||||
#ifdef NERMINER_S3_DONGLE
|
||||
#include <User_Setups/Setup300_TTGO_T_Dongle.h>
|
||||
#endif
|
||||
|
||||
//#include <User_Setups/Setup301_BW16_ST7735.h> // Setup file for Bw16-based boards with ST7735 160 x 80 TFT
|
||||
|
||||
//#include <User_Setups/SetupX_Template.h> // Template file for a setup
|
||||
|
37
lib/TFT_eSPI/User_Setups/Setup300_TTGO_T_Dongle.h
Normal file
37
lib/TFT_eSPI/User_Setups/Setup300_TTGO_T_Dongle.h
Normal file
@ -0,0 +1,37 @@
|
||||
#define USER_SETUP_ID 300
|
||||
|
||||
#define ST7735_DRIVER
|
||||
|
||||
#define TFT_WIDTH 80
|
||||
#define TFT_HEIGHT 160
|
||||
|
||||
#define TFT_RST 1
|
||||
#define TFT_MISO -1
|
||||
#define TFT_MOSI 3
|
||||
#define TFT_SCLK 5
|
||||
#define TFT_CS 4
|
||||
#define TFT_DC 2
|
||||
// #define TFT_BL 38
|
||||
// #define TFT_BACKLIGHT_ON LOW
|
||||
|
||||
#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
|
||||
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
// #define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
|
||||
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
|
||||
|
||||
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
|
||||
// this will save ~20kbytes of FLASH
|
||||
#define SMOOTH_FONT
|
||||
|
||||
#define SPI_FREQUENCY 50000000 // Actually sets it to 26.67MHz = 80/3
|
||||
|
||||
// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
|
||||
// #define SPI_FREQUENCY 80000000
|
||||
|
||||
#define TFT_RGB_ORDER TFT_BGR
|
41
lib/rm67162/pins_config.h
Normal file
41
lib/rm67162/pins_config.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
/***********************config*************************/
|
||||
#define LCD_USB_QSPI_DREVER 1
|
||||
|
||||
#define SPI_FREQUENCY 75000000
|
||||
#define TFT_SPI_MODE SPI_MODE0
|
||||
#define TFT_SPI_HOST SPI2_HOST
|
||||
|
||||
#define EXAMPLE_LCD_H_RES 536
|
||||
#define EXAMPLE_LCD_V_RES 240
|
||||
#define LVGL_LCD_BUF_SIZE (EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES)
|
||||
|
||||
/***********************config*************************/
|
||||
|
||||
#define TFT_WIDTH 240
|
||||
#define TFT_HEIGHT 536
|
||||
#define SEND_BUF_SIZE (0x4000) //(LCD_WIDTH * LCD_HEIGHT + 8) / 10
|
||||
|
||||
#define TFT_TE 9
|
||||
#define TFT_SDO 8
|
||||
|
||||
#define TFT_DC 7
|
||||
#define TFT_RES 17
|
||||
#define TFT_CS 6
|
||||
#define TFT_MOSI 18
|
||||
#define TFT_SCK 47
|
||||
|
||||
#define TFT_QSPI_CS 6
|
||||
#define TFT_QSPI_SCK 47
|
||||
#define TFT_QSPI_D0 18
|
||||
#define TFT_QSPI_D1 7
|
||||
#define TFT_QSPI_D2 48
|
||||
#define TFT_QSPI_D3 5
|
||||
#define TFT_QSPI_RST 17
|
||||
|
||||
#define PIN_LED 38
|
||||
#define PIN_BAT_VOLT 4
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 21
|
349
lib/rm67162/rm67162.cpp
Normal file
349
lib/rm67162/rm67162.cpp
Normal file
@ -0,0 +1,349 @@
|
||||
#include "rm67162.h"
|
||||
#include "SPI.h"
|
||||
#include "Arduino.h"
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
const static lcd_cmd_t rm67162_spi_init[] = {
|
||||
{0xFE, {0x00}, 0x01}, // PAGE
|
||||
{0x35, {0x00}, 0x00}, // TE ON
|
||||
// {0x34, {0x00}, 0x00}, //TE OFF
|
||||
{0x36, {0x00}, 0x01}, // Scan Direction Control
|
||||
{0x3A, {0x75}, 0x01}, // Interface Pixel Format 16bit/pixel
|
||||
// {0x3A, {0x76}, 0x01}, //Interface Pixel Format 18bit/pixel
|
||||
// {0x3A, {0x77}, 0x01}, //Interface Pixel Format 24bit/pixel
|
||||
{0x51, {0x00}, 0x01}, // Write Display Brightness MAX_VAL=0XFF
|
||||
{0x11, {0x00}, 0x01 | 0x80}, // Sleep Out
|
||||
{0x29, {0x00}, 0x01 | 0x80}, // Display on
|
||||
{0x51, {0xD0}, 0x01}, // Write Display Brightness MAX_VAL=0XFF
|
||||
};
|
||||
|
||||
const static lcd_cmd_t rm67162_qspi_init[] = {
|
||||
{0x11, {0x00}, 0x80}, // Sleep Out
|
||||
// {0x44, {0x01, 0x66}, 0x02}, //Set_Tear_Scanline
|
||||
// {0x35, {0x00}, 0x00}, //TE ON
|
||||
// {0x34, {0x00}, 0x00}, //TE OFF
|
||||
// {0x36, {0x00}, 0x01}, //Scan Direction Control
|
||||
{0x3A, {0x55}, 0x01}, // Interface Pixel Format 16bit/pixel
|
||||
// {0x3A, {0x66}, 0x01}, //Interface Pixel Format 18bit/pixel
|
||||
// {0x3A, {0x77}, 0x01}, //Interface Pixel Format 24bit/pixel
|
||||
{0x51, {0x00}, 0x01}, // Write Display Brightness MAX_VAL=0XFF
|
||||
{0x29, {0x00}, 0x80}, // Display on
|
||||
{0x51, {0xD0}, 0x01}, // Write Display Brightness MAX_VAL=0XFF
|
||||
};
|
||||
|
||||
static spi_device_handle_t spi;
|
||||
|
||||
static void WriteComm(uint8_t data)
|
||||
{
|
||||
TFT_CS_L;
|
||||
SPI.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE));
|
||||
TFT_DC_L;
|
||||
SPI.write(data);
|
||||
TFT_DC_H;
|
||||
SPI.endTransaction();
|
||||
TFT_CS_H;
|
||||
}
|
||||
|
||||
static void WriteData(uint8_t data)
|
||||
{
|
||||
TFT_CS_L;
|
||||
SPI.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE));
|
||||
TFT_DC_H;
|
||||
SPI.write(data);
|
||||
SPI.endTransaction();
|
||||
TFT_CS_H;
|
||||
}
|
||||
|
||||
static void WriteData16(uint16_t data)
|
||||
{
|
||||
TFT_CS_L;
|
||||
SPI.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE));
|
||||
TFT_DC_H;
|
||||
SPI.write16(data);
|
||||
SPI.endTransaction();
|
||||
TFT_CS_H;
|
||||
}
|
||||
|
||||
static void lcd_send_cmd(uint32_t cmd, uint8_t *dat, uint32_t len)
|
||||
{
|
||||
#if LCD_USB_QSPI_DREVER == 1
|
||||
TFT_CS_L;
|
||||
spi_transaction_t t;
|
||||
memset(&t, 0, sizeof(t));
|
||||
t.flags = (SPI_TRANS_MULTILINE_CMD | SPI_TRANS_MULTILINE_ADDR);
|
||||
t.cmd = 0x02;
|
||||
t.addr = cmd << 8;
|
||||
// Serial.printf("t.addr:0x%X\r\n", t.addr);
|
||||
if (len != 0)
|
||||
{
|
||||
t.tx_buffer = dat;
|
||||
t.length = 8 * len;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.tx_buffer = NULL;
|
||||
t.length = 0;
|
||||
}
|
||||
spi_device_polling_transmit(spi, &t);
|
||||
TFT_CS_H;
|
||||
#else
|
||||
WriteComm(cmd);
|
||||
if (len != 0)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
WriteData(dat[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void rm67162_init(void)
|
||||
{
|
||||
pinMode(TFT_CS, OUTPUT);
|
||||
pinMode(TFT_RES, OUTPUT);
|
||||
|
||||
TFT_RES_L;
|
||||
delay(300);
|
||||
TFT_RES_H;
|
||||
delay(200);
|
||||
|
||||
#if LCD_USB_QSPI_DREVER == 1
|
||||
esp_err_t ret;
|
||||
|
||||
spi_bus_config_t buscfg = {
|
||||
.data0_io_num = TFT_QSPI_D0,
|
||||
.data1_io_num = TFT_QSPI_D1,
|
||||
.sclk_io_num = TFT_QSPI_SCK,
|
||||
.data2_io_num = TFT_QSPI_D2,
|
||||
.data3_io_num = TFT_QSPI_D3,
|
||||
.max_transfer_sz = (SEND_BUF_SIZE * 16) + 8,
|
||||
.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_GPIO_PINS /* |
|
||||
SPICOMMON_BUSFLAG_QUAD */
|
||||
,
|
||||
};
|
||||
spi_device_interface_config_t devcfg = {
|
||||
.command_bits = 8,
|
||||
.address_bits = 24,
|
||||
.mode = TFT_SPI_MODE,
|
||||
.clock_speed_hz = SPI_FREQUENCY,
|
||||
.spics_io_num = -1,
|
||||
// .spics_io_num = TFT_QSPI_CS,
|
||||
.flags = SPI_DEVICE_HALFDUPLEX,
|
||||
.queue_size = 17,
|
||||
};
|
||||
ret = spi_bus_initialize(TFT_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
ret = spi_bus_add_device(TFT_SPI_HOST, &devcfg, &spi);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
#else
|
||||
SPI.begin(TFT_SCK, -1, TFT_MOSI, TFT_CS);
|
||||
SPI.setFrequency(SPI_FREQUENCY);
|
||||
pinMode(TFT_DC, OUTPUT);
|
||||
#endif
|
||||
// Initialize the screen multiple times to prevent initialization failure
|
||||
int i = 3;
|
||||
while (i--)
|
||||
{
|
||||
#if LCD_USB_QSPI_DREVER == 1
|
||||
const lcd_cmd_t *lcd_init = rm67162_qspi_init;
|
||||
for (int i = 0; i < sizeof(rm67162_qspi_init) / sizeof(lcd_cmd_t); i++)
|
||||
#else
|
||||
const lcd_cmd_t *lcd_init = rm67162_spi_init;
|
||||
for (int i = 0; i < sizeof(rm67162_spi_init) / sizeof(lcd_cmd_t); i++)
|
||||
#endif
|
||||
{
|
||||
lcd_send_cmd(lcd_init[i].cmd,
|
||||
(uint8_t *)lcd_init[i].data,
|
||||
lcd_init[i].len & 0x7f);
|
||||
|
||||
if (lcd_init[i].len & 0x80)
|
||||
delay(120);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_setRotation(uint8_t r)
|
||||
{
|
||||
uint8_t gbr = TFT_MAD_RGB;
|
||||
|
||||
switch (r)
|
||||
{
|
||||
case 0: // Portrait
|
||||
// WriteData(gbr);
|
||||
break;
|
||||
case 1: // Landscape (Portrait + 90)
|
||||
gbr = TFT_MAD_MX | TFT_MAD_MV | gbr;
|
||||
break;
|
||||
case 2: // Inverter portrait
|
||||
gbr = TFT_MAD_MX | TFT_MAD_MY | gbr;
|
||||
break;
|
||||
case 3: // Inverted landscape
|
||||
gbr = TFT_MAD_MV | TFT_MAD_MY | gbr;
|
||||
break;
|
||||
}
|
||||
lcd_send_cmd(TFT_MADCTL, &gbr, 1);
|
||||
}
|
||||
|
||||
void lcd_address_set(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
||||
{
|
||||
lcd_cmd_t t[3] = {
|
||||
{0x2a, {uint8_t(x1 >> 8), (uint8_t)x1, (uint8_t)(x2 >> 8), (uint8_t)x2}, 0x04},
|
||||
{0x2b, {uint8_t(y1 >> 8), (uint8_t)y1, (uint8_t)(y2 >> 8), (uint8_t)y2}, 0x04},
|
||||
{0x2c, {0x00}, 0x00},
|
||||
};
|
||||
|
||||
for (uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
lcd_send_cmd(t[i].cmd, t[i].data, t[i].len);
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_fill(uint16_t xsta,
|
||||
uint16_t ysta,
|
||||
uint16_t xend,
|
||||
uint16_t yend,
|
||||
uint16_t color)
|
||||
{
|
||||
|
||||
uint16_t w = xend - xsta;
|
||||
uint16_t h = yend - ysta;
|
||||
uint16_t *color_p = (uint16_t *)ps_malloc(w * h * 2);
|
||||
if (!color_p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
memset(color_p, color, w * h * 2);
|
||||
lcd_PushColors(xsta, ysta, w, h, color_p);
|
||||
free(color_p);
|
||||
}
|
||||
|
||||
void lcd_DrawPoint(uint16_t x, uint16_t y, uint16_t color)
|
||||
{
|
||||
lcd_address_set(x, y, x + 1, y + 1);
|
||||
lcd_PushColors(&color, 1);
|
||||
}
|
||||
|
||||
void lcd_PushColors(uint16_t x,
|
||||
uint16_t y,
|
||||
uint16_t width,
|
||||
uint16_t high,
|
||||
uint16_t *data)
|
||||
{
|
||||
#if LCD_USB_QSPI_DREVER == 1
|
||||
bool first_send = 1;
|
||||
size_t len = width * high;
|
||||
uint16_t *p = (uint16_t *)data;
|
||||
|
||||
lcd_address_set(x, y, x + width - 1, y + high - 1);
|
||||
TFT_CS_L;
|
||||
do
|
||||
{
|
||||
size_t chunk_size = len;
|
||||
spi_transaction_ext_t t = {0};
|
||||
memset(&t, 0, sizeof(t));
|
||||
if (first_send)
|
||||
{
|
||||
t.base.flags =
|
||||
SPI_TRANS_MODE_QIO /* | SPI_TRANS_MODE_DIOQIO_ADDR */;
|
||||
t.base.cmd = 0x32 /* 0x12 */;
|
||||
t.base.addr = 0x002C00;
|
||||
first_send = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.base.flags = SPI_TRANS_MODE_QIO | SPI_TRANS_VARIABLE_CMD |
|
||||
SPI_TRANS_VARIABLE_ADDR | SPI_TRANS_VARIABLE_DUMMY;
|
||||
t.command_bits = 0;
|
||||
t.address_bits = 0;
|
||||
t.dummy_bits = 0;
|
||||
}
|
||||
if (chunk_size > SEND_BUF_SIZE)
|
||||
{
|
||||
chunk_size = SEND_BUF_SIZE;
|
||||
}
|
||||
t.base.tx_buffer = p;
|
||||
t.base.length = chunk_size * 16;
|
||||
|
||||
// spi_device_queue_trans(spi, (spi_transaction_t *)&t, portMAX_DELAY);
|
||||
spi_device_polling_transmit(spi, (spi_transaction_t *)&t);
|
||||
len -= chunk_size;
|
||||
p += chunk_size;
|
||||
} while (len > 0);
|
||||
TFT_CS_H;
|
||||
|
||||
#else
|
||||
lcd_address_set(x, y, x + width - 1, y + high - 1);
|
||||
TFT_CS_L;
|
||||
SPI.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE));
|
||||
TFT_DC_H;
|
||||
SPI.writeBytes((uint8_t *)data, width * high * 2);
|
||||
SPI.endTransaction();
|
||||
TFT_CS_H;
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcd_PushColors(uint16_t *data, uint32_t len)
|
||||
{
|
||||
#if LCD_USB_QSPI_DREVER == 1
|
||||
bool first_send = 1;
|
||||
uint16_t *p = (uint16_t *)data;
|
||||
TFT_CS_L;
|
||||
do
|
||||
{
|
||||
size_t chunk_size = len;
|
||||
spi_transaction_ext_t t = {0};
|
||||
memset(&t, 0, sizeof(t));
|
||||
if (first_send)
|
||||
{
|
||||
t.base.flags =
|
||||
SPI_TRANS_MODE_QIO /* | SPI_TRANS_MODE_DIOQIO_ADDR */;
|
||||
t.base.cmd = 0x32 /* 0x12 */;
|
||||
t.base.addr = 0x002C00;
|
||||
first_send = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t.base.flags = SPI_TRANS_MODE_QIO | SPI_TRANS_VARIABLE_CMD |
|
||||
SPI_TRANS_VARIABLE_ADDR | SPI_TRANS_VARIABLE_DUMMY;
|
||||
t.command_bits = 0;
|
||||
t.address_bits = 0;
|
||||
t.dummy_bits = 0;
|
||||
}
|
||||
if (chunk_size > SEND_BUF_SIZE)
|
||||
{
|
||||
chunk_size = SEND_BUF_SIZE;
|
||||
}
|
||||
t.base.tx_buffer = p;
|
||||
t.base.length = chunk_size * 16;
|
||||
|
||||
// spi_device_queue_trans(spi, (spi_transaction_t *)&t, portMAX_DELAY);
|
||||
spi_device_polling_transmit(spi, (spi_transaction_t *)&t);
|
||||
len -= chunk_size;
|
||||
p += chunk_size;
|
||||
} while (len > 0);
|
||||
TFT_CS_H;
|
||||
|
||||
#else
|
||||
TFT_CS_L;
|
||||
SPI.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE));
|
||||
TFT_DC_H;
|
||||
SPI.writeBytes((uint8_t *)data, len * 2);
|
||||
SPI.endTransaction();
|
||||
TFT_CS_H;
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcd_sleep()
|
||||
{
|
||||
lcd_send_cmd(0x10, NULL, 0);
|
||||
}
|
||||
|
||||
void lcd_on()
|
||||
{
|
||||
lcd_send_cmd(0x29, NULL, 0x00);
|
||||
}
|
||||
|
||||
void lcd_off()
|
||||
{
|
||||
lcd_send_cmd(0x28, NULL, 0x00);
|
||||
}
|
57
lib/rm67162/rm67162.h
Normal file
57
lib/rm67162/rm67162.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdint.h"
|
||||
#include "pins_config.h"
|
||||
|
||||
#define TFT_MADCTL 0x36
|
||||
#define TFT_MAD_MY 0x80
|
||||
#define TFT_MAD_MX 0x40
|
||||
#define TFT_MAD_MV 0x20
|
||||
#define TFT_MAD_ML 0x10
|
||||
#define TFT_MAD_BGR 0x08
|
||||
#define TFT_MAD_MH 0x04
|
||||
#define TFT_MAD_RGB 0x00
|
||||
|
||||
#define TFT_INVOFF 0x20
|
||||
#define TFT_INVON 0x21
|
||||
|
||||
#define TFT_SCK_H digitalWrite(TFT_SCK, 1);
|
||||
#define TFT_SCK_L digitalWrite(TFT_SCK, 0);
|
||||
#define TFT_SDA_H digitalWrite(TFT_MOSI, 1);
|
||||
#define TFT_SDA_L digitalWrite(TFT_MOSI, 0);
|
||||
|
||||
#define TFT_RES_H digitalWrite(TFT_RES, 1);
|
||||
#define TFT_RES_L digitalWrite(TFT_RES, 0);
|
||||
#define TFT_DC_H digitalWrite(TFT_DC, 1);
|
||||
#define TFT_DC_L digitalWrite(TFT_DC, 0);
|
||||
#define TFT_CS_H digitalWrite(TFT_CS, 1);
|
||||
#define TFT_CS_L digitalWrite(TFT_CS, 0);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t data[4];
|
||||
uint8_t len;
|
||||
} lcd_cmd_t;
|
||||
|
||||
void rm67162_init(void);
|
||||
|
||||
// Set the display window size
|
||||
void lcd_address_set(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void lcd_setRotation(uint8_t r);
|
||||
void lcd_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
|
||||
void lcd_fill(uint16_t xsta,
|
||||
uint16_t ysta,
|
||||
uint16_t xend,
|
||||
uint16_t yend,
|
||||
uint16_t color);
|
||||
void lcd_PushColors(uint16_t x,
|
||||
uint16_t y,
|
||||
uint16_t width,
|
||||
uint16_t high,
|
||||
uint16_t *data);
|
||||
void lcd_PushColors(uint16_t *data, uint32_t len);
|
||||
void lcd_sleep();
|
||||
|
||||
void lcd_on();
|
||||
void lcd_off();
|
@ -97,4 +97,43 @@ lib_deps =
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
[env:NerminerV2-S3-AMOLED]
|
||||
platform = espressif32
|
||||
board = lilygo-t-display-s3
|
||||
framework = arduino
|
||||
|
||||
board_build.partitions = huge_app.csv
|
||||
|
||||
build_flags =
|
||||
-DNERMINER_S3_AMOLED
|
||||
-DBOARD_HAS_PSRAM
|
||||
-DARDUINO_USB_CDC_ON_BOOT
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
[env:NerminerV2-S3-DONGLE]
|
||||
platform = espressif32
|
||||
board = esp32-s3-devkitc-1
|
||||
framework = arduino
|
||||
|
||||
board_build.partitions = huge_app.csv
|
||||
|
||||
build_flags =
|
||||
-DNERMINER_S3_DONGLE
|
||||
-DBOARD_HAS_PSRAM
|
||||
-DARDUINO_USB_CDC_ON_BOOT
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
https://github.com/FastLED/FastLED
|
||||
|
@ -4,56 +4,37 @@
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <TFT_eSPI.h> // Graphics and font library
|
||||
#include <OneButton.h>
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "media/images.h"
|
||||
#include "media/myFonts.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include "wManager.h"
|
||||
#include "mining.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#define CURRENT_VERSION "V1.6.1"
|
||||
#include "drivers/display.h"
|
||||
|
||||
//3 seconds WDT
|
||||
#define WDT_TIMEOUT 3
|
||||
//15 minutes WDT for miner task
|
||||
#define WDT_MINER_TIMEOUT 900
|
||||
OneButton button1(PIN_BUTTON_1);
|
||||
OneButton button2(PIN_BUTTON_2);
|
||||
|
||||
#ifdef PIN_BUTTON_1
|
||||
OneButton button1(PIN_BUTTON_1);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_BUTTON_2
|
||||
OneButton button2(PIN_BUTTON_2);
|
||||
#endif
|
||||
|
||||
|
||||
OpenFontRender render;
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
/**********************⚡ GLOBAL Vars *******************************/
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
|
||||
|
||||
unsigned long start = millis();
|
||||
const char* ntpServer = "pool.ntp.org";
|
||||
|
||||
//void runMonitor(void *name);
|
||||
|
||||
void alternate_screen_state() {
|
||||
#ifdef NERDMINERV2
|
||||
int screen_state= digitalRead(TFT_BL);
|
||||
//Serial.printf("Screen state is '%s', switching to '%s'", screen_state, !screen_state);
|
||||
Serial.println("Switching display state");
|
||||
digitalWrite(TFT_BL, !screen_state);
|
||||
#endif
|
||||
}
|
||||
|
||||
void alternate_screen_rotation() {
|
||||
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********* INIT *****/
|
||||
void setup()
|
||||
{
|
||||
@ -67,58 +48,39 @@ void setup()
|
||||
//disableCore1WDT();
|
||||
|
||||
// Setup the buttons
|
||||
#ifdef NERDMINERV2
|
||||
// Button 1 (Boot)
|
||||
button1.setPressTicks(5000);
|
||||
button1.attachClick(alternate_screen_state);
|
||||
button1.attachDoubleClick(alternate_screen_rotation);
|
||||
// Button 2 (GPIO14)
|
||||
button2.setPressTicks(5000);
|
||||
button2.attachClick(changeScreen);
|
||||
button2.attachLongPressStart(reset_configurations);
|
||||
#elif defined(DEVKITV1)
|
||||
//Standard ESP32-devKit
|
||||
button1.setPressTicks(5000);
|
||||
button1.attachLongPressStart(reset_configurations);
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
#if defined(PIN_BUTTON_1) && !defined(PIN_BUTTON_2) //One button device
|
||||
button1.setPressTicks(5000);
|
||||
button1.attachClick(switchToNextScreen);
|
||||
button1.attachDoubleClick(alternateScreenRotation);
|
||||
button1.attachLongPressStart(reset_configurations);
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device
|
||||
button1.setPressTicks(5000);
|
||||
button1.attachClick(alternateScreenState);
|
||||
button1.attachDoubleClick(alternateScreenRotation);
|
||||
#endif
|
||||
|
||||
#if defined(PIN_BUTTON_2) //Button 2 of two button device
|
||||
button2.setPressTicks(5000);
|
||||
button2.attachClick(switchToNextScreen);
|
||||
button2.attachLongPressStart(reset_configurations);
|
||||
#endif
|
||||
|
||||
/******** INIT NERDMINER ************/
|
||||
Serial.println("NerdMiner v2 starting......");
|
||||
|
||||
|
||||
/******** INIT DISPLAY ************/
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.setSwapBytes(true);// Swap the colour byte order when rendering
|
||||
background.createSprite(initWidth,initHeight); //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(NotoSans_Bold, sizeof(NotoSans_Bold))) {
|
||||
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers))){
|
||||
Serial.println("Initialise error");
|
||||
return;
|
||||
}
|
||||
initDisplay();
|
||||
|
||||
/******** PRINT INIT SCREEN *****/
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.pushImage(0, 0, initWidth, initHeight, initScreen);
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString(CURRENT_VERSION, 24, 147, FONT2);
|
||||
drawLoadingScreen();
|
||||
delay(2000);
|
||||
|
||||
/******** SHOW LED INIT STATUS (devices without screen) *****/
|
||||
mMonitor.NerdStatus = NM_waitingConfig;
|
||||
#ifdef DEVKITV1
|
||||
doLedStuff(LED_PIN);
|
||||
#endif
|
||||
|
||||
doLedStuff(0);
|
||||
|
||||
/******** INIT WIFI ************/
|
||||
init_WifiManager();
|
||||
|
||||
@ -129,7 +91,7 @@ void setup()
|
||||
Serial.println("Initiating tasks...");
|
||||
char *name = (char*) malloc(32);
|
||||
sprintf(name, "(%s)", "Monitor");
|
||||
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 5000, (void*)name, 4, NULL,1);
|
||||
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)name, 4, NULL,1);
|
||||
|
||||
/******** CREATE STRATUM TASK *****/
|
||||
sprintf(name, "(%s)", "Stratum");
|
||||
@ -168,14 +130,15 @@ void app_error_fault_handler(void *arg) {
|
||||
|
||||
void loop() {
|
||||
// keep watching the push buttons:
|
||||
button1.tick();
|
||||
button2.tick();
|
||||
#ifdef PIN_BUTTON_1
|
||||
button1.tick();
|
||||
#endif
|
||||
|
||||
#ifdef PIN_BUTTON_2
|
||||
button2.tick();
|
||||
#endif
|
||||
|
||||
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
||||
|
||||
#ifdef DEVKITV1
|
||||
doLedStuff(LED_PIN);
|
||||
#endif
|
||||
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
9
src/drivers/devices/esp32DevKit.h
Normal file
9
src/drivers/devices/esp32DevKit.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _ESP32_DEV_KIT_H
|
||||
#define _ESP32_DEV_KIT_H
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define LED_PIN 2
|
||||
|
||||
#define NO_DISPLAY
|
||||
|
||||
#endif
|
9
src/drivers/devices/lilygoS3Amoled.h
Normal file
9
src/drivers/devices/lilygoS3Amoled.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _LILYGO_S3_AMOLED_H
|
||||
#define _LILYGO_S3_AMOLED_H
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 21
|
||||
|
||||
#define AMOLED_DISPLAY
|
||||
|
||||
#endif
|
11
src/drivers/devices/lilygoS3Dongle.h
Normal file
11
src/drivers/devices/lilygoS3Dongle.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _LILYGO_S3_DONGLE_H
|
||||
#define _LILYGO_S3_DONGLE_H
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define LED_DI_PIN 40
|
||||
#define LED_CI_PIN 39
|
||||
|
||||
#define USE_LED
|
||||
#define DONGLE_DISPLAY
|
||||
|
||||
#endif
|
10
src/drivers/devices/lilygoS3TDisplay.h
Normal file
10
src/drivers/devices/lilygoS3TDisplay.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _LILYGO_S3_T_DISPLAY_H
|
||||
#define _LILYGO_S3_T_DISPLAY_H
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 14
|
||||
#define PIN_ENABLE5V 15
|
||||
|
||||
#define T_DISPLAY
|
||||
|
||||
#endif
|
10
src/drivers/devices/nerdMinerV2.h
Normal file
10
src/drivers/devices/nerdMinerV2.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _NERD_MINER_V2_H
|
||||
#define _NERD_MINER_V2_H
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 14
|
||||
#define PIN_ENABLE5V 15
|
||||
|
||||
#define T_DISPLAY
|
||||
|
||||
#endif
|
77
src/drivers/display.cpp
Normal file
77
src/drivers/display.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "display.h"
|
||||
|
||||
#ifdef NO_DISPLAY
|
||||
DisplayDriver *currentDisplayDriver = &noDisplayDriver;
|
||||
#endif
|
||||
|
||||
#ifdef T_DISPLAY
|
||||
DisplayDriver *currentDisplayDriver = &tDisplayDriver;
|
||||
#endif
|
||||
|
||||
#ifdef AMOLED_DISPLAY
|
||||
DisplayDriver *currentDisplayDriver = &amoledDisplayDriver;
|
||||
#endif
|
||||
|
||||
#ifdef DONGLE_DISPLAY
|
||||
DisplayDriver *currentDisplayDriver = &dongleDisplayDriver;
|
||||
#endif
|
||||
|
||||
// Initialize the display
|
||||
void initDisplay()
|
||||
{
|
||||
currentDisplayDriver->initDisplay();
|
||||
}
|
||||
|
||||
// Alternate screen state
|
||||
void alternateScreenState()
|
||||
{
|
||||
currentDisplayDriver->alternateScreenState();
|
||||
}
|
||||
|
||||
// Alternate screen rotation
|
||||
void alternateScreenRotation()
|
||||
{
|
||||
currentDisplayDriver->alternateScreenRotation();
|
||||
}
|
||||
|
||||
// Draw the loading screen
|
||||
void drawLoadingScreen()
|
||||
{
|
||||
currentDisplayDriver->loadingScreen();
|
||||
}
|
||||
|
||||
// Draw the setup screen
|
||||
void drawSetupScreen()
|
||||
{
|
||||
currentDisplayDriver->setupScreen();
|
||||
}
|
||||
|
||||
// Reset the current cyclic screen to the first one
|
||||
void resetToFirstScreen()
|
||||
{
|
||||
currentDisplayDriver->current_cyclic_screen = 0;
|
||||
}
|
||||
|
||||
// Switches to the next cyclic screen without drawing it
|
||||
void switchToNextScreen()
|
||||
{
|
||||
currentDisplayDriver->current_cyclic_screen = (currentDisplayDriver->current_cyclic_screen + 1) % currentDisplayDriver->num_cyclic_screens;
|
||||
}
|
||||
|
||||
// Draw the current cyclic screen
|
||||
void drawCurrentScreen(unsigned long mElapsed)
|
||||
{
|
||||
currentDisplayDriver->cyclic_screens[currentDisplayDriver->current_cyclic_screen](mElapsed);
|
||||
}
|
||||
|
||||
// Animate the current cyclic screen
|
||||
void animateCurrentScreen(unsigned long frame)
|
||||
{
|
||||
currentDisplayDriver->animateCurrentScreen(frame);
|
||||
}
|
||||
|
||||
// Do LED stuff
|
||||
void doLedStuff(unsigned long frame)
|
||||
{
|
||||
currentDisplayDriver->doLedStuff(frame);
|
||||
}
|
19
src/drivers/display.h
Normal file
19
src/drivers/display.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include "drivers.h"
|
||||
|
||||
extern DisplayDriver *currentDisplayDriver;
|
||||
|
||||
void initDisplay();
|
||||
void alternateScreenState();
|
||||
void alternateScreenRotation();
|
||||
void switchToNextScreen();
|
||||
void resetToFirstScreen();
|
||||
void drawLoadingScreen();
|
||||
void drawSetupScreen();
|
||||
void drawCurrentScreen(unsigned long mElapsed);
|
||||
void animateCurrentScreen(unsigned long frame);
|
||||
void doLedStuff(unsigned long frame);
|
||||
|
||||
#endif // DISPLAY_H
|
246
src/drivers/displays/amoledDisplayDriver.cpp
Normal file
246
src/drivers/displays/amoledDisplayDriver.cpp
Normal file
@ -0,0 +1,246 @@
|
||||
#include "../drivers.h"
|
||||
|
||||
#ifdef AMOLED_DISPLAY
|
||||
|
||||
#include <rm67162.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include "media/images_536_240.h"
|
||||
#include "media/myFonts.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "version.h"
|
||||
#include "monitor.h"
|
||||
#include "OpenFontRender.h"
|
||||
|
||||
#define WIDTH 536
|
||||
#define HEIGHT 240
|
||||
|
||||
#define SOURCE_HEIGHT 170
|
||||
|
||||
#define MARGIN_LEFT 42
|
||||
#define SCALE HEIGHT / SOURCE_HEIGHT
|
||||
|
||||
#define X(x) (MARGIN_LEFT + (x * SCALE))
|
||||
#define Y(y) (y * SCALE)
|
||||
#define FS(S) (S * SCALE)
|
||||
|
||||
OpenFontRender render;
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite background = TFT_eSprite(&tft);
|
||||
|
||||
void amoledDisplay_Init(void)
|
||||
{
|
||||
rm67162_init();
|
||||
lcd_setRotation(1);
|
||||
|
||||
background.createSprite(WIDTH, HEIGHT);
|
||||
background.setSwapBytes(true);
|
||||
render.setDrawer(background);
|
||||
render.setLineSpaceRatio(0.9);
|
||||
|
||||
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers)))
|
||||
{
|
||||
Serial.println("Initialise error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int screen_state = 1;
|
||||
void amoledDisplay_AlternateScreenState(void)
|
||||
{
|
||||
screen_state == 1 ? lcd_off() : lcd_on();
|
||||
screen_state ^= 1;
|
||||
}
|
||||
|
||||
int screen_rotation = 1;
|
||||
void amoledDisplay_AlternateRotation(void)
|
||||
{
|
||||
screen_rotation == 1 ? lcd_setRotation(3) : lcd_setRotation(1);
|
||||
screen_rotation ^= 1;
|
||||
}
|
||||
|
||||
void amoledDisplay_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(FS(35));
|
||||
render.setFontColor(TFT_BLACK);
|
||||
|
||||
render.rdrawString(data.currentHashRate.c_str(), X(118), Y(114), TFT_BLACK);
|
||||
// Total hashes
|
||||
render.setFontSize(FS(18));
|
||||
render.rdrawString(data.totalMHashes.c_str(), X(268), Y(138), TFT_BLACK);
|
||||
// Block templates
|
||||
render.setFontSize(FS(18));
|
||||
render.drawString(data.templates.c_str(), X(186), Y(20), 0xDEDB);
|
||||
// Best diff
|
||||
render.drawString(data.bestDiff.c_str(), X(186), Y(48), 0xDEDB);
|
||||
// 32Bit shares
|
||||
render.setFontSize(FS(18));
|
||||
render.drawString(data.completedShares.c_str(), X(186), Y(76), 0xDEDB);
|
||||
// Hores
|
||||
render.setFontSize(FS(14));
|
||||
render.rdrawString(data.timeMining.c_str(), X(315), Y(104), 0xDEDB);
|
||||
|
||||
// Valid Blocks
|
||||
render.setFontSize(FS(24));
|
||||
render.drawString(data.valids.c_str(), X(285), Y(56), 0xDEDB);
|
||||
|
||||
// Print Temp
|
||||
render.setFontSize(FS(10));
|
||||
render.rdrawString(data.temp.c_str(), X(239), Y(1), TFT_BLACK);
|
||||
|
||||
render.setFontSize(FS(4));
|
||||
render.rdrawString(String(0).c_str(), X(244), Y(3), TFT_BLACK);
|
||||
|
||||
// Print Hour
|
||||
render.setFontSize(FS(10));
|
||||
render.rdrawString(data.currentTime.c_str(), X(286), Y(1), TFT_BLACK);
|
||||
|
||||
// Push prepared background to screen
|
||||
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
|
||||
}
|
||||
|
||||
void amoledDisplay_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(FS(25));
|
||||
render.setFontColor(TFT_BLACK);
|
||||
render.rdrawString(data.currentHashRate.c_str(), X(94), Y(129), TFT_BLACK);
|
||||
|
||||
// Print BTC Price
|
||||
background.setFreeFont(FSSB12);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(data.btcPrice.c_str(), X(202), Y(3), GFXFF);
|
||||
|
||||
// Print BlockHeight
|
||||
render.setFontSize(FS(18));
|
||||
render.rdrawString(data.blockHeight.c_str(), X(254), Y(140), TFT_BLACK);
|
||||
|
||||
// Print Hour
|
||||
background.setFreeFont(FF24);
|
||||
background.setTextSize(2);
|
||||
background.setTextColor(0xDEDB, TFT_BLACK);
|
||||
|
||||
background.drawString(data.currentTime.c_str(), X(130), Y(50), GFXFF);
|
||||
|
||||
// Push prepared background to screen
|
||||
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
|
||||
}
|
||||
|
||||
void amoledDisplay_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(FSSB12);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(data.btcPrice.c_str(), X(198), Y(3), GFXFF);
|
||||
|
||||
// Print Hour
|
||||
background.setFreeFont(FSSB12);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(data.currentTime.c_str(), X(268), Y(3), GFXFF);
|
||||
|
||||
// Print Last Pool Block
|
||||
background.setFreeFont(FSS12);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
background.drawString(data.halfHourFee.c_str(), X(302), Y(52), GFXFF);
|
||||
|
||||
// Print Difficulty
|
||||
background.setFreeFont(FSS12);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
background.drawString(data.netwrokDifficulty.c_str(), X(302), Y(88), GFXFF);
|
||||
|
||||
// Print Global Hashrate
|
||||
render.setFontSize(FS(17));
|
||||
render.rdrawString(data.globalHashRate.c_str(), X(274), Y(145), TFT_BLACK);
|
||||
|
||||
// Print BlockHeight
|
||||
render.setFontSize(FS(28));
|
||||
render.rdrawString(data.blockHeight.c_str(), X(140), Y(104), 0xDEDB);
|
||||
|
||||
// Draw percentage rectangle
|
||||
int x2 = 2 + (138 * data.progressPercent / 100);
|
||||
background.fillRect(2, Y(149), X(x2), Y(238), 0xDEDB);
|
||||
|
||||
// Print Remaining BLocks
|
||||
background.setTextFont(FONT4);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(MC_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(data.remainingBlocks.c_str(), X(72), Y(159), FONT2);
|
||||
|
||||
// Push prepared background to screen
|
||||
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
|
||||
}
|
||||
|
||||
void amoledDisplay_LoadingScreen(void)
|
||||
{
|
||||
background.fillScreen(TFT_BLACK);
|
||||
background.pushImage(0, 0, initWidth, initHeight, initScreen);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(CURRENT_VERSION, X(24), Y(147), FONT2);
|
||||
|
||||
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
|
||||
}
|
||||
|
||||
void amoledDisplay_SetupScreen(void)
|
||||
{
|
||||
background.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen);
|
||||
|
||||
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
|
||||
}
|
||||
|
||||
void amoledDisplay_AnimateCurrentScreen(unsigned long frame)
|
||||
{
|
||||
}
|
||||
|
||||
void amoledDisplay_DoLedStuff(unsigned long frame)
|
||||
{
|
||||
}
|
||||
|
||||
CyclicScreenFunction amoledDisplayCyclicScreens[] = {amoledDisplay_MinerScreen, amoledDisplay_ClockScreen, amoledDisplay_GlobalHashScreen};
|
||||
|
||||
DisplayDriver amoledDisplayDriver = {
|
||||
amoledDisplay_Init,
|
||||
amoledDisplay_AlternateScreenState,
|
||||
amoledDisplay_AlternateRotation,
|
||||
amoledDisplay_LoadingScreen,
|
||||
amoledDisplay_SetupScreen,
|
||||
amoledDisplayCyclicScreens,
|
||||
amoledDisplay_AnimateCurrentScreen,
|
||||
amoledDisplay_DoLedStuff,
|
||||
SCREENS_ARRAY_SIZE(amoledDisplayCyclicScreens),
|
||||
0,
|
||||
WIDTH,
|
||||
HEIGHT};
|
||||
#endif
|
212
src/drivers/displays/dongleDisplayDriver.cpp
Normal file
212
src/drivers/displays/dongleDisplayDriver.cpp
Normal file
@ -0,0 +1,212 @@
|
||||
#include "../drivers.h"
|
||||
|
||||
#ifdef DONGLE_DISPLAY
|
||||
|
||||
#include <TFT_eSPI.h>
|
||||
#include "media/images_160_80.h"
|
||||
#include "media/myFonts.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "version.h"
|
||||
#include "monitor.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include <FastLED.h>
|
||||
|
||||
#define WIDTH 160
|
||||
#define HEIGHT 80
|
||||
|
||||
#define BUFFER_WIDTH MinerWidth
|
||||
#define BUFFER_HEIGHT MinerHeight
|
||||
|
||||
#define SCROLL_SPEED 2
|
||||
int pos_y = 0;
|
||||
int delta_y = SCROLL_SPEED;
|
||||
int max_y = BUFFER_HEIGHT - HEIGHT;
|
||||
|
||||
OpenFontRender render;
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite background = TFT_eSprite(&tft);
|
||||
|
||||
#define MAX_BRIGHTNESS 16
|
||||
#define SLOW_FADE 1;
|
||||
#define FAST_FADE 4;
|
||||
|
||||
CRGB leds(0, 0, 0);
|
||||
int brightness = 0;
|
||||
int fadeDirection = 1;
|
||||
int fadeAmount = 0;
|
||||
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
#define BACK_COLOR TFT_BLACK
|
||||
#define VALUE_COLOR TFT_WHITE
|
||||
#define KEY_COLOR TFT_WHITE
|
||||
|
||||
#define RESET_SCREEN() \
|
||||
int32_t x = 8, y = 8; \
|
||||
background.setTextSize(1); \
|
||||
background.setTextFont(FONT2); \
|
||||
\
|
||||
background.setTextColor(KEY_COLOR); \
|
||||
\
|
||||
render.setFontSize(18);
|
||||
|
||||
#define CLEAR_SCREEN() \
|
||||
RESET_SCREEN(); \
|
||||
background.fillRect(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT, BACK_COLOR); \
|
||||
\
|
||||
|
||||
|
||||
#define PRINT_STR(str) \
|
||||
{ \
|
||||
background.drawString(String(str).c_str(), x, y); \
|
||||
y += 32; \
|
||||
max_y = y; \
|
||||
}
|
||||
|
||||
#define PRINT_VALUE(value) \
|
||||
{ \
|
||||
render.drawString(String(value).c_str(), x, y, VALUE_COLOR); \
|
||||
y += 27; \
|
||||
}
|
||||
|
||||
#define PUSH_SCREEN() \
|
||||
background.pushSprite(0, 0);
|
||||
|
||||
void dongleDisplay_Init(void)
|
||||
{
|
||||
FastLED.addLeds<APA102, LED_DI_PIN, LED_CI_PIN, BGR>(&leds, 1);
|
||||
FastLED.show();
|
||||
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
tft.setSwapBytes(true);
|
||||
background.createSprite(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
background.setSwapBytes(true);
|
||||
render.setDrawer(background);
|
||||
render.setLineSpaceRatio(0.9);
|
||||
|
||||
// Load the font and check it can be read OK
|
||||
// if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) {
|
||||
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers)))
|
||||
{
|
||||
Serial.println("Initialise error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dongleDisplay_AlternateScreenState(void)
|
||||
{
|
||||
}
|
||||
|
||||
void dongleDisplay_AlternateRotation(void)
|
||||
{
|
||||
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
|
||||
}
|
||||
|
||||
void dongleDisplay_MinerScreen(unsigned long mElapsed)
|
||||
{
|
||||
max_y = BUFFER_HEIGHT;
|
||||
mining_data data = getMiningData(mElapsed);
|
||||
|
||||
// Print background screen
|
||||
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());
|
||||
|
||||
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
||||
RESET_SCREEN();
|
||||
x = 74;
|
||||
y = 15;
|
||||
render.setFontSize(20);
|
||||
PRINT_VALUE(data.currentTime);
|
||||
|
||||
render.setFontSize(18);
|
||||
x = 68;
|
||||
y = 51;
|
||||
PRINT_VALUE(data.currentHashRate);
|
||||
PRINT_VALUE(data.valids);
|
||||
PRINT_VALUE(data.templates);
|
||||
PRINT_VALUE(data.bestDiff);
|
||||
PRINT_VALUE(data.completedShares);
|
||||
PRINT_VALUE(data.totalMHashes);
|
||||
PRINT_VALUE(data.temp);
|
||||
}
|
||||
|
||||
void dongleDisplay_LoadingScreen(void)
|
||||
{
|
||||
CLEAR_SCREEN();
|
||||
PRINT_STR("Initializing...");
|
||||
PUSH_SCREEN();
|
||||
}
|
||||
|
||||
void dongleDisplay_SetupScreen(void)
|
||||
{
|
||||
CLEAR_SCREEN();
|
||||
PRINT_STR("Use WiFi for setup...");
|
||||
PUSH_SCREEN();
|
||||
}
|
||||
|
||||
void dongleDisplay_AnimateCurrentScreen(unsigned long frame)
|
||||
{
|
||||
if (pos_y > max_y)
|
||||
{
|
||||
pos_y = 0;
|
||||
}
|
||||
if (pos_y > max_y - HEIGHT)
|
||||
{
|
||||
background.pushSprite(0, max_y - pos_y);
|
||||
}
|
||||
pos_y += delta_y;
|
||||
background.pushSprite(0, -pos_y);
|
||||
}
|
||||
|
||||
void dongleDisplay_DoLedStuff(unsigned long frame)
|
||||
{
|
||||
#ifdef USE_LED
|
||||
switch (mMonitor.NerdStatus)
|
||||
{
|
||||
case NM_waitingConfig:
|
||||
brightness = MAX_BRIGHTNESS;
|
||||
leds.setRGB(255, 255, 0);
|
||||
fadeAmount = 0;
|
||||
break;
|
||||
|
||||
case NM_Connecting:
|
||||
leds.setRGB(0, 0, 255);
|
||||
fadeAmount = SLOW_FADE;
|
||||
break;
|
||||
|
||||
case NM_hashing:
|
||||
leds.setRGB(0, 0, 255);
|
||||
fadeAmount = FAST_FADE;
|
||||
break;
|
||||
}
|
||||
|
||||
leds.fadeLightBy(0xFF - brightness);
|
||||
FastLED.show();
|
||||
|
||||
brightness = brightness + (fadeDirection * fadeAmount);
|
||||
if (brightness <= 0 || brightness >= MAX_BRIGHTNESS)
|
||||
{
|
||||
fadeDirection = -fadeDirection;
|
||||
}
|
||||
brightness = constrain(brightness, 0, MAX_BRIGHTNESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
CyclicScreenFunction dongleDisplayCyclicScreens[] = {dongleDisplay_MinerScreen};
|
||||
|
||||
DisplayDriver dongleDisplayDriver = {
|
||||
dongleDisplay_Init,
|
||||
dongleDisplay_AlternateScreenState,
|
||||
dongleDisplay_AlternateRotation,
|
||||
dongleDisplay_LoadingScreen,
|
||||
dongleDisplay_SetupScreen,
|
||||
dongleDisplayCyclicScreens,
|
||||
dongleDisplay_AnimateCurrentScreen,
|
||||
dongleDisplay_DoLedStuff,
|
||||
SCREENS_ARRAY_SIZE(dongleDisplayCyclicScreens),
|
||||
0,
|
||||
WIDTH,
|
||||
HEIGHT};
|
||||
|
||||
#endif
|
104
src/drivers/displays/noDisplayDriver.cpp
Normal file
104
src/drivers/displays/noDisplayDriver.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "../drivers.h"
|
||||
|
||||
#ifdef NO_DISPLAY
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "monitor.h"
|
||||
#include "wManager.h"
|
||||
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
void noDisplay_Init(void)
|
||||
{
|
||||
Serial.println("No display driver initialized");
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
void noDisplay_AlternateScreenState(void)
|
||||
{
|
||||
}
|
||||
|
||||
void noDisplay_AlternateRotation(void)
|
||||
{
|
||||
}
|
||||
|
||||
void noDisplay_NoScreen(unsigned long mElapsed)
|
||||
{
|
||||
mining_data data = getMiningData(mElapsed);
|
||||
|
||||
// Print hashrate to serial
|
||||
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 extended data to serial for no display devices
|
||||
Serial.printf(">>> Valid blocks: %s\n", data.valids.c_str());
|
||||
Serial.printf(">>> Block templates: %s\n", data.templates.c_str());
|
||||
Serial.printf(">>> Best difficulty: %s\n", data.bestDiff.c_str());
|
||||
Serial.printf(">>> 32Bit shares: %s\n", data.completedShares.c_str());
|
||||
Serial.printf(">>> Temperature: %s\n", data.temp.c_str());
|
||||
Serial.printf(">>> Total MHashes: %s\n", data.totalMHashes.c_str());
|
||||
Serial.printf(">>> Time mining: %s\n", data.timeMining.c_str());
|
||||
}
|
||||
void noDisplay_LoadingScreen(void)
|
||||
{
|
||||
Serial.println("Initializing...");
|
||||
}
|
||||
|
||||
void noDisplay_SetupScreen(void)
|
||||
{
|
||||
Serial.println("Setup...");
|
||||
}
|
||||
|
||||
// Variables para controlar el parpadeo con millis()
|
||||
unsigned long previousMillis = 0;
|
||||
|
||||
void noDisplay_DoLedStuff(unsigned long frame)
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
switch (mMonitor.NerdStatus)
|
||||
{
|
||||
|
||||
case NM_waitingConfig:
|
||||
digitalWrite(LED_PIN, HIGH); // LED encendido de forma continua
|
||||
break;
|
||||
|
||||
case NM_Connecting:
|
||||
if (currentMillis - previousMillis >= 500)
|
||||
{ // 0.5sec blink
|
||||
previousMillis = currentMillis;
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED
|
||||
}
|
||||
break;
|
||||
|
||||
case NM_hashing:
|
||||
if (currentMillis - previousMillis >= 100)
|
||||
{ // 0.1sec blink
|
||||
previousMillis = currentMillis;
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Cambia el estado del LED
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void noDisplay_AnimateCurrentScreen(unsigned long frame)
|
||||
{
|
||||
}
|
||||
|
||||
CyclicScreenFunction noDisplayCyclicScreens[] = {noDisplay_NoScreen};
|
||||
|
||||
DisplayDriver noDisplayDriver = {
|
||||
noDisplay_Init,
|
||||
noDisplay_AlternateScreenState,
|
||||
noDisplay_AlternateRotation,
|
||||
noDisplay_LoadingScreen,
|
||||
noDisplay_SetupScreen,
|
||||
noDisplayCyclicScreens,
|
||||
noDisplay_AnimateCurrentScreen,
|
||||
noDisplay_DoLedStuff,
|
||||
SCREENS_ARRAY_SIZE(noDisplayCyclicScreens),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
#endif
|
234
src/drivers/displays/tDisplayDriver.cpp
Normal file
234
src/drivers/displays/tDisplayDriver.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
#include "../drivers.h"
|
||||
|
||||
#ifdef T_DISPLAY
|
||||
|
||||
#include <TFT_eSPI.h>
|
||||
#include "media/images_320_170.h"
|
||||
#include "media/myFonts.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "version.h"
|
||||
#include "monitor.h"
|
||||
#include "OpenFontRender.h"
|
||||
|
||||
#define WIDTH 340
|
||||
#define HEIGHT 170
|
||||
|
||||
OpenFontRender render;
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
|
||||
|
||||
void tDisplay_Init(void)
|
||||
{
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
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(NotoSans_Bold, sizeof(NotoSans_Bold))) {
|
||||
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers)))
|
||||
{
|
||||
Serial.println("Initialise error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void tDisplay_AlternateScreenState(void)
|
||||
{
|
||||
int screen_state = digitalRead(TFT_BL);
|
||||
Serial.println("Switching display state");
|
||||
digitalWrite(TFT_BL, !screen_state);
|
||||
}
|
||||
|
||||
void tDisplay_AlternateRotation(void)
|
||||
{
|
||||
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
|
||||
}
|
||||
|
||||
void tDisplay_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(35);
|
||||
render.setCursor(19, 118);
|
||||
render.setFontColor(TFT_BLACK);
|
||||
|
||||
render.rdrawString(data.currentHashRate.c_str(), 118, 114, TFT_BLACK);
|
||||
// Total hashes
|
||||
render.setFontSize(18);
|
||||
render.rdrawString(data.totalMHashes.c_str(), 268, 138, TFT_BLACK);
|
||||
// Block templates
|
||||
render.setFontSize(18);
|
||||
render.drawString(data.templates.c_str(), 186, 20, 0xDEDB);
|
||||
// Best diff
|
||||
render.drawString(data.bestDiff.c_str(), 186, 48, 0xDEDB);
|
||||
// 32Bit shares
|
||||
render.setFontSize(18);
|
||||
render.drawString(data.completedShares.c_str(), 186, 76, 0xDEDB);
|
||||
// Hores
|
||||
render.setFontSize(14);
|
||||
render.rdrawString(data.timeMining.c_str(), 315, 104, 0xDEDB);
|
||||
|
||||
// Valid Blocks
|
||||
render.setFontSize(24);
|
||||
render.drawString(data.valids.c_str(), 285, 56, 0xDEDB);
|
||||
|
||||
// Print Temp
|
||||
render.setFontSize(10);
|
||||
render.rdrawString(data.temp.c_str(), 239, 1, TFT_BLACK);
|
||||
|
||||
render.setFontSize(4);
|
||||
render.rdrawString(String(0).c_str(), 244, 3, TFT_BLACK);
|
||||
|
||||
// Print Hour
|
||||
render.setFontSize(10);
|
||||
render.rdrawString(data.currentTime.c_str(), 286, 1, TFT_BLACK);
|
||||
|
||||
// Push prepared background to screen
|
||||
background.pushSprite(0, 0);
|
||||
}
|
||||
|
||||
void tDisplay_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(25);
|
||||
render.setCursor(19, 122);
|
||||
render.setFontColor(TFT_BLACK);
|
||||
render.rdrawString(data.currentHashRate.c_str(), 94, 129, 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(), 202, 3, GFXFF);
|
||||
|
||||
// Print BlockHeight
|
||||
render.setFontSize(18);
|
||||
render.rdrawString(data.blockHeight.c_str(), 254, 140, TFT_BLACK);
|
||||
|
||||
// Print Hour
|
||||
background.setFreeFont(FF23);
|
||||
background.setTextSize(2);
|
||||
background.setTextColor(0xDEDB, TFT_BLACK);
|
||||
|
||||
background.drawString(data.currentTime.c_str(), 130, 50, GFXFF);
|
||||
|
||||
// Push prepared background to screen
|
||||
background.pushSprite(0, 0);
|
||||
}
|
||||
|
||||
void tDisplay_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(), 198, 3, GFXFF);
|
||||
|
||||
// Print Hour
|
||||
background.setFreeFont(FSSB9);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(data.currentTime.c_str(), 268, 3, GFXFF);
|
||||
|
||||
// Print Last Pool Block
|
||||
background.setFreeFont(FSS9);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
background.drawString(data.halfHourFee.c_str(), 302, 52, GFXFF);
|
||||
|
||||
// Print Difficulty
|
||||
background.setFreeFont(FSS9);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
background.drawString(data.netwrokDifficulty.c_str(), 302, 88, GFXFF);
|
||||
|
||||
// Print Global Hashrate
|
||||
render.setFontSize(17);
|
||||
render.rdrawString(data.globalHashRate.c_str(), 274, 145, TFT_BLACK);
|
||||
|
||||
// Print BlockHeight
|
||||
render.setFontSize(28);
|
||||
render.rdrawString(data.blockHeight.c_str(), 140, 104, 0xDEDB);
|
||||
|
||||
// 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(), 72, 159, FONT2);
|
||||
|
||||
// Push prepared background to screen
|
||||
background.pushSprite(0, 0);
|
||||
}
|
||||
|
||||
void tDisplay_LoadingScreen(void)
|
||||
{
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.pushImage(0, 0, initWidth, initHeight, initScreen);
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString(CURRENT_VERSION, 24, 147, FONT2);
|
||||
}
|
||||
|
||||
void tDisplay_SetupScreen(void)
|
||||
{
|
||||
tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen);
|
||||
}
|
||||
|
||||
void tDisplay_AnimateCurrentScreen(unsigned long frame)
|
||||
{
|
||||
}
|
||||
|
||||
void tDisplay_DoLedStuff(unsigned long frame)
|
||||
{
|
||||
}
|
||||
|
||||
CyclicScreenFunction tDisplayCyclicScreens[] = {tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen};
|
||||
|
||||
DisplayDriver tDisplayDriver = {
|
||||
tDisplay_Init,
|
||||
tDisplay_AlternateScreenState,
|
||||
tDisplay_AlternateRotation,
|
||||
tDisplay_LoadingScreen,
|
||||
tDisplay_SetupScreen,
|
||||
tDisplayCyclicScreens,
|
||||
tDisplay_AnimateCurrentScreen,
|
||||
tDisplay_DoLedStuff,
|
||||
SCREENS_ARRAY_SIZE(tDisplayCyclicScreens),
|
||||
0,
|
||||
WIDTH,
|
||||
HEIGHT};
|
||||
#endif
|
50
src/drivers/drivers.h
Normal file
50
src/drivers/drivers.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef DRIVERS_H
|
||||
#define DRIVERS_H
|
||||
|
||||
#if defined(NERDMINERV2)
|
||||
#include "devices/nerdMinerV2.h"
|
||||
#elif defined(DEVKITV1)
|
||||
#include "devices/esp32DevKit.h"
|
||||
#elif defined(TDISPLAY)
|
||||
#include "devices/lilygoS3TDisplay.h"
|
||||
#elif defined(NERMINER_S3_AMOLED)
|
||||
#include "devices/lilygoS3Amoled.h"
|
||||
#elif defined(NERMINER_S3_DONGLE)
|
||||
#include "devices/lilygoS3Dongle.h"
|
||||
#else
|
||||
#error "No device defined"
|
||||
#endif
|
||||
|
||||
typedef void (*AlternateFunction)(void);
|
||||
typedef void (*DriverInitFunction)(void);
|
||||
typedef void (*ScreenFunction)(void);
|
||||
typedef void (*CyclicScreenFunction)(unsigned long mElapsed);
|
||||
typedef void (*AnimateCurrentScreenFunction)(unsigned long frame);
|
||||
typedef void (*DoLedStuff)(unsigned long frame);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DriverInitFunction initDisplay; // Initialize the display
|
||||
AlternateFunction alternateScreenState; // Alternate screen state
|
||||
AlternateFunction alternateScreenRotation; // Alternate screen rotation
|
||||
ScreenFunction loadingScreen; // Explicit loading screen
|
||||
ScreenFunction setupScreen; // Explicit setup screen
|
||||
CyclicScreenFunction *cyclic_screens; // Array of cyclic screens
|
||||
AnimateCurrentScreenFunction animateCurrentScreen; // Animate the current cyclic screen
|
||||
DoLedStuff doLedStuff; // Do LED stuff
|
||||
int num_cyclic_screens; // Number of cyclic screens
|
||||
int current_cyclic_screen; // Current cyclic screen being displayed
|
||||
int screenWidth; // Screen width
|
||||
int screenHeight; // Screen height
|
||||
} DisplayDriver;
|
||||
|
||||
extern DisplayDriver *currentDisplayDriver;
|
||||
|
||||
extern DisplayDriver noDisplayDriver;
|
||||
extern DisplayDriver tDisplayDriver;
|
||||
extern DisplayDriver amoledDisplayDriver;
|
||||
extern DisplayDriver dongleDisplayDriver;
|
||||
|
||||
#define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
#endif // DRIVERS_H
|
2427
src/media/images_160_80.h
Normal file
2427
src/media/images_160_80.h
Normal file
File diff suppressed because it is too large
Load Diff
40235
src/media/images_536_240.h
Normal file
40235
src/media/images_536_240.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,16 +2,13 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include "ShaTests/nerdSHA256.h"
|
||||
//#include "ShaTests/nerdSHA256plus.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "media/images.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include "stratum.h"
|
||||
#include "mining.h"
|
||||
#include "utils.h"
|
||||
#include "monitor.h"
|
||||
#include "drivers/display.h"
|
||||
|
||||
unsigned long templates = 0;
|
||||
unsigned long hashes= 0;
|
||||
@ -31,9 +28,6 @@ extern int portNumber;
|
||||
extern char btcString[80];
|
||||
IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres
|
||||
|
||||
extern OpenFontRender render;
|
||||
extern TFT_eSprite background;
|
||||
|
||||
//Global work data
|
||||
static WiFiClient client;
|
||||
static miner_data mMiner; //Global miner data (Create a miner class TODO)
|
||||
@ -378,42 +372,50 @@ void runMiner(void * task_id) {
|
||||
}
|
||||
}
|
||||
|
||||
void runMonitor(void *name){
|
||||
#define DELAY 100
|
||||
#define REDRAW_EVERY 10
|
||||
|
||||
void runMonitor(void *name)
|
||||
{
|
||||
|
||||
Serial.println("[MONITOR] started");
|
||||
|
||||
|
||||
unsigned long mLastCheck = 0;
|
||||
mMonitor.screen = SCREEN_MINING;
|
||||
|
||||
#ifdef DEVKITV1
|
||||
mMonitor.screen = NO_SCREEN;
|
||||
#endif
|
||||
resetToFirstScreen();
|
||||
|
||||
while(1){
|
||||
|
||||
|
||||
unsigned long mElapsed = millis()-mLastCheck;
|
||||
mLastCheck = millis();
|
||||
unsigned long currentKHashes = (Mhashes*1000) + hashes/1000;
|
||||
elapsedKHs = currentKHashes - totalKHashes;
|
||||
totalKHashes = currentKHashes;
|
||||
|
||||
switch(mMonitor.screen){
|
||||
case SCREEN_MINING: show_MinerScreen(mElapsed); break;
|
||||
case SCREEN_CLOCK: show_ClockScreen(mElapsed); break;
|
||||
case SCREEN_GLOBAL: show_GlobalHashScreen(mElapsed); break;
|
||||
case NO_SCREEN: show_NoScreen(mElapsed); break;
|
||||
}
|
||||
|
||||
//Monitor state when hashrate is 0.0
|
||||
if(elapsedKHs == 0) {
|
||||
Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n",
|
||||
mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false",
|
||||
client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false");
|
||||
unsigned long frame = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((frame % REDRAW_EVERY) == 0)
|
||||
{
|
||||
unsigned long mElapsed = millis() - mLastCheck;
|
||||
mLastCheck = millis();
|
||||
unsigned long currentKHashes = (Mhashes * 1000) + hashes / 1000;
|
||||
elapsedKHs = currentKHashes - totalKHashes;
|
||||
totalKHashes = currentKHashes;
|
||||
|
||||
drawCurrentScreen(mElapsed);
|
||||
|
||||
// Monitor state when hashrate is 0.0
|
||||
if (elapsedKHs == 0)
|
||||
{
|
||||
Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n",
|
||||
mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false",
|
||||
client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false");
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap());
|
||||
Serial.printf("### Max stack usage: %d\n", uxTaskGetStackHighWaterMark(NULL));
|
||||
#endif
|
||||
}
|
||||
animateCurrentScreen(frame);
|
||||
doLedStuff(frame);
|
||||
|
||||
// Pause the task for 1000ms
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(DELAY / portTICK_PERIOD_MS);
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
|
||||
|
313
src/monitor.cpp
313
src/monitor.cpp
@ -1,10 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "media/images.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include "HTTPClient.h"
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
@ -24,8 +20,6 @@ extern unsigned int valids; // increased if blockhash <= target
|
||||
|
||||
extern double best_diff; // track best diff
|
||||
|
||||
extern OpenFontRender render;
|
||||
extern TFT_eSprite background;
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
extern int GMTzone; //Gotten from saved config
|
||||
@ -61,7 +55,7 @@ void updateGlobalData(void){
|
||||
http.begin(getGlobalHash);
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
String payload = http.getString();
|
||||
|
||||
DynamicJsonDocument doc(1024);
|
||||
@ -81,33 +75,12 @@ void updateGlobalData(void){
|
||||
}
|
||||
http.end();
|
||||
|
||||
|
||||
//OLD code gets remaining blocks to next difficulty ajustment
|
||||
/*//Make second API call to get remaining Blocks
|
||||
http.begin(getDifficulty);
|
||||
httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
String payload = http.getString();
|
||||
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, payload);
|
||||
String temp = "";
|
||||
if (doc.containsKey("progressPercent")) gData.progressPercent = doc["progressPercent"].as<float>();
|
||||
if (doc.containsKey("remainingBlocks")) gData.remainingBlocks = doc["remainingBlocks"].as<int>();
|
||||
|
||||
doc.clear();
|
||||
|
||||
mGlobalUpdate = millis();
|
||||
}
|
||||
|
||||
http.end();*/
|
||||
|
||||
|
||||
//Make third API call to get fees
|
||||
http.begin(getFees);
|
||||
httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
String payload = http.getString();
|
||||
|
||||
DynamicJsonDocument doc(1024);
|
||||
@ -137,7 +110,7 @@ String getBlockHeight(void){
|
||||
http.begin(getHeightAPI);
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
String payload = http.getString();
|
||||
payload.trim();
|
||||
|
||||
@ -165,7 +138,7 @@ String getBTCprice(void){
|
||||
http.begin(getBTCAPI);
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
String payload = http.getString();
|
||||
|
||||
DynamicJsonDocument doc(1024);
|
||||
@ -214,235 +187,75 @@ String getTime(void){
|
||||
return LocalHour;
|
||||
}
|
||||
|
||||
void changeScreen(void){
|
||||
mMonitor.screen++;
|
||||
if(mMonitor.screen> SCREEN_GLOBAL) mMonitor.screen = SCREEN_MINING;
|
||||
String getCurrentHashRate(unsigned long mElapsed)
|
||||
{
|
||||
return String((1.0 * (elapsedKHs * 1000)) / mElapsed, 2);
|
||||
}
|
||||
|
||||
void show_NoScreen(unsigned long mElapsed){
|
||||
char CurrentHashrate[10] = {0};
|
||||
sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed);
|
||||
mining_data getMiningData(unsigned long mElapsed)
|
||||
{
|
||||
mining_data data;
|
||||
|
||||
//Print hashrate to serial
|
||||
Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n",
|
||||
shares, totalKHashes, CurrentHashrate);
|
||||
char best_diff_string[16] = {0};
|
||||
suffix_string(best_diff, best_diff_string, 16, 0);
|
||||
|
||||
char timeMining[15] = {0};
|
||||
unsigned long secElapsed = millis() / 1000;
|
||||
int days = secElapsed / 86400;
|
||||
int hours = (secElapsed - (days * 86400)) / 3600; // Number of seconds in an hour
|
||||
int mins = (secElapsed - (days * 86400) - (hours * 3600)) / 60; // Remove the number of hours and calculate the minutes.
|
||||
int secs = secElapsed - (days * 86400) - (hours * 3600) - (mins * 60);
|
||||
sprintf(timeMining, "%01d %02d:%02d:%02d", days, hours, mins, secs);
|
||||
|
||||
data.completedShares = shares;
|
||||
data.totalMHashes = Mhashes;
|
||||
data.totalKHashes = totalKHashes;
|
||||
data.currentHashRate = getCurrentHashRate(mElapsed);
|
||||
data.templates = templates;
|
||||
data.bestDiff = best_diff_string;
|
||||
data.timeMining = timeMining;
|
||||
data.valids = valids;
|
||||
data.temp = String(temperatureRead(), 0);
|
||||
data.currentTime = getTime();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void show_MinerScreen(unsigned long mElapsed){
|
||||
clock_data getClockData(unsigned long mElapsed)
|
||||
{
|
||||
clock_data data;
|
||||
|
||||
//Print background screen
|
||||
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
||||
data.completedShares = shares;
|
||||
data.totalKHashes = totalKHashes;
|
||||
data.currentHashRate = getCurrentHashRate(mElapsed);
|
||||
data.btcPrice = getBTCprice();
|
||||
data.blockHeight = getBlockHeight();
|
||||
data.currentTime = getTime();
|
||||
|
||||
char CurrentHashrate[10] = {0};
|
||||
sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed);
|
||||
|
||||
//Serial.println("[runMonitor Task] -> Printing results on screen ");
|
||||
|
||||
Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n",
|
||||
shares, totalKHashes, CurrentHashrate);
|
||||
|
||||
//Hashrate
|
||||
render.setFontSize(35);
|
||||
render.setCursor(19, 118);
|
||||
render.setFontColor(TFT_BLACK);
|
||||
|
||||
render.rdrawString(CurrentHashrate, 118, 114, TFT_BLACK);
|
||||
//Total hashes
|
||||
render.setFontSize(18);
|
||||
render.rdrawString(String(Mhashes).c_str(), 268, 138, TFT_BLACK);
|
||||
//Block templates
|
||||
render.setFontSize(18);
|
||||
render.drawString(String(templates).c_str(), 186, 20, 0xDEDB);
|
||||
//Best diff
|
||||
char best_diff_string[16] = {0};
|
||||
suffix_string(best_diff, best_diff_string, 16, 0);
|
||||
render.setFontSize(18);
|
||||
render.drawString(String(best_diff_string).c_str(), 186, 48, 0xDEDB);
|
||||
//32Bit shares
|
||||
render.setFontSize(18);
|
||||
render.drawString(String(shares).c_str(), 186, 76, 0xDEDB);
|
||||
//Hores
|
||||
char timeMining[15];
|
||||
|
||||
unsigned long secElapsed = millis() / 1000;
|
||||
int days = secElapsed / 86400;
|
||||
int hours = (secElapsed - (days * 86400)) / 3600; //Number of seconds in an hour
|
||||
int mins = (secElapsed - (days * 86400) - (hours * 3600)) / 60; //Remove the number of hours and calculate the minutes.
|
||||
int secs = secElapsed - (days * 86400) - (hours * 3600) - (mins * 60);
|
||||
sprintf(timeMining, "%01d %02d:%02d:%02d", days, hours, mins, secs);
|
||||
render.setFontSize(14);
|
||||
render.rdrawString(String(timeMining).c_str(), 315, 104, 0xDEDB);
|
||||
|
||||
//Valid Blocks
|
||||
render.setFontSize(24);
|
||||
render.drawString(String(valids).c_str(), 285, 56, 0xDEDB);
|
||||
|
||||
//Print Temp
|
||||
String temp = String(temperatureRead(), 0);
|
||||
render.setFontSize(10);
|
||||
render.rdrawString(String(temp).c_str(), 239, 1, TFT_BLACK);
|
||||
|
||||
render.setFontSize(4);
|
||||
render.rdrawString(String(0).c_str(), 244, 3, TFT_BLACK);
|
||||
|
||||
//Print Hour
|
||||
render.setFontSize(10);
|
||||
render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK);
|
||||
|
||||
// pool url
|
||||
/*background.setTextSize(1);
|
||||
background.setTextDatum(MC_DATUM);
|
||||
background.setTextColor(0xDEDB);
|
||||
background.drawString(String(poolString), 59, 85, FONT2);*/
|
||||
|
||||
//Push prepared background to screen
|
||||
background.pushSprite(0,0);
|
||||
return data;
|
||||
}
|
||||
|
||||
coin_data getCoinData(unsigned long mElapsed)
|
||||
{
|
||||
coin_data data;
|
||||
|
||||
void show_ClockScreen(unsigned long mElapsed){
|
||||
updateGlobalData(); // Update gData vars asking mempool APIs
|
||||
|
||||
//Print background screen
|
||||
background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen);
|
||||
data.completedShares = shares;
|
||||
data.totalKHashes = totalKHashes;
|
||||
data.currentHashRate = getCurrentHashRate(mElapsed);
|
||||
data.btcPrice = getBTCprice();
|
||||
data.currentTime = getTime();
|
||||
data.halfHourFee = String(gData.halfHourFee) + " sat/vB";
|
||||
data.netwrokDifficulty = gData.difficulty;
|
||||
data.globalHashRate = gData.globalHash;
|
||||
data.blockHeight = getBlockHeight();
|
||||
|
||||
char CurrentHashrate[10] = {0};
|
||||
sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed);
|
||||
unsigned long currentBlock = data.blockHeight.toInt();
|
||||
unsigned long remainingBlocks = (((currentBlock / HALVING_BLOCKS) + 1) * HALVING_BLOCKS) - currentBlock;
|
||||
data.progressPercent = (HALVING_BLOCKS - remainingBlocks) * 100 / HALVING_BLOCKS;
|
||||
data.remainingBlocks = String(remainingBlocks) + " BLOCKS";
|
||||
|
||||
//Serial.println("[runMonitor Task] -> Printing results on screen ");
|
||||
|
||||
Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n",
|
||||
shares, totalKHashes, CurrentHashrate);
|
||||
|
||||
//Hashrate
|
||||
render.setFontSize(25);
|
||||
render.setCursor(19, 122);
|
||||
render.setFontColor(TFT_BLACK);
|
||||
|
||||
render.rdrawString(CurrentHashrate, 94, 129, TFT_BLACK);
|
||||
|
||||
//Print BTC Price
|
||||
//render.setFontSize(22);
|
||||
//render.drawString(getBTCprice().c_str(), 202, 3, TFT_BLACK);
|
||||
background.setFreeFont(FSSB9);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(getBTCprice().c_str(), 202, 3, GFXFF);
|
||||
|
||||
//Print BlockHeight
|
||||
render.setFontSize(18);
|
||||
render.rdrawString(getBlockHeight().c_str(), 254, 140, TFT_BLACK);
|
||||
|
||||
//Print Hour
|
||||
background.setFreeFont(FF23);
|
||||
background.setTextSize(2);
|
||||
background.setTextColor(0xDEDB, TFT_BLACK);
|
||||
|
||||
//background.setTexSize(2);
|
||||
background.drawString(getTime().c_str(), 130, 50, GFXFF);
|
||||
//render.setFontColor(TFT_WHITE);
|
||||
//render.setFontSize(110);
|
||||
//render.rdrawString(getTime().c_str(), 290, 40, TFT_WHITE);
|
||||
|
||||
//Push prepared background to screen
|
||||
background.pushSprite(0,0);
|
||||
}
|
||||
|
||||
void show_GlobalHashScreen(unsigned long mElapsed){
|
||||
|
||||
//Print background screen
|
||||
background.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen);
|
||||
|
||||
char CurrentHashrate[10] = {0};
|
||||
sprintf(CurrentHashrate, "%.2f", (1.0*(elapsedKHs*1000))/mElapsed);
|
||||
|
||||
//Serial.println("[runMonitor Task] -> Printing results on screen ");
|
||||
|
||||
Serial.printf(">>> Completed %d share(s), %d Khashes, avg. hashrate %s KH/s\n",
|
||||
shares, totalKHashes, CurrentHashrate);
|
||||
|
||||
//Hashrate
|
||||
updateGlobalData(); //Update gData vars asking mempool APIs
|
||||
|
||||
//Print BTC Price
|
||||
background.setFreeFont(FSSB9);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(getBTCprice().c_str(), 198, 3, GFXFF);
|
||||
|
||||
//Print Hour
|
||||
background.setFreeFont(FSSB9);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(TL_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
background.drawString(getTime().c_str(), 268, 3, GFXFF);
|
||||
|
||||
//Print Last Pool Block
|
||||
background.setFreeFont(FSS9);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
String temp = String(gData.halfHourFee) + " sat/vB";
|
||||
background.drawString(temp.c_str(), 302, 52, GFXFF);
|
||||
|
||||
//Print Difficulty
|
||||
background.setFreeFont(FSS9);
|
||||
background.setTextDatum(TR_DATUM);
|
||||
background.setTextColor(0x9C92);
|
||||
background.drawString(gData.difficulty.c_str(), 302, 88, GFXFF);
|
||||
|
||||
//Print Global Hashrate
|
||||
render.setFontSize(17);
|
||||
render.rdrawString(gData.globalHash.c_str(), 274, 145, TFT_BLACK);
|
||||
|
||||
//Print BlockHeight
|
||||
render.setFontSize(28);
|
||||
gData.currentBlock = getBlockHeight();
|
||||
render.rdrawString(gData.currentBlock.c_str(), 140, 104, 0xDEDB);
|
||||
|
||||
//Draw percentage rectangle
|
||||
//width percent bar 140 - 2
|
||||
unsigned long cBlock = gData.currentBlock.toInt();
|
||||
gData.remainingBlocks = (((cBlock / HALVING_BLOCKS)+1) * HALVING_BLOCKS) - cBlock;
|
||||
gData.progressPercent = (HALVING_BLOCKS-gData.remainingBlocks)*100/HALVING_BLOCKS;
|
||||
int x2 = 2 + (138*gData.progressPercent/100);
|
||||
background.fillRect(2, 149, x2, 168, 0xDEDB);
|
||||
|
||||
//Print Remaining BLocks
|
||||
//background.setFreeFont(FSSB9);
|
||||
background.setTextFont(FONT2);
|
||||
background.setTextSize(1);
|
||||
background.setTextDatum(MC_DATUM);
|
||||
background.setTextColor(TFT_BLACK);
|
||||
temp = String(gData.remainingBlocks) + " BLOCKS";
|
||||
background.drawString(temp.c_str(), 72, 159, FONT2);//GFXFF);
|
||||
|
||||
//Push prepared background to screen
|
||||
background.pushSprite(0,0);
|
||||
}
|
||||
|
||||
// Variables para controlar el parpadeo con millis()
|
||||
unsigned long previousMillis = 0;
|
||||
|
||||
void doLedStuff(int ledPin){
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
switch (mMonitor.NerdStatus) {
|
||||
|
||||
case NM_waitingConfig: digitalWrite(ledPin, HIGH); // LED encendido de forma continua
|
||||
break;
|
||||
|
||||
case NM_Connecting: if (currentMillis - previousMillis >= 500) { //0.5sec blink
|
||||
previousMillis = currentMillis;
|
||||
digitalWrite(ledPin, !digitalRead(ledPin)); // Cambia el estado del LED
|
||||
}
|
||||
break;
|
||||
|
||||
case NM_hashing: if (currentMillis - previousMillis >= 100) { //0.1sec blink
|
||||
previousMillis = currentMillis;
|
||||
digitalWrite(ledPin, !digitalRead(ledPin)); // Cambia el estado del LED
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
@ -51,14 +51,46 @@ typedef struct{
|
||||
int halfHourFee;
|
||||
}global_data;
|
||||
|
||||
typedef struct {
|
||||
String completedShares;
|
||||
String totalMHashes;
|
||||
String totalKHashes;
|
||||
String currentHashRate;
|
||||
String templates;
|
||||
String bestDiff;
|
||||
String timeMining;
|
||||
String valids;
|
||||
String temp;
|
||||
String currentTime;
|
||||
}mining_data;
|
||||
|
||||
typedef struct {
|
||||
String completedShares;
|
||||
String totalKHashes;
|
||||
String currentHashRate;
|
||||
String btcPrice;
|
||||
String blockHeight;
|
||||
String currentTime;
|
||||
}clock_data;
|
||||
|
||||
typedef struct {
|
||||
String completedShares;
|
||||
String totalKHashes;
|
||||
String currentHashRate;
|
||||
String btcPrice;
|
||||
String currentTime;
|
||||
String halfHourFee;
|
||||
String netwrokDifficulty;
|
||||
String globalHashRate;
|
||||
String blockHeight;
|
||||
float progressPercent;
|
||||
String remainingBlocks;
|
||||
}coin_data;
|
||||
|
||||
void setup_monitor(void);
|
||||
void show_MinerScreen(unsigned long mElapsed);
|
||||
void show_ClockScreen(unsigned long mElapsed);
|
||||
void show_GlobalHashScreen(unsigned long mElapsed);
|
||||
void show_NoScreen(unsigned long mElapsed);
|
||||
void changeScreen(void);
|
||||
void doLedStuff(int ledPin);
|
||||
|
||||
mining_data getMiningData(unsigned long mElapsed);
|
||||
clock_data getClockData(unsigned long mElapsed);
|
||||
coin_data getCoinData(unsigned long mElapsed);
|
||||
|
||||
#endif //MONITOR_API_H
|
6
src/version.h
Normal file
6
src/version.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define CURRENT_VERSION "V1.6.1"
|
||||
|
||||
#endif // VERSION_H
|
@ -8,10 +8,9 @@
|
||||
|
||||
#include <WiFiManager.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "media/images.h"
|
||||
#include <TFT_eSPI.h> // Graphics and font library
|
||||
#include "wManager.h"
|
||||
#include "monitor.h"
|
||||
#include "drivers/display.h"
|
||||
|
||||
// JSON configuration file
|
||||
#define JSON_CONFIG_FILE "/config.json"
|
||||
@ -28,9 +27,6 @@ int GMTzone = 2; //Currently selected in spain
|
||||
|
||||
// Define WiFiManager Object
|
||||
WiFiManager wm;
|
||||
|
||||
|
||||
extern TFT_eSPI tft; // tft variable declared on main
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
void saveConfigFile()
|
||||
@ -143,19 +139,21 @@ void init_WifiManager()
|
||||
//Serial.setTxTimeoutMs(10);
|
||||
|
||||
//Init pin 15 to eneble 5V external power (LilyGo bug)
|
||||
pinMode(PIN_ENABLE5V, OUTPUT);
|
||||
digitalWrite(PIN_ENABLE5V, HIGH);
|
||||
#ifdef PIN_ENABLE5V
|
||||
pinMode(PIN_ENABLE5V, OUTPUT);
|
||||
digitalWrite(PIN_ENABLE5V, HIGH);
|
||||
#endif
|
||||
|
||||
// Change to true when testing to force configuration every time we run
|
||||
bool forceConfig = false;
|
||||
|
||||
#if !defined(DEVKITV1)
|
||||
// Check if button2 is pressed to enter configMode with actual configuration
|
||||
if(!digitalRead(PIN_BUTTON_2)){
|
||||
Serial.println(F("Button pressed to force start config mode"));
|
||||
forceConfig = true;
|
||||
wm.setBreakAfterConfig(true); //Set to detect config edition and save
|
||||
}
|
||||
#if defined(PIN_BUTTON_2)
|
||||
// Check if button2 is pressed to enter configMode with actual configuration
|
||||
if(!digitalRead(PIN_BUTTON_2)){
|
||||
Serial.println(F("Button pressed to force start config mode"));
|
||||
forceConfig = true;
|
||||
wm.setBreakAfterConfig(true); //Set to detect config edition and save
|
||||
}
|
||||
#endif
|
||||
|
||||
bool spiffsSetup = loadConfigFile();
|
||||
@ -222,7 +220,7 @@ void init_WifiManager()
|
||||
{
|
||||
//No configuramos timeout al modulo
|
||||
wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware
|
||||
tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen);
|
||||
drawSetupScreen();
|
||||
if (!wm.startConfigPortal("NerdMinerAP","MineYourCoins"))
|
||||
{
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
|
@ -1,17 +1,3 @@
|
||||
|
||||
#ifdef NERDMINERV2
|
||||
//Define config buttons for TTGO-TDisplay-s3
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 14
|
||||
#define PIN_ENABLE5V 15
|
||||
#elif defined(DEVKITV1)
|
||||
//Standard ESP32-devKit
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 19 //Not used
|
||||
#define PIN_ENABLE5V 21 //Not used
|
||||
#define LED_PIN 2
|
||||
#endif
|
||||
|
||||
void init_WifiManager();
|
||||
void wifiManagerProcess();
|
||||
void reset_configurations();
|
Loading…
Reference in New Issue
Block a user