Skip to content

Commit

Permalink
♻️ combine sensor measurements [#1]
Browse files Browse the repository at this point in the history
Combine acc_x, acc_y, acc_z into sensor measurements in a property.
Similar to gyro.
  • Loading branch information
selyunin committed Nov 20, 2024
1 parent 71c13b9 commit 393d232
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/umrx_app_v3/sensors/bmi088.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import struct
from collections.abc import Callable


Expand Down Expand Up @@ -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("<hhh", payload)
return g_x, g_y, g_z

@property
def gyro_int_stat_1(self) -> int:
Expand Down Expand Up @@ -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("<hhh", payload)
return a_x, a_y, a_z

@property
def acc_sensor_time(self) -> int:
Expand Down

0 comments on commit 393d232

Please sign in to comment.