Browse Source

multiple serial callbacks

main
Hendrik Langer 4 years ago
parent
commit
4ec15f9bee
  1. 10
      raspberry/roberto/Serial.py

10
raspberry/roberto/Serial.py

@ -54,8 +54,8 @@ class Serial(object):
command = data[0] command = data[0]
argument = data[2:].strip() argument = data[2:].strip()
if command and command in self._callbacks: if command and command in self._callbacks:
cb = self._callbacks[command] callbacks = self._callbacks[command]
if cb: for cb in callbacks:
cb(argument) cb(argument)
else: else:
print("no callback found for command '%s'" % command) print("no callback found for command '%s'" % command)
@ -66,8 +66,10 @@ class Serial(object):
#raise #raise
def add_callback(self, cmd, callback): def add_callback(self, cmd, callback):
self._callbacks[cmd] = callback if not cmd in self._callbacks:
self._callbacks[cmd] = []
self._callbacks[cmd].append(callback)
def del_callback(self, cmd, callback): def del_callback(self, cmd, callback):
if cmd in self._callbacks: if cmd in self._callbacks:
del self._callbacks[cmd] self._callbacks[cmd].remove(callback)

Loading…
Cancel
Save