Skip to content

Commit 02d72c5

Browse files
authored
Merge pull request #35 from tammymakesthings/issue32-add-type-annotations
Issue32 add type annotations
2 parents 2e7705b + dfc81f0 commit 02d72c5

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed

adafruit_amg88xx.py

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,69 @@
2323
**Notes:**
2424
"""
2525

26-
__version__ = "0.0.0-auto.0"
27-
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_AMG88xx"
26+
__version__: str = "0.0.0-auto.0"
27+
__repo__: str = "https://github.com/adafruit/Adafruit_CircuitPython_AMG88xx"
2828

2929
from adafruit_bus_device.i2c_device import I2CDevice
3030
from adafruit_register import i2c_bit, i2c_bits
31+
from adafruit_register.i2c_bits import (
32+
RWBits,
33+
) # pylint: disable=unused-import,line-too-long
34+
from adafruit_register.i2c_bit import (
35+
RWBit,
36+
) # pylint: disable=unused-import,line-too-long
3137
from micropython import const
3238

39+
try:
40+
from typing import List
41+
42+
# These are only needed for typing
43+
import busio # pylint: disable=unused-import
44+
except ImportError:
45+
pass
3346

3447
# Registers are defined below in the class. These are possible register values.
3548

3649
# Operating Modes
37-
_NORMAL_MODE = const(0x00)
38-
_SLEEP_MODE = const(0x10)
39-
_STAND_BY_60 = const(0x20)
40-
_STAND_BY_10 = const(0x21)
50+
_NORMAL_MODE: int = const(0x00)
51+
_SLEEP_MODE: int = const(0x10)
52+
_STAND_BY_60: int = const(0x20)
53+
_STAND_BY_10: int = const(0x21)
4154

4255
# sw resets
43-
_FLAG_RESET = const(0x30)
44-
_INITIAL_RESET = const(0x3F)
56+
_FLAG_RESET: int = const(0x30)
57+
_INITIAL_RESET: int = const(0x3F)
4558

4659
# frame rates
47-
_FPS_10 = const(0x00)
48-
_FPS_1 = const(0x01)
60+
_FPS_10: int = const(0x00)
61+
_FPS_1: int = const(0x01)
4962

5063
# int enables
51-
_INT_DISABLED = const(0x00)
52-
_INT_ENABLED = const(0x01)
64+
_INT_DISABLED: int = const(0x00)
65+
_INT_ENABLED: int = const(0x01)
5366

5467
# int modes
55-
_DIFFERENCE = const(0x00)
56-
_ABSOLUTE_VALUE = const(0x01)
68+
_DIFFERENCE: int = const(0x00)
69+
_ABSOLUTE_VALUE: int = const(0x01)
5770

58-
_INT_OFFSET = const(0x010)
59-
_PIXEL_OFFSET = const(0x80)
71+
_INT_OFFSET: int = const(0x010)
72+
_PIXEL_OFFSET: int = const(0x80)
6073

61-
_PIXEL_ARRAY_WIDTH = const(8)
62-
_PIXEL_ARRAY_HEIGHT = const(8)
63-
_PIXEL_TEMP_CONVERSION = 0.25
64-
_THERMISTOR_CONVERSION = 0.0625
74+
_PIXEL_ARRAY_WIDTH: int = const(8)
75+
_PIXEL_ARRAY_HEIGHT: int = const(8)
76+
_PIXEL_TEMP_CONVERSION: int = 0.25
77+
_THERMISTOR_CONVERSION: int = 0.0625
6578

6679

67-
def _signed_12bit_to_float(val):
80+
def _signed_12bit_to_float(val: int) -> float:
6881
# take first 11 bits as absolute val
6982
abs_val = val & 0x7FF
7083
if val & 0x800:
7184
return 0 - float(abs_val)
7285
return float(abs_val)
7386

7487

75-
def _twos_comp_to_float(val):
88+
def _twos_comp_to_float(val: int) -> float:
7689
val &= 0xFFF
7790
if val & 0x800:
7891
val -= 0x1000
@@ -83,34 +96,34 @@ class AMG88XX:
8396
"""Driver for the AMG88xx GRID-Eye IR 8x8 thermal camera."""
8497

8598
# Set up the registers
86-
_pctl = i2c_bits.RWBits(8, 0x00, 0)
87-
_rst = i2c_bits.RWBits(8, 0x01, 0)
88-
_fps = i2c_bit.RWBit(0x02, 0)
89-
_inten = i2c_bit.RWBit(0x03, 0)
90-
_intmod = i2c_bit.RWBit(0x03, 1)
99+
_pctl: RWBits = i2c_bits.RWBits(8, 0x00, 0)
100+
_rst: RWBits = i2c_bits.RWBits(8, 0x01, 0)
101+
_fps: RWBit = i2c_bit.RWBit(0x02, 0)
102+
_inten: RWBit = i2c_bit.RWBit(0x03, 0)
103+
_intmod: RWBit = i2c_bit.RWBit(0x03, 1)
91104

92-
_intf = i2c_bit.RWBit(0x04, 1)
93-
_ovf_irs = i2c_bit.RWBit(0x04, 2)
94-
_ovf_ths = i2c_bit.RWBit(0x04, 3)
105+
_intf: RWBit = i2c_bit.RWBit(0x04, 1)
106+
_ovf_irs: RWBit = i2c_bit.RWBit(0x04, 2)
107+
_ovf_ths: RWBit = i2c_bit.RWBit(0x04, 3)
95108

96-
_intclr = i2c_bit.RWBit(0x05, 1)
97-
_ovs_clr = i2c_bit.RWBit(0x05, 2)
98-
_ovt_clr = i2c_bit.RWBit(0x05, 3)
109+
_intclr: RWBit = i2c_bit.RWBit(0x05, 1)
110+
_ovs_clr: RWBit = i2c_bit.RWBit(0x05, 2)
111+
_ovt_clr: RWBit = i2c_bit.RWBit(0x05, 3)
99112

100-
_mamod = i2c_bit.RWBit(0x07, 5)
113+
_mamod: RWBit = i2c_bit.RWBit(0x07, 5)
101114

102-
_inthl = i2c_bits.RWBits(8, 0x08, 0)
103-
_inthh = i2c_bits.RWBits(4, 0x09, 0)
104-
_intll = i2c_bits.RWBits(8, 0x0A, 0)
105-
_intlh = i2c_bits.RWBits(4, 0x0B, 0)
106-
_ihysl = i2c_bits.RWBits(8, 0x0C, 0)
107-
_ihysh = i2c_bits.RWBits(4, 0x0D, 0)
115+
_inthl: RWBits = i2c_bits.RWBits(8, 0x08, 0)
116+
_inthh: RWBits = i2c_bits.RWBits(4, 0x09, 0)
117+
_intll: RWBits = i2c_bits.RWBits(8, 0x0A, 0)
118+
_intlh: RWBits = i2c_bits.RWBits(4, 0x0B, 0)
119+
_ihysl: RWBits = i2c_bits.RWBits(8, 0x0C, 0)
120+
_ihysh: RWBits = i2c_bits.RWBits(4, 0x0D, 0)
108121

109-
_tthl = i2c_bits.RWBits(8, 0x0E, 0)
122+
_tthl: RWBits = i2c_bits.RWBits(8, 0x0E, 0)
110123

111-
_tthh = i2c_bits.RWBits(4, 0x0F, 0)
124+
_tthh: RWBits = i2c_bits.RWBits(4, 0x0F, 0)
112125

113-
def __init__(self, i2c, addr=0x69):
126+
def __init__(self, i2c: busio.I2C, addr: int = 0x69) -> None:
114127
self.i2c_device = I2CDevice(i2c, addr)
115128

116129
# enter normal mode
@@ -126,13 +139,13 @@ def __init__(self, i2c, addr=0x69):
126139
self._fps = _FPS_10
127140

128141
@property
129-
def temperature(self):
142+
def temperature(self) -> float:
130143
"""Temperature of the sensor in Celsius"""
131144
raw = (self._tthh << 8) | self._tthl
132145
return _signed_12bit_to_float(raw) * _THERMISTOR_CONVERSION
133146

134147
@property
135-
def pixels(self):
148+
def pixels(self) -> List[List[float]]:
136149
"""Temperature of each pixel across the sensor in Celsius.
137150
138151
Temperatures are stored in a two dimensional list where the first index is the row and

0 commit comments

Comments
 (0)