23
23
**Notes:**
24
24
"""
25
25
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"
28
28
29
29
from adafruit_bus_device .i2c_device import I2CDevice
30
30
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
31
37
from micropython import const
32
38
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
33
46
34
47
# Registers are defined below in the class. These are possible register values.
35
48
36
49
# 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 )
41
54
42
55
# sw resets
43
- _FLAG_RESET = const (0x30 )
44
- _INITIAL_RESET = const (0x3F )
56
+ _FLAG_RESET : int = const (0x30 )
57
+ _INITIAL_RESET : int = const (0x3F )
45
58
46
59
# frame rates
47
- _FPS_10 = const (0x00 )
48
- _FPS_1 = const (0x01 )
60
+ _FPS_10 : int = const (0x00 )
61
+ _FPS_1 : int = const (0x01 )
49
62
50
63
# int enables
51
- _INT_DISABLED = const (0x00 )
52
- _INT_ENABLED = const (0x01 )
64
+ _INT_DISABLED : int = const (0x00 )
65
+ _INT_ENABLED : int = const (0x01 )
53
66
54
67
# int modes
55
- _DIFFERENCE = const (0x00 )
56
- _ABSOLUTE_VALUE = const (0x01 )
68
+ _DIFFERENCE : int = const (0x00 )
69
+ _ABSOLUTE_VALUE : int = const (0x01 )
57
70
58
- _INT_OFFSET = const (0x010 )
59
- _PIXEL_OFFSET = const (0x80 )
71
+ _INT_OFFSET : int = const (0x010 )
72
+ _PIXEL_OFFSET : int = const (0x80 )
60
73
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
65
78
66
79
67
- def _signed_12bit_to_float (val ) :
80
+ def _signed_12bit_to_float (val : int ) -> float :
68
81
# take first 11 bits as absolute val
69
82
abs_val = val & 0x7FF
70
83
if val & 0x800 :
71
84
return 0 - float (abs_val )
72
85
return float (abs_val )
73
86
74
87
75
- def _twos_comp_to_float (val ) :
88
+ def _twos_comp_to_float (val : int ) -> float :
76
89
val &= 0xFFF
77
90
if val & 0x800 :
78
91
val -= 0x1000
@@ -83,34 +96,34 @@ class AMG88XX:
83
96
"""Driver for the AMG88xx GRID-Eye IR 8x8 thermal camera."""
84
97
85
98
# 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 )
91
104
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 )
95
108
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 )
99
112
100
- _mamod = i2c_bit .RWBit (0x07 , 5 )
113
+ _mamod : RWBit = i2c_bit .RWBit (0x07 , 5 )
101
114
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 )
108
121
109
- _tthl = i2c_bits .RWBits (8 , 0x0E , 0 )
122
+ _tthl : RWBits = i2c_bits .RWBits (8 , 0x0E , 0 )
110
123
111
- _tthh = i2c_bits .RWBits (4 , 0x0F , 0 )
124
+ _tthh : RWBits = i2c_bits .RWBits (4 , 0x0F , 0 )
112
125
113
- def __init__ (self , i2c , addr = 0x69 ):
126
+ def __init__ (self , i2c : busio . I2C , addr : int = 0x69 ) -> None :
114
127
self .i2c_device = I2CDevice (i2c , addr )
115
128
116
129
# enter normal mode
@@ -126,13 +139,13 @@ def __init__(self, i2c, addr=0x69):
126
139
self ._fps = _FPS_10
127
140
128
141
@property
129
- def temperature (self ):
142
+ def temperature (self ) -> float :
130
143
"""Temperature of the sensor in Celsius"""
131
144
raw = (self ._tthh << 8 ) | self ._tthl
132
145
return _signed_12bit_to_float (raw ) * _THERMISTOR_CONVERSION
133
146
134
147
@property
135
- def pixels (self ):
148
+ def pixels (self ) -> List [ List [ float ]] :
136
149
"""Temperature of each pixel across the sensor in Celsius.
137
150
138
151
Temperatures are stored in a two dimensional list where the first index is the row and
0 commit comments