Skip to content

Commit 76ffcd0

Browse files
authored
Merge pull request #26 from tcfranks/main
Add missing type annotations
2 parents 5bb22ed + 88aa049 commit 76ffcd0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

adafruit_fxas21002c.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
import struct
3232
import time
3333

34+
try:
35+
from typing import List, Tuple
36+
from busio import I2C
37+
except ImportError:
38+
pass
39+
3440
__version__ = "0.0.0+auto.0"
3541
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C.git"
3642

@@ -105,7 +111,12 @@ class FXAS21002C:
105111
# thread safe!
106112
_BUFFER = bytearray(7)
107113

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:
109120
if gyro_range not in (
110121
GYRO_RANGE_250DPS,
111122
GYRO_RANGE_500DPS,
@@ -137,21 +148,21 @@ def __init__(self, i2c, address=_FXAS21002C_ADDRESS, gyro_range=GYRO_RANGE_250DP
137148
self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x0E) # Active
138149
time.sleep(0.1) # 60 ms + 1/ODR
139150

140-
def _read_u8(self, address):
151+
def _read_u8(self, address: int) -> int:
141152
# Read an 8-bit unsigned value from the specified 8-bit address.
142153
with self._device as i2c:
143154
self._BUFFER[0] = address & 0xFF
144155
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
145156
return self._BUFFER[0]
146157

147-
def _write_u8(self, address, val):
158+
def _write_u8(self, address: int, val: int) -> None:
148159
# Write an 8-bit unsigned value to the specified 8-bit address.
149160
with self._device as i2c:
150161
self._BUFFER[0] = address & 0xFF
151162
self._BUFFER[1] = val & 0xFF
152163
i2c.write(self._BUFFER, end=2)
153164

154-
def read_raw(self):
165+
def read_raw(self) -> Tuple[int, int, int]:
155166
"""Read the raw gyroscope readings. Returns a 3-tuple of X, Y, Z axis
156167
16-bit signed values. If you want the gyroscope values in friendly
157168
units consider using the gyroscope property!
@@ -170,7 +181,7 @@ def read_raw(self):
170181
# types. Perhaps it doesn't understand map returns an iterable value.
171182
# Disable the warning.
172183
@property
173-
def gyroscope(self):
184+
def gyroscope(self) -> List[float]:
174185
"""Read the gyroscope value and return its X, Y, Z axis values as a
175186
3-tuple in radians/second.
176187
"""

0 commit comments

Comments
 (0)