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
|
||||
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 */
|
||||
|
||||
void Arduboy2Base::setFrameRate(uint8_t rate)
|
||||
|
@ -188,13 +209,14 @@ int Arduboy2Base::cpuLoad()
|
|||
|
||||
void Arduboy2Base::initRandomSeed()
|
||||
{
|
||||
power_adc_enable(); // ADC on
|
||||
randomSeed(~rawADC(ADC_TEMP) * ~rawADC(ADC_VOLTAGE) * ~micros() + micros());
|
||||
power_adc_disable(); // ADC off
|
||||
}
|
||||
|
||||
uint16_t Arduboy2Base::rawADC(uint8_t adc_bits)
|
||||
{
|
||||
power_adc_enable(); // ADC on
|
||||
|
||||
ADMUX = adc_bits;
|
||||
// we also need MUX5 for temperature check
|
||||
if (adc_bits == ADC_TEMP) {
|
||||
|
|
|
@ -253,6 +253,17 @@ class Arduboy2Base : public Arduboy2Core
|
|||
// information after the logo stops scrolling down.
|
||||
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
|
||||
* Clear the display buffer.
|
||||
*
|
||||
|
@ -695,7 +706,7 @@ class Arduboy2Base : public Arduboy2Core
|
|||
int cpuLoad();
|
||||
|
||||
// Useful for getting raw approximate voltage values.
|
||||
uint16_t rawADC(uint8_t adc_bits);
|
||||
static uint16_t rawADC(uint8_t adc_bits);
|
||||
|
||||
/** \brief
|
||||
* Test if the specified buttons are pressed.
|
||||
|
@ -1074,7 +1085,7 @@ class Arduboy2 : public Print, public Arduboy2Base
|
|||
*
|
||||
* \details
|
||||
* This function is called by the `bootLogo()` function.
|
||||
*
|
||||
*
|
||||
* If a unit name has been saved in system EEPROM, it will be displayed at
|
||||
* the bottom of the screen. This function pauses for a short time to allow
|
||||
* the name to be seen.
|
||||
|
|
Loading…
Reference in New Issue