From 393d232741db2f1784c6a6ca78e52d6b3e2c1750 Mon Sep 17 00:00:00 2001 From: Konstantin Selyunin Date: Wed, 20 Nov 2024 21:35:40 +0100 Subject: [PATCH] :recycle: combine sensor measurements [#1] Combine acc_x, acc_y, acc_z into sensor measurements in a property. Similar to gyro. --- src/umrx_app_v3/sensors/bmi088.py | 35 ++++++++----------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/umrx_app_v3/sensors/bmi088.py b/src/umrx_app_v3/sensors/bmi088.py index b7a278c..40afcb3 100644 --- a/src/umrx_app_v3/sensors/bmi088.py +++ b/src/umrx_app_v3/sensors/bmi088.py @@ -1,3 +1,4 @@ +import struct from collections.abc import Callable @@ -77,19 +78,10 @@ def gyro_chip_id(self) -> int: return self.read_gyro(BMI088.gyro_chip_id_addr) @property - def gyro_rate_x(self) -> int: - lsb, msb = self.read_gyro(BMI088.gyro_rate_x_lsb_addr, 2) - return (msb << 8) | lsb - - @property - def gyro_rate_y(self) -> int: - lsb, msb = self.read_gyro(BMI088.gyro_rate_y_lsb_addr, 2) - return (msb << 8) | lsb - - @property - def gyro_rate_z(self) -> int: - lsb, msb = self.read_gyro(BMI088.gyro_rate_z_lsb_addr, 2) - return (msb << 8) | lsb + def gyro_rate(self) -> tuple[int, int, int]: + payload = self.read_gyro(BMI088.gyro_rate_x_lsb_addr, 6) + g_x, g_y, g_z = struct.unpack(" int: @@ -210,19 +202,10 @@ def acc_status(self) -> int: return self.read_accel(BMI088.acc_status_addr) @property - def acc_x(self) -> int: - lsb, msb = self.read_accel(BMI088.acc_x_lsb_addr, 2) - return (msb << 8) | lsb - - @property - def acc_y(self) -> int: - lsb, msb = self.read_accel(BMI088.acc_y_lsb_addr, 2) - return (msb << 8) | lsb - - @property - def acc_z(self) -> int: - lsb, msb = self.read_accel(BMI088.acc_z_lsb_addr, 2) - return (msb << 8) | lsb + def acceleration(self) -> tuple[int, int, int]: + payload = self.read_accel(BMI088.acc_x_lsb_addr, 6) + a_x, a_y, a_z = struct.unpack(" int: