Commit 18ce3a70 authored by Constantin's avatar Constantin
Browse files

some comments

parent 2aa5af75
......@@ -32,6 +32,19 @@ class Actor:
if delay > 0:
time.sleep(delay)
''' todo list explanation
type:
[(bool,float),(bool,float)...]
semantic:
[(b0,t0),(b1,t1)...]
means
Set the given pin to state b0 and then wait for t0 seconds. Then set the pin to b1 and wait for t1 seconds, and so on.
'''
''' tid explanation
All cmds with same tid will be executed by the same worker thread.
Worker threads do work one thing at a time from their input queue.
=> different commands with same tid will never be executed simultaneously
'''
CMDs = {
CMD_UNLOCK: CMD("unlock", pin=12, tid=0, todo=[(True, 0.3), (False, 0.1)]),
CMD_LOCK: CMD("lock", pin=16, tid=0, todo=[(True, 0.3), (False, 0.1)]),
......@@ -47,7 +60,9 @@ class Actor:
self.threads = {}
for cmd in Actor.CMDs.values():
GPIO.setup(cmd.pin, GPIO.OUT)
# initialize all output pins with False
GPIO.output(cmd.pin, False)
# one thread for each tid
if not cmd.tid in self.threads:
self.threads[cmd.tid] = ThreadFunction(self._execute, "Actor TID %d" % cmd.tid)
......
......@@ -80,6 +80,7 @@ def fire_and_forget_cmd (cmd, log_prefix):
fire_and_forget(_fire_and_forget_cmd)
# Threaded callback class
# Wrapper function class which takes care that all calls to the wrapped function are sequentialized
class ThreadFunction():
_CALL = 0
_TERM = 1
......
......@@ -18,7 +18,7 @@ class Waker():
self._t = ThreadRepeater(self._wake, SLEEP_TIME, name="Waker")
def register(self, f, time, one_shot = False):
'''Register a function which is called approximately every <time> seconds (or just once, if one_shot is True). f should return quickly, or it will delay the waker!'''
'''Register a function which is called approximately every <time> seconds (or just once, if one_shot is True). f should return quickly, or it will delay the waker! If f does not naturally return quickly, you can wrap it with libtuer.fire_and_forget.'''
time = max(time//SLEEP_TIME, 1)
with self._tobewokens_lock:
self._tobewokens.append(ToBeWoken(f, time, one_shot))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment