Files

35 lines
1.2 KiB
C++
Raw Permalink Normal View History

2025-01-12 18:08:57 +01:00
#include "graphics/common/BatteryLevel.h"
2024-07-20 11:52:36 +02:00
BatteryLevel::BatteryLevel(void)
: levels{
2025-03-19 20:35:45 +01:00
{100, 0.0f}, // Plugged
{100, (float)CHARGING_VOLTAGE}, // Charging
{80, 4.00f}, // Full
{35, 3.50f}, // Mid
{10, 3.30f}, // Low
{0, 3.12f}, // Empty
{0, 3.10f} // Warn
2024-07-20 11:52:36 +02:00
}
{
}
BatteryLevel::Status BatteryLevel::calcStatus(uint32_t percentage, float voltage)
{
2024-07-28 19:42:38 +02:00
if (voltage == levels[Plugged].voltage) {
2024-07-22 22:37:59 +02:00
return Plugged;
}
2024-07-20 11:52:36 +02:00
if (percentage >= levels[Charging].percentage && voltage > levels[Charging].voltage) {
return Charging;
} else if (percentage >= levels[Full].percentage && voltage > levels[Full].voltage) {
return Full;
} else if (percentage >= levels[Mid].percentage && voltage > levels[Mid].voltage) {
return Mid;
} else if (percentage >= levels[Low].percentage && voltage > levels[Low].voltage) {
return Low;
2024-07-22 22:37:59 +02:00
} else if (percentage > levels[Empty].percentage) {
2024-07-20 11:52:36 +02:00
return Empty;
} else {
2024-07-22 22:37:59 +02:00
return Warn;
2024-07-20 11:52:36 +02:00
}
}