diff --git a/include/globals.h b/include/globals.h index a3edad17..d76d0e4c 100644 --- a/include/globals.h +++ b/include/globals.h @@ -42,8 +42,7 @@ #define SCREEN_MODE (0x80) // I2C bus access control -#define I2C_MUTEX_LOCK() \ - xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(3 * DISPLAYREFRESH_MS)) == pdTRUE +#define I2C_MUTEX_LOCK() xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE #define I2C_MUTEX_UNLOCK() xSemaphoreGive(I2Caccess) // Struct holding devices's runtime configuration diff --git a/platformio.ini b/platformio.ini index ad4f16a7..554960bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,6 +26,7 @@ halfile = generic.h ;halfile = lolin32lora.h ;halfile = lolin32lite.h ;halfile = wemos32oled.h +;halfile = wemos32matrix.h ;halfile = octopus32.h [platformio] @@ -41,7 +42,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.7.8 +release_version = 1.7.82 ; 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 @@ -50,8 +51,6 @@ otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h platform_espressif32 = espressif32@1.9.0 -board_build.partitions = min_spiffs.csv -board = esp32dev monitor_speed = 115200 upload_speed = 115200 lib_deps_lora = @@ -97,11 +96,11 @@ build_flags_all = -mfix-esp32-psram-cache-issue [env] -board = ${common.board} +framework = arduino +board = esp32dev +board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} platform = ${common.platform_espressif32} -framework = arduino -board_build.partitions = ${common.board_build.partitions} lib_deps = ${common.lib_deps_all} build_flags = ${common.build_flags_all} upload_protocol = ${common.upload_protocol} diff --git a/src/button.cpp b/src/button.cpp index 1765928e..6e52173e 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -28,19 +28,12 @@ void button_init(int pin) { #ifdef HAS_MATRIX_DISPLAY refreshTheMatrixDisplay(true); // switch to next display page #endif - -#if (!defined HAS_DISPLAY) && (!defined HAS_MATRIX_DISPLAY) - payload.reset(); - payload.addButton(0x01); - SendPayload(BUTTONPORT, prio_normal); -#endif }); b->setOnHolding([]() { -#if (HAS_LORA) - cfg.adrmode = !cfg.adrmode; - LMIC_setAdrMode(cfg.adrmode); -#endif + payload.reset(); + payload.addButton(0x01); + SendPayload(BUTTONPORT, prio_normal); }); // attach interrupt to the button diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 936590e5..1287d485 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -22,14 +22,14 @@ void defaultConfig() { WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] cfg.blescantime = BLESCANINTERVAL / - 10; // BT channel scan cycle [seconds/100], default 1 (= 10ms) - cfg.blescan = 0; // 0=disabled, 1=enabled - cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) - cfg.vendorfilter = 1; // 0=disabled, 1=enabled - cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) - cfg.monitormode = 0; // 0=disabled, 1=enabled - cfg.runmode = 0; // 0=normal, 1=update - cfg.payloadmask = 0xFF; // all payload switched on + 10; // BT channel scan cycle [seconds/100], default 1 (= 10ms) + cfg.blescan = BLECOUNTER; // 0=disabled, 1=enabled + cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) + cfg.vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled + cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) + cfg.monitormode = 0; // 0=disabled, 1=enabled + cfg.runmode = 0; // 0=normal, 1=update + cfg.payloadmask = 0xFF; // all payload switched on cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = { 0}; // init BSEC state for BME680 sensor diff --git a/src/display.cpp b/src/display.cpp index 2c1c3048..0c1a9422 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -306,12 +306,12 @@ void draw_page(time_t t, uint8_t page) { wasnofix = false; } // line 3-4: GPS latitude - snprintf(buff, sizeof(buff), "%c%-07.4f", + snprintf(buff, sizeof(buff), "%c%07.4f", gps.location.rawLat().negative ? 'S' : 'N', gps.location.lat()); u8x8.draw2x2String(0, 3, buff); // line 6-7: GPS longitude - snprintf(buff, sizeof(buff), "%c%-07.4f", + snprintf(buff, sizeof(buff), "%c%07.4f", gps.location.rawLat().negative ? 'W' : 'E', gps.location.lng()); u8x8.draw2x2String(0, 6, buff); @@ -334,7 +334,7 @@ void draw_page(time_t t, uint8_t page) { #if (HAS_BME) // line 2-3: Temp - snprintf(buff, sizeof(buff), "TMP:%--4.1f", bme_status.temperature); + snprintf(buff, sizeof(buff), "TMP:%-4.1f", bme_status.temperature); u8x8.draw2x2String(0, 2, buff); // line 4-5: Hum diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 142eef08..1bc8f343 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -79,13 +79,12 @@ void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) { if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) { - /* nmea telegram serial delay compensation; not sure if we need this? + // nmea telegram serial delay compensation; not sure if we need this? - if (gps.time.age() > nmea_txDelay_ms) - gps_store.timedate.Second = gps.time.second() + 1; - else - gps_store.timedate.Second = gps.time.second(); - */ + if (gps.time.age() > nmea_txDelay_ms) + gps_store.timedate.Second = gps.time.second() + 1; + else + gps_store.timedate.Second = gps.time.second(); gps_store.timedate.Second = gps.time.second(); gps_store.timedate.Minute = gps.time.minute(); diff --git a/src/hal/wemos32matrix.h b/src/hal/wemos32matrix.h new file mode 100644 index 00000000..66935f00 --- /dev/null +++ b/src/hal/wemos32matrix.h @@ -0,0 +1,47 @@ +// clang-format off +// upload_speed 921600 +// board lolin32 + +#ifndef _WEMOS32MATRIX_H +#define _WEMOS32MATRIX_H + +#include + +#define HAS_LED NOT_A_PIN // no LED + +// LED Matrix display settings +#define HAS_MATRIX_DISPLAY 1 // Uncomment to enable LED matrix display output +#define LED_MATRIX_WIDTH 64 // Width in pixels (LEDs) of your display +#define LED_MATRIX_HEIGHT 16 // Height in pixels (LEDs ) of your display + +// Pin numbers work fine for Wemos Lolin32 board (all used pins are on 1 side of the board) +// Explanation of pin signals see https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/new-wiring +#define MATRIX_DISPLAY_SCAN_US 500 // Matrix display scan rate in microseconds (1ms is about 'acceptable') +#define LED_MATRIX_LATCHPIN 13 // LAT (or STB = Strobe) +#define LED_MATRIX_CLOCKPIN 32 // CLK +#define LED_MATRIX_EN_74138 12 // EN (or OE) +#define LED_MATRIX_LA_74138 14 // LA (or A) +#define LED_MATRIX_LB_74138 27 // LB (or B) +#define LED_MATRIX_LC_74138 25 // LC (or C) +#define LED_MATRIX_LD_74138 26 // LD (or D) +#define LED_MATRIX_DATA_R1 33 // R1 (or R0) + +// CLK: The clock signal moves the data bits from pin R1 ("red") in the shift registers +// LAT: The latch signal enables LEDs according to the shift register's contents +// Line Selects: LA, LB, LC, LD select which rows of the display are currently lit (0 .. 15) +// OE: Output enable switches the LEDs on/off while transitioning from one row to the next + +/* +How it works: + +1. clock out 8 bytes for columns via R1 and CLK (8 * 8 bit -> 64 columns) +2. OE disable (LEDs off) +3. select line to lit with LA/LB/LC/LD hex coded (4 bit -> 16 rows) +4. latch data from shift registers to columns +5. OE enable (LEDs on) +6. repeat with step1 for next line +*/ + +#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature + +#endif \ No newline at end of file diff --git a/src/hal/wemos32oled.h b/src/hal/wemos32oled.h index 49911a37..3b59e450 100644 --- a/src/hal/wemos32oled.h +++ b/src/hal/wemos32oled.h @@ -7,41 +7,14 @@ #include -// Hardware related definitions for TTGO T-Beam board -// (only) for older T-Beam version T22_V05 eternal wiring LORA_IO1 to GPIO33 is needed! -// -// pinouts taken from http://tinymicros.com/wiki/TTGO_T-Beam - #define HAS_LED NOT_A_PIN // no LED -//#define HAS_LORA 1 // comment out if device shall not send data via LoRa -//#define CFG_sx1276_radio 1 // HPD13A LoRa SoC -//#define BOARD_HAS_PSRAM // use extra 4MB external RAM -//#define HAS_BUTTON GPIO_NUM_39 // on board button (next to reset) -//#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 - -// GPS settings -//#define HAS_GPS 1 // use on board GPS -//#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M -//#define GPS_INT GPIO_NUM_34 // 30ns accurary timepulse, to be external wired on pcb: NEO 6M Pin#3 -> GPIO34 - -// enable only if device has these sensors, otherwise comment these lines -// BME680 sensor on I2C bus -//#define HAS_BME 1 // Enable BME sensors in general -//#define HAS_BME680 SDA, SCL -//#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !! - -// display (if connected) #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C #define MY_OLED_SDA (5) #define MY_OLED_SCL (4) #define MY_OLED_RST U8X8_PIN_NONE #define DISPLAY_FLIP 1 // use if display is rotated -// user defined sensors (if connected) -//#define HAS_SENSORS 1 // comment out if device has user defined sensors - #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature #endif diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index 9d8e6ec5..f95f6fe9 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -121,13 +121,16 @@ void IRAM_ATTR GpsIRQ() { int mask_user_IRQ() { // begin of time critical section: lock I2C bus to ensure accurate timing - if (!I2C_MUTEX_LOCK()) + if (I2C_MUTEX_LOCK()) { + xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); + return 0; + } else return 1; // failure - xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); } int unmask_user_IRQ() { // end of time critical section: release I2C bus I2C_MUTEX_UNLOCK(); xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); -} + return 0; +} \ No newline at end of file diff --git a/src/ledmatrixdisplay.cpp b/src/ledmatrixdisplay.cpp index 5eb55934..3cfe31f2 100644 --- a/src/ledmatrixdisplay.cpp +++ b/src/ledmatrixdisplay.cpp @@ -21,9 +21,9 @@ uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / NUMCHARS]; // --- SELECT YOUR FONT HERE --- const FONT_INFO *ActiveFontInfo = &digital7_18ptFontInfo; -//const FONT_INFO *ActiveFontInfo = &arialNarrow_17ptFontInfo; -//const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_18ptFontInfo; -//const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_16ptFontInfo; +// const FONT_INFO *ActiveFontInfo = &arialNarrow_17ptFontInfo; +// const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_18ptFontInfo; +// const FONT_INFO *ActiveFontInfo = &gillSansMTCondensed_16ptFontInfo; const uint8_t *iaActiveFont = ActiveFontInfo->Bitmap; const FONT_CHAR_INFO *ActiveFontCharInfo = ActiveFontInfo->Descriptors; @@ -68,6 +68,7 @@ void refreshTheMatrixDisplay(bool nextPage) { matrix.clear(); DrawNumber(String(ulLastNumMacs)); } + break; case 1: @@ -79,6 +80,7 @@ void refreshTheMatrixDisplay(bool nextPage) { second(t)); DrawNumber(String(buff)); } + break; } // switch page diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 40dddb3f..5507e12b 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -183,7 +183,6 @@ void showLoraKeys(void) { void onEvent(ev_t ev) { char buff[24] = ""; - uint32_t now_micros = 0; switch (ev) { @@ -421,7 +420,7 @@ esp_err_t lora_stack_init() { return ESP_FAIL; } ESP_LOGI(TAG, "LORA send queue created, size %d Bytes", - SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); + SEND_QUEUE_SIZE * sizeof(MessageBuffer_t)); ESP_LOGI(TAG, "Starting LMIC..."); @@ -460,7 +459,7 @@ void lora_enqueuedata(MessageBuffer_t *message, sendprio_t prio) { switch (prio) { case prio_high: // clear space in queue if full, then fallthrough to normal - if (uxQueueSpacesAvailable == 0) + if (uxQueueSpacesAvailable(LoraSendQueue) == 0) xQueueReceive(LoraSendQueue, &DummyBuffer, (TickType_t)0); case prio_normal: ret = xQueueSendToFront(LoraSendQueue, (void *)message, (TickType_t)0); diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 395f7c79..13b6c0b7 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -106,21 +106,4 @@ #define CAYENNE_ACTUATOR 10 // actuator commands #define CAYENNE_DEVICECONFIG 11 // device period configuration #define CAYENNE_SENSORREAD 13 // sensor period configuration -#define CAYENNE_SENSORENABLE 14 // sensor enable configuration - -// LED Matrix display settings. -// Note: LED Matrix will only show number of found devices, no other information will be shown for now -//#define HAS_MATRIX_DISPLAY 1 // Uncomment to enable LED matrix display output -#define LED_MATRIX_WIDTH 64 // Width in pixels (LEDs) of your display -#define LED_MATRIX_HEIGHT 16 // Height in pixels (LEDs ) of your display - -// Pin numbers work fine for Wemos Lolin32 board (all used pins are on 1 side of the board) -#define MATRIX_DISPLAY_SCAN_US 500 // Matrix display scan rate in microseconds (1ms is about 'acceptable') -#define LED_MATRIX_LATCHPIN 13 // Connects to LAT pin on display -#define LED_MATRIX_CLOCKPIN 32 // Connects to CLK pin on display -#define LED_MATRIX_EN_74138 12 // Connects to OE pin on display -#define LED_MATRIX_LA_74138 14 // Connects to LA pin on display -#define LED_MATRIX_LB_74138 27 // Connects to LB pin on display -#define LED_MATRIX_LC_74138 25 // Connects to LC pin on display -#define LED_MATRIX_LD_74138 26 // Connects to LD pin on display -#define LED_MATRIX_DATA_R1 33 // Connects to R1 pin on display \ No newline at end of file +#define CAYENNE_SENSORENABLE 14 // sensor enable configuration \ No newline at end of file diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index a6130ad9..750f9c5a 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -47,21 +47,23 @@ IRAM_ATTR void wifi_sniffer_packet_handler(void *buff, // Software-timer driven Wifi channel rotation callback function void switchWifiChannel(TimerHandle_t xTimer) { - channel = - (channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX - esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); - } + channel = + (channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX + esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); +} void wifi_sniffer_init(void) { wifi_init_config_t wificfg = WIFI_INIT_CONFIG_DEFAULT(); wificfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM wificfg.wifi_task_core_id = 0; // we want wifi task running on core 0 - wifi_promiscuous_filter_t filter = { - // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames - .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames - ESP_ERROR_CHECK(esp_coex_preference_set( - ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib + // wifi_promiscuous_filter_t filter = { + // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames + // .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames + + wifi_promiscuous_filter_t filter = {.filter_mask = + WIFI_PROMIS_FILTER_MASK_MGMT | + WIFI_PROMIS_FILTER_MASK_DATA}; ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg ESP_ERROR_CHECK(