nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
A state machine to monitor a LiPo battery and charger. More...
#include <nrfcxx/misc/lipomon.hpp>
Public Types | |
enum | PowerSource_e : uint8_t { PS_Unknown = 0, PS_OnBattery = 1, PS_Charging = 2, PS_Charged = 3 } |
State of power source as inferred from VCHG_DETECT and BAT_CHG_STAT signals. More... | |
Public Member Functions | |
lipo_monitor (notifier_type notify, const gpio::gpio_pin &vchg_detect, const gpio::gpio_pin &chgn_state, sensor::adc::voltage_divider &battmeas) | |
Construct an instance. More... | |
bool | vchg_detected_live () |
Read the live USB detection signal. | |
bool | charging_live () |
Read the live charging signal. | |
int | calibrate () |
Initiate a calibration of the ADC used to measure voltage. More... | |
int | batt_mV () const |
The most recently collected LiPo output voltage. More... | |
int | power_source () const |
Get the latest processed power source. More... | |
Public Member Functions inherited from nrfcxx::lpm::lpsm_capable | |
virtual int | lpsm_start () |
Validate and prepare to initiate an LPM collection. More... | |
virtual int | lpsm_sample () |
Ask the LPM infrastructure to initiate a new sample. More... | |
lpm::state_machine::process_flags_type | lpsm_process () |
Make progress on an LPM collection. More... | |
int | lpsm_stop () |
int | lpsm_reset () |
int | lpsm_process_rc () const |
Get the internal result code from the last invocation of lpsm_process_(). More... | |
const lpm::state_machine & | machine () const |
Gain read-only access to the LPM machine state. | |
Static Public Attributes | |
static constexpr auto | PF_STARTED = lpm::state_machine::PF_STARTED |
static constexpr auto | PF_LIPO = lpm::state_machine::PF_APP_BASE |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been removed and the system is running from battery power. | |
static constexpr auto | PF_MAINS = lpm::state_machine::PF_APP_BASE << 1 |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been inserted and the system is running from mains power. More... | |
static constexpr auto | PF_CHARGING = lpm::state_machine::PF_APP_BASE << 2 |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the LiPo battery is being charged from a mains power source. | |
static constexpr auto | PF_CHARGED = lpm::state_machine::PF_APP_BASE << 3 |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the LiPo battery has completed charging. | |
static constexpr auto | PF_CALIBRATED = lpm::state_machine::PF_APP_BASE << 5 |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the battery voltage sensor has been calibrated. | |
Additional Inherited Members | |
Protected Types inherited from nrfcxx::lpm::lpsm_capable | |
using | state_type = state_machine::state_type |
using | process_flags_type = state_machine::process_flags_type |
Protected Member Functions inherited from nrfcxx::lpm::lpsm_capable | |
lpsm_capable (notifier_type notify) | |
Create a state machine that records state and supports delayed transitions. More... | |
virtual int | lpsm_process_ (int &delay, process_flags_type &pf) |
Override to implement machine-specific operations of lpsm_process(). More... | |
virtual void | lpsm_reset_ () |
Override to reset state that is held outside the machine. | |
Protected Attributes inherited from nrfcxx::lpm::lpsm_capable | |
state_machine | machine_ |
A state machine to monitor a LiPo battery and charger.
This class does several things:
lpm::lpsm_capable::lpsm_process() for this sensor returns the following flags:
calibrate() should be invoked by the application on startup and whenever the ambient temperature changes by more than 10 Cel from the last calibration.
enum nrfcxx::misc::lipo_monitor::PowerSource_e : uint8_t |
State of power source as inferred from VCHG_DETECT and BAT_CHG_STAT signals.
nrfcxx::misc::lipo_monitor::lipo_monitor | ( | notifier_type | notify, |
const gpio::gpio_pin & | vchg_detect, | ||
const gpio::gpio_pin & | chgn_state, | ||
sensor::adc::voltage_divider & | battmeas | ||
) |
Construct an instance.
notify | the setter used to indicate to the application that lpsm_process() should be invoked. |
vchg_detect | a GPIO reference that is high when a charging voltage is available, and low when it is not. |
chgn_state | a GPIO reference that is low when the battery is being charged, and high when it is not being charged. The signal is considered valid only when a charging voltage is available. |
battmeas | the ADC client used to measure the voltage of the LiPo battery. A reference to this instance will be retained. |
|
inline |
The most recently collected LiPo output voltage.
int nrfcxx::misc::lipo_monitor::calibrate | ( | ) |
Initiate a calibration of the ADC used to measure voltage.
int nrfcxx::misc::lipo_monitor::power_source | ( | ) | const |
Get the latest processed power source.
|
staticconstexpr |
Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been inserted and the system is running from mains power.
If this flag is returned either PF_CHARGING or PF_CHARGED will appear with it.