|
29 | 29 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
|
30 | 30 | """
|
31 | 31 | from struct import unpack
|
32 |
| - |
33 | 32 | from micropython import const
|
34 | 33 | from adafruit_bus_device import i2c_device
|
35 | 34 |
|
36 | 35 | try:
|
37 | 36 | from typing import Tuple, Dict
|
38 | 37 |
|
39 | 38 | # This is only needed for typing
|
40 |
| - import busio # pylint: disable=unused-import |
| 39 | + import busio |
41 | 40 | except ImportError:
|
42 | 41 | pass
|
43 | 42 |
|
@@ -110,12 +109,12 @@ class DataRate: # pylint: disable=too-few-public-methods
|
110 | 109 | """
|
111 | 110 |
|
112 | 111 | RATE_3200_HZ: int = const(0b1111) # 1600Hz Bandwidth 140mA IDD
|
113 |
| - RATE_1600_HZ: int = const(0b1110) # 800Hz Bandwidth 90mA IDD |
114 |
| - RATE_800_HZ: int = const(0b1101) # 400Hz Bandwidth 140mA IDD |
115 |
| - RATE_400_HZ: int = const(0b1100) # 200Hz Bandwidth 140mA IDD |
116 |
| - RATE_200_HZ: int = const(0b1011) # 100Hz Bandwidth 140mA IDD |
117 |
| - RATE_100_HZ: int = const(0b1010) # 50Hz Bandwidth 140mA IDD |
118 |
| - RATE_50_HZ: int = const(0b1001) # 25Hz Bandwidth 90mA IDD |
| 112 | + RATE_1600_HZ: int = const(0b1110) # 800Hz Bandwidth 90mA IDD |
| 113 | + RATE_800_HZ: int = const(0b1101) # 400Hz Bandwidth 140mA IDD |
| 114 | + RATE_400_HZ: int = const(0b1100) # 200Hz Bandwidth 140mA IDD |
| 115 | + RATE_200_HZ: int = const(0b1011) # 100Hz Bandwidth 140mA IDD |
| 116 | + RATE_100_HZ: int = const(0b1010) # 50Hz Bandwidth 140mA IDD |
| 117 | + RATE_50_HZ: int = const(0b1001) # 25Hz Bandwidth 90mA IDD |
119 | 118 | RATE_25_HZ: int = const(0b1000) # 12.5Hz Bandwidth 60mA IDD
|
120 | 119 | RATE_12_5_HZ: int = const(0b0111) # 6.25Hz Bandwidth 50mA IDD
|
121 | 120 | RATE_6_25HZ: int = const(0b0110) # 3.13Hz Bandwidth 45mA IDD
|
@@ -195,7 +194,22 @@ def acceleration(self) -> Tuple[int, int, int]:
|
195 | 194 | x = x * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
|
196 | 195 | y = y * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
|
197 | 196 | z = z * _ADXL345_MG2G_MULTIPLIER * _STANDARD_GRAVITY
|
198 |
| - return (x, y, z) |
| 197 | + return x, y, z |
| 198 | + |
| 199 | + @property |
| 200 | + def raw_x(self) -> int: |
| 201 | + """The raw x value.""" |
| 202 | + return unpack("<h", self._read_register(_REG_DATAX0, 2))[0] |
| 203 | + |
| 204 | + @property |
| 205 | + def raw_y(self) -> int: |
| 206 | + """The raw y value.""" |
| 207 | + return unpack("<h", self._read_register(_REG_DATAY0, 2))[0] |
| 208 | + |
| 209 | + @property |
| 210 | + def raw_z(self) -> int: |
| 211 | + """The raw z value.""" |
| 212 | + return unpack("<h", self._read_register(_REG_DATAZ0, 2))[0] |
199 | 213 |
|
200 | 214 | @property
|
201 | 215 | def events(self) -> Dict[str, bool]:
|
@@ -312,7 +326,7 @@ def enable_freefall_detection(self, *, threshold: int = 10, time: int = 25) -> N
|
312 | 326 | self._enabled_interrupts["freefall"] = True
|
313 | 327 |
|
314 | 328 | def disable_freefall_detection(self) -> None:
|
315 |
| - "Disable freefall detection" |
| 329 | + """Disable freefall detection""" |
316 | 330 | active_interrupts = self._read_register_unpacked(_REG_INT_ENABLE)
|
317 | 331 | active_interrupts &= ~_INT_FREE_FALL
|
318 | 332 | self._write_register_byte(_REG_INT_ENABLE, active_interrupts)
|
@@ -379,7 +393,7 @@ def enable_tap_detection(
|
379 | 393 | )
|
380 | 394 |
|
381 | 395 | def disable_tap_detection(self) -> None:
|
382 |
| - "Disable tap detection" |
| 396 | + """Disable tap detection""" |
383 | 397 | active_interrupts = self._read_register_unpacked(_REG_INT_ENABLE)
|
384 | 398 | active_interrupts &= ~_INT_SINGLE_TAP
|
385 | 399 | active_interrupts &= ~_INT_DOUBLE_TAP
|
@@ -417,6 +431,23 @@ def range(self, val: int) -> None:
|
417 | 431 | # write the updated values
|
418 | 432 | self._write_register_byte(_REG_DATA_FORMAT, format_register)
|
419 | 433 |
|
| 434 | + @property |
| 435 | + def offset(self) -> Tuple[int, int, int]: |
| 436 | + """ |
| 437 | + The x, y, z offsets as a tuple of raw count values. |
| 438 | +
|
| 439 | + See offset_calibration example for usage. |
| 440 | + """ |
| 441 | + x_offset, y_offset, z_offset = unpack("<bbb", self._read_register(_REG_OFSX, 3)) |
| 442 | + return x_offset, y_offset, z_offset |
| 443 | + |
| 444 | + @offset.setter |
| 445 | + def offset(self, val: Tuple[int, int, int]) -> None: |
| 446 | + x_offset, y_offset, z_offset = val |
| 447 | + self._write_register_byte(_REG_OFSX, x_offset) |
| 448 | + self._write_register_byte(_REG_OFSY, y_offset) |
| 449 | + self._write_register_byte(_REG_OFSZ, z_offset) |
| 450 | + |
420 | 451 | def _read_clear_interrupt_source(self) -> int:
|
421 | 452 | return self._read_register_unpacked(_REG_INT_SOURCE)
|
422 | 453 |
|
|
0 commit comments