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>
This commit is contained in:
BAALBAKYA
2022-03-03 17:16:24 +01:00
committed by GitHub
parent 9edf026110
commit 19e5562228

View File

@@ -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';