Skip to content

Commit b4577d0

Browse files
Fix SensorManager
1 parent eaa2ee3 commit b4577d0

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- API: restore sys.path after starting app
1010
- API: add AudioFlinger for audio playback (i2s DAC and buzzer)
1111
- API: add LightsManager for multicolor LEDs
12+
- API: add SensorManager for IMU/accelerometers, temperature sensors etc.
1213
- About app: add free, used and total storage space info
1314
- AppStore app: remove unnecessary scrollbar over publisher's name
1415
- Camera app: massive overhaul!

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,9 @@ def update_frame(self, a, b):
10101010
- **Units**: Standard SI (m/s² for acceleration, deg/s for gyroscope, °C for temperature)
10111011
- **Calibration**: Persistent via SharedPreferences (`data/com.micropythonos.sensors/config.json`)
10121012
- **Thread-safe**: Uses locks for concurrent access
1013-
- **Auto-detection**: Identifies IMU type via chip ID registers
1013+
- **Auto-detection**: Identifies IMU type via chip ID registers (QMI8658: chip_id=0x05 at reg=0x00, WSEN_ISDS: chip_id=0x6A at reg=0x0F)
10141014
- **Desktop**: Functions return `None` (graceful fallback) on desktop builds
1015+
- **Important**: Driver constants defined with `const()` cannot be imported at runtime - SensorManager uses hardcoded values instead
10151016

10161017
### Driver Locations
10171018

internal_filesystem/lib/mpos/board/linux.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def adc_to_voltage(adc_value):
113113
# === SENSOR HARDWARE ===
114114
# Note: Desktop builds have no sensor hardware
115115
import mpos.sensor_manager as SensorManager
116-
# Don't call init() - SensorManager functions will return None/False
116+
117+
# Initialize with no I2C bus - will detect MCU temp if available
118+
# (On Linux desktop, this will fail gracefully but set _initialized flag)
119+
SensorManager.init(None)
117120

118121
print("linux.py finished")
119122

internal_filesystem/lib/mpos/sensor_manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def init(i2c_bus, address=0x6B):
9898
# Try QMI8658 first (Waveshare board)
9999
if i2c_bus:
100100
try:
101-
from mpos.hardware.drivers.qmi8658 import QMI8658, _QMI8685_PARTID, _REG_PARTID
101+
from mpos.hardware.drivers.qmi8658 import QMI8658
102+
# QMI8658 constants (can't import const() values)
103+
_QMI8685_PARTID = 0x05
104+
_REG_PARTID = 0x00
102105
chip_id = i2c_bus.readfrom_mem(address, _REG_PARTID, 1)[0]
103106
if chip_id == _QMI8685_PARTID:
104107
print("[SensorManager] Detected QMI8658 IMU")
@@ -308,7 +311,10 @@ class _QMI8658Driver(_IMUDriver):
308311
"""Wrapper for QMI8658 IMU (Waveshare board)."""
309312

310313
def __init__(self, i2c_bus, address):
311-
from mpos.hardware.drivers.qmi8658 import QMI8658, _ACCELSCALE_RANGE_8G, _GYROSCALE_RANGE_256DPS
314+
from mpos.hardware.drivers.qmi8658 import QMI8658
315+
# QMI8658 scale constants (can't import const() values)
316+
_ACCELSCALE_RANGE_8G = 0b10
317+
_GYROSCALE_RANGE_256DPS = 0b100
312318
self.sensor = QMI8658(
313319
i2c_bus,
314320
address=address,

0 commit comments

Comments
 (0)