oled lib release migration

This commit is contained in:
cyberman54 2022-07-17 18:07:39 +02:00
parent 739fecfc98
commit e097589267
3 changed files with 135 additions and 153 deletions

View File

@ -14,14 +14,17 @@
#endif
#define DISPLAY_PAGES (7) // number of paxcounter display pages
#define PLOTBUFFERSIZE (MY_DISPLAY_WIDTH * MY_DISPLAY_HEIGHT / 8)
// settings for OLED display library
#if (HAS_DISPLAY) == 1
#define MY_FONT_SMALL FONT_SMALL
#define MY_FONT_NORMAL FONT_NORMAL
#define MY_FONT_LARGE FONT_LARGE
#define MY_FONT_STRETCHED FONT_STRETCHED
#define USE_BACKBUFFER 1
#define MY_FONT_SMALL FONT_6x8
#define MY_FONT_NORMAL FONT_8x8
#define MY_FONT_LARGE FONT_16x32
#define MY_FONT_STRETCHED FONT_12x16
#define MY_DISPLAY_FIRSTLINE 30
#ifdef MY_DISPLAY_ADDR
#define OLED_ADDR MY_DISPLAY_ADDR
#else
@ -33,6 +36,12 @@
#ifndef OLED_FREQUENCY
#define OLED_FREQUENCY 400000L
#endif
#ifndef MY_DISPLAY_FGCOLOR
#define MY_DISPLAY_FGCOLOR OLED_WHITE
#endif
#ifndef MY_DISPLAY_BGCOLOR
#define MY_DISPLAY_BGCOLOR OLED_BLACK
#endif
// settings for TFT display library
#elif (HAS_DISPLAY == 2)
@ -42,6 +51,8 @@
#define MY_FONT_LARGE 4
#define MY_FONT_STRETCHED 6
#define MY_DISPLAY_FIRSTLINE 30
#ifndef MY_DISPLAY_FGCOLOR
#define MY_DISPLAY_FGCOLOR TFT_WHITE
#endif
@ -76,7 +87,7 @@
const uint8_t QR_SCALEFACTOR = (MY_DISPLAY_HEIGHT - 4) / 29; // 4px borderlines
extern uint8_t DisplayIsOn, displaybuf[];
extern uint8_t DisplayIsOn;
extern hw_timer_t *displayIRQ;
extern uint8_t volatile channel; // wifi channel rotation counter
@ -86,11 +97,11 @@ void dp_init(bool verbose = false);
void dp_shutdown(void);
void dp_message(const char *msg, int line, bool invers);
void dp_drawPage(bool nextpage);
void dp_println(int lines = 1);
void dp_println(void);
void dp_printf(const char *format, ...);
void dp_setFont(int font, int inv = 0);
void dp_dump(uint8_t *pBuffer);
void dp_setTextCursor(int col, int row);
void dp_dump(uint8_t *pBuffer = NULL);
void dp_setTextCursor(int col = 0, int row = MY_DISPLAY_FIRSTLINE);
void dp_contrast(uint8_t contrast);
void dp_clear(void);
void dp_power(uint8_t screenon);

View File

