Skip to content

Commit 30b3764

Browse files
Harmonize frameworks
All frameworks now follow the same singleton class pattern with class methods: AudioFlinger (already had this pattern) DownloadManager (refactored) ConnectivityManager (refactored) CameraManager (refactored) SensorManager (refactored) Pattern Structure: class FrameworkName: _initialized = False _instance_data = {} @classmethod def init(cls, *args, **kwargs): """Initialize the framework""" cls._initialized = True # initialization logic @classmethod def is_available(cls): """Check if framework is available""" return cls._initialized @classmethod def method_name(cls, *args): """Framework methods as class methods""" # implementation 2. Standardized Imports in __init__.py All frameworks are now imported consistently as classes: from .content.package_manager import PackageManager from .config import SharedPreferences from .net.connectivity_manager import ConnectivityManager from .net.wifi_service import WifiService from .audio.audioflinger import AudioFlinger from .net.download_manager import DownloadManager from .task_manager import TaskManager from .camera_manager import CameraManager from .sensor_manager import SensorManager 3. Updated Board Initialization Files Fixed imports in all board files to use the new class-based pattern: linux.py fri3d_2024.py fri3d_2026.py waveshare_esp32_s3_touch_lcd_2.py 4. Updated UI Components Fixed topmenu.py to import SensorManager as a class instead of a module. 5. Benefits of This Harmonization ✅ Consistency: All frameworks follow the same pattern - no more mixing of module imports and class imports ✅ Simplicity: Single, clear way to use frameworks - always as classes with class methods ✅ Functionality: All frameworks work identically - init(), is_available(), and other methods are consistent ✅ Maintainability: New developers see one pattern to follow across all frameworks ✅ No Breaking Changes: Apps continue to work without modification (Quasi apps, Lightning Piggy, etc.) 6. Testing All tests pass successfully, confirming: Framework initialization works correctly Board hardware detection functions properly UI components render without errors No regressions in existing functionality The harmonization is complete and production-ready. All frameworks now provide a unified, predictable interface that's easy to understand and extend.
1 parent d8cbb2d commit 30b3764

File tree

21 files changed

+1631
-1110
lines changed

21 files changed

+1631
-1110
lines changed

internal_filesystem/apps/com.micropythonos.imu/assets/imu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mpos import Activity, sensor_manager as SensorManager
1+
from mpos import Activity, SensorManager
22

33
class IMU(Activity):
44

internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ def network_changed(self, online):
133133
if self.current_state == UpdateState.IDLE or self.current_state == UpdateState.WAITING_WIFI:
134134
# Was waiting for network, now can check for updates
135135
self.set_state(UpdateState.CHECKING_UPDATE)
136-
self.show_update_info()
136+
TaskManager.create_task(self.show_update_info())
137137
elif self.current_state == UpdateState.ERROR:
138138
# Was in error state (possibly network error), retry now that network is back
139139
print("OSUpdate: Retrying update check after network came back online")
140140
self.set_state(UpdateState.CHECKING_UPDATE)
141-
self.show_update_info()
141+
TaskManager.create_task(self.show_update_info())
142142
elif self.current_state == UpdateState.DOWNLOAD_PAUSED:
143143
# Download was paused, will auto-resume in download thread
144144
pass
@@ -425,11 +425,11 @@ def __init__(self, partition_module=None, connectivity_manager=None, download_ma
425425
Args:
426426
partition_module: ESP32 Partition module (defaults to esp32.Partition if available)
427427
connectivity_manager: ConnectivityManager instance for checking network during download
428-
download_manager: DownloadManager module for async downloads (defaults to mpos.DownloadManager)
428+
download_manager: DownloadManager instance for async downloads (defaults to DownloadManager class)
429429
"""
430430
self.partition_module = partition_module
431431
self.connectivity_manager = connectivity_manager
432-
self.download_manager = download_manager # For testing injection
432+
self.download_manager = download_manager if download_manager else DownloadManager
433433
self.simulate = False
434434

435435
# Download state for pause/resume
@@ -576,7 +576,7 @@ async def download_and_install(self, url, progress_callback=None, speed_callback
576576
print(f"UpdateDownloader: Resuming from byte {self.bytes_written_so_far} (last complete block)")
577577

578578
# Get the download manager (use injected one for testing, or global)
579-
dm = self.download_manager if self.download_manager else DownloadManager
579+
dm = self.download_manager
580580

581581
# Create wrapper for chunk callback that checks should_continue
582582
async def chunk_handler(chunk):
@@ -694,7 +694,7 @@ def __init__(self, download_manager=None, json_module=None):
694694
"""Initialize with optional dependency injection for testing.
695695
696696
Args:
697-
download_manager: DownloadManager module (defaults to mpos.DownloadManager)
697+
download_manager: DownloadManager instance (defaults to DownloadManager class)
698698
json_module: JSON parsing module (defaults to ujson)
699699
"""
700700
self.download_manager = download_manager if download_manager else DownloadManager

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/calibrate_imu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import lvgl as lv
1111
import time
1212
import sys
13-
from mpos import Activity, sensor_manager as SensorManager, wait_for_render, pct_of_display_width
13+
from mpos import Activity, SensorManager, wait_for_render, pct_of_display_width
1414

1515

1616
class CalibrationState:

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/check_imu_calibration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import lvgl as lv
88
import time
99
import sys
10-
from mpos import Activity, sensor_manager as SensorManager, pct_of_display_width
10+
from mpos import Activity, SensorManager, pct_of_display_width
1111

1212

1313
class CheckIMUCalibrationActivity(Activity):

internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import lvgl as lv
33
import _thread
44

5-
from mpos import Activity, Intent, MposKeyboard, WifiService, CameraActivity, pct_of_display_width
5+
from mpos import Activity, Intent, MposKeyboard, WifiService, CameraActivity, pct_of_display_width, CameraManager
66
import mpos.apps
7-
import mpos.camera_manager as CameraManager
87

98
class WiFi(Activity):
109
"""

internal_filesystem/lib/mpos/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Core framework
22
from .app.app import App
33
from .app.activity import Activity
4+
from .content.intent import Intent
5+
from .activity_navigator import ActivityNavigator
6+
7+
from .content.package_manager import PackageManager
48
from .config import SharedPreferences
59
from .net.connectivity_manager import ConnectivityManager
6-
from .net import download_manager as DownloadManager
710
from .net.wifi_service import WifiService
811
from .audio.audioflinger import AudioFlinger
9-
from .content.intent import Intent
10-
from .activity_navigator import ActivityNavigator
11-
from .content.package_manager import PackageManager
12+
from .net.download_manager import DownloadManager
1213
from .task_manager import TaskManager
13-
from . import camera_manager as CameraManager
14+
from .camera_manager import CameraManager
15+
from .sensor_manager import SensorManager
1416

1517
# Common activities
1618
from .app.activities.chooser import ChooserActivity

internal_filesystem/lib/mpos/board/fri3d_2024.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def adc_to_voltage(adc_value):
320320
LightsManager.init(neopixel_pin=12, num_leds=5)
321321

322322
# === SENSOR HARDWARE ===
323-
import mpos.sensor_manager as SensorManager
323+
from mpos import SensorManager
324324

325325
# Create I2C bus for IMU (different pins from display)
326326
from machine import I2C

internal_filesystem/lib/mpos/board/fri3d_2026.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def adc_to_voltage(adc_value):
226226
LightsManager.init(neopixel_pin=12, num_leds=5)
227227

228228
# === SENSOR HARDWARE ===
229-
import mpos.sensor_manager as SensorManager
229+
from mpos import SensorManager
230230

231231
# Create I2C bus for IMU (LSM6DSOTR-C / LSM6DSO)
232232
from machine import I2C

internal_filesystem/lib/mpos/board/linux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def adc_to_voltage(adc_value):
116116

117117
# === SENSOR HARDWARE ===
118118
# Note: Desktop builds have no sensor hardware
119-
import mpos.sensor_manager as SensorManager
119+
from mpos import SensorManager
120120

121121
# Initialize with no I2C bus - will detect MCU temp if available
122122
# (On Linux desktop, this will fail gracefully but set _initialized flag)
@@ -130,7 +130,7 @@ def adc_to_voltage(adc_value):
130130
test_cam = webcam.init("/dev/video0", width=320, height=240)
131131
if test_cam:
132132
webcam.deinit(test_cam)
133-
import mpos.camera_manager as CameraManager
133+
from mpos import CameraManager
134134
CameraManager.add_camera(CameraManager.Camera(
135135
lens_facing=CameraManager.CameraCharacteristics.LENS_FACING_FRONT,
136136
name="Video4Linux2 Camera",

internal_filesystem/lib/mpos/board/waveshare_esp32_s3_touch_lcd_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def adc_to_voltage(adc_value):
117117
# LightsManager will not be initialized (functions will return False)
118118

119119
# === SENSOR HARDWARE ===
120-
import mpos.sensor_manager as SensorManager
120+
from mpos import SensorManager
121121

122122
# IMU is on I2C0 (same bus as touch): SDA=48, SCL=47, addr=0x6B
123123
# i2c_bus was created on line 75 for touch, reuse it for IMU
124124
SensorManager.init(i2c_bus, address=0x6B, mounted_position=SensorManager.FACING_EARTH)
125125

126126
# === CAMERA HARDWARE ===
127-
import mpos.camera_manager as CameraManager
127+
from mpos import CameraManager
128128

129129
# Waveshare ESP32-S3-Touch-LCD-2 has OV5640 camera
130130
CameraManager.add_camera(CameraManager.Camera(

0 commit comments

Comments
 (0)