You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
SensorManager: skip if no iio sensor connected
This fixes: Traceback (most recent call last): File "<stdin>", line 31, in <module> File "lib/mpos/main.py", line 150, in <module> File "lib/mpos/board/linux.py", line 133, in <module> File "lib/mpos/sensor_manager.py", line 286, in class_method File "lib/mpos/sensor_manager.py", line 109, in init_iio File "lib/mpos/imu/manager.py", line 52, in init_iio File "lib/mpos/imu/drivers/iio.py", line 21, in __init__ File "lib/mpos/imu/drivers/iio.py", line 129, in ensure_sampling_frequency_max TypeError: unsupported types for __add__: 'NoneType', 'str'
This commit is contained in:
@@ -18,12 +18,21 @@ class IIODriver(IMUDriverBase):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.accel_path = self.find_iio_device_with_file("in_accel_x_raw")
|
||||
self.ensure_sampling_frequency_max(self.accel_path)
|
||||
self.mag_path = self.find_iio_device_with_file("in_magn_x_raw")
|
||||
self.ensure_sampling_frequency_max(self.mag_path)
|
||||
self.gyro_path = self.find_iio_device_with_file("in_anglvel_x_raw")
|
||||
self.ensure_sampling_frequency_max(self.gyro_path)
|
||||
|
||||
self.available = any((self.accel_path, self.mag_path, self.gyro_path))
|
||||
|
||||
if not self.available:
|
||||
print("IIO: no IIO sensors detected")
|
||||
return
|
||||
|
||||
if self.accel_path:
|
||||
self.ensure_sampling_frequency_max(self.accel_path)
|
||||
if self.mag_path:
|
||||
self.ensure_sampling_frequency_max(self.mag_path)
|
||||
if self.gyro_path:
|
||||
self.ensure_sampling_frequency_max(self.gyro_path)
|
||||
|
||||
def _p(self, name: str):
|
||||
return self.accel_path + "/" + name
|
||||
|
||||
@@ -126,6 +135,9 @@ class IIODriver(IMUDriverBase):
|
||||
Returns:
|
||||
(changed: bool, max_freq: float or None, current: float or None)
|
||||
"""
|
||||
if not dev_path:
|
||||
return (False, None, None)
|
||||
|
||||
sf = dev_path + "/sampling_frequency"
|
||||
sfa = dev_path + "/sampling_frequency_available"
|
||||
|
||||
@@ -280,8 +292,11 @@ class IIODriver(IMUDriverBase):
|
||||
)
|
||||
|
||||
def read_magnetometer(self) -> tuple[float, float, float]:
|
||||
if not self.mag_path:
|
||||
return (0.0, 0.0, 0.0)
|
||||
|
||||
gx = self._read_raw_scaled(self.mag_path + "/" + "in_magn_x_raw", self.mag_path + "/" + "in_magn_x_scale")
|
||||
gy = self._read_raw_scaled(self.mag_path + "/" + "in_magn_y_raw", self.mag_path + "/" + "in_magn_y_scale")
|
||||
gz = self._read_raw_scaled(self.mag_path + "/" + "in_magn_z_raw", self.mag_path + "/" + "in_magn_z_scale")
|
||||
gz = self._read_raw_scaled(self.mag_path + "/" + "in_magn_z_raw", self.mag_path + "/" + "in_magn_z_scale")
|
||||
|
||||
return self._apply_mount_matrix(gx, gy, gz, self.mag_path)
|
||||
|
||||
@@ -50,6 +50,12 @@ class ImuManager:
|
||||
|
||||
def init_iio(self):
|
||||
self._imu_driver = IIODriver()
|
||||
if not getattr(self._imu_driver, "available", True):
|
||||
self._imu_driver = None
|
||||
self._sensor_list = []
|
||||
self._initialized = False
|
||||
return False
|
||||
|
||||
self._sensor_list = [
|
||||
Sensor(
|
||||
name="Magnetometer",
|
||||
|
||||
Reference in New Issue
Block a user