Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,17 @@ def accel_range(self) -> int:

@accel_range.setter
def accel_range(self, rng: int = ACCEL_4G) -> None:
old_mode = None
if self.mode != CONFIG_MODE:
old_mode = self.mode
self.mode = CONFIG_MODE
self._write_register(_PAGE_REGISTER, 0x01)
value = self._read_register(_ACCEL_CONFIG_REGISTER)
masked_value = 0b11111100 & value
self._write_register(_ACCEL_CONFIG_REGISTER, masked_value | rng)
self._write_register(_PAGE_REGISTER, 0x00)
if old_mode is not None:
self.mode = old_mode

@property
def accel_bandwidth(self) -> int:
Expand All @@ -534,11 +540,17 @@ def accel_bandwidth(self) -> int:
def accel_bandwidth(self, bandwidth: int = ACCEL_62_5HZ) -> None:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
raise RuntimeError("Mode must not be a fusion mode")
old_mode = None
if self.mode != CONFIG_MODE:
old_mode = self.mode
self.mode = CONFIG_MODE
self._write_register(_PAGE_REGISTER, 0x01)
value = self._read_register(_ACCEL_CONFIG_REGISTER)
masked_value = 0b11100011 & value
self._write_register(_ACCEL_CONFIG_REGISTER, masked_value | bandwidth)
self._write_register(_PAGE_REGISTER, 0x00)
if old_mode is not None:
self.mode = old_mode

@property
def accel_mode(self) -> int:
Expand Down Expand Up @@ -574,11 +586,17 @@ def gyro_range(self) -> int:
def gyro_range(self, rng: int = GYRO_2000_DPS) -> None:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
raise RuntimeError("Mode must not be a fusion mode")
old_mode = None
if self.mode != CONFIG_MODE:
old_mode = self.mode
self.mode = CONFIG_MODE
self._write_register(_PAGE_REGISTER, 0x01)
value = self._read_register(_GYRO_CONFIG_0_REGISTER)
masked_value = 0b00111000 & value
self._write_register(_GYRO_CONFIG_0_REGISTER, masked_value | rng)
self._write_register(_PAGE_REGISTER, 0x00)
if old_mode is not None:
self.mode = old_mode

@property
def gyro_bandwidth(self) -> int:
Expand All @@ -594,11 +612,17 @@ def gyro_bandwidth(self) -> int:
def gyro_bandwidth(self, bandwidth: int = GYRO_32HZ) -> None:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
raise RuntimeError("Mode must not be a fusion mode")
old_mode = None
if self.mode != CONFIG_MODE:
old_mode = self.mode
self.mode = CONFIG_MODE
self._write_register(_PAGE_REGISTER, 0x01)
value = self._read_register(_GYRO_CONFIG_0_REGISTER)
masked_value = 0b00000111 & value
self._write_register(_GYRO_CONFIG_0_REGISTER, masked_value | bandwidth)
self._write_register(_PAGE_REGISTER, 0x00)
if old_mode is not None:
self.mode = old_mode

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