From 56cfa8be1cec0e7fc7df9bd8ac4411a67428a3c7 Mon Sep 17 00:00:00 2001 From: Li Hua Qian Date: Tue, 12 Dec 2023 16:19:17 +0800 Subject: [PATCH] iot2050-event-record: Access sensors via platform nodes Sometimes the different kernel module loading order will make sensors event record not work. Retrieve the iio:device from sensors' plaform device nodes, independent of kernel module loading order. Signed-off-by: Li Hua Qian --- .../files/iot2050-event-record.py | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/recipes-app/iot2050-event-record/files/iot2050-event-record.py b/recipes-app/iot2050-event-record/files/iot2050-event-record.py index 579c7f9b1..dc6439b8d 100644 --- a/recipes-app/iot2050-event-record/files/iot2050-event-record.py +++ b/recipes-app/iot2050-event-record/files/iot2050-event-record.py @@ -133,17 +133,33 @@ def record_eio_events(): write_event(EVENT_TYPES["eio"], event) time.sleep(5) -IIO_ACCEL_X_RAW = "/sys/bus/iio/devices/iio:device2/in_accel_x_raw" -IIO_ACCEL_Y_RAW = "/sys/bus/iio/devices/iio:device2/in_accel_y_raw" -IIO_ACCEL_Z_RAW = "/sys/bus/iio/devices/iio:device2/in_accel_z_raw" -IIO_LUX_RAW = "/sys/bus/iio/devices/iio:device0/in_illuminance0_raw" + + +IIO_IMU_PATH = "/sys/devices/platform/bus@100000/2030000.i2c/i2c-5/5-006a/" +IIO_LUX_PATH = "/sys/devices/platform/bus@100000/2030000.i2c/i2c-5/5-0044/" ACCEL_CRITICAL_VALUE = 1000 LUX_CRITICAL_VALUE = 300 def record_sensor_events(): - with open(IIO_ACCEL_X_RAW, 'r') as x, \ - open(IIO_ACCEL_Y_RAW, 'r') as y, \ - open(IIO_ACCEL_Z_RAW, 'r') as z, \ - open(IIO_LUX_RAW, 'r') as l: + accel_x_raw = "{}/in_accel_x_raw" + accel_y_raw = "{}/in_accel_y_raw" + accel_z_raw = "{}/in_accel_z_raw" + lux_raw = "{}/in_illuminance0_raw" + imu_w = os.walk(IIO_IMU_PATH) + lux_w = os.walk(IIO_LUX_PATH) + for (dirpath, dirnames, filenames) in imu_w: + if "in_accel_x_raw" in filenames: + accel_x_raw = accel_x_raw.format(dirpath) + accel_y_raw = accel_y_raw.format(dirpath) + accel_z_raw = accel_z_raw.format(dirpath) + break + for (dirpath, dirnames, filenames) in lux_w: + if "in_illuminance0_raw" in filenames: + lux_raw = lux_raw.format(dirpath) + break + with open(accel_x_raw, 'r') as x, \ + open(accel_y_raw, 'r') as y, \ + open(accel_z_raw, 'r') as z, \ + open(lux_raw, 'r') as l: is_uncovered = False while True: # Detect tilt sensor event