3636from . import OBD
3737
3838class Async (OBD ):
39- """ subclass representing an OBD-II connection """
39+ """
40+ Class representing an OBD-II connection with it's assorted commands/sensors
41+ Specialized for asynchronous value reporting.
42+ """
4043
4144 def __init__ (self , portstr = None , baudrate = 38400 ):
4245 super (Async , self ).__init__ (portstr , baudrate )
@@ -47,6 +50,7 @@ def __init__(self, portstr=None, baudrate=38400):
4750
4851
4952 def start (self ):
53+ """ Starts the async update loop """
5054 if self .is_connected ():
5155 debug ("Starting async thread" )
5256 self .running = True
@@ -58,6 +62,7 @@ def start(self):
5862
5963
6064 def stop (self ):
65+ """ Stops the async update loop """
6166 if self .thread is not None :
6267 debug ("Stopping async thread..." )
6368 self .running = False
@@ -67,11 +72,17 @@ def stop(self):
6772
6873
6974 def close (self ):
75+ """ Closes the connection """
7076 self .stop ()
7177 super (Async , self ).close ()
7278
7379
7480 def watch (self , c , callback = None , force = False ):
81+ """
82+ Subscribes the given command for continuous updating. Once subscribed,
83+ query() will return that command's latest value. Optional callbacks can
84+ be given, which will be fired upon every new value.
85+ """
7586
7687 # the dict shouldn't be changed while the daemon thread is iterating
7788 if self .running :
@@ -95,6 +106,11 @@ def watch(self, c, callback=None, force=False):
95106
96107
97108 def unwatch (self , c , callback = None ):
109+ """
110+ Unsubscribes a specific command (and optionally, a specific callback)
111+ from being updated. If no callback is specified, all callbacks for
112+ that command are dropped.
113+ """
98114
99115 # the dict shouldn't be changed while the daemon thread is iterating
100116 if self .running :
@@ -117,6 +133,7 @@ def unwatch(self, c, callback=None):
117133
118134
119135 def unwatch_all (self ):
136+ """ Unsubscribes all commands and callbacks from being updated """
120137
121138 # the dict shouldn't be changed while the daemon thread is iterating
122139 if self .running :
@@ -128,6 +145,11 @@ def unwatch_all(self):
128145
129146
130147 def query (self , c ):
148+ """
149+ Non-blocking query().
150+ Only commands that have been watch()ed will return valid responses
151+ """
152+
131153 if c in self .commands :
132154 return self .commands [c ]
133155 else :
@@ -155,4 +177,4 @@ def run(self):
155177 callback (r )
156178
157179 else :
158- time .sleep (1 ) # idle
180+ time .sleep (0.25 ) # idle
0 commit comments