From 2a6c8be68416d818b9b60e43ab15ceead297afe2 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 3 Oct 2023 10:09:27 -0500 Subject: [PATCH 01/32] Avoid problematic sleep state transitions for power saving sensors and trackers (#2860) * Avoid problematic sleep state transitions for power saving sensors and trackers * Line got duped :-| --- src/PowerFSM.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index b9c7586e4..c64599ce6 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -245,6 +245,8 @@ Fsm powerFSM(&stateBOOT); void PowerFSM_setup() { bool isRouter = (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER ? 1 : 0); + bool isTrackerOrSensor = config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR; bool hasPower = isPowered(); LOG_INFO("PowerFSM init, USB power=%d\n", hasPower ? 1 : 0); @@ -351,7 +353,9 @@ void PowerFSM_setup() // We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally) #ifdef ARCH_ESP32 // See: https://github.com/meshtastic/firmware/issues/1071 - if (isRouter || config.power.is_power_saving) { + // Don't add power saving transitions if we are a power saving tracker or sensor. Sleep will be initiatiated through the + // modules + if ((isRouter || config.power.is_power_saving) && !isTrackerOrSensor) { powerFSM.add_timed_transition(&stateNB, &stateLS, getConfiguredOrDefaultMs(config.power.min_wake_secs, default_min_wake_secs), NULL, "Min wake timeout"); From aa38f53aed372875bf820473bb2d99091120c46f Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 3 Oct 2023 12:05:40 -0500 Subject: [PATCH 02/32] Fix for T-Beam 1.2 GPS (#2858) * Fix for T-Beam 1.2 GPS, with DEBUG enabled * Don't break other devices * Saving GPS data on this breaks on next boot. Fix. * derp * disable the extra verbosity * Try the same sort of factory reset as the Lilygo image * Catch GPS reboots and squash * trunk * GPS --------- Co-authored-by: Ben Meadors --- platformio.ini | 2 +- src/gps/GPS.cpp | 130 +++++++++++++++++++++++++++------------ src/gps/GPS.h | 2 + variants/tbeam/variant.h | 1 + 4 files changed, 95 insertions(+), 40 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0a5029f9d..a6ad6f873 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,7 +70,7 @@ lib_deps = https://github.com/meshtastic/esp8266-oled-ssd1306.git#b38094e03dfa964fbc0e799bc374e91a605c1223 ; ESP8266_SSD1306 https://github.com/mathertel/OneButton#2.1.0 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 - https://github.com/meshtastic/TinyGPSPlus.git#127ad674ef85f0201cb68a065879653ed94792c4 + https://github.com/meshtastic/TinyGPSPlus.git#076e8d2c8fb702d9be5b08c55b93ff76f8af7e61 https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 nanopb/Nanopb@^0.4.7 erriez/ErriezCRC32@^1.0.1 diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 025e6007b..eb8cec1c9 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -76,28 +76,25 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis) while (millis() < startTimeout) { if (_serial_gps->available()) { b = _serial_gps->read(); +#ifdef GPS_DEBUG + LOG_DEBUG("%02X", (char *)buffer); +#endif buffer[bytesRead] = b; bytesRead++; if ((bytesRead == 767) || (b == '\r')) { if (strnstr((char *)buffer, message, bytesRead) != nullptr) { #ifdef GPS_DEBUG - buffer[bytesRead] = '\0'; - LOG_DEBUG("%s\r", (char *)buffer); + LOG_DEBUG("\r"); #endif return GNSS_RESPONSE_OK; } else { -#ifdef GPS_DEBUG - buffer[bytesRead] = '\0'; - LOG_INFO("Bytes read:%s\n", (char *)buffer); -#endif bytesRead = 0; } } } } #ifdef GPS_DEBUG - buffer[bytesRead] = '\0'; - LOG_INFO("Bytes read:%s\n", (char *)buffer); + LOG_DEBUG("\n"); #endif return GNSS_RESPONSE_NONE; } @@ -252,10 +249,18 @@ int GPS::getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t bool GPS::setup() { int msglen = 0; + bool isProblematicGPS = false; if (!didSerialInit) { #if !defined(GPS_UC6580) - if (tx_gpio) { +#ifdef HAS_PMU + // The T-Beam 1.2 has issues with the GPS + if (HW_VENDOR == meshtastic_HardwareModel_TBEAM && PMU->getChipModel() == XPOWERS_AXP2101) { + gnssModel = GNSS_MODEL_UBLOX; + isProblematicGPS = true; + } +#endif + if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { LOG_DEBUG("Probing for GPS at %d \n", serialSpeeds[speedSelect]); gnssModel = probe(serialSpeeds[speedSelect]); if (gnssModel == GNSS_MODEL_UNKNOWN) { @@ -390,32 +395,36 @@ bool GPS::setup() LOG_WARN("Unable to enable powersaving for GPS.\n"); } } else { - if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode has only been tested on this hardware - msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_PSM); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving mode for GPS.\n"); - } - msglen = makeUBXPacket(0x06, 0x3B, 44, _message_CFG_PM2); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x3B, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving details for GPS.\n"); - } - } else { - msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving ECO mode for GPS.\n"); + if (!(isProblematicGPS)) { + if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode has only been tested on this hardware + msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_PSM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving mode for GPS.\n"); + } + msglen = makeUBXPacket(0x06, 0x3B, 44, _message_CFG_PM2); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x3B, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving details for GPS.\n"); + } + } else { + msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving ECO mode for GPS.\n"); + } } } } - - msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE), _message_SAVE); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x09, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to save GNSS module configuration.\n"); - } else { - LOG_INFO("GNSS module configuration saved!\n"); + // The T-beam 1.2 has issues. + if (!(isProblematicGPS)) { + msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE), _message_SAVE); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x09, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to save GNSS module configuration.\n"); + } else { + LOG_INFO("GNSS module configuration saved!\n"); + } } } didSerialInit = true; @@ -635,6 +644,11 @@ int32_t GPS::runOnce() } } } + // At least one GPS has a bad habit of losing its mind from time to time + if (rebootsSeen > 2) { + rebootsSeen = 0; + gps->factoryReset(); + } // If we are overdue for an update, turn on the GPS and at least publish the current status uint32_t now = millis(); @@ -958,11 +972,38 @@ bool GPS::factoryReset() digitalWrite(PIN_GPS_REINIT, 1); #endif - // send the UBLOX Factory Reset Command regardless of detect state, something is very wrong, just assume it's UBLOX. - // Factory Reset - byte _message_reset[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, 0xFB, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x17, 0x2B, 0x7E}; - _serial_gps->write(_message_reset, sizeof(_message_reset)); + if (HW_VENDOR == meshtastic_HardwareModel_TBEAM) { + byte _message_reset1[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1C, 0xA2}; + _serial_gps->write(_message_reset1, sizeof(_message_reset1)); + if (getACK(0x05, 0x01, 10000)) { + LOG_INFO("Get ack success!\n"); + } + delay(100); + byte _message_reset2[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1B, 0xA1}; + _serial_gps->write(_message_reset2, sizeof(_message_reset2)); + if (getACK(0x05, 0x01, 10000)) { + LOG_INFO("Get ack success!\n"); + } + delay(100); + byte _message_reset3[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0x1D, 0xB3}; + _serial_gps->write(_message_reset3, sizeof(_message_reset3)); + if (getACK(0x05, 0x01, 10000)) { + LOG_INFO("Get ack success!\n"); + } + // Reset device ram to COLDSTART state + // byte _message_CFG_RST_COLDSTART[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0xFF, 0xB9, 0x00, 0x00, 0xC6, 0x8B}; + // _serial_gps->write(_message_CFG_RST_COLDSTART, sizeof(_message_CFG_RST_COLDSTART)); + // delay(1000); + } else { + // send the UBLOX Factory Reset Command regardless of detect state, something is very wrong, just assume it's UBLOX. + // Factory Reset + byte _message_reset[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, 0xFB, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x17, 0x2B, 0x7E}; + _serial_gps->write(_message_reset, sizeof(_message_reset)); + } delay(1000); return true; } @@ -1159,6 +1200,7 @@ bool GPS::hasFlow() bool GPS::whileIdle() { + int charsInBuf = 0; bool isValid = false; if (!isAwake) { clearBuffer(); @@ -1175,10 +1217,20 @@ bool GPS::whileIdle() // First consume any chars that have piled up at the receiver while (_serial_gps->available() > 0) { int c = _serial_gps->read(); - // LOG_DEBUG("%c", c); + UBXscratch[charsInBuf] = c; +#ifdef GPS_DEBUG + LOG_DEBUG("%c", c); +#endif isValid |= reader.encode(c); + if (charsInBuf > sizeof(UBXscratch) - 10 || c == '\r') { + if (strnstr((char *)UBXscratch, "$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50", charsInBuf)) { + rebootsSeen++; + } + charsInBuf = 0; + } else { + charsInBuf++; + } } - return isValid; } void GPS::enable() diff --git a/src/gps/GPS.h b/src/gps/GPS.h index bdd0b31a7..d52c79182 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -154,6 +154,8 @@ class GPS : private concurrency::OSThread // scratch space for creating ublox packets uint8_t UBXscratch[250] = {0}; + int rebootsSeen = 0; + int getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedID, uint32_t waitMillis); GPS_RESPONSE getACK(uint8_t c, uint8_t i, uint32_t waitMillis); GPS_RESPONSE getACK(const char *message, uint32_t waitMillis); diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 84a3477d4..a0ba70bfd 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -42,3 +42,4 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 +// #define GPS_DEBUG \ No newline at end of file From 7cebd79475b4b00187406ecde07429651947b8be Mon Sep 17 00:00:00 2001 From: code8buster <20384924+code8buster@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:50:27 +0000 Subject: [PATCH 03/32] Use doNotEnterOff flag to prevent GNSS poweroff before fix acquisition (#2861) Co-authored-by: Ben Meadors --- src/gps/ubx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gps/ubx.h b/src/gps/ubx.h index 2be2d1d33..bc839c41e 100644 --- a/src/gps/ubx.h +++ b/src/gps/ubx.h @@ -17,7 +17,7 @@ const uint8_t GPS::_message_CFG_RXM_ECO[] PROGMEM = { const uint8_t GPS::_message_CFG_PM2[] PROGMEM = { 0x01, 0x06, 0x00, 0x00, // version, Reserved - 0x0e, 0x81, 0x42, 0x01, // flags + 0x0E, 0x81, 0x43, 0x01, // flags 0xE8, 0x03, 0x00, 0x00, // update period 1000 ms 0x10, 0x27, 0x00, 0x00, // search period 10s 0x00, 0x00, 0x00, 0x00, // Grod offset 0 @@ -189,4 +189,4 @@ const uint8_t GPS::_message_SAVE[] = { 0xFF, 0xFF, 0x00, 0x00, // saveMask: save all sections 0x00, 0x00, 0x00, 0x00, // loadMask: no sections loaded 0x0F // deviceMask: BBR, Flash, EEPROM, and SPI Flash -}; \ No newline at end of file +}; From fbf74fc0b21842f25e681bd2e783588a59559520 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:23:55 -0500 Subject: [PATCH 04/32] [create-pull-request] automated change (#2863) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index fc48509e1..43b9f255e 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 10 +build = 11 From fc06754e1f9e66b88ed47dab86b6bdb20a8cd78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 5 Oct 2023 05:24:25 +0200 Subject: [PATCH 05/32] Possibly fix #2704 "Heltec Wireless Tracker screen doesn't display anything" (#2749) * fix #2704 Co-authored-by: Ben Meadors Co-authored-by: Jonathan Bennett --- src/Power.cpp | 12 ++++ src/graphics/TFTDisplay.cpp | 49 ++++++++++++++- src/main.cpp | 73 +++++++++++++++++++++- src/main.h | 2 + src/sleep.cpp | 8 ++- variants/heltec_wireless_tracker/variant.h | 20 ++++-- 6 files changed, 155 insertions(+), 9 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 57d6513a7..da2c9da93 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -175,9 +175,21 @@ class AnalogBatteryLevel : public HasBatteryLevel uint32_t raw = 0; #ifdef ARCH_ESP32 #ifndef BAT_MEASURE_ADC_UNIT // ADC1 +#ifdef ADC_CTRL + if (heltec_version == 5) { + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, HIGH); + delay(10); + } +#endif for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { raw += adc1_get_raw(adc_channel); } +#ifdef ADC_CTRL + if (heltec_version == 5) { + digitalWrite(ADC_CTRL, LOW); + } +#endif #else // ADC2 int32_t adc_buf = 0; for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 71ce35e82..5eec2b200 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -1,4 +1,5 @@ #include "configuration.h" +#include "main.h" #ifndef TFT_BACKLIGHT_ON #define TFT_BACKLIGHT_ON HIGH @@ -81,8 +82,16 @@ class LGFX : public lgfx::LGFX_Device { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. +#ifdef ST7735_BL_V03 + if (heltec_version == 3) { + cfg.pin_bl = ST7735_BL_V03; + } else { + cfg.pin_bl = ST7735_BL_V05; + } +#else cfg.pin_bl = ST7735_BL; // Pin number to which the backlight is connected - cfg.invert = true; // true to invert the brightness of the backlight +#endif + cfg.invert = true; // true to invert the brightness of the backlight // cfg.freq = 44100; // PWM frequency of backlight // cfg.pwm_channel = 1; // PWM channel number to use @@ -364,9 +373,23 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { +#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); + } +#endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #endif +#ifdef VTFT_CTRL_V03 + if (heltec_version == 3) { + digitalWrite(VTFT_CTRL_V03, LOW); + } else { + digitalWrite(VTFT_CTRL_V05, LOW); + } +#endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, LOW); #endif @@ -376,9 +399,23 @@ void TFTDisplay::sendCommand(uint8_t com) break; } case DISPLAYOFF: { +#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, !TFT_BACKLIGHT_ON); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, !TFT_BACKLIGHT_ON); + } +#endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #endif +#ifdef VTFT_CTRL_V03 + if (heltec_version == 3) { + digitalWrite(VTFT_CTRL_V03, HIGH); + } else { + digitalWrite(VTFT_CTRL_V05, HIGH); + } +#endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, HIGH); #endif @@ -436,6 +473,16 @@ bool TFTDisplay::connect() pinMode(TFT_BL, OUTPUT); #endif +#ifdef ST7735_BACKLIGHT_EN_V03 + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); + pinMode(ST7735_BACKLIGHT_EN_V03, OUTPUT); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); + pinMode(ST7735_BACKLIGHT_EN_V05, OUTPUT); + } +#endif + tft.init(); #if defined(M5STACK) tft.setRotation(0); diff --git a/src/main.cpp b/src/main.cpp index a4caad3fd..c9ba4c795 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,6 +146,25 @@ const char *getDeviceName() return name; } +#ifdef VEXT_ENABLE_V03 + +#include + +static uint32_t calibrate_one(rtc_cal_sel_t cal_clk, const char *name) +{ + const uint32_t cal_count = 1000; + uint32_t cali_val; + for (int i = 0; i < 5; ++i) { + cali_val = rtc_clk_cal(cal_clk, cal_count); + } + return cali_val; +} + +int heltec_version = 3; + +#define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) +#endif + static int32_t ledBlinker() { static bool ledOn; @@ -216,11 +235,63 @@ void setup() digitalWrite(PIN_EINK_PWR_ON, HIGH); #endif -#ifdef VEXT_ENABLE +#ifdef ST7735_BL_V03 // Heltec Wireless Tracker PCB Change Detect/Hack + + rtc_clk_32k_enable(true); + CALIBRATE_ONE(RTC_CAL_RTC_MUX); + if (CALIBRATE_ONE(RTC_CAL_32K_XTAL) != 0) { + rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL); + CALIBRATE_ONE(RTC_CAL_RTC_MUX); + CALIBRATE_ONE(RTC_CAL_32K_XTAL); + } + + if (rtc_clk_slow_freq_get() != RTC_SLOW_FREQ_32K_XTAL) { + heltec_version = 3; + } else { + heltec_version = 5; + } +#endif + +#if defined(VEXT_ENABLE_V03) + if (heltec_version == 3) { + pinMode(VEXT_ENABLE_V03, OUTPUT); + digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power + LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); + } else { + pinMode(VEXT_ENABLE_V05, OUTPUT); + digitalWrite(VEXT_ENABLE_V05, 1); // turn on the display power + LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); + } +#elif defined(VEXT_ENABLE) pinMode(VEXT_ENABLE, OUTPUT); digitalWrite(VEXT_ENABLE, 0); // turn on the display power #endif +#if defined(VGNSS_CTRL_V03) + if (heltec_version == 3) { + pinMode(VGNSS_CTRL_V03, OUTPUT); + digitalWrite(VGNSS_CTRL_V03, LOW); + } else { + pinMode(VGNSS_CTRL_V05, OUTPUT); + digitalWrite(VGNSS_CTRL_V05, LOW); + } +#endif + +#if defined(VTFT_CTRL_V03) + if (heltec_version == 3) { + pinMode(VTFT_CTRL_V03, OUTPUT); + digitalWrite(VTFT_CTRL_V03, LOW); + } else { + pinMode(VTFT_CTRL_V05, OUTPUT); + digitalWrite(VTFT_CTRL_V05, LOW); + } +#endif + +#if defined(VGNSS_CTRL) + pinMode(VGNSS_CTRL, OUTPUT); + digitalWrite(VGNSS_CTRL, LOW); +#endif + #if defined(VTFT_CTRL) pinMode(VTFT_CTRL, OUTPUT); digitalWrite(VTFT_CTRL, LOW); diff --git a/src/main.h b/src/main.h index 301e8a10c..3f0120406 100644 --- a/src/main.h +++ b/src/main.h @@ -64,6 +64,8 @@ extern uint32_t shutdownAtMsec; extern uint32_t serialSinceMsec; +extern int heltec_version; + // If a thread does something that might need for it to be rescheduled ASAP it can set this flag // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; diff --git a/src/sleep.cpp b/src/sleep.cpp index da3e43dcb..b0f4aec88 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -202,7 +202,13 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) digitalWrite(RESET_OLED, 1); // put the display in reset before killing its power #endif -#ifdef VEXT_ENABLE +#if defined(VEXT_ENABLE_V03) + if (heltec_version == 3) { + digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power + } else { + digitalWrite(VEXT_ENABLE_V05, 0); // turn off the display power + } +#elif defined(VEXT_ENABLE) digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index cfb752d03..4a1b61038 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -9,9 +9,11 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 45 +#define ST7735_BL_V03 45 +#define ST7735_BL_V05 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST -#define ST7735_BACKLIGHT_EN 45 +#define ST7735_BACKLIGHT_EN_V03 45 +#define ST7735_BACKLIGHT_EN_V05 21 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define SCREEN_ROTATE @@ -19,17 +21,20 @@ #define TFT_WIDTH 80 #define TFT_OFFSET_X 26 #define TFT_OFFSET_Y 0 -#define VTFT_CTRL 46 // Heltec Tracker needs this pulled low for TFT +#define VTFT_CTRL_V03 46 // Heltec Tracker needs this pulled low for TFT +#define VTFT_CTRL_V05 -1 #define SCREEN_TRANSITION_FRAMERATE 1 // fps #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ENABLE_V03 Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ENABLE_V05 3 // active HIGH, powers the oled display #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider #define ADC_MULTIPLIER 4.9 +#define ADC_CTRL 2 // active HIGH, powers the voltage divider. Only on 1.1 #undef GPS_RX_PIN #undef GPS_TX_PIN @@ -37,9 +42,12 @@ #define GPS_TX_PIN 34 #define PIN_GPS_RESET 35 #define PIN_GPS_PPS 36 -#define VGNSS_CTRL 37 // Heltec Tracker needs this pulled low for GPS -#define PIN_GPS_EN VGNSS_CTRL + +#define VGNSS_CTRL_V03 37 // Heltec Tracker needs this pulled low for GPS +#define VGNSS_CTRL_V05 -1 // Heltec Tracker needs this pulled low for GPS +#define PIN_GPS_EN VGNSS_CTRL_V03 #define GPS_EN_ACTIVE LOW + #define GPS_RESET_MODE LOW #define GPS_UC6580 From 950d5f09464fb6049c9e9c4c35a4b5c5205f4e73 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 5 Oct 2023 12:42:03 -0500 Subject: [PATCH 06/32] Power saving sensor (#2865) * Trunk * Again * This thing just keeps updating itself * Ignore tools * Sleepy sensor * Batrunkadunk --- .trunk/.gitignore | 2 +- .trunk/trunk.yaml | 26 +++++++++---------- src/modules/PositionModule.cpp | 4 +-- .../Telemetry/EnvironmentTelemetry.cpp | 15 +++++++++++ src/platform/nrf52/main-nrf52.cpp | 14 ++++++---- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/.trunk/.gitignore b/.trunk/.gitignore index 695b51906..1e2465290 100644 --- a/.trunk/.gitignore +++ b/.trunk/.gitignore @@ -2,7 +2,7 @@ *logs *actions *notifications +*tools plugins user_trunk.yaml user.yaml -tools diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 7e81046a7..f2de06f0d 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,48 +1,48 @@ version: 0.1 cli: - version: 1.13.0 + version: 1.16.2 plugins: sources: - id: trunk - ref: v1.1.1 + ref: v1.2.5 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@2.4.1 + - checkov@2.5.0 - terrascan@1.18.3 - - trivy@0.44.1 - - trufflehog@3.48.0 + - trivy@0.45.1 + - trufflehog@3.59.0 - taplo@0.8.1 - - ruff@0.0.284 + - ruff@0.0.292 - yamllint@1.32.0 - isort@5.12.0 - - markdownlint@0.35.0 + - markdownlint@0.37.0 - oxipng@8.0.0 - svgo@3.0.2 - - actionlint@1.6.25 + - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 - shfmt@3.6.0 - shellcheck@0.9.0 - - black@23.7.0 + - black@23.9.1 - git-diff-check - - gitleaks@8.17.0 + - gitleaks@8.18.0 - clang-format@16.0.3 - - prettier@3.0.2 + - prettier@3.0.3 disabled: - taplo@0.8.1 - shellcheck@0.9.0 - shfmt@3.6.0 - oxipng@8.0.0 - actionlint@1.6.22 - - markdownlint@0.35.0 + - markdownlint@0.37.0 - hadolint@2.12.0 - svgo@3.0.2 runtimes: enabled: - python@3.10.8 - - go@1.19.5 + - go@1.21.0 - node@18.12.1 actions: disabled: diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 29ddde4ce..a7beeda28 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -178,9 +178,9 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha service.sendToMesh(p, RX_SRC_LOCAL, true); if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving) { - LOG_DEBUG("Starting next execution in 3 seconds and then going to sleep.\n"); + LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n"); sleepOnNextExecution = true; - setIntervalFromNow(3000); + setIntervalFromNow(5000); } } diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 1f1a0cbf9..1047ade1d 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -8,6 +8,8 @@ #include "configuration.h" #include "main.h" #include "power.h" +#include "sleep.h" +#include "target_specific.h" #include #include @@ -51,6 +53,13 @@ SHT31Sensor sht31Sensor; int32_t EnvironmentTelemetryModule::runOnce() { + if (sleepOnNextExecution == true) { + sleepOnNextExecution = false; + uint32_t nightyNightMs = getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval); + LOG_DEBUG("Sleeping for %ims, then awaking to send metrics again.\n", nightyNightMs); + doDeepSleep(nightyNightMs, true); + } + uint32_t result = UINT32_MAX; /* Uncomment the preferences below if you want to use the module @@ -266,6 +275,12 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) } else { LOG_INFO("Sending packet to mesh\n"); service.sendToMesh(p, RX_SRC_LOCAL, true); + + if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) { + LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n"); + sleepOnNextExecution = true; + setIntervalFromNow(5000); + } } } return valid; diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 6b986c778..65b45f1e9 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -180,15 +180,19 @@ void cpuDeepSleep(uint32_t msecToWake) digitalWrite(AQ_SET_PIN, LOW); #endif #endif - // FIXME, use system off mode with ram retention for key state? - // FIXME, use non-init RAM per - // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled - - if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving == true) { + // Sleepy trackers or sensors can low power "sleep" + // Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event + if (msecToWake != portMAX_DELAY && + (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) && + config.power.is_power_saving == true) { sd_power_mode_set(NRF_POWER_MODE_LOWPWR); delay(msecToWake); NVIC_SystemReset(); } else { + // FIXME, use system off mode with ram retention for key state? + // FIXME, use non-init RAM per + // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled auto ok = sd_power_system_off(); if (ok != NRF_SUCCESS) { LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n"); From ef1d8c8eeed427cbd0fc3b61fee757f0e366598b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:51:23 -0500 Subject: [PATCH 07/32] [create-pull-request] automated change (#2869) --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 0fb2f8471..82f6b6083 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 0fb2f847141006c36d7e9d5118766f3a5da4225a +Subproject commit 82f6b6083f2445b07b07906bf5a91b38f1ee0d95 From 33f28c3d56a5d170456119451b347a067d57d3bd Mon Sep 17 00:00:00 2001 From: pat-trunk-io Date: Fri, 6 Oct 2023 13:02:27 -0700 Subject: [PATCH 08/32] Add trunk githooks to the repo (#2870) --- .trunk/trunk.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index f2de06f0d..7de96bd21 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -47,7 +47,7 @@ runtimes: actions: disabled: - trunk-announce - - trunk-check-pre-push - - trunk-fmt-pre-commit enabled: + - trunk-fmt-pre-commit + - trunk-check-pre-push - trunk-upgrade-available From dc6f0b8e0b639bdf1d8616fdaf45a3063368da45 Mon Sep 17 00:00:00 2001 From: pat-trunk-io Date: Fri, 6 Oct 2023 13:31:04 -0700 Subject: [PATCH 09/32] mention trunk is beta on windows (#2871) Co-authored-by: Ben Meadors --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 32f280a04..512dea311 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,7 +7,7 @@ is appreciated." This will allow other devs to potentially save you time by not accidentially duplicating work etc... - Please do not check in files that don't have real changes - Please do not reformat lines that you didn't have to change the code on -- We recommend using the [Visual Studio Code](https://platformio.org/install/ide?install=vscode) editor along with the ['Trunk Check' extension](https://marketplace.visualstudio.com/items?itemName=trunk.io) (WSL2 is required on windows), +- We recommend using the [Visual Studio Code](https://platformio.org/install/ide?install=vscode) editor along with the ['Trunk Check' extension](https://marketplace.visualstudio.com/items?itemName=trunk.io) (In beta for windows, WSL2 for the linux version), because it automatically follows our indentation rules and its auto reformatting will not cause spurious changes to lines. - If your PR fixes a bug, mention "fixes #bugnum" somewhere in your pull request description. - If your other co-developers have comments on your PR please tweak as needed. From 3ddad671a5f7053034627753cd542e87f6323713 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 08:12:42 -0500 Subject: [PATCH 10/32] [create-pull-request] automated change (#2875) Co-authored-by: thebentern --- protobufs | 2 +- src/mesh/generated/meshtastic/mesh.pb.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 82f6b6083..175a5c97f 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 82f6b6083f2445b07b07906bf5a91b38f1ee0d95 +Subproject commit 175a5c97fb608b28f100551d302603efd0c22185 diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index c32f55aab..7733e1d99 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -113,6 +113,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_PICOMPUTER_S3 = 52, /* Heltec HT-CT62 with ESP32-C3 CPU and SX1262 LoRa */ meshtastic_HardwareModel_HELTEC_HT62 = 53, + /* E22-900M series modules with ESP32-S3 */ + meshtastic_HardwareModel_E22_900M_S3 = 54, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ From 54f0c045e4a3c4fec3079bd0374407fd2df53fb2 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Mon, 9 Oct 2023 22:30:02 +1000 Subject: [PATCH 11/32] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d450b88d3..ca8a924fd 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ This repository contains the device firmware for the Meshtastic project. -**[Building Instructions](https://meshtastic.org/docs/development/firmware/build)** -**[Flashing Instructions](https://meshtastic.org/docs/getting-started/flashing-firmware/)** +- **[Building Instructions](https://meshtastic.org/docs/development/firmware/build)** +- **[Flashing Instructions](https://meshtastic.org/docs/getting-started/flashing-firmware/)** ## Stats From 8780d93941248add99aa0dd317b32f1f92c04ace Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 9 Oct 2023 13:30:51 -0500 Subject: [PATCH 12/32] Remove missed GPS definition (#2878) --- variants/heltec_wsl_v3/variant.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 240a482f7..417abf34d 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -8,8 +8,6 @@ #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 -#define PIN_GPS_EN 46 // GPS power enable pin - #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider From 10265aabd5214ae271e7c3827e08eaf4776cf56d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 9 Oct 2023 18:33:04 -0500 Subject: [PATCH 13/32] Fix buggy phone positions (#2876) * Guard-clause channel util. to reduce nesting * Try-fix PhoneAPI position not updating * Trunk * Missed it * Really disable GPS when asked to --------- Co-authored-by: Jonathan Bennett --- src/gps/GPS.cpp | 6 +- src/mesh/NodeDB.cpp | 2 +- src/mesh/NodeDB.h | 7 +++ src/modules/PositionModule.cpp | 108 +++++++++++++++++++-------------- 4 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index eb8cec1c9..ce5b18af8 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -611,7 +611,7 @@ int32_t GPS::runOnce() return 2000; // Setup failed, re-run in two seconds // We have now loaded our saved preferences from flash - if (config.position.gps_enabled == false && config.position.fixed_position == false) { + if (config.position.gps_enabled == false) { return disable(); } // ONCE we will factory reset the GPS for bug #327 @@ -703,8 +703,8 @@ int32_t GPS::runOnce() // If state has changed do a publish publishUpdate(); - if (config.position.gps_enabled == false) // This should trigger if GPS is disabled but fixed_position is true - return disable(); + if (config.position.fixed_position == true && hasValidLocation) + return disable(); // This should trigger when we have a fixed position, and get that first position // 9600bps is approx 1 byte per msec, so considering our buffer size we never need to wake more often than 200ms // if not awake we can run super infrquently (once every 5 secs?) to see if we need to wake. diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d7fd84fb7..3b6168f27 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -687,8 +687,8 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou LOG_INFO("updatePosition LOCAL pos@%x, time=%u, latI=%d, lonI=%d, alt=%d\n", p.timestamp, p.time, p.latitude_i, p.longitude_i, p.altitude); + setLocalPosition(p); info->position = ConvertToPositionLite(p); - localPosition = p; } else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.timestamp && !p.location_source) { // FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO // (stop-gap fix for issue #900) diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index f906acd58..22d5a7780 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -131,6 +131,13 @@ class NodeDB meshtastic_NodeInfoLite *getMeshNode(NodeNum n); size_t getNumMeshNodes() { return *numMeshNodes; } + void setLocalPosition(meshtastic_Position position) + { + LOG_DEBUG("Setting local position: latitude=%i, longitude=%i, time=%i\n", position.latitude_i, position.longitude_i, + position.time); + localPosition = position; + } + private: /// Find a node in our DB, create an empty NodeInfoLite if missing meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n); diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index a7beeda28..445bde42b 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -44,10 +44,11 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes // FIXME this can in fact happen with packets sent from EUD (src=RX_SRC_USER) // to set fixed location, EUD-GPS location or just the time (see also issue #900) + bool isLocal = false; if (nodeDB.getNodeNum() == getFrom(&mp)) { LOG_DEBUG("Incoming update from MYSELF\n"); - // LOG_DEBUG("Ignored an incoming update from MYSELF\n"); - // return false; + isLocal = true; + nodeDB.setLocalPosition(p); } // Log packet size and data fields @@ -64,7 +65,8 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes tv.tv_sec = secs; tv.tv_usec = 0; - perhapsSetRTC(RTCQualityFromNet, &tv); + // Set from phone RTC Quality to RTCQualityNTP since it should be approximately so + perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv); } nodeDB.updatePosition(getFrom(&mp), p); @@ -94,8 +96,9 @@ meshtastic_MeshPacket *PositionModule::allocReply() // Populate a Position struct with ONLY the requested fields meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure + // if localPosition is totally empty, put our last saved position (lite) in there if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) { - localPosition = ConvertToPosition(node->position); + nodeDB.setLocalPosition(ConvertToPosition(node->position)); } localPosition.seq_number++; @@ -184,6 +187,8 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha } } +#define RUNONCE_INTERVAL 5000; + int32_t PositionModule::runOnce() { if (sleepOnNextExecution == true) { @@ -199,60 +204,58 @@ int32_t PositionModule::runOnce() uint32_t now = millis(); uint32_t intervalMs = getConfiguredOrDefaultMs(config.position.position_broadcast_secs, default_broadcast_interval_secs); uint32_t msSinceLastSend = now - lastGpsSend; + // Only send packets if the channel util. is less than 25% utilized or we're a tracker with less than 40% utilized. + if (!airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER)) { + return RUNONCE_INTERVAL; + } if (lastGpsSend == 0 || msSinceLastSend >= intervalMs) { - // Only send packets if the channel is less than 40% utilized. - if (airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER)) { - if (hasValidPosition(node)) { - lastGpsSend = now; + if (hasValidPosition(node)) { + lastGpsSend = now; - lastGpsLatitude = node->position.latitude_i; - lastGpsLongitude = node->position.longitude_i; + lastGpsLatitude = node->position.latitude_i; + lastGpsLongitude = node->position.longitude_i; - // If we changed channels, ask everyone else for their latest info + // If we changed channels, ask everyone else for their latest info + bool requestReplies = currentGeneration != radioGeneration; + currentGeneration = radioGeneration; + + LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies); + sendOurPosition(NODENUM_BROADCAST, requestReplies); + } + } else if (config.position.position_broadcast_smart_enabled) { + const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position + + if (hasValidPosition(node2)) { + // The minimum time (in seconds) that would pass before we are able to send a new position packet. + const uint32_t minimumTimeThreshold = + getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30); + + auto smartPosition = getDistanceTraveledSinceLastSend(node->position); + + if (smartPosition.hasTraveledOverThreshold && msSinceLastSend >= minimumTimeThreshold) { bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies); + LOG_INFO("Sending smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, " + "minTimeInterval=%ims)\n", + localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold, + msSinceLastSend, minimumTimeThreshold); sendOurPosition(NODENUM_BROADCAST, requestReplies); - } - } - } else if (config.position.position_broadcast_smart_enabled) { - // Only send packets if the channel is less than 25% utilized or we're a tracker. - if (airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER)) { - const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position - if (hasValidPosition(node2)) { - // The minimum time (in seconds) that would pass before we are able to send a new position packet. - const uint32_t minimumTimeThreshold = - getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30); + // Set the current coords as our last ones, after we've compared distance with current and decided to send + lastGpsLatitude = node->position.latitude_i; + lastGpsLongitude = node->position.longitude_i; - auto smartPosition = getDistanceTraveledSinceLastSend(node->position); - - if (smartPosition.hasTraveledOverThreshold && msSinceLastSend >= minimumTimeThreshold) { - bool requestReplies = currentGeneration != radioGeneration; - currentGeneration = radioGeneration; - - LOG_INFO("Sending smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, " - "minTimeInterval=%ims)\n", - localPosition.timestamp, smartPosition.distanceTraveled, smartPosition.distanceThreshold, - msSinceLastSend, minimumTimeThreshold); - sendOurPosition(NODENUM_BROADCAST, requestReplies); - - // Set the current coords as our last ones, after we've compared distance with current and decided to send - lastGpsLatitude = node->position.latitude_i; - lastGpsLongitude = node->position.longitude_i; - - /* Update lastGpsSend to now. This means if the device is stationary, then - getPref_position_broadcast_secs will still apply. - */ - lastGpsSend = now; - } + /* Update lastGpsSend to now. This means if the device is stationary, then + getPref_position_broadcast_secs will still apply. + */ + lastGpsSend = now; } } } - return 5000; // to save power only wake for our callback occasionally + return RUNONCE_INTERVAL; // to save power only wake for our callback occasionally } struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition) @@ -264,6 +267,23 @@ struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic float distanceTraveledSinceLastSend = GeoCoord::latLongToMeter( lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, currentPosition.latitude_i * 1e-7, currentPosition.longitude_i * 1e-7); +#ifdef GPS_EXTRAVERBOSE + LOG_DEBUG("--------LAST POSITION------------------------------------\n"); + LOG_DEBUG("lastGpsLatitude=%i, lastGpsLatitude=%i\n", lastGpsLatitude, lastGpsLongitude); + + LOG_DEBUG("--------CURRENT POSITION---------------------------------\n"); + LOG_DEBUG("currentPosition.latitude_i=%i, currentPosition.longitude_i=%i\n", lastGpsLatitude, lastGpsLongitude); + + LOG_DEBUG("--------SMART POSITION-----------------------------------\n"); + LOG_DEBUG("hasTraveledOverThreshold=%i, distanceTraveled=%d, distanceThreshold=% u\n", + abs(distanceTraveledSinceLastSend) >= distanceTravelThreshold, abs(distanceTraveledSinceLastSend), + distanceTravelThreshold); + + if (abs(distanceTraveledSinceLastSend) >= distanceTravelThreshold) { + LOG_DEBUG("\n\n\nSMART SEEEEEEEEENDING\n\n\n"); + } +#endif + return SmartPosition{.distanceTraveled = abs(distanceTraveledSinceLastSend), .distanceThreshold = distanceTravelThreshold, .hasTraveledOverThreshold = abs(distanceTraveledSinceLastSend) >= distanceTravelThreshold}; From 87396d9105f8c45f63525787ffaeb84a91331d3a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 9 Oct 2023 20:43:16 -0500 Subject: [PATCH 14/32] Refactor away some code duplication in screen frames and display formatter for modem presets (#2872) * Refactor away some duplication * Refactor preset names to display formatter method * Remove unused screen brightness adjustment and extract wifi disconnect reason name to display formatter method * Tronk * Let's be more clear with this naming * Effed * DisplayFormatters static class and use native wifi disconnect reason names method * git mv file so casing should match now * Include titlecase * Trunk --- src/DisplayFormatters.cpp | 34 ++++++ src/DisplayFormatters.h | 8 ++ src/graphics/Screen.cpp | 232 ++++++++------------------------------ src/graphics/Screen.h | 5 +- src/mesh/Channels.cpp | 34 +----- 5 files changed, 95 insertions(+), 218 deletions(-) create mode 100644 src/DisplayFormatters.cpp create mode 100644 src/DisplayFormatters.h diff --git a/src/DisplayFormatters.cpp b/src/DisplayFormatters.cpp new file mode 100644 index 000000000..f15052de6 --- /dev/null +++ b/src/DisplayFormatters.cpp @@ -0,0 +1,34 @@ +#include "DisplayFormatters.h" + +const char *DisplayFormatters::getModemPresetDisplayName(meshtastic_Config_LoRaConfig_ModemPreset preset, bool useShortName) +{ + switch (preset) { + case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_SLOW: + return useShortName ? "ShortS" : "ShortSlow"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST: + return useShortName ? "ShortF" : "ShortFast"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_SLOW: + return useShortName ? "MedS" : "MediumSlow"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_FAST: + return useShortName ? "MedF" : "MediumFast"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_LONG_SLOW: + return useShortName ? "LongS" : "LongSlow"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST: + return useShortName ? "LongF" : "LongFast"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE: + return useShortName ? "LongM" : "LongMod"; + break; + case meshtastic_Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: + return useShortName ? "VeryL" : "VLongSlow"; + break; + default: + return useShortName ? "Custom" : "Invalid"; + break; + } +} \ No newline at end of file diff --git a/src/DisplayFormatters.h b/src/DisplayFormatters.h new file mode 100644 index 000000000..f8ccfcbb6 --- /dev/null +++ b/src/DisplayFormatters.h @@ -0,0 +1,8 @@ +#pragma once +#include "NodeDB.h" + +class DisplayFormatters +{ + public: + static const char *getModemPresetDisplayName(meshtastic_Config_LoRaConfig_ModemPreset preset, bool useShortName); +}; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 547d7f59e..b626e393a 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . #if HAS_SCREEN #include +#include "DisplayFormatters.h" #include "GPS.h" #include "MeshService.h" #include "NodeDB.h" @@ -160,34 +161,9 @@ static void drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDispl xstr(APP_VERSION_SHORT)); // Note: we don't bother printing region or now, it makes the string too long display->drawString(x + SCREEN_WIDTH - display->getStringWidth(buf), y + 0, buf); screen->forceDisplay(); - // FIXME - draw serial # somewhere? } -#ifdef ARCH_ESP32 -static void drawFrameResume(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -{ - uint16_t x_offset = display->width() / 2; - display->setTextAlignment(TEXT_ALIGN_CENTER); - display->setFont(FONT_MEDIUM); - display->drawString(x_offset + x, 26 + y, "Resuming..."); -} -#endif - -static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -{ -#ifdef ARCH_ESP32 - if (wakeCause == ESP_SLEEP_WAKEUP_TIMER || wakeCause == ESP_SLEEP_WAKEUP_EXT1) { - drawFrameResume(display, state, x, y); - } else -#endif - { - // Draw region in upper left - const char *region = myRegion ? myRegion->name : NULL; - drawIconScreen(region, display, state, x, y); - } -} - static void drawOEMIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { // draw an xbm image. @@ -237,6 +213,28 @@ static void drawOEMBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, i drawOEMIconScreen(region, display, state, x, y); } +static void drawFrameText(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y, const char *message) +{ + uint16_t x_offset = display->width() / 2; + display->setTextAlignment(TEXT_ALIGN_CENTER); + display->setFont(FONT_MEDIUM); + display->drawString(x_offset + x, 26 + y, message); +} + +static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ +#ifdef ARCH_ESP32 + if (wakeCause == ESP_SLEEP_WAKEUP_TIMER || wakeCause == ESP_SLEEP_WAKEUP_EXT1) { + drawFrameText(display, state, x, y, "Resuming..."); + } else +#endif + { + // Draw region in upper left + const char *region = myRegion ? myRegion->name : NULL; + drawIconScreen(region, display, state, x, y); + } +} + // Used on boot when a certificate is being created static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { @@ -337,22 +335,6 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state, display->drawString(x_offset + x, y_offset + y, deviceName); } -static void drawFrameShutdown(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -{ - uint16_t x_offset = display->width() / 2; - display->setTextAlignment(TEXT_ALIGN_CENTER); - display->setFont(FONT_MEDIUM); - display->drawString(x_offset + x, 26 + y, "Shutting down..."); -} - -static void drawFrameReboot(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -{ - uint16_t x_offset = display->width() / 2; - display->setTextAlignment(TEXT_ALIGN_CENTER); - display->setFont(FONT_MEDIUM); - display->drawString(x_offset + x, 26 + y, "Rebooting..."); -} - static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { display->setTextAlignment(TEXT_ALIGN_CENTER); @@ -923,20 +905,6 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ drawColumns(display, x, y, fields); } -// #ifdef RAK4630 -// Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), -// dispdev_oled(address, sda, scl), ui(&dispdev) -// { -// address_found = address; -// cmdQueue.setReader(this); -// if (screen_found) { -// (void)dispdev; -// AutoOLEDWire dispdev = dispdev_oled; -// (void)ui; -// OLEDDisplayUi ui(&dispdev); -// } -// } -// #else Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) : concurrency::OSThread("Screen"), address_found(address), model(screenType), geometry(geometry), cmdQueue(32), dispdev(address.address, -1, -1, geometry, (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE), @@ -944,7 +912,7 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O { cmdQueue.setReader(this); } -// #endif + /** * Prepare the display for the unit going to the lowest power mode possible. Most screens will just * poweroff, but eink screens will show a "I'm sleeping" graphic, possibly with a QR code @@ -1261,11 +1229,8 @@ void Screen::setWelcomeFrames() { if (address_found.address) { // LOG_DEBUG("showing Welcome frames\n"); - ui.disableAllIndicators(); - - static FrameCallback welcomeFrames[] = {drawWelcomeScreen}; - ui.setFrames(welcomeFrames, 1); - ui.update(); + static FrameCallback frames[] = {drawWelcomeScreen}; + setFrameImmediateDraw(frames); } } @@ -1352,12 +1317,15 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin) LOG_DEBUG("showing bluetooth screen\n"); showingNormalScreen = false; - static FrameCallback btFrames[] = {drawFrameBluetooth}; - + static FrameCallback frames[] = {drawFrameBluetooth}; snprintf(btPIN, sizeof(btPIN), "%06u", pin); + setFrameImmediateDraw(frames); +} +void Screen::setFrameImmediateDraw(FrameCallback *drawFrames) +{ ui.disableAllIndicators(); - ui.setFrames(btFrames, 1); + ui.setFrames(drawFrames, 1); setFastFramerate(); } @@ -1366,11 +1334,12 @@ void Screen::handleShutdownScreen() LOG_DEBUG("showing shutdown screen\n"); showingNormalScreen = false; - static FrameCallback shutdownFrames[] = {drawFrameShutdown}; + auto frame = [](OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -> void { + drawFrameText(display, state, x, y, "Shutting down..."); + }; + static FrameCallback frames[] = {frame}; - ui.disableAllIndicators(); - ui.setFrames(shutdownFrames, 1); - setFastFramerate(); + setFrameImmediateDraw(frames); } void Screen::handleRebootScreen() @@ -1378,11 +1347,11 @@ void Screen::handleRebootScreen() LOG_DEBUG("showing reboot screen\n"); showingNormalScreen = false; - static FrameCallback rebootFrames[] = {drawFrameReboot}; - - ui.disableAllIndicators(); - ui.setFrames(rebootFrames, 1); - setFastFramerate(); + auto frame = [](OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -> void { + drawFrameText(display, state, x, y, "Rebooting..."); + }; + static FrameCallback frames[] = {frame}; + setFrameImmediateDraw(frames); } void Screen::handleStartFirmwareUpdateScreen() @@ -1390,11 +1359,8 @@ void Screen::handleStartFirmwareUpdateScreen() LOG_DEBUG("showing firmware screen\n"); showingNormalScreen = false; - static FrameCallback btFrames[] = {drawFrameFirmware}; - - ui.disableAllIndicators(); - ui.setFrames(btFrames, 1); - setFastFramerate(); + static FrameCallback frames[] = {drawFrameFirmware}; + setFrameImmediateDraw(frames); } void Screen::blink() @@ -1655,65 +1621,8 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i } else { // Codes: // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reason-code - if (getWifiDisconnectReason() == 2) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Authentication Invalid"); - } else if (getWifiDisconnectReason() == 3) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "De-authenticated"); - } else if (getWifiDisconnectReason() == 4) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Disassociated Expired"); - } else if (getWifiDisconnectReason() == 5) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "AP - Too Many Clients"); - } else if (getWifiDisconnectReason() == 6) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "NOT_AUTHED"); - } else if (getWifiDisconnectReason() == 7) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "NOT_ASSOCED"); - } else if (getWifiDisconnectReason() == 8) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Disassociated"); - } else if (getWifiDisconnectReason() == 9) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "ASSOC_NOT_AUTHED"); - } else if (getWifiDisconnectReason() == 10) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "DISASSOC_PWRCAP_BAD"); - } else if (getWifiDisconnectReason() == 11) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "DISASSOC_SUPCHAN_BAD"); - } else if (getWifiDisconnectReason() == 13) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IE_INVALID"); - } else if (getWifiDisconnectReason() == 14) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "MIC_FAILURE"); - } else if (getWifiDisconnectReason() == 15) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "AP Handshake Timeout"); - } else if (getWifiDisconnectReason() == 16) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "GROUP_KEY_UPDATE_TIMEOUT"); - } else if (getWifiDisconnectReason() == 17) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IE_IN_4WAY_DIFFERS"); - } else if (getWifiDisconnectReason() == 18) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Invalid Group Cipher"); - } else if (getWifiDisconnectReason() == 19) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Invalid Pairwise Cipher"); - } else if (getWifiDisconnectReason() == 20) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "AKMP_INVALID"); - } else if (getWifiDisconnectReason() == 21) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "UNSUPP_RSN_IE_VERSION"); - } else if (getWifiDisconnectReason() == 22) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "INVALID_RSN_IE_CAP"); - } else if (getWifiDisconnectReason() == 23) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "802_1X_AUTH_FAILED"); - } else if (getWifiDisconnectReason() == 24) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "CIPHER_SUITE_REJECTED"); - } else if (getWifiDisconnectReason() == 200) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "BEACON_TIMEOUT"); - } else if (getWifiDisconnectReason() == 201) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "AP Not Found"); - } else if (getWifiDisconnectReason() == 202) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "AUTH_FAIL"); - } else if (getWifiDisconnectReason() == 203) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "ASSOC_FAIL"); - } else if (getWifiDisconnectReason() == 204) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "HANDSHAKE_TIMEOUT"); - } else if (getWifiDisconnectReason() == 205) { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Connection Failed"); - } else { - display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "Unknown Status"); - } + display->drawString(x, y + FONT_HEIGHT_SMALL * 1, + WiFi.disconnectReasonName(static_cast(getWifiDisconnectReason()))); } display->drawString(x, y + FONT_HEIGHT_SMALL * 2, "SSID: " + String(wifiName)); @@ -1760,37 +1669,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->drawString(x + 1, y, String("USB")); } - auto mode = ""; - - switch (config.lora.modem_preset) { - case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_SLOW: - mode = "ShortS"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST: - mode = "ShortF"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_SLOW: - mode = "MedS"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_FAST: - mode = "MedF"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_SLOW: - mode = "LongS"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST: - mode = "LongF"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE: - mode = "LongM"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: - mode = "VeryL"; - break; - default: - mode = "Custom"; - break; - } + auto mode = DisplayFormatters::getModemPresetDisplayName(config.lora.modem_preset, true); display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode), y, mode); if (config.display.heading_bold) @@ -1857,23 +1736,6 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat heartbeat = !heartbeat; #endif } -// adjust Brightness cycle through 1 to 254 as long as attachDuringLongPress is true -void Screen::adjustBrightness() -{ - if (!useDisplay) - return; - - if (brightness == 254) { - brightness = 0; - } else { - brightness++; - } - int width = brightness / (254.00 / SCREEN_WIDTH); - dispdev.drawRect(0, 30, SCREEN_WIDTH, 4); - dispdev.fillRect(0, 31, width, 2); - dispdev.display(); - dispdev.setBrightness(brightness); -} int Screen::handleStatusUpdate(const meshtastic::Status *arg) { diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 8812b7c70..d6fb7b5d3 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -19,7 +19,6 @@ class Screen void setup() {} void setOn(bool) {} void print(const char *) {} - void adjustBrightness() {} void doDeepSleep() {} void forceDisplay() {} void startBluetoothPinScreen(uint32_t pin) {} @@ -161,7 +160,6 @@ class Screen : public concurrency::OSThread void showNextFrame() { enqueueCmd(ScreenCmd{.cmd = Cmd::SHOW_NEXT_FRAME}); } // Implementation to Adjust Brightness - void adjustBrightness(); uint8_t brightness = BRIGHTNESS_DEFAULT; /// Starts showing the Bluetooth PIN screen. @@ -363,6 +361,9 @@ class Screen : public concurrency::OSThread /// Try to start drawing ASAP void setFastFramerate(); + // Sets frame up for immediate drawing + void setFrameImmediateDraw(FrameCallback *drawFrames); + /// Called when debug screen is to be drawn, calls through to debugInfo.drawFrame. static void drawDebugInfoTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 2a0b5ee39..9974297fa 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -1,5 +1,6 @@ #include "Channels.h" #include "CryptoEngine.h" +#include "DisplayFormatters.h" #include "NodeDB.h" #include "configuration.h" @@ -239,38 +240,9 @@ const char *Channels::getName(size_t chIndex) const char *channelName = channelSettings.name; if (!*channelName) { // emptystring // Per mesh.proto spec, if bandwidth is specified we must ignore modemPreset enum, we assume that in that case - // the app fucked up and forgot to set channelSettings.name - + // the app effed up and forgot to set channelSettings.name if (config.lora.use_preset) { - switch (config.lora.modem_preset) { - case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_SLOW: - channelName = "ShortSlow"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST: - channelName = "ShortFast"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_SLOW: - channelName = "MediumSlow"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_FAST: - channelName = "MediumFast"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_SLOW: - channelName = "LongSlow"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST: - channelName = "LongFast"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE: - channelName = "LongMod"; - break; - case meshtastic_Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: - channelName = "VLongSlow"; - break; - default: - channelName = "Invalid"; - break; - } + channelName = DisplayFormatters::getModemPresetDisplayName(config.lora.modem_preset, false); } else { channelName = "Custom"; } From d1ac2dc6ea21038a2bf18d3defdf7b94143897ee Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 9 Oct 2023 20:43:42 -0500 Subject: [PATCH 15/32] [create-pull-request] automated change (#2879) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 43b9f255e..4bc25ac89 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 11 +build = 12 From 786248a6b1442af352767af32c1b3896f750c135 Mon Sep 17 00:00:00 2001 From: Aciid <703382+Aciid@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:20:46 +0300 Subject: [PATCH 16/32] Dragino TrackerD wip (#2324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Dragino TrackerD initial variant * fmt --------- Co-authored-by: Thomas Göttgens Co-authored-by: Ben Meadors --- variants/trackerd/platformio.ini | 13 +++++++++ variants/trackerd/variant.h | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 variants/trackerd/platformio.ini create mode 100644 variants/trackerd/variant.h diff --git a/variants/trackerd/platformio.ini b/variants/trackerd/platformio.ini new file mode 100644 index 000000000..23868ffb4 --- /dev/null +++ b/variants/trackerd/platformio.ini @@ -0,0 +1,13 @@ +[env:trackerd] +extends = esp32_base +;platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream +platform = espressif32 +board = pico32 +board_build.f_flash = 80000000L +board_level = extra +build_flags = + ${esp32_base.build_flags} -D PRIVATE_HW -I variants/trackerd -D BSFILE=\"boards/dragino_lbt2.h\" +;board_build.partitions = no_ota.csv +;platform_packages = +; platformio/framework-arduinoespressif32@3 +;platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1-RC1 \ No newline at end of file diff --git a/variants/trackerd/variant.h b/variants/trackerd/variant.h new file mode 100644 index 000000000..b3fca367f --- /dev/null +++ b/variants/trackerd/variant.h @@ -0,0 +1,46 @@ +// Initialize i2c bus on sd_dat and esp_led pins, respectively. We need a bus to not hang on boot +#define HAS_SCREEN 0 +#define I2C_SDA 21 +#define I2C_SCL 22 + +#undef GPS_RX_PIN +#undef GPS_TX_PIN +#define GPS_RX_PIN 9 +#define GPS_TX_PIN 10 + +#define LED_PIN 13 // 13 red, 2 blue, 15 red + +//#define HAS_BUTTON 0 +#define BUTTON_PIN 0 +#define BUTTON_NEED_PULLUP + +#define USE_RF95 +#define LORA_DIO0 26 // a No connect on the SX1262 module +#define LORA_RESET 23 +#define LORA_DIO1 33 +#define LORA_DIO2 32 // Not really used + +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage + +// Battery +// The battery sense is hooked to pin A0 (4) +// it is defined in the anlaolgue pin section of this file +// and has 12 bit resolution +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +// Definition of milliVolt per LSB => 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 +#define VBAT_MV_PER_LSB (0.73242188F) +// Voltage divider value => 100K + 100K voltage divider on VBAT = (100K / (100K + 100K)) +#define VBAT_DIVIDER (0.5F) +// Compensation factor for the VBAT divider +#define VBAT_DIVIDER_COMP (2.0) +// Fixed calculation of milliVolt from compensation value +#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER VBAT_DIVIDER_COMP +#define VBAT_RAW_TO_SCALED(x) (REAL_VBAT_MV_PER_LSB * x) + +//#define BATTERY_SENSE_SAMPLES 15 // Set the number of samples, It has an effect of increasing sensitivity. +//#define ADC_MULTIPLIER 3.3 \ No newline at end of file From 9d1fe8c245b71247a6e8f2868a1642bdfe60aaa2 Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:35:07 +0100 Subject: [PATCH 17/32] Update architecture.h (#2880) --- src/platform/nrf52/architecture.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 904ab908d..e6eebc45b 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -46,6 +46,8 @@ #define HW_VENDOR meshtastic_HardwareModel_RAK4631 #elif defined(TTGO_T_ECHO) #define HW_VENDOR meshtastic_HardwareModel_T_ECHO +#elif defined(NANO_G2_ULTRA) +#define HW_VENDOR meshtastic_HardwareModel_NANO_G2_ULTRA #elif defined(NORDIC_PCA10059) #define HW_VENDOR meshtastic_HardwareModel_NRF52840_PCA10059 #elif defined(PRIVATE_HW) || defined(FEATHER_DIY) From e39f129bd6218454f7dce5fadb3e130b112d91f5 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 10 Oct 2023 19:33:58 -0500 Subject: [PATCH 18/32] More comprehensively clear current position info (#2881) --- src/modules/PositionModule.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 445bde42b..b40c8ed02 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -33,6 +33,9 @@ void PositionModule::clearPosition() meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); node->position.latitude_i = 0; node->position.longitude_i = 0; + node->position.altitude = 0; + node->position.time = 0; + nodeDB.setLocalPosition(meshtastic_Position_init_default); } bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Position *pptr) From 092c6cac66524af13ec2d5bf6a98d8b0aee63c76 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 11 Oct 2023 06:17:05 -0500 Subject: [PATCH 19/32] Convert from inline to static class methods (#2883) --- src/mesh/MeshService.cpp | 2 +- src/mesh/NodeDB.cpp | 4 +-- src/mesh/PhoneAPI.cpp | 2 +- src/mesh/TypeConversions.cpp | 55 +++++++++++++++++++++++++++++++ src/mesh/TypeConversions.h | 59 ++++++---------------------------- src/modules/PositionModule.cpp | 2 +- 6 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 src/mesh/TypeConversions.cpp diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 9d2ecdcee..038861937 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -335,7 +335,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) // Used fixed position if configured regalrdless of GPS lock if (config.position.fixed_position) { LOG_WARN("Using fixed position\n"); - pos = ConvertToPosition(node->position); + pos = TypeConversions::ConvertToPosition(node->position); } // Add a fresh timestamp diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 3b6168f27..09366facb 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -688,7 +688,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou p.longitude_i, p.altitude); setLocalPosition(p); - info->position = ConvertToPositionLite(p); + info->position = TypeConversions::ConvertToPositionLite(p); } else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.timestamp && !p.location_source) { // FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO // (stop-gap fix for issue #900) @@ -706,7 +706,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou uint32_t tmp_time = info->position.time; // Next, update atomically - info->position = ConvertToPositionLite(p); + info->position = TypeConversions::ConvertToPositionLite(p); // Last, restore any fields that may have been overwritten if (!info->position.time) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 672c6871e..5abcc8a31 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -405,7 +405,7 @@ bool PhoneAPI::available() if (nodeInfoForPhone.num == 0) { auto nextNode = nodeDB.readNextMeshNode(readIndex); if (nextNode) { - nodeInfoForPhone = ConvertToNodeInfo(nextNode); + nodeInfoForPhone = TypeConversions::ConvertToNodeInfo(nextNode); } } return true; // Always say we have something, because we might need to advance our state machine diff --git a/src/mesh/TypeConversions.cpp b/src/mesh/TypeConversions.cpp new file mode 100644 index 000000000..4e0fdd385 --- /dev/null +++ b/src/mesh/TypeConversions.cpp @@ -0,0 +1,55 @@ +#include "TypeConversions.h" +#include "mesh/generated/meshtastic/deviceonly.pb.h" +#include "mesh/generated/meshtastic/mesh.pb.h" + +meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite) +{ + meshtastic_NodeInfo info = meshtastic_NodeInfo_init_default; + + info.num = lite->num; + info.snr = lite->snr; + info.last_heard = lite->last_heard; + info.channel = lite->channel; + + if (lite->has_position) { + info.has_position = true; + info.position.latitude_i = lite->position.latitude_i; + info.position.longitude_i = lite->position.longitude_i; + info.position.altitude = lite->position.altitude; + info.position.location_source = lite->position.location_source; + info.position.time = lite->position.time; + } + if (lite->has_user) { + info.has_user = true; + info.user = lite->user; + } + if (lite->has_device_metrics) { + info.has_device_metrics = true; + info.device_metrics = lite->device_metrics; + } + return info; +} + +meshtastic_PositionLite TypeConversions::ConvertToPositionLite(meshtastic_Position position) +{ + meshtastic_PositionLite lite = meshtastic_PositionLite_init_default; + lite.latitude_i = position.latitude_i; + lite.longitude_i = position.longitude_i; + lite.altitude = position.altitude; + lite.location_source = position.location_source; + lite.time = position.time; + + return lite; +} + +meshtastic_Position TypeConversions::ConvertToPosition(meshtastic_PositionLite lite) +{ + meshtastic_Position position = meshtastic_Position_init_default; + position.latitude_i = lite.latitude_i; + position.longitude_i = lite.longitude_i; + position.altitude = lite.altitude; + position.location_source = lite.location_source; + position.time = lite.time; + + return position; +} \ No newline at end of file diff --git a/src/mesh/TypeConversions.h b/src/mesh/TypeConversions.h index bfc87102b..ffc3c12a7 100644 --- a/src/mesh/TypeConversions.h +++ b/src/mesh/TypeConversions.h @@ -1,54 +1,13 @@ #include "mesh/generated/meshtastic/deviceonly.pb.h" #include "mesh/generated/meshtastic/mesh.pb.h" -inline static meshtastic_NodeInfo ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite) +#pragma once +#include "NodeDB.h" + +class TypeConversions { - meshtastic_NodeInfo info = meshtastic_NodeInfo_init_default; - - info.num = lite->num; - info.snr = lite->snr; - info.last_heard = lite->last_heard; - info.channel = lite->channel; - - if (lite->has_position) { - info.has_position = true; - info.position.latitude_i = lite->position.latitude_i; - info.position.longitude_i = lite->position.longitude_i; - info.position.altitude = lite->position.altitude; - info.position.location_source = lite->position.location_source; - info.position.time = lite->position.time; - } - if (lite->has_user) { - info.has_user = true; - info.user = lite->user; - } - if (lite->has_device_metrics) { - info.has_device_metrics = true; - info.device_metrics = lite->device_metrics; - } - return info; -} - -inline static meshtastic_PositionLite ConvertToPositionLite(meshtastic_Position position) -{ - meshtastic_PositionLite lite = meshtastic_PositionLite_init_default; - lite.latitude_i = position.latitude_i; - lite.longitude_i = position.longitude_i; - lite.altitude = position.altitude; - lite.location_source = position.location_source; - lite.time = position.time; - - return lite; -} - -inline static meshtastic_Position ConvertToPosition(meshtastic_PositionLite lite) -{ - meshtastic_Position position = meshtastic_Position_init_default; - position.latitude_i = lite.latitude_i; - position.longitude_i = lite.longitude_i; - position.altitude = lite.altitude; - position.location_source = lite.location_source; - position.time = lite.time; - - return position; -} \ No newline at end of file + public: + static meshtastic_NodeInfo ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite); + static meshtastic_PositionLite ConvertToPositionLite(meshtastic_Position position); + static meshtastic_Position ConvertToPosition(meshtastic_PositionLite lite); +}; diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index b40c8ed02..69cd4848e 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -101,7 +101,7 @@ meshtastic_MeshPacket *PositionModule::allocReply() meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure // if localPosition is totally empty, put our last saved position (lite) in there if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) { - nodeDB.setLocalPosition(ConvertToPosition(node->position)); + nodeDB.setLocalPosition(TypeConversions::ConvertToPosition(node->position)); } localPosition.seq_number++; From def55ec0630fbca3ec5c8f254c1a5e6aaa4316a2 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 11 Oct 2023 10:21:38 -0500 Subject: [PATCH 20/32] Remove specific upload ports from pio --- variants/MakePython_nRF52840_eink/platformio.ini | 2 +- variants/betafpv_2400_tx_micro/platformio.ini | 2 +- variants/betafpv_900_tx_nano/platformio.ini | 2 +- variants/bpi_picow_esp32_s3/platformio.ini | 2 +- variants/heltec_esp32c3/platformio.ini | 4 ++-- variants/m5stack-stamp-c3/platformio.ini | 2 +- variants/m5stack_coreink/platformio.ini | 2 +- variants/my_esp32s3_diy_eink/platformio.ini | 2 +- variants/my_esp32s3_diy_oled/platformio.ini | 2 +- variants/rak4631_epaper_onrxtx/platformio.ini | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/variants/MakePython_nRF52840_eink/platformio.ini b/variants/MakePython_nRF52840_eink/platformio.ini index 2b08ec9a1..3ac18bcf0 100644 --- a/variants/MakePython_nRF52840_eink/platformio.ini +++ b/variants/MakePython_nRF52840_eink/platformio.ini @@ -11,4 +11,4 @@ lib_deps = https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f zinggjm/GxEPD2@^1.4.9 debug_tool = jlink -upload_port = /dev/ttyACM4 +;upload_port = /dev/ttyACM4 diff --git a/variants/betafpv_2400_tx_micro/platformio.ini b/variants/betafpv_2400_tx_micro/platformio.ini index decdb390e..82fe2a9e4 100644 --- a/variants/betafpv_2400_tx_micro/platformio.ini +++ b/variants/betafpv_2400_tx_micro/platformio.ini @@ -11,7 +11,7 @@ build_flags = -I variants/betafpv_2400_tx_micro board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyUSB0 +;upload_port = /dev/ttyUSB0 upload_speed = 460800 lib_deps = ${esp32_base.lib_deps} diff --git a/variants/betafpv_900_tx_nano/platformio.ini b/variants/betafpv_900_tx_nano/platformio.ini index e4c945cab..68e1a469b 100644 --- a/variants/betafpv_900_tx_nano/platformio.ini +++ b/variants/betafpv_900_tx_nano/platformio.ini @@ -10,7 +10,7 @@ build_flags = -I variants/betafpv_900_tx_nano board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyUSB0 +;upload_port = /dev/ttyUSB0 upload_speed = 460800 lib_deps = ${esp32_base.lib_deps} diff --git a/variants/bpi_picow_esp32_s3/platformio.ini b/variants/bpi_picow_esp32_s3/platformio.ini index 27c420df5..7e94cc97e 100644 --- a/variants/bpi_picow_esp32_s3/platformio.ini +++ b/variants/bpi_picow_esp32_s3/platformio.ini @@ -6,7 +6,7 @@ board_level = extra ;upload_protocol = esp-builtin ;Normal method upload_protocol = esptool -upload_port = /dev/ttyACM2 +;upload_port = /dev/ttyACM2 lib_deps = ${esp32_base.lib_deps} caveman99/ESP32 Codec2@^1.0.1 diff --git a/variants/heltec_esp32c3/platformio.ini b/variants/heltec_esp32c3/platformio.ini index a9843ef85..c9c80213e 100644 --- a/variants/heltec_esp32c3/platformio.ini +++ b/variants/heltec_esp32c3/platformio.ini @@ -8,5 +8,5 @@ build_flags = -I variants/heltec_esp32c3 monitor_speed = 115200 upload_protocol = esptool -upload_port = /dev/ttyUSB0 -upload_speed = 921600 +;upload_port = /dev/ttyUSB0 +upload_speed = 921600 \ No newline at end of file diff --git a/variants/m5stack-stamp-c3/platformio.ini b/variants/m5stack-stamp-c3/platformio.ini index b7cec5552..bab65b621 100644 --- a/variants/m5stack-stamp-c3/platformio.ini +++ b/variants/m5stack-stamp-c3/platformio.ini @@ -8,5 +8,5 @@ build_flags = -I variants/m5stack-stamp-c3 monitor_speed = 115200 upload_protocol = esptool -upload_port = /dev/ttyACM2 +;upload_port = /dev/ttyACM2 upload_speed = 921600 diff --git a/variants/m5stack_coreink/platformio.ini b/variants/m5stack_coreink/platformio.ini index 1a7926d7e..e6aef380c 100644 --- a/variants/m5stack_coreink/platformio.ini +++ b/variants/m5stack_coreink/platformio.ini @@ -23,4 +23,4 @@ lib_ignore = monitor_filters = esp32_exception_decoder board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyACM0 +;upload_port = /dev/ttyACM0 diff --git a/variants/my_esp32s3_diy_eink/platformio.ini b/variants/my_esp32s3_diy_eink/platformio.ini index 8405f784e..d3c55afda 100644 --- a/variants/my_esp32s3_diy_eink/platformio.ini +++ b/variants/my_esp32s3_diy_eink/platformio.ini @@ -6,7 +6,7 @@ board_build.arduino.memory_type = dio_opi board_build.mcu = esp32s3 board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyACM1 +;upload_port = /dev/ttyACM1 upload_speed = 921600 platform_packages = tool-esptoolpy@^1.40500.0 diff --git a/variants/my_esp32s3_diy_oled/platformio.ini b/variants/my_esp32s3_diy_oled/platformio.ini index 1430dfd96..9b8b09f7f 100644 --- a/variants/my_esp32s3_diy_oled/platformio.ini +++ b/variants/my_esp32s3_diy_oled/platformio.ini @@ -6,7 +6,7 @@ board_build.arduino.memory_type = dio_opi board_build.mcu = esp32s3 board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyACM0 +;upload_port = /dev/ttyACM0 upload_speed = 921600 platform_packages = tool-esptoolpy@^1.40500.0 diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 08c55d129..0a4f05344 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -15,4 +15,4 @@ lib_deps = debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink -upload_port = /dev/ttyACM3 +;upload_port = /dev/ttyACM3 From 1af970765fefd6e2765d4dae3ced0deea2c859bd Mon Sep 17 00:00:00 2001 From: Yurii Pyvovarov <3873062+yupyvovarov@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:31:10 +0300 Subject: [PATCH 21/32] Fix typo in tbeam-s3-core hwids address --- boards/tbeam-s3-core.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/tbeam-s3-core.json b/boards/tbeam-s3-core.json index 767791d35..7bda2e5a0 100644 --- a/boards/tbeam-s3-core.json +++ b/boards/tbeam-s3-core.json @@ -15,7 +15,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "dio", - "hwids": [["0X303A", "0x1001"]], + "hwids": [["0x303A", "0x1001"]], "mcu": "esp32s3", "variant": "tbeam-s3-core" }, From 9e203532d08a05c0694b15da029c70f5e2e162cd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 20:02:59 -0500 Subject: [PATCH 22/32] [create-pull-request] automated change (#2889) --- protobufs | 2 +- src/mesh/generated/meshtastic/config.pb.h | 11 ++++++++--- src/mesh/generated/meshtastic/mesh.pb.h | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/protobufs b/protobufs index 175a5c97f..6290ee0f6 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 175a5c97fb608b28f100551d302603efd0c22185 +Subproject commit 6290ee0f6aa15939ee582c3c59bc7a048cc0478f diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 2a811140f..9dcc14940 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -38,7 +38,12 @@ typedef enum _meshtastic_Config_DeviceConfig_Role { Telemetry Mesh packets will be prioritized higher and sent more frequently by default. When used in conjunction with power.is_power_saving = true, nodes will wake up, send environment telemetry, and then sleep for telemetry.environment_update_interval seconds. */ - meshtastic_Config_DeviceConfig_Role_SENSOR = 6 + meshtastic_Config_DeviceConfig_Role_SENSOR = 6, + /* TAK device role + Used for nodes dedicated for connection to an ATAK EUD. + Turns off many of the routine broadcasts to favor CoT packet stream + from the Meshtastic ATAK plugin -> IMeshService -> Node */ + meshtastic_Config_DeviceConfig_Role_TAK = 7 } meshtastic_Config_DeviceConfig_Role; /* Defines the device's behavior for how messages are rebroadcast */ @@ -474,8 +479,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_Config_DeviceConfig_Role_MIN meshtastic_Config_DeviceConfig_Role_CLIENT -#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_SENSOR -#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_SENSOR+1)) +#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_TAK +#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_TAK+1)) #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN meshtastic_Config_DeviceConfig_RebroadcastMode_ALL #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MAX meshtastic_Config_DeviceConfig_RebroadcastMode_LOCAL_ONLY diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 7733e1d99..dfaf693fc 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -113,8 +113,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_PICOMPUTER_S3 = 52, /* Heltec HT-CT62 with ESP32-C3 CPU and SX1262 LoRa */ meshtastic_HardwareModel_HELTEC_HT62 = 53, - /* E22-900M series modules with ESP32-S3 */ - meshtastic_HardwareModel_E22_900M_S3 = 54, + /* EBYTE SPI LoRa module and ESP32-S3 */ + meshtastic_HardwareModel_EBYTE_ESP32_S3 = 54, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ From f4b40562d33faaf966e1da035a3797b80887d0a9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 14 Oct 2023 06:49:38 -0500 Subject: [PATCH 23/32] Start of TAK role (#2890) * Start of TAK role * Position flags change for CoT friendly altitudes * Trunk --- .trunk/trunk.yaml | 2 +- src/mesh/NodeDB.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 7de96bd21..9c1dcf707 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,6 +1,6 @@ version: 0.1 cli: - version: 1.16.2 + version: 1.17.0 plugins: sources: - id: trunk diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 09366facb..9ca7f2fb2 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -285,6 +285,15 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role) } else if (role == meshtastic_Config_DeviceConfig_Role_SENSOR) { moduleConfig.telemetry.environment_measurement_enabled = true; moduleConfig.telemetry.environment_update_interval = 300; + } else if (role == meshtastic_Config_DeviceConfig_Role_TAK) { + config.device.node_info_broadcast_secs = ONE_DAY; + config.position.position_broadcast_smart_enabled = false; + config.position.position_broadcast_secs = ONE_DAY; + // Remove Altitude MSL from flags since CoTs use HAE (height above ellipsoid) + config.position.position_flags = + (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_SPEED | + meshtastic_Config_PositionConfig_PositionFlags_HEADING | meshtastic_Config_PositionConfig_PositionFlags_DOP); + moduleConfig.telemetry.device_update_interval = ONE_DAY; } } From 142d56c663f3c06764bd4a4d6461b41762bbcc99 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:33:45 +0200 Subject: [PATCH 24/32] allow sensors connected to second I2C port (#2891) --- src/Power.cpp | 10 ++++++---- src/detect/ScanI2CTwoWire.h | 4 ++-- src/main.cpp | 9 +++++---- src/modules/Modules.cpp | 2 +- src/modules/Telemetry/Sensor/BME280Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/BME280Sensor.h | 2 +- src/modules/Telemetry/Sensor/BME680Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/BME680Sensor.h | 2 +- src/modules/Telemetry/Sensor/BMP280Sensor.cpp | 3 ++- src/modules/Telemetry/Sensor/BMP280Sensor.h | 2 +- src/modules/Telemetry/Sensor/INA219Sensor.cpp | 4 ++-- src/modules/Telemetry/Sensor/INA219Sensor.h | 2 +- src/modules/Telemetry/Sensor/INA260Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/INA260Sensor.h | 2 +- src/modules/Telemetry/Sensor/LPS22HBSensor.cpp | 2 +- src/modules/Telemetry/Sensor/LPS22HBSensor.h | 2 +- src/modules/Telemetry/Sensor/MCP9808Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/MCP9808Sensor.h | 2 +- src/modules/Telemetry/Sensor/SHT31Sensor.h | 2 +- src/modules/Telemetry/Sensor/SHTC3Sensor.h | 2 +- src/modules/Telemetry/Sensor/TelemetrySensor.h | 13 ++++++++----- 21 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index da2c9da93..72bb38181 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -281,9 +281,10 @@ class AnalogBatteryLevel : public HasBatteryLevel #if defined(HAS_TELEMETRY) && !defined(ARCH_PORTDUINO) uint16_t getINAVoltage() { - if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219] == config.power.device_battery_ina_address) { + if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) { return ina219Sensor.getBusVoltageMv(); - } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260] == config.power.device_battery_ina_address) { + } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first == + config.power.device_battery_ina_address) { return ina260Sensor.getBusVoltageMv(); } return 0; @@ -294,11 +295,12 @@ class AnalogBatteryLevel : public HasBatteryLevel if (!config.power.device_battery_ina_address) { return false; } - if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219] == config.power.device_battery_ina_address) { + if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) { if (!ina219Sensor.isInitialized()) return ina219Sensor.runOnce() > 0; return ina219Sensor.isRunning(); - } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260] == config.power.device_battery_ina_address) { + } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first == + config.power.device_battery_ina_address) { if (!ina260Sensor.isInitialized()) return ina260Sensor.runOnce() > 0; return ina260Sensor.isRunning(); diff --git a/src/detect/ScanI2CTwoWire.h b/src/detect/ScanI2CTwoWire.h index 52c3cb085..9acd736d2 100644 --- a/src/detect/ScanI2CTwoWire.h +++ b/src/detect/ScanI2CTwoWire.h @@ -18,6 +18,8 @@ class ScanI2CTwoWire : public ScanI2C ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override; + TwoWire *fetchI2CBus(ScanI2C::DeviceAddress) const; + bool exists(ScanI2C::DeviceType) const override; size_t countDevices() const override; @@ -51,6 +53,4 @@ class ScanI2CTwoWire : public ScanI2C uint16_t getRegisterValue(const RegisterLocation &, ResponseWidth) const; DeviceType probeOLED(ScanI2C::DeviceAddress) const; - - TwoWire *fetchI2CBus(ScanI2C::DeviceAddress) const; }; diff --git a/src/main.cpp b/src/main.cpp index c9ba4c795..9b7d811c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ #include "target_specific.h" #include #include +#include // #include #include "mesh/eth/ethClient.h" @@ -122,9 +123,8 @@ uint32_t serialSinceMsec; bool pmu_found; -// Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan -uint8_t nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1] = { - 0}; // one is enough, missing elements will be initialized to 0 anyway. +// Array map of sensor types with i2c address and wire as we'll find in the i2c scan +std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1] = {}; Router *router = NULL; // Users of router don't care what sort of subclass implements that API @@ -491,7 +491,8 @@ void setup() { \ auto found = i2cScanner->find(SCANNER_T); \ if (found.type != ScanI2C::DeviceType::NONE) { \ - nodeTelemetrySensorsMap[PB_T] = found.address.address; \ + nodeTelemetrySensorsMap[PB_T].first = found.address.address; \ + nodeTelemetrySensorsMap[PB_T].second = i2cScanner->fetchI2CBus(found.address); \ LOG_DEBUG("found i2c sensor %s\n", STRING(PB_T)); \ } \ } diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 1780a8528..4c3d7eb61 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -88,7 +88,7 @@ void setupModules() #endif #if HAS_SENSOR new EnvironmentTelemetryModule(); - if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) { + if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I].first > 0) { new AirQualityTelemetryModule(); } #endif diff --git a/src/modules/Telemetry/Sensor/BME280Sensor.cpp b/src/modules/Telemetry/Sensor/BME280Sensor.cpp index 7bc65a418..a30614123 100644 --- a/src/modules/Telemetry/Sensor/BME280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME280Sensor.cpp @@ -13,7 +13,7 @@ int32_t BME280Sensor::runOnce() if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = bme280.begin(nodeTelemetrySensorsMap[sensorType]); + status = bme280.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second); bme280.setSampling(Adafruit_BME280::MODE_FORCED, Adafruit_BME280::SAMPLING_X1, // Temp. oversampling diff --git a/src/modules/Telemetry/Sensor/BME280Sensor.h b/src/modules/Telemetry/Sensor/BME280Sensor.h index 780dcdb61..2034c0a82 100644 --- a/src/modules/Telemetry/Sensor/BME280Sensor.h +++ b/src/modules/Telemetry/Sensor/BME280Sensor.h @@ -2,7 +2,7 @@ #include "TelemetrySensor.h" #include -class BME280Sensor : virtual public TelemetrySensor +class BME280Sensor : public TelemetrySensor { private: Adafruit_BME280 bme280; diff --git a/src/modules/Telemetry/Sensor/BME680Sensor.cpp b/src/modules/Telemetry/Sensor/BME680Sensor.cpp index 5b32645e6..323dce31f 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME680Sensor.cpp @@ -20,7 +20,7 @@ int32_t BME680Sensor::runOnce() if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if (!bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire)) + if (!bme680.begin(nodeTelemetrySensorsMap[sensorType].first, *nodeTelemetrySensorsMap[sensorType].second)) checkStatus("begin"); if (bme680.status == BSEC_OK) { diff --git a/src/modules/Telemetry/Sensor/BME680Sensor.h b/src/modules/Telemetry/Sensor/BME680Sensor.h index 06e24b1a9..4b7f84cf0 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.h +++ b/src/modules/Telemetry/Sensor/BME680Sensor.h @@ -6,7 +6,7 @@ #include "bme680_iaq_33v_3s_4d/bsec_iaq.h" -class BME680Sensor : virtual public TelemetrySensor +class BME680Sensor : public TelemetrySensor { private: Bsec2 bme680; diff --git a/src/modules/Telemetry/Sensor/BMP280Sensor.cpp b/src/modules/Telemetry/Sensor/BMP280Sensor.cpp index c0b5625de..408532388 100644 --- a/src/modules/Telemetry/Sensor/BMP280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BMP280Sensor.cpp @@ -13,7 +13,8 @@ int32_t BMP280Sensor::runOnce() if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]); + bmp280 = Adafruit_BMP280(nodeTelemetrySensorsMap[sensorType].second); + status = bmp280.begin(nodeTelemetrySensorsMap[sensorType].first); bmp280.setSampling(Adafruit_BMP280::MODE_FORCED, Adafruit_BMP280::SAMPLING_X1, // Temp. oversampling diff --git a/src/modules/Telemetry/Sensor/BMP280Sensor.h b/src/modules/Telemetry/Sensor/BMP280Sensor.h index cc8c0b9da..48581df8f 100644 --- a/src/modules/Telemetry/Sensor/BMP280Sensor.h +++ b/src/modules/Telemetry/Sensor/BMP280Sensor.h @@ -2,7 +2,7 @@ #include "TelemetrySensor.h" #include -class BMP280Sensor : virtual public TelemetrySensor +class BMP280Sensor : public TelemetrySensor { private: Adafruit_BMP280 bmp280; diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.cpp b/src/modules/Telemetry/Sensor/INA219Sensor.cpp index 1dd7f7f2c..5a1faa99f 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -13,8 +13,8 @@ int32_t INA219Sensor::runOnce() return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } if (!ina219.success()) { - ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType]); - status = ina219.begin(); + ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType].first); + status = ina219.begin(nodeTelemetrySensorsMap[sensorType].second); } else { status = ina219.success(); } diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.h b/src/modules/Telemetry/Sensor/INA219Sensor.h index f11a571cc..76f4613db 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.h +++ b/src/modules/Telemetry/Sensor/INA219Sensor.h @@ -3,7 +3,7 @@ #include "VoltageSensor.h" #include -class INA219Sensor : virtual public TelemetrySensor, VoltageSensor +class INA219Sensor : public TelemetrySensor, VoltageSensor { private: Adafruit_INA219 ina219; diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.cpp b/src/modules/Telemetry/Sensor/INA260Sensor.cpp index 034fecca0..89b7580d2 100644 --- a/src/modules/Telemetry/Sensor/INA260Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA260Sensor.cpp @@ -14,7 +14,7 @@ int32_t INA260Sensor::runOnce() } if (!status) { - status = ina260.begin(nodeTelemetrySensorsMap[sensorType]); + status = ina260.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second); } return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.h b/src/modules/Telemetry/Sensor/INA260Sensor.h index 8ea532697..28e8944bf 100644 --- a/src/modules/Telemetry/Sensor/INA260Sensor.h +++ b/src/modules/Telemetry/Sensor/INA260Sensor.h @@ -3,7 +3,7 @@ #include "VoltageSensor.h" #include -class INA260Sensor : virtual public TelemetrySensor, VoltageSensor +class INA260Sensor : public TelemetrySensor, VoltageSensor { private: Adafruit_INA260 ina260 = Adafruit_INA260(); diff --git a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp index 05f940656..6e30113cd 100644 --- a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp +++ b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp @@ -13,7 +13,7 @@ int32_t LPS22HBSensor::runOnce() if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType]); + status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/LPS22HBSensor.h b/src/modules/Telemetry/Sensor/LPS22HBSensor.h index 556d161c4..5b86539b1 100644 --- a/src/modules/Telemetry/Sensor/LPS22HBSensor.h +++ b/src/modules/Telemetry/Sensor/LPS22HBSensor.h @@ -3,7 +3,7 @@ #include #include -class LPS22HBSensor : virtual public TelemetrySensor +class LPS22HBSensor : public TelemetrySensor { private: Adafruit_LPS22 lps22hb; diff --git a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp index 28db3d8a9..c1d9bfa71 100644 --- a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp +++ b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp @@ -12,7 +12,7 @@ int32_t MCP9808Sensor::runOnce() if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]); + status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/MCP9808Sensor.h b/src/modules/Telemetry/Sensor/MCP9808Sensor.h index b70707477..c1029f8a7 100644 --- a/src/modules/Telemetry/Sensor/MCP9808Sensor.h +++ b/src/modules/Telemetry/Sensor/MCP9808Sensor.h @@ -2,7 +2,7 @@ #include "TelemetrySensor.h" #include -class MCP9808Sensor : virtual public TelemetrySensor +class MCP9808Sensor : public TelemetrySensor { private: Adafruit_MCP9808 mcp9808; diff --git a/src/modules/Telemetry/Sensor/SHT31Sensor.h b/src/modules/Telemetry/Sensor/SHT31Sensor.h index 60354aaea..940361325 100644 --- a/src/modules/Telemetry/Sensor/SHT31Sensor.h +++ b/src/modules/Telemetry/Sensor/SHT31Sensor.h @@ -2,7 +2,7 @@ #include "TelemetrySensor.h" #include -class SHT31Sensor : virtual public TelemetrySensor +class SHT31Sensor : public TelemetrySensor { private: Adafruit_SHT31 sht31 = Adafruit_SHT31(); diff --git a/src/modules/Telemetry/Sensor/SHTC3Sensor.h b/src/modules/Telemetry/Sensor/SHTC3Sensor.h index c67047396..e5db417f5 100644 --- a/src/modules/Telemetry/Sensor/SHTC3Sensor.h +++ b/src/modules/Telemetry/Sensor/SHTC3Sensor.h @@ -2,7 +2,7 @@ #include "TelemetrySensor.h" #include -class SHTC3Sensor : virtual public TelemetrySensor +class SHTC3Sensor : public TelemetrySensor { private: Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); diff --git a/src/modules/Telemetry/Sensor/TelemetrySensor.h b/src/modules/Telemetry/Sensor/TelemetrySensor.h index dec81e061..7282e6dfa 100644 --- a/src/modules/Telemetry/Sensor/TelemetrySensor.h +++ b/src/modules/Telemetry/Sensor/TelemetrySensor.h @@ -1,9 +1,12 @@ #pragma once #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "NodeDB.h" +#include + +class TwoWire; #define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 -extern uint8_t nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1]; +extern std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1]; class TelemetrySensor { @@ -16,7 +19,7 @@ class TelemetrySensor } const char *sensorName; - meshtastic_TelemetrySensorType sensorType; + meshtastic_TelemetrySensorType sensorType = meshtastic_TelemetrySensorType_SENSOR_UNSET; unsigned status; bool initialized = false; @@ -24,9 +27,9 @@ class TelemetrySensor { if (!status) { LOG_WARN("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName); - nodeTelemetrySensorsMap[sensorType] = 0; + nodeTelemetrySensorsMap[sensorType].first = 0; } else { - LOG_INFO("Opened %s sensor on default i2c bus\n", sensorName); + LOG_INFO("Opened %s sensor on i2c bus\n", sensorName); setup(); } initialized = true; @@ -35,7 +38,7 @@ class TelemetrySensor virtual void setup(); public: - bool hasSensor() { return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0; } + bool hasSensor() { return nodeTelemetrySensorsMap[sensorType].first > 0; } virtual int32_t runOnce() = 0; virtual bool isInitialized() { return initialized; } From 2c625f6ba1dd18f4102c45d7c0f3fb573378daa8 Mon Sep 17 00:00:00 2001 From: Andre K Date: Sun, 15 Oct 2023 08:41:40 -0300 Subject: [PATCH 25/32] fix: channel routing for decoded MQTT packets (#2892) Co-authored-by: Ben Meadors --- src/mqtt/MQTT.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index f369f873f..cbaba45d6 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -133,10 +133,16 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) if (strcmp(e.gateway_id, owner.id) == 0) LOG_INFO("Ignoring downlink message we originally sent.\n"); else { - if (e.packet) { + // Find channel by channel_id and check downlink_enabled + meshtastic_Channel ch = channels.getByName(e.channel_id); + if (strcmp(e.channel_id, channels.getGlobalId(ch.index)) == 0 && e.packet && ch.settings.downlink_enabled) { LOG_INFO("Received MQTT topic %s, len=%u\n", topic, length); meshtastic_MeshPacket *p = packetPool.allocCopy(*e.packet); + if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + p->channel = ch.index; + } + // ignore messages sent by us or if we don't have the channel key if (router && p->from != nodeDB.getNodeNum() && perhapsDecode(p)) router->enqueueReceivedMessage(p); From e6b20bff771b5c72174cf8f04e6a8c31bd0726e3 Mon Sep 17 00:00:00 2001 From: Andre K Date: Sun, 15 Oct 2023 20:56:47 -0300 Subject: [PATCH 26/32] refactor: simplify MQTT defaults (#2893) Co-authored-by: Ben Meadors --- src/mesh/NodeDB.cpp | 2 ++ src/mesh/NodeDB.h | 1 + src/mesh/Router.cpp | 23 +++-------------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 9ca7f2fb2..2046c2cea 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -254,6 +254,8 @@ void NodeDB::installDefaultModuleConfig() strncpy(moduleConfig.mqtt.address, default_mqtt_address, sizeof(moduleConfig.mqtt.address)); strncpy(moduleConfig.mqtt.username, default_mqtt_username, sizeof(moduleConfig.mqtt.username)); strncpy(moduleConfig.mqtt.password, default_mqtt_password, sizeof(moduleConfig.mqtt.password)); + strncpy(moduleConfig.mqtt.root, default_mqtt_root, sizeof(moduleConfig.mqtt.root)); + moduleConfig.mqtt.encryption_enabled = true; moduleConfig.has_neighbor_info = true; moduleConfig.neighbor_info.enabled = false; diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 22d5a7780..5fca0e440 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -204,6 +204,7 @@ extern NodeDB nodeDB; #define default_mqtt_address "mqtt.meshtastic.org" #define default_mqtt_username "meshdev" #define default_mqtt_password "large4cats" +#define default_mqtt_root "msh" inline uint32_t getConfiguredOrDefaultMs(uint32_t configuredInterval) { diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 03aa57351..b2d8d585d 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -249,29 +249,12 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it - bool shouldActuallyEncrypt = true; - if (moduleConfig.mqtt.enabled) { - // check if we should send decrypted packets to mqtt - // truth table: - /* mqtt_server mqtt_encryption_enabled should_encrypt - * not set 0 1 - * not set 1 1 - * set 0 0 - * set 1 1 - * - * => so we only decrypt mqtt if they have a custom mqtt server AND mqtt_encryption_enabled is FALSE - */ - - if (*moduleConfig.mqtt.address && !moduleConfig.mqtt.encryption_enabled) { - shouldActuallyEncrypt = false; - } - - LOG_INFO("Should encrypt MQTT?: %d\n", shouldActuallyEncrypt); + LOG_INFO("Should encrypt MQTT?: %d\n", moduleConfig.mqtt.encryption_enabled); // the packet is currently in a decrypted state. send it now if they want decrypted packets - if (mqtt && !shouldActuallyEncrypt) + if (mqtt && !moduleConfig.mqtt.encryption_enabled) mqtt->onSend(*p, chIndex); } @@ -284,7 +267,7 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) if (moduleConfig.mqtt.enabled) { // the packet is now encrypted. // check if we should send encrypted packets to mqtt - if (mqtt && shouldActuallyEncrypt) + if (mqtt && moduleConfig.mqtt.encryption_enabled) mqtt->onSend(*p, chIndex); } } From 092e6f2424aac486267c15e1c94f18c36093017a Mon Sep 17 00:00:00 2001 From: Tavis Date: Tue, 17 Oct 2023 01:50:36 -1000 Subject: [PATCH 27/32] add rssi and snr to json output (#2894) * add rssi and snr to json output * explicitly cast to int and float --- src/mqtt/MQTT.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index cbaba45d6..a9e80c947 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -692,6 +692,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) jsonObj["channel"] = new JSONValue((uint)mp->channel); jsonObj["type"] = new JSONValue(msgType.c_str()); jsonObj["sender"] = new JSONValue(owner.id); + if (mp->rx_rssi != 0) + jsonObj["rssi"] = new JSONValue((int)mp->rx_rssi); + if (mp->rx_snr != 0) + jsonObj["snr"] = new JSONValue((float)mp->rx_snr); // serialize and write it to the stream JSONValue *value = new JSONValue(jsonObj); From 227467f638397ea42742f104816c60afdef6fac0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:52:56 -0500 Subject: [PATCH 28/32] [create-pull-request] automated change (#2897) Co-authored-by: thebentern --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 4bc25ac89..006a90013 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 12 +build = 13 From a60b4d08bfaf678006156e028fdc7caf52420f17 Mon Sep 17 00:00:00 2001 From: S5NC <145265251+S5NC@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:47:36 +0100 Subject: [PATCH 29/32] Hydra variant rectification (#2903) * Update variant.h * Update variant.h * Update platformio.ini --- variants/diy/hydra/variant.h | 54 ++++++++++++++++-------------------- variants/diy/platformio.ini | 2 -- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/variants/diy/hydra/variant.h b/variants/diy/hydra/variant.h index 98c1c2ae1..601bca310 100644 --- a/variants/diy/hydra/variant.h +++ b/variants/diy/hydra/variant.h @@ -2,44 +2,38 @@ #define I2C_SDA 21 #define I2C_SCL 22 -// GPS -#undef GPS_RX_PIN -#undef GPS_TX_PIN -#define GPS_RX_PIN 12 +// For GPS, 'undef's not needed #define GPS_TX_PIN 15 -#define GPS_UBLOX +#define GPS_RX_PIN 12 #define PIN_GPS_EN 4 +#define GPS_POWER_TOGGLE // Moved definition from platformio.ini to here #define BUTTON_PIN 39 // The middle button GPIO on the T-Beam #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define ADC_MULTIPLIER 1.85 // (R1 = 470k, R2 = 680k) -#define EXT_PWR_DETECT 4 // Pin to detect connected external power source for LILYGO® TTGO T-Energy T18 and other DIY boards -#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Module (#975). -#define LED_PIN 2 // add status LED (compatible with core-pcb and DIY targets) +#define EXT_PWR_DETECT 4 // Pin to detect connected external power source for LILYGO® TTGO T-Energy T18 and other DIY boards +#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Module (#975). +#define LED_PIN 2 // add status LED (compatible with core-pcb and DIY targets) -#define LORA_DIO0 26 // a No connect on the SX1262/SX1268 module -#define LORA_RESET 23 // RST for SX1276, and for SX1262/SX1268 -#define LORA_DIO1 33 // IRQ for SX1262/SX1268 -#define LORA_DIO2 32 // BUSY for SX1262/SX1268 -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled +// Radio +#define USE_SX1262 // E22-900M30S uses SX1262 +#define SX126X_MAX_POWER 22 // Outputting 22dBm from SX1262 results in ~30dBm E22-900M30S output (module only uses last stage of the YP2233W PA) +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 // E22 series TCXO reference voltage is 1.8V -#define RF95_SCK 5 -#define RF95_MISO 19 -#define RF95_MOSI 27 -#define RF95_NSS 18 +#define SX126X_CS 18 // EBYTE module's NSS pin +#define SX126X_SCK 5 // EBYTE module's SCK pin +#define SX126X_MOSI 27 // EBYTE module's MOSI pin +#define SX126X_MISO 19 // EBYTE module's MISO pin +#define SX126X_RESET 23 // EBYTE module's NRST pin +#define SX126X_BUSY 32 // EBYTE module's BUSY pin +#define SX126X_DIO1 33 // EBYTE module's DIO1 pin -#define USE_SX1262 +#define SX126X_TXEN 13 // Schematic connects EBYTE module's TXEN pin to MCU +#define SX126X_RXEN 14 // Schematic connects EBYTE module's RXEN pin to MCU -#define SX126X_CS 18 // NSS for SX126X -#define SX126X_DIO1 LORA_DIO1 -#define SX126X_BUSY LORA_DIO2 -#define SX126X_RESET LORA_RESET -#define SX126X_RXEN 14 -#define SX126X_TXEN RADIOLIB_NC -#define SX126X_DIO2_AS_RF_SWITCH - -// Set lora.tx_power to 13 for Hydra or other E22 900M30S target due to PA -#define SX126X_MAX_POWER 13 - -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define RF95_NSS SX126X_CS // Compatibility with variant file configuration structure +#define RF95_SCK SX126X_SCK // Compatibility with variant file configuration structure +#define RF95_MOSI SX126X_MOSI // Compatibility with variant file configuration structure +#define RF95_MISO SX126X_MISO // Compatibility with variant file configuration structure +#define LORA_DIO1 SX126X_DIO1 // Compatibility with variant file configuration structure diff --git a/variants/diy/platformio.ini b/variants/diy/platformio.ini index cb031f266..e7d72d13f 100644 --- a/variants/diy/platformio.ini +++ b/variants/diy/platformio.ini @@ -43,6 +43,4 @@ board_level = extra build_flags = ${esp32_base.build_flags} -D DIY_V1 - -D EBYTE_E22 - -D GPS_POWER_TOGGLE -I variants/diy/hydra From b36ffe520048bf1079a7af30cc2d354628cd0355 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 24 Oct 2023 18:52:46 -0500 Subject: [PATCH 30/32] Trunk fmt fix --- variants/diy/hydra/variant.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/variants/diy/hydra/variant.h b/variants/diy/hydra/variant.h index 601bca310..64bdd73f7 100644 --- a/variants/diy/hydra/variant.h +++ b/variants/diy/hydra/variant.h @@ -12,14 +12,15 @@ #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define ADC_MULTIPLIER 1.85 // (R1 = 470k, R2 = 680k) -#define EXT_PWR_DETECT 4 // Pin to detect connected external power source for LILYGO® TTGO T-Energy T18 and other DIY boards -#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Module (#975). -#define LED_PIN 2 // add status LED (compatible with core-pcb and DIY targets) +#define EXT_PWR_DETECT 4 // Pin to detect connected external power source for LILYGO® TTGO T-Energy T18 and other DIY boards +#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Module (#975). +#define LED_PIN 2 // add status LED (compatible with core-pcb and DIY targets) // Radio #define USE_SX1262 // E22-900M30S uses SX1262 -#define SX126X_MAX_POWER 22 // Outputting 22dBm from SX1262 results in ~30dBm E22-900M30S output (module only uses last stage of the YP2233W PA) -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 // E22 series TCXO reference voltage is 1.8V +#define SX126X_MAX_POWER \ + 22 // Outputting 22dBm from SX1262 results in ~30dBm E22-900M30S output (module only uses last stage of the YP2233W PA) +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 // E22 series TCXO reference voltage is 1.8V #define SX126X_CS 18 // EBYTE module's NSS pin #define SX126X_SCK 5 // EBYTE module's SCK pin @@ -32,8 +33,8 @@ #define SX126X_TXEN 13 // Schematic connects EBYTE module's TXEN pin to MCU #define SX126X_RXEN 14 // Schematic connects EBYTE module's RXEN pin to MCU -#define RF95_NSS SX126X_CS // Compatibility with variant file configuration structure -#define RF95_SCK SX126X_SCK // Compatibility with variant file configuration structure +#define RF95_NSS SX126X_CS // Compatibility with variant file configuration structure +#define RF95_SCK SX126X_SCK // Compatibility with variant file configuration structure #define RF95_MOSI SX126X_MOSI // Compatibility with variant file configuration structure #define RF95_MISO SX126X_MISO // Compatibility with variant file configuration structure #define LORA_DIO1 SX126X_DIO1 // Compatibility with variant file configuration structure From 4052194dfefd3eed88b313128606488636e9ea80 Mon Sep 17 00:00:00 2001 From: Ric In New Mexico <78682404+RicInNewMexico@users.noreply.github.com> Date: Thu, 26 Oct 2023 05:25:06 -0600 Subject: [PATCH 31/32] Fix for is_licensed save / reboot (#2911) * Fix is_licensed save / reboot * Revert "Fix is_licensed save / reboot" This reverts commit 634151b8ec6f4063dc95966102234ef7aba8cefd. * Changed reloadConfig to saveChanges /w reboot --- src/modules/AdminModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 27b539f38..f25e8db33 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -676,7 +676,7 @@ void AdminModule::handleSetHamMode(const meshtastic_HamParameters &p) channels.onConfigChanged(); service.reloadOwner(false); - service.reloadConfig(SEGMENT_CONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); + saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); } AdminModule::AdminModule() : ProtobufModule("Admin", meshtastic_PortNum_ADMIN_APP, &meshtastic_AdminMessage_msg) From 8b8fffda81ef1dc1211955c9d0ff66225ef8abb9 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:12:22 +0100 Subject: [PATCH 32/32] Drop packets if `toPhoneQueue` is full, unless it's text/RangeTest (#2918) --- src/mesh/MeshService.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 038861937..44094f1bb 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -267,14 +267,22 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) void MeshService::sendToPhone(meshtastic_MeshPacket *p) { + perhapsDecode(p); + if (toPhoneQueue.numFree() == 0) { - LOG_WARN("ToPhone queue is full, discarding oldest\n"); - meshtastic_MeshPacket *d = toPhoneQueue.dequeuePtr(0); - if (d) - releaseToPool(d); + if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP || + p->decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP) { + LOG_WARN("ToPhone queue is full, discarding oldest\n"); + meshtastic_MeshPacket *d = toPhoneQueue.dequeuePtr(0); + if (d) + releaseToPool(d); + } else { + LOG_WARN("ToPhone queue is full, dropping packet.\n"); + releaseToPool(p); + return; + } } - perhapsDecode(p); assert(toPhoneQueue.enqueue(p, 0)); fromNum++; }