This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_listener.py
71 lines (48 loc) · 2.17 KB
/
controller_listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
from controls import main_controller
import websocket
import json
import _thread as thread
logger = logging.getLogger(__name__)
def start(websocket_url):
#websocket.enableTrace(True)
def update_controls(ws, message):
controls = json.loads(message)
logger.info(controls)
if 'request_type' in controls:
if controls['request_type'] == 'calibration':
main_controller.calibration = controls
if 'controls' in controls:
if 'camera_mode' in controls['controls']:
main_controller.camera_mode = controls['controls']['camera_mode']
if 'enable_calibration_feed' in controls:
main_controller.enable_calibration_feed = controls['enable_calibration_feed']
if 'enable_camera_feed' in controls:
main_controller.enable_camera_feed = controls['enable_camera_feed']
if 'enable_processing_feed' in controls:
main_controller.enable_processing_feed = controls['enable_processing_feed']
if 'color_profiles' in controls:
for (camera_mode, profile ) in controls['color_profiles'].items():
logger.info('updating %s ' % camera_mode)
current_profile = main_controller.color_profiles.get(camera_mode)
current_profile.update(profile)
if 'color_profile' in controls:
profile = controls['color_profile']
logger.info('updating %s ' % profile['camera_mode'])
current_profile = main_controller.color_profiles.get(profile['camera_mode'])
current_profile.update(profile)
#logger.info(main_controller.color_profiles)
def ws_closed(ws):
logger.info('closed socket')
def on_error(ws, error):
print(error)
def on_open(ws):
main_controller.enable_camera = True
def start_dashboard_socket(*args):
dashboard_ws = websocket.WebSocketApp(websocket_url,
on_message = update_controls,
on_close=ws_closed,
on_error = on_error)
dashboard_ws.on_open = on_open
dashboard_ws.run_forever()
thread.start_new_thread(start_dashboard_socket, ())