31
31
import struct
32
32
import time
33
33
34
+ try :
35
+ from typing import List , Tuple
36
+ from busio import I2C
37
+ except ImportError :
38
+ pass
39
+
34
40
__version__ = "0.0.0+auto.0"
35
41
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C.git"
36
42
@@ -105,7 +111,12 @@ class FXAS21002C:
105
111
# thread safe!
106
112
_BUFFER = bytearray (7 )
107
113
108
- def __init__ (self , i2c , address = _FXAS21002C_ADDRESS , gyro_range = GYRO_RANGE_250DPS ):
114
+ def __init__ (
115
+ self ,
116
+ i2c : I2C ,
117
+ address : int = _FXAS21002C_ADDRESS ,
118
+ gyro_range : int = GYRO_RANGE_250DPS ,
119
+ ) -> None :
109
120
if gyro_range not in (
110
121
GYRO_RANGE_250DPS ,
111
122
GYRO_RANGE_500DPS ,
@@ -137,21 +148,21 @@ def __init__(self, i2c, address=_FXAS21002C_ADDRESS, gyro_range=GYRO_RANGE_250DP
137
148
self ._write_u8 (_GYRO_REGISTER_CTRL_REG1 , 0x0E ) # Active
138
149
time .sleep (0.1 ) # 60 ms + 1/ODR
139
150
140
- def _read_u8 (self , address ) :
151
+ def _read_u8 (self , address : int ) -> int :
141
152
# Read an 8-bit unsigned value from the specified 8-bit address.
142
153
with self ._device as i2c :
143
154
self ._BUFFER [0 ] = address & 0xFF
144
155
i2c .write_then_readinto (self ._BUFFER , self ._BUFFER , out_end = 1 , in_end = 1 )
145
156
return self ._BUFFER [0 ]
146
157
147
- def _write_u8 (self , address , val ) :
158
+ def _write_u8 (self , address : int , val : int ) -> None :
148
159
# Write an 8-bit unsigned value to the specified 8-bit address.
149
160
with self ._device as i2c :
150
161
self ._BUFFER [0 ] = address & 0xFF
151
162
self ._BUFFER [1 ] = val & 0xFF
152
163
i2c .write (self ._BUFFER , end = 2 )
153
164
154
- def read_raw (self ):
165
+ def read_raw (self ) -> Tuple [ int , int , int ] :
155
166
"""Read the raw gyroscope readings. Returns a 3-tuple of X, Y, Z axis
156
167
16-bit signed values. If you want the gyroscope values in friendly
157
168
units consider using the gyroscope property!
@@ -170,7 +181,7 @@ def read_raw(self):
170
181
# types. Perhaps it doesn't understand map returns an iterable value.
171
182
# Disable the warning.
172
183
@property
173
- def gyroscope (self ):
184
+ def gyroscope (self ) -> List [ float ] :
174
185
"""Read the gyroscope value and return its X, Y, Z axis values as a
175
186
3-tuple in radians/second.
176
187
"""
0 commit comments