Converted percent remaining calc to int.

This commit is contained in:
panky-codes 2021-01-16 19:51:32 +01:00
parent 11280d5f37
commit e2d1f81915
3 changed files with 7 additions and 8 deletions

View file

@ -34,9 +34,9 @@ void Battery::Update() {
// see https://forum.pine64.org/showthread.php?tid=8147
voltage = (value * 2.0f) / (1024/3.0f);
float percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
percentRemaining = std::max(percentRemaining, 0.0f);
percentRemaining = std::min(percentRemaining, 100.0f);
int percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
percentRemaining = std::max(percentRemaining, 0);
percentRemaining = std::min(percentRemaining, 100);
percentRemainingBuffer.insert(percentRemaining);

View file

@ -20,8 +20,8 @@ namespace Pinetime {
}
}
float GetAverage() const {
float sum = std::accumulate(arr.begin(), arr.end(), 0.0f);
int GetAverage() const {
int sum = std::accumulate(arr.begin(), arr.end(), 0.0f);
return (sum / sz);
}
@ -36,7 +36,7 @@ namespace Pinetime {
public:
void Init();
void Update();
float PercentRemaining() const { return percentRemainingBuffer.GetAverage(); }
int PercentRemaining() const { return percentRemainingBuffer.GetAverage(); }
float Voltage() const { return voltage; }
bool IsCharging() const { return isCharging; }
bool IsPowerPresent() const { return isPowerPresent; }

View file

@ -98,8 +98,7 @@ bool Clock::Refresh() {
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
// lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
lv_label_set_text(batteryIcon, std::to_string(batteryPercent).c_str());
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent();
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
}