Skip to content

Commit 7b65ec7

Browse files
Simplify
1 parent 663be36 commit 7b65ec7

File tree

6 files changed

+64
-72
lines changed

6 files changed

+64
-72
lines changed

internal_filesystem/lib/mpos/main.py

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,70 @@
55
import mpos.apps
66
import mpos.config
77
import mpos.ui
8-
from . import ui
8+
99
from .content.package_manager import PackageManager
10-
from mpos.ui.display import init_rootscreen
11-
from mpos.ui.appearance_manager import AppearanceManager
10+
from .ui.appearance_manager import AppearanceManager
11+
from .ui.display_metrics import DisplayMetrics
1212
import mpos.ui.topmenu
1313

14-
# Auto-detect and initialize hardware
15-
import sys
16-
if sys.platform == "linux" or sys.platform == "darwin": # linux and macOS
17-
board = "linux"
18-
elif sys.platform == "esp32":
19-
from machine import Pin, I2C
20-
i2c0 = I2C(0, sda=Pin(48), scl=Pin(47))
21-
if {0x15, 0x6B} <= set(i2c0.scan()): # touch screen and IMU (at least, possibly more)
22-
board = "waveshare_esp32_s3_touch_lcd_2"
23-
else:
24-
i2c0 = I2C(0, sda=Pin(9), scl=Pin(18))
25-
if {0x6B} <= set(i2c0.scan()): # IMU (plus possibly the Communicator's LANA TNY at 0x38)
26-
board = "fri3d_2024"
27-
elif {0x6A} <= set(i2c0.scan()): # IMU (plus a few others, to be added later, but this should work)
28-
board = "fri3d_2026"
14+
15+
16+
# White text on black logo works (for dark mode) and can be inverted (for light mode)
17+
logo_white = "M:builtin/res/mipmap-mdpi/MicroPythonOS-logo-white-long-w296.png" # from the MPOS-logo repo
18+
19+
# Black text on transparent logo works (for light mode) but can't be inverted (for dark mode)
20+
# Even when trying different blend modes (SUBTRACTIVE, ADDITIVE, MULTIPLY)
21+
# Even when it's on a white (instead of transparent) background
22+
#logo_black = "M:builtin/res/mipmap-mdpi/MicroPythonOS-logo-black-long-w240.png"
23+
24+
25+
def init_rootscreen():
26+
"""Initialize the root screen and set display metrics."""
27+
screen = lv.screen_active()
28+
disp = screen.get_display()
29+
width = disp.get_horizontal_resolution()
30+
height = disp.get_vertical_resolution()
31+
dpi = disp.get_dpi()
32+
33+
# Initialize DisplayMetrics with actual display values
34+
DisplayMetrics.set_resolution(width, height)
35+
DisplayMetrics.set_dpi(dpi)
36+
37+
print(f"init_rootscreen set resolution to {width}x{height} at {dpi} DPI")
38+
39+
try:
40+
img = lv.image(screen)
41+
img.set_src(logo_white)
42+
img.set_blend_mode(lv.BLEND_MODE.DIFFERENCE)
43+
img.center()
44+
except Exception as e: # if image loading fails
45+
print(f"ERROR: logo image failed, LVGL will be in a bad state and the UI will hang: {e}")
46+
import sys
47+
sys.print_exception(e)
48+
print("Trying to fall back to a simple text-based 'logo' but it won't showup because the UI broke...")
49+
label = lv.label(screen)
50+
label.set_text("MicroPythonOS")
51+
label.set_style_text_font(lv.font_montserrat_20, lv.PART.MAIN)
52+
label.center()
53+
54+
def detect_board():
55+
import sys
56+
if sys.platform == "linux" or sys.platform == "darwin": # linux and macOS
57+
return "linux"
58+
elif sys.platform == "esp32":
59+
from machine import Pin, I2C
60+
i2c0 = I2C(0, sda=Pin(48), scl=Pin(47))
61+
if {0x15, 0x6B} <= set(i2c0.scan()): # touch screen and IMU (at least, possibly more)
62+
return "waveshare_esp32_s3_touch_lcd_2"
2963
else:
30-
print("Unable to identify board, defaulting...")
31-
board = "fri3d_2024" # default fallback
64+
i2c0 = I2C(0, sda=Pin(9), scl=Pin(18))
65+
if {0x6A} <= set(i2c0.scan()): # IMU (plus a few others, to be added later, but this should work)
66+
return "fri3d_2026"
67+
else: # if {0x6B} <= set(i2c0.scan()): # IMU (plus possibly the Communicator's LANA TNY at 0x38)
68+
return "fri3d_2024"
69+
3270

71+
board = detect_board()
3372
print(f"Initializing {board} hardware")
3473
import mpos.info
3574
mpos.info.set_hardware_id(board)
@@ -45,7 +84,7 @@
4584
AppearanceManager.init(prefs)
4685
init_rootscreen()
4786
mpos.ui.topmenu.create_notification_bar()
48-
mpos.ui.topmenu.create_drawer(mpos.ui.display)
87+
mpos.ui.topmenu.create_drawer()
4988
mpos.ui.handle_back_swipe()
5089
mpos.ui.handle_top_swipe()
5190

internal_filesystem/lib/mpos/ui/camera_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ..config import SharedPreferences
44
from ..app.activity import Activity
5-
from .display import DisplayMetrics
5+
from .display_metrics import DisplayMetrics
66
from .widget_animator import WidgetAnimator
77

88
class CameraSettingsActivity(Activity):

internal_filesystem/lib/mpos/ui/display.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

internal_filesystem/lib/mpos/ui/gesture_navigation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .widget_animator import WidgetAnimator
44
from .view import back_screen
55
from mpos.ui import topmenu as topmenu
6-
from .display import DisplayMetrics
6+
from .display_metrics import DisplayMetrics
77
from .appearance_manager import AppearanceManager
88

99
downbutton = None

internal_filesystem/lib/mpos/ui/setting_activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ..app.activity import Activity
44
from .camera_activity import CameraActivity
5-
from .display import DisplayMetrics
5+
from .display_metrics import DisplayMetrics
66
from .widget_animator import WidgetAnimator
77
from ..camera_manager import CameraManager
88

internal_filesystem/lib/mpos/ui/topmenu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def update_memfree(timer):
217217

218218

219219

220-
def create_drawer(display=None):
220+
def create_drawer():
221221
global drawer
222222
drawer=lv.obj(lv.layer_top())
223223
drawer.set_size(lv.pct(100),lv.pct(90))

0 commit comments

Comments
 (0)