improve battery tracking
This commit is contained in:
@@ -33,6 +33,12 @@ double Battery::getBatteryVoltage() {
|
||||
return (int)(res*100+0.5)/100.0;
|
||||
}
|
||||
|
||||
bool Battery::isBatteryLow(uint8_t percent) {
|
||||
if (this->getBatteryPercent() <= percent && this->batteryVoltage > this->absurdLowVoltage)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
double Battery::readInputVoltage() {
|
||||
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
|
||||
double reading = analogRead(this->pin);
|
||||
|
||||
@@ -73,13 +73,28 @@ class Battery {
|
||||
*/
|
||||
uint8_t getBatteryPercent() {return this->batteryPercent;}
|
||||
|
||||
/**
|
||||
* @brief Checks if the battery is low.
|
||||
*
|
||||
* The function will also return false if the battery voltage is
|
||||
* absurd low. This is for the case that the uController is powered
|
||||
* by usb and no battery is connected.
|
||||
*
|
||||
* @param percent the limit the battery have to
|
||||
* @return true if the battery is low
|
||||
* @return false if the battery is high
|
||||
*/
|
||||
bool isBatteryLow(uint8_t percent);
|
||||
|
||||
private:
|
||||
double readInputVoltage();
|
||||
void calculateBatteryVoltage();
|
||||
void calculateBatteryPercent();
|
||||
|
||||
uint8_t absurdLowVoltage = 5;
|
||||
uint8_t pin;
|
||||
uint8_t batteryPercent;
|
||||
uint8_t batteryLowPercent = 10;
|
||||
uint16_t delay = 20000;
|
||||
uint32_t r1;
|
||||
uint32_t r2;
|
||||
|
||||
Reference in New Issue
Block a user