|
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,80 +139,95 @@ 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 | +
|
154 | 161 | .. code-block:: python
|
155 |
| - bd3491fs.active_input = adafruit_bd3491fs.Input.A |
| 162 | +
|
| 163 | + bd3491fs.active_input = adafruit_bd3491fs.Input.A |
| 164 | +
|
156 | 165 | """
|
157 | 166 | return self._current_active_input
|
158 | 167 |
|
159 | 168 | @active_input.setter
|
160 |
| - def active_input(self, value): |
| 169 | + def active_input(self, value: int) -> None: |
161 | 170 | self._input_selector = value
|
162 | 171 | self._current_active_input = value
|
163 | 172 |
|
164 | 173 | @property
|
165 |
| - def input_gain(self): |
166 |
| - """The gain applied to all inputs equally" |
| 174 | + def input_gain(self) -> int: |
| 175 | + """The gain applied to all inputs equally |
| 176 | +
|
167 | 177 | This example sets the input gain to 10dB.
|
| 178 | +
|
168 | 179 | .. code-block:: python
|
169 |
| - bd3491fs.input_gain = adafruit_bd3491fs.Level.10_DB"" |
| 180 | +
|
| 181 | + bd3491fs.input_gain = adafruit_bd3491fs.Level.10_DB |
| 182 | +
|
170 | 183 | """
|
171 | 184 | return self._current_input_gain
|
172 | 185 |
|
173 | 186 | @input_gain.setter
|
174 |
| - def input_gain(self, value): |
| 187 | + def input_gain(self, value: int) -> None: |
175 | 188 | allowed_gains = [0, 1, 2, 3, 4, 6, 8, 10]
|
176 | 189 | if not value in allowed_gains:
|
177 | 190 | raise ValueError("input gain must be one of 0, 2, 4, 6, 8, 12, 16, 20 dB")
|
178 | 191 | self._input_gain = value
|
179 | 192 | self._current_input_gain = value
|
180 | 193 |
|
181 | 194 | @property
|
182 |
| - def channel_1_attenuation(self): |
| 195 | + def channel_1_attenuation(self) -> int: |
183 | 196 | """The attenuation applied to channel 1 of the currently selected input pair in -dB.
|
184 |
| - Maximum is -87dB. To mute set to 255 |
| 197 | + Maximum is -87dB. To mute set to 255. |
| 198 | +
|
185 | 199 | This example sets the attenuation for input channel 1 to -10dB.
|
| 200 | +
|
186 | 201 | .. code-block:: python
|
187 |
| - bd3491fs.channel_1_attenuation = 10"" |
| 202 | +
|
| 203 | + bd3491fs.channel_1_attenuation = 10 |
| 204 | +
|
188 | 205 | """
|
189 | 206 | return self._current_ch1_attenuation
|
190 | 207 |
|
191 | 208 | @channel_1_attenuation.setter
|
192 |
| - def channel_1_attenuation(self, value): |
| 209 | + def channel_1_attenuation(self, value: int) -> None: |
193 | 210 | if (value < 0) or ((value > 87) and (value != 255)):
|
194 | 211 | raise ValueError("channel 1 attenuation must be from 0-87db")
|
195 | 212 | self._ch1_attenuation = value
|
196 | 213 | self._current_ch1_attenuation = value
|
197 | 214 |
|
198 | 215 | @property
|
199 |
| - def channel_2_attenuation(self): |
| 216 | + def channel_2_attenuation(self) -> int: |
200 | 217 | """The attenuation applied to channel 2 of the currently selected input pair in -dB.
|
201 |
| - Maximum is -87dB. To mute set to 255 |
| 218 | + Maximum is -87dB. To mute set to 255. |
| 219 | +
|
202 | 220 | This example sets the attenuation for input channel 2 to -10dB.
|
| 221 | +
|
203 | 222 | .. code-block:: python
|
204 |
| - bd3491fs.channel_2_attenuation = 10"" |
| 223 | +
|
| 224 | + bd3491fs.channel_2_attenuation = 10 |
| 225 | +
|
205 | 226 | """
|
206 | 227 | return self._current_ch2_attenuation
|
207 | 228 |
|
208 | 229 | @channel_2_attenuation.setter
|
209 |
| - def channel_2_attenuation(self, value): |
| 230 | + def channel_2_attenuation(self, value: int) -> None: |
210 | 231 | if (value < 0) or ((value > 87) and (value != 255)):
|
211 | 232 | raise ValueError("channel 2 attenuation must be from 0-87db")
|
212 | 233 | self._ch2_attenuation = value
|
|
0 commit comments