diff --git a/.gitignore b/.gitignore index e9d3cfdf9..be3ca3397 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ __pycache__ venv/ release/ +.vscode/extensions.json diff --git a/boards/tbeam-s3-core.json b/boards/tbeam-s3-core.json index ee66650fc..06d93c6a0 100644 --- a/boards/tbeam-s3-core.json +++ b/boards/tbeam-s3-core.json @@ -43,4 +43,4 @@ }, "url": "http://www.lilygo.cn/", "vendor": "LilyGo" -} +} \ No newline at end of file diff --git a/src/Power.cpp b/src/Power.cpp index 5b379f3c6..d2c5b01a0 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -102,6 +102,10 @@ class AnalogBatteryLevel : public HasBatteryLevel #define ADC_MULTIPLIER 2.0 #endif +#ifndef BATTERY_SENSE_SAMPLES +#define BATTERY_SENSE_SAMPLES 30 +#endif + #ifdef BATTERY_PIN // Override variant or default ADC_MULTIPLIER if we have the override pref float operativeAdcMultiplier = config.power.adc_multiplier_override > 0 @@ -112,16 +116,12 @@ class AnalogBatteryLevel : public HasBatteryLevel if (millis() - last_read_time_ms > min_read_interval) { last_read_time_ms = millis(); -#ifdef BATTERY_SENSE_SAMPLES //Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic environment. uint32_t raw = 0; - for(uint32_t i=0; igetBattVoltage() < MIN_BAT_MILLIVOLTS) { low_voltage_counter++; - if (low_voltage_counter > 3) - powerFSM.trigger(EVENT_LOW_BATTERY); + DEBUG_MSG("Warning RAK4631 Low voltage counter: %d/10\n", low_voltage_counter); + if (low_voltage_counter > 10) { + // We can't trigger deep sleep on NRF52, it's freezing the board + //powerFSM.trigger(EVENT_LOW_BATTERY); + DEBUG_MSG("Low voltage detected, but not triggering deep sleep\n"); + } } else { low_voltage_counter = 0; } @@ -573,11 +577,15 @@ bool Power::axpChipInit() } DEBUG_MSG("=======================================================================\n"); - - +// We can safely ignore this approach for most (or all) boards because MCU turned off +// earlier than battery discharged to 2.6V. +// +// Unfortanly for now we can't use this killswitch for RAK4630-based boards because they have a bug with +// battery voltage measurement. Probably it sometimes drops to low values. +#ifndef RAK4630 // Set PMU shutdown voltage at 2.6V to maximize battery utilization PMU->setSysPowerDownVoltage(2600); - +#endif #ifdef PMU_IRQ diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index dd3992a14..647167242 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -34,7 +34,7 @@ static void sdsEnter() { DEBUG_MSG("Enter state: SDS\n"); // FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw - doDeepSleep(config.power.sds_secs * 1000); + doDeepSleep(getConfiguredOrDefaultMs(config.power.sds_secs)); } extern Power *power; @@ -324,11 +324,6 @@ void PowerFSM_setup() powerFSM.add_transition(&stateDARK, &stateDARK, EVENT_CONTACT_FROM_PHONE, NULL, "Contact from phone"); - // each time we get a new update packet make sure we are staying in the ON state so the screen stays awake (also we don't - // shutdown bluetooth if is_router) - powerFSM.add_transition(&stateDARK, &stateON, EVENT_FIRMWARE_UPDATE, NULL, "Got firmware update"); - powerFSM.add_transition(&stateON, &stateON, EVENT_FIRMWARE_UPDATE, NULL, "Got firmware update"); - powerFSM.add_timed_transition(&stateON, &stateDARK, getConfiguredOrDefaultMs(config.display.screen_on_secs, default_screen_on_secs), NULL, "Screen-on timeout"); // On most boards we use light-sleep to be our main state, but on NRF52 we just stay in DARK @@ -341,14 +336,15 @@ void PowerFSM_setup() if (isRouter || config.power.is_power_saving) { powerFSM.add_timed_transition(&stateNB, &stateLS, getConfiguredOrDefaultMs(config.power.min_wake_secs, default_min_wake_secs), NULL, "Min wake timeout"); powerFSM.add_timed_transition(&stateDARK, &stateLS, getConfiguredOrDefaultMs(config.power.wait_bluetooth_secs, default_wait_bluetooth_secs), NULL, "Bluetooth timeout"); - } + } + + if (config.power.sds_secs != UINT32_MAX) + powerFSM.add_timed_transition(lowPowerState, &stateSDS, getConfiguredOrDefaultMs(config.power.sds_secs), NULL, "mesh timeout"); #elif defined (ARCH_NRF52) lowPowerState = &stateDARK; #endif - if (config.power.sds_secs != UINT32_MAX) - powerFSM.add_timed_transition(lowPowerState, &stateSDS, config.power.sds_secs * 1000, NULL, "mesh timeout"); powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state } diff --git a/src/PowerFSMThread.h b/src/PowerFSMThread.h index 36bee834d..f45eec2f7 100644 --- a/src/PowerFSMThread.h +++ b/src/PowerFSMThread.h @@ -26,11 +26,9 @@ class PowerFSMThread : public OSThread if (powerStatus->getHasUSB()) { timeLastPowered = millis(); - } else if (config.power.on_battery_shutdown_after_secs > 0 && - millis() > - timeLastPowered + - (1000 * - config.power.on_battery_shutdown_after_secs)) { // shutdown after 30 minutes unpowered + } else if (config.power.on_battery_shutdown_after_secs > 0 && + config.power.on_battery_shutdown_after_secs != UINT32_MAX && + millis() > (timeLastPowered + getConfiguredOrDefaultMs(config.power.on_battery_shutdown_after_secs))) { // shutdown after 30 minutes unpowered powerFSM.trigger(EVENT_SHUTDOWN); } diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index b278704d7..267ebc2ab 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -1,7 +1,5 @@ #define LED_PIN LED -#define HAS_GPS 0 - #define RESET_OLED RST_OLED #define I2C_SDA SDA_OLED // I2C pins for this board #define I2C_SCL SCL_OLED @@ -29,4 +27,4 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_E22 \ No newline at end of file +#define SX126X_E22 diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index d811bad20..7b07c9aff 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -127,7 +127,7 @@ static const uint8_t SCK = PIN_SPI_SCK; * eink display pins */ -#define PIN_EINK_EN (0 + 2) // (0 + 2) Note: this is really just backlight power +#define PIN_EINK_EN (32 + 2) // (0 + 2) Note: this is really just backlight power #define PIN_EINK_CS (0 + 26) #define PIN_EINK_BUSY (0 + 4) #define PIN_EINK_DC (0 + 17) diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 71ce58714..890f00ddd 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -127,7 +127,7 @@ static const uint8_t SCK = PIN_SPI_SCK; * eink display pins */ -#define PIN_EINK_EN (0 + 2) // (0 + 2) Note: this is really just backlight power +#define PIN_EINK_EN (32 + 2) // (0 + 2) Note: this is really just backlight power #define PIN_EINK_CS (0 + 26) #define PIN_EINK_BUSY (0 + 4) #define PIN_EINK_DC (0 + 17) diff --git a/variants/tlora_v2_1_18/platformio.ini b/variants/tlora_v2_1_18/platformio.ini index ac7c1a5e4..9c79fa259 100644 --- a/variants/tlora_v2_1_18/platformio.ini +++ b/variants/tlora_v2_1_18/platformio.ini @@ -1,5 +1,11 @@ [env:tlora-v2-1-1.8] extends = esp32_base board = ttgo-lora32-v21 +lib_deps = + ${esp32_base.lib_deps} + caveman99/ESP32 Codec2@^1.0.1 + +; the RADIOLIB_GODMODE flag can be removed once the next version of RadioLib is released. (>5.5.0) + build_flags = ${esp32_base.build_flags} -D TLORA_V2_1_18 -I variants/tlora_v2_1_18 -D RADIOLIB_GODMODE \ No newline at end of file diff --git a/version.properties b/version.properties index eee8783cb..9964c8bdb 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 7 +build = 8