Add display.get_dpi() and show in About app

This commit is contained in:
Thomas Farstrike
2026-01-15 08:09:34 +01:00
parent bcfd941179
commit 22a16661ba
4 changed files with 32 additions and 44 deletions
@@ -1,4 +1,4 @@
from mpos import Activity, pct_of_display_width
from mpos import Activity, pct_of_display_width, get_display_width, get_display_height, get_dpi
import mpos.info
import sys
@@ -90,32 +90,22 @@ class About(Activity):
try:
self._add_label(screen, f"{lv.SYMBOL.SETTINGS} ESP32 Hardware", is_header=True)
import esp32
self._add_label(screen, f"Flash size: {esp32.flash_size()} bytes")
try:
psram_size = esp32.psram_size()
self._add_label(screen, f"PSRAM size: {psram_size} bytes")
except:
pass
try:
idf_version = esp32.idf_version()
self._add_label(screen, f"IDF version: {idf_version}")
except:
pass
self._add_label(screen, f"Temperature: {esp32.mcu_temperature()} °C")
except Exception as e:
print(f"Could not get ESP32 hardware info: {e}")
# Partition info (ESP32 only)
try:
self._add_label(screen, f"{lv.SYMBOL.SD_CARD} Partition Info", is_header=True)
from esp32 import Partition
current = Partition(Partition.RUNNING)
self._add_label(screen, f"Partition.RUNNING: {current}")
next_partition = current.get_next_update()
self._add_label(screen, f"Next update partition: {next_partition}")
except Exception as e:
error = f"Could not find partition info because: {e}\nIt's normal to get this error on desktop."
print(error)
self._add_label(screen, error)
# Partition info (ESP32 only)
try:
self._add_label(screen, f"{lv.SYMBOL.SD_CARD} Partition Info", is_header=True)
from esp32 import Partition
current = Partition(Partition.RUNNING)
self._add_label(screen, f"Partition.RUNNING: {current}")
next_partition = current.get_next_update()
self._add_label(screen, f"Next update partition: {next_partition}")
except Exception as e:
error = f"Could not find partition info because: {e}\nIt's normal to get this error on desktop."
print(error)
self._add_label(screen, error)
# Machine info
try:
@@ -154,16 +144,11 @@ class About(Activity):
# Display info
try:
self._add_label(screen, f"{lv.SYMBOL.IMAGE} Display", is_header=True)
disp = lv.disp_get_default()
if disp:
hor_res = disp.get_hor_res()
ver_res = disp.get_ver_res()
self._add_label(screen, f"Resolution: {hor_res}x{ver_res}")
try:
dpi = disp.get_dpi()
self._add_label(screen, f"DPI: {dpi}")
except:
pass
hor_res = get_display_width()
ver_res = get_display_height()
self._add_label(screen, f"Resolution: {hor_res}x{ver_res}")
dpi = get_dpi()
self._add_label(screen, f"Dots Per Inch (dpi): {dpi}")
except Exception as e:
print(f"Could not get display info: {e}")
+2 -2
View File
@@ -31,7 +31,7 @@ from .ui.testing import (
# UI utility functions
from .ui.display import (
pct_of_display_width, pct_of_display_height,
get_display_width, get_display_height,
get_display_width, get_display_height, get_dpi,
min_resolution, max_resolution, get_pointer_xy
)
from .ui.event import get_event_name, print_event
@@ -73,7 +73,7 @@ __all__ = [
"MposKeyboard",
# UI utility functions
"pct_of_display_width", "pct_of_display_height",
"get_display_width", "get_display_height",
"get_display_width", "get_display_height", "get_dpi",
"min_resolution", "max_resolution", "get_pointer_xy",
"get_event_name", "print_event",
"setContentView", "back_screen",
+2 -2
View File
@@ -7,7 +7,7 @@ from .theme import set_theme
from .topmenu import open_bar, close_bar, open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT
from .focus import save_and_clear_current_focusgroup
from .display import (
get_display_width, get_display_height,
get_display_width, get_display_height, get_dpi,
pct_of_display_width, pct_of_display_height,
min_resolution, max_resolution,
get_pointer_xy # ← now correct
@@ -28,7 +28,7 @@ __all__ = [
"set_theme",
"open_bar", "close_bar", "open_drawer", "drawer_open", "NOTIFICATION_BAR_HEIGHT",
"save_and_clear_current_focusgroup",
"get_display_width", "get_display_height",
"get_display_width", "get_display_height", "get_dpi",
"pct_of_display_width", "pct_of_display_height",
"min_resolution", "max_resolution",
"get_pointer_xy",
+9 -6
View File
@@ -3,14 +3,16 @@ import lvgl as lv
_horizontal_resolution = None
_vertical_resolution = None
_dpi = None
def init_rootscreen():
global _horizontal_resolution, _vertical_resolution
global _horizontal_resolution, _vertical_resolution, _dpi
screen = lv.screen_active()
disp = screen.get_display()
_horizontal_resolution = disp.get_horizontal_resolution()
_vertical_resolution = disp.get_vertical_resolution()
print(f"init_rootscreen set _vertical_resolution to {_vertical_resolution}")
_dpi = disp.get_dpi()
print(f"init_rootscreen set resolution to {_horizontal_resolution}x{_vertical_resolution} at {_dpi} DPI")
label = lv.label(screen)
label.set_text("Welcome to MicroPythonOS")
label.center()
@@ -40,11 +42,12 @@ def max_resolution():
return max(_horizontal_resolution, _vertical_resolution)
def get_display_width():
if _horizontal_resolution is None:
_init_resolution()
return _horizontal_resolution
def get_display_height():
if _vertical_resolution is None:
_init_resolution()
return _vertical_resolution
def get_dpi():
print(f"get_dpi_called {_dpi}")
return _dpi