From aa042f69682b1015ee5fc9d28efcb19fdf490536 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 11 Mar 2020 23:47:16 +0100 Subject: [PATCH] update display lib --- include/display.h | 22 ++++++++++++++ platformio.ini | 6 ++-- src/display.cpp | 74 ++++++++++++++++++++++------------------------- 3 files changed, 59 insertions(+), 43 deletions(-) diff --git a/include/display.h b/include/display.h index 4091f0a9..670ed30c 100644 --- a/include/display.h +++ b/include/display.h @@ -3,15 +3,37 @@ #include "cyclic.h" #include "qrcode.h" +#define DISPLAY_PAGES (7) // number of paxcounter display pages + +// settings for oled display library +#define USE_BACKBUFFER 1 +#define MY_OLED OLED_128x64 +#define OLED_ADDR -1 +#define OLED_INVERT 0 +#define USE_HW_I2C 1 + +#ifndef DISPLAY_FLIP +#define DISPLAY_FLIP 0 +#endif + +// settings for qr code generator +#define QR_VERSION 3 // 29 x 29px +#define QR_SCALEFACTOR 2 // 29 -> 58x < 64px + +// settings for curve plotter +#define DISPLAY_WIDTH 128 // Width in pixels of OLED-display, must be 32X +#define DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 64X extern uint8_t DisplayIsOn, displaybuf[]; +void setup_display(int contrast = 0); void refreshTheDisplay(bool nextPage = false); void init_display(bool verbose = false); void shutdown_display(void); void draw_page(time_t t, bool nextpage); void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, const char *format, ...); +void dp_dump(uint8_t *pBuffer); void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message); void oledfillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t bRender); diff --git a/platformio.ini b/platformio.ini index 67094d96..0ee61057 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,7 +45,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.95 +release_version = 1.9.96 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 3 @@ -59,8 +59,8 @@ upload_speed = 115200 lib_deps_lora = MCCI LoRaWAN LMIC library@>=3.1.0 ; MCCI LMIC by Terrill Moore lib_deps_display = - ss_oled@>=3.3.1 ; simple and small OLED lib by Larry Bank - BitBang_I2C@>=1.3.0 + ss_oled@4.0.1 ; simple and small OLED lib by Larry Bank + BitBang_I2C@2.0.0 QRCode@>=0.0.1 lib_deps_matrix_display = Ultrathin_LED_Matrix@>=1.0.0 diff --git a/src/display.cpp b/src/display.cpp index 0765b452..b10fb7d9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -39,19 +39,6 @@ FONT_STRETCHED: 16x32px = 8 chars / line // local Tag for logging static const char TAG[] = __FILE__; -#define DISPLAY_PAGES (7) // number of paxcounter display pages - -// settings for oled display library -#define USE_BACKBUFFER - -// settings for qr code generator -#define QR_VERSION 3 // 29 x 29px -#define QR_SCALEFACTOR 2 // 29 -> 58x < 64px - -// settings for curve plotter -#define DISPLAY_WIDTH 128 // Width in pixels of OLED-display, must be 32X -#define DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 64X - // helper array for converting month values to text const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -60,6 +47,23 @@ uint8_t displaybuf[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8] = {0}; static uint8_t plotbuf[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8] = {0}; QRCode qrcode; +SSOLED ssoled; + +void setup_display(int contrast) { + int rc = oledInit(&ssoled, MY_OLED, OLED_ADDR, DISPLAY_FLIP, OLED_INVERT, + USE_HW_I2C, MY_OLED_SDA, MY_OLED_SCL, MY_OLED_RST, + 400000L); // use standard I2C bus at 400Khz + + assert(rc != OLED_NOT_FOUND); + + // set display buffer + oledSetBackBuffer(&ssoled, displaybuf); + if (contrast) + oledSetContrast(&ssoled, contrast); + + // clear display + oledFill(&ssoled, 0, 1); +} void init_display(bool verbose) { @@ -68,19 +72,7 @@ void init_display(bool verbose) { ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { - // init display -#ifndef DISPLAY_FLIP - oledInit(OLED_128x64, false, false, -1, -1, MY_OLED_RST, 400000L); -#else - oledInit(OLED_128x64, true, false, -1, -1, MY_OLED_RST, 400000L); -#endif - - // set display buffer - oledSetBackBuffer(displaybuf); - - // clear display - oledSetContrast(DISPLAYCONTRAST); - oledFill(0, 1); + setup_display(DISPLAYCONTRAST); if (verbose) { @@ -104,9 +96,9 @@ void init_display(bool verbose) { : "ext."); // give user some time to read or take picture - oledDumpBuffer(displaybuf); + dp_dump(displaybuf); delay(2000); - oledFill(0x00, 1); + oledFill(&ssoled, 0x00, 1); #endif // VERBOSE #if (HAS_LORA) @@ -117,7 +109,7 @@ void init_display(bool verbose) { snprintf(deveui, 17, "%016llX", *((uint64_t *)&buf)); // display DEVEUI as QR code on the left - oledSetContrast(30); + oledSetContrast(&ssoled, 30); dp_printqr(3, 3, deveui); // display DEVEUI as plain text on the right @@ -127,15 +119,15 @@ void init_display(bool verbose) { dp_printf(80, i + 3, FONT_NORMAL, 0, "%4.4s", deveui + i * 4); // give user some time to read or take picture - oledDumpBuffer(displaybuf); + dp_dump(displaybuf); delay(8000); - oledSetContrast(DISPLAYCONTRAST); - oledFill(0x00, 1); + oledSetContrast(&ssoled, DISPLAYCONTRAST); + oledFill(&ssoled, 0x00, 1); #endif // HAS_LORA } // verbose - oledPower(cfg.screenon); // set display off if disabled + oledPower(&ssoled, cfg.screenon); // set display off if disabled I2C_MUTEX_UNLOCK(); // release i2c bus access } // mutex @@ -164,7 +156,7 @@ void refreshTheDisplay(bool nextPage) { // set display on/off according to current device configuration if (DisplayIsOn != cfg.screenon) { DisplayIsOn = cfg.screenon; - oledPower(cfg.screenon); + oledPower(&ssoled, cfg.screenon); } #ifndef HAS_BUTTON @@ -176,7 +168,7 @@ void refreshTheDisplay(bool nextPage) { #endif draw_page(t, nextPage); - oledDumpBuffer(displaybuf); + dp_dump(displaybuf); I2C_MUTEX_UNLOCK(); // release i2c bus access @@ -214,7 +206,7 @@ start: if (nextpage) { DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); - oledFill(0, 1); + oledFill(&ssoled, 0, 1); } switch (DisplayPage) { @@ -307,7 +299,7 @@ start: // page 1: pax graph case 1: - oledDumpBuffer(plotbuf); + dp_dump(plotbuf); break; // page1 // page 2: GPS @@ -391,7 +383,7 @@ start: // page 6: blank screen case 6: #ifdef HAS_BUTTON - oledFill(0, 1); + oledFill(&ssoled, 0, 1); break; #else // don't show blank page if we are unattended DisplayPage++; // next page @@ -428,12 +420,14 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, len = vsnprintf(temp, len + 1, format, arg); } va_end(arg); - oledWriteString(0, x, y, temp, font, inv, false); + oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); if (temp != loc_buf) { free(temp); } } +void dp_dump(uint8_t *pBuffer) { oledDumpBuffer(&ssoled, pBuffer); } + void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { uint8_t qrcodeData[qrcode_getBufferSize(QR_VERSION)]; qrcode_initText(&qrcode, qrcodeData, QR_VERSION, ECC_HIGH, Message); @@ -460,7 +454,7 @@ void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { void oledfillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t bRender) { for (uint16_t xi = x; xi < x + width; xi++) - oledDrawLine(xi, y, xi, y + height - 1, bRender); + oledDrawLine(&ssoled, xi, y, xi, y + height - 1, bRender); } int oledDrawPixel(uint8_t *buf, const uint16_t x, const uint16_t y,