Skip to content

Made temperature more stable on raspberry pi #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 24 additions & 9 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import time
import struct

from os import uname
from micropython import const
from adafruit_bus_device.i2c_device import I2CDevice
from adafruit_register.i2c_struct import Struct, UnaryStruct
Expand Down Expand Up @@ -146,6 +147,20 @@ def __set__(self, obj, value):


class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-methods
def __init__(self, register_address, struct_format):
super().__init__(register_address, struct_format)
self.last_val = 0xFFFF

def __get__(self, obj, objtype=None):
result = super().__get__(obj, objtype)
if uname().sysname == "Linux":
if abs(result - self.last_val) == 128:
result = super().__get__(obj, objtype)
if abs(result - self.last_val) == 128:
return 0b00111111 & result
self.last_val = result
return result

def __set__(self, obj, value):
raise NotImplementedError()

Expand Down Expand Up @@ -456,7 +471,7 @@ def _gravity(self):

@property
def accel_range(self):
""" Switch the accelerometer range and return the new range. Default value: +/- 4g
"""Switch the accelerometer range and return the new range. Default value: +/- 4g
See table 3-8 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -474,7 +489,7 @@ def accel_range(self, rng=ACCEL_4G):

@property
def accel_bandwidth(self):
""" Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz
"""Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz
See table 3-8 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -494,7 +509,7 @@ def accel_bandwidth(self, bandwidth=ACCEL_62_5HZ):

@property
def accel_mode(self):
""" Switch the accelerometer mode and return the new mode. Default value: Normal
"""Switch the accelerometer mode and return the new mode. Default value: Normal
See table 3-8 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -514,7 +529,7 @@ def accel_mode(self, mode=ACCEL_NORMAL_MODE):

@property
def gyro_range(self):
""" Switch the gyroscope range and return the new range. Default value: 2000 dps
"""Switch the gyroscope range and return the new range. Default value: 2000 dps
See table 3-9 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -534,7 +549,7 @@ def gyro_range(self, rng=GYRO_2000_DPS):

@property
def gyro_bandwidth(self):
""" Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz
"""Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz
See table 3-9 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -554,7 +569,7 @@ def gyro_bandwidth(self, bandwidth=GYRO_32HZ):

@property
def gyro_mode(self):
""" Switch the gyroscope mode and return the new mode. Default value: Normal
"""Switch the gyroscope mode and return the new mode. Default value: Normal
See table 3-9 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -574,7 +589,7 @@ def gyro_mode(self, mode=GYRO_NORMAL_MODE):

@property
def magnet_rate(self):
""" Switch the magnetometer data output rate and return the new rate. Default value: 20Hz
"""Switch the magnetometer data output rate and return the new rate. Default value: 20Hz
See table 3-10 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -594,7 +609,7 @@ def magnet_rate(self, rate=MAGNET_20HZ):

@property
def magnet_operation_mode(self):
""" Switch the magnetometer operation mode and return the new mode. Default value: Regular
"""Switch the magnetometer operation mode and return the new mode. Default value: Regular
See table 3-10 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand All @@ -614,7 +629,7 @@ def magnet_operation_mode(self, mode=MAGNET_REGULAR_MODE):

@property
def magnet_mode(self):
""" Switch the magnetometer power mode and return the new mode. Default value: Forced
"""Switch the magnetometer power mode and return the new mode. Default value: Forced
See table 3-10 in the datasheet.
"""
self._write_register(_PAGE_REGISTER, 0x01)
Expand Down