mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-21 12:38:34 +00:00
Support external charge detection (#3386)
* Support external charge detection * trunk fmt
This commit is contained in:
parent
6215495ccc
commit
7f063fbf81
@ -54,6 +54,19 @@ static const adc_atten_t atten = ADC_ATTENUATION;
|
|||||||
#endif
|
#endif
|
||||||
#endif // BATTERY_PIN && ARCH_ESP32
|
#endif // BATTERY_PIN && ARCH_ESP32
|
||||||
|
|
||||||
|
#ifdef EXT_CHRG_DETECT
|
||||||
|
#ifndef EXT_CHRG_DETECT_MODE
|
||||||
|
static const uint8_t ext_chrg_detect_mode = INPUT;
|
||||||
|
#else
|
||||||
|
static const uint8_t ext_chrg_detect_mode = EXT_CHRG_DETECT_MODE;
|
||||||
|
#endif
|
||||||
|
#ifndef EXT_CHRG_DETECT_VALUE
|
||||||
|
static const uint8_t ext_chrg_detect_value = HIGH;
|
||||||
|
#else
|
||||||
|
static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
||||||
INA260Sensor ina260Sensor;
|
INA260Sensor ina260Sensor;
|
||||||
INA219Sensor ina219Sensor;
|
INA219Sensor ina219Sensor;
|
||||||
@ -322,7 +335,14 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
|
|
||||||
/// Assume charging if we have a battery and external power is connected.
|
/// Assume charging if we have a battery and external power is connected.
|
||||||
/// we can't be smart enough to say 'full'?
|
/// we can't be smart enough to say 'full'?
|
||||||
virtual bool isCharging() override { return isBatteryConnect() && isVbusIn(); }
|
virtual bool isCharging() override
|
||||||
|
{
|
||||||
|
#ifdef EXT_CHRG_DETECT
|
||||||
|
return digitalRead(EXT_CHRG_DETECT) == ext_chrg_detect_value;
|
||||||
|
#else
|
||||||
|
return isBatteryConnect() && isVbusIn();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
||||||
@ -389,6 +409,9 @@ bool Power::analogInit()
|
|||||||
#ifdef EXT_PWR_DETECT
|
#ifdef EXT_PWR_DETECT
|
||||||
pinMode(EXT_PWR_DETECT, INPUT);
|
pinMode(EXT_PWR_DETECT, INPUT);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef EXT_CHRG_DETECT
|
||||||
|
pinMode(EXT_CHRG_DETECT, ext_chrg_detect_mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BATTERY_PIN
|
#ifdef BATTERY_PIN
|
||||||
LOG_DEBUG("Using analog input %d for battery level\n", BATTERY_PIN);
|
LOG_DEBUG("Using analog input %d for battery level\n", BATTERY_PIN);
|
||||||
|
Loading…
Reference in New Issue
Block a user