81 bool enableInternalPullResistor);
98 bool enableInternalPullResistor);
108 inline static InputGPIO _powerSensePin{};
109 inline static bool _powerSenseNegativeLogic =
false;
110 inline static InputGPIO _chargingSensePin{};
111 inline static bool _chargingSenseNegativeLogic =
false;
136 this->status = fakeStatus;
145 virtual bool read_soc(uint8_t &soc)
override {
return false; }
170 bool read(uint8_t regAddress, uint16_t &value);
180 bool write(uint8_t regAddress, uint16_t value);
190 virtual bool read_soc(uint8_t ¤tSoC)
override;
230 virtual bool read_soc(uint8_t ¤tSoC)
override;
262 uint32_t resistorToGND = 200,
263 uint32_t resistorToBattery = 110);
Types and constants used everywhere for firmware implementation.
Types and constants required for custom firmware setup.
I2CBus
I2C bus controller.
Hardware witnesses regarding battery chargers.
static void setExternalPowerWitness(InputGPIO sensePin, bool negativeLogic, bool enableInternalPullResistor)
Set a GPIO pin to sense the power wire.
static void setChargingWitness(InputGPIO sensePin, bool negativeLogic, bool enableInternalPullResistor)
Set a GPIO pin to sense if the battery is being charged.
static void update(BatteryStatus &status)
Update the battery status according to the witnesses.
Interface to hardware implementing a battery monitor.
virtual void getStatus(BatteryStatus ¤tStatus)
Get the battery status.
virtual void onStart()
Called once when the battery monitor daemon is started.
virtual bool read_soc(uint8_t &soc)=0
Retrieve the current state of charge.
Fake battery monitor for testing.
virtual bool read_soc(uint8_t &soc) override
Retrieve the current state of charge.
FakeBatteryMonitor(BatteryStatus *fakeStatus)
Construct a new Fake Battery Monitor object.
virtual void getStatus(BatteryStatus ¤tStatus) override
Get the battery status.
BatteryStatus * status
Pointer to variable that holds fake battery status.
MAX1704x chips for battery monitoring.
bool read(uint8_t regAddress, uint16_t &value)
Read from a register.
MAX1704x(I2CBus bus=I2CBus::PRIMARY, uint8_t i2c_address=0xFF)
Construct a new MAX1704x object.
bool quickStart()
Send a quick start command.
virtual ~MAX1704x()
Destroy the MAX1704x object.
void * device
I2C slave device (must be type-casted)
virtual void onStart() override
Called once when the battery monitor daemon is started.
bool write(uint8_t regAddress, uint16_t value)
Write to a register.
virtual bool read_soc(uint8_t ¤tSoC) override
Retrieve the current state of charge.
Battery monitor implemented as a voltage divider.
virtual bool read_soc(uint8_t ¤tSoC) override
Retrieve the current state of charge.
int lastBatteryReading
Last ADC reading.
OutputGPIO _batteryENPin
ADC-capable GPIO for reading.
int CHARGING_ADC_READING
Minimum expected ADC reading when the battery is charging.
ADC_GPIO _batteryREADPin
output GPIO to enable/disable the circuitry
VoltageDividerMonitor(ADC_GPIO battREADPin, OutputGPIO battENPin, uint32_t resistorToGND=200, uint32_t resistorToBattery=110)
Construct a new Voltage Divider Monitor object.
static uint8_t readingToSoC(int reading)
Translate a battery reading to a state of charge.
int read()
Get ADC reading.
ADC-capable GPIO pin number.
Output-capable GPIO pin number.