Skip to content

Commit 8b0bc55

Browse files
authored
Merge pull request #21 from FoamyGuy/type_annotations
type annotations
2 parents 1867ca8 + a060906 commit 8b0bc55

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

adafruit_msa3xx.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
from adafruit_register.i2c_bits import RWBits
4141
import adafruit_bus_device.i2c_device as i2cdevice
4242

43+
44+
try:
45+
from typing import Tuple
46+
from busio import I2C
47+
except ImportError:
48+
pass
49+
4350
_MSA301_I2CADDR_DEFAULT = const(0x26)
4451
_MSA311_I2CADDR_DEFAULT = const(0x62)
4552

@@ -244,7 +251,7 @@ def __init__(self):
244251
self._tap_count = 0
245252

246253
@property
247-
def acceleration(self):
254+
def acceleration(self) -> Tuple[float, float, float]:
248255
"""The x, y, z acceleration values returned in a
249256
3-tuple and are in :math:`m / s ^ 2`"""
250257
# read the 6 bytes of acceleration data
@@ -268,12 +275,12 @@ def acceleration(self):
268275
def enable_tap_detection(
269276
self,
270277
*,
271-
tap_count=1,
272-
threshold=25,
273-
long_initial_window=True,
274-
long_quiet_window=True,
275-
double_tap_window=TapDuration.DURATION_250_MS
276-
):
278+
tap_count: int = 1,
279+
threshold: int = 25,
280+
long_initial_window: bool = True,
281+
long_quiet_window: bool = True,
282+
double_tap_window: int = TapDuration.DURATION_250_MS
283+
) -> None:
277284
"""
278285
Enables tap detection with configurable parameters.
279286
@@ -321,7 +328,7 @@ def enable_tap_detection(
321328
raise ValueError("tap must be 1 for single tap, or 2 for double tap")
322329

323330
@property
324-
def tapped(self):
331+
def tapped(self) -> bool:
325332
"""`True` if a single or double tap was detected, depending on the value of the\
326333
``tap_count`` argument passed to ``enable_tap_detection``"""
327334
if self._tap_count == 0:
@@ -346,7 +353,7 @@ class MSA301(MSA3XX):
346353
:param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to.
347354
"""
348355

349-
def __init__(self, i2c_bus):
356+
def __init__(self, i2c_bus: I2C):
350357
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, _MSA301_I2CADDR_DEFAULT)
351358

352359
if self._part_id != 0x13:
@@ -361,7 +368,7 @@ class MSA311(MSA3XX):
361368
:param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to.
362369
"""
363370

364-
def __init__(self, i2c_bus):
371+
def __init__(self, i2c_bus: I2C):
365372
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, _MSA311_I2CADDR_DEFAULT)
366373

367374
if self._part_id != 0x13:

0 commit comments

Comments
 (0)