25
25
import time
26
26
import struct
27
27
28
+ try :
29
+ import typing # pylint: disable=unused-import
30
+ from busio import UART
31
+ except ImportError :
32
+ pass
33
+
28
34
__version__ = "0.0.0+auto.0"
29
35
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TFmini.git"
30
36
@@ -46,7 +52,7 @@ class TFmini:
46
52
:param timeout: how long we'll wait for valid data or response, in seconds. Default is 1
47
53
"""
48
54
49
- def __init__ (self , uart , * , timeout = 1 ) :
55
+ def __init__ (self , uart : UART , * , timeout : int = 1 ) -> None :
50
56
self ._uart = uart
51
57
self ._uart .baudrate = 115200
52
58
self ._uart .reset_input_buffer ()
@@ -55,7 +61,7 @@ def __init__(self, uart, *, timeout=1):
55
61
self ._mode = None
56
62
57
63
@property
58
- def distance (self ):
64
+ def distance (self ) -> None :
59
65
"""The most recent distance measurement in centimeters"""
60
66
try :
61
67
self ._uart .reset_input_buffer ()
@@ -87,24 +93,24 @@ def distance(self):
87
93
raise RuntimeError ("Timed out looking for valid data" )
88
94
89
95
@property
90
- def strength (self ):
96
+ def strength (self ) -> int :
91
97
"""The signal validity, higher value means better measurement"""
92
98
_ = self .distance # trigger distance measurement
93
99
return self ._strength
94
100
95
101
@property
96
- def mode (self ):
102
+ def mode (self ) -> int :
97
103
"""The measurement mode can be MODE_SHORT (2) or MODE_LONG (7)"""
98
104
_ = self .distance # trigger distance measurement
99
105
return self ._mode
100
106
101
107
@mode .setter
102
- def mode (self , newmode ) :
108
+ def mode (self , newmode : int ) -> None :
103
109
if not newmode in (MODE_LONG , MODE_SHORT ):
104
110
raise ValueError ("Invalid mode" )
105
111
self ._set_config (_CONFIGPARAM + bytes ([0 , 0 , newmode , 0x11 ]))
106
112
107
- def _set_config (self , command ) :
113
+ def _set_config (self , command : int ) -> None :
108
114
"""Manager for sending commands, put sensor into config mode, config,
109
115
then exit configuration mode!"""
110
116
self ._uart .write (_STARTCONFIG )
0 commit comments