Skip to content

Commit d783bed

Browse files
authored
Add temperature support
1 parent fee9519 commit d783bed

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

adafruit_lsm6ds/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
174174
# Structs
175175
_raw_accel_data = Struct(_LSM6DS_OUTX_L_A, "<hhh")
176176
_raw_gyro_data = Struct(_LSM6DS_OUTX_L_G, "<hhh")
177+
_raw_temp_data = Struct(_LSM6DS_OUT_TEMP_L, "<hh")
178+
177179
# RWBits:
178180

179181
_accel_range = RWBits(2, _LSM6DS_CTRL1_XL, 2)
180182
_accel_data_rate = RWBits(4, _LSM6DS_CTRL1_XL, 4)
181183

184+
182185
_gyro_data_rate = RWBits(4, _LSM6DS_CTRL2_G, 4)
183186
_gyro_range = RWBits(2, _LSM6DS_CTRL2_G, 2)
184187
_gyro_range_125dps = RWBit(_LSM6DS_CTRL2_G, 1)
@@ -248,6 +251,15 @@ def _add_accel_ranges():
248251
)
249252
)
250253

254+
@property
255+
def temperature(self):
256+
raw_temp_data = self._raw_temp_data
257+
258+
temperature_raw = raw_temp_data[0] | (raw_temp_data[1] << 8)
259+
temperature_c = temperature_raw / 16.0 + 25.0
260+
261+
return temperature_c
262+
251263
@property
252264
def acceleration(self):
253265
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""

0 commit comments

Comments
 (0)