35
35
import adafruit_bus_device .i2c_device as i2cdevice
36
36
from adafruit_register .i2c_struct import UnaryStruct
37
37
38
+ try :
39
+ import typing # pylint: disable=unused-import
40
+ from busio import I2C
41
+ except ImportError :
42
+ pass
43
+
38
44
_INPUT_SELECTOR = const (0x04 )
39
45
_INPUT_GAIN = const (0x06 )
40
46
_VOLUME_GAIN_CH1 = const (0x21 )
@@ -133,21 +139,21 @@ class BD3491FS: # pylint: disable=too-many-instance-attributes
133
139
_ch2_attenuation = UnaryStruct (_VOLUME_GAIN_CH2 , "<B" )
134
140
_system_reset = UnaryStruct (_SYSTEM_RESET , "<B" )
135
141
136
- def __init__ (self , i2c_bus ) :
142
+ def __init__ (self , i2c_bus : I2C ) -> None :
137
143
self .i2c_device = i2cdevice .I2CDevice (i2c_bus , 0x41 )
138
144
self ._current_active_input = 7 # mute
139
145
self ._current_input_gain = 0 # 0dB
140
146
self ._current_ch1_attenuation = 255 # muted
141
147
self ._current_ch2_attenuation = 255 # muted
142
148
self .reset ()
143
149
144
- def reset (self ):
150
+ def reset (self ) -> None :
145
151
"""Reset the sensor, muting the input, reducting input gain to 0dB, and the output channnel
146
152
attenuation to maximum"""
147
153
self ._reset = 0x81
148
154
149
155
@property
150
- def active_input (self ):
156
+ def active_input (self ) -> int :
151
157
"""The currently selected input. Must be an ``Input``
152
158
153
159
This example sets A1 and A2 to the active input pair.
@@ -160,12 +166,12 @@ def active_input(self):
160
166
return self ._current_active_input
161
167
162
168
@active_input .setter
163
- def active_input (self , value ) :
169
+ def active_input (self , value : int ) -> None :
164
170
self ._input_selector = value
165
171
self ._current_active_input = value
166
172
167
173
@property
168
- def input_gain (self ):
174
+ def input_gain (self ) -> int :
169
175
"""The gain applied to all inputs equally
170
176
171
177
This example sets the input gain to 10dB.
@@ -178,15 +184,15 @@ def input_gain(self):
178
184
return self ._current_input_gain
179
185
180
186
@input_gain .setter
181
- def input_gain (self , value ) :
187
+ def input_gain (self , value : int ) -> None :
182
188
allowed_gains = [0 , 1 , 2 , 3 , 4 , 6 , 8 , 10 ]
183
189
if not value in allowed_gains :
184
190
raise ValueError ("input gain must be one of 0, 2, 4, 6, 8, 12, 16, 20 dB" )
185
191
self ._input_gain = value
186
192
self ._current_input_gain = value
187
193
188
194
@property
189
- def channel_1_attenuation (self ):
195
+ def channel_1_attenuation (self ) -> int :
190
196
"""The attenuation applied to channel 1 of the currently selected input pair in -dB.
191
197
Maximum is -87dB. To mute set to 255.
192
198
@@ -200,14 +206,14 @@ def channel_1_attenuation(self):
200
206
return self ._current_ch1_attenuation
201
207
202
208
@channel_1_attenuation .setter
203
- def channel_1_attenuation (self , value ) :
209
+ def channel_1_attenuation (self , value : int ) -> None :
204
210
if (value < 0 ) or ((value > 87 ) and (value != 255 )):
205
211
raise ValueError ("channel 1 attenuation must be from 0-87db" )
206
212
self ._ch1_attenuation = value
207
213
self ._current_ch1_attenuation = value
208
214
209
215
@property
210
- def channel_2_attenuation (self ):
216
+ def channel_2_attenuation (self ) -> int :
211
217
"""The attenuation applied to channel 2 of the currently selected input pair in -dB.
212
218
Maximum is -87dB. To mute set to 255.
213
219
@@ -221,7 +227,7 @@ def channel_2_attenuation(self):
221
227
return self ._current_ch2_attenuation
222
228
223
229
@channel_2_attenuation .setter
224
- def channel_2_attenuation (self , value ) :
230
+ def channel_2_attenuation (self , value : int ) -> None :
225
231
if (value < 0 ) or ((value > 87 ) and (value != 255 )):
226
232
raise ValueError ("channel 2 attenuation must be from 0-87db" )
227
233
self ._ch2_attenuation = value
0 commit comments