Skip to content

Commit 1971e1c

Browse files
UI: Don't show battery icon if not present
1 parent bc62096 commit 1971e1c

2 files changed

Lines changed: 40 additions & 36 deletions

File tree

internal_filesystem/lib/mpos/board/matouch_esp32_s3_2_8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def apply_cam_settings(cam_obj, prefs):
212212
# MaTouch ESP32-S3 has OV3660 camera (3MP, up to 2048x1536)
213213
# Camera pins are available but initialization is handled by the camera driver
214214
CameraManager.add_camera(CameraManager.Camera(
215-
lens_facing=CameraManager.CameraCharacteristics.LENS_FACING_BACK,
215+
lens_facing=CameraManager.CameraCharacteristics.LENS_FACING_FRONT,
216216
name="OV3660",
217217
vendor="OmniVision",
218218
init=init_cam,

internal_filesystem/lib/mpos/ui/topmenu.py

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,49 @@ def create_notification_bar():
106106
#notif_icon = lv.label(notification_bar)
107107
#notif_icon.set_text(lv.SYMBOL.BELL)
108108
#notif_icon.align_to(time_label, lv.ALIGN.OUT_RIGHT_MID, PADDING_TINY, 0)
109-
# Battery percentage
110-
#battery_label = lv.label(notification_bar)
111-
#battery_label.set_text("100%")
112-
#battery_label.align(lv.ALIGN.RIGHT_MID, 0, 0)
113-
#battery_label.add_flag(lv.obj.FLAG.HIDDEN)
114-
# Battery icon
115-
battery_icon = lv.label(notification_bar)
116-
battery_icon.set_text(lv.SYMBOL.BATTERY_FULL)
117-
#battery_icon.align_to(battery_label, lv.ALIGN.OUT_LEFT_MID, 0, 0)
118-
battery_icon.align(lv.ALIGN.RIGHT_MID, -DisplayMetrics.pct_of_width(10), 0)
119-
battery_icon.add_flag(lv.obj.FLAG.HIDDEN) # keep it hidden until it has a correct value
109+
120110
# WiFi icon
121111
wifi_icon = lv.label(notification_bar)
122112
wifi_icon.set_text(lv.SYMBOL.WIFI)
123-
wifi_icon.align_to(battery_icon, lv.ALIGN.OUT_LEFT_MID, -DisplayMetrics.pct_of_width(1), 0)
124113
wifi_icon.add_flag(lv.obj.FLAG.HIDDEN)
114+
wifi_icon.align(lv.ALIGN.RIGHT_MID, -DisplayMetrics.pct_of_width(10), 0)
115+
116+
# Battery percentage
117+
if BatteryManager.has_battery():
118+
#battery_label = lv.label(notification_bar)
119+
#battery_label.set_text("100%")
120+
#battery_label.align(lv.ALIGN.RIGHT_MID, 0, 0)
121+
#battery_label.add_flag(lv.obj.FLAG.HIDDEN)
122+
# Battery icon
123+
battery_icon = lv.label(notification_bar)
124+
battery_icon.set_text(lv.SYMBOL.BATTERY_FULL)
125+
#battery_icon.align_to(battery_label, lv.ALIGN.OUT_LEFT_MID, 0, 0)
126+
battery_icon.align(lv.ALIGN.RIGHT_MID, -DisplayMetrics.pct_of_width(10), 0)
127+
wifi_icon.align_to(battery_icon, lv.ALIGN.OUT_LEFT_MID, -DisplayMetrics.pct_of_width(1), 0)
128+
battery_icon.add_flag(lv.obj.FLAG.HIDDEN) # keep it hidden until it has a correct value
129+
def update_battery_icon(timer=None):
130+
try:
131+
percent = BatteryManager.get_battery_percentage()
132+
except Exception as e:
133+
print(f"BatteryManager.get_battery_percentage got exception, not updating battery_icon: {e}")
134+
return
135+
if percent > 80:
136+
battery_icon.set_text(lv.SYMBOL.BATTERY_FULL)
137+
elif percent > 60:
138+
battery_icon.set_text(lv.SYMBOL.BATTERY_3)
139+
elif percent > 40:
140+
battery_icon.set_text(lv.SYMBOL.BATTERY_2)
141+
elif percent > 20:
142+
battery_icon.set_text(lv.SYMBOL.BATTERY_1)
143+
else:
144+
battery_icon.set_text(lv.SYMBOL.BATTERY_EMPTY)
145+
battery_icon.remove_flag(lv.obj.FLAG.HIDDEN)
146+
# Percentage is not shown for now:
147+
#battery_label.set_text(f"{round(percent)}%")
148+
#battery_label.remove_flag(lv.obj.FLAG.HIDDEN)
149+
update_battery_icon() # run it immediately instead of waiting for the timer
150+
lv.timer_create(update_battery_icon, BATTERY_ICON_UPDATE_INTERVAL, None)
151+
125152
# Update time
126153
def update_time(timer):
127154
hours = mpos.time.localtime()[3]
@@ -136,28 +163,6 @@ def update_time(timer):
136163
except Exception as e:
137164
print("Warning: could not check WLAN status:", str(e))
138165

139-
def update_battery_icon(timer=None):
140-
try:
141-
percent = BatteryManager.get_battery_percentage()
142-
except Exception as e:
143-
print(f"BatteryManager.get_battery_percentage got exception, not updating battery_icon: {e}")
144-
return
145-
if percent > 80:
146-
battery_icon.set_text(lv.SYMBOL.BATTERY_FULL)
147-
elif percent > 60:
148-
battery_icon.set_text(lv.SYMBOL.BATTERY_3)
149-
elif percent > 40:
150-
battery_icon.set_text(lv.SYMBOL.BATTERY_2)
151-
elif percent > 20:
152-
battery_icon.set_text(lv.SYMBOL.BATTERY_1)
153-
else:
154-
battery_icon.set_text(lv.SYMBOL.BATTERY_EMPTY)
155-
battery_icon.remove_flag(lv.obj.FLAG.HIDDEN)
156-
# Percentage is not shown for now:
157-
#battery_label.set_text(f"{round(percent)}%")
158-
#battery_label.remove_flag(lv.obj.FLAG.HIDDEN)
159-
update_battery_icon() # run it immediately instead of waiting for the timer
160-
161166
def update_wifi_icon(timer):
162167
from mpos import WifiService
163168
if WifiService.is_connected():
@@ -197,7 +202,6 @@ def update_memfree(timer):
197202
lv.timer_create(update_temperature, TEMPERATURE_UPDATE_INTERVAL, None)
198203
#lv.timer_create(update_memfree, MEMFREE_UPDATE_INTERVAL, None)
199204
lv.timer_create(update_wifi_icon, WIFI_ICON_UPDATE_INTERVAL, None)
200-
lv.timer_create(update_battery_icon, BATTERY_ICON_UPDATE_INTERVAL, None)
201205

202206
# hide bar animation
203207
global hide_bar_animation

0 commit comments

Comments
 (0)