@ -8,11 +8,11 @@ Display-Mask (128 x 64 pixel):
| 11111111112
|012345678901234567890 Font
----------------------- ---------
0|PAX:aabbccdd STRETCHED
1|PAX:aabbccdd STRETCHED
0|PAX:aabbccdd LARGE
1|PAX:aabbccdd LARGE
2|
3|WIFI:abcde BLTH:abcde SMALL
4|B:a.bcV Sats:ab ch:ab SMALL
4|Batt:abc% chan:ab SMALL
5|RLIM:abcd Mem:abcdKB SMALL
6|27.Feb 2019 20:27:00* SMALL
7|yyyyyyyyyyyyy xx SFab SMALL
@ -25,9 +25,10 @@ y = LMIC event message
xx = payload sendqueue length
ab = LMIC spread factor
MY_FONT_SMALL: 6x8px = 21 chars / line
MY_FONT_NORMAL: 8x8px = 16 chars / line
MY_FONT_STRETCHED: 16x32px = 8 chars / line
MY_FONT_SMALL: 6x8px = 21 chars / line @ 8 lines
MY_FONT_NORMAL: 8x8px = 16 chars / line @ 8 lines
MY_FONT_STRETCHED: 12x16px = 10 chars / line @ 4 lines
MY_FONT_LARGE: 16x32px = 8 chars / line @ 2 lines
*/
@ -39,18 +40,14 @@ MY_FONT_STRETCHED: 16x32px = 8 chars / line
// local Tag for logging
static const char TAG[] = __FILE__;
static uint8_t plotbuf[PLOTBUFFERSIZE] = {0};
uint8_t DisplayIsOn = 0;
uint8_t displaybuf[MY_DISPLAY_WIDTH * MY_DISPLAY_HEIGHT / 8] = {0};
static uint8_t plotbuf[MY_DISPLAY_WIDTH * MY_DISPLAY_HEIGHT / 8] = {0};
static int dp_row = 0, dp_col = 0, dp_font = 0;
hw_timer_t *displayIRQ = NULL;
QRCode qrcode;
#ifdef HAS_DISPLAY
#if (HAS_DISPLAY) == 1
OBDISP ssoled;
ONE_BIT_DISPLAY oled;
#elif (HAS_DISPLAY) == 2
TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT);
#else
@ -62,16 +59,11 @@ void dp_setup(int contrast) {
#if (HAS_DISPLAY) == 1 // I2C OLED
int rc = obdI2CInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP,
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
MY_DISPLAY_SCL, MY_DISPLAY_RST,
OLED_FREQUENCY); // use standard I2C bus at 400Khz
//_ASSERT(rc != OLED_NOT_FOUND);
// set display buffer
obdSetBackBuffer(&ssoled, displaybuf);
obdSetTextWrap(&ssoled, true);
dp_font = MY_FONT_NORMAL;
oled.I2Cbegin(OLED_TYPE, OLED_ADDR, OLED_FREQUENCY);
assert(oled.allocBuffer()); // render all outputs to lib internal backbuffer
oled.setTextWrap(false);
oled.setRotation(
MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280°
#elif (HAS_DISPLAY) == 2 // SPI TFT
@ -118,7 +110,7 @@ void dp_init(bool verbose) {
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext.");
// give user some time to read or take picture
dp_dump(displaybuf);
dp_dump();
delay(2000);
dp_clear();
#endif // VERBOSE
@ -136,17 +128,17 @@ void dp_init(bool verbose) {
// display DEVEUI as plain text on the right
const int x_offset = QR_SCALEFACTOR * 29 + 14;
dp_setTextCursor(x_offset, 0);
dp_setFont(MY_FONT_NORMAL);
dp_printf("DEVEUI");
dp_setTextCursor(x_offset, 0);
dp_printf("DEVEUI:");
dp_println();
for (uint8_t i = 0; i <= 3; i++) {
dp_setTextCursor(x_offset, i + 3);
dp_setTextCursor(x_offset, i * 8 + 20);
dp_printf("%4.4s", deveui + i * 4);
}
// give user some time to read or take picture
dp_dump(displaybuf);
dp_dump();
#if !(BOOTMENU)
delay(8000);
#endif
@ -198,10 +190,6 @@ void dp_drawPage(bool nextpage) {
time_t now;
struct tm timeinfo = {0};
#if (HAS_GPS)
static bool wasnofix = true;
#endif
if (nextpage) {
DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1);
dp_clear();
@ -215,9 +203,9 @@ void dp_drawPage(bool nextpage) {
// line 1/2: pax counter
// display number of unique macs total Wifi + BLE
if (DisplayPage < 5) {
dp_setFont(MY_FONT_STRETCHED);
dp_printf("%-5d", count.pax);
if (DisplayPage < 3) {
dp_setFont(MY_FONT_LARGE);
dp_printf("%-8d", count.pax);
}
switch (DisplayPage) {
@ -233,8 +221,8 @@ void dp_drawPage(bool nextpage) {
// ---------- page 0: parameters overview ----------
case 0:
dp_setTextCursor(0, 3);
dp_setFont(MY_FONT_SMALL);
dp_setTextCursor();
// line 3: wifi + bluetooth counters
// WIFI:abcde BLTH:abcde
@ -268,19 +256,11 @@ void dp_drawPage(bool nextpage) {
if (batt_level == 0)
dp_printf("No batt ");
else
dp_printf("B:%3d%% ", batt_level);
dp_printf("Batt:%3u%% ", batt_level);
#else
dp_printf(" ");
#endif
#if (HAS_GPS)
dp_setFont(MY_FONT_SMALL, !gps_hasfix());
dp_printf("Sats:%.2d", gps.satellites.value());
dp_setFont(MY_FONT_SMALL);
#else
dp_printf(" ");
#endif
dp_printf(" ch:%02d", channel);
dp_printf("chan:%02u", channel);
dp_println();
// line 5: RSSI limiter + free memory
@ -322,7 +302,7 @@ void dp_drawPage(bool nextpage) {
dp_setFont(MY_FONT_SMALL, 0);
#endif // HAS_LORA
dp_dump(displaybuf);
dp_dump();
break;
// ---------- page 1: lorawan parameters ----------
@ -337,7 +317,7 @@ void dp_drawPage(bool nextpage) {
// 7|SNR:-0000 RSSI:-0000
dp_setFont(MY_FONT_SMALL);
dp_setTextCursor(0, 3);
dp_setTextCursor();
dp_printf("Net:%06X Pwr:%-2d", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow);
dp_println();
dp_printf("Dev:%08X DR:%1d", LMIC.devaddr, LMIC.datarate);
@ -349,7 +329,7 @@ void dp_drawPage(bool nextpage) {
dp_println();
dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi);
dp_dump(displaybuf);
dp_dump();
break;
#else // flip page if we are unattended
DisplayPage++;
@ -359,31 +339,22 @@ void dp_drawPage(bool nextpage) {
case 2:
#if (HAS_GPS)
// show satellite status at bottom line
dp_setFont(MY_FONT_SMALL);
dp_setTextCursor(0, 56);
dp_printf("%u Sats", gps.satellites.value());
dp_printf(gps_hasfix() ? " " : " - No fix");
// show latitude and longitude
dp_setFont(MY_FONT_STRETCHED);
dp_setTextCursor(0, 3);
if (gps_hasfix()) {
// line 5: clear "No fix"
if (wasnofix) {
dp_setTextCursor(2, 4);
dp_printf(" ");
wasnofix = false;
}
// line 3-4: GPS latitude
dp_printf("%c%07.4f", gps.location.rawLat().negative ? 'S' : 'N',
dp_setTextCursor();
dp_printf("%c%09.6f", gps.location.rawLat().negative ? 'S' : 'N',
gps.location.lat());
// line 6-7: GPS longitude
dp_printf("%c%07.4f", gps.location.rawLng().negative ? 'W' : 'E',
dp_println();
dp_printf("%c%09.6f", gps.location.rawLng().negative ? 'W' : 'E',
gps.location.lng());
} else {
dp_setTextCursor(2, 4);
dp_setFont(MY_FONT_STRETCHED, 1);
dp_printf("No fix");
wasnofix = true;
}
dp_dump(displaybuf);
dp_dump();
break;
#else // flip page if we are unattended
DisplayPage++;
@ -394,25 +365,17 @@ void dp_drawPage(bool nextpage) {
#if (HAS_BME)
dp_setFont(MY_FONT_STRETCHED);
dp_setTextCursor(0, 2);
// line 2-3: Temp
dp_printf("TMP:%-2.1f", bme_status.temperature);
dp_println(2);
// line 4-5: Hum
dp_printf("HUM:%-2.1f", bme_status.humidity);
dp_println(2);
dp_setTextCursor(0, 0);
dp_printf("TMP: %-6.1f", bme_status.temperature);
dp_println();
dp_printf("HUM: %-6.1f", bme_status.humidity);
dp_println();
dp_printf("PRE: %-6.1f", bme_status.pressure);
#ifdef HAS_BME680
// line 6-7: IAQ
dp_printf("IAQ:%-3.0f", bme_status.iaq);
#else // is BME280 or BMP180
// line 6-7: Pre
dp_printf("PRE:%-2.1f", bme_status.pressure);
#endif // HAS_BME680
dp_dump(displaybuf);
dp_println();
dp_printf("IAQ: %-6.0f", bme_status.iaq);
#endif
dp_dump();
break; // page 3
#else // flip page if we are unattended
DisplayPage++;
@ -421,20 +384,26 @@ void dp_drawPage(bool nextpage) {
// ---------- page 4: time ----------
case 4:
dp_setFont(MY_FONT_LARGE);
dp_setTextCursor(0, 4);
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo);
dp_printf("%.8s", strftime_buf);
dp_dump(displaybuf);
dp_setFont(MY_FONT_STRETCHED);
dp_setTextCursor(0, 0);
dp_printf("Timeofday:");
dp_setTextCursor(0, 26);
dp_setFont(MY_FONT_LARGE);
dp_printf("%.8s", strftime_buf);
dp_println();
dp_setFont(MY_FONT_SMALL);
dp_printf("%21.1f", uptime() / 1000.0);
dp_dump();
break;
// ---------- page 5: pax graph ----------
case 5:
// update histogram
// update and show histogram
dp_plotCurve(count.pax, false);
dp_dump(plotbuf);
break;
@ -455,35 +424,33 @@ void dp_drawPage(bool nextpage) {
// ------------- display helper functions -----------------
void dp_setTextCursor(int x, int y) {
// x represents the pixel column
// y represents the text row
dp_col = x;
#if (HAS_DISPLAY) == 1
dp_row = y;
obdSetCursor(&ssoled, dp_col, dp_row);
oled.setCursor(x, y);
#elif (HAS_DISPLAY) == 2
switch (dp_font >> 1) {
case MY_FONT_STRETCHED:
case MY_FONT_LARGE:
dp_row = y * 26;
break;
case MY_FONT_SMALL:
case MY_FONT_NORMAL:
default:
dp_row = y * 16;
break;
}
tft.setCursor(dp_col, dp_row);
tft.setCursor(x, y);
#endif
}
void dp_setFont(int font, int inv) {
#if (HAS_DISPLAY) == 1
dp_font = (font << 1) | (inv & 0x01);
// handle invers printing
if (inv)
oled.setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR);
else
oled.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR);
// set desired font
oled.setFont(font);
#elif (HAS_DISPLAY) == 2
// map font oled -> tft
// handle invers printing
if (inv)
tft.setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR);
else
tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR);
// map desired oled font to tft font
switch (font) {
case MY_FONT_STRETCHED: // 16x16 on OLED
case MY_FONT_LARGE: // 16x32 on OLED
@ -495,17 +462,14 @@ void dp_setFont(int font, int inv) {
tft.setTextFont(2); // 16px
break;
}
// to do: invers printing
#endif
}
void dp_println(int lines) {
dp_col = 0;
dp_row += lines;
void dp_println(void) {
#if (HAS_DISPLAY) == 1
dp_setTextCursor(dp_col, dp_row);
oled.println();
#elif (HAS_DISPLAY) == 2
for (int i = 1; i <= lines; i++)
tft.println();
#endif
};
@ -533,8 +497,7 @@ void dp_printf(const char *format, ...) {
}
va_end(arg);
#if (HAS_DISPLAY) == 1
obdWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01,
false);
oled.write(temp);
#elif (HAS_DISPLAY) == 2
tft.printf(temp);
#endif
@ -545,26 +508,29 @@ void dp_printf(const char *format, ...) {
void dp_dump(uint8_t *pBuffer) {
#if (HAS_DISPLAY) == 1
obdDumpBuffer(&ssoled, pBuffer);
if (pBuffer)
memcpy(oled.getBuffer(), pBuffer, PLOTBUFFERSIZE);
oled.display();
#elif (HAS_DISPLAY) == 2
// probably oled buffer stucture is not suitable for tft -> to be checked
if (pBuffer)
tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT,
MY_DISPLAY_FGCOLOR);
#endif
}
void dp_clear(void) {
dp_setTextCursor(0, 0);
#if (HAS_DISPLAY) == 1
obdFill(&ssoled, 0, 1);
oled.fillScreen(MY_DISPLAY_BGCOLOR);
oled.display();
#elif (HAS_DISPLAY) == 2
tft.fillScreen(MY_DISPLAY_BGCOLOR);
#endif
dp_setTextCursor(0, 0);
}
void dp_contrast(uint8_t contrast) {
#if (HAS_DISPLAY) == 1
obdSetContrast(&ssoled, contrast);
oled.setContrast(contrast);
#elif (HAS_DISPLAY) == 2
// to do: gamma correction for TFT
#endif
@ -572,7 +538,10 @@ void dp_contrast(uint8_t contrast) {
void dp_power(uint8_t screenon) {
#if (HAS_DISPLAY) == 1
obdPower(&ssoled, screenon);
//not yet in library, awaiting PR https://github.com/bitbank2/OneBitDisplay/pull/34
//oled.setPower(screenon);
//as workaround be blank the sreen
dp_clear();
#elif (HAS_DISPLAY) == 2
// to come
#endif
@ -580,7 +549,10 @@ void dp_power(uint8_t screenon) {
void dp_shutdown(void) {
#if (HAS_DISPLAY) == 1
obdPower(&ssoled, false);
//not yet in library, awaiting PR https://github.com/bitbank2/OneBitDisplay/pull/34
//oled.setPower(false);
//as workaround be blank the sreen
dp_clear();
delay(DISPLAYREFRESH_MS / 1000 * 1.1);
#elif (HAS_DISPLAY) == 2
// to come
@ -589,10 +561,10 @@ void dp_shutdown(void) {
// print static message on display
void dp_message(const char *msg, int line, bool invers) {
dp_setTextCursor(0, line);
dp_setFont(MY_FONT_NORMAL, invers ? 1 : 0);
dp_setFont(MY_FONT_SMALL, invers ? 1 : 0);
dp_setTextCursor(0, line * 8);
dp_printf("%-16s", msg);
dp_dump(displaybuf);
dp_dump();
} // dp_message
// ------------- QR code plotter -----------------
@ -625,8 +597,7 @@ void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) {
void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
uint8_t bRender) {
#if (HAS_DISPLAY) == 1
for (uint16_t xi = x; xi < x + width; xi++)
obdDrawLine(&ssoled, xi, y, xi, y + height - 1, 1, bRender);
oled.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR);
#elif (HAS_DISPLAY) == 2
tft.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR);
#endif

View File

@ -62,7 +62,7 @@ void start_ota_update() {
dp_printf("Downloading ..");
dp_println();
dp_printf("Rebooting ..");
dp_dump(displaybuf);
dp_dump();
#endif
ESP_LOGI(TAG, "Starting Wifi OTA update");
@ -331,14 +331,14 @@ void ota_display(const uint8_t row, const std::string status,
const std::string msg) {
#ifdef HAS_DISPLAY
dp_setFont(MY_FONT_SMALL);
dp_setTextCursor(14, row);
dp_setTextCursor(14, row * 8);
dp_printf(status.substr(0, 2).c_str());
if (!msg.empty()) {
dp_printf(" ");
dp_printf(msg.substr(0, 16).c_str());
dp_println();
}
dp_dump(displaybuf);
dp_dump();
#endif
}