33
33
from adafruit_register .i2c_bit import RWBit
34
34
from adafruit_register .i2c_bits import RWBits
35
35
36
+ try :
37
+ from typing import Tuple
38
+ from busio import I2C
39
+ except ImportError :
40
+ pass
41
+
36
42
__version__ = "0.0.0+auto.0"
37
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LTR329_LTR303.git"
38
44
@@ -83,43 +89,43 @@ class LTR329:
83
89
_als_data_gain_range = RWBits (3 , _LTR329_REG_STATUS , 4 )
84
90
new_als_data_available = RWBit (_LTR329_REG_STATUS , 2 )
85
91
86
- def __init__ (self , i2c , address = _LTR329_I2CADDR_DEFAULT ):
92
+ def __init__ (self , i2c : I2C , address : int = _LTR329_I2CADDR_DEFAULT ) -> None :
87
93
self .i2c_device = i2c_device .I2CDevice (i2c , address )
88
94
if self .part_id != 0xA0 or self .manufacturer_id != 0x05 :
89
95
raise RuntimeError ("Unable to find LTR-329, check your wiring" )
90
96
self .reset ()
91
97
self .active_mode = True
92
98
93
- def reset (self ):
99
+ def reset (self ) -> None :
94
100
"""Reset the sensor to the default state set by the library"""
95
101
self ._reset = True
96
102
time .sleep (0.010 )
97
103
98
104
@property
99
- def als_gain (self ):
105
+ def als_gain (self ) -> int :
100
106
"""ALS gain, can be: 1, 2, 4, 8, 48 or 96 times"""
101
107
return _als_gains [self ._als_gain ]
102
108
103
109
@als_gain .setter
104
- def als_gain (self , gain ) :
110
+ def als_gain (self , gain : int ) -> None :
105
111
if not gain in _als_gains :
106
112
raise RuntimeError ("Invalid gain: must be 1, 2, 4, 8, 48 or 96 x" )
107
113
self ._als_gain = _als_gains .index (gain )
108
114
109
115
@property
110
- def als_data_gain (self ):
116
+ def als_data_gain (self ) -> int :
111
117
"""ALS gain for data that is being read now,
112
118
can be: 1, 2, 4, 8, 48 or 96 times"""
113
119
return _als_gains [self ._als_data_gain_range ]
114
120
115
121
@property
116
- def integration_time (self ):
122
+ def integration_time (self ) -> int :
117
123
"""ALS integration times, can be: 50, 100, 150, 200, 250,
118
124
300, 350, or 400 millisec"""
119
125
return _integration_times [self ._integration_time ]
120
126
121
127
@integration_time .setter
122
- def integration_time (self , int_time ) :
128
+ def integration_time (self , int_time : int ) -> None :
123
129
if not int_time in _integration_times :
124
130
raise RuntimeError (
125
131
"Invalid integration time: must be 50, 100, 150, "
@@ -128,49 +134,49 @@ def integration_time(self, int_time):
128
134
self ._integration_time = _integration_times .index (int_time )
129
135
130
136
@property
131
- def measurement_rate (self ):
137
+ def measurement_rate (self ) -> int :
132
138
"""ALS measurement rate, must be = or > than ALS integration rate!
133
139
Can be: 50, 100, 200, 500, 1000, or 2000 millisec"""
134
140
return _measurement_rates [self ._measurement_rate ]
135
141
136
142
@measurement_rate .setter
137
- def measurement_rate (self , rate ) :
143
+ def measurement_rate (self , rate : int ) -> None :
138
144
if not rate in _measurement_rates :
139
145
raise RuntimeError (
140
146
"Invalid measurement rate: must be 50, 100, 200, 500, 1000, or 2000 millisec"
141
147
)
142
148
self ._measurement_rate = _measurement_rates .index (rate )
143
149
144
- def throw_out_reading (self ):
150
+ def throw_out_reading (self ) -> None :
145
151
"""Throw out a reading (typically done to clear it out)"""
146
152
_ = self ._light_data
147
153
148
154
@property
149
- def light_channels (self ):
155
+ def light_channels (self ) -> Tuple [ int , int ] :
150
156
"""A data pair of both visible+IR light, and the IR-only light"""
151
157
temp = self ._light_data
152
158
if self .als_data_invalid :
153
159
raise ValueError ("Data invalid / over-run!" )
154
160
return (temp >> 16 , temp & 0xFFFF )
155
161
156
162
@property
157
- def visible_plus_ir_light (self ):
163
+ def visible_plus_ir_light (self ) -> int :
158
164
"""The visible + IR light data"""
159
165
if self .als_data_invalid :
160
166
_ = self ._light_data # read data to clear it out
161
167
raise ValueError ("Data invalid / over-run!" )
162
168
return self ._light_data >> 16
163
169
164
170
@property
165
- def ir_light (self ):
171
+ def ir_light (self ) -> int :
166
172
"""The IR light data"""
167
173
if self .als_data_invalid :
168
174
_ = self ._light_data # read data to clear it out
169
175
raise ValueError ("Data invalid / over-run!" )
170
176
return self ._light_data & 0xFFFF
171
177
172
178
@property
173
- def visible_light (self ):
179
+ def visible_light (self ) -> int :
174
180
"""The visible light data"""
175
181
temp = self ._light_data
176
182
if self .als_data_invalid :
@@ -196,26 +202,26 @@ class LTR303(LTR329):
196
202
_int_persistance = RWBits (4 , _LTR303_REG_INTPERSIST , 0 )
197
203
198
204
@property
199
- def int_persistance (self ):
205
+ def int_persistance (self ) -> int :
200
206
"""How long the data needs to be high/low to generate an interrupt.
201
207
Setting of 1 means 'every measurement', 2 means "two in a row", etc
202
208
up to 16
203
209
"""
204
210
return self ._int_persistance + 1
205
211
206
212
@int_persistance .setter
207
- def int_persistance (self , counts ) :
213
+ def int_persistance (self , counts : int ) -> None :
208
214
if not 1 <= counts <= 16 :
209
215
raise ValueError ("Persistance counts must be 1-16" )
210
216
self ._int_persistance = counts - 1
211
217
212
218
@property
213
- def enable_int (self ):
219
+ def enable_int (self ) -> bool :
214
220
"""Whether the interupt is enabled"""
215
221
return self ._enable_int
216
222
217
223
@enable_int .setter
218
- def enable_int (self , enable ) :
224
+ def enable_int (self , enable : bool ) -> None :
219
225
# we must be in non-active mode to change this register!
220
226
curr_mode = self .active_mode
221
227
self .active_mode = False
@@ -225,12 +231,12 @@ def enable_int(self, enable):
225
231
self .active_mode = curr_mode
226
232
227
233
@property
228
- def int_polarity (self ):
234
+ def int_polarity (self ) -> bool :
229
235
"""The polarity of the interupt (whether high or low is "active")"""
230
236
return self ._int_polarity
231
237
232
238
@int_polarity .setter
233
- def int_polarity (self , pol ) :
239
+ def int_polarity (self , pol : bool ) -> None :
234
240
# we must be in non-active mode to change this register!
235
241
curr_mode = self .active_mode
236
242
self .active_mode = False
0 commit comments