Converted percent remaining calc to int.
This commit is contained in:
parent
11280d5f37
commit
e2d1f81915
3 changed files with 7 additions and 8 deletions
|
@ -34,9 +34,9 @@ void Battery::Update() {
|
||||||
|
|
||||||
// see https://forum.pine64.org/showthread.php?tid=8147
|
// see https://forum.pine64.org/showthread.php?tid=8147
|
||||||
voltage = (value * 2.0f) / (1024/3.0f);
|
voltage = (value * 2.0f) / (1024/3.0f);
|
||||||
float percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
|
int percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
|
||||||
percentRemaining = std::max(percentRemaining, 0.0f);
|
percentRemaining = std::max(percentRemaining, 0);
|
||||||
percentRemaining = std::min(percentRemaining, 100.0f);
|
percentRemaining = std::min(percentRemaining, 100);
|
||||||
|
|
||||||
percentRemainingBuffer.insert(percentRemaining);
|
percentRemainingBuffer.insert(percentRemaining);
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ namespace Pinetime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetAverage() const {
|
int GetAverage() const {
|
||||||
float sum = std::accumulate(arr.begin(), arr.end(), 0.0f);
|
int sum = std::accumulate(arr.begin(), arr.end(), 0.0f);
|
||||||
return (sum / sz);
|
return (sum / sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace Pinetime {
|
||||||
public:
|
public:
|
||||||
void Init();
|
void Init();
|
||||||
void Update();
|
void Update();
|
||||||
float PercentRemaining() const { return percentRemainingBuffer.GetAverage(); }
|
int PercentRemaining() const { return percentRemainingBuffer.GetAverage(); }
|
||||||
float Voltage() const { return voltage; }
|
float Voltage() const { return voltage; }
|
||||||
bool IsCharging() const { return isCharging; }
|
bool IsCharging() const { return isCharging; }
|
||||||
bool IsPowerPresent() const { return isPowerPresent; }
|
bool IsPowerPresent() const { return isPowerPresent; }
|
||||||
|
|
|
@ -98,8 +98,7 @@ bool Clock::Refresh() {
|
||||||
batteryPercentRemaining = batteryController.PercentRemaining();
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
||||||
if (batteryPercentRemaining.IsUpdated()) {
|
if (batteryPercentRemaining.IsUpdated()) {
|
||||||
auto batteryPercent = batteryPercentRemaining.Get();
|
auto batteryPercent = batteryPercentRemaining.Get();
|
||||||
// lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
||||||
lv_label_set_text(batteryIcon, std::to_string(batteryPercent).c_str());
|
|
||||||
auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent();
|
auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent();
|
||||||
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
|
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue