39
39
40
40
from adafruit_emc2101 import emc2101_regs
41
41
42
+ try :
43
+ from typing import Tuple
44
+ from busio import I2C
45
+ except ImportError :
46
+ pass
47
+
42
48
__version__ = "0.0.0+auto.0"
43
49
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EMC2101.git"
44
50
@@ -175,7 +181,7 @@ class to add those features, at the cost of increased memory usage.
175
181
"""Set whether spin-up is aborted if measured speed is lower than the limit.
176
182
Ignored unless _tach_mode_enable is 1."""
177
183
178
- def __init__ (self , i2c_bus ) :
184
+ def __init__ (self , i2c_bus : I2C ) -> None :
179
185
# These devices don't ship with any other address.
180
186
self .i2c_device = i2cdevice .I2CDevice (i2c_bus , emc2101_regs .I2C_ADDR )
181
187
part = self ._part_id
@@ -186,27 +192,27 @@ def __init__(self, i2c_bus):
186
192
not part in [emc2101_regs .PART_ID_EMC2101 , emc2101_regs .PART_ID_EMC2101R ]
187
193
or mfg != emc2101_regs .MFG_ID_SMSC
188
194
):
189
- raise RuntimeError ("No EMC2101 (part={}.{})" . format ( part , mfg ) )
195
+ raise RuntimeError (f "No EMC2101 (part={ part } .{ mfg } )" )
190
196
191
197
self ._full_speed_lsb = None # See _calculate_full_speed().
192
198
self .initialize ()
193
199
194
- def initialize (self ):
200
+ def initialize (self ) -> None :
195
201
"""Reset the controller to an initial default configuration"""
196
202
self ._tach_mode_enable = True
197
203
self ._enabled_forced_temp = False
198
204
self ._spin_tach_limit = False
199
205
self ._calculate_full_speed ()
200
206
201
207
@property
202
- def part_info (self ):
208
+ def part_info (self ) -> Tuple [ int , int , int ] :
203
209
"""The part information: manufacturer, part id and revision.
204
210
Normally returns (0x5d, 0x16, 0x1).
205
211
"""
206
212
return (self ._mfg_id , self ._part_id , self ._part_rev )
207
213
208
214
@property
209
- def devconfig (self ):
215
+ def devconfig (self ) -> int :
210
216
"""Read the main device config register.
211
217
See the CONFIG_* bit definitions in the emc2101_regs module, or refer
212
218
to the datasheet for more detail. Note: this is not the Fan Config
@@ -215,15 +221,15 @@ def devconfig(self):
215
221
return self ._config
216
222
217
223
@property
218
- def devstatus (self ):
224
+ def devstatus (self ) -> int :
219
225
"""Read device status (alerts) register. See the STATUS_* bit
220
226
definitions in the emc2101_regs module, or refer to the datasheet for
221
227
more detail.
222
228
"""
223
229
return self ._status
224
230
225
231
@property
226
- def internal_temperature (self ):
232
+ def internal_temperature (self ) -> int :
227
233
"""The temperature as measured by the EMC2101's internal 8-bit
228
234
temperature sensor, which validly ranges from 0 to 85 and does not
229
235
support fractions (unlike the external readings).
@@ -233,7 +239,7 @@ def internal_temperature(self):
233
239
return self ._int_temp
234
240
235
241
@property
236
- def external_temperature (self ):
242
+ def external_temperature (self ) -> float :
237
243
"""The temperature measured using the external diode. The value is
238
244
read as a fixed-point 11-bit value ranging from -64 to approx 126,
239
245
with fractional part of 1/8 degree.
@@ -259,7 +265,7 @@ def external_temperature(self):
259
265
return full_tmp
260
266
261
267
@property
262
- def fan_speed (self ):
268
+ def fan_speed (self ) -> float :
263
269
"""The current speed in Revolutions per Minute (RPM).
264
270
265
271
:return: float fan speed rounded to 2dp.
@@ -270,7 +276,7 @@ def fan_speed(self):
270
276
raise OSError ("Connection" )
271
277
return round (emc2101_regs .FAN_RPM_DIVISOR / val , 2 )
272
278
273
- def _calculate_full_speed (self , pwm_f = None , dac = None ):
279
+ def _calculate_full_speed (self , pwm_f : int = None , dac : int = None ) -> None :
274
280
"""Determine the LSB value for a 100% fan setting"""
275
281
if dac is None :
276
282
dac = self .dac_output_enabled
@@ -287,12 +293,12 @@ def _calculate_full_speed(self, pwm_f=None, dac=None):
287
293
# PWM_F=0 behaves like PWM_F=1.
288
294
self ._full_speed_lsb = 2.0 * max (1 , pwm_f )
289
295
290
- def _speed_to_lsb (self , percentage ) :
296
+ def _speed_to_lsb (self , percentage : int ) -> int :
291
297
"""Convert a fan speed percentage to a Fan Setting byte value"""
292
298
return round ((percentage / 100.0 ) * self ._full_speed_lsb )
293
299
294
300
@property
295
- def manual_fan_speed (self ):
301
+ def manual_fan_speed (self ) -> float :
296
302
"""The fan speed used while the LUT is being updated and is unavailable. The
297
303
speed is given as the fan's PWM duty cycle represented as a float percentage.
298
304
The value roughly approximates the percentage of the fan's maximum speed.
@@ -304,7 +310,7 @@ def manual_fan_speed(self):
304
310
return (raw_setting / fan_speed ) * 100.0
305
311
306
312
@manual_fan_speed .setter
307
- def manual_fan_speed (self , fan_speed ) :
313
+ def manual_fan_speed (self , fan_speed : float ) -> None :
308
314
"""The fan speed used while the LUT is being updated and is unavailable. The
309
315
speed is given as the fan's PWM duty cycle represented as a float percentage.
310
316
The value roughly approximates the percentage of the fan's maximum speed.
@@ -324,13 +330,13 @@ def manual_fan_speed(self, fan_speed):
324
330
self ._fan_lut_prog = lut_disabled
325
331
326
332
@property
327
- def dac_output_enabled (self ):
333
+ def dac_output_enabled (self ) -> int :
328
334
"""When set, the fan control signal is output as a DC voltage instead
329
335
of a PWM signal."""
330
336
return self ._dac_output_enabled
331
337
332
338
@dac_output_enabled .setter
333
- def dac_output_enabled (self , value ) :
339
+ def dac_output_enabled (self , value : int ) -> None :
334
340
"""When set, the fan control signal is output as a DC voltage instead of
335
341
a PWM signal. Be aware that the DAC output very likely requires different
336
342
hardware to the PWM output. See datasheet and examples for info.
@@ -339,7 +345,7 @@ def dac_output_enabled(self, value):
339
345
self ._calculate_full_speed (dac = value )
340
346
341
347
@property
342
- def lut_enabled (self ):
348
+ def lut_enabled (self ) -> bool :
343
349
"""Enable or disable the internal look up table used to map a given
344
350
temperature to a fan speed.
345
351
@@ -350,7 +356,7 @@ def lut_enabled(self):
350
356
return not self ._fan_lut_prog
351
357
352
358
@property
353
- def tach_limit (self ):
359
+ def tach_limit (self ) -> float :
354
360
"""The maximum speed expected for the fan. If the fan exceeds this
355
361
speed, the status register TACH bit will be set.
356
362
@@ -365,7 +371,7 @@ def tach_limit(self):
365
371
return round (emc2101_regs .FAN_RPM_DIVISOR / limit , 2 )
366
372
367
373
@tach_limit .setter
368
- def tach_limit (self , new_limit ) :
374
+ def tach_limit (self , new_limit : float ) -> None :
369
375
"""Set the speed limiter on the fan PWM signal. The value of
370
376
15000 is arbitrary, but very few fans run faster than this. If the
371
377
fan exceeds this speed, the status register TACH bit will be set.
@@ -384,7 +390,7 @@ def tach_limit(self, new_limit):
384
390
self ._tach_limit_msb = (num >> 8 ) & 0xFF
385
391
386
392
@property
387
- def spinup_time (self ):
393
+ def spinup_time (self ) -> int :
388
394
"""The amount of time the fan will spin at the currently set drive
389
395
strength.
390
396
@@ -393,7 +399,7 @@ def spinup_time(self):
393
399
return self ._spin_time
394
400
395
401
@spinup_time .setter
396
- def spinup_time (self , spin_time ) :
402
+ def spinup_time (self , spin_time : int ) -> None :
397
403
"""Set the time that the SpinupDrive value will be used to get the
398
404
fan moving before the normal speed controls are activated. This is
399
405
needed because fan motors typically need a 'kick' to get them moving,
@@ -417,7 +423,7 @@ def spinup_time(self, spin_time):
417
423
self ._spin_time = spin_time
418
424
419
425
@property
420
- def spinup_drive (self ):
426
+ def spinup_drive (self ) -> int :
421
427
"""The drive strength of the fan on spinup in % max PWM duty cycle
422
428
(which approximates to max fan speed).
423
429
@@ -426,7 +432,7 @@ def spinup_drive(self):
426
432
return self ._spin_drive
427
433
428
434
@spinup_drive .setter
429
- def spinup_drive (self , spin_drive ) :
435
+ def spinup_drive (self , spin_drive : int ) -> None :
430
436
"""Set the drive (pwm duty percentage) that the SpinupTime value is applied
431
437
to move the fan before the normal speed controls are activated. This is needed
432
438
because fan motors typically need a 'kick' to get them moving, but after this
@@ -450,16 +456,16 @@ def spinup_drive(self, spin_drive):
450
456
self ._spin_drive = spin_drive
451
457
452
458
@property
453
- def conversion_rate (self ):
459
+ def conversion_rate (self ) -> int :
454
460
"""The rate at which temperature measurements are taken.
455
461
456
462
:return int: corresponding to the ConversionRate enumeration."""
457
463
return self ._conversion_rate
458
464
459
465
@conversion_rate .setter
460
- def conversion_rate (self , rate ) :
466
+ def conversion_rate (self , rate : int ) -> None :
461
467
"""Set the rate at which the external temperature is checked by
462
- by the device. Reducing this rate can reduce power consumption.
468
+ the device. Reducing this rate can reduce power consumption.
463
469
464
470
Usage:
465
471
0 commit comments