mirror of https://github.com/MLXXXp/Arduboy2.git
add checkBatteryLow() function
This commit is contained in:
parent
4ff6973a4b
commit
c847c8348b
|
@ -130,6 +130,27 @@ void Arduboy2Base::bootLogo()
|
||||||
// Virtual function overridden by derived class
|
// Virtual function overridden by derived class
|
||||||
void Arduboy2Base::bootLogoExtra() { }
|
void Arduboy2Base::bootLogoExtra() { }
|
||||||
|
|
||||||
|
bool Arduboy2Base::checkBatteryLow() {
|
||||||
|
bool batteryLow;
|
||||||
|
uint16_t voltage;
|
||||||
|
|
||||||
|
voltage = rawADC(ADC_VOLTAGE);
|
||||||
|
power_adc_disable(); // turn the ADC back off
|
||||||
|
|
||||||
|
// some voltage values for reference
|
||||||
|
// 4262mv - fully charged (plugged in)
|
||||||
|
// 41??mv - fully charged
|
||||||
|
voltage = 1125300L / voltage;
|
||||||
|
batteryLow = voltage < 3700;
|
||||||
|
|
||||||
|
if (batteryLow) {
|
||||||
|
TXLED1;
|
||||||
|
} else {
|
||||||
|
TXLED0;
|
||||||
|
}
|
||||||
|
return batteryLow;
|
||||||
|
}
|
||||||
|
|
||||||
/* Frame management */
|
/* Frame management */
|
||||||
|
|
||||||
void Arduboy2Base::setFrameRate(uint8_t rate)
|
void Arduboy2Base::setFrameRate(uint8_t rate)
|
||||||
|
@ -188,13 +209,14 @@ int Arduboy2Base::cpuLoad()
|
||||||
|
|
||||||
void Arduboy2Base::initRandomSeed()
|
void Arduboy2Base::initRandomSeed()
|
||||||
{
|
{
|
||||||
power_adc_enable(); // ADC on
|
|
||||||
randomSeed(~rawADC(ADC_TEMP) * ~rawADC(ADC_VOLTAGE) * ~micros() + micros());
|
randomSeed(~rawADC(ADC_TEMP) * ~rawADC(ADC_VOLTAGE) * ~micros() + micros());
|
||||||
power_adc_disable(); // ADC off
|
power_adc_disable(); // ADC off
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Arduboy2Base::rawADC(uint8_t adc_bits)
|
uint16_t Arduboy2Base::rawADC(uint8_t adc_bits)
|
||||||
{
|
{
|
||||||
|
power_adc_enable(); // ADC on
|
||||||
|
|
||||||
ADMUX = adc_bits;
|
ADMUX = adc_bits;
|
||||||
// we also need MUX5 for temperature check
|
// we also need MUX5 for temperature check
|
||||||
if (adc_bits == ADC_TEMP) {
|
if (adc_bits == ADC_TEMP) {
|
||||||
|
|
|
@ -253,6 +253,17 @@ class Arduboy2Base : public Arduboy2Core
|
||||||
// information after the logo stops scrolling down.
|
// information after the logo stops scrolling down.
|
||||||
virtual void bootLogoExtra();
|
virtual void bootLogoExtra();
|
||||||
|
|
||||||
|
/** \brief
|
||||||
|
* Checks the battery voltage level.
|
||||||
|
*
|
||||||
|
* \return true if the battery is running low
|
||||||
|
*
|
||||||
|
* \details
|
||||||
|
* This is called periodically by the frame management loop and will
|
||||||
|
* light the TX LED (yellow) if the battery is detected to be low.
|
||||||
|
*/
|
||||||
|
static bool checkBatteryLow();
|
||||||
|
|
||||||
/** \brief
|
/** \brief
|
||||||
* Clear the display buffer.
|
* Clear the display buffer.
|
||||||
*
|
*
|
||||||
|
@ -695,7 +706,7 @@ class Arduboy2Base : public Arduboy2Core
|
||||||
int cpuLoad();
|
int cpuLoad();
|
||||||
|
|
||||||
// Useful for getting raw approximate voltage values.
|
// Useful for getting raw approximate voltage values.
|
||||||
uint16_t rawADC(uint8_t adc_bits);
|
static uint16_t rawADC(uint8_t adc_bits);
|
||||||
|
|
||||||
/** \brief
|
/** \brief
|
||||||
* Test if the specified buttons are pressed.
|
* Test if the specified buttons are pressed.
|
||||||
|
|
Loading…
Reference in New Issue