new tft display lib

This commit is contained in:
cyberman54 2022-08-16 13:16:29 +02:00
parent c0688d6357
commit 4f46fb21fd
2 changed files with 30 additions and 60 deletions

View File

@ -11,8 +11,8 @@
#include <OneBitDisplay.h> #include <OneBitDisplay.h>
extern ONE_BIT_DISPLAY *dp; extern ONE_BIT_DISPLAY *dp;
#elif (HAS_DISPLAY) == 2 #elif (HAS_DISPLAY) == 2
#include <TFT_eSPI.h> #include <bb_spi_lcd.h>
extern TFT_eSPI *dp; extern BB_SPI_LCD *dp;
#endif #endif
#define DISPLAY_PAGES (7) // number of paxcounter display pages #define DISPLAY_PAGES (7) // number of paxcounter display pages
@ -61,14 +61,10 @@ extern TFT_eSPI *dp;
#endif #endif
#ifndef MY_DISPLAY_FGCOLOR #ifndef MY_DISPLAY_FGCOLOR
#define MY_DISPLAY_FGCOLOR 0xFFFF // TFT_WHITE #define MY_DISPLAY_FGCOLOR TFT_YELLOW
#endif #endif
#ifndef MY_DISPLAY_BGCOLOR #ifndef MY_DISPLAY_BGCOLOR
#define MY_DISPLAY_BGCOLOR 0x0000 // TFT_BLACK #define MY_DISPLAY_BGCOLOR TFT_BLACK
#endif
#ifndef TOUCH_CS
#define TOUCH_CS NOT_A_PIN
#endif #endif
#endif #endif

View File

@ -50,7 +50,7 @@ static QRCode qrcode;
#if (HAS_DISPLAY) == 1 #if (HAS_DISPLAY) == 1
ONE_BIT_DISPLAY *dp = NULL; ONE_BIT_DISPLAY *dp = NULL;
#elif (HAS_DISPLAY) == 2 #elif (HAS_DISPLAY) == 2
TFT_eSPI *dp = NULL; BB_SPI_LCD *dp = NULL;
#else #else
#error Unknown display type specified in hal file #error Unknown display type specified in hal file
#endif #endif
@ -58,6 +58,7 @@ TFT_eSPI *dp = NULL;
void dp_setup(int contrast) { void dp_setup(int contrast) {
#if (HAS_DISPLAY) == 1 // I2C OLED #if (HAS_DISPLAY) == 1 // I2C OLED
dp = new ONE_BIT_DISPLAY; dp = new ONE_BIT_DISPLAY;
dp->setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST); dp->setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST);
dp->setBitBang(false); dp->setBitBang(false);
@ -68,10 +69,15 @@ void dp_setup(int contrast) {
MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280° MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280°
#elif (HAS_DISPLAY) == 2 // SPI TFT #elif (HAS_DISPLAY) == 2 // SPI TFT
dp = new TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT);
dp->init(); dp = new BB_SPI_LCD;
dp->setRotation(MY_DISPLAY_FLIP ? 3 : 1); dp->begin(TFT_TYPE, FLAGS_NONE, TFT_FREQUENCY, TFT_CS, TFT_DC, TFT_RST,
dp->invertDisplay(MY_DISPLAY_INVERT ? true : false); TFT_BL, TFT_MISO, TFT_MOSI, TFT_SCLK);
dp->allocBuffer(); // render all outputs to lib internal backbuffer
dp->setRotation(
MY_DISPLAY_FLIP ? 1 : 3); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280°
// dp->invertDisplay(MY_DISPLAY_INVERT ? true : false);
// dp->setTextWrap(false);
dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR);
#endif #endif
@ -99,8 +105,6 @@ void dp_init(bool verbose) {
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
dp->printf("%dMB %s Flash", spi_flash_get_chip_size() / (1024 * 1024), dp->printf("%dMB %s Flash", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext."); (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext.");
// give user some time to read or take picture
dp_dump(); dp_dump();
delay(2000); delay(2000);
dp_clear(); dp_clear();
@ -143,7 +147,6 @@ void dp_init(bool verbose) {
// write display content to display buffer // write display content to display buffer
// nextpage = true -> flip 1 page // nextpage = true -> flip 1 page
void dp_refresh(bool nextPage) { void dp_refresh(bool nextPage) {
struct count_payload_t count; // libpax count storage struct count_payload_t count; // libpax count storage
static uint8_t DisplayPage = 0; static uint8_t DisplayPage = 0;
char timeState, strftime_buf[64]; char timeState, strftime_buf[64];
@ -194,7 +197,7 @@ void dp_refresh(bool nextPage) {
// show pax // show pax
libpax_counter_count(&count); libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE); dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax); dp->printf("%-8u", count.pax);
dp_setFont(MY_FONT_SMALL); dp_setFont(MY_FONT_SMALL);
dp->setCursor(0, MY_DISPLAY_FIRSTLINE); dp->setCursor(0, MY_DISPLAY_FIRSTLINE);
@ -204,21 +207,21 @@ void dp_refresh(bool nextPage) {
#if ((WIFICOUNTER) && (BLECOUNTER)) #if ((WIFICOUNTER) && (BLECOUNTER))
if (cfg.wifiscan) if (cfg.wifiscan)
dp->printf("WIFI:%-5d", count.wifi_count); dp->printf("WIFI:%-5u", count.wifi_count);
else else
dp->printf("WIFI:off"); dp->printf("WIFI:off");
if (cfg.blescan) if (cfg.blescan)
dp->printf("BLTH:%-5d", count.ble_count); dp->printf("BLTH:%-5u", count.ble_count);
else else
dp->printf(" BLTH:off"); dp->printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER)) #elif ((WIFICOUNTER) && (!BLECOUNTER))
if (cfg.wifiscan) if (cfg.wifiscan)
dp->printf("WIFI:%-5d", count.wifi_count); dp->printf("WIFI:%-5u", count.wifi_count);
else else
dp->printf("WIFI:off"); dp->printf("WIFI:off");
#elif ((!WIFICOUNTER) && (BLECOUNTER)) #elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan) if (cfg.blescan)
dp->printf("BLTH:%-5d", count.ble_count); dp->printf("BLTH:%-5u", count.ble_count);
dp->printf("BLTH:off"); dp->printf("BLTH:off");
#else #else
dp->printf("Sniffer disabled"); dp->printf("Sniffer disabled");
@ -240,7 +243,7 @@ void dp_refresh(bool nextPage) {
// line 5: RSSI limiter + free memory // line 5: RSSI limiter + free memory
// RLIM:abcd Mem:abcdKB // RLIM:abcd Mem:abcdKB
dp->printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); dp->printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit);
dp->printf(" Mem:%4dKB\r\n", getFreeRAM() / 1024); dp->printf(" Mem:%uKB\r\n", getFreeRAM() / 1024);
// line 6: time + date // line 6: time + date
// Wed Jan 12 21:49:08 * // Wed Jan 12 21:49:08 *
@ -291,15 +294,15 @@ void dp_refresh(bool nextPage) {
// show pax // show pax
libpax_counter_count(&count); libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE); dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax); dp->printf("%-8u", count.pax);
dp_setFont(MY_FONT_SMALL); dp_setFont(MY_FONT_SMALL);
dp->setCursor(0, MY_DISPLAY_FIRSTLINE); dp->setCursor(0, MY_DISPLAY_FIRSTLINE);
dp->printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, dp->printf("Net:%06X Pwr:%2u\r\n", LMIC.netid & 0x001FFFFF,
LMIC.radio_txpow); LMIC.radio_txpow);
dp->printf("Dev:%08X DR:%1d\r\n", LMIC.devaddr, LMIC.datarate); dp->printf("Dev:%08X DR:%1u\r\n", LMIC.devaddr, LMIC.datarate);
dp->printf("ChMsk:%04X Nonce:%04X\r\n", LMIC.channelMap, LMIC.devNonce); dp->printf("ChMsk:%04X Nonce:%04X\r\n", LMIC.channelMap, LMIC.devNonce);
dp->printf("fUp:%-6d fDn:%-6d\r\n", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, dp->printf("fUp:%-6u fDn:%-6u\r\n", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0,
LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0);
dp->printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); dp->printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi);
@ -318,7 +321,7 @@ void dp_refresh(bool nextPage) {
// show pax // show pax
libpax_counter_count(&count); libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE); dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax); dp->printf("%-8u", count.pax);
// show satellite status at bottom line // show satellite status at bottom line
dp_setFont(MY_FONT_SMALL); dp_setFont(MY_FONT_SMALL);
@ -373,7 +376,7 @@ void dp_refresh(bool nextPage) {
strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo);
dp->printf("%.8s\r\n", strftime_buf); dp->printf("%.8s\r\n", strftime_buf);
dp_setFont(MY_FONT_SMALL); dp_setFont(MY_FONT_SMALL);
dp->printf("%21.1f", uptime() / 1000.0); dp->printf("%-12.1f", uptime() / 1000.0);
dp_dump(); dp_dump();
break; break;
@ -402,51 +405,22 @@ void dp_refresh(bool nextPage) {
// ------------- display helper functions ----------------- // ------------- display helper functions -----------------
void dp_setFont(int font, int inv) { void dp_setFont(int font, int inv) {
dp->setFont(font);
// handle invers printing
if (inv) if (inv)
dp->setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR); dp->setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR);
else else
dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR);
#if (HAS_DISPLAY) == 1
// set desired font
dp->setFont(font);
#elif (HAS_DISPLAY) == 2
// map desired oled font to tft font
switch (font) {
case MY_FONT_STRETCHED: // 16x16 on OLED
case MY_FONT_LARGE: // 16x32 on OLED
dp->setTextFont(4); // 26px
break;
case MY_FONT_SMALL: // 6x8 on OLED
case MY_FONT_NORMAL: // 8x8 on OLED
default:
dp->setTextFont(2); // 16px
break;
}
#endif
} }
void dp_dump(uint8_t *pBuffer) { void dp_dump(uint8_t *pBuffer) {
if (pBuffer) if (pBuffer)
memcpy(dp->getBuffer(), pBuffer, PLOTBUFFERSIZE); memcpy(dp->getBuffer(), pBuffer, PLOTBUFFERSIZE);
dp->display(); dp->display();
#elif (HAS_DISPLAY) == 2
if (pBuffer)
dp->drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT,
MY_DISPLAY_FGCOLOR);
#endif
} }
void dp_clear(void) { void dp_clear(void) {
#if (HAS_DISPLAY) == 1
dp->fillScreen(MY_DISPLAY_BGCOLOR); dp->fillScreen(MY_DISPLAY_BGCOLOR);
dp->display(); dp->display();
#elif (HAS_DISPLAY) == 2
dp->fillScreen(MY_DISPLAY_BGCOLOR);
#endif
dp->setCursor(0, 0); dp->setCursor(0, 0);
} }