|
5 | 5 | import mpos.apps |
6 | 6 | import mpos.config |
7 | 7 | import mpos.ui |
8 | | -from . import ui |
| 8 | + |
9 | 9 | 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 |
12 | 12 | import mpos.ui.topmenu |
13 | 13 |
|
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" |
29 | 63 | 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 | + |
32 | 70 |
|
| 71 | +board = detect_board() |
33 | 72 | print(f"Initializing {board} hardware") |
34 | 73 | import mpos.info |
35 | 74 | mpos.info.set_hardware_id(board) |
|
45 | 84 | AppearanceManager.init(prefs) |
46 | 85 | init_rootscreen() |
47 | 86 | mpos.ui.topmenu.create_notification_bar() |
48 | | -mpos.ui.topmenu.create_drawer(mpos.ui.display) |
| 87 | +mpos.ui.topmenu.create_drawer() |
49 | 88 | mpos.ui.handle_back_swipe() |
50 | 89 | mpos.ui.handle_top_swipe() |
51 | 90 |
|
|
0 commit comments