1616
1717CLOCK_UPDATE_INTERVAL = 1000 # 10 or even 1 ms doesn't seem to change the framerate but 100ms is enough
1818WIFI_ICON_UPDATE_INTERVAL = 1500
19- BATTERY_ICON_UPDATE_INTERVAL = 30000
19+ BATTERY_ICON_UPDATE_INTERVAL = 5000
2020TEMPERATURE_UPDATE_INTERVAL = 2000
2121MEMFREE_UPDATE_INTERVAL = 5000 # not too frequent because there's a forced gc.collect() to give it a reliable value
2222
@@ -136,15 +136,8 @@ def init_rootscreen():
136136rootlabel .set_text ("Welcome to MicroPythonOS" )
137137rootlabel .center ()
138138
139-
140- timer1 = None
141- timer2 = None
142- timer3 = None
143- timer4 = None
144-
145139def create_notification_bar ():
146140global notification_bar
147- global timer1 ,timer2 ,timer3 ,timer4
148141# Create notification bar
149142notification_bar = lv .obj (lv .layer_top ())
150143notification_bar .set_size (lv .pct (100 ),NOTIFICATION_BAR_HEIGHT )
@@ -172,15 +165,16 @@ def create_notification_bar():
172165#notif_icon.set_text(lv.SYMBOL.BELL)
173166#notif_icon.align_to(time_label, lv.ALIGN.OUT_RIGHT_MID, PADDING_TINY, 0)
174167# Battery percentage
175- battery_label = lv .label (notification_bar )
176- battery_label .set_text ("100%" )
177- battery_label .align (lv .ALIGN .RIGHT_MID ,0 ,0 )
178- battery_label .add_flag (lv .obj .FLAG .HIDDEN )
168+ # battery_label = lv.label(notification_bar)
169+ # battery_label.set_text("100%")
170+ # battery_label.align(lv.ALIGN.RIGHT_MID, 0, 0)
171+ # battery_label.add_flag(lv.obj.FLAG.HIDDEN)
179172# Battery icon
180173battery_icon = lv .label (notification_bar )
181174battery_icon .set_text (lv .SYMBOL .BATTERY_FULL )
182- battery_icon .align_to (battery_label ,lv .ALIGN .OUT_LEFT_MID ,0 ,0 )
183- battery_icon .add_flag (lv .obj .FLAG .HIDDEN )
175+ #battery_icon.align_to(battery_label, lv.ALIGN.OUT_LEFT_MID, 0, 0)
176+ battery_icon .align (lv .ALIGN .RIGHT_MID ,0 ,0 )
177+ battery_icon .add_flag (lv .obj .FLAG .HIDDEN )# keep it hidden until it has a correct value
184178# WiFi icon
185179wifi_icon = lv .label (notification_bar )
186180wifi_icon .set_text (lv .SYMBOL .WIFI )
@@ -202,22 +196,21 @@ def update_time(timer):
202196print ("Warning: could not check WLAN status:" ,str (e ))
203197
204198def update_battery_icon (timer = None ):
205- volt = mpos .battery_voltage .read_battery_voltage ()
206- percent = (volt - 3.7 )* 100 / (4.2 - 3.7 )
207- battery_label .set_text (f"{ round (percent )} %" )
208- battery_label .remove_flag (lv .obj .FLAG .HIDDEN )
209- # 3.7 - 4.15 => 0.5V diff / 3 = 0.015
210- if volt > 4.15 :
199+ percent = mpos .battery_voltage .get_battery_percentage ()
200+ if percent > 80 :# 4.1V
211201battery_icon .set_text (lv .SYMBOL .BATTERY_FULL )
212- elif volt > 4 :
202+ elif percent > 60 : # 4.0V
213203battery_icon .set_text (lv .SYMBOL .BATTERY_3 )
214- elif volt > 3.85 :
204+ elif percent > 40 : # 3.9V
215205battery_icon .set_text (lv .SYMBOL .BATTERY_2 )
216- elif volt > 3.75 :
206+ elif percent > 20 : # 3.8V
217207battery_icon .set_text (lv .SYMBOL .BATTERY_1 )
218- else :
208+ else :# > 3.7V
219209battery_icon .set_text (lv .SYMBOL .BATTERY_EMPTY )
220210battery_icon .remove_flag (lv .obj .FLAG .HIDDEN )
211+ # Percentage is not shown for now:
212+ #battery_label.set_text(f"{round(percent)}%")
213+ #battery_label.remove_flag(lv.obj.FLAG.HIDDEN)
221214update_battery_icon ()# run it immediately instead of waiting for the timer
222215
223216def update_wifi_icon (timer ):
@@ -248,11 +241,11 @@ def update_memfree(timer):
248241percentage = round (free * 100 / (free + used ))
249242memfree_label .set_text (f"{ percentage } %" )
250243
251- timer1 = lv .timer_create (update_time ,CLOCK_UPDATE_INTERVAL ,None )
252- timer2 = lv .timer_create (update_temperature ,TEMPERATURE_UPDATE_INTERVAL ,None )
253- timer3 = lv .timer_create (update_memfree ,MEMFREE_UPDATE_INTERVAL ,None )
254- timer4 = lv .timer_create (update_wifi_icon ,WIFI_ICON_UPDATE_INTERVAL ,None )
255- timer5 = lv .timer_create (update_battery_icon ,BATTERY_ICON_UPDATE_INTERVAL ,None )
244+ lv .timer_create (update_time ,CLOCK_UPDATE_INTERVAL ,None )
245+ lv .timer_create (update_temperature ,TEMPERATURE_UPDATE_INTERVAL ,None )
246+ lv .timer_create (update_memfree ,MEMFREE_UPDATE_INTERVAL ,None )
247+ lv .timer_create (update_wifi_icon ,WIFI_ICON_UPDATE_INTERVAL ,None )
248+ lv .timer_create (update_battery_icon ,BATTERY_ICON_UPDATE_INTERVAL ,None )
256249
257250# hide bar animation
258251global hide_bar_animation