Add configurable battery and USB display behavior
Persist separate display modes and timeouts in seconds for battery and USB power, expose four controls in WebConfig and CLI, and apply one shared policy across display-equipped roles. Detect R8 external power from a USB host or calibrated battery voltage above 4.21 V, with cached sampling and hysteresis. Add policy, persistence, browser, and R8 power-detection regression coverage.
This commit is contained in:
1 parent
d83153e935
commit
a814a00ce7
39 files changed
+3187
-2488
No files matched your search
@@ -65,6 +65,24 @@ uint16_t HeltecV4R8Board::getBattMilliVolts() {
|
||||
return (adc_mult * raw);
|
||||
}
|
||||
|
||||
bool HeltecV4R8Board::isExternalPowered() {
|
||||
// R8 has no MCU-connected VBUS/charger-status pin. A USB host is definitive;
|
||||
// otherwise use the calibrated battery voltage as a best-effort estimate.
|
||||
if (isUsbHostConnected()) return true;
|
||||
|
||||
const uint32_t now = millis();
|
||||
if (!power_voltage_sampled || uint32_t(now - last_power_check_ms) >= 5000) {
|
||||
last_power_check_ms = now;
|
||||
power_voltage_sampled = true;
|
||||
// Like Meshtastic's analog power detection, enter above a full Li-ion cell
|
||||
// plus 10 mV. Release at 4.20 V to reduce display-profile chatter. This can
|
||||
// miss a charger while the battery is low; it is not a charging-status flag.
|
||||
const uint16_t millivolts = getBattMilliVolts();
|
||||
voltage_external_power = millivolts > (voltage_external_power ? 4200 : 4210);
|
||||
}
|
||||
return voltage_external_power;
|
||||
}
|
||||
|
||||
const char* HeltecV4R8Board::getManufacturerName() const {
|
||||
#ifdef HELTEC_V4_R8_TFT
|
||||
return "Heltec V4 R8 TFT";
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
class HeltecV4R8Board : public ESP32Board {
|
||||
protected:
|
||||
float adc_mult = ADC_MULTIPLIER;
|
||||
uint32_t last_power_check_ms = 0;
|
||||
bool power_voltage_sampled = false;
|
||||
bool voltage_external_power = false;
|
||||
|
||||
public:
|
||||
RefCountedDigitalPin periph_power;
|
||||
@@ -28,6 +31,7 @@ public:
|
||||
bool canControlLoRaFemLna() const override;
|
||||
bool isLoRaFemLnaEnabled() const override;
|
||||
uint16_t getBattMilliVolts() override;
|
||||
bool isExternalPowered() override;
|
||||
bool setAdcMultiplier(float multiplier) override {
|
||||
if (multiplier == 0.0f) {
|
||||
adc_mult = ADC_MULTIPLIER;
|
||||
|
||||
@@ -347,8 +347,8 @@ build_flags =
|
||||
-D DISPLAY_ACTIVITY_DASHBOARD=1
|
||||
-D USER_BTN_LONG_PRESS_MILLIS=3000
|
||||
-D USER_BTN_MULTICLICK=1
|
||||
; display.timeout controls runtime blanking; touch and the existing button
|
||||
; handling can toggle the panel manually. Multiclick remains enabled.
|
||||
; Battery/USB display modes and timeouts control runtime blanking.
|
||||
; Touch and button presses request a wake when allowed. Multiclick stays enabled.
|
||||
-D DISPLAY_TOUCH_TOGGLE=1
|
||||
build_src_filter = ${heltec_v4_r8_tft.build_src_filter}
|
||||
+<helpers/bridges/MQTTBridge.cpp>
|
||||
@@ -422,8 +422,8 @@ build_flags =
|
||||
-D DISPLAY_ACTIVITY_DASHBOARD=1
|
||||
-D USER_BTN_LONG_PRESS_MILLIS=3000
|
||||
-D USER_BTN_MULTICLICK=0
|
||||
; display.timeout controls runtime blanking; touch and the existing button
|
||||
; handling can toggle the panel manually. Room has no multiclick action, so a
|
||||
; Battery/USB display modes and timeouts control runtime blanking. Touch and
|
||||
; button presses request a wake when allowed. Room has no multiclick action, so a
|
||||
; click is delivered immediately instead of waiting for a second click.
|
||||
-D DISPLAY_TOUCH_TOGGLE=1
|
||||
build_src_filter = ${heltec_v4_r8_tft.build_src_filter}
|
||||
|
||||
Reference in new issue
Block a user