From 19e5562228913ce46c83ebad0513eea1f5e024a3 Mon Sep 17 00:00:00 2001 From: BAALBAKYA <62015246+AlexandreArduino@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:16:24 +0100 Subject: [PATCH] 2 corrections of bugs about the battery level in the settings (#148) * added battery level handler for simulator * added battery level > 100% when charging * corrected version * laury version but with float type * Update apps/settings/sub_menu/about_controller.cpp * Update apps/settings/sub_menu/about_controller.cpp Co-authored-by: = <=> Co-authored-by: Lauryy06 <80424145+Lauryy06@users.noreply.github.com> --- apps/settings/sub_menu/about_controller.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/settings/sub_menu/about_controller.cpp b/apps/settings/sub_menu/about_controller.cpp index 09debd6e9..812862ab9 100644 --- a/apps/settings/sub_menu/about_controller.cpp +++ b/apps/settings/sub_menu/about_controller.cpp @@ -112,11 +112,21 @@ bool AboutController::handleEvent(Ion::Events::Event event) { if(childLabel == I18n::Message::Battery){ MessageTableCellWithBuffer * myCell = (MessageTableCellWithBuffer *)m_selectableTableView.selectedCell(); char batteryLevel[5]; - if(strchr(myCell->accessoryText(), '%') == NULL){ - int batteryLen = Poincare::Integer((int) ((Ion::Battery::voltage() - 3.6) * 166)).serialize(batteryLevel, 5); - batteryLevel[batteryLen] = '%'; - batteryLevel[batteryLen+1] = '\0'; - }else{ + if(strchr(myCell->accessoryText(), '%') == NULL) { + float voltage = (Ion::Battery::voltage() - 3.6) * 166; + if(voltage < 0.0) { + myCell->setAccessoryText("1%"); // We cheat... + return true; + } else if (voltage >= 100.0) { + myCell->setAccessoryText("100%"); + return true; + } else { + int batteryLen = Poincare::Integer((int) voltage).serialize(batteryLevel, 5); + batteryLevel[batteryLen] = '%'; + batteryLevel[batteryLen+1] = '\0'; + } + } + else { int batteryLen = Poincare::Number::FloatNumber(Ion::Battery::voltage()).serialize(batteryLevel, 5, Poincare::Preferences::PrintFloatMode::Decimal, 3); batteryLevel[batteryLen] = 'V'; batteryLevel[batteryLen+1] = '\0';