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

View File

@ -50,7 +50,7 @@ static QRCode qrcode;
#if (HAS_DISPLAY) == 1
ONE_BIT_DISPLAY *dp = NULL;
#elif (HAS_DISPLAY) == 2
TFT_eSPI *dp = NULL;
BB_SPI_LCD *dp = NULL;
#else
#error Unknown display type specified in hal file
#endif
@ -58,6 +58,7 @@ TFT_eSPI *dp = NULL;
void dp_setup(int contrast) {
#if (HAS_DISPLAY) == 1 // I2C OLED
dp = new ONE_BIT_DISPLAY;
dp->setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST);
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°
#elif (HAS_DISPLAY) == 2 // SPI TFT
dp = new TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT);
dp->init();
dp->setRotation(MY_DISPLAY_FLIP ? 3 : 1);
dp->invertDisplay(MY_DISPLAY_INVERT ? true : false);
dp = new BB_SPI_LCD;
dp->begin(TFT_TYPE, FLAGS_NONE, TFT_FREQUENCY, TFT_CS, TFT_DC, TFT_RST,
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);
#endif
@ -99,8 +105,6 @@ void dp_init(bool verbose) {
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
dp->printf("%dMB %s Flash", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext.");
// give user some time to read or take picture
dp_dump();
delay(2000);
dp_clear();
@ -143,7 +147,6 @@ void dp_init(bool verbose) {
// write display content to display buffer
// nextpage = true -> flip 1 page
void dp_refresh(bool nextPage) {
struct count_payload_t count; // libpax count storage
static uint8_t DisplayPage = 0;
char timeState, strftime_buf[64];
@ -194,7 +197,7 @@ void dp_refresh(bool nextPage) {
// show pax
libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax);
dp->printf("%-8u", count.pax);
dp_setFont(MY_FONT_SMALL);
dp->setCursor(0, MY_DISPLAY_FIRSTLINE);
@ -204,21 +207,21 @@ void dp_refresh(bool nextPage) {
#if ((WIFICOUNTER) && (BLECOUNTER))
if (cfg.wifiscan)
dp->printf("WIFI:%-5d", count.wifi_count);
dp->printf("WIFI:%-5u", count.wifi_count);
else
dp->printf("WIFI:off");
if (cfg.blescan)
dp->printf("BLTH:%-5d", count.ble_count);
dp->printf("BLTH:%-5u", count.ble_count);
else
dp->printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER))
if (cfg.wifiscan)
dp->printf("WIFI:%-5d", count.wifi_count);
dp->printf("WIFI:%-5u", count.wifi_count);
else
dp->printf("WIFI:off");
#elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan)
dp->printf("BLTH:%-5d", count.ble_count);
dp->printf("BLTH:%-5u", count.ble_count);
dp->printf("BLTH:off");
#else
dp->printf("Sniffer disabled");
@ -240,7 +243,7 @@ void dp_refresh(bool nextPage) {
// line 5: RSSI limiter + free memory
// RLIM:abcd Mem:abcdKB
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
// Wed Jan 12 21:49:08 *
@ -291,15 +294,15 @@ void dp_refresh(bool nextPage) {
// show pax
libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax);
dp->printf("%-8u", count.pax);
dp_setFont(MY_FONT_SMALL);
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);
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("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);
dp->printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi);
@ -318,7 +321,7 @@ void dp_refresh(bool nextPage) {
// show pax
libpax_counter_count(&count);
dp_setFont(MY_FONT_LARGE);
dp->printf("%-8d", count.pax);
dp->printf("%-8u", count.pax);
// show satellite status at bottom line
dp_setFont(MY_FONT_SMALL);
@ -373,7 +376,7 @@ void dp_refresh(bool nextPage) {
strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo);
dp->printf("%.8s\r\n", strftime_buf);
dp_setFont(MY_FONT_SMALL);
dp->printf("%21.1f", uptime() / 1000.0);
dp->printf("%-12.1f", uptime() / 1000.0);
dp_dump();
break;
@ -402,51 +405,22 @@ void dp_refresh(bool nextPage) {
// ------------- display helper functions -----------------
void dp_setFont(int font, int inv) {
// handle invers printing
dp->setFont(font);
if (inv)
dp->setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR);
else
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) {
if (pBuffer)
memcpy(dp->getBuffer(), pBuffer, PLOTBUFFERSIZE);
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) {
#if (HAS_DISPLAY) == 1
dp->fillScreen(MY_DISPLAY_BGCOLOR);
dp->display();
#elif (HAS_DISPLAY) == 2
dp->fillScreen(MY_DISPLAY_BGCOLOR);
#endif
dp->setCursor(0, 0);
}