From 322a109ed374e403c3b68b434bcb06e209f54bf3 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 2 Aug 2022 13:59:51 +0200 Subject: [PATCH 01/45] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46b1964b..1e2f80d1 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,9 @@ You can build this project battery powered using ESP32 deep sleep mode and reach *LoRa & SPI*: +- **LilyGo: [Paxcounter-Board*](https://www.aliexpress.com/item/32915894264.html?spm=a2g0o.productlist.0.0.3d656325QrcfQc&algo_pvid=4a150199-63e7-4d21-bdb1-b48164537744&algo_exp_id=4a150199-63e7-4d21-bdb1-b48164537744-2&pdp_ext_f=%7B%22sku_id%22%3A%2212000023374441919%22%7D)** +- TTGO: T1*, T2*, T3*, T-Beam, T-Fox - Heltec: LoRa-32 v1 and v2 -- TTGO: [Paxcounter-Board*](https://www.aliexpress.com/item/32915894264.html?spm=a2g0o.productlist.0.0.3d656325QrcfQc&algo_pvid=4a150199-63e7-4d21-bdb1-b48164537744&algo_exp_id=4a150199-63e7-4d21-bdb1-b48164537744-2&pdp_ext_f=%7B%22sku_id%22%3A%2212000023374441919%22%7D), T1*, T2*, T3*, T-Beam, T-Fox - Pycom: LoPy, LoPy4, FiPy - Radioshuttle.de: [ECO Power Board](https://www.radioshuttle.de/esp32-eco-power/esp32-eco-power-board/) - WeMos: LoLin32 + [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora), From c78250b8d392e72f11905821ec6a991a01ae36a7 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 10 Aug 2022 14:43:57 +0200 Subject: [PATCH 02/45] fix compile error "OLED_WHITE" --- include/display.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/display.h b/include/display.h index b30ec372..b3656121 100644 --- a/include/display.h +++ b/include/display.h @@ -40,10 +40,10 @@ #endif #ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR OLED_WHITE +#define MY_DISPLAY_FGCOLOR 1 //OLED_WHITE #endif #ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR OLED_BLACK +#define MY_DISPLAY_BGCOLOR 0 //OLED_BLACK #endif // settings for TFT display library @@ -57,10 +57,10 @@ #define MY_DISPLAY_FIRSTLINE 30 #ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR TFT_WHITE +#define MY_DISPLAY_FGCOLOR 0xFFFF //TFT_WHITE #endif #ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR TFT_BLACK +#define MY_DISPLAY_BGCOLOR 0x0000 //TFT_BLACK #endif #ifndef TOUCH_CS From 09cc2f57b1bcea6df5fc5ad2ba3373fdecff1378 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 10 Aug 2022 16:40:38 +0200 Subject: [PATCH 03/45] sanitize display logic code --- include/display.h | 2 +- src/display.cpp | 56 +++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/include/display.h b/include/display.h index b3656121..20194b43 100644 --- a/include/display.h +++ b/include/display.h @@ -107,7 +107,7 @@ void dp_drawPage(bool nextpage); void dp_printf(const char *format, ...); void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer = NULL); -void dp_setTextCursor(int col = 0, int row = MY_DISPLAY_FIRSTLINE); +void dp_setTextCursor(int col, int row); void dp_contrast(uint8_t contrast); void dp_clear(void); void dp_power(uint8_t screenon); diff --git a/src/display.cpp b/src/display.cpp index 6cb029f4..06f87ea7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -100,7 +100,8 @@ void dp_init(bool verbose) { dp_printf("Software v%s\r\n", PROGVERSION); dp_printf("ESP32 %d cores\r\n", chip_info.cores); dp_printf("Chip Rev.%d\r\n", chip_info.revision); - dp_printf("WiFi%s%s\r\n", (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", + dp_printf("WiFi%s%s\r\n", + (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", (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."); @@ -185,31 +186,29 @@ void dp_drawPage(bool nextpage) { time_t now; struct tm timeinfo = {0}; - if (nextpage) { - DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); - dp_clear(); - } - // update counter values from libpax libpax_counter_count(&count); - // cursor home - dp_setTextCursor(0, 0); + if (nextpage) { + DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); + dp_clear(); + } else + dp_setTextCursor(0, 0); // line 1/2: pax counter // display number of unique macs total Wifi + BLE - if (DisplayPage < 3) { + if (DisplayPage <= 2) { dp_setFont(MY_FONT_LARGE); dp_printf("%-8d", count.pax); } switch (DisplayPage) { - // page 0: parameters overview - // page 1: lorawan parameters - // page 2: GPS - // page 3: BME280/680 - // page 4: time + // page 0: pax + parameters overview + // page 1: pax + lorawan parameters + // page 2: pax + GPS lat/lon + // page 3: BME280/680 values + // page 4: timeofday // page 5: pax graph // page 6: blank screen @@ -217,7 +216,7 @@ void dp_drawPage(bool nextpage) { case 0: dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(); + dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); // line 3: wifi + bluetooth counters // WIFI:abcde BLTH:abcde @@ -309,8 +308,9 @@ void dp_drawPage(bool nextpage) { // 7|SNR:-0000 RSSI:-0000 dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(); - dp_printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); + dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); + dp_printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, + LMIC.radio_txpow); dp_printf("Dev:%08X DR:%1d\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, @@ -319,8 +319,9 @@ void dp_drawPage(bool nextpage) { dp_dump(); break; -#else // flip page if we are unattended +#else // skip this page DisplayPage++; + break; #endif // HAS_LORA // ---------- page 2: GPS ---------- @@ -336,15 +337,16 @@ void dp_drawPage(bool nextpage) { // show latitude and longitude dp_setFont(MY_FONT_STRETCHED); - dp_setTextCursor(); + dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); dp_printf("%c%09.6f\r\n", gps.location.rawLat().negative ? 'S' : 'N', gps.location.lat()); dp_printf("%c%09.6f", gps.location.rawLng().negative ? 'W' : 'E', gps.location.lng()); dp_dump(); break; -#else // flip page if we are unattended +#else // skip this page DisplayPage++; + break; #endif // ---------- page 3: BME280/680 ---------- @@ -360,23 +362,24 @@ void dp_drawPage(bool nextpage) { dp_printf("IAQ: %-6.0f", bme_status.iaq); #endif dp_dump(); - break; // page 3 -#else // flip page if we are unattended + break; +#else // skip this page DisplayPage++; -#endif // HAS_BME + break; +#endif // HAS_BME // ---------- page 4: time ---------- case 4: time(&now); localtime_r(&now, &timeinfo); - strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo); dp_setFont(MY_FONT_STRETCHED); dp_setTextCursor(0, 0); dp_printf("Timeofday:"); dp_setTextCursor(0, 26); dp_setFont(MY_FONT_LARGE); + 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); @@ -397,8 +400,9 @@ void dp_drawPage(bool nextpage) { #ifdef HAS_BUTTON dp_clear(); break; -#else // flip page if we are unattended +#else // skip this page DisplayPage++; + break; #endif } // switch (page) @@ -445,7 +449,7 @@ void dp_setFont(int font, int inv) { tft.setTextFont(2); // 16px break; } - + #endif } From 63985162972dc9e760a435a9f2a919e234bb65ba Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 14 Aug 2022 15:49:32 +0200 Subject: [PATCH 04/45] sanitize display code --- src/display.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index 06f87ea7..0b902355 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -151,6 +151,7 @@ void dp_refresh(bool nextPage) { #ifndef HAS_BUTTON static uint32_t framecounter = 0; + const uint32_t flip_threshold = DISPLAYCYCLE * 1000 / DISPLAYREFRESH_MS; #endif // if display is switched off we don't refresh it to relax cpu @@ -165,7 +166,7 @@ void dp_refresh(bool nextPage) { #ifndef HAS_BUTTON // auto flip page if we are in unattended mode - if ((++framecounter) > (DISPLAYCYCLE * 1000 / DISPLAYREFRESH_MS)) { + if (++framecounter > flip_threshold) { framecounter = 0; nextPage = true; } From cb137109d68466dfff69630321ad07f4543377c6 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 14 Aug 2022 15:55:23 +0200 Subject: [PATCH 05/45] bugfix display logic --- src/display.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 0b902355..4601ab8d 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -196,13 +196,6 @@ void dp_drawPage(bool nextpage) { } else dp_setTextCursor(0, 0); - // line 1/2: pax counter - // display number of unique macs total Wifi + BLE - if (DisplayPage <= 2) { - dp_setFont(MY_FONT_LARGE); - dp_printf("%-8d", count.pax); - } - switch (DisplayPage) { // page 0: pax + parameters overview @@ -216,6 +209,10 @@ void dp_drawPage(bool nextpage) { // ---------- page 0: parameters overview ---------- case 0: + // show pax + dp_setFont(MY_FONT_LARGE); + dp_printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); @@ -308,6 +305,10 @@ void dp_drawPage(bool nextpage) { // 6|fUp:000000 fDn:000000 // 7|SNR:-0000 RSSI:-0000 + // show pax + dp_setFont(MY_FONT_LARGE); + dp_printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); dp_printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, @@ -330,6 +331,10 @@ void dp_drawPage(bool nextpage) { #if (HAS_GPS) + // show pax + dp_setFont(MY_FONT_LARGE); + dp_printf("%-8d", count.pax); + // show satellite status at bottom line dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, 56); From 0af786224f61eaa697862e213fca9dc1ac98c2ea Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 14 Aug 2022 16:49:30 +0200 Subject: [PATCH 06/45] display code sanitization --- include/display.h | 13 ++- src/display.cpp | 257 +++++++++++++++++++--------------------------- src/ota.cpp | 20 ++-- 3 files changed, 122 insertions(+), 168 deletions(-) diff --git a/include/display.h b/include/display.h index 20194b43..3c31d5e8 100644 --- a/include/display.h +++ b/include/display.h @@ -9,8 +9,10 @@ #if (HAS_DISPLAY) == 1 #include +extern ONE_BIT_DISPLAY *dp; #elif (HAS_DISPLAY) == 2 #include +extern TFT_eSPI *dp; #endif #define DISPLAY_PAGES (7) // number of paxcounter display pages @@ -40,10 +42,10 @@ #endif #ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR 1 //OLED_WHITE +#define MY_DISPLAY_FGCOLOR 1 // OLED_WHITE #endif #ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR 0 //OLED_BLACK +#define MY_DISPLAY_BGCOLOR 0 // OLED_BLACK #endif // settings for TFT display library @@ -57,10 +59,10 @@ #define MY_DISPLAY_FIRSTLINE 30 #ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR 0xFFFF //TFT_WHITE +#define MY_DISPLAY_FGCOLOR 0xFFFF // TFT_WHITE #endif #ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR 0x0000 //TFT_BLACK +#define MY_DISPLAY_BGCOLOR 0x0000 // TFT_BLACK #endif #ifndef TOUCH_CS @@ -104,7 +106,6 @@ 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_printf(const char *format, ...); void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer = NULL); void dp_setTextCursor(int col, int row); @@ -112,8 +113,6 @@ void dp_contrast(uint8_t contrast); void dp_clear(void); void dp_power(uint8_t screenon); 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); void dp_scrollHorizontal(uint8_t *buf, const uint16_t width, const uint16_t height, bool left = true); void dp_scrollVertical(uint8_t *buf, const uint16_t width, diff --git a/src/display.cpp b/src/display.cpp index 4601ab8d..3a273d27 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -45,11 +45,12 @@ uint8_t DisplayIsOn = 0; hw_timer_t *displayIRQ = NULL; static QRCode qrcode; +// select display driver #ifdef HAS_DISPLAY #if (HAS_DISPLAY) == 1 -static ONE_BIT_DISPLAY oled; +ONE_BIT_DISPLAY *dp = NULL; #elif (HAS_DISPLAY) == 2 -static TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); +TFT_eSPI *dp = NULL; #else #error Unknown display type specified in hal file #endif @@ -58,20 +59,21 @@ static TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); void dp_setup(int contrast) { #if (HAS_DISPLAY) == 1 // I2C OLED - oled.setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST); - oled.setBitBang(false); - oled.I2Cbegin(OLED_TYPE, OLED_ADDR, OLED_FREQUENCY); - oled.allocBuffer(); // render all outputs to lib internal backbuffer - oled.setTextWrap(false); - oled.setRotation( + dp = new ONE_BIT_DISPLAY; + dp->setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST); + dp->setBitBang(false); + dp->I2Cbegin(OLED_TYPE, OLED_ADDR, OLED_FREQUENCY); + dp->allocBuffer(); // render all outputs to lib internal backbuffer + dp->setTextWrap(false); + dp->setRotation( MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280° #elif (HAS_DISPLAY) == 2 // SPI TFT - - tft.init(); - tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); - tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); - tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); + 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->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); #endif @@ -96,15 +98,15 @@ void dp_init(bool verbose) { esp_chip_info(&chip_info); dp_setFont(MY_FONT_NORMAL); - dp_printf("** PAXCOUNTER **\r\n"); - dp_printf("Software v%s\r\n", PROGVERSION); - dp_printf("ESP32 %d cores\r\n", chip_info.cores); - dp_printf("Chip Rev.%d\r\n", chip_info.revision); - dp_printf("WiFi%s%s\r\n", - (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", - (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."); + dp->printf("** PAXCOUNTER **\r\n"); + dp->printf("Software v%s\r\n", PROGVERSION); + dp->printf("ESP32 %d cores\r\n", chip_info.cores); + dp->printf("Chip Rev.%d\r\n", chip_info.revision); + dp->printf("WiFi%s%s\r\n", + (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", + (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(); @@ -127,10 +129,10 @@ void dp_init(bool verbose) { const int x_offset = QR_SCALEFACTOR * 29 + 14; dp_setFont(MY_FONT_NORMAL); dp_setTextCursor(x_offset, 0); - dp_printf("DEVEUI:\r\n"); + dp->printf("DEVEUI:\r\n"); for (uint8_t i = 0; i <= 3; i++) { dp_setTextCursor(x_offset, i * 8 + 20); - dp_printf("%4.4s", deveui + i * 4); + dp->printf("%4.4s", deveui + i * 4); } // give user some time to read or take picture @@ -211,8 +213,8 @@ void dp_drawPage(bool nextpage) { // show pax dp_setFont(MY_FONT_LARGE); - dp_printf("%-8d", count.pax); - + dp->printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); @@ -221,43 +223,43 @@ void dp_drawPage(bool nextpage) { #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", count.wifi_count); + dp->printf("WIFI:%-5d", count.wifi_count); else - dp_printf("WIFI:off"); + dp->printf("WIFI:off"); if (cfg.blescan) - dp_printf("BLTH:%-5d", count.ble_count); + dp->printf("BLTH:%-5d", count.ble_count); else - dp_printf(" BLTH:off"); + dp->printf(" BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", count.wifi_count); + dp->printf("WIFI:%-5d", count.wifi_count); else - dp_printf("WIFI:off"); + dp->printf("WIFI:off"); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) - dp_printf("BLTH:%-5d", count.ble_count); - dp_printf("BLTH:off"); + dp->printf("BLTH:%-5d", count.ble_count); + dp->printf("BLTH:off"); #else - dp_printf("Sniffer disabled"); + dp->printf("Sniffer disabled"); #endif - dp_printf("\r\n"); + dp->printf("\r\n"); // line 4: Battery + GPS status + Wifi channel // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306) if (batt_level == 0) - dp_printf("No batt "); + dp->printf("No batt "); else - dp_printf("Batt:%3u%% ", batt_level); + dp->printf("Batt:%3u%% ", batt_level); #else - dp_printf(" "); + dp->printf(" "); #endif - dp_printf("chan:%02u\r\n", channel); + dp->printf("chan:%02u\r\n", channel); // 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(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); + dp->printf(" Mem:%4dKB\r\n", getFreeRAM() / 1024); // line 6: time + date // Wed Jan 12 21:49:08 * @@ -267,15 +269,15 @@ void dp_drawPage(bool nextpage) { time(&now); localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); - dp_printf("%.20s", strftime_buf); + dp->printf("%.20s", strftime_buf); // display inverse timeState if clock controller is enabled #if (defined HAS_DCF77) || (defined HAS_IF482) dp_setFont(MY_FONT_SMALL, 1); - dp_printf("%c\r\n", timeState); + dp->printf("%c\r\n", timeState); dp_setFont(MY_FONT_SMALL, 0); #else - dp_printf("%c\r\n", timeState); + dp->printf("%c\r\n", timeState); #endif #endif // TIME_SYNC_INTERVAL @@ -284,10 +286,10 @@ void dp_drawPage(bool nextpage) { #if (HAS_LORA) // LMiC event display - dp_printf("%-16s ", lmic_event_msg); + dp->printf("%-16s ", lmic_event_msg); // LORA datarate, display inverse if ADR disabled dp_setFont(MY_FONT_SMALL, !cfg.adrmode); - dp_printf("%-4s", getSfName(updr2rps(LMIC.datarate))); + dp->printf("%-4s", getSfName(updr2rps(LMIC.datarate))); dp_setFont(MY_FONT_SMALL, 0); #endif // HAS_LORA @@ -307,17 +309,17 @@ void dp_drawPage(bool nextpage) { // show pax dp_setFont(MY_FONT_LARGE); - dp_printf("%-8d", count.pax); - + dp->printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); - dp_printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, - LMIC.radio_txpow); - dp_printf("Dev:%08X DR:%1d\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, - LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); - dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); + dp->printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, + LMIC.radio_txpow); + dp->printf("Dev:%08X DR:%1d\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, + LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); + dp->printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); dp_dump(); break; @@ -333,21 +335,21 @@ void dp_drawPage(bool nextpage) { // show pax dp_setFont(MY_FONT_LARGE); - dp_printf("%-8d", count.pax); - + dp->printf("%-8d", count.pax); + // 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"); + 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, MY_DISPLAY_FIRSTLINE); - dp_printf("%c%09.6f\r\n", gps.location.rawLat().negative ? 'S' : 'N', - gps.location.lat()); - dp_printf("%c%09.6f", gps.location.rawLng().negative ? 'W' : 'E', - gps.location.lng()); + dp->printf("%c%09.6f\r\n", gps.location.rawLat().negative ? 'S' : 'N', + gps.location.lat()); + dp->printf("%c%09.6f", gps.location.rawLng().negative ? 'W' : 'E', + gps.location.lng()); dp_dump(); break; #else // skip this page @@ -361,11 +363,11 @@ void dp_drawPage(bool nextpage) { #if (HAS_BME) dp_setFont(MY_FONT_STRETCHED); dp_setTextCursor(0, 0); - dp_printf("TMP: %-6.1f\r\n", bme_status.temperature); - dp_printf("HUM: %-6.1f\r\n", bme_status.humidity); - dp_printf("PRE: %-6.1f\r\n", bme_status.pressure); + dp->printf("TMP: %-6.1f\r\n", bme_status.temperature); + dp->printf("HUM: %-6.1f\r\n", bme_status.humidity); + dp->printf("PRE: %-6.1f\r\n", bme_status.pressure); #ifdef HAS_BME680 - dp_printf("IAQ: %-6.0f", bme_status.iaq); + dp->printf("IAQ: %-6.0f", bme_status.iaq); #endif dp_dump(); break; @@ -382,13 +384,13 @@ void dp_drawPage(bool nextpage) { dp_setFont(MY_FONT_STRETCHED); dp_setTextCursor(0, 0); - dp_printf("Timeofday:"); + dp->printf("Timeofday:"); dp_setTextCursor(0, 26); dp_setFont(MY_FONT_LARGE); 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_printf("%21.1f", uptime() / 1000.0); + dp->printf("%21.1f", uptime() / 1000.0); dp_dump(); break; @@ -418,104 +420,65 @@ void dp_drawPage(bool nextpage) { void dp_setTextCursor(int x, int y) { #if (HAS_DISPLAY) == 1 - oled.setCursor(x, y); + dp->setCursor(x, y); #elif (HAS_DISPLAY) == 2 - tft.setCursor(x, y); + dp->setCursor(x, y); #endif } void dp_setFont(int font, int inv) { + // handle invers printing + if (inv) + dp->setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR); + else + dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); + #if (HAS_DISPLAY) == 1 - // 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); - + dp->setFont(font); #elif (HAS_DISPLAY) == 2 - // 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 - tft.setTextFont(4); // 26px + dp->setTextFont(4); // 26px break; case MY_FONT_SMALL: // 6x8 on OLED case MY_FONT_NORMAL: // 8x8 on OLED default: - tft.setTextFont(2); // 16px + dp->setTextFont(2); // 16px break; } #endif } -void dp_printf(const char *format, ...) { - char loc_buf[64]; - char *temp = loc_buf; - va_list arg; - va_list copy; - va_start(arg, format); - va_copy(copy, arg); - int len = vsnprintf(temp, sizeof(loc_buf), format, copy); - va_end(copy); - if (len < 0) { - va_end(arg); - return; - }; - if (len >= sizeof(loc_buf)) { - temp = (char *)malloc(len + 1); - if (temp == NULL) { - va_end(arg); - return; - } - vsnprintf(temp, len + 1, format, arg); - } - va_end(arg); -#if (HAS_DISPLAY) == 1 - oled.write(temp); -#elif (HAS_DISPLAY) == 2 - tft.printf(temp); -#endif - if (temp != loc_buf) { - free(temp); - } -} - void dp_dump(uint8_t *pBuffer) { #if (HAS_DISPLAY) == 1 if (pBuffer) - memcpy(oled.getBuffer(), pBuffer, PLOTBUFFERSIZE); - oled.display(); + memcpy(dp->getBuffer(), pBuffer, PLOTBUFFERSIZE); + dp->display(); #elif (HAS_DISPLAY) == 2 if (pBuffer) - tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, + dp->drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, MY_DISPLAY_FGCOLOR); #endif } void dp_clear(void) { #if (HAS_DISPLAY) == 1 - oled.fillScreen(MY_DISPLAY_BGCOLOR); - oled.display(); + dp->fillScreen(MY_DISPLAY_BGCOLOR); + dp->display(); #elif (HAS_DISPLAY) == 2 - tft.fillScreen(MY_DISPLAY_BGCOLOR); + dp->fillScreen(MY_DISPLAY_BGCOLOR); #endif dp_setTextCursor(0, 0); } void dp_contrast(uint8_t contrast) { #if (HAS_DISPLAY) == 1 - oled.setContrast(contrast); + dp->setContrast(contrast); #elif (HAS_DISPLAY) == 2 // to do: gamma correction for TFT #endif @@ -523,7 +486,7 @@ void dp_contrast(uint8_t contrast) { void dp_power(uint8_t screenon) { #if (HAS_DISPLAY) == 1 - oled.setPower(screenon); + dp->setPower(screenon); #elif (HAS_DISPLAY) == 2 // to come #endif @@ -531,7 +494,7 @@ void dp_power(uint8_t screenon) { void dp_shutdown(void) { #if (HAS_DISPLAY) == 1 - oled.setPower(false); + dp->setPower(false); delay(DISPLAYREFRESH_MS / 1000 * 1.1); #elif (HAS_DISPLAY) == 2 // to come @@ -542,7 +505,7 @@ void dp_shutdown(void) { void dp_message(const char *msg, int line, bool invers) { dp_setFont(MY_FONT_SMALL, invers ? 1 : 0); dp_setTextCursor(0, line * 8); - dp_printf("%-16s", msg); + dp->printf("%-16s", msg); dp_dump(); } // dp_message @@ -556,32 +519,24 @@ void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { for (uint8_t y = 0; y < qrcode.size; y++) for (uint8_t x = 0; x < qrcode.size; x++) if (!qrcode_getModule(&qrcode, x, y)) // "black" - dp_fillRect(x * QR_SCALEFACTOR + offset_x, - y * QR_SCALEFACTOR + offset_y, QR_SCALEFACTOR, - QR_SCALEFACTOR, false); + dp->fillRect(x * QR_SCALEFACTOR + offset_x, + y * QR_SCALEFACTOR + offset_y, QR_SCALEFACTOR, + QR_SCALEFACTOR, MY_DISPLAY_FGCOLOR); // draw horizontal frame lines - dp_fillRect(0, 0, qrcode.size * QR_SCALEFACTOR + 2 * offset_x, offset_y, - false); - dp_fillRect(0, qrcode.size * QR_SCALEFACTOR + offset_y, - qrcode.size * QR_SCALEFACTOR + 2 * offset_x, offset_y, false); + dp->fillRect(0, 0, qrcode.size * QR_SCALEFACTOR + 2 * offset_x, offset_y, + MY_DISPLAY_FGCOLOR); + dp->fillRect(0, qrcode.size * QR_SCALEFACTOR + offset_y, + qrcode.size * QR_SCALEFACTOR + 2 * offset_x, offset_y, + MY_DISPLAY_FGCOLOR); // draw vertical frame lines - dp_fillRect(0, 0, offset_x, qrcode.size * QR_SCALEFACTOR + 2 * offset_y, - false); - dp_fillRect(qrcode.size * QR_SCALEFACTOR + offset_x, 0, offset_x, - qrcode.size * QR_SCALEFACTOR + 2 * offset_y, false); + dp->fillRect(0, 0, offset_x, qrcode.size * QR_SCALEFACTOR + 2 * offset_y, + MY_DISPLAY_FGCOLOR); + dp->fillRect(qrcode.size * QR_SCALEFACTOR + offset_x, 0, offset_x, + qrcode.size * QR_SCALEFACTOR + 2 * offset_y, MY_DISPLAY_FGCOLOR); } // ------------- graphics primitives ----------------- -void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, - uint8_t bRender) { -#if (HAS_DISPLAY) == 1 - oled.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR); -#elif (HAS_DISPLAY) == 2 - tft.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR); -#endif -} - int dp_drawPixel(uint8_t *buf, const uint16_t x, const uint16_t y, const uint8_t dot) { diff --git a/src/ota.cpp b/src/ota.cpp index 77726708..c11714cd 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -51,12 +51,12 @@ void start_ota_update() { dp_setup(); dp_setFont(MY_FONT_NORMAL); - dp_printf("SOFTWARE UPDATE\r\n"); - dp_printf("WiFi connect ..\r\n"); - dp_printf("Has Update? ..\r\n"); - dp_printf("Fetching ..\r\n"); - dp_printf("Downloading ..\r\n"); - dp_printf("Rebooting ..\r\n"); + dp->printf("SOFTWARE UPDATE\r\n"); + dp->printf("WiFi connect ..\r\n"); + dp->printf("Has Update? ..\r\n"); + dp->printf("Fetching ..\r\n"); + dp->printf("Downloading ..\r\n"); + dp->printf("Rebooting ..\r\n"); dp_dump(); #endif @@ -326,11 +326,11 @@ void ota_display(const uint8_t row, const std::string status, const std::string msg) { #ifdef HAS_DISPLAY dp_setTextCursor(14 * 8, row * 8); - dp_printf(status.substr(0, 2).c_str()); + dp->printf(status.substr(0, 2).c_str()); if (!msg.empty()) { - dp_printf(" "); - dp_printf(msg.substr(0, 16).c_str()); - // dp_printf("\r\n"); + dp->printf(" "); + dp->printf(msg.substr(0, 16).c_str()); + // dp->printf("\r\n"); } dp_dump(); #endif From 6bfcf4d367d584fa5bc8a4d55adeb265bc8e85b7 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 14 Aug 2022 18:19:45 +0200 Subject: [PATCH 07/45] display code sanitization --- include/display.h | 1 - src/display.cpp | 38 +++++++++++++++----------------------- src/main.cpp | 4 ++-- src/ota.cpp | 2 +- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/include/display.h b/include/display.h index 3c31d5e8..7c102942 100644 --- a/include/display.h +++ b/include/display.h @@ -108,7 +108,6 @@ void dp_message(const char *msg, int line, bool invers); void dp_drawPage(bool nextpage); void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer = NULL); -void dp_setTextCursor(int col, int row); void dp_contrast(uint8_t contrast); void dp_clear(void); void dp_power(uint8_t screenon); diff --git a/src/display.cpp b/src/display.cpp index 3a273d27..586e9684 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -128,10 +128,10 @@ void dp_init(bool verbose) { // display DEVEUI as plain text on the right const int x_offset = QR_SCALEFACTOR * 29 + 14; dp_setFont(MY_FONT_NORMAL); - dp_setTextCursor(x_offset, 0); + dp->setCursor(x_offset, 0); dp->printf("DEVEUI:\r\n"); for (uint8_t i = 0; i <= 3; i++) { - dp_setTextCursor(x_offset, i * 8 + 20); + dp->setCursor(x_offset, i * 8 + 20); dp->printf("%4.4s", deveui + i * 4); } @@ -189,14 +189,11 @@ void dp_drawPage(bool nextpage) { time_t now; struct tm timeinfo = {0}; - // update counter values from libpax - libpax_counter_count(&count); - if (nextpage) { DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); dp_clear(); } else - dp_setTextCursor(0, 0); + dp->setCursor(0, 0); switch (DisplayPage) { @@ -212,11 +209,12 @@ void dp_drawPage(bool nextpage) { case 0: // show pax + libpax_counter_count(&count); dp_setFont(MY_FONT_LARGE); dp->printf("%-8d", count.pax); dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); + dp->setCursor(0, MY_DISPLAY_FIRSTLINE); // line 3: wifi + bluetooth counters // WIFI:abcde BLTH:abcde @@ -308,11 +306,12 @@ void dp_drawPage(bool nextpage) { // 7|SNR:-0000 RSSI:-0000 // show pax + libpax_counter_count(&count); dp_setFont(MY_FONT_LARGE); dp->printf("%-8d", count.pax); dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(0, MY_DISPLAY_FIRSTLINE); + dp->setCursor(0, MY_DISPLAY_FIRSTLINE); dp->printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); dp->printf("Dev:%08X DR:%1d\r\n", LMIC.devaddr, LMIC.datarate); @@ -334,18 +333,19 @@ void dp_drawPage(bool nextpage) { #if (HAS_GPS) // show pax + libpax_counter_count(&count); dp_setFont(MY_FONT_LARGE); dp->printf("%-8d", count.pax); // show satellite status at bottom line dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(0, 56); + dp->setCursor(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, MY_DISPLAY_FIRSTLINE); + dp->setCursor(0, MY_DISPLAY_FIRSTLINE); dp->printf("%c%09.6f\r\n", gps.location.rawLat().negative ? 'S' : 'N', gps.location.lat()); dp->printf("%c%09.6f", gps.location.rawLng().negative ? 'W' : 'E', @@ -362,7 +362,7 @@ void dp_drawPage(bool nextpage) { #if (HAS_BME) dp_setFont(MY_FONT_STRETCHED); - dp_setTextCursor(0, 0); + dp->setCursor(0, 0); dp->printf("TMP: %-6.1f\r\n", bme_status.temperature); dp->printf("HUM: %-6.1f\r\n", bme_status.humidity); dp->printf("PRE: %-6.1f\r\n", bme_status.pressure); @@ -383,9 +383,9 @@ void dp_drawPage(bool nextpage) { localtime_r(&now, &timeinfo); dp_setFont(MY_FONT_STRETCHED); - dp_setTextCursor(0, 0); + dp->setCursor(0, 0); dp->printf("Timeofday:"); - dp_setTextCursor(0, 26); + dp->setCursor(0, 26); dp_setFont(MY_FONT_LARGE); strftime(strftime_buf, sizeof(strftime_buf), "%T", &timeinfo); dp->printf("%.8s\r\n", strftime_buf); @@ -418,14 +418,6 @@ void dp_drawPage(bool nextpage) { // ------------- display helper functions ----------------- -void dp_setTextCursor(int x, int y) { -#if (HAS_DISPLAY) == 1 - dp->setCursor(x, y); -#elif (HAS_DISPLAY) == 2 - dp->setCursor(x, y); -#endif -} - void dp_setFont(int font, int inv) { // handle invers printing @@ -473,7 +465,7 @@ void dp_clear(void) { #elif (HAS_DISPLAY) == 2 dp->fillScreen(MY_DISPLAY_BGCOLOR); #endif - dp_setTextCursor(0, 0); + dp->setCursor(0, 0); } void dp_contrast(uint8_t contrast) { @@ -504,7 +496,7 @@ void dp_shutdown(void) { // print static message on display void dp_message(const char *msg, int line, bool invers) { dp_setFont(MY_FONT_SMALL, invers ? 1 : 0); - dp_setTextCursor(0, line * 8); + dp->setCursor(0, line * 8); dp->printf("%-16s", msg); dp_dump(); } // dp_message diff --git a/src/main.cpp b/src/main.cpp index e84c376a..9577c062 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -185,7 +185,7 @@ void setup() { // initialize display #ifdef HAS_DISPLAY - strcat_P(features, " OLED"); + strcat_P(features, " DISP"); DisplayIsOn = cfg.screenon; // display verbose info only after a coldstart (note: blocking call!) dp_init(RTC_runmode == RUNMODE_POWERCYCLE ? true : false); @@ -213,7 +213,7 @@ void setup() { #ifdef HAS_TWO_LED pinMode(HAS_TWO_LED, OUTPUT); - strcat_P(features, " LED1"); + strcat_P(features, " LED2"); #endif // use LED for power display if we have additional RGB LED, else for status diff --git a/src/ota.cpp b/src/ota.cpp index c11714cd..6f42c22c 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -325,7 +325,7 @@ retry: void ota_display(const uint8_t row, const std::string status, const std::string msg) { #ifdef HAS_DISPLAY - dp_setTextCursor(14 * 8, row * 8); + dp->setCursor(14 * 8, row * 8); dp->printf(status.substr(0, 2).c_str()); if (!msg.empty()) { dp->printf(" "); From fc1c46076912652c64702c93a0ab75715d8a6a2f Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 15 Aug 2022 14:41:39 +0200 Subject: [PATCH 08/45] display code sanitization --- include/display.h | 1 - src/display.cpp | 26 +++++++++----------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/include/display.h b/include/display.h index 7c102942..a530914c 100644 --- a/include/display.h +++ b/include/display.h @@ -105,7 +105,6 @@ void dp_refresh(bool nextPage = false); 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_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer = NULL); void dp_contrast(uint8_t contrast); diff --git a/src/display.cpp b/src/display.cpp index 586e9684..0fc28077 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -149,8 +149,15 @@ void dp_init(bool verbose) { } // dp_init +// 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]; + time_t now; + struct tm timeinfo = {0}; #ifndef HAS_BUTTON static uint32_t framecounter = 0; const uint32_t flip_threshold = DISPLAYCYCLE * 1000 / DISPLAYREFRESH_MS; @@ -174,22 +181,7 @@ void dp_refresh(bool nextPage) { } #endif - dp_drawPage(nextPage); - -} // refreshDisplay() - -void dp_drawPage(bool nextpage) { - - // write display content to display buffer - // nextpage = true -> flip 1 page - - struct count_payload_t count; // libpax count storage - static uint8_t DisplayPage = 0; - char timeState, strftime_buf[64]; - time_t now; - struct tm timeinfo = {0}; - - if (nextpage) { + if (nextPage) { DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); dp_clear(); } else @@ -414,7 +406,7 @@ void dp_drawPage(bool nextpage) { #endif } // switch (page) -} // dp_drawPage +} // dp_refresh // ------------- display helper functions ----------------- From 3e882c172384165c3510f01a2ee5012dcccfb025 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 16 Aug 2022 09:30:52 +0200 Subject: [PATCH 09/45] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1e2f80d1..d7130609 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Tutorial (in german language): https://www.heise.de/select/make/2019/1/1551099236518668 +[![CodeFactor](https://www.codefactor.io/repository/github/cyberman54/esp32-paxcounter/badge)](https://www.codefactor.io/repository/github/cyberman54/esp32-paxcounter) From 2fa14e21ff227f9b4e367369118e86483baaa6be Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 09:36:36 +0200 Subject: [PATCH 10/45] code sanitzations --- src/rcommand.cpp | 7 ------- src/timekeeper.cpp | 18 ------------------ 2 files changed, 25 deletions(-) diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 639e6c84..45bfce07 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -234,7 +234,6 @@ void set_loradr(uint8_t val[]) { getSfName(updr2rps(LMIC.datarate)), getBwName(updr2rps(LMIC.datarate)), getCrName(updr2rps(LMIC.datarate))); - } else ESP_LOGI( TAG, @@ -430,14 +429,12 @@ static const uint8_t cmdtablesize = // check and execute remote command void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) { - if (cmdlength == 0) return; uint8_t foundcmd[cmdlength], cursor = 0; while (cursor < cmdlength) { - int i = cmdtablesize; while (i--) { if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table @@ -462,7 +459,6 @@ void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) { break; } } // command parsing loop - } // rcmd_execute() // remote command processing task @@ -485,9 +481,7 @@ void rcmd_process(void *pvParameters) { // enqueue remote command void rcommand(const uint8_t *cmd, const size_t cmdlength) { - RcmdBuffer_t rcmd = {0}; - rcmd.cmdLen = cmdlength; memcpy(rcmd.cmd, cmd, cmdlength); @@ -505,7 +499,6 @@ void rcmd_deinit(void) { } esp_err_t rcmd_init(void) { - _ASSERT(RCMD_QUEUE_SIZE > 0); RcmdQueue = xQueueCreate(RCMD_QUEUE_SIZE, sizeof(RcmdBuffer_t)); if (RcmdQueue == 0) { diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index ee0a4ed1..e551b8ec 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -40,7 +40,6 @@ void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); } #ifdef GPS_INT // interrupt service routine triggered by GPS PPS void IRAM_ATTR GPSIRQ(void) { - BaseType_t xHigherPriorityTaskWoken = pdFALSE; // take timestamp @@ -54,7 +53,6 @@ void IRAM_ATTR GPSIRQ(void) { // interrupt service routine triggered by esp32 hardware timer void IRAM_ATTR CLOCKIRQ(void) { - BaseType_t xHigherPriorityTaskWoken = pdFALSE; // advance wall clock, if we have @@ -79,7 +77,6 @@ void IRAM_ATTR CLOCKIRQ(void) { } void calibrateTime(void) { - // kick off asynchronous lora timesync if we have #if (HAS_LORA_TIME) timesync_request(); @@ -106,12 +103,10 @@ void calibrateTime(void) { #endif #endif - } // calibrateTime() // set system time (UTC), calibrate RTC and RTC_INT pps bool setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { - struct timeval tv = {0}; // called with invalid timesource? @@ -123,7 +118,6 @@ bool setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { // do we have a valid time? if (timeIsValid(time_to_set)) { - // if we have msec fraction, then wait until top of second with // millisecond precision if (t_msec % 1000) { @@ -160,7 +154,6 @@ bool setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { return true; } else { - timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ); ESP_LOGV(TAG, "[%0.3f] Failed to synchronise time from source %c | unix sec " @@ -173,7 +166,6 @@ bool setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { // helper function to setup a pulse per second for time synchronisation void timepulse_init(void) { - // set esp-idf API sntp sync mode // sntp_init(); sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED); @@ -210,7 +202,6 @@ void timepulse_init(void) { // start cyclic time sync timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ); - } // timepulse_init // helper function to check plausibility of a given epoch time @@ -224,7 +215,6 @@ bool timeIsValid(time_t const t) { // helper function to calculate serial transmit time TickType_t tx_Ticks(uint32_t framesize, unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPins) { - uint32_t databits = ((config & 0x0c) >> 2) + 5; uint32_t stopbits = ((config & 0x20) >> 5) + 1; uint32_t txTime = (databits + stopbits + 1) * framesize * 1000.0 / baud; @@ -234,7 +224,6 @@ TickType_t tx_Ticks(uint32_t framesize, unsigned long baud, uint32_t config, } void clock_loop(void *taskparameter) { // ClockTask - uint32_t current_time = 0, previous_time = 0; time_t tt; struct tm t = {0}; @@ -248,7 +237,6 @@ void clock_loop(void *taskparameter) { // ClockTask // output the next second's pulse/telegram after pps arrived for (;;) { - // wait for timepulse and store UTC time xTaskNotifyWait(0x00, ULONG_MAX, ¤t_time, portMAX_DELAY); @@ -291,7 +279,6 @@ void clock_loop(void *taskparameter) { // ClockTask ESP_LOGD(TAG, "[%0.3f] DCF77: new frame for min %d", _seconds(), t.tm_min); } else { - // generate impulse if (t.tm_min == ClockMinute) { // ensure frame is recent DCF77_Pulse(ClockPulse & 1); // output next second @@ -311,12 +298,10 @@ void clock_loop(void *taskparameter) { // ClockTask #endif previous_time = current_time; - } // for } // clock_loop() void clock_init(void) { - // setup clock output interface #ifdef HAS_IF482 IF482.begin(HAS_IF482); @@ -337,7 +322,6 @@ void clock_init(void) { // we use compile date to create a time_t reference "in the past" time_t compileTime(void) { - char s_month[5]; int year; struct tm t = {0}; @@ -347,7 +331,6 @@ time_t compileTime(void) { static time_t secs = -1; if (secs == -1) { - // determine date sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; @@ -396,7 +379,6 @@ time_t mkgmtime(const struct tm *ptm) { } void time_init(void) { - #if (defined HAS_IF482 || defined HAS_DCF77) ESP_LOGI(TAG, "Starting clock controller..."); clock_init(); From c9303e916d187e3b89eee3a0fd886422c69496d2 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 09:41:41 +0200 Subject: [PATCH 11/45] code sanitizations --- src/lorawan.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 1d40e5eb..cda3a2d8 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -21,18 +21,17 @@ TaskHandle_t lmicTask = NULL, lorasendTask = NULL; char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t { - public: MyHalConfig_t(){}; // set SPI pins to board configuration, pins may come from pins_arduino.h - virtual void begin(void) override { + void begin(void) override { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); } - // virtual void end(void) override + // void end(void) override - // virtual ostime_t setModuleActive(bool state) override + // ostime_t setModuleActive(bool state) override }; static MyHalConfig_t myHalConfig{}; @@ -50,9 +49,7 @@ static const lmic_pinmap myPinmap = { .pConfig = &myHalConfig}; void lora_setupForNetwork(bool preJoin) { - if (preJoin) { - #if CFG_LMIC_US_like // in the US, with TTN, it saves join time if we start on subband 1 // (channels 8-15). This will get overridden after the join by @@ -196,7 +193,6 @@ void lora_send(void *pvParameters) { MessageBuffer_t SendBuffer; while (1) { - // postpone until we are joined if we are not while (!LMIC.devaddr) { vTaskDelay(pdMS_TO_TICKS(500)); @@ -213,7 +209,6 @@ void lora_send(void *pvParameters) { switch (LMIC_setTxData2_strict(SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize, (cfg.countermode & 0x02))) { - case LMIC_ERROR_SUCCESS: #if (TIME_SYNC_LORASERVER) // if last packet sent was a timesync request, store TX timestamp @@ -237,7 +232,6 @@ void lora_send(void *pvParameters) { break; default: // other LMIC return code ESP_LOGE(TAG, "LMIC error, message not sent and deleted"); - } // switch delay(2); // yield to CPU } // while(1) @@ -351,7 +345,6 @@ void lmictask(void *pvParameters) { // lmic event handler void myEventCallback(void *pUserData, ev_t ev) { - // using message descriptors from LMIC library static const char *const evNames[] = {LMIC_EVENT_NAME_TABLE__INIT}; // get current length of lora send queue @@ -366,7 +359,6 @@ void myEventCallback(void *pUserData, ev_t ev) { // process current event message switch (ev) { - case EV_TXCOMPLETE: // -> processed in lora_send() break; @@ -411,7 +403,6 @@ void myEventCallback(void *pUserData, ev_t ev) { // event EV_RXCOMPLETE message handler void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, size_t nMsg) { - // display amount of received data if (nMsg) ESP_LOGI(TAG, "Received %u byte(s) of payload on port %u", nMsg, port); @@ -419,7 +410,6 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, ESP_LOGI(TAG, "Received empty message on port %u", port); switch (port) { - // rcommand received -> call interpreter case RCMDPORT: rcommand(pMsg, nMsg); @@ -432,7 +422,6 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, timesync_serverAnswer(const_cast(pMsg), nMsg); break; #endif - } // switch } @@ -513,7 +502,6 @@ bool ttn_rtc_restore() { // https://github.com/JackGruber/ESP32-LMIC-DeepSleep-example/blob/master/src/main.cpp void SaveLMICToRTC(int deepsleep_sec) { - // ESP32 can't track millis during DeepSleep and no option to advance // millis after DeepSleep. Therefore reset DutyCyles before saving LMIC struct From 5327f17237cf2f03088aedd89f0e8602a55493fe Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 09:47:40 +0200 Subject: [PATCH 12/45] code sanitizations --- src/gpsread.cpp | 10 ---------- src/ledmatrixdisplay.cpp | 6 ------ src/ota.cpp | 4 ---- src/power.cpp | 6 ------ 4 files changed, 26 deletions(-) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 3f1e0acd..2adf6aec 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -87,7 +87,6 @@ byte CFG_CFG[] = { // helper functions to send UBX commands to ublox gps chip void sendPacket(byte *packet, byte len) { - uint8_t CK_A = 0; uint8_t CK_B = 0; @@ -107,7 +106,6 @@ void restoreDefaults() { sendPacket(CFG_CFG, sizeof(CFG_CFG)); } void changeBaudrate() { sendPacket(CFG_PRT, sizeof(CFG_PRT)); } void disableNmea() { - // tinygps++ processes only $GPGGA/$GNGGA and $GPRMC/$GNRMC // thus, we disable all other NMEA messages @@ -128,7 +126,6 @@ void disableNmea() { // initialize and configure GPS int gps_init(void) { - ESP_LOGI(TAG, "Opening serial GPS"); GPS_Serial.begin(GPS_SERIAL); @@ -144,7 +141,6 @@ int gps_init(void) { disableNmea(); return 1; - } // gps_init() // store current GPS location data in struct @@ -170,13 +166,11 @@ bool gps_hasfix() { // function to poll UTC time from GPS NMEA data; note: this is costly time_t get_gpstime(uint16_t *msec = 0) { - const uint16_t txDelay = 70U * 1000 / (GPS_BAUDRATE / 9); // serial tx of 70 NMEA chars // did we get a current date & time? if (gps.time.age() < 1000) { - // convert tinygps time format to struct tm format struct tm gps_tm = {0}; gps_tm.tm_sec = gps.time.second(); @@ -209,18 +203,15 @@ time_t get_gpstime(uint16_t *msec = 0) { ESP_LOGD(TAG, "no valid GPS time"); return 0; - } // get_gpstime() // GPS serial feed FreeRTos Task void gps_loop(void *pvParameters) { - _ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check // feed GPS decoder with serial NMEA data from GPS device while (1) { while (cfg.payloadmask & GPS_DATA) { - while (GPS_Serial.available()) gps.encode(GPS_Serial.read()); @@ -228,7 +219,6 @@ void gps_loop(void *pvParameters) { } delay(1000); } // infinite while loop - } // gps_loop() #endif // HAS_GPS diff --git a/src/ledmatrixdisplay.cpp b/src/ledmatrixdisplay.cpp index 8940d6ec..c197620c 100644 --- a/src/ledmatrixdisplay.cpp +++ b/src/ledmatrixdisplay.cpp @@ -70,7 +70,6 @@ void refreshTheMatrixDisplay(bool nextPage) { } switch (DisplayPage % MATRIX_DISPLAY_PAGES) { - // page 0: number of current pax OR footfall line diagram // page 1: time of day @@ -89,18 +88,14 @@ void refreshTheMatrixDisplay(bool nextPage) { } else { // cyclic counter mode -> plot a line diagram - if (ulLastNumMacs != count.pax) { - // next count cycle? if (count.pax == 0) { - // matrix full? then scroll left 1 dot, else increment column if (col < (LED_MATRIX_WIDTH - 1)) col++; else ScrollMatrixLeft(displaybuf, LED_MATRIX_WIDTH, LED_MATRIX_HEIGHT); - } else matrix.drawPoint(col, row, 0); // clear current dot @@ -124,7 +119,6 @@ void refreshTheMatrixDisplay(bool nextPage) { // DrawNumber(myTZ.dateTime("H:i:s").c_str()); } break; - } // switch page matrix.scan(); diff --git a/src/ota.cpp b/src/ota.cpp index 6f42c22c..d4da2fd5 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -41,7 +41,6 @@ inline String getHeaderValue(String header, String headerName) { } void start_ota_update() { - const char *host = clientId; switch_LED(LED_ON); @@ -121,13 +120,11 @@ end: ota_display(5, "**", ""); // mark line rebooting delay(5000); do_reset(false); - } // start_ota_update // Reads data vom wifi client and flashes it to ota partition // returns: 0 = finished, 1 = retry, -1 = abort int do_ota_update() { - char buf[17]; bool redirect = true; size_t written = 0; @@ -319,7 +316,6 @@ abort: retry: return 1; - } // do_ota_update void ota_display(const uint8_t row, const std::string status, diff --git a/src/power.cpp b/src/power.cpp index 61e6416c..8045b09d 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -26,7 +26,6 @@ static const adc_unit_t unit = ADC_UNIT_1; AXP20X_Class pmu; void AXP192_powerevent_IRQ(void) { - pmu.readIRQ(); if (pmu.isVbusOverVoltageIRQ()) @@ -83,9 +82,7 @@ void AXP192_powerevent_IRQ(void) { } void AXP192_power(pmu_power_t powerlevel) { - switch (powerlevel) { - case pmu_power_off: pmu.shutdown(); break; @@ -119,7 +116,6 @@ void AXP192_power(pmu_power_t powerlevel) { } void AXP192_showstatus(void) { - if (pmu.isBatteryConnect()) if (pmu.isChargeing()) ESP_LOGI(TAG, "Battery charging, %.2fV @ %.0fmAh", @@ -137,12 +133,10 @@ void AXP192_showstatus(void) { } void AXP192_init(void) { - if (pmu.begin(i2c_readBytes, i2c_writeBytes, AXP192_PRIMARY_ADDRESS) == AXP_FAIL) ESP_LOGI(TAG, "AXP192 PMU initialization failed"); else { - // configure voltages pmu.setDCDC1Voltage(3300); // for external OLED display pmu.setLDO2Voltage(3300); // LORA VDD 3v3 From 0519bdc81daae0ed39edf293275ce34823464742 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:12:09 +0200 Subject: [PATCH 13/45] change TFT display lib --- include/display.h | 18 ++-- platformio_orig.ini | 9 +- src/display.cpp | 176 ++++++++++++++++----------------------- src/hal/m5core.h | 43 +++------- src/hal/m5fire.h | 42 +++------- src/hal/ttgotdisplay.h | 30 ++----- src/hal/ttgotwristband.h | 32 ++----- 7 files changed, 122 insertions(+), 228 deletions(-) diff --git a/include/display.h b/include/display.h index b30ec372..c46fa081 100644 --- a/include/display.h +++ b/include/display.h @@ -9,8 +9,10 @@ #if (HAS_DISPLAY) == 1 #include +extern ONE_BIT_DISPLAY *dp; #elif (HAS_DISPLAY) == 2 #include +extern TFT_eSPI *dp; #endif #define DISPLAY_PAGES (7) // number of paxcounter display pages @@ -22,7 +24,6 @@ #define MY_FONT_NORMAL FONT_8x8 #define MY_FONT_LARGE FONT_16x32 #define MY_FONT_STRETCHED FONT_12x16 - #define MY_DISPLAY_FIRSTLINE 30 #ifndef MY_DISPLAY_RST @@ -49,18 +50,21 @@ // settings for TFT display library #elif (HAS_DISPLAY == 2) -#define MY_FONT_SMALL 1 +#define MY_FONT_SMALL 2 #define MY_FONT_NORMAL 2 -#define MY_FONT_LARGE 4 -#define MY_FONT_STRETCHED 6 - +#define MY_FONT_LARGE 2 +#define MY_FONT_STRETCHED 2 #define MY_DISPLAY_FIRSTLINE 30 +#ifndef TFT_FREQUENCY +#define TFT_FREQUENCY 400000L +#endif + #ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR TFT_WHITE +#define MY_DISPLAY_FGCOLOR 0xFFFF // TFT_WHITE #endif #ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR TFT_BLACK +#define MY_DISPLAY_BGCOLOR 0x0000 // TFT_BLACK #endif #ifndef TOUCH_CS diff --git a/platformio_orig.ini b/platformio_orig.ini index b618a5e7..0ce2ab6b 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -46,7 +46,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 = 3.3.0 +release_version = 3.3.1 ; 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 @@ -54,17 +54,18 @@ extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@5.0.0 +platform_espressif32 = espressif32@5.1.0 monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file lib_deps_lora = mcci-catena/MCCI LoRaWAN LMIC library @ ^4.1.1 lib_deps_display = - https://github.com/bitbank2/OneBitDisplay#8d4ab34 + https://github.com/bitbank2/OneBitDisplay.git ;bitbank2/OneBitDisplay @ ^2.1.0 + https://github.com/bitbank2/bb_spi_lcd.git + ;bitbank2/bb_spi_lcd @ ^2.3.0 ricmoo/QRCode @ ^0.0.1 - bodmer/TFT_eSPI @ ^2.3.84 lib_deps_ledmatrix = seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0 lib_deps_rgbled = diff --git a/src/display.cpp b/src/display.cpp index 6cb029f4..ebebbcb2 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -12,8 +12,8 @@ Display-Mask (128 x 64 pixel): 1|PAX:aabbccdd LARGE 2| 3|WIFI:abcde BLTH:abcde SMALL -4|Batt:abc% chan:ab SMALL -5|RLIM:abcd Mem:abcdKB SMALL +4|Batt:abc% chan:ab SMALL +5|RLIM:abcd Mem:abcdeKB SMALL 6|27.Feb 2019 20:27:00* SMALL 7|yyyyyyyyyyyyy xx SFab SMALL @@ -49,61 +49,55 @@ static QRCode qrcode; #if (HAS_DISPLAY) == 1 static ONE_BIT_DISPLAY oled; #elif (HAS_DISPLAY) == 2 -static TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); +TFT_eSPI *dp = NULL; #else #error Unknown display type specified in hal file #endif #endif void dp_setup(int contrast) { - #if (HAS_DISPLAY) == 1 // I2C OLED - oled.setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST); - oled.setBitBang(false); - oled.I2Cbegin(OLED_TYPE, OLED_ADDR, OLED_FREQUENCY); - oled.allocBuffer(); // render all outputs to lib internal backbuffer - oled.setTextWrap(false); - oled.setRotation( + dp = new ONE_BIT_DISPLAY; + dp->setI2CPins(MY_DISPLAY_SDA, MY_DISPLAY_SCL, MY_DISPLAY_RST); + dp->setBitBang(false); + dp->I2Cbegin(OLED_TYPE, OLED_ADDR, OLED_FREQUENCY); + dp->allocBuffer(); // render all outputs to lib internal backbuffer + dp->setTextWrap(false); + dp->setRotation( MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280° #elif (HAS_DISPLAY) == 2 // SPI TFT - - tft.init(); - tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); - tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); - tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); + 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->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); #endif - // clear display dp_clear(); if (contrast) dp_contrast(contrast); } void dp_init(bool verbose) { - dp_setup(DISPLAYCONTRAST); + // show chip information if (verbose) { - - // show startup screen - // to come -> display .bmp file with logo - -// show chip information #if (VERBOSE) esp_chip_info_t chip_info; esp_chip_info(&chip_info); - dp_setFont(MY_FONT_NORMAL); - dp_printf("** PAXCOUNTER **\r\n"); - dp_printf("Software v%s\r\n", PROGVERSION); - dp_printf("ESP32 %d cores\r\n", chip_info.cores); - dp_printf("Chip Rev.%d\r\n", chip_info.revision); - dp_printf("WiFi%s%s\r\n", (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", - (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."); + dp->printf("** PAXCOUNTER **\r\n"); + dp->printf("Software v%s\r\n", PROGVERSION); + dp->printf("ESP32 %d cores\r\n", chip_info.cores); + dp->printf("Chip Rev.%d\r\n", chip_info.revision); + dp->printf("WiFi%s%s\r\n", + (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", + (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(); @@ -143,11 +137,15 @@ void dp_init(bool verbose) { } // verbose dp_power(cfg.screenon); // set display off if disabled - } // dp_init void dp_refresh(bool nextPage) { + struct count_payload_t count; // libpax count storage + static uint8_t DisplayPage = 0; + char timeState, strftime_buf[64]; + time_t now; + struct tm timeinfo = {0}; #ifndef HAS_BUTTON static uint32_t framecounter = 0; #endif @@ -216,6 +214,11 @@ void dp_drawPage(bool nextpage) { // ---------- page 0: parameters overview ---------- case 0: + // show pax + libpax_counter_count(&count); + dp_setFont(MY_FONT_LARGE); + dp->printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); dp_setTextCursor(); @@ -224,22 +227,22 @@ void dp_drawPage(bool nextpage) { #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", count.wifi_count); + dp->printf("WIFI:%-5d", count.wifi_count); else dp_printf("WIFI:off"); if (cfg.blescan) - dp_printf("BLTH:%-5d", count.ble_count); + dp->printf("BLTH:%-5d", count.ble_count); else dp_printf(" BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", count.wifi_count); + dp->printf("WIFI:%-5d", count.wifi_count); else dp_printf("WIFI:off"); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) - dp_printf("BLTH:%-5d", count.ble_count); - dp_printf("BLTH:off"); + dp->printf("BLTH:%-5d", count.ble_count); + dp->printf("BLTH:off"); #else dp_printf("Sniffer disabled"); #endif @@ -259,8 +262,8 @@ void dp_drawPage(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(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); + dp->printf(" Mem:%4dKB\r\n", getFreeRAM() / 1024); // line 6: time + date // Wed Jan 12 21:49:08 * @@ -308,14 +311,20 @@ void dp_drawPage(bool nextpage) { // 6|fUp:000000 fDn:000000 // 7|SNR:-0000 RSSI:-0000 + // show pax + libpax_counter_count(&count); + dp_setFont(MY_FONT_LARGE); + dp->printf("%-8d", count.pax); + dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(); - dp_printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); - dp_printf("Dev:%08X DR:%1d\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, - LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); - dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); + dp->setCursor(0, MY_DISPLAY_FIRSTLINE); + dp->printf("Net:%06X Pwr:%-2d\r\n", LMIC.netid & 0x001FFFFF, + LMIC.radio_txpow); + dp->printf("Dev:%08X DR:%1d\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, + LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); + dp->printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); dp_dump(); break; @@ -328,6 +337,11 @@ void dp_drawPage(bool nextpage) { #if (HAS_GPS) + // show pax + libpax_counter_count(&count); + dp_setFont(MY_FONT_LARGE); + dp->printf("%-8d", count.pax); + // show satellite status at bottom line dp_setFont(MY_FONT_SMALL); dp_setTextCursor(0, 56); @@ -379,7 +393,7 @@ void dp_drawPage(bool nextpage) { dp_setFont(MY_FONT_LARGE); dp_printf("%.8s\r\n", strftime_buf); dp_setFont(MY_FONT_SMALL); - dp_printf("%21.1f", uptime() / 1000.0); + dp->printf("%21.1f", uptime() / 1000.0); dp_dump(); break; @@ -416,91 +430,51 @@ void dp_setTextCursor(int x, int y) { void dp_setFont(int font, int inv) { -#if (HAS_DISPLAY) == 1 // handle invers printing if (inv) oled.setTextColor(MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR); else - oled.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); + dp->setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); +#if (HAS_DISPLAY) == 1 // set desired font - oled.setFont(font); - + dp->setFont(font); #elif (HAS_DISPLAY) == 2 - // 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 - tft.setTextFont(4); // 26px + dp->setTextFont(4); // 26px break; case MY_FONT_SMALL: // 6x8 on OLED case MY_FONT_NORMAL: // 8x8 on OLED default: - tft.setTextFont(2); // 16px + dp->setTextFont(2); // 16px break; } - -#endif -} -void dp_printf(const char *format, ...) { - char loc_buf[64]; - char *temp = loc_buf; - va_list arg; - va_list copy; - va_start(arg, format); - va_copy(copy, arg); - int len = vsnprintf(temp, sizeof(loc_buf), format, copy); - va_end(copy); - if (len < 0) { - va_end(arg); - return; - }; - if (len >= sizeof(loc_buf)) { - temp = (char *)malloc(len + 1); - if (temp == NULL) { - va_end(arg); - return; - } - vsnprintf(temp, len + 1, format, arg); - } - va_end(arg); -#if (HAS_DISPLAY) == 1 - oled.write(temp); -#elif (HAS_DISPLAY) == 2 - tft.printf(temp); #endif - if (temp != loc_buf) { - free(temp); - } } void dp_dump(uint8_t *pBuffer) { -#if (HAS_DISPLAY) == 1 if (pBuffer) - memcpy(oled.getBuffer(), pBuffer, PLOTBUFFERSIZE); - oled.display(); + memcpy(dp->getBuffer(), pBuffer, PLOTBUFFERSIZE); + dp->display(); #elif (HAS_DISPLAY) == 2 if (pBuffer) - tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, + dp->drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, MY_DISPLAY_FGCOLOR); #endif } void dp_clear(void) { #if (HAS_DISPLAY) == 1 - oled.fillScreen(MY_DISPLAY_BGCOLOR); - oled.display(); + dp->fillScreen(MY_DISPLAY_BGCOLOR); + dp->display(); #elif (HAS_DISPLAY) == 2 - tft.fillScreen(MY_DISPLAY_BGCOLOR); + dp->fillScreen(MY_DISPLAY_BGCOLOR); #endif - dp_setTextCursor(0, 0); + dp->setCursor(0, 0); } void dp_contrast(uint8_t contrast) { @@ -574,7 +548,6 @@ void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, int dp_drawPixel(uint8_t *buf, const uint16_t x, const uint16_t y, const uint8_t dot) { - if (x > MY_DISPLAY_WIDTH || y > MY_DISPLAY_HEIGHT) return -1; @@ -592,7 +565,6 @@ int dp_drawPixel(uint8_t *buf, const uint16_t x, const uint16_t y, void dp_scrollHorizontal(uint8_t *buf, const uint16_t width, const uint16_t height, bool left) { - uint16_t col, page, idx = 0; for (page = 0; page < height / 8; page++) { @@ -615,7 +587,6 @@ void dp_scrollHorizontal(uint8_t *buf, const uint16_t width, void dp_scrollVertical(uint8_t *buf, const uint16_t width, const uint16_t height, int offset) { - uint64_t buf_col; if (!offset) @@ -638,7 +609,6 @@ void dp_scrollVertical(uint8_t *buf, const uint16_t width, // ------------- curve plotter ----------------- void dp_plotCurve(uint16_t count, bool reset) { - static uint16_t last_count = 0, col = 0, row = 0; uint16_t v_scroll = 0; diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 7a65e40a..1f3cd537 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -28,9 +28,6 @@ #define CFG_sx1276_radio 1 // select LoRa chip #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature -#define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet -//#define MY_DISPLAY_FLIP 1 // use if display is rotated - #define HAS_LED NOT_A_PIN // no on board LED (?) #define HAS_BUTTON (39) // on board button A @@ -44,38 +41,22 @@ // GPS settings #define HAS_GPS 1 // use on board GPS #define GPS_SERIAL 9600, SERIAL_8N1, RXD2, TXD2 // UBlox NEO 6M RX, TX -#define GPS_INT GPIO_NUM_35 // 30ns accurary timepulse, to be external wired on pcb: shorten R12! +#define GPS_INT // Display Settings +#define HAS_DISPLAY 2 // TFT-LCD +//#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 #define MY_DISPLAY_INVERT 1 - -// setting for M5 display -#define USER_SETUP_LOADED 1 -#define ILI9341_DRIVER 1 -#define M5STACK // needed for TFT driver - -#define TFT_MISO MISO // SPI -#define TFT_MOSI MOSI // SPI -#define TFT_SCLK SCK // SPI -#define TFT_CS GPIO_NUM_14 // Chip select control -#define TFT_DC GPIO_NUM_27 // Data Command control -#define TFT_RST GPIO_NUM_33 // Reset -#define TFT_BL GPIO_NUM_32 // LED back-light - -#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red - -//#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 -#define SMOOTH_FONT - -#define SPI_FREQUENCY 40000000 +#define TFT_TYPE LCD_ILI9341 +#define TFT_MOSI MOSI // SPI +#define TFT_MISO MISO // SPI +#define TFT_SCLK SCK // SPI +#define TFT_CS GPIO_NUM_14 // Chip select control +#define TFT_DC GPIO_NUM_27 // Data Command control +#define TFT_RST GPIO_NUM_33 // Reset +#define TFT_BL GPIO_NUM_32 // LED back-light +#define TFT_FREQUENCY 40000000 #endif diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index b83de54a..e93d0f5f 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -20,7 +20,6 @@ #define LORA_IO1 GPIO_NUM_34 // must be wired by you on PCB! #define LORA_IO2 LMIC_UNUSED_PIN - // enable only if you want to store a local paxcount table on the device #define HAS_SDCARD 1 // this board has an SD-card-reader/writer #define SDCARD_CS GPIO_NUM_4 @@ -31,9 +30,6 @@ #define CFG_sx1276_radio 1 // select LoRa chip #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature -#define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet -//#define MY_DISPLAY_FLIP 1 // use if display is rotated - #define HAS_LED NOT_A_PIN // no on board LED (?) #define RGB_LED_COUNT 10 @@ -53,35 +49,19 @@ // #define GPS_INT GPIO_NUM_35 // 30ns accurary timepulse, to be external wired on pcb: shorten R12! // Display Settings +#define HAS_DISPLAY 2 // TFT-LCD +//#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 #define MY_DISPLAY_INVERT 1 - -// setting for M5 display -#define USER_SETUP_LOADED 1 -#define ILI9341_DRIVER 1 -#define M5STACK // needed for TFT driver - -#define TFT_MISO MISO // SPI -#define TFT_MOSI MOSI // SPI -#define TFT_SCLK SCK // SPI -#define TFT_CS GPIO_NUM_14 // Chip select control -#define TFT_DC GPIO_NUM_27 // Data Command control -#define TFT_RST GPIO_NUM_33 // Reset -#define TFT_BL GPIO_NUM_32 // LED back-light - -#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red - -//#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 -#define SMOOTH_FONT - -#define SPI_FREQUENCY 40000000 +#define TFT_TYPE LCD_ILI9341 +#define TFT_MOSI MOSI // SPI +#define TFT_MISO MISO // SPI +#define TFT_SCLK SCK // SPI +#define TFT_CS GPIO_NUM_14 // Chip select control +#define TFT_DC GPIO_NUM_27 // Data Command control +#define TFT_RST GPIO_NUM_33 // Reset +#define TFT_BL GPIO_NUM_32 // LED back-light +#define TFT_FREQUENCY 40000000 #endif \ No newline at end of file diff --git a/src/hal/ttgotdisplay.h b/src/hal/ttgotdisplay.h index 0011d825..b1f625eb 100644 --- a/src/hal/ttgotdisplay.h +++ b/src/hal/ttgotdisplay.h @@ -9,9 +9,6 @@ #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature -#define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet -#define MY_DISPLAY_FLIP 1 // use if display is rotated - #define HAS_LED NOT_A_PIN // no on board LED (?) #define HAS_BUTTON (35) // on board button A @@ -20,36 +17,19 @@ #define BAT_VOLTAGE_DIVIDER 2.605f // voltage divider // Display Settings +#define HAS_DISPLAY 2 // TFT-LCD +#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 135 #define MY_DISPLAY_HEIGHT 240 #define MY_DISPLAY_INVERT 1 - -// setting for TTGO T-display -#define USER_SETUP_LOADED 1 -#define ST7789_DRIVER 1 - -#define CGRAM_OFFSET - +#define TFT_TYPE LCD_ST7789_135 // size 135x240 px #define TFT_MOSI GPIO_NUM_19 // SPI +#define TFT_MISO NOT_A_PIN // SPI #define TFT_SCLK GPIO_NUM_18 // SPI #define TFT_CS GPIO_NUM_5 // Chip select control #define TFT_DC GPIO_NUM_16 // Data Command control #define TFT_RST GPIO_NUM_23 // Reset #define TFT_BL GPIO_NUM_4 // LED back-light - -#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red - -#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 -#define SMOOTH_FONT - -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 6000000 +#define TFT_FREQUENCY 40000000 #endif diff --git a/src/hal/ttgotwristband.h b/src/hal/ttgotwristband.h index a7f48af8..2439de6e 100644 --- a/src/hal/ttgotwristband.h +++ b/src/hal/ttgotwristband.h @@ -9,9 +9,6 @@ #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature -#define HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet -#define MY_DISPLAY_FLIP 1 // use if display is rotated - #define HAS_LED NOT_A_PIN // no on board LED (?) #define HAS_BUTTON (33) // on board button A @@ -20,39 +17,20 @@ #define BAT_VOLTAGE_DIVIDER 2.605f // voltage divider // Display Settings +#define HAS_DISPLAY 2 // TFT-LCD +#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 80 #define MY_DISPLAY_HEIGHT 160 #define MY_DISPLAY_INVERT 1 - -// setting for TTGO T-display -#define USER_SETUP_LOADED 1 -#define ST7735_DRIVER 1 - -#define CGRAM_OFFSET - -#define TFT_MISO -1 +#define TFT_TYPE LCD_ST7735S #define TFT_MOSI GPIO_NUM_19 // SPI +#define TFT_MISO NOT_A_PIN // SPI #define TFT_SCLK GPIO_NUM_18 // SPI #define TFT_CS GPIO_NUM_5 // Chip select control #define TFT_DC GPIO_NUM_23 // Data Command control #define TFT_RST GPIO_NUM_26 // Reset #define TFT_BL GPIO_NUM_27 // LED back-light -#define TFT_BACKLIGHT_ON 1 -#define ST7735_GREENTAB160x80 - -#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red - -#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_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts -#define SMOOTH_FONT - -#define SPI_FREQUENCY 27000000 -#define SPI_READ_FREQUENCY 6000000 +#define TFT_FREQUENCY 27000000 #endif From 4f46fb21fd6677ecdde177e46871bf82cca89628 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:16:29 +0200 Subject: [PATCH 14/45] new tft display lib --- include/display.h | 12 +++----- src/display.cpp | 78 ++++++++++++++++------------------------------- 2 files changed, 30 insertions(+), 60 deletions(-) diff --git a/include/display.h b/include/display.h index db4551f6..86f7ccff 100644 --- a/include/display.h +++ b/include/display.h @@ -11,8 +11,8 @@ #include extern ONE_BIT_DISPLAY *dp; #elif (HAS_DISPLAY) == 2 -#include -extern TFT_eSPI *dp; +#include +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 diff --git a/src/display.cpp b/src/display.cpp index 6bb06a4b..4b98b76a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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); @@ -67,11 +68,16 @@ void dp_setup(int contrast) { dp->setRotation( 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); +#elif (HAS_DISPLAY) == 2 // SPI TFT + + 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"); @@ -238,9 +241,9 @@ void dp_refresh(bool nextPage) { dp->printf("chan:%02u\r\n", channel); // 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(" 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); } From 27fd2967532eebfdbd8323a9ef2bee19fc24ef93 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:27:48 +0200 Subject: [PATCH 15/45] code sanitizations --- src/display.cpp | 3 --- src/main.cpp | 2 -- src/payload.cpp | 1 - src/reset.cpp | 7 +++---- src/sdcard.cpp | 7 +------ src/senddata.cpp | 2 -- 6 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 4b98b76a..2343430e 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -138,7 +138,6 @@ void dp_init(bool verbose) { #endif #endif // HAS_LORA - } // verbose dp_power(cfg.screenon); // set display off if disabled @@ -182,7 +181,6 @@ void dp_refresh(bool nextPage) { dp->setCursor(0, 0); switch (DisplayPage) { - // page 0: pax + parameters overview // page 1: pax + lorawan parameters // page 2: pax + GPS lat/lon @@ -398,7 +396,6 @@ void dp_refresh(bool nextPage) { DisplayPage++; break; #endif - } // switch (page) } // dp_refresh diff --git a/src/main.cpp b/src/main.cpp index 9577c062..1ddb86f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,6 @@ static const char TAG[] = __FILE__; char clientId[20] = {0}; // unique ClientID void setup() { - char features[100] = ""; // disable brownout detection @@ -487,7 +486,6 @@ void setup() { RTC_runmode = RUNMODE_NORMAL; vTaskDelete(NULL); - } // setup() void loop() { vTaskDelete(NULL); } diff --git a/src/payload.cpp b/src/payload.cpp index 3e2854e3..bd9977c0 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -58,7 +58,6 @@ void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem, uint8_t reset0, uint32_t restarts) { - buffer[cursor++] = highByte(voltage); buffer[cursor++] = lowByte(voltage); buffer[cursor++] = (byte)((uptime & 0xFF00000000000000) >> 56); diff --git a/src/reset.cpp b/src/reset.cpp index f62cb54b..b6d39984 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -39,7 +39,6 @@ void do_reset(bool warmstart) { } void do_after_reset(void) { - struct timeval sleep_stop_time; uint64_t sleep_time_ms; @@ -54,7 +53,6 @@ void do_after_reset(void) { #endif switch (rtc_get_reset_reason(0)) { - case POWERON_RESET: // 0x01 Vbat power on reset case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not // stable @@ -102,7 +100,6 @@ void do_after_reset(void) { } void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { - ESP_LOGI(TAG, "Preparing to sleep..."); RTC_runmode = RUNMODE_SLEEP; @@ -205,4 +202,6 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { esp_deep_sleep_start(); } -unsigned long long uptime() { return (RTC_millis + esp_timer_get_time() / 1000); } \ No newline at end of file +unsigned long long uptime() { + return (RTC_millis + esp_timer_get_time() / 1000); +} \ No newline at end of file diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 4794ce00..d4c23e46 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -67,7 +67,6 @@ int print_to_sd_card(const char *fmt, va_list args) { #endif bool openFile(FILE **fd, const char *filename) { - char _filename[50]; sprintf(_filename, "%s%s", MOUNT_POINT, filename); @@ -81,7 +80,6 @@ bool openFile(FILE **fd, const char *filename) { } // openfile bool sdcard_init(bool create) { - esp_err_t ret; // for usage of SD drivers on ESP32 platform see @@ -171,7 +169,6 @@ bool sdcard_init(bool create) { snprintf(bufferFilename, sizeof(bufferFilename), "/%s.csv", SDCARD_FILE_NAME); if (openFile(&data_file, bufferFilename)) { - fpos_t position; fgetpos(data_file, &position); @@ -207,7 +204,6 @@ bool sdcard_init(bool create) { #endif return useSDCard; - } // sdcard_init void sdcard_flush(void) { @@ -236,7 +232,6 @@ void sdcard_close(void) { void sdcardWriteData(uint16_t noWifi, uint16_t noBle, __attribute__((unused)) uint16_t voltage) { - if (!useSDCard) return; @@ -264,4 +259,4 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle, fprintf(data_file, "\n"); } -#endif // (HAS_SDCARD) +#endif // (HAS_SDCARD) \ No newline at end of file diff --git a/src/senddata.cpp b/src/senddata.cpp index d55ee92c..518fd30f 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -25,7 +25,6 @@ void initSendDataTimer(uint8_t sendcycle) { // put data to send in RTos Queues used for transmit over channels Lora and SPI void SendPayload(uint8_t port) { - ESP_LOGD(TAG, "sending Payload for Port %d", port); MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[] @@ -69,7 +68,6 @@ void SendPayload(uint8_t port) { #ifdef HAS_MQTT mqtt_enqueuedata(&SendBuffer); #endif - } // SendPayload // timer triggered function to prepare payload to send From f05acd32a85aae337466887f3b3746f90b9c3b8f Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:43:04 +0200 Subject: [PATCH 16/45] code sanitizations --- include/payload.h | 2 +- lib/BintrayClient/src/BintrayClient.h | 1 - src/bmesensor.cpp | 4 ---- src/boot.cpp | 4 ---- src/configmanager.cpp | 3 --- src/cyclic.cpp | 2 -- src/dcf77.cpp | 10 ---------- src/i2c.cpp | 5 +---- src/if482.cpp | 1 - src/irqhandler.cpp | 1 - src/led.cpp | 1 - src/loraconf_abp.cpp | 1 - src/mqttclient.cpp | 8 +------- src/rtctime.cpp | 3 --- src/senddata.cpp | 3 --- src/sensor.cpp | 9 +-------- src/timesync.cpp | 5 ----- 17 files changed, 4 insertions(+), 59 deletions(-) diff --git a/include/payload.h b/include/payload.h index e8376bf6..43bbb1d8 100644 --- a/include/payload.h +++ b/include/payload.h @@ -39,7 +39,6 @@ #endif class PayloadConvert { - public: PayloadConvert(uint8_t size); ~PayloadConvert(); @@ -59,6 +58,7 @@ public: void addSensor(uint8_t[]); void addTime(time_t value); void addSDS(sdsStatus_t value); + private: void addChars( char* string, int len); diff --git a/lib/BintrayClient/src/BintrayClient.h b/lib/BintrayClient/src/BintrayClient.h index d0b7e67d..ec478893 100644 --- a/lib/BintrayClient/src/BintrayClient.h +++ b/lib/BintrayClient/src/BintrayClient.h @@ -23,7 +23,6 @@ #include class BintrayClient { - public: BintrayClient(const String& user, const String& repository, const String& package); String getUser() const; diff --git a/src/bmesensor.cpp b/src/bmesensor.cpp index edda04f8..f790051b 100644 --- a/src/bmesensor.cpp +++ b/src/bmesensor.cpp @@ -48,7 +48,6 @@ void setBMEIRQ() { xTaskNotify(irqHandlerTask, BME_IRQ, eSetBits); } // initialize MEMS sensor // return = 0 -> error / return = 1 -> success int bme_init(void) { - int rc = 0; #ifdef HAS_BME680 @@ -77,7 +76,6 @@ int bme_init(void) { if (rc) bmecycler.attach(BMECYCLE, setBMEIRQ); // start cyclic data transmit return rc; - } // bme_init() #ifdef HAS_BME680 @@ -108,7 +106,6 @@ int checkIaqSensorStatus(void) { // store current BME sensor data in struct void bme_storedata(bmeStatus_t *bme_store) { - if (cfg.payloadmask & MEMS_DATA) #ifdef HAS_BME680 @@ -138,7 +135,6 @@ void bme_storedata(bmeStatus_t *bme_store) { // bme.readAltitude(SEALEVELPRESSURE_HPA); bme_store->iaq = 0; // IAQ feature not present with BME280 #endif - } // bme_storedata() #ifdef HAS_BME680 diff --git a/src/boot.cpp b/src/boot.cpp index 28202243..6d271132 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -75,7 +75,6 @@ void IRAM_ATTR watchdog() { xTaskResumeFromISR(RestartHandle); } // used for manually uploading a firmware file via wifi void start_boot_menu(void) { - const char *host = clientId; const char *ssid = WIFI_SSID; const char *password = WIFI_PASS; @@ -150,9 +149,7 @@ void start_boot_menu(void) { // did we get a file name? if (upload.filename != NULL) { - switch (upload.status) { - case UPLOAD_FILE_START: // start file transfer ESP_LOGI(TAG, "Uploading %s", upload.filename.c_str()); @@ -177,7 +174,6 @@ void start_boot_menu(void) { case UPLOAD_FILE_ABORTED: default: break; - } // switch // don't boot to production if update failed diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 6112444d..77557281 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -26,7 +26,6 @@ static uint8_t buffer[cfgLen + cfgLen2]; // 3. magicByte [cfgLen2 bytes, containing a fixed identifier] static void defaultConfig(configData_t *myconfig) { - strncpy(myconfig->version, PROGVERSION, sizeof(myconfig->version) - 1); // Firmware version @@ -92,7 +91,6 @@ void saveConfig(bool erase) { // load configuration from NVRAM into RAM and make it current void loadConfig(void) { - int readBytes = 0; ESP_LOGI(TAG, "Loading device configuration from NVRAM..."); @@ -144,7 +142,6 @@ bool comp(char s1, char s2) { return (tolower(s1) < tolower(s2)); } // helper function to lexicographically compare two versions. Returns 1 if v2 // is smaller, -1 if v1 is smaller, 0 if equal int version_compare(const String v1, const String v2) { - if (v1 == v2) return 0; diff --git a/src/cyclic.cpp b/src/cyclic.cpp index f5d905c0..ef2f2d5c 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -13,7 +13,6 @@ void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); } // do all housekeeping void doHousekeeping() { - // check if update or maintenance mode trigger switch was set by rcommand if ((RTC_runmode == RUNMODE_UPDATE) || (RTC_runmode == RUNMODE_MAINTENANCE)) do_reset(true); // warmstart @@ -125,7 +124,6 @@ void doHousekeeping() { #if (HAS_SDCARD) sdcard_flush(); #endif - } // doHousekeeping() uint32_t getFreeRAM() { diff --git a/src/dcf77.cpp b/src/dcf77.cpp index 8b30dcf4..794ff5a6 100644 --- a/src/dcf77.cpp +++ b/src/dcf77.cpp @@ -18,41 +18,33 @@ static const char TAG[] = __FILE__; // triggered by second timepulse to ticker out DCF signal void DCF77_Pulse(uint8_t bit) { - TickType_t startTime; // induce a DCF Pulse for (uint8_t pulseLength = 0; pulseLength <= 2; pulseLength++) { - startTime = xTaskGetTickCount(); // reference time pulse start switch (pulseLength) { - case 0: // 0ms = start of pulse digitalWrite(HAS_DCF77, dcf_low); break; - case 1: // 100ms = logic 0 if (bit == 0) digitalWrite(HAS_DCF77, dcf_high); break; - case 2: // 200ms = logic 1 digitalWrite(HAS_DCF77, dcf_high); break; - } // switch // delay to genrate pulseLength vTaskDelayUntil(&startTime, pdMS_TO_TICKS(100)); - } // for } // DCF77_Pulse() // helper function to convert decimal to bcd digit uint64_t dec2bcd(uint8_t const dec, uint8_t const startpos, uint8_t const endpos, uint8_t *parity) { - uint8_t data = dec < 10 ? dec : ((dec / 10) << 4) + dec % 10; uint64_t bcd = 0; @@ -68,7 +60,6 @@ uint64_t dec2bcd(uint8_t const dec, uint8_t const startpos, // generates a 1 minute dcf pulse frame for calendar time t uint64_t DCF77_Frame(const struct tm t) { - uint8_t parity = 0, parity_sum = 0; uint64_t frame = 0; // start with all bits 0 @@ -105,7 +96,6 @@ uint64_t DCF77_Frame(const struct tm t) { frame += parity_sum ? set_dcfbit(58) : 0; return frame; - } // DCF77_Frame() #endif // HAS_DCF77 \ No newline at end of file diff --git a/src/i2c.cpp b/src/i2c.cpp index 1d7a3dd7..02c307f0 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -15,7 +15,6 @@ void i2c_init(void) { void i2c_deinit(void) { Wire.end(); } void i2c_scan(void) { - // parts of the code in this function were taken from: // // Copyright (c) 2019 BitBank Software, Inc. @@ -78,7 +77,6 @@ void i2c_scan(void) { // functions for i2c r/w access, mutexing is done by Wire.cpp int i2c_readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { - uint8_t ret = 0; Wire.beginTransmission(addr); Wire.write(reg); @@ -100,7 +98,6 @@ finish: } int i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { - uint8_t ret = 0; Wire.beginTransmission(addr); Wire.write(reg); @@ -110,4 +107,4 @@ int i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { ret = Wire.endTransmission(); return ret ? ret : 0xFF; -} +} \ No newline at end of file diff --git a/src/if482.cpp b/src/if482.cpp index 81add69a..14592470 100644 --- a/src/if482.cpp +++ b/src/if482.cpp @@ -85,7 +85,6 @@ not evaluated by model BU-190, use "F" instead for this model static const char TAG[] = __FILE__; String IF482_Frame(time_t t) { - char mon, out[IF482_FRAME_SIZE + 1], buf[IF482_FRAME_SIZE - 3]; if (sntp_get_sync_status() == SNTP_SYNC_STATUS_IN_PROGRESS) diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index b971aeac..81b24304 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -7,7 +7,6 @@ TaskHandle_t irqHandlerTask = NULL; // irq handler task, handles all our application level interrupts void irqHandler(void *pvParameters) { - _ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check uint32_t irqSource; diff --git a/src/led.cpp b/src/led.cpp index 8095a3a9..ecd5b99a 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -158,7 +158,6 @@ void ledLoop(void *parameter) { } // No custom blink, check LoRaWAN state } else { - #if (HAS_LORA) // LED indicators for viusalizing LoRaWAN state if (LMIC.opmode & (OP_JOINING | OP_REJOIN)) { diff --git a/src/loraconf_abp.cpp b/src/loraconf_abp.cpp index 675b90fa..84a7ed44 100644 --- a/src/loraconf_abp.cpp +++ b/src/loraconf_abp.cpp @@ -14,7 +14,6 @@ *********************************************************************/ void setABPParameters() { - /** ************************************************************** * ************************************************************* */ #if defined(CFG_eu868) diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index c8d85ceb..f490fd85 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -19,7 +19,6 @@ void mqtt_deinit(void) { } esp_err_t mqtt_init(void) { - // setup network connection and MQTT client ETH.begin(); ETH.setHostname(clientId); @@ -43,7 +42,6 @@ esp_err_t mqtt_init(void) { } int mqtt_connect(const char *my_host, const uint16_t my_port) { - IPAddress mqtt_server_ip; ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME); @@ -75,13 +73,10 @@ int mqtt_connect(const char *my_host, const uint16_t my_port) { } void mqtt_client_task(void *param) { - MessageBuffer_t msg; while (1) { - if (mqttClient.connected()) { - // check for incoming messages mqttClient.loop(); @@ -124,11 +119,10 @@ void mqtt_client_task(void *param) { // process incoming MQTT messages void mqtt_callback(MQTTClient *client, char *topic, char *payload, int length) { if (strcmp(topic, MQTT_INTOPIC) == 0) { - // get length of base64 encoded message size_t out_len = 0; mbedtls_base64_decode(NULL, 0, &out_len, (unsigned char *)payload, length); - + // decode the base64 message unsigned char decoded[out_len]; mbedtls_base64_decode(decoded, out_len, &out_len, (unsigned char *)payload, diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 0de8e176..23b3ad20 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -9,7 +9,6 @@ RtcDS3231 Rtc(Wire); // RTC hardware i2c interface // initialize RTC uint8_t rtc_init(void) { - Wire.begin(HAS_RTC); Rtc.Begin(MY_DISPLAY_SDA, MY_DISPLAY_SCL); @@ -43,7 +42,6 @@ uint8_t rtc_init(void) { } // rtc_init() uint8_t set_rtctime(time_t t) { // t is sec epoch time - #ifdef RTC_INT // sync rtc 1Hz pulse on top of second Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); // off Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); // start @@ -55,7 +53,6 @@ uint8_t set_rtctime(time_t t) { // t is sec epoch time } // set_rtctime() time_t get_rtctime(uint16_t *msec) { - time_t t = 0; *msec = 0; if (Rtc.IsDateTimeValid() && Rtc.GetIsRunning()) { diff --git a/src/senddata.cpp b/src/senddata.cpp index 518fd30f..1d4bd81b 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -72,7 +72,6 @@ void SendPayload(uint8_t port) { // timer triggered function to prepare payload to send void sendData() { - uint8_t bitmask = cfg.payloadmask; uint8_t mask = 1; @@ -91,7 +90,6 @@ void sendData() { while (bitmask) { switch (bitmask & mask) { - #if ((WIFICOUNTER) || (BLECOUNTER)) case COUNT_DATA: payload.reset(); @@ -197,7 +195,6 @@ void sendData() { SendPayload(BATTPORT); break; #endif - } // switch bitmask &= ~mask; mask <<= 1; diff --git a/src/sensor.cpp b/src/sensor.cpp index 2d077175..7189b6fa 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -9,7 +9,6 @@ static const char TAG[] = __FILE__; 10 // max. size of user sensor data buffer in bytes [default=20] void sensor_init(void) { - // this function is called during device startup // put your user sensor initialization routines here } @@ -38,14 +37,11 @@ uint8_t sensor_mask(uint8_t sensor_no) { } uint8_t *sensor_read(uint8_t sensor) { - static uint8_t buf[SENSORBUFFER] = {0}; uint8_t length = 3; switch (sensor) { - case 1: - // insert user specific sensor data frames here buf[0] = length; buf[1] = 0x01; @@ -53,15 +49,12 @@ uint8_t *sensor_read(uint8_t sensor) { buf[3] = 0x03; break; case 2: - buf[0] = length; buf[1] = 0x01; buf[2] = 0x02; buf[3] = 0x03; break; - case 3: - buf[0] = length; buf[1] = 0x01; buf[2] = 0x02; @@ -70,4 +63,4 @@ uint8_t *sensor_read(uint8_t sensor) { } return buf; -} +} \ No newline at end of file diff --git a/src/timesync.cpp b/src/timesync.cpp index 8660c597..917afef4 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -56,7 +56,6 @@ void timesync_request(void) { // task for processing time sync request void timesync_processReq(void *taskparameter) { - uint32_t rcv_seqNo = TIME_SYNC_END_FLAG; uint32_t time_offset_sec = 0, time_offset_ms = 0; @@ -68,7 +67,6 @@ void timesync_processReq(void *taskparameter) { // --- asnychronous part: generate and collect timestamps from gateway --- while (1) { - // wait for kickoff ulTaskNotifyTake(pdFALSE, portMAX_DELAY); @@ -85,7 +83,6 @@ void timesync_processReq(void *taskparameter) { // collect timestamp samples in timestamp array for (int8_t i = 0; i < TIME_SYNC_SAMPLES; i++) { - // send timesync request #if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3) payload.reset(); @@ -122,7 +119,6 @@ void timesync_processReq(void *taskparameter) { // if we are not in last cycle, pause until next cycle if (i < TIME_SYNC_SAMPLES - 1) vTaskDelay(pdMS_TO_TICKS(TIME_SYNC_CYCLE * 1000)); - } // for i // --- time critial part: evaluate timestamps and calculate time --- @@ -174,7 +170,6 @@ void timesync_store(uint32_t timestamp, timesync_t timestamp_type) { // callback function to receive time answer from network or answer void timesync_serverAnswer(void *pUserData, int flag) { - #if (HAS_LORA_TIME) // if no timesync handshake is pending then exit From 85425e22de314e98902415aab34553a48eb44b7d Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:45:05 +0200 Subject: [PATCH 17/45] code sanitizations --- src/bmesensor.cpp | 1 - src/rtctime.cpp | 3 --- src/timesync.cpp | 1 - 3 files changed, 5 deletions(-) diff --git a/src/bmesensor.cpp b/src/bmesensor.cpp index f790051b..5e5a8bf9 100644 --- a/src/bmesensor.cpp +++ b/src/bmesensor.cpp @@ -161,7 +161,6 @@ void updateState(void) { stateUpdateCounter++; } } else { - /* Update every STATE_SAVE_PERIOD minutes */ if ((long)(millis() - stateUpdateCounter * STATE_SAVE_PERIOD) >= 0) { update = true; diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 23b3ad20..3d494267 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -38,7 +38,6 @@ uint8_t rtc_init(void) { // failure // return 0 - } // rtc_init() uint8_t set_rtctime(time_t t) { // t is sec epoch time @@ -49,7 +48,6 @@ uint8_t set_rtctime(time_t t) { // t is sec epoch time Rtc.SetDateTime(RtcDateTime(t - SECS_YR_2000)); // epoch -> sec2000 ESP_LOGI(TAG, "RTC time synced"); return 1; // success - } // set_rtctime() time_t get_rtctime(uint16_t *msec) { @@ -72,7 +70,6 @@ time_t get_rtctime(uint16_t *msec) { #endif return t; - } // get_rtctime() float get_rtctemp(void) { diff --git a/src/timesync.cpp b/src/timesync.cpp index 917afef4..c382676a 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -157,7 +157,6 @@ void timesync_processReq(void *taskparameter) { // end of time critical section: release app irq lock timeSyncPending = false; unmask_user_IRQ(); - } // infinite while(1) } From eacf4a0d5609d7a203e7ff79793e7b19bbf8dfdb Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 16 Aug 2022 13:49:00 +0200 Subject: [PATCH 18/45] cwe-120 bugfix in timekeeper.cpp --- src/timekeeper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index e551b8ec..f366543a 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -332,7 +332,7 @@ time_t compileTime(void) { if (secs == -1) { // determine date - sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__DATE__, "%4s %d %d", s_month, &t.tm_mday, &year); t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; t.tm_year = year - 1900; // determine time From c7026ee7a4a75786b3f877ea238d0a0a36a1cebc Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 17 Aug 2022 19:05:41 +0200 Subject: [PATCH 19/45] AXP PMU library changed --- include/power.h | 8 +-- src/hal/ttgobeam10.h | 13 ++-- src/power.cpp | 150 ++++++++++++++++++------------------------- 3 files changed, 72 insertions(+), 99 deletions(-) diff --git a/include/power.h b/include/power.h index 24f6fb67..c853447b 100644 --- a/include/power.h +++ b/include/power.h @@ -20,7 +20,7 @@ #ifndef PMU_CHG_CUTOFF #ifdef HAS_PMU -#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V +#define PMU_CHG_CUTOFF XPOWERS_CHG_VOL_4V2 #elif defined HAS_IP5306 #define PMU_CHG_CUTOFF 0 #endif @@ -28,7 +28,7 @@ #ifndef PMU_CHG_CURRENT #ifdef HAS_PMU -#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_450MA +#define PMU_CHG_CURRENT XPOWERS_CHG_CUR_450MA #elif defined HAS_IP5306 #define PMU_CHG_CURRENT 2 #endif @@ -55,8 +55,8 @@ void calibrate_voltage(void); bool batt_sufficient(void); #ifdef HAS_PMU -#include -extern AXP20X_Class pmu; +#include "XPowersLib.h" +extern XPowersPMU pmu; enum pmu_power_t { pmu_power_on, pmu_power_off, pmu_power_sleep }; void AXP192_powerevent_IRQ(void); void AXP192_power(pmu_power_t powerlevel); diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index 0fc5e8fe..90a2465b 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -34,19 +34,14 @@ Reset -> reset device // power management settings #define HAS_PMU 1 // has AXP192 chip +#define XPOWERS_CHIP_AXP192 1 #define PMU_INT GPIO_NUM_35 // battery interrupt -#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_1000MA // battery charge current +#define PMU_CHG_CURRENT XPOWERS_CHG_CUR_1000MA // battery charge current // possible values (mA): // 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 -#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V // battery charge cutoff +#define PMU_CHG_CUTOFF XPOWERS_CHG_VOL_4V2 // battery charge cutoff // possible values (V): -// 4_1/4_15/4_2/4_36 - -// blue onboard led settings -// possible values: -// AXP20X_LED_OFF / AXP20X_LED_LOW_LEVEL (means LED ON) / AXP20X_LED_BLINK_1HZ / AXP20X_LED_BLINK_4HZ -#define PMU_LED_RUN_MODE AXP20X_LED_LOW_LEVEL -#define PMU_LED_SLEEP_MODE AXP20X_LED_OFF +// 4V1/4V15/4V2/4V36 // GPS settings #define HAS_GPS 1 // use on board GPS diff --git a/src/power.cpp b/src/power.cpp index 8045b09d..e28324ac 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -23,59 +23,44 @@ static const adc_unit_t unit = ADC_UNIT_1; #endif // BAT_MEASURE_ADC #ifdef HAS_PMU -AXP20X_Class pmu; +XPowersPMU pmu; void AXP192_powerevent_IRQ(void) { - pmu.readIRQ(); + pmu.getIrqStatus(); - if (pmu.isVbusOverVoltageIRQ()) + if (pmu.isVbusOverVoltageIrq()) ESP_LOGI(TAG, "USB voltage %.2fV too high.", pmu.getVbusVoltage() / 1000); - if (pmu.isVbusPlugInIRQ()) + if (pmu.isVbusInsertIrq()) ESP_LOGI(TAG, "USB plugged, %.2fV @ %.0mA", pmu.getVbusVoltage() / 1000, pmu.getVbusCurrent()); - if (pmu.isVbusRemoveIRQ()) + if (pmu.isVbusRemoveIrq()) ESP_LOGI(TAG, "USB unplugged."); - if (pmu.isBattPlugInIRQ()) + if (pmu.isBatInsertIrq()) ESP_LOGI(TAG, "Battery is connected."); - if (pmu.isBattRemoveIRQ()) + if (pmu.isBatRemoveIrq()) ESP_LOGI(TAG, "Battery was removed."); - if (pmu.isChargingIRQ()) - ESP_LOGI(TAG, "Battery charging."); - if (pmu.isChargingDoneIRQ()) { + if (pmu.isBatChagerStartIrq()) + ESP_LOGI(TAG, "Battery charging started."); + if (pmu.isBatChagerDoneIrq()) ESP_LOGI(TAG, "Battery charging done."); -#ifdef PMU_LED_RUN_MODE - pmu.setChgLEDMode(PMU_LED_RUN_MODE); -#else - pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL); -#endif - } - if (pmu.isBattTempLowIRQ()) + if (pmu.isBattTempLowIrq()) ESP_LOGI(TAG, "Battery high temperature."); - if (pmu.isBattTempHighIRQ()) + if (pmu.isBattTempHighIrq()) ESP_LOGI(TAG, "Battery low temperature."); - if (pmu.isLowVoltageLevel1IRQ()) { - ESP_LOGI(TAG, "Battery has reached voltage level 1."); - pmu.setChgLEDMode(AXP20X_LED_BLINK_4HZ); - } - if (pmu.isLowVoltageLevel2IRQ()) { - ESP_LOGI(TAG, "Battery has reached voltage level 2."); - pmu.setChgLEDMode(AXP20X_LED_BLINK_1HZ); - } - #ifdef HAS_BUTTON // short press -> esp32 deep sleep mode, can be exited by pressing user button - if (pmu.isPEKShortPressIRQ()) { + if (pmu.isPekeyShortPressIrq()) { enter_deepsleep(0, HAS_BUTTON); } #endif // long press -> shutdown power, can be exited by another longpress - if (pmu.isPEKLongtPressIRQ()) { + if (pmu.isPekeyLongPressIrq()) { AXP192_power(pmu_power_off); // switch off Lora, GPS, display } - pmu.clearIRQ(); + pmu.clearIrqStatus(); // refresh stored voltage value read_battlevel(); @@ -86,46 +71,37 @@ void AXP192_power(pmu_power_t powerlevel) { case pmu_power_off: pmu.shutdown(); break; - case pmu_power_sleep: -#ifdef PMU_LED_SLEEP_MODE - pmu.setChgLEDMode(PMU_LED_SLEEP_MODE); -#else - pmu.setChgLEDMode(AXP20X_LED_OFF); -#endif + pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_CHG_LED_FRE_1HZ); // we don't cut off DCDC1, because OLED display will then block i2c bus - // pmu.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); // OLED off - pmu.setPowerOutPut(AXP192_LDO3, AXP202_OFF); // gps off - pmu.setPowerOutPut(AXP192_LDO2, AXP202_OFF); // lora off + // pmu.disableDC1(); // OLED off + pmu.disableLDO3(); // gps off + pmu.disableLDO2(); // lora off + pmu.enableSleep(); break; - case pmu_power_on: default: - pmu.setPowerOutPut(AXP192_LDO2, AXP202_ON); // Lora on T-Beam V1.0/1.1 - pmu.setPowerOutPut(AXP192_LDO3, AXP202_ON); // Gps on T-Beam V1.0/1.1 - pmu.setPowerOutPut(AXP192_DCDC1, AXP202_ON); // OLED on T-Beam v1.0/1.1 - pmu.setPowerOutPut(AXP192_DCDC2, AXP202_OFF); // unused on T-Beam v1.0/1.1 - pmu.setPowerOutPut(AXP192_EXTEN, AXP202_OFF); // unused on T-Beam v1.0/1.1 -#ifdef PMU_LED_RUN_MODE - pmu.setChgLEDMode(PMU_LED_RUN_MODE); -#else - pmu.setChgLEDMode(AXP20X_LED_LOW_LEVEL); -#endif + pmu.enableLDO2(); // Lora on T-Beam V1.0/1.1 + pmu.enableLDO3(); // Gps on T-Beam V1.0/1.1 + pmu.enableDC1(); // OLED on T-Beam v1.0/1.1 + pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_CHG_LED_LEVEL_LOW); break; } } void AXP192_showstatus(void) { if (pmu.isBatteryConnect()) - if (pmu.isChargeing()) + if (pmu.isCharging()) ESP_LOGI(TAG, "Battery charging, %.2fV @ %.0fmAh", - pmu.getBattVoltage() / 1000, pmu.getBattChargeCurrent()); + pmu.getBattVoltage() / 1000, pmu.getBatteryChargeCurrent()); else ESP_LOGI(TAG, "Battery not charging"); else ESP_LOGI(TAG, "No Battery"); - if (pmu.isVBUSPlug()) + if (pmu.isVbusIn()) ESP_LOGI(TAG, "USB powered, %.0fmW", pmu.getVbusVoltage() / 1000 * pmu.getVbusCurrent()); else @@ -133,58 +109,58 @@ void AXP192_showstatus(void) { } void AXP192_init(void) { - if (pmu.begin(i2c_readBytes, i2c_writeBytes, AXP192_PRIMARY_ADDRESS) == - AXP_FAIL) + if (!pmu.begin(Wire, AXP192_PRIMARY_ADDRESS, SCL, SDA)) ESP_LOGI(TAG, "AXP192 PMU initialization failed"); else { - // configure voltages - pmu.setDCDC1Voltage(3300); // for external OLED display - pmu.setLDO2Voltage(3300); // LORA VDD 3v3 - pmu.setLDO3Voltage(3300); // GPS VDD 3v3 + ESP_LOGD(TAG, "AXP192 ChipID:0x%x", pmu.getChipID()); - // configure voltage warning levels - pmu.setVWarningLevel1(3600); - pmu.setVWarningLevel2(3800); - pmu.setPowerDownVoltage(3300); + // set pmu operating voltages + pmu.setMinSystemVoltage(2700); + pmu.setVbusVoltageLimit(XPOWERS_VBUS_VOL_LIM_4V5); + pmu.disableVbusCurrLimit(); + + // set device operating voltages + pmu.setDC1Voltage(3300); // for external OLED display + pmu.setLDO2Voltage(3300); // LORA VDD 3v3 + pmu.setLDO3Voltage(3300); // GPS VDD 3v3 // configure PEK button settings - pmu.setTimeOutShutdown(false); // forced shutdown by PEK enabled - pmu.setShutdownTime( - AXP_POWER_OFF_TIME_6S); // 6 sec button press for shutdown - pmu.setlongPressTime( - AXP_LONGPRESS_TIME_1S5); // 1.5 sec button press for long press - pmu.setStartupTime( - AXP192_STARTUP_TIME_1S); // 1 sec button press for startup + pmu.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + pmu.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); // set battery temperature sensing pin off to save power - pmu.setTSmode(AXP_TS_PIN_MODE_DISABLE); + pmu.disableTSPinMeasure(); - // switch ADCs on - pmu.adc1Enable(AXP202_BATT_VOL_ADC1, true); - pmu.adc1Enable(AXP202_BATT_CUR_ADC1, true); - pmu.adc1Enable(AXP202_VBUS_VOL_ADC1, true); - pmu.adc1Enable(AXP202_VBUS_CUR_ADC1, true); + // Enable internal ADC detection + pmu.enableBattDetection(); + pmu.enableVbusVoltageMeasure(); + pmu.enableBattVoltageMeasure(); + pmu.enableSystemVoltageMeasure(); #ifdef PMU_INT pinMode(PMU_INT, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PMU_INT), PMUIRQ, FALLING); - pmu.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | - AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ | - AXP202_CHARGING_FINISHED_IRQ | AXP202_PEK_SHORTPRESS_IRQ, - 1); - pmu.clearIRQ(); + // disable all interrupts + pmu.disableIRQ(XPOWERS_ALL_IRQ); + // clear all interrupt flags + pmu.clearIrqStatus(); + // enable the required interrupt function + pmu.enableIRQ(XPOWERS_BAT_INSERT_IRQ | XPOWERS_BAT_REMOVE_IRQ | // BATTERY + XPOWERS_VBUS_INSERT_IRQ | XPOWERS_VBUS_REMOVE_IRQ | // VBUS + XPOWERS_PKEY_SHORT_IRQ | XPOWERS_PKEY_LONG_IRQ | // POWER KEY + XPOWERS_BAT_CHG_DONE_IRQ | XPOWERS_BAT_CHG_START_IRQ // CHARGE + ); #endif // PMU_INT // set charging parameterss according to user settings if we have (see power.h) #ifdef PMU_CHG_CURRENT - pmu.setChargeControlCur(PMU_CHG_CURRENT); - pmu.setChargingTargetVoltage(PMU_CHG_CUTOFF); - pmu.enableChargeing(true); + pmu.setChargeCurrent(PMU_CHG_CURRENT); + pmu.setChargerVoltageLimit(PMU_CHG_CUTOFF); + pmu.enableCharge(); #endif // switch power rails on AXP192_power(pmu_power_on); - ESP_LOGI(TAG, "AXP192 PMU initialized"); } } @@ -263,6 +239,8 @@ uint8_t read_battlevel(mapFn_t mapFunction) { uint8_t batt_percent = 0; #ifdef HAS_IP5306 batt_percent = IP5306_GetBatteryLevel(); +#elif defined HAS_PMU + batt_percent = pmu.getBatteryPercent(); #else const uint16_t batt_voltage = read_voltage(); if (batt_voltage <= BAT_MIN_VOLTAGE) @@ -292,7 +270,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { // overwrite calculated value if we have external power #ifdef HAS_PMU - if (pmu.isVBUSPlug()) + if (pmu.isVbusIn()) LMIC_setBatteryLevel(MCMD_DEVS_EXT_POWER); #elif defined HAS_IP5306 if (IP5306_GetPowerSource()) From f43126eec2067d4114b16e5c6a557ad866dba42f Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 18 Aug 2022 12:11:47 +0200 Subject: [PATCH 20/45] cleanups after change PMU lib --- include/display.h | 1 - include/power.h | 2 +- src/display.cpp | 8 -------- src/power.cpp | 22 +++++++++++----------- src/reset.cpp | 12 +++--------- 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/include/display.h b/include/display.h index 86f7ccff..b4569481 100644 --- a/include/display.h +++ b/include/display.h @@ -102,7 +102,6 @@ void dp_setup(int contrast = 0); void dp_refresh(bool nextPage = false); void dp_init(bool verbose = false); void dp_shutdown(void); -void dp_message(const char *msg, int line, bool invers); void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer = NULL); void dp_contrast(uint8_t contrast); diff --git a/include/power.h b/include/power.h index c853447b..8a69e269 100644 --- a/include/power.h +++ b/include/power.h @@ -55,7 +55,7 @@ void calibrate_voltage(void); bool batt_sufficient(void); #ifdef HAS_PMU -#include "XPowersLib.h" +#include extern XPowersPMU pmu; enum pmu_power_t { pmu_power_on, pmu_power_off, pmu_power_sleep }; void AXP192_powerevent_IRQ(void); diff --git a/src/display.cpp b/src/display.cpp index 2343430e..56dc2ac5 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -446,14 +446,6 @@ void dp_shutdown(void) { #endif } -// print static message on display -void dp_message(const char *msg, int line, bool invers) { - dp_setFont(MY_FONT_SMALL, invers ? 1 : 0); - dp->setCursor(0, line * 8); - dp->printf("%-16s", msg); - dp_dump(); -} // dp_message - // ------------- QR code plotter ----------------- void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { diff --git a/src/power.cpp b/src/power.cpp index e28324ac..9a9a47a7 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -35,7 +35,6 @@ void AXP192_powerevent_IRQ(void) { pmu.getVbusCurrent()); if (pmu.isVbusRemoveIrq()) ESP_LOGI(TAG, "USB unplugged."); - if (pmu.isBatInsertIrq()) ESP_LOGI(TAG, "Battery is connected."); if (pmu.isBatRemoveIrq()) @@ -48,17 +47,16 @@ void AXP192_powerevent_IRQ(void) { ESP_LOGI(TAG, "Battery high temperature."); if (pmu.isBattTempHighIrq()) ESP_LOGI(TAG, "Battery low temperature."); -#ifdef HAS_BUTTON - // short press -> esp32 deep sleep mode, can be exited by pressing user button - if (pmu.isPekeyShortPressIrq()) { - enter_deepsleep(0, HAS_BUTTON); - } -#endif - // long press -> shutdown power, can be exited by another longpress - if (pmu.isPekeyLongPressIrq()) { + // PEK button handling: + // long press -> shutdown power, must be exited by another longpress + if (pmu.isPekeyLongPressIrq()) AXP192_power(pmu_power_off); // switch off Lora, GPS, display - } +#ifdef HAS_BUTTON + // short press -> esp32 deep sleep mode, must be exited by user button + if (pmu.isPekeyShortPressIrq()) + enter_deepsleep(0, HAS_BUTTON); +#endif pmu.clearIrqStatus(); @@ -69,6 +67,8 @@ void AXP192_powerevent_IRQ(void) { void AXP192_power(pmu_power_t powerlevel) { switch (powerlevel) { case pmu_power_off: + pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_CHG_LED_DISABLE); pmu.shutdown(); break; case pmu_power_sleep: @@ -152,7 +152,7 @@ void AXP192_init(void) { ); #endif // PMU_INT -// set charging parameterss according to user settings if we have (see power.h) +// set charging parameters according to user settings if we have (see power.h) #ifdef PMU_CHG_CURRENT pmu.setChargeCurrent(PMU_CHG_CURRENT); pmu.setChargerVoltageLimit(PMU_CHG_CUTOFF); diff --git a/src/reset.cpp b/src/reset.cpp index b6d39984..18470eef 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -105,20 +105,14 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { RTC_runmode = RUNMODE_SLEEP; int i; - // show message on display -#ifdef HAS_DISPLAY - dp_message("-GOING TO SLEEP-", 7, true); -#endif - // validate wake up pin, if we have if (!GPIO_IS_VALID_GPIO(wakeup_gpio)) wakeup_gpio = GPIO_NUM_MAX; - // stop further enqueuing of senddata and MAC processing - // -> skipped, because shutting down bluedroid stack tends to crash - // libpax_counter_stop(); + // stop further enqueuing of senddata and MAC processing + libpax_counter_stop(); - // switch off any power consuming hardware + // switch off any power consuming hardware #if (HAS_SDS011) sds011_sleep(); #endif From 9791333b0e40f653a3d0d89840f45f1125961f24 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 18 Aug 2022 12:11:59 +0200 Subject: [PATCH 21/45] v3.3.1 --- platformio_orig.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 0ce2ab6b..3549699b 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -62,9 +62,7 @@ lib_deps_lora = mcci-catena/MCCI LoRaWAN LMIC library @ ^4.1.1 lib_deps_display = https://github.com/bitbank2/OneBitDisplay.git - ;bitbank2/OneBitDisplay @ ^2.1.0 https://github.com/bitbank2/bb_spi_lcd.git - ;bitbank2/bb_spi_lcd @ ^2.3.0 ricmoo/QRCode @ ^0.0.1 lib_deps_ledmatrix = seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0 @@ -84,7 +82,7 @@ lib_deps_basic = bblanchon/ArduinoJson @ ^6 makuna/RTC @ ^2.3.5 spacehuhn/SimpleButton - lewisxhe/AXP202X_Library @ ^1.1.3 + https://github.com/lewisxhe/XPowersLib.git 256dpi/MQTT @ ^2.4.8 lib_deps_all = ${common.lib_deps_basic} From 4b216fb564d6513ac60fdf630b43ac77effc1597 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Aug 2022 16:35:02 +0200 Subject: [PATCH 22/45] simplify TFT display definition --- include/display.h | 7 ++----- include/globals.h | 3 +++ include/i2c.h | 1 + include/led.h | 4 ++++ src/display.cpp | 9 +++------ src/hal/m5core.h | 3 +-- src/hal/m5fire.h | 4 ++-- src/hal/ttgotdisplay.h | 11 +---------- src/hal/ttgotdisplays3.h | 27 +++++++++++++++++++++++++++ src/hal/ttgotwristband.h | 3 +-- 10 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 src/hal/ttgotdisplays3.h diff --git a/include/display.h b/include/display.h index b4569481..4965f526 100644 --- a/include/display.h +++ b/include/display.h @@ -2,6 +2,7 @@ #define _DISPLAY_H #include +#include #include "cyclic.h" #include "qrcode.h" #include "power.h" @@ -48,7 +49,7 @@ extern BB_SPI_LCD *dp; #endif // settings for TFT display library -#elif (HAS_DISPLAY == 2) +#elif (HAS_DISPLAY) == 2 #define MY_FONT_SMALL 2 #define MY_FONT_NORMAL 2 @@ -74,10 +75,6 @@ extern BB_SPI_LCD *dp; #define OLED_TYPE OLED_128x64 #endif -#ifndef MY_DISPLAY_INVERT -#define MY_DISPLAY_INVERT 0 -#endif - #ifndef MY_DISPLAY_FLIP #define MY_DISPLAY_FLIP 0 #endif diff --git a/include/globals.h b/include/globals.h index 9150be80..8d57f1dd 100644 --- a/include/globals.h +++ b/include/globals.h @@ -12,7 +12,10 @@ #include #include #include + +#ifdef HAS_BME680 #include +#endif #define _bit(b) (1U << (b)) #define _bitl(b) (1UL << (b)) diff --git a/include/i2c.h b/include/i2c.h index ce64ff70..a8c7c8ea 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -2,6 +2,7 @@ #define _I2C_H #include +#include #include #define SSD1306_PRIMARY_ADDRESS (0x3D) diff --git a/include/led.h b/include/led.h index 6ee08289..6bbef12d 100644 --- a/include/led.h +++ b/include/led.h @@ -1,8 +1,12 @@ #ifndef _LED_H #define _LED_H +#ifdef RGB_LED_COUNT #include +#endif +#ifdef HAS_LORA #include "lorawan.h" +#endif #ifndef RGB_LED_COUNT #define RGB_LED_COUNT 1 diff --git a/src/display.cpp b/src/display.cpp index 56dc2ac5..c9aaad20 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -68,16 +68,13 @@ void dp_setup(int contrast) { dp->setRotation( MY_DISPLAY_FLIP ? 2 : 0); // 0 = no rotation, 1 = 90°, 2 = 180°, 3 = 280° -#elif (HAS_DISPLAY) == 2 // SPI TFT +#elif (HAS_DISPLAY) == 2 // TFT LCD 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->begin(TFT_TYPE); 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 @@ -138,7 +135,7 @@ void dp_init(bool verbose) { #endif #endif // HAS_LORA - } // verbose + } // verbose dp_power(cfg.screenon); // set display off if disabled } // dp_init diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 1f3cd537..d1bd87c6 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -48,8 +48,6 @@ //#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_INVERT 1 -#define TFT_TYPE LCD_ILI9341 #define TFT_MOSI MOSI // SPI #define TFT_MISO MISO // SPI #define TFT_SCLK SCK // SPI @@ -58,5 +56,6 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light #define TFT_FREQUENCY 40000000 +#define TFT_TYPE LCD_ILI9341, FLAGS_NONE, TFT_FREQUENCY, TFT_CS, TFT_DC, TFT_RST, TFT_BL, TFT_MISO, TFT_MOSI, TFT_SCLK #endif diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index e93d0f5f..156cd494 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -53,8 +53,6 @@ //#define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_INVERT 1 -#define TFT_TYPE LCD_ILI9341 #define TFT_MOSI MOSI // SPI #define TFT_MISO MISO // SPI #define TFT_SCLK SCK // SPI @@ -63,5 +61,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light #define TFT_FREQUENCY 40000000 +#define TFT_TYPE LCD_ILI9341, FLAGS_NONE, TFT_FREQUENCY, TFT_CS, TFT_DC, TFT_RST, TFT_BL, TFT_MISO, TFT_MOSI, TFT_SCLK + #endif \ No newline at end of file diff --git a/src/hal/ttgotdisplay.h b/src/hal/ttgotdisplay.h index b1f625eb..4cabd198 100644 --- a/src/hal/ttgotdisplay.h +++ b/src/hal/ttgotdisplay.h @@ -18,18 +18,9 @@ // Display Settings #define HAS_DISPLAY 2 // TFT-LCD +#define TFT_TYPE DISPLAY_T_DISPLAY #define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 135 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_INVERT 1 -#define TFT_TYPE LCD_ST7789_135 // size 135x240 px -#define TFT_MOSI GPIO_NUM_19 // SPI -#define TFT_MISO NOT_A_PIN // SPI -#define TFT_SCLK GPIO_NUM_18 // SPI -#define TFT_CS GPIO_NUM_5 // Chip select control -#define TFT_DC GPIO_NUM_16 // Data Command control -#define TFT_RST GPIO_NUM_23 // Reset -#define TFT_BL GPIO_NUM_4 // LED back-light -#define TFT_FREQUENCY 40000000 #endif diff --git a/src/hal/ttgotdisplays3.h b/src/hal/ttgotdisplays3.h new file mode 100644 index 00000000..fc0a60fd --- /dev/null +++ b/src/hal/ttgotdisplays3.h @@ -0,0 +1,27 @@ +// clang-format off +// upload_speed 1500000 +// board ESP32-S3-DevKitC-1 + +#ifndef _TTGOTDISPLAYS3_H +#define _TTGOTDISPLAYS3_H + +#include + +#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature + +#define HAS_LED LED_BUILTIN +#define HAS_BUTTON 14 // on board button (right side) + +// power management settings +//#define BAT_MEASURE_ADC ADC1_GPIO4_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_6 +//#define BAT_VOLTAGE_DIVIDER 2.605f // voltage divider + +// Display Settings +#define HAS_DISPLAY 2 // TFT-LCD parallel +#define TFT_TYPE DISPLAY_T_DISPLAY_S3 +#define MY_DISPLAY_FLIP 1 // use if display is rotated +#define MY_DISPLAY_WIDTH 172 +#define MY_DISPLAY_HEIGHT 320 + + +#endif \ No newline at end of file diff --git a/src/hal/ttgotwristband.h b/src/hal/ttgotwristband.h index 2439de6e..91c06633 100644 --- a/src/hal/ttgotwristband.h +++ b/src/hal/ttgotwristband.h @@ -21,8 +21,6 @@ #define MY_DISPLAY_FLIP 1 // use if display is rotated #define MY_DISPLAY_WIDTH 80 #define MY_DISPLAY_HEIGHT 160 -#define MY_DISPLAY_INVERT 1 -#define TFT_TYPE LCD_ST7735S #define TFT_MOSI GPIO_NUM_19 // SPI #define TFT_MISO NOT_A_PIN // SPI #define TFT_SCLK GPIO_NUM_18 // SPI @@ -31,6 +29,7 @@ #define TFT_RST GPIO_NUM_26 // Reset #define TFT_BL GPIO_NUM_27 // LED back-light #define TFT_FREQUENCY 27000000 +#define TFT_TYPE LCD_ST7735S, FLAGS_NONE, TFT_FREQUENCY, TFT_CS, TFT_DC, TFT_RST, TFT_BL, TFT_MISO, TFT_MOSI, TFT_SCLK #endif From 69fd3e51e2b034cfa566abeeb553588a60558459 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Aug 2022 18:18:47 +0200 Subject: [PATCH 23/45] reset.cpp: cleanup reset reasons --- include/reset.h | 2 +- src/reset.cpp | 24 ++++-------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/include/reset.h b/include/reset.h index 6ce2661e..8f700769 100644 --- a/include/reset.h +++ b/include/reset.h @@ -2,7 +2,7 @@ #define _RESET_H #include -#include +#include #include "i2c.h" #include "lorawan.h" diff --git a/src/reset.cpp b/src/reset.cpp index 18470eef..9c58efb8 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -11,7 +11,6 @@ static const char TAG[] = __FILE__; // RTC_NOINIT_ATTR -> keep value after a software restart or system crash RTC_NOINIT_ATTR runmode_t RTC_runmode; RTC_NOINIT_ATTR uint32_t RTC_restarts; - // RTC_DATA_ATTR -> keep values after a wakeup from sleep RTC_DATA_ATTR struct timeval RTC_sleep_start_time; RTC_DATA_ATTR unsigned long long RTC_millis = 0; @@ -53,18 +52,17 @@ void do_after_reset(void) { #endif switch (rtc_get_reset_reason(0)) { - case POWERON_RESET: // 0x01 Vbat power on reset - case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not - // stable + case RESET_REASON_CHIP_POWER_ON: + case RESET_REASON_SYS_BROWN_OUT: reset_rtc_vars(); break; - case SW_CPU_RESET: // 0x0c Software reset CPU + case RESET_REASON_CPU0_SW: // keep previous set runmode (update / normal / maintenance) RTC_restarts++; break; - case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core + case RESET_REASON_CORE_DEEP_SLEEP: // calculate time spent in deep sleep gettimeofday(&sleep_stop_time, NULL); sleep_time_ms = @@ -72,26 +70,13 @@ void do_after_reset(void) { (sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000; RTC_millis += sleep_time_ms; // increment system monotonic time ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms); - // do we have a valid time? -> set global variable timeSource = timeIsValid(sleep_stop_time.tv_sec) ? _set : _unsynced; - // set wakeup state, not if we have pending OTA update if (RTC_runmode == RUNMODE_SLEEP) RTC_runmode = RUNMODE_WAKEUP; break; - case SW_RESET: // 0x03 Software reset digital core - case OWDT_RESET: // 0x04 Legacy watch dog reset digital core - case SDIO_RESET: // 0x06 Reset by SLC module, reset digital core - case TG0WDT_SYS_RESET: // 0x07 Timer Group0 Watch dog reset digital core - case TG1WDT_SYS_RESET: // 0x08 Timer Group1 Watch dog reset digital core - case RTCWDT_SYS_RESET: // 0x09 RTC Watch dog Reset digital core - case INTRUSION_RESET: // 0x0a Instrusion tested to reset CPU - case TGWDT_CPU_RESET: // 0x0b Time Group reset CPU - case RTCWDT_CPU_RESET: // 0x0d RTC Watch dog Reset CPU - case EXT_CPU_RESET: // 0x0e for APP CPU, reseted by PRO CPU - case RTCWDT_RTC_RESET: // 0x10 RTC Watch dog reset digital core and rtc mode default: RTC_runmode = RUNMODE_POWERCYCLE; RTC_restarts++; @@ -108,7 +93,6 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { // validate wake up pin, if we have if (!GPIO_IS_VALID_GPIO(wakeup_gpio)) wakeup_gpio = GPIO_NUM_MAX; - // stop further enqueuing of senddata and MAC processing libpax_counter_stop(); From 3f162e616c5cf6f7e66a4a0fe5807b9a228d01e4 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Aug 2022 18:24:09 +0200 Subject: [PATCH 24/45] add ttgotdisplays3.h --- src/hal/ttgotdisplays3.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hal/ttgotdisplays3.h b/src/hal/ttgotdisplays3.h index fc0a60fd..0c8f13aa 100644 --- a/src/hal/ttgotdisplays3.h +++ b/src/hal/ttgotdisplays3.h @@ -7,9 +7,7 @@ #include -#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature - -#define HAS_LED LED_BUILTIN +#define HAS_LED NOT_A_PIN #define HAS_BUTTON 14 // on board button (right side) // power management settings @@ -23,5 +21,4 @@ #define MY_DISPLAY_WIDTH 172 #define MY_DISPLAY_HEIGHT 320 - #endif \ No newline at end of file From ddb87301a42d8a56a03d13b1bac9fec3b5254a11 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Aug 2022 19:27:04 +0200 Subject: [PATCH 25/45] ESP 32s3 fixes --- src/rcommand.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 45bfce07..686248f4 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -324,9 +324,15 @@ void get_config(uint8_t val[]) { void get_status(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: get device status"); payload.reset(); +#ifdef CONFIG_IDF_TARGET_ESP32S3 + payload.addStatus(read_voltage(), (uint64_t)(uptime() / 1000ULL), 0, + // temperatureRead(), + getFreeRAM(), rtc_get_reset_reason(0), RTC_restarts); +#else payload.addStatus(read_voltage(), (uint64_t)(uptime() / 1000ULL), temperatureRead(), getFreeRAM(), rtc_get_reset_reason(0), RTC_restarts); +#endif SendPayload(STATUSPORT); }; From ed9264793646b2a9a2842ac829fe85f5f93b0773 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 2 Sep 2022 14:23:44 +0200 Subject: [PATCH 26/45] update xpowerslib api --- src/power.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/power.cpp b/src/power.cpp index 9a9a47a7..e5d04553 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -67,13 +67,13 @@ void AXP192_powerevent_IRQ(void) { void AXP192_power(pmu_power_t powerlevel) { switch (powerlevel) { case pmu_power_off: - pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_CHG_LED_DISABLE); + pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_DISABLE); pmu.shutdown(); break; case pmu_power_sleep: - pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_CHG_LED_FRE_1HZ); + pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_FRE_1HZ); // we don't cut off DCDC1, because OLED display will then block i2c bus // pmu.disableDC1(); // OLED off pmu.disableLDO3(); // gps off @@ -85,8 +85,8 @@ void AXP192_power(pmu_power_t powerlevel) { pmu.enableLDO2(); // Lora on T-Beam V1.0/1.1 pmu.enableLDO3(); // Gps on T-Beam V1.0/1.1 pmu.enableDC1(); // OLED on T-Beam v1.0/1.1 - pmu.setChargerLedFunction(XPOWER_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_CHG_LED_LEVEL_LOW); + pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); + pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_LEVEL_LOW); break; } } @@ -125,8 +125,8 @@ void AXP192_init(void) { pmu.setLDO3Voltage(3300); // GPS VDD 3v3 // configure PEK button settings - pmu.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); - pmu.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + pmu.setPowerKeyPressOffTime(XPOWERS_AXP192_POWEROFF_4S); + pmu.setPowerKeyPressOnTime(XPOWERS_AXP192_POWERON_128MS); // set battery temperature sensing pin off to save power pmu.disableTSPinMeasure(); From 2d05e1696e6393a12dffe65c250f3987d5405eeb Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 17 Sep 2022 18:34:30 +0200 Subject: [PATCH 27/45] xpowers lib updates --- platformio_orig.ini | 2 +- src/hal/ttgobeam10.h | 4 ++-- src/power.cpp | 33 +++++++++++++++------------------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 3549699b..e53eded3 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -82,7 +82,7 @@ lib_deps_basic = bblanchon/ArduinoJson @ ^6 makuna/RTC @ ^2.3.5 spacehuhn/SimpleButton - https://github.com/lewisxhe/XPowersLib.git + lewisxhe/XPowersLib @ ^0.1.4 256dpi/MQTT @ ^2.4.8 lib_deps_all = ${common.lib_deps_basic} diff --git a/src/hal/ttgobeam10.h b/src/hal/ttgobeam10.h index 90a2465b..9dbfe173 100644 --- a/src/hal/ttgobeam10.h +++ b/src/hal/ttgobeam10.h @@ -36,10 +36,10 @@ Reset -> reset device #define HAS_PMU 1 // has AXP192 chip #define XPOWERS_CHIP_AXP192 1 #define PMU_INT GPIO_NUM_35 // battery interrupt -#define PMU_CHG_CURRENT XPOWERS_CHG_CUR_1000MA // battery charge current +#define PMU_CHG_CURRENT XPOWERS_AXP192_CHG_CUR_1000MA // battery charge current // possible values (mA): // 100/190/280/360/450/550/630/700/780/880/960/1000/1080/1160/1240/1320 -#define PMU_CHG_CUTOFF XPOWERS_CHG_VOL_4V2 // battery charge cutoff +#define PMU_CHG_CUTOFF XPOWERS_AXP192_CHG_VOL_4V2 // battery charge cutoff // possible values (V): // 4V1/4V15/4V2/4V36 diff --git a/src/power.cpp b/src/power.cpp index e5d04553..70962ef6 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -67,13 +67,11 @@ void AXP192_powerevent_IRQ(void) { void AXP192_power(pmu_power_t powerlevel) { switch (powerlevel) { case pmu_power_off: - pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_DISABLE); + pmu.setChargingLedMode(XPOWERS_CHG_LED_OFF); pmu.shutdown(); break; case pmu_power_sleep: - pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_FRE_1HZ); + pmu.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); // we don't cut off DCDC1, because OLED display will then block i2c bus // pmu.disableDC1(); // OLED off pmu.disableLDO3(); // gps off @@ -85,8 +83,7 @@ void AXP192_power(pmu_power_t powerlevel) { pmu.enableLDO2(); // Lora on T-Beam V1.0/1.1 pmu.enableLDO3(); // Gps on T-Beam V1.0/1.1 pmu.enableDC1(); // OLED on T-Beam v1.0/1.1 - pmu.setChargerLedFunction(XPOWER_AXP192_CHGLED_CTRL_MANUAL); - pmu.setChargingLedFreq(XPOWERS_AXP192_CHG_LED_LEVEL_LOW); + pmu.setChargingLedMode(XPOWERS_CHG_LED_ON); break; } } @@ -115,9 +112,9 @@ void AXP192_init(void) { ESP_LOGD(TAG, "AXP192 ChipID:0x%x", pmu.getChipID()); // set pmu operating voltages - pmu.setMinSystemVoltage(2700); - pmu.setVbusVoltageLimit(XPOWERS_VBUS_VOL_LIM_4V5); - pmu.disableVbusCurrLimit(); + pmu.setSysPowerDownVoltage(2700); + pmu.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); + pmu.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); // set device operating voltages pmu.setDC1Voltage(3300); // for external OLED display @@ -125,8 +122,8 @@ void AXP192_init(void) { pmu.setLDO3Voltage(3300); // GPS VDD 3v3 // configure PEK button settings - pmu.setPowerKeyPressOffTime(XPOWERS_AXP192_POWEROFF_4S); - pmu.setPowerKeyPressOnTime(XPOWERS_AXP192_POWERON_128MS); + pmu.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + pmu.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); // set battery temperature sensing pin off to save power pmu.disableTSPinMeasure(); @@ -141,21 +138,21 @@ void AXP192_init(void) { pinMode(PMU_INT, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PMU_INT), PMUIRQ, FALLING); // disable all interrupts - pmu.disableIRQ(XPOWERS_ALL_IRQ); + pmu.disableIRQ(XPOWERS_AXP192_ALL_IRQ); // clear all interrupt flags pmu.clearIrqStatus(); // enable the required interrupt function - pmu.enableIRQ(XPOWERS_BAT_INSERT_IRQ | XPOWERS_BAT_REMOVE_IRQ | // BATTERY - XPOWERS_VBUS_INSERT_IRQ | XPOWERS_VBUS_REMOVE_IRQ | // VBUS - XPOWERS_PKEY_SHORT_IRQ | XPOWERS_PKEY_LONG_IRQ | // POWER KEY - XPOWERS_BAT_CHG_DONE_IRQ | XPOWERS_BAT_CHG_START_IRQ // CHARGE + pmu.enableIRQ(XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | // BATTERY + XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | // VBUS + XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | // POWER KEY + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ // CHARGE ); #endif // PMU_INT // set charging parameters according to user settings if we have (see power.h) #ifdef PMU_CHG_CURRENT - pmu.setChargeCurrent(PMU_CHG_CURRENT); - pmu.setChargerVoltageLimit(PMU_CHG_CUTOFF); + pmu.setChargerConstantCurr(PMU_CHG_CURRENT); + pmu.setChargeTargetVoltage(PMU_CHG_CUTOFF); pmu.enableCharge(); #endif From a92eea351364c6a96e0a29139c749c7d95579877 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 17 Sep 2022 21:21:00 +0200 Subject: [PATCH 28/45] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7130609..2474657d 100644 --- a/README.md +++ b/README.md @@ -576,9 +576,9 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/ # License -Copyright 2018-2020 Oliver Brandmueller +Copyright 2018-2022 Oliver Brandmueller -Copyright 2018-2020 Klaus Wilting +Copyright 2018-2022 Klaus Wilting Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 43c3d9d7963abe572b64a37477c1c9451c2c23ed Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 17 Sep 2022 21:54:39 +0200 Subject: [PATCH 29/45] bugfix axp192 battpercent --- src/power.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/power.cpp b/src/power.cpp index 70962ef6..72934461 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -237,7 +237,8 @@ uint8_t read_battlevel(mapFn_t mapFunction) { #ifdef HAS_IP5306 batt_percent = IP5306_GetBatteryLevel(); #elif defined HAS_PMU - batt_percent = pmu.getBatteryPercent(); + int bp = pmu.getBatteryPercent(); + batt_percent = bp < 0 ? 0 : bp; #else const uint16_t batt_voltage = read_voltage(); if (batt_voltage <= BAT_MIN_VOLTAGE) From 3a800c09c21629b9e5ac271d6e8586b5d0e20165 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 18 Sep 2022 17:21:22 +0200 Subject: [PATCH 30/45] AXP192 lib updates --- include/payload.h | 2 +- include/power.h | 2 +- src/display.cpp | 6 +++--- src/power.cpp | 27 +++++++++++++++------------ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/payload.h b/include/payload.h index 43bbb1d8..2add80b7 100644 --- a/include/payload.h +++ b/include/payload.h @@ -100,6 +100,6 @@ private: }; extern PayloadConvert payload; -extern uint8_t batt_level; +extern int8_t batt_level; #endif // _PAYLOAD_H_ diff --git a/include/power.h b/include/power.h index 8a69e269..1f7b7333 100644 --- a/include/power.h +++ b/include/power.h @@ -131,6 +131,6 @@ static inline uint8_t linear(uint16_t voltage, uint16_t minVoltage, (maxVoltage - minVoltage); } -uint8_t read_battlevel(mapFn_t mapFunction = &sigmoidal); +int8_t read_battlevel(mapFn_t mapFunction = &sigmoidal); #endif \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index c9aaad20..2526e514 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -226,10 +226,10 @@ void dp_refresh(bool nextPage) { // line 4: Battery + GPS status + Wifi channel // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306) - if (batt_level == 0) - dp->printf("No batt "); - else + if (batt_level > 0) dp->printf("Batt:%3u%% ", batt_level); + else + dp->printf("No batt "); #else dp->printf(" "); #endif diff --git a/src/power.cpp b/src/power.cpp index 72934461..0e346cac 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -5,7 +5,7 @@ // Local logging tag static const char TAG[] = __FILE__; -uint8_t batt_level = 0; // display value +int8_t batt_level = -1; // percent batt level, global variable, -1 means no batt #ifdef BAT_MEASURE_ADC esp_adc_cal_characteristics_t *adc_characs = @@ -92,11 +92,11 @@ void AXP192_showstatus(void) { if (pmu.isBatteryConnect()) if (pmu.isCharging()) ESP_LOGI(TAG, "Battery charging, %.2fV @ %.0fmAh", - pmu.getBattVoltage() / 1000, pmu.getBatteryChargeCurrent()); + pmu.getBattVoltage() / 1000.0, pmu.getBatteryChargeCurrent()); else ESP_LOGI(TAG, "Battery not charging"); else - ESP_LOGI(TAG, "No Battery"); + ESP_LOGI(TAG, "Battery not present"); if (pmu.isVbusIn()) ESP_LOGI(TAG, "USB powered, %.0fmW", @@ -142,10 +142,14 @@ void AXP192_init(void) { // clear all interrupt flags pmu.clearIrqStatus(); // enable the required interrupt function - pmu.enableIRQ(XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | // BATTERY - XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | // VBUS - XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | // POWER KEY - XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ // CHARGE + pmu.enableIRQ(XPOWERS_AXP192_BAT_INSERT_IRQ | + XPOWERS_AXP192_BAT_REMOVE_IRQ | // BATTERY + XPOWERS_AXP192_VBUS_INSERT_IRQ | + XPOWERS_AXP192_VBUS_REMOVE_IRQ | // VBUS + XPOWERS_AXP192_PKEY_SHORT_IRQ | + XPOWERS_AXP192_PKEY_LONG_IRQ | // POWER KEY + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | + XPOWERS_AXP192_BAT_CHG_START_IRQ // CHARGE ); #endif // PMU_INT @@ -231,14 +235,13 @@ uint16_t read_voltage(void) { return voltage; } -uint8_t read_battlevel(mapFn_t mapFunction) { +int8_t read_battlevel(mapFn_t mapFunction) { // returns the estimated battery level in values 0 ... 100 [percent] uint8_t batt_percent = 0; #ifdef HAS_IP5306 batt_percent = IP5306_GetBatteryLevel(); #elif defined HAS_PMU - int bp = pmu.getBatteryPercent(); - batt_percent = bp < 0 ? 0 : bp; + batt_percent = pmu.getBatteryPercent(); #else const uint16_t batt_voltage = read_voltage(); if (batt_voltage <= BAT_MIN_VOLTAGE) @@ -260,7 +263,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { // we calculate the applicable value from MCMD_DEVS_BATT_MIN to // MCMD_DEVS_BATT_MAX from batt_percent value - if (batt_percent == 0) + if (batt_percent == -1) LMIC_setBatteryLevel(MCMD_DEVS_BATT_NOINFO); else LMIC_setBatteryLevel(batt_percent / 100.0 * @@ -282,7 +285,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { bool batt_sufficient() { #if (defined HAS_PMU || defined BAT_MEASURE_ADC || defined HAS_IP5306) - if (batt_level) // we have a battery voltage + if (batt_level > 0) // we have a battery percent value return (batt_level > OTA_MIN_BATT); else #endif From 6c44865f508bfa38c4a330f38b3154324270f283 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 18 Sep 2022 17:21:40 +0200 Subject: [PATCH 31/45] bump to v3.3.2 --- platformio_orig.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index e53eded3..f1ef2568 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -46,7 +46,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 = 3.3.1 +release_version = 3.3.2 ; 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 @@ -71,11 +71,11 @@ lib_deps_rgbled = lib_deps_gps = mikalhart/TinyGPSPlus @ ^1.0.2 lib_deps_sensors = - adafruit/Adafruit Unified Sensor @ ^1.1.4 - adafruit/Adafruit BME280 Library @ ^2.2.1 - adafruit/Adafruit BMP085 Library @ ^1.2.0 + adafruit/Adafruit Unified Sensor @ ^1.1.6 + adafruit/Adafruit BME280 Library @ ^2.2.2 + adafruit/Adafruit BMP085 Library @ ^1.2.1 boschsensortec/BSEC Software Library @ 1.6.1480 - https://github.com/cyberman54/sds-dust-sensors-arduino-library.git + lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1 lib_deps_basic = https://github.com/dbSuS/libpax.git https://github.com/SukkoPera/Arduino-Rokkit-Hash.git @@ -83,7 +83,7 @@ lib_deps_basic = makuna/RTC @ ^2.3.5 spacehuhn/SimpleButton lewisxhe/XPowersLib @ ^0.1.4 - 256dpi/MQTT @ ^2.4.8 + 256dpi/MQTT @ ^2.5.0 lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora} From 808edf9f3a49bf273ad9342e51e93c12658000cc Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 24 Sep 2022 16:58:36 +0200 Subject: [PATCH 32/45] update libpax version --- platformio_orig.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index f1ef2568..22dccb35 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -77,7 +77,7 @@ lib_deps_sensors = boschsensortec/BSEC Software Library @ 1.6.1480 lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1 lib_deps_basic = - https://github.com/dbSuS/libpax.git + greyrook/libpax @ ^1.0.1 https://github.com/SukkoPera/Arduino-Rokkit-Hash.git bblanchon/ArduinoJson @ ^6 makuna/RTC @ ^2.3.5 From 4ef487627d60b28a7dacac36aa69da1213a02916 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 1 Oct 2022 19:26:45 +0200 Subject: [PATCH 33/45] Update platformio_orig.ini --- platformio_orig.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index f1ef2568..97e13654 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -54,7 +54,7 @@ extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@5.1.0 +platform_espressif32 = espressif32@5.2.0 monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file From 7438400e58402f365921619994cfb9c1d4108c39 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 19 Oct 2022 13:53:12 +0200 Subject: [PATCH 34/45] Update platformio_orig.ini --- platformio_orig.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 97e13654..f1ef2568 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -54,7 +54,7 @@ extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@5.2.0 +platform_espressif32 = espressif32@5.1.0 monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file From 51246f1296ddf60f8d8f7c382791b25635189885 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 22:33:46 +0200 Subject: [PATCH 35/45] libpax update (experimental) --- platformio_orig.ini | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 22dccb35..3eb41b62 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -54,7 +54,7 @@ extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@5.1.0 +platform_espressif32 = espressif32@5.2.0 monitor_speed = 115200 upload_speed = 115200 ; set by build.py and taken from hal file display_library = ; set by build.py and taken from hal file @@ -69,7 +69,7 @@ lib_deps_ledmatrix = lib_deps_rgbled = https://github.com/RoboticsBrno/SmartLeds.git lib_deps_gps = - mikalhart/TinyGPSPlus @ ^1.0.2 + mikalhart/TinyGPSPlus @ ^1.0.3 lib_deps_sensors = adafruit/Adafruit Unified Sensor @ ^1.1.6 adafruit/Adafruit BME280 Library @ ^2.2.2 @@ -77,7 +77,8 @@ lib_deps_sensors = boschsensortec/BSEC Software Library @ 1.6.1480 lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1 lib_deps_basic = - greyrook/libpax @ ^1.0.1 + ;greyrook/libpax @ ^1.0.1 + https://github.com/cyberman54/libpax.git https://github.com/SukkoPera/Arduino-Rokkit-Hash.git bblanchon/ArduinoJson @ ^6 makuna/RTC @ ^2.3.5 From 2f407ab4ed465d2086f5f429b3d0b4d7d80e907a Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 22:55:22 +0200 Subject: [PATCH 36/45] new country setting style --- src/main.cpp | 1 + src/paxcounter_orig.conf | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ddb86f0..380120ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,6 +276,7 @@ void setup() { libpax_default_config(&configuration); // configure WIFI sniffing + strcpy(configuration.wifi_my_country, WIFI_MY_COUNTRY); configuration.wificounter = cfg.wifiscan; configuration.wifi_channel_map = WIFI_CHANNEL_ALL; configuration.wifi_channel_switch_interval = cfg.wifichancycle; diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index 2848a42d..5249a6f0 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -48,9 +48,7 @@ */ // WiFi scan parameters -#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings -#define WIFI_CHANNEL_MAX 13 // total channel number to scan -#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings +#define WIFI_MY_COUNTRY "01" // select 2-letter locale for Wifi RF settings, e.g. "DE"; use "01" for world safe mode #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. // LoRa payload default parameters From 2e3cc4ec0292769ac99aea44c851e82c76843fb6 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 24 Oct 2022 11:15:06 +0200 Subject: [PATCH 37/45] bugfix display layout --- src/display.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 2526e514..f50402ef 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -204,7 +204,7 @@ void dp_refresh(bool nextPage) { if (cfg.wifiscan) dp->printf("WIFI:%-5u", count.wifi_count); else - dp->printf("WIFI:off"); + dp->printf("WIFI:off "); if (cfg.blescan) dp->printf("BLTH:%-5u", count.ble_count); else @@ -213,7 +213,7 @@ void dp_refresh(bool nextPage) { if (cfg.wifiscan) dp->printf("WIFI:%-5u", count.wifi_count); else - dp->printf("WIFI:off"); + dp->printf("WIFI:off "); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) dp->printf("BLTH:%-5u", count.ble_count); From 2313480e115d99b94a00dc3c19b53b731c2a31e0 Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Thu, 27 Oct 2022 12:34:43 +0200 Subject: [PATCH 38/45] added build workflow --- .github/workflows/build.yml | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..e6a1457c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,45 @@ +name: PlatformIO CI + +on: + pull_request: + push: + # branches: + # - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.9.15" + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - run: ls + - name: Copy of necessary files + run: | + cp platformio_orig.ini platformio.ini + cp src/loraconf_sample.h src/loraconf.h + cp src/ota_sample.conf src/ota.conf + cp src/paxcounter_orig.conf src/paxcounter.conf + - run: ls + + - name: Run PlatformIO + run: pio run From a2d93ef0e450809774b73182dd47253c41f4bc33 Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Thu, 27 Oct 2022 13:11:50 +0200 Subject: [PATCH 39/45] updatet versions of actions and added os-matrix --- .github/workflows/build.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6a1457c..9347d009 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,38 +8,39 @@ on: jobs: build: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Cache pip - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Cache PlatformIO - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.platformio key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: "3.9.15" - name: Install PlatformIO run: | python -m pip install --upgrade pip pip install --upgrade platformio - - run: ls - name: Copy of necessary files run: | cp platformio_orig.ini platformio.ini cp src/loraconf_sample.h src/loraconf.h cp src/ota_sample.conf src/ota.conf cp src/paxcounter_orig.conf src/paxcounter.conf - - run: ls - - name: Run PlatformIO run: pio run From a900ea2e7e2955f7e09e826212f7af37b8a27486 Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Thu, 27 Oct 2022 13:20:19 +0200 Subject: [PATCH 40/45] changed python version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9347d009..534b8e28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.9.15" + python-version: "3.9.13" - name: Install PlatformIO run: | python -m pip install --upgrade pip From c72a6f78f1cf52871bf52f3d5749daa5f29e176e Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Thu, 27 Oct 2022 13:34:26 +0200 Subject: [PATCH 41/45] run only on push for master --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 534b8e28..26844765 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,8 +3,8 @@ name: PlatformIO CI on: pull_request: push: - # branches: - # - master + branches: + - master jobs: build: From 4a7d005fc889bc2a8b4f470886ad97caf7efce6b Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Thu, 27 Oct 2022 13:57:15 +0200 Subject: [PATCH 42/45] update cache paths --- .github/workflows/build.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26844765..87da98e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,16 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + path: ~/.cache/pip + platformio-path: ~/.platformio + - os: macos-latest + path: ~/Library/Caches/pip + platformio-path: ~/Library/Caches/platformio + - os: windows-latest + path: ~\AppData\Local\pip\Cache + platformio-path: ~\AppData\Local\platformio\Cache runs-on: ${{ matrix.os }} steps: @@ -19,14 +29,14 @@ jobs: - name: Cache pip uses: actions/cache@v3 with: - path: ~/.cache/pip + path: ${{ matrix.path }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Cache PlatformIO uses: actions/cache@v3 with: - path: ~/.platformio + path: ${{ matrix.platformio-path }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - name: Set up Python uses: actions/setup-python@v4 From 220a8f331da36dc10d16e980dd6e2909caf07d1a Mon Sep 17 00:00:00 2001 From: Tim Huyeng Date: Fri, 28 Oct 2022 11:59:02 +0200 Subject: [PATCH 43/45] added development branch for workflow runs --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 87da98e3..53185297 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,7 @@ on: push: branches: - master + - development jobs: build: From 93009419d97e95d88e715e4744b9b0e3ac5cfe4f Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 29 Oct 2022 13:01:17 +0200 Subject: [PATCH 44/45] libpax update --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 380120ee..00a8bf2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,7 +276,7 @@ void setup() { libpax_default_config(&configuration); // configure WIFI sniffing - strcpy(configuration.wifi_my_country, WIFI_MY_COUNTRY); + strcpy(configuration.wifi_my_country_str, WIFI_MY_COUNTRY); configuration.wificounter = cfg.wifiscan; configuration.wifi_channel_map = WIFI_CHANNEL_ALL; configuration.wifi_channel_switch_interval = cfg.wifichancycle; From 16d0c03f5ceeb2df21b949c871b53eff20ec406d Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 29 Oct 2022 13:01:28 +0200 Subject: [PATCH 45/45] reduce CI to master --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 53185297..87da98e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,6 @@ on: push: branches: - master - - development jobs: build: