RSeries astromech firmware
BatteryMonitor Class Reference

#include <core/BatteryMonitor.h>

+ Inheritance diagram for BatteryMonitor:
+ Collaboration diagram for BatteryMonitor:

Public Member Functions

 BatteryMonitor (uint8_t pin, uint16_t minVoltage=3000, uint16_t maxVoltage=4200, float scale=2 *3.3 *1000, unsigned(*mapping)(unsigned, unsigned, unsigned)=sigmoidal)
 Creates an instance to monitor battery voltage and level. More...
 
bool isBatteryPowered ()
 
bool isBatteryPowered (uint32_t voltage)
 
void setRefreshCallback (uint32_t millis, void(*callback)())
 
void setMapping (unsigned(*mapping)(unsigned, unsigned, unsigned))
 
unsigned level ()
 Returns the current battery level as a number between 0 and 100, with 0 indicating an empty battery and 100 a full battery. More...
 
unsigned level (uint32_t voltage)
 
uint32_t voltage ()
 Returns the current battery voltage in millivolts. More...
 
virtual void animate () override
 Subclasses must implement this function to run through a single frame of animation/activity. More...
 
- Public Member Functions inherited from AnimatedEvent
 AnimatedEvent ()
 Default Constructor. More...
 
void setLoopDoneCallback (AnimatedLoopDone loopProc)
 

Static Public Member Functions

static unsigned sigmoidal (unsigned voltage, unsigned minVoltage, unsigned maxVoltage)
 Symmetric sigmoidal approximation https://www.desmos.com/calculator/7m9lu26vpy. More...
 
static unsigned asigmoidal (unsigned voltage, unsigned minVoltage, unsigned maxVoltage)
 Asymmetric sigmoidal approximation https://www.desmos.com/calculator/oyhpsu8jnw. More...
 
static unsigned linear (unsigned voltage, unsigned minVoltage, unsigned maxVoltage)
 Linear mapping https://www.desmos.com/calculator/sowyhttjta. More...
 
- Static Public Member Functions inherited from AnimatedEvent
static void process ()
 Calls animate() for each created AnimatedEvent subclass. More...
 

Constructor & Destructor Documentation

◆ BatteryMonitor()

BatteryMonitor::BatteryMonitor ( uint8_t  pin,
uint16_t  minVoltage = 3000,
uint16_t  maxVoltage = 4200,
float  scale = 2 * 3.3 * 1000,
unsigned(*)(unsigned, unsigned, unsigned)  mapping = sigmoidal 
)
inline

Creates an instance to monitor battery voltage and level.

Initialization parameters depend on battery type and configuration.

Parameters
pinis the analog pin used for sensing the battery voltage
minVoltageis the voltage, expressed in millivolts, corresponding to an empty battery
maxVoltageis the voltage, expressed in millivolts, corresponding to a full battery
scaleis the multiplier used to obtain the real battery voltage in milli volts
mapFunctionis a pointer to the function used to map the battery voltage to the remaining capacity percentage (defaults to linear mapping)

Member Function Documentation

◆ animate()

virtual void BatteryMonitor::animate ( )
inlineoverridevirtual

Subclasses must implement this function to run through a single frame of animation/activity.

Subclasses should not call delay() or otherwise block.

Implements AnimatedEvent.

◆ asigmoidal()

static unsigned BatteryMonitor::asigmoidal ( unsigned  voltage,
unsigned  minVoltage,
unsigned  maxVoltage 
)
inlinestatic

Asymmetric sigmoidal approximation https://www.desmos.com/calculator/oyhpsu8jnw.

c - c / [1 + (k*x/v)^4.5]^3

◆ isBatteryPowered() [1/2]

bool BatteryMonitor::isBatteryPowered ( )
inline

◆ isBatteryPowered() [2/2]

bool BatteryMonitor::isBatteryPowered ( uint32_t  voltage)
inline

◆ level() [1/2]

unsigned BatteryMonitor::level ( )
inline

Returns the current battery level as a number between 0 and 100, with 0 indicating an empty battery and 100 a full battery.

◆ level() [2/2]

unsigned BatteryMonitor::level ( uint32_t  voltage)
inline

◆ linear()

static unsigned BatteryMonitor::linear ( unsigned  voltage,
unsigned  minVoltage,
unsigned  maxVoltage 
)
inlinestatic

Linear mapping https://www.desmos.com/calculator/sowyhttjta.

x * 100 / v

◆ setMapping()

void BatteryMonitor::setMapping ( unsigned(*)(unsigned, unsigned, unsigned)  mapping)
inline

◆ setRefreshCallback()

void BatteryMonitor::setRefreshCallback ( uint32_t  millis,
void(*)()  callback 
)
inline

◆ sigmoidal()

static unsigned BatteryMonitor::sigmoidal ( unsigned  voltage,
unsigned  minVoltage,
unsigned  maxVoltage 
)
inlinestatic

Symmetric sigmoidal approximation https://www.desmos.com/calculator/7m9lu26vpy.

c - c / (1 + k*x/v)^3

◆ voltage()

uint32_t BatteryMonitor::voltage ( )
inline

Returns the current battery voltage in millivolts.


The documentation for this class was generated from the following file: