summaryrefslogtreecommitdiff
path: root/reader/reader.py
diff options
context:
space:
mode:
Diffstat (limited to 'reader/reader.py')
-rw-r--r--reader/reader.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/reader/reader.py b/reader/reader.py
index e5a0d9b..8e4fe2c 100644
--- a/reader/reader.py
+++ b/reader/reader.py
@@ -1 +1,58 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python2
+
+from websocket_server import WebsocketServer
+
+import thread
+import serial
+import time
+import json
+
+measures = {
+ 'pressure_bottom': 0,
+ 'pressure_top': 0,
+ 'flexion': 0,
+ 'angle_x': 0,
+ 'angle_y': 0,
+ 'angle_z': 0,
+ }
+
+def server_procedure(server):
+ server.run_forever()
+
+def main():
+ server = WebsocketServer(1234, '0.0.0.0')
+
+ thread.start_new_thread(server_procedure, (server,))
+
+ #with serial.Serial('/dev/ttyACM0', 9600) as ser:
+ with open('/tmp/fifo') as ser:
+ while True:
+ line = ser.readline()
+
+ if not line:
+ time.sleep(0.01)
+ continue
+
+ line = line.strip()
+
+ if line.startswith('PRESSURE_BOTTOM:'):
+ measures['pressure_bottom'] = line.split('PRESSURE_BOTTOM:')[1]
+ elif line.startswith('PRESSURE_TOP:'):
+ measures['pressure_top'] = line.split('PRESSURE_TOP:')[1]
+ elif line.startswith('FLEXION:'):
+ measures['flexion'] = line.split('FLEXION:')[1]
+ elif line.startswith('ANGLE_X:'):
+ measures['angle_x'] = line.split('ANGLE_X:')[1]
+ elif line.startswith('ANGLE_Y:'):
+ measures['angle_y'] = line.split('ANGLE_Y:')[1]
+ elif line.startswith('ANGLE_Z:'):
+ measures['angle_z'] = line.split('ANGLE_Z:')[1]
+ else:
+ print(line)
+
+ server.send_message_to_all(json.dumps(measures))
+
+
+
+if __name__ == '__main__':
+ main()