From: Andy Spencer Date: Tue, 11 Feb 2014 01:07:27 +0000 (+0000) Subject: Add initial plotting X-Git-Url: http://pileus.org/git/?p=~andy%2Fcsm213a-hw;a=commitdiff_plain;h=3912db35028a79fb9b660e8bd372be6abd2b8d8a Add initial plotting --- diff --git a/vis/visual.py b/vis/visual.py index 62a0bc3..4f0e0e0 100644 --- a/vis/visual.py +++ b/vis/visual.py @@ -25,6 +25,7 @@ class Visual: self.device = device self.logger = logger self.builder = Gtk.Builder() + self.history = [0.5]*1000 self.builder.add_from_file('visual.ui') self.builder.connect_signals(self) @@ -91,6 +92,23 @@ class Visual: setattr(self.config, name, value) self.config.save() + def on_expose(self, obj, _): + cairo = obj.window.cairo_create() + count = len(self.history) + extents = cairo.clip_extents() + width = extents[2] - extents[0] + height = extents[3] - extents[1] + + cairo.set_line_width(4) + for i in range(0,len(self.history)): + x = i*width/(count-1) + y = ((1-self.history[i]) * 0.8 + 0.1) * height + if i==0: + cairo.move_to(x, y) + else: + cairo.line_to(x, y) + cairo.stroke() + def on_key(self, win, ev): if ev.string == 'q': Gtk.main_quit(); @@ -141,6 +159,9 @@ class Visual: setval(self.tchs, state.tch, ['P', 'D']) setval(self.a2ds, state.a2d, []) + self.history = self.history[1:] + [state.a2d[0]] + self.window.queue_draw() + def debug(self, state): print('update: ' + str(state)) print('\tacc - ' + str(state.acc)) diff --git a/vis/visual.ui b/vis/visual.ui index 1c862a7..4973021 100644 --- a/vis/visual.ui +++ b/vis/visual.ui @@ -2,21 +2,6 @@ - - Serial - gtk-connect - - - - Settings - gtk-preferences - - - - Xively - gtk-connect - - 100 1 @@ -34,17 +19,17 @@ 1 10 - - Upload - gtk-floppy - - 6 8 1 10 + + Upload + gtk-floppy + + 100 1 @@ -62,7 +47,22 @@ 1 10 + + Serial + gtk-connect + + + + Settings + gtk-preferences + + + + Xively + gtk-connect + + False 5 @@ -1183,10 +1183,10 @@ - + True False - Plots + 2