@@ -38,11 +38,7 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont
3838
3939 percent = lv_label_create (lv_scr_act (), nullptr );
4040 lv_obj_set_style_local_text_font (percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
41- if (batteryPercent >= 0 ) {
42- lv_label_set_text_fmt (percent, " %02i%%" , batteryPercent);
43- } else {
44- lv_label_set_text (percent, " --%" );
45- }
41+ lv_label_set_text_fmt (percent, " %02i%%" , batteryPercent);
4642 lv_label_set_align (percent, LV_LABEL_ALIGN_LEFT);
4743 lv_obj_align (percent, nullptr , LV_ALIGN_CENTER, 0 , -60 );
4844
@@ -72,24 +68,22 @@ BatteryInfo::~BatteryInfo() {
7268void BatteryInfo::UpdateAnim () {
7369 batteryPercent = batteryController.PercentRemaining ();
7470
75- if (batteryPercent >= 0 ) {
76- if (batteryController.IsCharging () and batteryPercent < 100 ) {
77- animation += 1 ;
78- if (animation >= 100 ) {
79- animation = 0 ;
80- }
81-
82- } else {
83- if (animation > batteryPercent) {
84- animation--;
85- }
86- if (animation < batteryPercent) {
87- animation++;
88- }
71+ if (batteryController.IsCharging () and batteryPercent < 100 ) {
72+ animation += 1 ;
73+ if (animation >= 100 ) {
74+ animation = 0 ;
8975 }
9076
91- lv_bar_set_value (charging_bar, animation, LV_ANIM_OFF);
77+ } else {
78+ if (animation > batteryPercent) {
79+ animation--;
80+ }
81+ if (animation < batteryPercent) {
82+ animation++;
83+ }
9284 }
85+
86+ lv_bar_set_value (charging_bar, animation, LV_ANIM_OFF);
9387}
9488
9589void BatteryInfo::UpdateScreen () {
@@ -99,28 +93,22 @@ void BatteryInfo::UpdateScreen() {
9993 batteryPercent = batteryController.PercentRemaining ();
10094 batteryVoltage = batteryController.Voltage ();
10195
102- if (batteryPercent >= 0 ) {
103- if (batteryController.IsCharging () and batteryPercent < 100 ) {
104- lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
105- lv_label_set_text_static (status, " Charging" );
106- } else if (batteryPercent == 100 ) {
107- lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
108- lv_label_set_text_static (status, " Fully charged" );
109- } else if (batteryPercent < 10 ) {
110- lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
111- lv_label_set_text_static (status, " Battery low" );
112- } else {
113- lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
114- lv_label_set_text_static (status, " Discharging" );
115- }
116-
117- lv_label_set_text_fmt (percent, " %02i%%" , batteryPercent);
118-
96+ if (batteryController.IsCharging () and batteryPercent < 100 ) {
97+ lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
98+ lv_label_set_text_static (status, " Charging" );
99+ } else if (batteryPercent == 100 ) {
100+ lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
101+ lv_label_set_text_static (status, " Fully charged" );
102+ } else if (batteryPercent < 10 ) {
103+ lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
104+ lv_label_set_text_static (status, " Battery low" );
119105 } else {
120- lv_label_set_text_static (status, " Reading Battery status " );
121- lv_label_set_text (percent , " --% " );
106+ lv_obj_set_style_local_bg_color (charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN );
107+ lv_label_set_text_static (status , " Discharging " );
122108 }
123109
110+ lv_label_set_text_fmt (percent, " %02i%%" , batteryPercent);
111+
124112 lv_obj_align (status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0 , 20 );
125113 lv_label_set_text_fmt (voltage, " %1i.%02i volts" , batteryVoltage / 1000 , batteryVoltage % 1000 / 10 );
126114}
0 commit comments