From fef2ed9c1cc5879c366da7febc6d5a9043b38ad1 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Tue, 13 Sep 2022 10:56:51 -0400 Subject: [PATCH 1/2] Add missint type annotations --- adafruit_fxas21002c.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/adafruit_fxas21002c.py b/adafruit_fxas21002c.py index 8177149..fd123fc 100644 --- a/adafruit_fxas21002c.py +++ b/adafruit_fxas21002c.py @@ -31,6 +31,12 @@ import struct import time +try: + from typing import Tuple + from busio import I2C +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C.git" @@ -105,7 +111,12 @@ class FXAS21002C: # thread safe! _BUFFER = bytearray(7) - def __init__(self, i2c, address=_FXAS21002C_ADDRESS, gyro_range=GYRO_RANGE_250DPS): + def __init__( + self, + i2c: I2C, + address: int = _FXAS21002C_ADDRESS, + gyro_range: int = GYRO_RANGE_250DPS, + ) -> None: if gyro_range not in ( GYRO_RANGE_250DPS, GYRO_RANGE_500DPS, @@ -137,21 +148,21 @@ def __init__(self, i2c, address=_FXAS21002C_ADDRESS, gyro_range=GYRO_RANGE_250DP self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x0E) # Active time.sleep(0.1) # 60 ms + 1/ODR - def _read_u8(self, address): + def _read_u8(self, address: int) -> int: # Read an 8-bit unsigned value from the specified 8-bit address. with self._device as i2c: self._BUFFER[0] = address & 0xFF i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1) return self._BUFFER[0] - def _write_u8(self, address, val): + def _write_u8(self, address: int, val: int) -> None: # Write an 8-bit unsigned value to the specified 8-bit address. with self._device as i2c: self._BUFFER[0] = address & 0xFF self._BUFFER[1] = val & 0xFF i2c.write(self._BUFFER, end=2) - def read_raw(self): + def read_raw(self) -> Tuple[int, int, int]: """Read the raw gyroscope readings. Returns a 3-tuple of X, Y, Z axis 16-bit signed values. If you want the gyroscope values in friendly units consider using the gyroscope property! @@ -170,7 +181,7 @@ def read_raw(self): # types. Perhaps it doesn't understand map returns an iterable value. # Disable the warning. @property - def gyroscope(self): + def gyroscope(self) -> Tuple[float, float, float]: """Read the gyroscope value and return its X, Y, Z axis values as a 3-tuple in radians/second. """ From 88aa049a5eae10b44a9e75a4586f240ffb4555f8 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Tue, 13 Sep 2022 13:25:17 -0400 Subject: [PATCH 2/2] Add missint type annotations --- adafruit_fxas21002c.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_fxas21002c.py b/adafruit_fxas21002c.py index fd123fc..c307ee1 100644 --- a/adafruit_fxas21002c.py +++ b/adafruit_fxas21002c.py @@ -32,7 +32,7 @@ import time try: - from typing import Tuple + from typing import List, Tuple from busio import I2C except ImportError: pass @@ -181,7 +181,7 @@ def read_raw(self) -> Tuple[int, int, int]: # types. Perhaps it doesn't understand map returns an iterable value. # Disable the warning. @property - def gyroscope(self) -> Tuple[float, float, float]: + def gyroscope(self) -> List[float]: """Read the gyroscope value and return its X, Y, Z axis values as a 3-tuple in radians/second. """