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]
argument = data[2:].strip()
if command and command in self._callbacks:
cb = self._callbacks[command]
if cb:
callbacks = self._callbacks[command]
for cb in callbacks:
cb(argument)
else:
print("no callback found for command '%s'" % command)
@ -66,8 +66,10 @@ class Serial(object):
#raise
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):
if cmd in self._callbacks:
del self._callbacks[cmd]
self._callbacks[cmd].remove(callback)

Loading…
Cancel
Save