diff --git a/Battery.h b/Battery.h index 6ecf5c3..0ea46be 100644 --- a/Battery.h +++ b/Battery.h @@ -127,11 +127,11 @@ */ void Battery::batteryUpdate() { - if (rateskip % 5 == 0 || statusColor == 0 ) + if (rateskip % 5 == 0 || statusColor == 0) { statusColor = getBatteryColor(); } - if (rateskip == 1 || i_percent == -1 ) + if (rateskip == 1 || i_percent == -1) { i_percent = calcBatteryPercent(); rateskip = ratecount; @@ -139,10 +139,10 @@ // 電池図形内部背景塗りつぶし _sprite->fillRect(_x, _y, _width - 1, _height - 1, TFT_BLACK); // 電池の外形 - drawBatteryLines(); + drawBatteryLines(); // バッテリー残量の割合を計算して背景色塗りつぶし int b_width = int((_width - 2) * (i_percent / 100.0f)); - _sprite->fillRect(_x + 2, _y + 2, b_width , _height - 3, statusColor); + _sprite->fillRect(_x + 2, _y + 2, b_width, _height - 3, statusColor); showBatteryPercent(); // バッテリー数値を表示 // Serial.printf("batt %d", i_percent); @@ -171,7 +171,7 @@ void Battery::showBatteryPercent() { // バッテリー数値を表示 - _sprite->setCursor(_x + _width + 7, _y + _showSize+1); + _sprite->setCursor(_x + _width + 7, _y + _showSize + 1); _sprite->setTextFont(1); _sprite->setTextColor(_text_color); _sprite->setTextSize(_showSize); @@ -239,5 +239,7 @@ float percent = (_vbat - MIN_BATTERY_VOLTAGE) / (MAX_BATTERY_VOLTAGE - MIN_BATTERY_VOLTAGE); if (percent > 1.0f) percent = 1.0f; + if (percent < 0.0f) + percent = 0.0f; return roundf(percent * 100.0f); }