|
28 | 28 |
|
29 | 29 | """
|
30 | 30 |
|
| 31 | +from struct import unpack |
31 | 32 | from micropython import const
|
32 | 33 | import adafruit_adxl34x
|
33 | 34 |
|
| 35 | +try: |
| 36 | + from typing import Tuple, Optional |
| 37 | + |
| 38 | + # This is only needed for typing |
| 39 | + import busio |
| 40 | +except ImportError: |
| 41 | + pass |
| 42 | + |
34 | 43 | __version__ = "0.0.0-auto.0"
|
35 | 44 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADXL37x.git"
|
36 | 45 |
|
37 | 46 | _ADXL375_DEFAULT_ADDRESS = const(0x53)
|
38 | 47 |
|
| 48 | +_ADXL347_MULTIPLIER: float = 0.049 # 49mg per lsb |
| 49 | +_STANDARD_GRAVITY: float = 9.80665 # earth standard gravity |
| 50 | + |
| 51 | +_REG_DATAX0: int = const(0x32) # X-axis data 0 |
| 52 | +_REG_DATAX1: int = const(0x33) # X-axis data 1 |
| 53 | +_REG_DATAY0: int = const(0x34) # Y-axis data 0 |
| 54 | +_REG_DATAY1: int = const(0x35) # Y-axis data 1 |
| 55 | +_REG_DATAZ0: int = const(0x36) # Z-axis data 0 |
| 56 | +_REG_DATAZ1: int = const(0x37) # Z-axis data 1 |
| 57 | + |
39 | 58 |
|
40 | 59 | class DataRate(adafruit_adxl34x.DataRate): # pylint: disable=too-few-public-methods
|
41 | 60 | """Stub class for data rate."""
|
@@ -79,17 +98,26 @@ class ADXL375(adafruit_adxl34x.ADXL345):
|
79 | 98 |
|
80 | 99 | """
|
81 | 100 |
|
82 |
| - def __init__(self, i2c, address=None): |
| 101 | + def __init__(self, i2c: busio.I2C, address: Optional[int] = None): |
83 | 102 | super().__init__(
|
84 | 103 | i2c, address if address is not None else _ADXL375_DEFAULT_ADDRESS
|
85 | 104 | )
|
86 | 105 |
|
87 | 106 | @property
|
88 |
| - def range(self): |
| 107 | + def acceleration(self) -> Tuple[int, int, int]: |
| 108 | + """The x, y, z acceleration values returned in a 3-tuple in :math:`m / s ^ 2`""" |
| 109 | + x, y, z = unpack("<hhh", self._read_register(_REG_DATAX0, 6)) |
| 110 | + x = x * _ADXL347_MULTIPLIER * _STANDARD_GRAVITY |
| 111 | + y = y * _ADXL347_MULTIPLIER * _STANDARD_GRAVITY |
| 112 | + z = z * _ADXL347_MULTIPLIER * _STANDARD_GRAVITY |
| 113 | + return x, y, z |
| 114 | + |
| 115 | + @property |
| 116 | + def range(self) -> int: |
89 | 117 | """Range is fixed. Updating the range is not implemented."""
|
90 |
| - return |
| 118 | + raise NotImplementedError("Range not implemented. ADXL375 is fixed at 200G.") |
91 | 119 |
|
92 | 120 | @range.setter
|
93 |
| - def range(self, val): |
| 121 | + def range(self, val: int) -> None: |
94 | 122 | """Range is fixed. Updating the range is not implemented."""
|
95 | 123 | raise NotImplementedError("Range not implemented. ADXL375 is fixed at 200G.")
|
0 commit comments