Commit e4e75d3fa192a94ebce1138da6bc7c9090493825
1 parent
6432a3a5
Exists in
master
Accept data from serial port, store in series
Showing
1 changed file
with
13 additions
and
3 deletions
Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
| @@ -3,10 +3,19 @@ | @@ -3,10 +3,19 @@ | ||
| 3 | import pyglet | 3 | import pyglet |
| 4 | #import math | 4 | #import math |
| 5 | #import time | 5 | #import time |
| 6 | -#import serial | 6 | +import serial |
| 7 | 7 | ||
| 8 | from colours import * | 8 | from colours import * |
| 9 | 9 | ||
| 10 | +datafeed = serial.Serial( | ||
| 11 | +port='/dev/ttyUSB0', | ||
| 12 | +baudrate = 9600, | ||
| 13 | +parity=serial.PARITY_NONE, | ||
| 14 | +stopbits=serial.STOPBITS_ONE, | ||
| 15 | +bytesize=serial.EIGHTBITS, | ||
| 16 | +timeout=1 | ||
| 17 | +) | ||
| 18 | + | ||
| 10 | class Series: | 19 | class Series: |
| 11 | def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): | 20 | def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): |
| 12 | self.title = title | 21 | self.title = title |
| @@ -58,9 +67,10 @@ plots = [] | @@ -58,9 +67,10 @@ plots = [] | ||
| 58 | plots.append(Plot(testseries)) | 67 | plots.append(Plot(testseries)) |
| 59 | 68 | ||
| 60 | def pollSerial(foo): | 69 | def pollSerial(foo): |
| 61 | - """Dummy, will check serial port for incoming data""" | 70 | + """Check serial port for incoming data""" |
| 62 | # Note, foo seems to be a float | 71 | # Note, foo seems to be a float |
| 63 | - pass | 72 | + values = datafeed.readline().strip().split(", ") |
| 73 | + testseries.addpoint(values) | ||
| 64 | 74 | ||
| 65 | pyglet.clock.schedule_interval(pollSerial, 0.1) | 75 | pyglet.clock.schedule_interval(pollSerial, 0.1) |
| 66 | 76 |