From 11e91bbd0099592ff7a7b77ce4e4aad3246e5b82 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 17:03:55 +0200 Subject: [PATCH 01/24] timesync.cpp small debug msg change --- src/timesync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timesync.cpp b/src/timesync.cpp index ce364dcd..e50f4353 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -48,7 +48,7 @@ void timesync_request(void) { return; // start timesync handshake else { - ESP_LOGI(TAG, "[%0.3f] Timeserver sync request seqNo#%d started", + ESP_LOGI(TAG, "[%0.3f] Timeserver sync request started, seqNo#%d", millis() / 1000.0, time_sync_seqNo); xTaskNotifyGive(timeSyncProcTask); // unblock timesync task } From 87d93f6978feb134ac13da6d80d29344c98e60ef Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 18:08:52 +0200 Subject: [PATCH 02/24] #include cleanup --- include/bmesensor.h | 5 ++++- include/button.h | 4 ++++ include/cyclic.h | 18 +----------------- include/globals.h | 38 -------------------------------------- include/irqhandler.h | 2 ++ include/led.h | 3 +-- include/ledmatrixdisplay.h | 1 + include/macsniff.h | 1 + include/main.h | 7 +++---- include/ota.h | 4 +++- include/payload.h | 4 ---- include/power.h | 1 + include/rcommand.h | 9 ++++----- include/reset.h | 4 ++++ include/rtctime.h | 5 +++-- include/sdcard.h | 3 ++- include/sds011read.h | 2 +- include/senddata.h | 10 +--------- include/spislave.h | 1 + include/timekeeper.h | 7 ------- include/vendor_array.h | 2 +- include/wifiscan.h | 12 ++++++++---- src/blecsan.cpp | 5 ++--- src/configmanager.cpp | 1 + src/gpsread.cpp | 1 + src/ledmatrixdisplay.cpp | 1 + src/macsniff.cpp | 1 + src/sensor.cpp | 1 + src/timekeeper.cpp | 1 - src/timesync.cpp | 6 +----- src/wifiscan.cpp | 2 -- 31 files changed, 54 insertions(+), 108 deletions(-) diff --git a/include/bmesensor.h b/include/bmesensor.h index b73a712a..d8ffaa7b 100644 --- a/include/bmesensor.h +++ b/include/bmesensor.h @@ -1,9 +1,12 @@ #ifndef _BMESENSOR_H #define _BMESENSOR_H -#include "globals.h" #include +#include "globals.h" +#include "irqhandler.h" +#include "configmanager.h" + #ifdef HAS_BME680 #include #elif defined HAS_BME280 diff --git a/include/button.h b/include/button.h index e7799847..fd6e046a 100644 --- a/include/button.h +++ b/include/button.h @@ -2,6 +2,10 @@ #define _BUTTON_H #include +#include "irqhandler.h" +#include "senddata.h" +#include "display.h" +#include "payload.h" void button_init(int pin); void readButton(); diff --git a/include/cyclic.h b/include/cyclic.h index ccadbb65..7d90d408 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -1,31 +1,15 @@ #ifndef _CYCLIC_H #define _CYCLIC_H +//#include #include "globals.h" #include "senddata.h" #include "rcommand.h" #include "spislave.h" - -#if(HAS_LORA) -#include -#endif - -#if (HAS_BME) #include "bmesensor.h" -#endif - -#ifdef HAS_DISPLAY #include "display.h" -#endif - -#if (HAS_SDS011) #include "sds011read.h" -#endif - -#if (HAS_SDCARD) #include "sdcard.h" -#endif - extern Ticker housekeeper; diff --git a/include/globals.h b/include/globals.h index d56998e3..c4ad3871 100644 --- a/include/globals.h +++ b/include/globals.h @@ -134,42 +134,4 @@ extern TimerHandle_t WifiChanTimer; extern Timezone myTZ; extern RTC_DATA_ATTR runmode_t RTC_runmode; -// application includes -#include "led.h" -#include "payload.h" -#include "blescan.h" -#include "power.h" - -#if (HAS_GPS) -#include "gpsread.h" -#endif - -#if (HAS_LORA) -#include "lorawan.h" -#endif - -#ifdef HAS_DISPLAY -#include "display.h" -#endif - -#ifdef HAS_MATRIX_DISPLAY -#include "ledmatrixdisplay.h" -#endif - -#ifdef HAS_BUTTON -#include "button.h" -#endif - -#ifdef HAS_ANTENNA_SWITCH -#include "antenna.h" -#endif - -#if (HAS_SENSORS) -#include "sensor.h" -#endif - -#if (HAS_BME) -#include "bmesensor.h" -#endif - #endif \ No newline at end of file diff --git a/include/irqhandler.h b/include/irqhandler.h index 193e32d5..04e62d93 100644 --- a/include/irqhandler.h +++ b/include/irqhandler.h @@ -13,11 +13,13 @@ #define PMU_IRQ 0x200 #include "globals.h" +#include "button.h" #include "cyclic.h" #include "senddata.h" #include "timekeeper.h" #include "bmesensor.h" #include "power.h" +#include "ledmatrixdisplay.h" void irqHandler(void *pvParameters); void mask_user_IRQ(); diff --git a/include/led.h b/include/led.h index de4d2227..1bc0ccde 100644 --- a/include/led.h +++ b/include/led.h @@ -1,9 +1,8 @@ #ifndef _LED_H #define _LED_H -#ifdef HAS_RGB_LED #include -#endif +#include "lorawan.h" // value for HSL color // see http://www.workwithcolor.com/blue-color-hue-range-01.htm diff --git a/include/ledmatrixdisplay.h b/include/ledmatrixdisplay.h index b2863146..9db9ebee 100644 --- a/include/ledmatrixdisplay.h +++ b/include/ledmatrixdisplay.h @@ -3,6 +3,7 @@ #include "LEDMatrix.h" #include "ledmatrixfonts.h" +#include "ledmatrixdisplay.h" extern uint8_t MatrixDisplayIsOn; diff --git a/include/macsniff.h b/include/macsniff.h index d41fc787..a04b7cc8 100644 --- a/include/macsniff.h +++ b/include/macsniff.h @@ -8,6 +8,7 @@ #include "hash.h" #include "senddata.h" #include "cyclic.h" +#include "led.h" #define MAC_SNIFF_WIFI 0 #define MAC_SNIFF_BLE 1 diff --git a/include/main.h b/include/main.h index 9037ccec..bc63ff4e 100644 --- a/include/main.h +++ b/include/main.h @@ -17,9 +17,8 @@ #include "ota.h" #include "irqhandler.h" #include "spislave.h" - -#if (HAS_LORA) +#include "sensor.h" #include "lorawan.h" -#endif #include "timekeeper.h" -#endif + +#endif \ No newline at end of file diff --git a/include/ota.h b/include/ota.h index cec28750..900ef530 100644 --- a/include/ota.h +++ b/include/ota.h @@ -4,7 +4,9 @@ #ifdef USE_OTA #include "globals.h" -#include +#include "led.h" +#include "display.h" + #include #include #include diff --git a/include/payload.h b/include/payload.h index 889c164d..9963ff02 100644 --- a/include/payload.h +++ b/include/payload.h @@ -1,11 +1,7 @@ #ifndef _PAYLOAD_H_ #define _PAYLOAD_H_ -#include "paxcounter.conf" - -#if (HAS_SDS011) #include "sds011read.h" -#endif // MyDevices CayenneLPP 1.0 channels for Synamic sensor payload format // all payload goes out on LoRa FPort 1 diff --git a/include/power.h b/include/power.h index 2db12da5..5e0ee363 100644 --- a/include/power.h +++ b/include/power.h @@ -4,6 +4,7 @@ #include #include #include + #include "i2c.h" #include "reset.h" diff --git a/include/rcommand.h b/include/rcommand.h index 2f6ae64f..488b7005 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -1,20 +1,19 @@ #ifndef _RCOMMAND_H #define _RCOMMAND_H +#include + #include "senddata.h" #include "cyclic.h" #include "configmanager.h" -#if(HAS_LORA) #include "lorawan.h" -#endif +#include "sensor.h" #include "macsniff.h" #include "wifiscan.h" -#include #include "cyclic.h" #include "timekeeper.h" -#if(TIME_SYNC_LORASERVER) #include "timesync.h" -#endif +#include "blescan.h" // table of remote commands and assigned functions typedef struct { diff --git a/include/reset.h b/include/reset.h index 533a79c1..be40bd3a 100644 --- a/include/reset.h +++ b/include/reset.h @@ -3,7 +3,11 @@ #include #include + #include "i2c.h" +#include "lorawan.h" +#include "display.h" +#include "power.h" void do_reset(bool warmstart); void do_after_reset(int reason); diff --git a/include/rtctime.h b/include/rtctime.h index 3429d44e..d4d64935 100644 --- a/include/rtctime.h +++ b/include/rtctime.h @@ -1,11 +1,12 @@ #ifndef _RTCTIME_H #define _RTCTIME_H -#include "globals.h" -#include "timekeeper.h" #include // must be included here so that Arduino library object file references work #include +#include "globals.h" +#include "timekeeper.h" + extern RtcDS3231 Rtc; // make RTC instance globally available uint8_t rtc_init(void); diff --git a/include/sdcard.h b/include/sdcard.h index 99e784cb..4323c6a3 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -3,10 +3,11 @@ #include #include - #include #include +#include "sds011read.h" + #define SDCARD_FILE_NAME "paxcount.%02d" #define SDCARD_FILE_HEADER "date, time, wifi, bluet" diff --git a/include/sds011read.h b/include/sds011read.h index 97307d1c..f49c34f0 100644 --- a/include/sds011read.h +++ b/include/sds011read.h @@ -1,8 +1,8 @@ #ifndef _SDS011READ_H #define _SDS011READ_H -#include "globals.h" #include +#include "globals.h" #define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25" diff --git a/include/senddata.h b/include/senddata.h index 5022800c..7be85016 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -3,18 +3,10 @@ #include "spislave.h" #include "cyclic.h" - -#if(HAS_LORA) +#include "sensor.h" #include "lorawan.h" -#endif - -#ifdef HAS_DISPLAY #include "display.h" -#endif - -#ifdef HAS_SDCARD #include "sdcard.h" -#endif extern Ticker sendcycler; diff --git a/include/spislave.h b/include/spislave.h index cf1db7a3..6db35d00 100644 --- a/include/spislave.h +++ b/include/spislave.h @@ -25,6 +25,7 @@ licenses. Refer to LICENSE.txt file in repository for more details. #define _SPISLAVE_H #include "globals.h" +#include "rcommand.h" esp_err_t spi_init(); diff --git a/include/timekeeper.h b/include/timekeeper.h index 7a98eb61..035cec6a 100644 --- a/include/timekeeper.h +++ b/include/timekeeper.h @@ -6,16 +6,9 @@ #include "TimeLib.h" #include "irqhandler.h" #include "timesync.h" - -#if (HAS_GPS) #include "gpsread.h" -#endif - -#ifdef HAS_IF482 #include "if482.h" -#elif defined HAS_DCF77 #include "dcf77.h" -#endif extern const char timeSetSymbols[]; extern Ticker timesyncer; diff --git a/include/vendor_array.h b/include/vendor_array.h index 76ee4618..b3bc7744 100644 --- a/include/vendor_array.h +++ b/include/vendor_array.h @@ -240,4 +240,4 @@ std::array vendors = { 0xb84fd5, 0xc0eefb, 0x206e9c, 0x6c2f2c, 0x18227e, 0x30c7ae, 0x501ac5, 0x6045bd, 0x1cb094, 0xe85b5b, 0x0025ae, 0x001dd8, 0x000a75, 0xa4c939, 0xc0dcda, 0x04b429, 0x48794d, -}; +}; \ No newline at end of file diff --git a/include/wifiscan.h b/include/wifiscan.h index 2e093cf8..88de6d26 100644 --- a/include/wifiscan.h +++ b/include/wifiscan.h @@ -3,13 +3,17 @@ // ESP32 Functions #include +#include +#include "coexist_internal.h" -// Hash function for scrambling MAC addresses -#include "hash.h" +#include "hash.h" // Hash function for scrambling MAC addresses +#include "antenna.h" // code for switching wifi antennas +#include "macsniff.h" void wifi_sniffer_init(void); -void switch_wifi_sniffer (uint8_t state); -void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); +void switch_wifi_sniffer(uint8_t state); +void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, + wifi_promiscuous_pkt_type_t type); void switchWifiChannel(TimerHandle_t xTimer); #endif \ No newline at end of file diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 90761f75..d305680e 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -1,6 +1,5 @@ -/* code snippets taken from -https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner -*/ +// some code snippets taken from +// https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include "blescan.h" diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 84f8e603..b4de1a56 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -1,6 +1,7 @@ /* configmanager persists runtime configuration using NVRAM of ESP32*/ #include "globals.h" +#include "configmanager.h" // Local logging tag static const char TAG[] = "flash"; diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 49a579f4..45f1b65d 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -1,6 +1,7 @@ #if (HAS_GPS) #include "globals.h" +#include "gpsread.h" // Local logging tag static const char TAG[] = __FILE__; diff --git a/src/ledmatrixdisplay.cpp b/src/ledmatrixdisplay.cpp index d31abf73..ad484e34 100644 --- a/src/ledmatrixdisplay.cpp +++ b/src/ledmatrixdisplay.cpp @@ -1,6 +1,7 @@ #ifdef HAS_MATRIX_DISPLAY #include "globals.h" +#include "ledmatrixdisplay.h" #define MATRIX_DISPLAY_PAGES (2) // number of display pages #define LINE_DIAGRAM_DIVIDER (2) // scales pax numbers to led rows diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 7307f345..213a0aff 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -1,6 +1,7 @@ // Basic Config #include "globals.h" +#include "macsniff.h #if (VENDORFILTER) #include "vendor_array.h" diff --git a/src/sensor.cpp b/src/sensor.cpp index 807e6f78..abed9b75 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -1,5 +1,6 @@ // Basic Config #include "globals.h" +#include "sensor.h" // Local logging tag static const char TAG[] = __FILE__; diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index df178dcb..6d8439ec 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -1,5 +1,4 @@ #include "timekeeper.h" -#include "paxcounter.conf" #if !(HAS_LORA) #if (TIME_SYNC_LORASERVER) diff --git a/src/timesync.cpp b/src/timesync.cpp index e50f4353..ce32d4e6 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -13,8 +13,6 @@ accept this. */ -#if (HAS_LORA) - #if (TIME_SYNC_LORASERVER) && (TIME_SYNC_LORAWAN) #error Duplicate timesync method selected. You must select either LORASERVER or LORAWAN timesync. #endif @@ -274,6 +272,4 @@ Exit: // inform processing task xTaskNotify(timeSyncProcTask, (rc ? rcv_seqNo : TIME_SYNC_END_FLAG), eSetBits); -} - -#endif // HAS_LORA \ No newline at end of file +} \ No newline at end of file diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 13e03e2b..6409298c 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -1,8 +1,6 @@ // Basic Config #include "globals.h" #include "wifiscan.h" -#include -#include "coexist_internal.h" // Local logging tag static const char TAG[] = "wifi"; From a90889dce332ab973f9896d87a4135871124f0a1 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 18:09:52 +0200 Subject: [PATCH 03/24] #include cleanup 2 --- include/cyclic.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/cyclic.h b/include/cyclic.h index 7d90d408..44c475e8 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -1,7 +1,6 @@ #ifndef _CYCLIC_H #define _CYCLIC_H -//#include #include "globals.h" #include "senddata.h" #include "rcommand.h" From 62c30a1684b05ff4cf31647d611cfe0be24ef2ca Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 18:11:24 +0200 Subject: [PATCH 04/24] #include cleanup 3 --- src/macsniff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 213a0aff..a64e49b1 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -1,7 +1,7 @@ // Basic Config #include "globals.h" -#include "macsniff.h +#include "macsniff.h" #if (VENDORFILTER) #include "vendor_array.h" From 7fcf93a655c23b8d21de5a36018b828195426524 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 19:41:33 +0200 Subject: [PATCH 05/24] M5 TFT display initial commit (experimental) --- include/display.h | 80 ++++++++++++------------ platformio.ini | 9 ++- src/display.cpp | 151 +++++++++++++++++++++++----------------------- src/hal/m5core.h | 46 +++++++++++--- src/hal/m5fire.h | 47 +++++++++++---- 5 files changed, 190 insertions(+), 143 deletions(-) diff --git a/include/display.h b/include/display.h index 26a04930..75f95eff 100644 --- a/include/display.h +++ b/include/display.h @@ -7,33 +7,57 @@ #if (HAS_DISPLAY) == 1 #include #elif (HAS_DISPLAY) == 2 -#include -#else -#error Unknown display type +#include #endif #define DISPLAY_PAGES (7) // number of paxcounter display pages -// settings for display library +// settings for OLED display library +#if (HAS_DISPLAY) == 1 +#define MY_FONT_SMALL FONT_SMALL +#define MY_FONT_NORMAL FONT_NORMAL +#define MY_FONT_LARGE FONT_LARGE +#define MY_FONT_STRETCHED FONT_STRETCHED #define USE_BACKBUFFER 1 - -// setup display hardware type, default is OLED 128x64 -#ifndef MY_DISPLAY_TYPE -#define MY_DISPLAY_TYPE OLED_128x64 -#endif - #ifdef MY_DISPLAY_ADDR #define OLED_ADDR MY_DISPLAY_ADDR #else #define OLED_ADDR -1 #endif -#ifndef MY_DISPLAY_INVERT -#define MY_DISPLAY_INVERT 0 -#endif - #ifndef USW_HW_I2C #define USE_HW_I2C 1 #endif +#ifndef OLED_FREQUENCY +#define OLED_FREQUENCY 400000L +#endif + +// settings for TFT display library +#elif (HAS_DISPLAY == 2) + +#define ESP32 + +#define MY_FONT_SMALL 1 +#define MY_FONT_NORMAL 2 +#define MY_FONT_LARGE 4 +#define MY_FONT_STRETCHED 6 + +#ifndef MY_DISPLAY_FGCOLOR +#define MY_DISPLAY_FGCOLOR TFT_WHITE +#endif +#ifndef MY_DISPLAY_BGCOLOR +#define MY_DISPLAY_BGCOLOR TFT_BLACK +#endif + +#endif + +// setup display hardware type, default is OLED 128x64 +#ifndef OLED_TYPE +#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 @@ -46,34 +70,6 @@ #define MY_DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 64X #endif -// some RGB color definitions -#define Black 0x0000 /* 0, 0, 0 */ -#define Navy 0x000F /* 0, 0, 128 */ -#define DarkGreen 0x03E0 /* 0, 128, 0 */ -#define DarkCyan 0x03EF /* 0, 128, 128 */ -#define Maroon 0x7800 /* 128, 0, 0 */ -#define Purple 0x780F /* 128, 0, 128 */ -#define Olive 0x7BE0 /* 128, 128, 0 */ -#define LightGrey 0xC618 /* 192, 192, 192 */ -#define DarkGrey 0x7BEF /* 128, 128, 128 */ -#define Blue 0x001F /* 0, 0, 255 */ -#define Green 0x07E0 /* 0, 255, 0 */ -#define Cyan 0x07FF /* 0, 255, 255 */ -#define Red 0xF800 /* 255, 0, 0 */ -#define Magenta 0xF81F /* 255, 0, 255 */ -#define Yellow 0xFFE0 /* 255, 255, 0 */ -#define White 0xFFFF /* 255, 255, 255 */ -#define Orange 0xFD20 /* 255, 165, 0 */ -#define GreenYellow 0xAFE5 /* 173, 255, 47 */ -#define Pink 0xF81F - -#ifndef MY_DISPLAY_FGCOLOR -#define MY_DISPLAY_FGCOLOR White -#endif -#ifndef MY_DISPLAY_BGCOLOR -#define MY_DISPLAY_BGCOLOR Black -#endif - // settings for qr code generator #define QR_VERSION 3 // 29 x 29px #define QR_SCALEFACTOR 2 // 29 -> 58x < 64px diff --git a/platformio.ini b/platformio.ini index 24b0b474..c47248c8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,7 +45,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.982 +release_version = 1.9.983 ; 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 @@ -56,15 +56,14 @@ lmicconfigfile = lmic_config.h platform_espressif32 = espressif32@1.12.0 monitor_speed = 115200 upload_speed = 115200 -;upload_port = COM9 lib_deps_lora = MCCI LoRaWAN LMIC library@>=3.1.0 ; MCCI LMIC by Terrill Moore lib_deps_display = - ;ss_oled@4.1.1 ; simple and small OLED lib by Larry Bank + ;ss_oled@4.1.2 ; simple and small OLED lib by Larry Bank https://github.com/bitbank2/ss_oled.git BitBang_I2C@2.0.1 QRCode@>=0.0.1 - bb_spi_lcd@1.1.0 ; LCD TFT driver lib by Larry Bank + TFT_eSPI lib_deps_matrix_display = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = @@ -112,7 +111,7 @@ framework = arduino board = esp32dev board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} -;upload_port = ${common.upload_port} +;upload_port = COM5 platform = ${common.platform_espressif32} lib_deps = ${common.lib_deps_all} build_flags = ${common.build_flags_all} diff --git a/src/display.cpp b/src/display.cpp index fd450a1b..6f132423 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -25,15 +25,16 @@ y = LMIC event message xx = payload sendqueue length ab = LMIC spread factor -FONT_SMALL: 6x8px = 21 chars / line -FONT_NORMAL: 8x8px = 16 chars / line -FONT_STRETCHED: 16x32px = 8 chars / line +MY_FONT_SMALL: 6x8px = 21 chars / line +MY_FONT_NORMAL: 8x8px = 16 chars / line +MY_FONT_STRETCHED: 16x32px = 8 chars / line */ // Basic Config -#include "globals.h" #include // needed for reading ESP32 chip attributes +#include "globals.h" +#include "display.h" // local Tag for logging static const char TAG[] = __FILE__; @@ -49,31 +50,33 @@ QRCode qrcode; #if (HAS_DISPLAY) == 1 SSOLED ssoled; +#elif (HAS_DISPLAY) == 2 +TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); // Invoke library #endif void dp_setup(int contrast) { -#if (HAS_DISPLAY) == 1 - int rc = oledInit(&ssoled, MY_DISPLAY_TYPE, OLED_ADDR, MY_DISPLAY_FLIP, - MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA, MY_DISPLAY_SCL, - MY_DISPLAY_RST, - 400000L); // use standard I2C bus at 400Khz +#if (HAS_DISPLAY) == 1 // I2C OLED + int rc = oledInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP, + MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA, + MY_DISPLAY_SCL, MY_DISPLAY_RST, + OLED_FREQUENCY); // use standard I2C bus at 400Khz assert(rc != OLED_NOT_FOUND); // set display buffer oledSetBackBuffer(&ssoled, displaybuf); -#elif (HAS_DISPLAY) == 2 +#elif (HAS_DISPLAY) == 2 // SPI TFT - int rc = - spilcdInit(MY_DISPLAY_TYPE, 0, MY_DISPLAY_INVERT, MY_DISPLAY_FLIP, 32000000, - MY_DISPLAY_CS, MY_DISPLAY_DC, MY_DISPLAY_RST, MY_DISPLAY_BL, - MY_DISPLAY_MISO, MY_DISPLAY_MOSI, MY_DISPLAY_CLK); + tft.init(); - assert(rc == 0); + if (MY_DISPLAY_FLIP) + tft.setRotation(0); + else + tft.setRotation(2); // portrait - // set display buffer - spilcdAllocBackbuffer(); + if (MY_DISPLAY_INVERT) + tft.invertDisplay(true); // Tell TFT to invert all displayed colours #endif @@ -85,10 +88,12 @@ void dp_setup(int contrast) { void dp_init(bool verbose) { +#if (HAS_DISPLAY) == 1 // i2c // block i2c bus access if (!I2C_MUTEX_LOCK()) ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { +#endif dp_setup(DISPLAYCONTRAST); @@ -131,10 +136,10 @@ void dp_init(bool verbose) { dp_printqr(3, 3, deveui); // display DEVEUI as plain text on the right - dp_printf(72, 0, FONT_NORMAL, 0, "LORAWAN"); - dp_printf(72, 1, FONT_NORMAL, 0, "DEVEUI:"); + dp_printf(72, 0, MY_FONT_NORMAL, 0, "LORAWAN"); + dp_printf(72, 1, MY_FONT_NORMAL, 0, "DEVEUI:"); for (uint8_t i = 0; i <= 3; i++) - dp_printf(80, i + 3, FONT_NORMAL, 0, "%4.4s", deveui + i * 4); + dp_printf(80, i + 3, MY_FONT_NORMAL, 0, "%4.4s", deveui + i * 4); // give user some time to read or take picture dp_dump(displaybuf); @@ -147,8 +152,11 @@ void dp_init(bool verbose) { dp_power(cfg.screenon); // set display off if disabled +#if (HAS_DISPLAY) == 1 // i2c I2C_MUTEX_UNLOCK(); // release i2c bus access } // mutex +#endif + } // dp_init void dp_refresh(bool nextPage) { @@ -205,7 +213,7 @@ void dp_drawPage(time_t t, bool nextpage) { #endif // line 1/2: pax counter - dp_printf(0, 0, FONT_STRETCHED, 0, "PAX:%-4d", + dp_printf(0, 0, MY_FONT_STRETCHED, 0, "PAX:%-4d", macs.size()); // display number of unique macs total Wifi + BLE start: @@ -231,64 +239,64 @@ start: // line 3: wifi + bluetooth counters #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) - dp_printf(0, 3, FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); + dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); else - dp_printf(0, 3, FONT_SMALL, 0, "%s", "WIFI:off"); + dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "WIFI:off"); if (cfg.blescan) - dp_printf(66, 3, FONT_SMALL, 0, "BLTH:%-5d", macs_ble); + dp_printf(66, 3, MY_FONT_SMALL, 0, "BLTH:%-5d", macs_ble); else - dp_printf(66, 3, FONT_SMALL, 0, "%s", "BLTH:off"); + dp_printf(66, 3, MY_FONT_SMALL, 0, "%s", "BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) - dp_printf(0, 3, FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); + dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); else - dp_printf(0, 3, FONT_SMALL, 0, "%s", "WIFI:off"); + dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "WIFI:off"); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) - dp_printf(0, 3, FONT_SMALL, 0, "BLTH:%-5d", macs_ble); + dp_printf(0, 3, MY_FONT_SMALL, 0, "BLTH:%-5d", macs_ble); else - dp_printf(0, 3, FONT_SMALL, 0, "%s", "BLTH:off"); + dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "BLTH:off"); #else - dp_printf(0, 3, FONT_SMALL, 0, "%s", "Sniffer disabled"); + dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "Sniffer disabled"); #endif // line 4: Battery + GPS status + Wifi channel #if (defined BAT_MEASURE_ADC || defined HAS_PMU) if (batt_voltage == 0xffff) - dp_printf(0, 4, FONT_SMALL, 0, "%s", "USB "); + dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "USB "); else if (batt_voltage == 0) - dp_printf(0, 4, FONT_SMALL, 0, "%s", "No batt"); + dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "No batt"); else - dp_printf(0, 4, FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0); + dp_printf(0, 4, MY_FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0); #endif #if (HAS_GPS) if (gps_hasfix()) - dp_printf(48, 4, FONT_SMALL, 0, "Sats:%.2d", gps.satellites.value()); + dp_printf(48, 4, MY_FONT_SMALL, 0, "Sats:%.2d", gps.satellites.value()); else // if no fix then display Sats value inverse - dp_printf(48, 4, FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value()); + dp_printf(48, 4, MY_FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value()); #endif - dp_printf(96, 4, FONT_SMALL, 0, "ch:%02d", channel); + dp_printf(96, 4, MY_FONT_SMALL, 0, "ch:%02d", channel); // line 5: RSSI limiter + free memory - dp_printf(0, 5, FONT_SMALL, 0, !cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", - cfg.rssilimit); - dp_printf(66, 5, FONT_SMALL, 0, "Mem:%4dKB", getFreeRAM() / 1024); + dp_printf(0, 5, MY_FONT_SMALL, 0, + !cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); + dp_printf(66, 5, MY_FONT_SMALL, 0, "Mem:%4dKB", getFreeRAM() / 1024); // line 6: time + date #if (TIME_SYNC_INTERVAL) timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource]; TimePulseTick = false; - dp_printf(0, 6, FONT_SMALL, 0, "%02d.%3s %4d", day(t), printmonth[month(t)], - year(t)); - dp_printf(72, 6, FONT_SMALL, 0, "%02d:%02d:%02d", hour(t), minute(t), + dp_printf(0, 6, MY_FONT_SMALL, 0, "%02d.%3s %4d", day(t), + printmonth[month(t)], year(t)); + dp_printf(72, 6, MY_FONT_SMALL, 0, "%02d:%02d:%02d", hour(t), minute(t), second(t)); // display inverse timeState if clock controller is enabled #if (defined HAS_DCF77) || (defined HAS_IF482) - dp_printf(120, 6, FONT_SMALL, 1, "%c", timeState); + dp_printf(120, 6, MY_FONT_SMALL, 1, "%c", timeState); #else - dp_printf(120, 6, FONT_SMALL, 0, "%c", timeState); + dp_printf(120, 6, MY_FONT_SMALL, 0, "%c", timeState); #endif #endif // TIME_SYNC_INTERVAL @@ -296,9 +304,9 @@ start: // line 7: LORA network status #if (HAS_LORA) // LMiC event display - dp_printf(0, 7, FONT_SMALL, 0, "%-16s", lmic_event_msg); + dp_printf(0, 7, MY_FONT_SMALL, 0, "%-16s", lmic_event_msg); // LORA datarate, display inverse if ADR disabled - dp_printf(102, 7, FONT_SMALL, !cfg.adrmode, "%-4s", + dp_printf(102, 7, MY_FONT_SMALL, !cfg.adrmode, "%-4s", getSfName(updr2rps(LMIC.datarate))); #endif // HAS_LORA break; // page0 @@ -314,19 +322,19 @@ start: if (gps_hasfix()) { // line 5: clear "No fix" if (wasnofix) { - dp_printf(16, 5, FONT_STRETCHED, 0, " "); + dp_printf(16, 5, MY_FONT_STRETCHED, 0, " "); wasnofix = false; } // line 3-4: GPS latitude - dp_printf(0, 3, FONT_STRETCHED, 0, "%c%07.4f", + dp_printf(0, 3, MY_FONT_STRETCHED, 0, "%c%07.4f", gps.location.rawLat().negative ? 'S' : 'N', gps.location.lat()); // line 6-7: GPS longitude - dp_printf(0, 6, FONT_STRETCHED, 0, "%c%07.4f", + dp_printf(0, 6, MY_FONT_STRETCHED, 0, "%c%07.4f", gps.location.rawLat().negative ? 'W' : 'E', gps.location.lng()); } else { - dp_printf(16, 5, FONT_STRETCHED, 1, "No fix"); + dp_printf(16, 5, MY_FONT_STRETCHED, 1, "No fix"); wasnofix = true; } break; // page2 @@ -338,17 +346,17 @@ start: case 3: #if (HAS_BME) // line 2-3: Temp - dp_printf(0, 2, FONT_STRETCHED, 0, "TMP:%-2.1f", bme_status.temperature); + dp_printf(0, 2, MY_FONT_STRETCHED, 0, "TMP:%-2.1f", bme_status.temperature); // line 4-5: Hum - dp_printf(0, 4, FONT_STRETCHED, 0, "HUM:%-2.1f", bme_status.humidity); + dp_printf(0, 4, MY_FONT_STRETCHED, 0, "HUM:%-2.1f", bme_status.humidity); #ifdef HAS_BME680 // line 6-7: IAQ - dp_printf(0, 6, FONT_STRETCHED, 0, "IAQ:%-3.0f", bme_status.iaq); + dp_printf(0, 6, MY_FONT_STRETCHED, 0, "IAQ:%-3.0f", bme_status.iaq); #else // is BME280 or BMP180 // line 6-7: Pre - dp_printf(0, 6, FONT_STRETCHED, 0, "PRE:%-2.1f", bme_status.pressure); + dp_printf(0, 6, MY_FONT_STRETCHED, 0, "PRE:%-2.1f", bme_status.pressure); #endif // HAS_BME680 break; // page 3 #else @@ -357,7 +365,7 @@ start: // page 4: time case 4: - dp_printf(0, 4, FONT_LARGE, 0, "%02d:%02d:%02d", hour(t), minute(t), + dp_printf(0, 4, MY_FONT_LARGE, 0, "%02d:%02d:%02d", hour(t), minute(t), second(t)); break; @@ -370,16 +378,16 @@ start: // 5|CHMsk:0000 Nonce:0000 // 6|CUp:000000 CDn:000000 // 7|SNR:-0000 RSSI:-0000 - dp_printf(0, 3, FONT_SMALL, 0, "NetwID:%06X TXpw:%-2d", + dp_printf(0, 3, MY_FONT_SMALL, 0, "NetwID:%06X TXpw:%-2d", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); - dp_printf(0, 4, FONT_SMALL, 0, "DevAdd:%08X DR:%1d", LMIC.devaddr, + dp_printf(0, 4, MY_FONT_SMALL, 0, "DevAdd:%08X DR:%1d", LMIC.devaddr, LMIC.datarate); - dp_printf(0, 5, FONT_SMALL, 0, "ChMsk:%04X Nonce:%04X", LMIC.channelMap, + dp_printf(0, 5, MY_FONT_SMALL, 0, "ChMsk:%04X Nonce:%04X", LMIC.channelMap, LMIC.devNonce); - dp_printf(0, 6, FONT_SMALL, 0, "fUp:%-6d fDn:%-6d", + dp_printf(0, 6, MY_FONT_SMALL, 0, "fUp:%-6d fDn:%-6d", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); - dp_printf(0, 7, FONT_SMALL, 0, "SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, + dp_printf(0, 7, MY_FONT_SMALL, 0, "SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); break; // page5 #else // don't show blank page if we are unattended @@ -429,14 +437,7 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, #if (HAS_DISPLAY) == 1 oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); #elif (HAS_DISPLAY) == 2 - /* - if (font = 0 || font == 1) - spilcdWriteStringFast(x, y, temp, MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR, - font); - else - */ - spilcdWriteString(x, y, temp, MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR, font, - 1); + tft.drawString(temp, x, y, font); #endif if (temp != loc_buf) { free(temp); @@ -447,7 +448,7 @@ void dp_dump(uint8_t *pBuffer) { #if (HAS_DISPLAY) == 1 oledDumpBuffer(&ssoled, pBuffer); #elif (HAS_DISPLAY) == 2 - spilcdShowBuffer(0, 0, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); + // no buffered rendering for TFT #endif } @@ -455,8 +456,7 @@ void dp_clear() { #if (HAS_DISPLAY) == 1 oledFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 - spilcdFill(0, 1); - spilcdScrollReset(); + tft.fillScreen(TFT_WHITE); #endif } @@ -464,7 +464,7 @@ void dp_contrast(uint8_t contrast) { #if (HAS_DISPLAY) == 1 oledSetContrast(&ssoled, contrast); #elif (HAS_DISPLAY) == 2 - // to come + // no contrast setting for TFT #endif } @@ -483,13 +483,12 @@ void dp_shutdown(void) { ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { cfg.screenon = 0; - oledShutdown(&ssoled); + oledPower(&ssoled, false); delay(DISPLAYREFRESH_MS / 1000 * 1.1); I2C_MUTEX_UNLOCK(); // release i2c bus access } #elif (HAS_DISPLAY) == 2 - spilcdShutdown(); - spilcdFreeBackbuffer(); + // to come #endif } @@ -522,7 +521,7 @@ void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, for (uint16_t xi = x; xi < x + width; xi++) oledDrawLine(&ssoled, xi, y, xi, y + height - 1, bRender); #elif (HAS_DISPLAY) == 2 - spilcdRectangle(x, y, width, height, MY_DISPLAY_BGCOLOR, MY_DISPLAY_FGCOLOR, 1, 1); + tft.drawRect(x, y, width, height, MY_DISPLAY_FGCOLOR); #endif } diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 920908b7..bb6b28c4 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -32,7 +32,7 @@ #define BOARD_HAS_PSRAM // use if board has external PSRAM #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 HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet //#define MY_DISPLAY_FLIP 1 // use if display is rotated //#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board @@ -45,13 +45,41 @@ #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! -// Pins for interface of LC Display -#define MY_DISPLAY_CS GPIO_NUM_14 -#define MY_DISPLAY_DC GPIO_NUM_27 -#define MY_DISPLAY_CLK GPIO_NUM_18 -#define MY_DISPLAY_RST GPIO_NUM_33 -#define MY_DISPLAY_BL GPIO_NUM_32 -#define MY_DISPLAY_MOSI GPIO_NUM_23 -#define MY_DISPLAY_MISO GPIO_NUM_19 +// Display Settings +#define MY_DISPLAY_WIDTH 320 +#define MY_DISPLAY_HEIGHT 240 +#define MY_DISPLAY_INVERT 1 + +// setting for M5 display +#define ILI9341_DRIVER +#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 USE_HSPI_PORT +#define TFT_SDA_READ +#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +//#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 27000000 + +// Optional reduced SPI frequency for reading TFT +#define SPI_READ_FREQUENCY 5000000 #endif \ No newline at end of file diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 3adf4e1d..a82e8583 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -7,7 +7,7 @@ #include -#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no M5 RA01 LoRa module +//#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no M5 RA01 LoRa module #define LORA_SCK SCK #define LORA_CS SS #define LORA_MISO MISO @@ -19,7 +19,7 @@ // 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 HAS_SDCARD 1 // this board has an SD-card-reader/writer #define SDCARD_CS GPIO_NUM_4 #define SDCARD_MOSI MOSI #define SDCARD_MISO MISO @@ -32,7 +32,7 @@ #define BOARD_HAS_PSRAM // use if board has external PSRAM #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 HAS_DISPLAY 2 // TFT-LCD, support work in progess, not ready yet //#define MY_DISPLAY_FLIP 1 // use if display is rotated //#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board @@ -49,13 +49,38 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_TYPE LCD_ILI9341 -#define MY_DISPLAY_CS GPIO_NUM_14 // Display CS pin -#define MY_DISPLAY_CLK GPIO_NUM_18 // SPI CLOCK pin -#define MY_DISPLAY_DC GPIO_NUM_27 // Display command/data pin -#define MY_DISPLAY_MOSI GPIO_NUM_23 // SPI MOSI -#define MY_DISPLAY_MISO GPIO_NUM_19 // SPI MISO -#define MY_DISPLAY_BL GPIO_NUM_32 // backlight control -#define MY_DISPLAY_RST GPIO_NUM_33 // RESET control +#define MY_DISPLAY_INVERT 1 + +// setting for M5 display +#define ILI9341_DRIVER +#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 USE_HSPI_PORT +#define TFT_SDA_READ +#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +//#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 27000000 + +// Optional reduced SPI frequency for reading TFT +#define SPI_READ_FREQUENCY 5000000 #endif \ No newline at end of file From bb0f1fd10a7d3b37d08834f688da48d29e83367e Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 19:58:50 +0200 Subject: [PATCH 06/24] M5 hal files corrections --- src/hal/m5core.h | 2 +- src/hal/m5fire.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hal/m5core.h b/src/hal/m5core.h index bb6b28c4..55d0b0fc 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -51,7 +51,7 @@ #define MY_DISPLAY_INVERT 1 // setting for M5 display -#define ILI9341_DRIVER +#define ILI9341_DRIVER 1 #define M5STACK // needed for TFT driver #define TFT_MISO MISO // SPI diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index a82e8583..53e962df 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -7,7 +7,7 @@ #include -//#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no M5 RA01 LoRa module +#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no M5 RA01 LoRa module #define LORA_SCK SCK #define LORA_CS SS #define LORA_MISO MISO @@ -19,7 +19,7 @@ // 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 HAS_SDCARD 1 // this board has an SD-card-reader/writer #define SDCARD_CS GPIO_NUM_4 #define SDCARD_MOSI MOSI #define SDCARD_MISO MISO @@ -52,7 +52,7 @@ #define MY_DISPLAY_INVERT 1 // setting for M5 display -#define ILI9341_DRIVER +#define ILI9341_DRIVER 1 #define M5STACK // needed for TFT driver #define TFT_MISO MISO // SPI From e2af3e095111ed9389483fd20fde30dc4560f385 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 20:08:30 +0200 Subject: [PATCH 07/24] M5 TFT display support (experimental) --- platformio.ini | 6 ++++-- src/hal/m5core.h | 1 - src/hal/m5fire.h | 10 ++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index c47248c8..f2d0801e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,7 @@ ; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -halfile = generic.h +;halfile = generic.h ;halfile = ebox.h ;halfile = eboxtube.h ;halfile = ecopower.h @@ -32,7 +32,7 @@ halfile = generic.h ;halfile = tinypico.h ;halfile = tinypicomatrix.h ;halfile = m5core.h -;halfile = m5fire.h +halfile = m5fire.h [platformio] ; upload firmware to board with usb cable @@ -98,6 +98,8 @@ build_flags_basic = '-DCORE_DEBUG_LEVEL=${common.debug_level}' '-DLOG_LOCAL_LEVEL=${common.debug_level}' '-DPROGVERSION="${common.release_version}"' + '-DUSER_SETUP_LOADED=1' + build_flags_sensors = -Llib/Bosch-BSEC/src/esp32/ -lalgobsec diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 55d0b0fc..d70839ea 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -48,7 +48,6 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 53e962df..0c110328 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -49,7 +49,6 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 -#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 @@ -63,9 +62,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light -//#define USE_HSPI_PORT -#define TFT_SDA_READ -#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue //#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 @@ -78,9 +75,6 @@ #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 - -// Optional reduced SPI frequency for reading TFT -#define SPI_READ_FREQUENCY 5000000 +#define SPI_FREQUENCY 40000000 #endif \ No newline at end of file From 2f8301d36a9eb4f63f345403ffc1624fbb958bad Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 29 Mar 2020 23:05:42 +0200 Subject: [PATCH 08/24] M5 display support (experimental) --- include/display.h | 2 -- platformio.ini | 4 ++-- src/display.cpp | 33 +++++++++++++++++++++++---------- src/hal/m5core.h | 11 +++-------- src/hal/m5fire.h | 4 ++-- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/display.h b/include/display.h index 75f95eff..f7c66407 100644 --- a/include/display.h +++ b/include/display.h @@ -34,8 +34,6 @@ // settings for TFT display library #elif (HAS_DISPLAY == 2) -#define ESP32 - #define MY_FONT_SMALL 1 #define MY_FONT_NORMAL 2 #define MY_FONT_LARGE 4 diff --git a/platformio.ini b/platformio.ini index f2d0801e..5dffe51b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,7 +63,7 @@ lib_deps_display = https://github.com/bitbank2/ss_oled.git BitBang_I2C@2.0.1 QRCode@>=0.0.1 - TFT_eSPI + TFT_eSPI@>=2.1.9 lib_deps_matrix_display = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = @@ -98,7 +98,7 @@ build_flags_basic = '-DCORE_DEBUG_LEVEL=${common.debug_level}' '-DLOG_LOCAL_LEVEL=${common.debug_level}' '-DPROGVERSION="${common.release_version}"' - '-DUSER_SETUP_LOADED=1' + '-DUSER_SETUP_LOADED=1' ; needed for TFT_eSPI library build_flags_sensors = -Llib/Bosch-BSEC/src/esp32/ diff --git a/src/display.cpp b/src/display.cpp index 6f132423..4a640ba1 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -51,7 +51,7 @@ QRCode qrcode; #if (HAS_DISPLAY) == 1 SSOLED ssoled; #elif (HAS_DISPLAY) == 2 -TFT_eSPI tft = TFT_eSPI(MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT); // Invoke library +TFT_eSPI tft = TFT_eSPI(); #endif void dp_setup(int contrast) { @@ -70,13 +70,9 @@ void dp_setup(int contrast) { tft.init(); - if (MY_DISPLAY_FLIP) - tft.setRotation(0); - else - tft.setRotation(2); // portrait - - if (MY_DISPLAY_INVERT) - tft.invertDisplay(true); // Tell TFT to invert all displayed colours + tft.setRotation(MY_DISPLAY_FLIP ? true : false); + tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); + tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); #endif @@ -437,7 +433,24 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, #if (HAS_DISPLAY) == 1 oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); #elif (HAS_DISPLAY) == 2 - tft.drawString(temp, x, y, font); + uint8_t myfont; + switch (font) { + case MY_FONT_SMALL: + myfont = 6; + break; + case MY_FONT_NORMAL: + case MY_FONT_LARGE: + myfont = 8; + break; + case MY_FONT_STRETCHED: + myfont = 16; + break; + default: + myfont = 8; + } + tft.drawString(temp, x * tft.textWidth("_", font) / myfont, + y * tft.fontHeight(font), font); + #endif if (temp != loc_buf) { free(temp); @@ -456,7 +469,7 @@ void dp_clear() { #if (HAS_DISPLAY) == 1 oledFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 - tft.fillScreen(TFT_WHITE); + tft.fillScreen(MY_DISPLAY_BGCOLOR); #endif } diff --git a/src/hal/m5core.h b/src/hal/m5core.h index d70839ea..06df0a0e 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -48,6 +48,7 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 +#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 @@ -61,10 +62,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light -//#define USE_HSPI_PORT -#define TFT_SDA_READ -#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue -//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red +#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 @@ -76,9 +74,6 @@ #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 - -// Optional reduced SPI frequency for reading TFT -#define SPI_READ_FREQUENCY 5000000 +#define SPI_FREQUENCY 40000000 #endif \ No newline at end of file diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index 0c110328..bb9c8229 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -49,6 +49,7 @@ // Display Settings #define MY_DISPLAY_WIDTH 320 #define MY_DISPLAY_HEIGHT 240 +#define MY_DISPLAY_INVERT 1 // setting for M5 display #define ILI9341_DRIVER 1 @@ -62,8 +63,7 @@ #define TFT_RST GPIO_NUM_33 // Reset #define TFT_BL GPIO_NUM_32 // LED back-light -//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue -//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red +#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 From 0de6d61e262137374f10249ad41a243365ebbbd1 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 1 Apr 2020 15:12:48 +0200 Subject: [PATCH 09/24] bugfix ttgov21new.h (issue #583) --- src/hal/ttgov21new.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index 1d95d8fe..309acd2d 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -29,9 +29,9 @@ #define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board // Pins for I2C interface of OLED Display -#define MY_OLED_SDA (21) -#define MY_OLED_SCL (22) -#define MY_OLED_RST NOT_A_PIN +#define MY_DISPLAY_SDA (21) +#define MY_DISPLAY_SCL (22) +#define MY_DISPLAY_RST NOT_A_PIN // Pins for LORA chip SPI interface, reset line and interrupt lines #define LORA_SCK (5) From 07d5b18cc17fd97fdf03ea02c1223bd4620f100b Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 3 Apr 2020 18:33:05 +0200 Subject: [PATCH 10/24] payload.cpp: sanitized --- src/payload.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/payload.cpp b/src/payload.cpp index 10c04ddc..7517e9d5 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -333,19 +333,22 @@ void PayloadConvert::addSDS(sdsStatus_t sds) { #if (HAS_SDS011) // value of PM10 #if (PAYLOAD_ENCODER == 3) // Cayenne LPP dynamic - buffer[cursor++] = LPP_PARTMATTER10_CHANNEL; // for PM10 + buffer[cursor++] = LPP_PARTMATTER10_CHANNEL; // for PM10 #endif - buffer[cursor++] = LPP_LUMINOSITY; // workaround since cayenne has no data type meter - buffer[cursor++] = highByte((uint16_t)(sds.pm10 * 10)); - buffer[cursor++] = lowByte((uint16_t)(sds.pm10 * 10)); + buffer[cursor++] = + LPP_LUMINOSITY; // workaround since cayenne has no data type meter + buffer[cursor++] = highByte((uint16_t)(sds.pm10 * 10)); + buffer[cursor++] = lowByte((uint16_t)(sds.pm10 * 10)); // value of PM2.5 #if (PAYLOAD_ENCODER == 3) // Cayenne LPP dynamic - buffer[cursor++] = LPP_PARTMATTER25_CHANNEL; // for PM2.5 + buffer[cursor++] = LPP_PARTMATTER25_CHANNEL; // for PM2.5 #endif - buffer[cursor++] = LPP_LUMINOSITY; // workaround since cayenne has no data type meter - buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10)); - buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10)); -#endif // HAS_SDS011 + buffer[cursor++] = + LPP_LUMINOSITY; // workaround since cayenne has no data type meter + buffer[cursor++] = highByte((uint16_t)(sds.pm25 * 10)); + buffer[cursor++] = lowByte((uint16_t)(sds.pm25 * 10)); +#endif // HAS_SDS011 +} void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) { switch (snifftype) { From 70d836d2f695797455fb628adeba0e44e697b03c Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 5 Apr 2020 18:19:39 +0200 Subject: [PATCH 11/24] M5stack display support (experimental) --- platformio.ini | 9 ++++----- src/display.cpp | 29 ++++++++++++++++------------- src/hal/m5core.h | 10 +++++----- src/hal/m5fire.h | 10 +++++----- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5dffe51b..661a5c4b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,7 +45,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.9.983 +release_version = 1.9.984 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 3 @@ -59,11 +59,10 @@ upload_speed = 115200 lib_deps_lora = MCCI LoRaWAN LMIC library@>=3.1.0 ; MCCI LMIC by Terrill Moore lib_deps_display = - ;ss_oled@4.1.2 ; simple and small OLED lib by Larry Bank - https://github.com/bitbank2/ss_oled.git - BitBang_I2C@2.0.1 + ss_oled@4.1.2 ; simple and small OLED lib by Larry Bank + BitBang_I2C@2.0.2 QRCode@>=0.0.1 - TFT_eSPI@>=2.1.9 + TFT_eSPI@>=2.2.0 lib_deps_matrix_display = Ultrathin_LED_Matrix@>=1.0.0 lib_deps_rgbled = diff --git a/src/display.cpp b/src/display.cpp index 4a640ba1..3c79a874 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -70,7 +70,7 @@ void dp_setup(int contrast) { tft.init(); - tft.setRotation(MY_DISPLAY_FLIP ? true : false); + tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); @@ -433,23 +433,26 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, #if (HAS_DISPLAY) == 1 oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); #elif (HAS_DISPLAY) == 2 - uint8_t myfont; + uint8_t tft_font, font_vScale; + // map font oled -> tft switch (font) { - case MY_FONT_SMALL: - myfont = 6; + case MY_FONT_STRETCHED: // 16x16 on OLED + case MY_FONT_LARGE: // 16x32 on OLED + tft_font = 4; // 26px + font_vScale = 26; break; - case MY_FONT_NORMAL: - case MY_FONT_LARGE: - myfont = 8; - break; - case MY_FONT_STRETCHED: - myfont = 16; + case MY_FONT_SMALL: // 6x8 on OLED + case MY_FONT_NORMAL: // 8x8 on OLED + tft_font = 2; // 16px + font_vScale = 16; break; default: - myfont = 8; + tft_font = 2; // 16px + font_vScale = 16; } - tft.drawString(temp, x * tft.textWidth("_", font) / myfont, - y * tft.fontHeight(font), font); + + tft.setCursor(x, y * font_vScale, tft_font); + tft.printf(temp); #endif if (temp != loc_buf) { diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 06df0a0e..10ff0ca6 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -64,14 +64,14 @@ #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_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_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 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 diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index bb9c8229..bb9fc848 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -65,14 +65,14 @@ #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_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_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 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 From a56c5341954a81054cae0bf66c4f666350d3aa91 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 5 Apr 2020 23:01:39 +0200 Subject: [PATCH 12/24] M5stack display support (experimental) --- include/display.h | 6 ++- src/display.cpp | 117 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 87 insertions(+), 36 deletions(-) diff --git a/include/display.h b/include/display.h index f7c66407..e82dad75 100644 --- a/include/display.h +++ b/include/display.h @@ -69,8 +69,8 @@ #endif // settings for qr code generator -#define QR_VERSION 3 // 29 x 29px -#define QR_SCALEFACTOR 2 // 29 -> 58x < 64px +#define QR_VERSION 3 // 29 x 29px +#define QR_SCALEFACTOR MY_DISPLAY_HEIGHT / (29 + 4) // 4px borderlines extern uint8_t DisplayIsOn, displaybuf[]; @@ -79,9 +79,11 @@ void dp_refresh(bool nextPage = false); void dp_init(bool verbose = false); void dp_shutdown(void); void dp_drawPage(time_t t, bool nextpage); +void dp_println(void); void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, const char *format, ...); void dp_dump(uint8_t *pBuffer); +void dp_setCursor(int x, int y); 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 3c79a874..7b8ce3bc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,8 +11,8 @@ Display-Mask (128 x 64 pixel): 0|PAX:aabbccdd STRETCHED 1|PAX:aabbccdd STRETCHED 2| -3|B:a.bcV Sats:ab ch:ab SMALL -4|WIFI:abcde BLTH:abcde SMALL +3|WIFI:abcde BLTH:abcde SMALL +4|B:a.bcV Sats:ab ch:ab SMALL 5|RLIM:abcd Mem:abcdKB SMALL 6|27.Feb 2019 20:27:00* SMALL 7|yyyyyyyyyyyyy xx SFab SMALL @@ -65,11 +65,11 @@ void dp_setup(int contrast) { // set display buffer oledSetBackBuffer(&ssoled, displaybuf); + oledSetTextWrap(&&ssoled, true); #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); @@ -132,10 +132,17 @@ void dp_init(bool verbose) { dp_printqr(3, 3, deveui); // display DEVEUI as plain text on the right - dp_printf(72, 0, MY_FONT_NORMAL, 0, "LORAWAN"); - dp_printf(72, 1, MY_FONT_NORMAL, 0, "DEVEUI:"); - for (uint8_t i = 0; i <= 3; i++) - dp_printf(80, i + 3, MY_FONT_NORMAL, 0, "%4.4s", deveui + i * 4); + const int x_offset = QR_SCALEFACTOR * 29 + 20; + dp_setCursor(x_offset, 1); + dp_printf(x_offset, 1, MY_FONT_NORMAL, 0, "DEVEUI:"); + for (uint8_t i = 0; i <= 3; i++) { +#if (HAS_DISPLAY) == 1 + dp_setCursor(x_offset, i + 3); +#elif (HAS_DISPLAY) == 2 + dp_setCursor(x_offset, 2 * (i + 3)); +#endif + dp_printf(x_offset, i + 3, MY_FONT_NORMAL, 0, "%4.4s", deveui + i * 4); + } // give user some time to read or take picture dp_dump(displaybuf); @@ -208,10 +215,6 @@ void dp_drawPage(time_t t, bool nextpage) { static bool wasnofix = true; #endif - // line 1/2: pax counter - dp_printf(0, 0, MY_FONT_STRETCHED, 0, "PAX:%-4d", - macs.size()); // display number of unique macs total Wifi + BLE - start: if (nextpage) { @@ -219,6 +222,16 @@ start: dp_clear(); } + // cursor home + dp_setCursor(0, 0); + + // line 1/2: pax counter + if (DisplayPage < 6) { + dp_printf(0, 0, MY_FONT_STRETCHED, 0, "PAX:%-4d", + macs.size()); // display number of unique macs total Wifi + BLE + dp_println(); + } + switch (DisplayPage) { // page 0: parameters overview @@ -233,15 +246,17 @@ start: case 0: // line 3: wifi + bluetooth counters + // WIFI:abcde BLTH:abcde + #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); else dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "WIFI:off"); if (cfg.blescan) - dp_printf(66, 3, MY_FONT_SMALL, 0, "BLTH:%-5d", macs_ble); + dp_printf(66, 3, MY_FONT_SMALL, 0, " BLTH:%-5d", macs_ble); else - dp_printf(66, 3, MY_FONT_SMALL, 0, "%s", "BLTH:off"); + dp_printf(66, 3, MY_FONT_SMALL, 0, "%s", " BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); @@ -255,8 +270,10 @@ start: #else dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "Sniffer disabled"); #endif + dp_println(); // line 4: Battery + GPS status + Wifi channel +// B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU) if (batt_voltage == 0xffff) dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "USB "); @@ -264,28 +281,38 @@ start: dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "No batt"); else dp_printf(0, 4, MY_FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0); +#else + dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", " "); #endif #if (HAS_GPS) if (gps_hasfix()) - dp_printf(48, 4, MY_FONT_SMALL, 0, "Sats:%.2d", gps.satellites.value()); + dp_printf(48, 4, MY_FONT_SMALL, 0, " Sats:%.2d", gps.satellites.value()); else // if no fix then display Sats value inverse - dp_printf(48, 4, MY_FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value()); + dp_printf(48, 4, MY_FONT_SMALL, 1, " Sats:%.2d", gps.satellites.value()); +#else + dp_printf(48, 4, MY_FONT_SMALL, 0, "%s", " "); #endif - dp_printf(96, 4, MY_FONT_SMALL, 0, "ch:%02d", channel); + dp_printf(96, 4, MY_FONT_SMALL, 0, " ch:%02d", channel); + dp_println(); // line 5: RSSI limiter + free memory + // RLIM:abcd Mem:abcdKB + dp_printf(0, 5, MY_FONT_SMALL, 0, !cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); - dp_printf(66, 5, MY_FONT_SMALL, 0, "Mem:%4dKB", getFreeRAM() / 1024); + dp_printf(66, 5, MY_FONT_SMALL, 0, " Mem:%4dKB", getFreeRAM() / 1024); + dp_println(); // line 6: time + date + // 27.Feb 2019 20:27:00* + #if (TIME_SYNC_INTERVAL) timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource]; TimePulseTick = false; dp_printf(0, 6, MY_FONT_SMALL, 0, "%02d.%3s %4d", day(t), printmonth[month(t)], year(t)); - dp_printf(72, 6, MY_FONT_SMALL, 0, "%02d:%02d:%02d", hour(t), minute(t), + dp_printf(72, 6, MY_FONT_SMALL, 0, " %02d:%02d:%02d", hour(t), minute(t), second(t)); // display inverse timeState if clock controller is enabled @@ -294,16 +321,19 @@ start: #else dp_printf(120, 6, MY_FONT_SMALL, 0, "%c", timeState); #endif - + dp_println(); #endif // TIME_SYNC_INTERVAL // line 7: LORA network status + // yyyyyyyyyyyyy xx SFab + #if (HAS_LORA) // LMiC event display dp_printf(0, 7, MY_FONT_SMALL, 0, "%-16s", lmic_event_msg); // LORA datarate, display inverse if ADR disabled - dp_printf(102, 7, MY_FONT_SMALL, !cfg.adrmode, "%-4s", + dp_printf(102, 7, MY_FONT_SMALL, !cfg.adrmode, " %-4s", getSfName(updr2rps(LMIC.datarate))); + dp_println(); #endif // HAS_LORA break; // page0 @@ -376,13 +406,17 @@ start: // 7|SNR:-0000 RSSI:-0000 dp_printf(0, 3, MY_FONT_SMALL, 0, "NetwID:%06X TXpw:%-2d", LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); + dp_println(); dp_printf(0, 4, MY_FONT_SMALL, 0, "DevAdd:%08X DR:%1d", LMIC.devaddr, LMIC.datarate); + dp_println(); dp_printf(0, 5, MY_FONT_SMALL, 0, "ChMsk:%04X Nonce:%04X", LMIC.channelMap, LMIC.devNonce); + dp_println(); dp_printf(0, 6, MY_FONT_SMALL, 0, "fUp:%-6d fDn:%-6d", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); + dp_println(); dp_printf(0, 7, MY_FONT_SMALL, 0, "SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); break; // page5 @@ -407,6 +441,23 @@ start: } // dp_drawPage // display helper functions + +void dp_setCursor(int x, int y) { +#if (HAS_DISPLAY) == 1 + oledSetCursor(&ssoled, x, y); +#elif (HAS_DISPLAY) == 2 + tft.setCursor(x, y * 8); +#endif +} + +void dp_println(void) { +#if (HAS_DISPLAY) == 1 + // to come +#elif (HAS_DISPLAY) == 2 + tft.println(); +#endif +}; + void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, const char *format, ...) { char loc_buf[64]; @@ -427,31 +478,27 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, va_end(arg); return; } - len = vsnprintf(temp, len + 1, format, arg); + vsnprintf(temp, len + 1, format, arg); } va_end(arg); #if (HAS_DISPLAY) == 1 oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); #elif (HAS_DISPLAY) == 2 - uint8_t tft_font, font_vScale; // map font oled -> tft + uint8_t tft_font; switch (font) { case MY_FONT_STRETCHED: // 16x16 on OLED case MY_FONT_LARGE: // 16x32 on OLED tft_font = 4; // 26px - font_vScale = 26; break; case MY_FONT_SMALL: // 6x8 on OLED case MY_FONT_NORMAL: // 8x8 on OLED - tft_font = 2; // 16px - font_vScale = 16; - break; default: tft_font = 2; // 16px - font_vScale = 16; + break; } - tft.setCursor(x, y * font_vScale, tft_font); + tft.setTextFont(tft_font); tft.printf(temp); #endif @@ -464,14 +511,16 @@ void dp_dump(uint8_t *pBuffer) { #if (HAS_DISPLAY) == 1 oledDumpBuffer(&ssoled, pBuffer); #elif (HAS_DISPLAY) == 2 - // no buffered rendering for TFT + // to do: buffered rendering for TFT #endif } -void dp_clear() { +void dp_clear(void) { #if (HAS_DISPLAY) == 1 + oledSetCursor(&ssoled, 0, 0); oledFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 + tft.setCursor(0, 0); tft.fillScreen(MY_DISPLAY_BGCOLOR); #endif } @@ -480,7 +529,7 @@ void dp_contrast(uint8_t contrast) { #if (HAS_DISPLAY) == 1 oledSetContrast(&ssoled, contrast); #elif (HAS_DISPLAY) == 2 - // no contrast setting for TFT + // to do: gamma correction for TFT #endif } @@ -513,8 +562,8 @@ void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { qrcode_initText(&qrcode, qrcodeData, QR_VERSION, ECC_HIGH, Message); // draw QR code - for (uint16_t y = 0; y < qrcode.size; y++) - for (uint16_t x = 0; x < qrcode.size; x++) + 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, @@ -537,7 +586,7 @@ void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, for (uint16_t xi = x; xi < x + width; xi++) oledDrawLine(&ssoled, xi, y, xi, y + height - 1, bRender); #elif (HAS_DISPLAY) == 2 - tft.drawRect(x, y, width, height, MY_DISPLAY_FGCOLOR); + tft.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR); #endif } From 2d45c599bdb555fd603ea4cb933048724bd40f3f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 5 Apr 2020 23:22:31 +0200 Subject: [PATCH 13/24] M5stack display support (experimental) --- platformio.ini | 6 ++---- src/display.cpp | 2 +- src/hal/m5core.h | 1 + src/hal/m5fire.h | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index 661a5c4b..306ec661 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,7 @@ ; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -;halfile = generic.h +halfile = generic.h ;halfile = ebox.h ;halfile = eboxtube.h ;halfile = ecopower.h @@ -32,7 +32,7 @@ ;halfile = tinypico.h ;halfile = tinypicomatrix.h ;halfile = m5core.h -halfile = m5fire.h +;halfile = m5fire.h [platformio] ; upload firmware to board with usb cable @@ -97,8 +97,6 @@ build_flags_basic = '-DCORE_DEBUG_LEVEL=${common.debug_level}' '-DLOG_LOCAL_LEVEL=${common.debug_level}' '-DPROGVERSION="${common.release_version}"' - '-DUSER_SETUP_LOADED=1' ; needed for TFT_eSPI library - build_flags_sensors = -Llib/Bosch-BSEC/src/esp32/ -lalgobsec diff --git a/src/display.cpp b/src/display.cpp index 7b8ce3bc..ac482ec5 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -65,7 +65,7 @@ void dp_setup(int contrast) { // set display buffer oledSetBackBuffer(&ssoled, displaybuf); - oledSetTextWrap(&&ssoled, true); + oledSetTextWrap(&ssoled, true); #elif (HAS_DISPLAY) == 2 // SPI TFT diff --git a/src/hal/m5core.h b/src/hal/m5core.h index 10ff0ca6..0d6c4496 100644 --- a/src/hal/m5core.h +++ b/src/hal/m5core.h @@ -51,6 +51,7 @@ #define MY_DISPLAY_INVERT 1 // setting for M5 display +#define USER_SETUP_LOADED 1 #define ILI9341_DRIVER 1 #define M5STACK // needed for TFT driver diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index bb9fc848..ff4e196b 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -52,6 +52,7 @@ #define MY_DISPLAY_INVERT 1 // setting for M5 display +#define USER_SETUP_LOADED 1 #define ILI9341_DRIVER 1 #define M5STACK // needed for TFT driver From 67cede28867a0da6e13cc070e8bb3a09d33897e5 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 6 Apr 2020 11:53:38 +0200 Subject: [PATCH 14/24] lmic_config.h: bugfix pycom boards --- src/lmic_config.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lmic_config.h b/src/lmic_config.h index df3c5668..4a48283e 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -17,8 +17,10 @@ // --> adapt to your device only if necessary // use interrupts only if LORA_IRQ and LORA_DIO are connected to interrupt -// capable GPIO pins on your board, if not disable interrupts +// capable and separate GPIO pins on your board, if not don't enable +#if (LORA_IRQ) != (LORA_IO1) #define LMIC_USE_INTERRUPTS 1 +#endif // time sync via LoRaWAN network, note: not supported by TTNv2 #define LMIC_ENABLE_DeviceTimeReq 1 From 59930870fdbe7a39c8bb2d88fd68c57ea21e4c18 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 6 Apr 2020 11:53:55 +0200 Subject: [PATCH 15/24] enhanced RGB LED control for M5fire --- include/led.h | 4 ++++ src/hal/m5fire.h | 3 ++- src/led.cpp | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/led.h b/include/led.h index 1bc0ccde..6ee08289 100644 --- a/include/led.h +++ b/include/led.h @@ -4,6 +4,10 @@ #include #include "lorawan.h" +#ifndef RGB_LED_COUNT +#define RGB_LED_COUNT 1 +#endif + // value for HSL color // see http://www.workwithcolor.com/blue-color-hue-range-01.htm #define COLOR_RED 0 diff --git a/src/hal/m5fire.h b/src/hal/m5fire.h index ff4e196b..969c05ee 100644 --- a/src/hal/m5fire.h +++ b/src/hal/m5fire.h @@ -38,7 +38,8 @@ //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board #define HAS_LED NOT_A_PIN // no on board LED (?) -#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, 10, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 +#define RGB_LED_COUNT 10 +#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, RGB_LED_COUNT, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 #define HAS_BUTTON (39) // on board button A // GPS settings diff --git a/src/led.cpp b/src/led.cpp index d7925b4e..64d33d2e 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -64,8 +64,9 @@ RGBColor rgb_hsl2rgb(float h, float s, float l) { void rgb_set_color(uint16_t hue) { if (hue == COLOR_NONE) { - // Off - rgb_led[0] = Rgb(0, 0, 0); + // set Off + for (int i = 0; i < RGB_LED_COUNT; i++) + rgb_led[i] = Rgb(0, 0, 0); } else { // see http://www.workwithcolor.com/blue-color-hue-range-01.htm // H (is color from 0..360) should be between 0.0 and 1.0 @@ -74,7 +75,8 @@ void rgb_set_color(uint16_t hue) { // cfg.rgblum is between 0 and 100 (percent) RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum); // uint32_t color = target.R<<16 | target.G<<8 | target.B; - rgb_led[0] = Rgb(target.R, target.G, target.B); + for (int i = 0; i < RGB_LED_COUNT; i++) + rgb_led[i] = Rgb(target.R, target.G, target.B); } // Show rgb_led.show(); @@ -211,7 +213,7 @@ void ledLoop(void *parameter) { } // give yield to CPU delay(2); - } // while(1) -}; // ledloop() + } // while(1) +}; // ledloop() #endif // #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) From 4584a5a34b8b3c60baf01b098944e657e06e1ab6 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 6 Apr 2020 17:40:45 +0200 Subject: [PATCH 16/24] M5 display support (experimental) --- include/display.h | 11 ++- src/display.cpp | 240 ++++++++++++++++++++++++++-------------------- src/ota.cpp | 8 +- 3 files changed, 148 insertions(+), 111 deletions(-) diff --git a/include/display.h b/include/display.h index e82dad75..97362950 100644 --- a/include/display.h +++ b/include/display.h @@ -69,9 +69,9 @@ #endif // settings for qr code generator -#define QR_VERSION 3 // 29 x 29px -#define QR_SCALEFACTOR MY_DISPLAY_HEIGHT / (29 + 4) // 4px borderlines +#define QR_VERSION 3 // 29 x 29px +const uint8_t QR_SCALEFACTOR = (MY_DISPLAY_HEIGHT - 4) / 29; // 4px borderlines extern uint8_t DisplayIsOn, displaybuf[]; void dp_setup(int contrast = 0); @@ -79,11 +79,12 @@ void dp_refresh(bool nextPage = false); void dp_init(bool verbose = false); void dp_shutdown(void); void dp_drawPage(time_t t, bool nextpage); -void dp_println(void); -void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, - const char *format, ...); +void dp_println(int lines = 1); +void dp_printf(const char *format, ...); +void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer); void dp_setCursor(int x, int y); +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 ac482ec5..5e847e8f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -45,6 +45,7 @@ const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun", uint8_t DisplayIsOn = 0; uint8_t displaybuf[MY_DISPLAY_WIDTH * MY_DISPLAY_HEIGHT / 8] = {0}; static uint8_t plotbuf[MY_DISPLAY_WIDTH * MY_DISPLAY_HEIGHT / 8] = {0}; +static int dp_row = 0, dp_col = 0, dp_font = 0; QRCode qrcode; @@ -66,6 +67,7 @@ void dp_setup(int contrast) { // set display buffer oledSetBackBuffer(&ssoled, displaybuf); oledSetTextWrap(&ssoled, true); + dp_font = MY_FONT_NORMAL; #elif (HAS_DISPLAY) == 2 // SPI TFT @@ -102,15 +104,20 @@ void dp_init(bool verbose) { #if (VERBOSE) esp_chip_info_t chip_info; esp_chip_info(&chip_info); - dp_printf(0, 0, 0, 0, "** PAXCOUNTER **"); - dp_printf(0, 1, 0, 0, "Software v%s", PROGVERSION); - dp_printf(0, 3, 0, 0, "ESP32 %d cores", chip_info.cores); - dp_printf(0, 4, 0, 0, "Chip Rev.%d", chip_info.revision); - dp_printf(0, 5, 0, 0, "WiFi%s%s", - (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", + + dp_setFont(MY_FONT_NORMAL); + dp_printf("** PAXCOUNTER **"); + dp_println(); + dp_printf("Software v%s", PROGVERSION); + dp_println(); + dp_printf("ESP32 %d cores", chip_info.cores); + dp_println(); + dp_printf("Chip Rev.%d", chip_info.revision); + dp_println(); + dp_printf("WiFi%s%s", (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); - dp_printf(0, 6, 0, 0, "%dMB %s Flash", - spi_flash_get_chip_size() / (1024 * 1024), + dp_println(); + dp_printf("%dMB %s Flash", spi_flash_get_chip_size() / (1024 * 1024), (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "int." : "ext."); @@ -132,16 +139,14 @@ void dp_init(bool verbose) { dp_printqr(3, 3, deveui); // display DEVEUI as plain text on the right - const int x_offset = QR_SCALEFACTOR * 29 + 20; - dp_setCursor(x_offset, 1); - dp_printf(x_offset, 1, MY_FONT_NORMAL, 0, "DEVEUI:"); + const int x_offset = (QR_SCALEFACTOR * 29 + 4) / 8 + 2; + dp_setTextCursor(x_offset, 0); + dp_setFont(MY_FONT_NORMAL); + dp_printf("DEVEUI"); + dp_println(); for (uint8_t i = 0; i <= 3; i++) { -#if (HAS_DISPLAY) == 1 - dp_setCursor(x_offset, i + 3); -#elif (HAS_DISPLAY) == 2 - dp_setCursor(x_offset, 2 * (i + 3)); -#endif - dp_printf(x_offset, i + 3, MY_FONT_NORMAL, 0, "%4.4s", deveui + i * 4); + dp_setTextCursor(x_offset, i + 3); + dp_printf("%4.4s", deveui + i * 4); } // give user some time to read or take picture @@ -223,13 +228,14 @@ start: } // cursor home - dp_setCursor(0, 0); + dp_setTextCursor(0, 0); // line 1/2: pax counter + // display number of unique macs total Wifi + BLE if (DisplayPage < 6) { - dp_printf(0, 0, MY_FONT_STRETCHED, 0, "PAX:%-4d", - macs.size()); // display number of unique macs total Wifi + BLE - dp_println(); + dp_setFont(MY_FONT_STRETCHED); + dp_printf("PAX:%-4d", macs.size()); + dp_println(3); } switch (DisplayPage) { @@ -244,82 +250,79 @@ start: // page 0: parameters overview case 0: + dp_setFont(MY_FONT_SMALL); // line 3: wifi + bluetooth counters // WIFI:abcde BLTH:abcde #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) - dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); + dp_printf("WIFI:%-5d", macs_wifi); else - dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "WIFI:off"); + dp_printf("WIFI:off"); if (cfg.blescan) - dp_printf(66, 3, MY_FONT_SMALL, 0, " BLTH:%-5d", macs_ble); + dp_printf(" BLTH:%-5d", macs_ble); else - dp_printf(66, 3, MY_FONT_SMALL, 0, "%s", " BLTH:off"); + dp_printf(" BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) - dp_printf(0, 3, MY_FONT_SMALL, 0, "WIFI:%-5d", macs_wifi); + dp_printf("WIFI:%-5d", macs_wifi); else - dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "WIFI:off"); + dp_printf("WIFI:off"); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) - dp_printf(0, 3, MY_FONT_SMALL, 0, "BLTH:%-5d", macs_ble); + dp_printf("BLTH:%-5d", macs_ble); else - dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "BLTH:off"); + dp_printf("BLTH:off"); #else - dp_printf(0, 3, MY_FONT_SMALL, 0, "%s", "Sniffer disabled"); + dp_printf("Sniffer disabled"); #endif dp_println(); -// line 4: Battery + GPS status + Wifi channel -// B:a.bcV Sats:ab ch:ab + // line 4: Battery + GPS status + Wifi channel + // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU) if (batt_voltage == 0xffff) - dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "USB "); + dp_printf("USB "); else if (batt_voltage == 0) - dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", "No batt"); + dp_printf("No batt "); else - dp_printf(0, 4, MY_FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0); + dp_printf("B:%.2fV ", batt_voltage / 1000.0); #else - dp_printf(0, 4, MY_FONT_SMALL, 0, "%s", " "); + dp_printf(" "); #endif #if (HAS_GPS) - if (gps_hasfix()) - dp_printf(48, 4, MY_FONT_SMALL, 0, " Sats:%.2d", gps.satellites.value()); - else // if no fix then display Sats value inverse - dp_printf(48, 4, MY_FONT_SMALL, 1, " Sats:%.2d", gps.satellites.value()); + dp_setFont(MY_FONT_SMALL, !gps_hasfix()); + dp_printf("Sats:%.2d", gps.satellites.value()); + dp_setFont(MY_FONT_SMALL); #else - dp_printf(48, 4, MY_FONT_SMALL, 0, "%s", " "); + dp_printf(" "); #endif - dp_printf(96, 4, MY_FONT_SMALL, 0, " ch:%02d", channel); + dp_printf(" ch:%02d", channel); dp_println(); // line 5: RSSI limiter + free memory // RLIM:abcd Mem:abcdKB - - dp_printf(0, 5, MY_FONT_SMALL, 0, - !cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); - dp_printf(66, 5, MY_FONT_SMALL, 0, " Mem:%4dKB", getFreeRAM() / 1024); + dp_printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); + dp_printf(" Mem:%4dKB", getFreeRAM() / 1024); dp_println(); // line 6: time + date // 27.Feb 2019 20:27:00* - #if (TIME_SYNC_INTERVAL) timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource]; TimePulseTick = false; - dp_printf(0, 6, MY_FONT_SMALL, 0, "%02d.%3s %4d", day(t), - printmonth[month(t)], year(t)); - dp_printf(72, 6, MY_FONT_SMALL, 0, " %02d:%02d:%02d", hour(t), minute(t), - second(t)); + dp_printf("%02d.%3s %4d", day(t), printmonth[month(t)], year(t)); + dp_printf(" %02d:%02d:%02d", hour(t), minute(t), second(t)); // display inverse timeState if clock controller is enabled #if (defined HAS_DCF77) || (defined HAS_IF482) - dp_printf(120, 6, MY_FONT_SMALL, 1, "%c", timeState); + dp_setFont(MY_FONT_SMALL, 1); + dp_printf("%c", timeState); + dp_setFont(MY_FONT_SMALL, 0); #else - dp_printf(120, 6, MY_FONT_SMALL, 0, "%c", timeState); + dp_printf("%c", timeState); #endif dp_println(); #endif // TIME_SYNC_INTERVAL @@ -329,10 +332,11 @@ start: #if (HAS_LORA) // LMiC event display - dp_printf(0, 7, MY_FONT_SMALL, 0, "%-16s", lmic_event_msg); + dp_printf("%-16s", lmic_event_msg); // LORA datarate, display inverse if ADR disabled - dp_printf(102, 7, MY_FONT_SMALL, !cfg.adrmode, " %-4s", - getSfName(updr2rps(LMIC.datarate))); + dp_setFont(MY_FONT_SMALL, !cfg.adrmode); + dp_printf(" %-4s", getSfName(updr2rps(LMIC.datarate))); + dp_setFont(MY_FONT_SMALL, 0); dp_println(); #endif // HAS_LORA break; // page0 @@ -345,22 +349,26 @@ start: // page 2: GPS case 2: #if (HAS_GPS) + dp_setFont(MY_FONT_STRETCHED); if (gps_hasfix()) { // line 5: clear "No fix" if (wasnofix) { - dp_printf(16, 5, MY_FONT_STRETCHED, 0, " "); + dp_setTextCursor(2, 4); + dp_printf(" "); wasnofix = false; } // line 3-4: GPS latitude - dp_printf(0, 3, MY_FONT_STRETCHED, 0, "%c%07.4f", - gps.location.rawLat().negative ? 'S' : 'N', gps.location.lat()); + dp_printf("%c%07.4f", gps.location.rawLat().negative ? 'S' : 'N', + gps.location.lat()); // line 6-7: GPS longitude - dp_printf(0, 6, MY_FONT_STRETCHED, 0, "%c%07.4f", - gps.location.rawLat().negative ? 'W' : 'E', gps.location.lng()); + dp_printf("%c%07.4f", gps.location.rawLat().negative ? 'W' : 'E', + gps.location.lng()); } else { - dp_printf(16, 5, MY_FONT_STRETCHED, 1, "No fix"); + dp_setTextCursor(2, 4); + dp_setFont(MY_FONT_STRETCHED, 1); + dp_printf("No fix"); wasnofix = true; } break; // page2 @@ -370,19 +378,23 @@ start: // page 3: BME280/680 case 3: + dp_setFont(MY_FONT_STRETCHED); + dp_setTextCursor(0, 2); #if (HAS_BME) // line 2-3: Temp - dp_printf(0, 2, MY_FONT_STRETCHED, 0, "TMP:%-2.1f", bme_status.temperature); + dp_printf("TMP:%-2.1f", bme_status.temperature); + dp_println(2); // line 4-5: Hum - dp_printf(0, 4, MY_FONT_STRETCHED, 0, "HUM:%-2.1f", bme_status.humidity); + dp_printf("HUM:%-2.1f", bme_status.humidity); + dp_println(2); #ifdef HAS_BME680 // line 6-7: IAQ - dp_printf(0, 6, MY_FONT_STRETCHED, 0, "IAQ:%-3.0f", bme_status.iaq); + dp_printf("IAQ:%-3.0f", bme_status.iaq); #else // is BME280 or BMP180 // line 6-7: Pre - dp_printf(0, 6, MY_FONT_STRETCHED, 0, "PRE:%-2.1f", bme_status.pressure); + dp_printf("PRE:%-2.1f", bme_status.pressure); #endif // HAS_BME680 break; // page 3 #else @@ -391,34 +403,33 @@ start: // page 4: time case 4: - dp_printf(0, 4, MY_FONT_LARGE, 0, "%02d:%02d:%02d", hour(t), minute(t), - second(t)); + dp_setFont(MY_FONT_LARGE); + dp_printf("%02d:%02d:%02d", hour(t), minute(t), second(t)); break; // page 5: lorawan parameters case 5: #if (HAS_LORA) + // 3|NtwkID:000000 TXpw:aa // 4|DevAdd:00000000 DR:0 // 5|CHMsk:0000 Nonce:0000 // 6|CUp:000000 CDn:000000 // 7|SNR:-0000 RSSI:-0000 - dp_printf(0, 3, MY_FONT_SMALL, 0, "NetwID:%06X TXpw:%-2d", - LMIC.netid & 0x001FFFFF, LMIC.radio_txpow); + + dp_setFont(MY_FONT_SMALL); + dp_printf("NetwID:%06X TXpw:%-2d", LMIC.netid & 0x001FFFFF, + LMIC.radio_txpow); dp_println(); - dp_printf(0, 4, MY_FONT_SMALL, 0, "DevAdd:%08X DR:%1d", LMIC.devaddr, - LMIC.datarate); + dp_printf("DevAdd:%08X DR:%1d", LMIC.devaddr, LMIC.datarate); dp_println(); - dp_printf(0, 5, MY_FONT_SMALL, 0, "ChMsk:%04X Nonce:%04X", LMIC.channelMap, - LMIC.devNonce); + dp_printf("ChMsk:%04X Nonce:%04X", LMIC.channelMap, LMIC.devNonce); dp_println(); - dp_printf(0, 6, MY_FONT_SMALL, 0, "fUp:%-6d fDn:%-6d", - LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, + dp_printf("fUp:%-6d fDn:%-6d", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); dp_println(); - dp_printf(0, 7, MY_FONT_SMALL, 0, "SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, - LMIC.rssi); + dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); break; // page5 #else // don't show blank page if we are unattended DisplayPage++; // next page @@ -440,26 +451,57 @@ start: } // dp_drawPage -// display helper functions +// ------------- display helper functions ----------------- + +void dp_setTextCursor(int col, int row) { + dp_col = col; + dp_row = row; +#if (HAS_DISPLAY) == 1 + oledSetCursor(&ssoled, dp_col * 8, dp_row); +#elif (HAS_DISPLAY) == 2 + tft.setCursor(dp_row, dp_col); +#endif +} void dp_setCursor(int x, int y) { #if (HAS_DISPLAY) == 1 oledSetCursor(&ssoled, x, y); #elif (HAS_DISPLAY) == 2 - tft.setCursor(x, y * 8); + tft.setCursor(x, y); #endif } -void dp_println(void) { +void dp_setFont(int font, int inv) { #if (HAS_DISPLAY) == 1 - // to come + dp_font = (font << 1) | (inv & 0x01); +#elif (HAS_DISPLAY) == 2 + // map font oled -> tft + switch (font) { + case MY_FONT_STRETCHED: // 16x16 on OLED + case MY_FONT_LARGE: // 16x32 on OLED + tft.setTextFont(4); // 26px + break; + case MY_FONT_SMALL: // 6x8 on OLED + case MY_FONT_NORMAL: // 8x8 on OLED + default: + tft.setTextFont(2); // 16px + break; + } + // to do: invers printing +#endif +} + +void dp_println(int lines) { + dp_col = 0; + dp_row += lines; +#if (HAS_DISPLAY) == 1 + dp_setTextCursor(dp_col, dp_row); #elif (HAS_DISPLAY) == 2 tft.println(); #endif }; -void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, - const char *format, ...) { +void dp_printf(const char *format, ...) { char loc_buf[64]; char *temp = loc_buf; va_list arg; @@ -482,25 +524,10 @@ void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv, } va_end(arg); #if (HAS_DISPLAY) == 1 - oledWriteString(&ssoled, 0, x, y, temp, font, inv, false); + oledWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01, + false); #elif (HAS_DISPLAY) == 2 - // map font oled -> tft - uint8_t tft_font; - switch (font) { - case MY_FONT_STRETCHED: // 16x16 on OLED - case MY_FONT_LARGE: // 16x32 on OLED - tft_font = 4; // 26px - break; - case MY_FONT_SMALL: // 6x8 on OLED - case MY_FONT_NORMAL: // 8x8 on OLED - default: - tft_font = 2; // 16px - break; - } - - tft.setTextFont(tft_font); tft.printf(temp); - #endif if (temp != loc_buf) { free(temp); @@ -516,11 +543,10 @@ void dp_dump(uint8_t *pBuffer) { } void dp_clear(void) { + dp_setTextCursor(0, 0); #if (HAS_DISPLAY) == 1 - oledSetCursor(&ssoled, 0, 0); oledFill(&ssoled, 0, 1); #elif (HAS_DISPLAY) == 2 - tft.setCursor(0, 0); tft.fillScreen(MY_DISPLAY_BGCOLOR); #endif } @@ -557,6 +583,8 @@ void dp_shutdown(void) { #endif } +// ------------- QR code plotter ----------------- + void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { uint8_t qrcodeData[qrcode_getBufferSize(QR_VERSION)]; qrcode_initText(&qrcode, qrcodeData, QR_VERSION, ECC_HIGH, Message); @@ -580,6 +608,8 @@ void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message) { qrcode.size * QR_SCALEFACTOR + 2 * offset_y, false); } +// ------------- graphics primitives ----------------- + void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t bRender) { #if (HAS_DISPLAY) == 1 @@ -606,6 +636,8 @@ int dp_drawPixel(uint8_t *buf, const uint16_t x, const uint16_t y, return 0; } +// ------------- buffer scroll functions ----------------- + void dp_scrollHorizontal(uint8_t *buf, const uint16_t width, const uint16_t height, bool left) { @@ -651,6 +683,8 @@ 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; diff --git a/src/ota.cpp b/src/ota.cpp index 76ac51b5..4feca99b 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -301,10 +301,12 @@ retry: void ota_display(const uint8_t row, const std::string status, const std::string msg) { #ifdef HAS_DISPLAY - dp_printf(112, row, 0, 0, status.substr(0, 2).c_str()); + dp_setFont(MY_FONT_SMALL); + dp_setTextCursor(0, row); + dp_printf(status.substr(0, 2).c_str()); if (!msg.empty()) { - dp_printf(0, 7, 0, 0, " "); - dp_printf(0, 7, 0, 0, msg.substr(0, 16).c_str()); + dp_printf(" "); + dp_printf(msg.substr(0, 16).c_str()); } dp_dump(displaybuf); #endif From bdcd05cb215835049cd667f4ca2c2f979676a307 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Apr 2020 18:40:40 +0200 Subject: [PATCH 17/24] M5 display support fixes --- include/display.h | 1 - src/display.cpp | 50 ++++++++++++++++++++++++++++++++--------------- src/ota.cpp | 20 ++++++++++++------- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/include/display.h b/include/display.h index 97362950..c6b39033 100644 --- a/include/display.h +++ b/include/display.h @@ -83,7 +83,6 @@ void dp_println(int lines = 1); void dp_printf(const char *format, ...); void dp_setFont(int font, int inv = 0); void dp_dump(uint8_t *pBuffer); -void dp_setCursor(int x, int y); void dp_setTextCursor(int col, int row); void dp_contrast(uint8_t contrast); void dp_clear(void); diff --git a/src/display.cpp b/src/display.cpp index 5e847e8f..2252a3e4 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -75,6 +75,7 @@ void dp_setup(int contrast) { tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); + //tft.setTextPadding(MY_DISPLAY_WIDTH); #endif @@ -139,7 +140,7 @@ void dp_init(bool verbose) { dp_printqr(3, 3, deveui); // display DEVEUI as plain text on the right - const int x_offset = (QR_SCALEFACTOR * 29 + 4) / 8 + 2; + const int x_offset = QR_SCALEFACTOR * 29 + 14; dp_setTextCursor(x_offset, 0); dp_setFont(MY_FONT_NORMAL); dp_printf("DEVEUI"); @@ -235,7 +236,7 @@ start: if (DisplayPage < 6) { dp_setFont(MY_FONT_STRETCHED); dp_printf("PAX:%-4d", macs.size()); - dp_println(3); + dp_setTextCursor(0, 2); } switch (DisplayPage) { @@ -379,7 +380,6 @@ start: // page 3: BME280/680 case 3: dp_setFont(MY_FONT_STRETCHED); - dp_setTextCursor(0, 2); #if (HAS_BME) // line 2-3: Temp dp_printf("TMP:%-2.1f", bme_status.temperature); @@ -453,21 +453,38 @@ start: // ------------- display helper functions ----------------- -void dp_setTextCursor(int col, int row) { - dp_col = col; - dp_row = row; -#if (HAS_DISPLAY) == 1 - oledSetCursor(&ssoled, dp_col * 8, dp_row); -#elif (HAS_DISPLAY) == 2 - tft.setCursor(dp_row, dp_col); -#endif -} +void dp_setTextCursor(int x, int y) { + // x represents the pixel column + // y represents the text row + + dp_col = x; -void dp_setCursor(int x, int y) { #if (HAS_DISPLAY) == 1 - oledSetCursor(&ssoled, x, y); + switch (dp_font >> 1) { + case MY_FONT_STRETCHED: // 16x16 on OLED + case MY_FONT_LARGE: // 16x32 on OLED + dp_row = y * 2; + break; + case MY_FONT_SMALL: // 6x8 on OLED + case MY_FONT_NORMAL: // 8x8 on OLED + default: + dp_row = y; + break; + } + oledSetCursor(&ssoled, dp_col, dp_row); #elif (HAS_DISPLAY) == 2 - tft.setCursor(x, y); + switch (dp_font >> 1) { + case MY_FONT_STRETCHED: + case MY_FONT_LARGE: + dp_row = y * 26; + break; + case MY_FONT_SMALL: + case MY_FONT_NORMAL: + default: + dp_row = y * 16; + break; + } + tft.setCursor(dp_col, dp_row); #endif } @@ -497,7 +514,8 @@ void dp_println(int lines) { #if (HAS_DISPLAY) == 1 dp_setTextCursor(dp_col, dp_row); #elif (HAS_DISPLAY) == 2 - tft.println(); + for (int i = 1; i <= lines; i++) + tft.println(); #endif }; diff --git a/src/ota.cpp b/src/ota.cpp index 4feca99b..07532c08 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -47,12 +47,17 @@ void start_ota_update() { dp_setup(); - dp_printf(0, 0, 0, 1, "SOFTWARE UPDATE"); - dp_printf(0, 1, 0, 0, "WiFi connect .."); - dp_printf(0, 2, 0, 0, "Has Update? .."); - dp_printf(0, 3, 0, 0, "Fetching .."); - dp_printf(0, 4, 0, 0, "Downloading .."); - dp_printf(0, 5, 0, 0, "Rebooting .."); + dp_printf("SOFTWARE UPDATE"); + dp_println(); + dp_printf("WiFi connect .."); + dp_println(); + dp_printf("Has Update? .."); + dp_println(); + dp_printf("Fetching .."); + dp_println(); + dp_printf("Downloading .."); + dp_println(); + dp_printf("Rebooting .."); dp_dump(displaybuf); #endif @@ -302,11 +307,12 @@ void ota_display(const uint8_t row, const std::string status, const std::string msg) { #ifdef HAS_DISPLAY dp_setFont(MY_FONT_SMALL); - dp_setTextCursor(0, row); + dp_setTextCursor(14, row); dp_printf(status.substr(0, 2).c_str()); if (!msg.empty()) { dp_printf(" "); dp_printf(msg.substr(0, 16).c_str()); + dp_println(); } dp_dump(displaybuf); #endif From 99b67deaec0b86d3a66ee93bf20be4a479b23288 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Apr 2020 22:27:37 +0200 Subject: [PATCH 18/24] M5 display support fixes --- src/display.cpp | 135 ++++++++++++++++++++++++------------------------ 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 2252a3e4..7c44bef7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -75,7 +75,6 @@ void dp_setup(int contrast) { tft.setRotation(MY_DISPLAY_FLIP ? 3 : 1); tft.invertDisplay(MY_DISPLAY_INVERT ? true : false); tft.setTextColor(MY_DISPLAY_FGCOLOR, MY_DISPLAY_BGCOLOR); - //tft.setTextPadding(MY_DISPLAY_WIDTH); #endif @@ -233,24 +232,25 @@ start: // line 1/2: pax counter // display number of unique macs total Wifi + BLE - if (DisplayPage < 6) { + if (DisplayPage < 5) { dp_setFont(MY_FONT_STRETCHED); dp_printf("PAX:%-4d", macs.size()); - dp_setTextCursor(0, 2); } switch (DisplayPage) { // page 0: parameters overview - // page 1: pax graph + // page 1: lorawan parameters // page 2: GPS // page 3: BME280/680 // page 4: time - // page 5: lorawan parameters + // page 5: pax graph // page 6: blank screen - // page 0: parameters overview + // ---------- page 0: parameters overview ---------- case 0: + + dp_setTextCursor(0, 3); dp_setFont(MY_FONT_SMALL); // line 3: wifi + bluetooth counters @@ -339,18 +339,44 @@ start: dp_printf(" %-4s", getSfName(updr2rps(LMIC.datarate))); dp_setFont(MY_FONT_SMALL, 0); dp_println(); -#endif // HAS_LORA - break; // page0 +#endif // HAS_LORA + break; - // page 1: pax graph + // ---------- page 1: lorawan parameters ---------- case 1: - dp_dump(plotbuf); - break; // page1 - // page 2: GPS +#if (HAS_LORA) + + // 3|NtwkID:000000 TXpw:aa + // 4|DevAdd:00000000 DR:0 + // 5|CHMsk:0000 Nonce:0000 + // 6|CUp:000000 CDn:000000 + // 7|SNR:-0000 RSSI:-0000 + + dp_setFont(MY_FONT_SMALL); + dp_setTextCursor(0, 3); + dp_printf("NetwID:%06X TXpw:%-2d", LMIC.netid & 0x001FFFFF, + LMIC.radio_txpow); + dp_println(); + dp_printf("DevAdd:%08X DR:%1d", LMIC.devaddr, LMIC.datarate); + dp_println(); + dp_printf("ChMsk:%04X Nonce:%04X", LMIC.channelMap, LMIC.devNonce); + dp_println(); + dp_printf("fUp:%-6d fDn:%-6d", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, + LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); + dp_println(); + dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); + break; +#else // flip page if we are unattended + DisplayPage++; +#endif // HAS_LORA + + // ---------- page 2: GPS ---------- case 2: + #if (HAS_GPS) dp_setFont(MY_FONT_STRETCHED); + dp_setTextCursor(0, 3); if (gps_hasfix()) { // line 5: clear "No fix" if (wasnofix) { @@ -372,15 +398,18 @@ start: dp_printf("No fix"); wasnofix = true; } - break; // page2 -#else - DisplayPage++; // next page + break; +#else // flip page if we are unattended + DisplayPage++; #endif - // page 3: BME280/680 + // ---------- page 3: BME280/680 ---------- case 3: - dp_setFont(MY_FONT_STRETCHED); + #if (HAS_BME) + dp_setFont(MY_FONT_STRETCHED); + dp_setTextCursor(0, 2); + // line 2-3: Temp dp_printf("TMP:%-2.1f", bme_status.temperature); dp_println(2); @@ -397,58 +426,38 @@ start: dp_printf("PRE:%-2.1f", bme_status.pressure); #endif // HAS_BME680 break; // page 3 -#else - DisplayPage++; // next page -#endif // HAS_BME +#else // flip page if we are unattended + DisplayPage++; +#endif // HAS_BME - // page 4: time + // ---------- page 4: time ---------- case 4: + dp_setFont(MY_FONT_LARGE); + dp_setTextCursor(0, 4); dp_printf("%02d:%02d:%02d", hour(t), minute(t), second(t)); break; - // page 5: lorawan parameters + // ---------- page 5: pax graph ---------- case 5: -#if (HAS_LORA) + dp_setFont(MY_FONT_NORMAL); + dp_setTextCursor(0, 0); + dp_printf("Pax graph"); + dp_dump(plotbuf); + break; - // 3|NtwkID:000000 TXpw:aa - // 4|DevAdd:00000000 DR:0 - // 5|CHMsk:0000 Nonce:0000 - // 6|CUp:000000 CDn:000000 - // 7|SNR:-0000 RSSI:-0000 - - dp_setFont(MY_FONT_SMALL); - dp_printf("NetwID:%06X TXpw:%-2d", LMIC.netid & 0x001FFFFF, - LMIC.radio_txpow); - dp_println(); - dp_printf("DevAdd:%08X DR:%1d", LMIC.devaddr, LMIC.datarate); - dp_println(); - dp_printf("ChMsk:%04X Nonce:%04X", LMIC.channelMap, LMIC.devNonce); - dp_println(); - dp_printf("fUp:%-6d fDn:%-6d", LMIC.seqnoUp ? LMIC.seqnoUp - 1 : 0, - LMIC.seqnoDn ? LMIC.seqnoDn - 1 : 0); - dp_println(); - dp_printf("SNR:%-5d RSSI:%-5d", (LMIC.snr + 2) / 4, LMIC.rssi); - break; // page5 -#else // don't show blank page if we are unattended - DisplayPage++; // next page -#endif // HAS_LORA - - // page 6: blank screen + // ---------- page 6: blank screen ---------- case 6: + #ifdef HAS_BUTTON dp_clear(); break; -#else // don't show blank page if we are unattended - DisplayPage++; // next page +#else // flip page if we are unattended + DisplayPage++; #endif - default: - goto start; // start over - - } // switch - + } // switch (page) } // dp_drawPage // ------------- display helper functions ----------------- @@ -456,22 +465,12 @@ start: void dp_setTextCursor(int x, int y) { // x represents the pixel column // y represents the text row - dp_col = x; #if (HAS_DISPLAY) == 1 - switch (dp_font >> 1) { - case MY_FONT_STRETCHED: // 16x16 on OLED - case MY_FONT_LARGE: // 16x32 on OLED - dp_row = y * 2; - break; - case MY_FONT_SMALL: // 6x8 on OLED - case MY_FONT_NORMAL: // 8x8 on OLED - default: - dp_row = y; - break; - } + dp_row = y; oledSetCursor(&ssoled, dp_col, dp_row); + #elif (HAS_DISPLAY) == 2 switch (dp_font >> 1) { case MY_FONT_STRETCHED: @@ -556,7 +555,9 @@ void dp_dump(uint8_t *pBuffer) { #if (HAS_DISPLAY) == 1 oledDumpBuffer(&ssoled, pBuffer); #elif (HAS_DISPLAY) == 2 - // to do: buffered rendering for TFT + // probably oled buffer stucture is not suitable for tft -> to be checked + tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT, + MY_DISPLAY_FGCOLOR); #endif } From 438b3485e52d85c09b6bff4a8f84cd040ac8ab71 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Apr 2020 22:37:18 +0200 Subject: [PATCH 19/24] compiler warning sanitizations --- src/display.cpp | 2 -- src/timesync.cpp | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 7c44bef7..5c3759dd 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -220,8 +220,6 @@ void dp_drawPage(time_t t, bool nextpage) { static bool wasnofix = true; #endif -start: - if (nextpage) { DisplayPage = (DisplayPage >= DISPLAY_PAGES - 1) ? 0 : (DisplayPage + 1); dp_clear(); diff --git a/src/timesync.cpp b/src/timesync.cpp index ce32d4e6..a44ab138 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -174,9 +174,6 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) { if (!timeSyncPending) return; - // store LMIC time when we received the timesync answer - ostime_t rxTime = osticks2ms(os_getTime()); - // mask application irq to ensure accurate timing mask_user_IRQ(); @@ -192,7 +189,7 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) { // flag: length of buffer // Store the instant the time request of the node was received on the gateway - timesync_store(rxTime, timesync_rx); + timesync_store(osticks2ms(os_getTime(), timesync_rx); // parse pUserData: // p type meaning From a6cbc2479eca299539dc295f262e3a7b97995aed Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Apr 2020 22:56:17 +0200 Subject: [PATCH 20/24] compiler warning sanitizations --- src/ledmatrixdisplay.cpp | 2 +- src/lmic_config.h | 6 +++++ src/lorawan.cpp | 50 ++++++++++++++++++++-------------------- src/timesync.cpp | 4 ++++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/ledmatrixdisplay.cpp b/src/ledmatrixdisplay.cpp index ad484e34..3e273731 100644 --- a/src/ledmatrixdisplay.cpp +++ b/src/ledmatrixdisplay.cpp @@ -206,7 +206,7 @@ uint8_t GetCharWidth(char cChar) { } void ScrollMatrixLeft(uint8_t *buf, const uint16_t cols, const uint16_t rows) { - uint32_t i, k, idx; + uint32_t i, k, idx = 0; const uint32_t x = cols / 8; for (k = 0; k < rows; k++) { diff --git a/src/lmic_config.h b/src/lmic_config.h index 4a48283e..9a955dc1 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -22,6 +22,12 @@ #define LMIC_USE_INTERRUPTS 1 #endif +// avoid lmic warning if we don't configure radio because we don't have one +#define CFG_sx1276_radio 1 +#if ! (defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio)) +#define CFG_sx1276_radio 1 +#endif + // time sync via LoRaWAN network, note: not supported by TTNv2 #define LMIC_ENABLE_DeviceTimeReq 1 diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 040e9805..6178580d 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -136,9 +136,9 @@ void RevBytes(unsigned char *b, size_t c) { } // LMIC callback functions -void os_getDevKey(u1_t *buf) { +void os_getDevKey(u1_t *buf) { #ifndef LORA_ABP - memcpy(buf, APPKEY, 16); + memcpy(buf, APPKEY, 16); #endif } @@ -306,30 +306,30 @@ esp_err_t lora_stack_init(bool do_join) { &lmicTask, // task handle 1); // CPU core - #ifdef LORA_ABP - // Pass ABP parameters to LMIC_setSession +#ifdef LORA_ABP + // Pass ABP parameters to LMIC_setSession + LMIC_reset(); + uint8_t appskey[sizeof(APPSKEY)]; + uint8_t nwkskey[sizeof(NWKSKEY)]; + memcpy_P(appskey, APPSKEY, sizeof(APPSKEY)); + memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY)); + LMIC_setSession(NETID, DEVADDR, nwkskey, appskey); + // These parameters are defined as macro in loraconf.h + setABPParamaters(); +#else + // Start join procedure if not already joined, + // lora_setupForNetwork(true) is called by eventhandler when joined + // else continue current session + if (do_join) { + if (!LMIC_startJoining()) + ESP_LOGI(TAG, "Already joined"); + } else { LMIC_reset(); - uint8_t appskey[sizeof(APPSKEY)]; - uint8_t nwkskey[sizeof(NWKSKEY)]; - memcpy_P(appskey, APPSKEY, sizeof(APPSKEY)); - memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY)); - LMIC_setSession (NETID, DEVADDR, nwkskey, appskey); - // These parameters are defined as macro in loraconf.h - setABPParamaters(); - #else - // Start join procedure if not already joined, - // lora_setupForNetwork(true) is called by eventhandler when joined - // else continue current session - if (do_join) { - if (!LMIC_startJoining()) - ESP_LOGI(TAG, "Already joined"); - } else { - LMIC_reset(); - LMIC_setSession(RTCnetid, RTCdevaddr, RTCnwkKey, RTCartKey); - LMIC.seqnoUp = RTCseqnoUp; - LMIC.seqnoDn = RTCseqnoDn; - } - #endif + LMIC_setSession(RTCnetid, RTCdevaddr, RTCnwkKey, RTCartKey); + LMIC.seqnoUp = RTCseqnoUp; + LMIC.seqnoDn = RTCseqnoDn; + } +#endif // start lmic send task xTaskCreatePinnedToCore(lora_send, // task function "lorasendtask", // name of task diff --git a/src/timesync.cpp b/src/timesync.cpp index a44ab138..d0bc4c5d 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -170,6 +170,8 @@ void timesync_store(uint32_t timestamp, timesync_t timestamp_type) { // callback function to receive time answer from network or answer void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) { +#if (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) + // if no timesync handshake is pending then exit if (!timeSyncPending) return; @@ -269,4 +271,6 @@ Exit: // inform processing task xTaskNotify(timeSyncProcTask, (rc ? rcv_seqNo : TIME_SYNC_END_FLAG), eSetBits); + +#endif // (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) } \ No newline at end of file From 90a004ec7958a87f5f21e9f30b1e1b76dee9c8c2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Apr 2020 23:26:29 +0200 Subject: [PATCH 21/24] prepare LMIC battlevel MAC request --- include/power.h | 4 ++++ src/lmic_config.h | 3 +++ src/lorawan.cpp | 26 -------------------------- src/power.cpp | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/include/power.h b/include/power.h index 5e0ee363..dbe3cfca 100644 --- a/include/power.h +++ b/include/power.h @@ -11,6 +11,10 @@ #define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate #define NO_OF_SAMPLES 64 // we do some multisampling to get better values +#ifndef BAT_MAX_VOLTAGE +#define BAT_MAX_VOLTAGE 4100 // millivolts +#endif + uint16_t read_voltage(void); void calibrate_voltage(void); bool batt_sufficient(void); diff --git a/src/lmic_config.h b/src/lmic_config.h index 9a955dc1..00df54d5 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -104,3 +104,6 @@ #define USE_IDEETRON_AES // //#define USE_MBEDTLS_AES + +// Define this for devices with external power. +//#define LMIC_MCMD_DEVS_BATT_DEFAULT MCMD_DEVS_EXT_POWER \ No newline at end of file diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 6178580d..fd0d5fb8 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -538,32 +538,6 @@ const char *getCrName(rps_t rps) { return t[getCr(rps)]; } -/* -u1_t os_getBattLevel() { - - //return values: - //MCMD_DEVS_EXT_POWER = 0x00, // external power supply - //MCMD_DEVS_BATT_MIN = 0x01, // min battery value - //MCMD_DEVS_BATT_MAX = 0xFE, // max battery value - //MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level - -#if (defined HAS_PMU || defined BAT_MEASURE_ADC) - uint16_t voltage = read_voltage(); - - switch (voltage) { - case 0: - return MCMD_DEVS_BATT_NOINFO; - case 0xffff: - return MCMD_DEVS_EXT_POWER; - default: - return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN); - } -#else // we don't have any info on battery level - return MCMD_DEVS_BATT_NOINFO; -#endif -} // getBattLevel() -*/ - #if (VERBOSE) // decode LORAWAN MAC message void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, bool is_down) { diff --git a/src/power.cpp b/src/power.cpp index 80d961cd..6fdaaac6 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -217,5 +217,28 @@ uint16_t read_voltage() { #endif // HAS_PMU + /* + // set battery level value for lmic stack + #if (HAS_LORA) + // Sets the battery level returned in MAC Command DevStatusAns. + // Available defines in lorabase.h: + // MCMD_DEVS_EXT_POWER = 0x00, // external power supply + // MCMD_DEVS_BATT_MIN = 0x01, // min battery value + // MCMD_DEVS_BATT_MAX = 0xFE, // max battery value + // MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level + // When setting the battery level calculate the applicable + // value from MCMD_DEVS_BATT_MIN to MCMD_DEVS_BATT_MAX. + + // external power + if (voltage == 0xffff) + LMIC_setBattLevel(MCMD_DEVS_EXT_POWER); + // scale battery millivolts to lmic battlevel + else + LMIC_setBattLevel(voltage / BAT_MAX_VOLTAGE * + (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1)); + +#endif // (HAS_LORA) +*/ + return voltage; } \ No newline at end of file From f4e8c67117cff5a63f4922356498baaf2c79edac Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 11 Apr 2020 21:30:09 +0200 Subject: [PATCH 22/24] Battery percentage display --- include/globals.h | 4 +-- include/power.h | 6 +++- src/cyclic.cpp | 8 ++--- src/display.cpp | 6 ++-- src/main.cpp | 13 +++---- src/power.cpp | 92 ++++++++++++++++++++++++++++------------------- 6 files changed, 76 insertions(+), 53 deletions(-) diff --git a/include/globals.h b/include/globals.h index c4ad3871..2d6988be 100644 --- a/include/globals.h +++ b/include/globals.h @@ -123,8 +123,8 @@ extern std::array beacons; extern configData_t cfg; // current device configuration extern char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer extern uint8_t volatile channel; // wifi channel rotation counter -extern uint16_t volatile macs_total, macs_wifi, macs_ble, - batt_voltage; // display values +extern uint8_t batt_level; // display value +extern uint16_t volatile macs_total, macs_wifi, macs_ble; // display values extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC extern timesource_t timeSource; extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ; diff --git a/include/power.h b/include/power.h index dbe3cfca..a5d1cfc9 100644 --- a/include/power.h +++ b/include/power.h @@ -12,10 +12,14 @@ #define NO_OF_SAMPLES 64 // we do some multisampling to get better values #ifndef BAT_MAX_VOLTAGE -#define BAT_MAX_VOLTAGE 4100 // millivolts +#define BAT_MAX_VOLTAGE 4200 // millivolts +#endif +#ifndef BAT_MIN_VOLTAGE +#define BAT_MIN_VOLTAGE 3100 // millivolts #endif uint16_t read_voltage(void); +uint8_t read_battlevel(void); void calibrate_voltage(void); bool batt_sufficient(void); diff --git a/src/cyclic.cpp b/src/cyclic.cpp index b1ad7210..8c5aceaa 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -28,7 +28,7 @@ void doHousekeeping() { if (batt_sufficient()) { do_reset(true); // warmstart to runmode update } else { - ESP_LOGE(TAG, "Battery voltage %dmV too low for OTA", batt_voltage); + ESP_LOGE(TAG, "Battery level %d%% is too low for OTA", batt_level); RTC_runmode = RUNMODE_NORMAL; // keep running in normal mode } } @@ -66,11 +66,11 @@ void doHousekeeping() { // read battery voltage into global variable #if (defined BAT_MEASURE_ADC || defined HAS_PMU) - batt_voltage = read_voltage(); - if (batt_voltage == 0xffff) + batt_level = read_battlevel(); + if (batt_level == MCMD_DEVS_EXT_POWER) ESP_LOGI(TAG, "Battery: external power"); else - ESP_LOGI(TAG, "Battery: %dmV", batt_voltage); + ESP_LOGI(TAG, "Battery: %d%%", batt_level); #ifdef HAS_PMU AXP192_showstatus(); #endif diff --git a/src/display.cpp b/src/display.cpp index 5c3759dd..a630f51a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -281,12 +281,12 @@ void dp_drawPage(time_t t, bool nextpage) { // line 4: Battery + GPS status + Wifi channel // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU) - if (batt_voltage == 0xffff) + if (batt_level == MCMD_DEVS_EXT_POWER) dp_printf("USB "); - else if (batt_voltage == 0) + else if (batt_level == MCMD_DEVS_BATT_NOINFO) dp_printf("No batt "); else - dp_printf("B:%.2fV ", batt_voltage / 1000.0); + dp_printf("B:%3d%% ", batt_level); #else dp_printf(" "); #endif diff --git a/src/main.cpp b/src/main.cpp index 24999f71..ec9d7abc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,8 +79,9 @@ triggers pps 1 sec impulse configData_t cfg; // struct holds current device configuration char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message uint8_t volatile channel = 0; // channel rotation counter -uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0, - batt_voltage = 0; // globals for display +uint8_t batt_level = 0; // display value +uint16_t volatile macs_total = 0, macs_wifi = 0, + macs_ble = 0; // globals for display hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL; @@ -260,7 +261,7 @@ void setup() { #if (defined BAT_MEASURE_ADC || defined HAS_PMU) strcat_P(features, " BATT"); calibrate_voltage(); - batt_voltage = read_voltage(); + batt_level = read_battlevel(); #endif #if (USE_OTA) @@ -328,9 +329,9 @@ void setup() { #endif #if (HAS_SDS011) - ESP_LOGI(TAG, "init fine-dust-sensor"); - if ( sds011_init() ) - strcat_P(features, " SDS"); + ESP_LOGI(TAG, "init fine-dust-sensor"); + if (sds011_init()) + strcat_P(features, " SDS"); #endif #if (VENDORFILTER) diff --git a/src/power.cpp b/src/power.cpp index 6fdaaac6..092f786e 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -63,7 +63,7 @@ void AXP192_powerevent_IRQ(void) { pmu.clearIRQ(); // refresh stored voltage value - read_voltage(); + read_battlevel(); } void AXP192_power(pmu_power_t powerlevel) { @@ -175,21 +175,11 @@ void calibrate_voltage(void) { #endif } -bool batt_sufficient() { -#if (defined HAS_PMU || defined BAT_MEASURE_ADC) - uint16_t volts = read_voltage(); - return ((volts < 1000) || - (volts > OTA_MIN_BATT)); // no battery or battery sufficient -#else - return true; -#endif -} - -uint16_t read_voltage() { +uint16_t read_voltage(void) { uint16_t voltage = 0; #ifdef HAS_PMU - voltage = pmu.isVBUSPlug() ? 0xffff : pmu.getBattVoltage(); + voltage = pmu.getBattVoltage(); #else #ifdef BAT_MEASURE_ADC @@ -217,28 +207,56 @@ uint16_t read_voltage() { #endif // HAS_PMU - /* - // set battery level value for lmic stack - #if (HAS_LORA) - // Sets the battery level returned in MAC Command DevStatusAns. - // Available defines in lorabase.h: - // MCMD_DEVS_EXT_POWER = 0x00, // external power supply - // MCMD_DEVS_BATT_MIN = 0x01, // min battery value - // MCMD_DEVS_BATT_MAX = 0xFE, // max battery value - // MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level - // When setting the battery level calculate the applicable - // value from MCMD_DEVS_BATT_MIN to MCMD_DEVS_BATT_MAX. - - // external power - if (voltage == 0xffff) - LMIC_setBattLevel(MCMD_DEVS_EXT_POWER); - // scale battery millivolts to lmic battlevel - else - LMIC_setBattLevel(voltage / BAT_MAX_VOLTAGE * - (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1)); - -#endif // (HAS_LORA) -*/ - return voltage; -} \ No newline at end of file +} + +uint8_t read_battlevel() { + + // return the battery value as sent in MAC Command + // DevStatusAns. Available defines in lorabase.h: + // MCMD_DEVS_EXT_POWER = 0x00, // external power supply + // MCMD_DEVS_BATT_MIN = 0x01, // min battery value + // MCMD_DEVS_BATT_MAX = 0xFE, // max battery value + // MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level + // we calculate the applicable value from MCMD_DEVS_BATT_MIN to + // MCMD_DEVS_BATT_MAX from bat_percent value + + const uint16_t batt_voltage_range = BAT_MAX_VOLTAGE - BAT_MIN_VOLTAGE; + const uint8_t batt_level_range = MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1; + const uint16_t batt_voltage = read_voltage() - BAT_MIN_VOLTAGE; + const uint8_t batt_percent = + batt_voltage > 0 ? batt_voltage / batt_voltage_range * 100 : 0; + uint8_t lmic_batt_level; + +#ifdef HAS_PMU + if (batt_percent > 0) + lmic_batt_level = pmu.isVBUSPlug() ? MCMD_DEVS_EXT_POWER + : batt_percent / 100 * batt_level_range; + else + lmic_batt_level = MCMD_DEVS_BATT_NOINFO; +#else + if (batt_percent > 0) + lmic_batt_level = batt_percent / 100 * batt_level_range; + else + lmic_batt_level = MCMD_DEVS_BATT_NOINFO; +#endif // HAS_PMU + +// set battery level value for lmic stack +#if (HAS_LORA) + //LMIC_setBattLevel(lmic_batt_level); +#endif + + return batt_percent; +} + +bool batt_sufficient() { +#if (defined HAS_PMU || defined BAT_MEASURE_ADC) + uint8_t my_batt_level = read_battlevel(); + if (my_batt_level == MCMD_DEVS_EXT_POWER) + return true; + else + return (my_batt_level > OTA_MIN_BATT); +#else + return true; // we don't know batt level +#endif +} From bf2d32896f1a0305130eb25fb3f03936220ee2d5 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 11 Apr 2020 23:36:17 +0200 Subject: [PATCH 23/24] battery percentage display fixes --- include/power.h | 2 +- src/cyclic.cpp | 25 +++++++++++++++---------- src/display.cpp | 10 +++++++--- src/power.cpp | 19 ++++++++++++------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/include/power.h b/include/power.h index a5d1cfc9..f41fced0 100644 --- a/include/power.h +++ b/include/power.h @@ -12,7 +12,7 @@ #define NO_OF_SAMPLES 64 // we do some multisampling to get better values #ifndef BAT_MAX_VOLTAGE -#define BAT_MAX_VOLTAGE 4200 // millivolts +#define BAT_MAX_VOLTAGE 4300 // millivolts #endif #ifndef BAT_MIN_VOLTAGE #define BAT_MIN_VOLTAGE 3100 // millivolts diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 8c5aceaa..425b1210 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -67,10 +67,16 @@ void doHousekeeping() { // read battery voltage into global variable #if (defined BAT_MEASURE_ADC || defined HAS_PMU) batt_level = read_battlevel(); - if (batt_level == MCMD_DEVS_EXT_POWER) + switch (batt_level) { + case MCMD_DEVS_EXT_POWER: ESP_LOGI(TAG, "Battery: external power"); - else + break; + case MCMD_DEVS_BATT_NOINFO : + ESP_LOGI(TAG, "Battery: unknown state"); + break; + default: ESP_LOGI(TAG, "Battery: %d%%", batt_level); + } #ifdef HAS_PMU AXP192_showstatus(); #endif @@ -116,14 +122,13 @@ void doHousekeeping() { #endif #if (HAS_SDS011) - if ( isSDS011Active ) { - ESP_LOGD(TAG, "SDS011: go to sleep"); - sds011_loop(); - } - else { - ESP_LOGD(TAG, "SDS011: wakeup"); - sds011_wakeup(); - } + if (isSDS011Active) { + ESP_LOGD(TAG, "SDS011: go to sleep"); + sds011_loop(); + } else { + ESP_LOGD(TAG, "SDS011: wakeup"); + sds011_wakeup(); + } #endif } // doHousekeeping() diff --git a/src/display.cpp b/src/display.cpp index a630f51a..38266b4b 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -281,12 +281,16 @@ void dp_drawPage(time_t t, bool nextpage) { // line 4: Battery + GPS status + Wifi channel // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU) - if (batt_level == MCMD_DEVS_EXT_POWER) + switch (batt_level) { + case MCMD_DEVS_EXT_POWER: dp_printf("USB "); - else if (batt_level == MCMD_DEVS_BATT_NOINFO) + break; + case MCMD_DEVS_BATT_NOINFO: dp_printf("No batt "); - else + break; + default: dp_printf("B:%3d%% ", batt_level); + } #else dp_printf(" "); #endif diff --git a/src/power.cpp b/src/power.cpp index 092f786e..1a290764 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -224,18 +224,19 @@ uint8_t read_battlevel() { const uint16_t batt_voltage_range = BAT_MAX_VOLTAGE - BAT_MIN_VOLTAGE; const uint8_t batt_level_range = MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1; const uint16_t batt_voltage = read_voltage() - BAT_MIN_VOLTAGE; - const uint8_t batt_percent = - batt_voltage > 0 ? batt_voltage / batt_voltage_range * 100 : 0; + const uint8_t batt_percent = batt_voltage > 0 + ? batt_voltage / batt_voltage_range * 100 + : MCMD_DEVS_BATT_NOINFO; uint8_t lmic_batt_level; #ifdef HAS_PMU - if (batt_percent > 0) + if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO)) lmic_batt_level = pmu.isVBUSPlug() ? MCMD_DEVS_EXT_POWER : batt_percent / 100 * batt_level_range; else lmic_batt_level = MCMD_DEVS_BATT_NOINFO; #else - if (batt_percent > 0) + if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO)) lmic_batt_level = batt_percent / 100 * batt_level_range; else lmic_batt_level = MCMD_DEVS_BATT_NOINFO; @@ -243,7 +244,7 @@ uint8_t read_battlevel() { // set battery level value for lmic stack #if (HAS_LORA) - //LMIC_setBattLevel(lmic_batt_level); + // LMIC_setBattLevel(lmic_batt_level); #endif return batt_percent; @@ -252,10 +253,14 @@ uint8_t read_battlevel() { bool batt_sufficient() { #if (defined HAS_PMU || defined BAT_MEASURE_ADC) uint8_t my_batt_level = read_battlevel(); - if (my_batt_level == MCMD_DEVS_EXT_POWER) + switch (my_batt_level) { + case MCMD_DEVS_EXT_POWER: return true; - else + case MCMD_DEVS_BATT_NOINFO: + return true; + default: return (my_batt_level > OTA_MIN_BATT); + } #else return true; // we don't know batt level #endif From 4a1499b2bb82669dbb41935a80bce19151900ef4 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 12 Apr 2020 17:33:13 +0200 Subject: [PATCH 24/24] battery percentage display fixes --- include/power.h | 2 +- src/display.cpp | 2 +- src/power.cpp | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/power.h b/include/power.h index f41fced0..a1033041 100644 --- a/include/power.h +++ b/include/power.h @@ -15,7 +15,7 @@ #define BAT_MAX_VOLTAGE 4300 // millivolts #endif #ifndef BAT_MIN_VOLTAGE -#define BAT_MIN_VOLTAGE 3100 // millivolts +#define BAT_MIN_VOLTAGE 3200 // millivolts #endif uint16_t read_voltage(void); diff --git a/src/display.cpp b/src/display.cpp index 38266b4b..764da7fc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -283,7 +283,7 @@ void dp_drawPage(time_t t, bool nextpage) { #if (defined BAT_MEASURE_ADC || defined HAS_PMU) switch (batt_level) { case MCMD_DEVS_EXT_POWER: - dp_printf("USB "); + dp_printf("ext.Pwr "); break; case MCMD_DEVS_BATT_NOINFO: dp_printf("No batt "); diff --git a/src/power.cpp b/src/power.cpp index 1a290764..4ab413a1 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -223,24 +223,24 @@ uint8_t read_battlevel() { const uint16_t batt_voltage_range = BAT_MAX_VOLTAGE - BAT_MIN_VOLTAGE; const uint8_t batt_level_range = MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1; - const uint16_t batt_voltage = read_voltage() - BAT_MIN_VOLTAGE; - const uint8_t batt_percent = batt_voltage > 0 - ? batt_voltage / batt_voltage_range * 100 + const int batt_voltage = read_voltage() - BAT_MIN_VOLTAGE; + const uint8_t batt_percent = (batt_voltage > 0) + ? (float)batt_voltage / (float)batt_voltage_range * 100.0 : MCMD_DEVS_BATT_NOINFO; uint8_t lmic_batt_level; + ESP_LOGD(TAG, "batt_voltage = %d mV / batt_level = %u%%", batt_voltage, + batt_percent); + + if (batt_percent != MCMD_DEVS_BATT_NOINFO) #ifdef HAS_PMU - if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO)) lmic_batt_level = pmu.isVBUSPlug() ? MCMD_DEVS_EXT_POWER - : batt_percent / 100 * batt_level_range; - else - lmic_batt_level = MCMD_DEVS_BATT_NOINFO; + : (float)batt_percent / (float)batt_level_range * 100.0; #else - if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO)) - lmic_batt_level = batt_percent / 100 * batt_level_range; + lmic_batt_level = (float)batt_percent / (float)batt_level_range * 100.0; +#endif // HAS_PMU else lmic_batt_level = MCMD_DEVS_BATT_NOINFO; -#endif // HAS_PMU // set battery level value for lmic stack #if (HAS_LORA) @@ -252,14 +252,13 @@ uint8_t read_battlevel() { bool batt_sufficient() { #if (defined HAS_PMU || defined BAT_MEASURE_ADC) - uint8_t my_batt_level = read_battlevel(); - switch (my_batt_level) { + switch (batt_level) { case MCMD_DEVS_EXT_POWER: return true; case MCMD_DEVS_BATT_NOINFO: return true; default: - return (my_batt_level > OTA_MIN_BATT); + return (batt_level > OTA_MIN_BATT); } #else return true; // we don't know batt level