Browse Source

serial callbacks in frontend

main
Hendrik Langer 4 years ago
parent
commit
68c75ff0e5
  1. 4
      raspberry/roberto/Serial.py
  2. 7
      raspberry/roberto/views/websocket/routes.py

4
raspberry/roberto/Serial.py

@ -62,3 +62,7 @@ class Serial(object):
def add_callback(cmd, callback): def add_callback(cmd, callback):
self._callbacks[cmd] = callback self._callbacks[cmd] = callback
def del_callback(cmd, callback):
if cmd in self._callbacks:
del self._callbacks[cmd]

7
raspberry/roberto/views/websocket/routes.py

@ -97,6 +97,8 @@ def disconnect():
print("Received Disconnect message from %s" % sid) print("Received Disconnect message from %s" % sid)
leave_room(ROOM) leave_room(ROOM)
webrtccamera.disconnect_client(sid, ROOM) webrtccamera.disconnect_client(sid, ROOM)
from roberto import serial
serial.del_callback('B', display_battery)
@socketio.on('connect', namespace='/webrtc') @socketio.on('connect', namespace='/webrtc')
def connect(): def connect():
@ -104,6 +106,8 @@ def connect():
print("Received Connect message from %s" % sid) print("Received Connect message from %s" % sid)
join_room(ROOM) join_room(ROOM)
webrtccamera.connect_client(sid, ROOM) webrtccamera.connect_client(sid, ROOM)
from roberto import serial
serial.add_callback('B', display_battery)
@socketio.on_error_default @socketio.on_error_default
def default_error_handler(e): def default_error_handler(e):
@ -113,3 +117,6 @@ def default_error_handler(e):
keys.sort() keys.sort()
for key in request: for key in request:
print('%s: %s' % (key, repr(request[key]))) print('%s: %s' % (key, repr(request[key])))
def display_battery(val):
socketio.emit('battery', data=val, room=ROOM, namespace='/webrtc')

Loading…
Cancel
Save