diff --git a/include/power_utils.h b/include/power_utils.h index ede4072..313a713 100644 --- a/include/power_utils.h +++ b/include/power_utils.h @@ -29,7 +29,7 @@ namespace POWER_Utils { - #ifdef VEXT_CTRL + #ifdef VEXT_CTRL_PIN void vext_ctrl_ON(); void vext_ctrl_OFF(); #endif @@ -46,6 +46,9 @@ namespace POWER_Utils { void activateLoRa(); void deactivateLoRa(); bool begin(TwoWire &port); + #ifdef SOLAR_CHARGE_PIN + void checkSolarCharge(); + #endif void setup(); } diff --git a/include/wx_utils.h b/include/wx_utils.h index ebf445d..778fa4b 100644 --- a/include/wx_utils.h +++ b/include/wx_utils.h @@ -36,6 +36,7 @@ namespace WX_Utils { String generateHumString(const float sensorHum); String generatePresString(const float sensorPres); String readDataSensor(); + float readBoardTemperature(); } diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 9fd9152..1c5c7c0 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -20,6 +20,7 @@ #include "battery_utils.h" #include "board_pinout.h" #include "power_utils.h" +#include "wx_utils.h" #include "utils.h" #if defined(HAS_AXP192) || defined(HAS_AXP2101) @@ -210,6 +211,23 @@ namespace POWER_Utils { #endif } + #ifdef SOLAR_CHARGE_PIN + void checkSolarCharge() { // called on each beacon: disable solar charging when too cold for Li-Ion + static bool chargingEnabled = true; + float boardTemp = WX_Utils::readBoardTemperature(); + if (isnan(boardTemp)) { + chargingEnabled = true; // sensor failure: keep charging (previous behaviour) + } else if (chargingEnabled && boardTemp < SOLAR_CHARGE_DISABLE_TEMP) { + chargingEnabled = false; + Serial.println("[SOLAR] Charging disabled, board temp: " + String(boardTemp, 1) + "C"); + } else if (!chargingEnabled && boardTemp > SOLAR_CHARGE_ENABLE_TEMP) { + chargingEnabled = true; + Serial.println("[SOLAR] Charging enabled, board temp: " + String(boardTemp, 1) + "C"); + } + digitalWrite(SOLAR_CHARGE_PIN, chargingEnabled ? SOLAR_CHARGE_ENABLED_STATE : !SOLAR_CHARGE_ENABLED_STATE); + } + #endif + void setup() { #ifdef HAS_AXP192 Wire.begin(SDA, SCL); @@ -254,6 +272,12 @@ namespace POWER_Utils { pinMode(BATTERY_PIN, INPUT); #endif + #ifdef SOLAR_CHARGE_PIN + pinMode(SOLAR_CHARGE_PIN, OUTPUT); + digitalWrite(SOLAR_CHARGE_PIN, SOLAR_CHARGE_ENABLED_STATE); // solar charging enabled by default + gpio_hold_dis((gpio_num_t)SOLAR_CHARGE_PIN); // release hold kept during deep sleep (if any) + #endif + #ifdef INTERNAL_LED_PIN pinMode(INTERNAL_LED_PIN, OUTPUT); digitalWrite(INTERNAL_LED_PIN, LOW); diff --git a/src/utils.cpp b/src/utils.cpp index 4435f29..005ebc7 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -25,6 +25,7 @@ #include "battery_utils.h" #include "aprs_is_utils.h" #include "board_pinout.h" +#include "power_utils.h" #include "syslog_utils.h" #include "A7670_utils.h" #include "lora_utils.h" @@ -168,6 +169,9 @@ namespace Utils { #endif if (beaconUpdate) { + #ifdef SOLAR_CHARGE_PIN + POWER_Utils::checkSolarCharge(); // solar boards: enable/disable charging by board temperature + #endif if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true); TELEMETRY_Utils::checkEUPInterval(); @@ -437,11 +441,16 @@ namespace Utils { displayToggle(false); } #ifdef VEXT_CTRL_PIN - #ifndef HELTEC_WSL_V3 - digitalWrite(VEXT_CTRL_PIN, LOW); - #endif + digitalWrite(VEXT_CTRL_PIN, !VEXT_CTRL_ON_STATE); // VEXT off before deep sleep (always, regardless of ecoMode) #endif LoRa_Utils::sleepRadio(); + #ifdef RADIO_VCC_PIN + digitalWrite(RADIO_VCC_PIN, LOW); // cut LoRa module power (QRP Labs LightGateway) so it draws nothing while sleeping + #endif + #ifdef SOLAR_CHARGE_PIN + gpio_hold_en((gpio_num_t)SOLAR_CHARGE_PIN); // keep charge on/off decided by temperature while sleeping + gpio_deep_sleep_hold_en(); + #endif transmitFlag = true; delay(100); esp_deep_sleep_start(); diff --git a/src/wx_utils.cpp b/src/wx_utils.cpp index 920f549..4125475 100644 --- a/src/wx_utils.cpp +++ b/src/wx_utils.cpp @@ -17,11 +17,11 @@ */ #include -#ifdef LIGHTGATEWAY_PLUS_1_0 -#include "Adafruit_SHTC3.h" -#endif #include "configuration.h" #include "board_pinout.h" +#ifdef HAS_SHTC3 +#include "Adafruit_SHTC3.h" +#endif #include "wx_utils.h" #include "display.h" @@ -51,8 +51,9 @@ Adafruit_BMP280 bmp280; Adafruit_BME680 bme680; Adafruit_Si7021 si7021 = Adafruit_Si7021(); #endif -#ifdef LIGHTGATEWAY_PLUS_1_0 +#ifdef HAS_SHTC3 Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); +bool boardTempSensorFound = false; // onboard SHTC3 (solar charge protection), independent of WX telemetry #endif @@ -66,7 +67,7 @@ namespace WX_Utils { err = SENSOR_I2C_BUS.endTransmission(); #else Wire.beginTransmission(addr); - #ifdef LIGHTGATEWAY_PLUS_1_0 + #ifdef HAS_SHTC3 Wire.write(0x35); Wire.write(0x17); #endif @@ -90,6 +91,15 @@ namespace WX_Utils { } void setup() { + #ifdef HAS_SHTC3 + Wire.beginTransmission(0x70); // SHTC3 wakeup (0x3517): it sleeps between reads and ignores its address while asleep (e.g. after deep sleep) + Wire.write(0x35); + Wire.write(0x17); + Wire.endTransmission(); + delay(1); + boardTempSensorFound = shtc3.begin(); + Serial.println(boardTempSensorFound ? "init : SHTC3 (onboard) ... done!" : "SHTC3 (onboard) not found!"); + #endif if (Config.wxsensor.active) { getWxModuleAddres(); if (wxModuleAddress != 0x00) { @@ -133,7 +143,7 @@ namespace WX_Utils { wxModuleFound = true; } } - #ifdef LIGHTGATEWAY_PLUS_1_0 + #ifdef HAS_SHTC3 else if (wxModuleAddress == 0x70) { if (shtc3.begin()) { Serial.println("SHTC3 sensor found"); @@ -238,6 +248,16 @@ namespace WX_Utils { #endif } + float readBoardTemperature() { // onboard SHTC3 (no WX correction applied), NAN if not available + #ifdef HAS_SHTC3 + if (boardTempSensorFound) { + sensors_event_t humidity, temp; + if (shtc3.getEvent(&humidity, &temp)) return temp.temperature; + } + #endif + return NAN; + } + String readDataSensor() { switch (wxModuleType) { case 1: // BME280 @@ -271,7 +291,7 @@ namespace WX_Utils { break; case 5: // SHTC3 { - #ifdef LIGHTGATEWAY_PLUS_1_0 + #ifdef HAS_SHTC3 sensors_event_t humidity, temp; shtc3.getEvent(&humidity, &temp); newTemp = temp.temperature; diff --git a/variants/QRPLabs_LightGateway_Plus_1_0/board_pinout.h b/variants/QRPLabs_LightGateway_Plus_1_0/board_pinout.h index 5925036..b81947f 100644 --- a/variants/QRPLabs_LightGateway_Plus_1_0/board_pinout.h +++ b/variants/QRPLabs_LightGateway_Plus_1_0/board_pinout.h @@ -54,5 +54,12 @@ #define INTERNAL_LED_PIN 16 #define BATTERY_PIN 1 #define BUTTON_PIN 0 + #define SOLAR_CHARGE_PIN 48 // HIGH = solar charging disabled / LOW = enabled + #define SOLAR_CHARGE_ENABLED_STATE LOW + #define SOLAR_CHARGE_DISABLE_TEMP -4.0 // °C: below this, stop charging (Li-Ion must not charge below 0°C) + #define SOLAR_CHARGE_ENABLE_TEMP -3.0 // °C: above this, charge again (1°C hysteresis) + + // Onboard Sensors + #define HAS_SHTC3 // temperature/humidity (I2C 0x70), used for solar charge protection #endif \ No newline at end of file diff --git a/variants/ttgo_t_deck_GPS/platformio.ini b/variants/ttgo_t_deck_GPS/platformio.ini index 7cacb31..e9f6e9e 100644 --- a/variants/ttgo_t_deck_GPS/platformio.ini +++ b/variants/ttgo_t_deck_GPS/platformio.ini @@ -14,6 +14,9 @@ board_build.embed_files = data_embed/leaflet.css.gz data_embed/leaflet.js.gz data_embed/favicon.png.gz + data_embed/aprs-symbols-24-0.png.gz + data_embed/aprs-symbols-24-1.png.gz + data_embed/aprs-symbols-24-2.png.gz extra_scripts = pre:tools/compress.py debug_tool = esp-prog diff --git a/variants/ttgo_t_deck_plus/platformio.ini b/variants/ttgo_t_deck_plus/platformio.ini index 2392d2d..3bb0378 100644 --- a/variants/ttgo_t_deck_plus/platformio.ini +++ b/variants/ttgo_t_deck_plus/platformio.ini @@ -14,6 +14,9 @@ board_build.embed_files = data_embed/leaflet.css.gz data_embed/leaflet.js.gz data_embed/favicon.png.gz + data_embed/aprs-symbols-24-0.png.gz + data_embed/aprs-symbols-24-1.png.gz + data_embed/aprs-symbols-24-2.png.gz extra_scripts = pre:tools/compress.py debug_tool = esp-prog