Przeglądaj źródła

add ac_values to graph

subDesTagesMitExtraKaese 4 lat temu
rodzic
commit
89b39493cd

+ 5 - 7
raspberry-pi/gui/graph.py

@@ -1,5 +1,5 @@
 import tkinter as tk
-import time, math, noise
+import time, math
 from PIL import Image, ImageDraw, ImageTk
 
 class Graph(tk.Canvas):
@@ -15,7 +15,7 @@ class Graph(tk.Canvas):
     self.image = self.create_image(0, 0, image=None, anchor='nw')
 
     self.bind("<Configure>", self.on_resize)
-    self.n = 0
+    self.scale = 450 / 2
 
   def drawBackground(self):
     self.bg = Image.new('RGB', (self.width, self.height), (0,20,0))
@@ -34,12 +34,10 @@ class Graph(tk.Canvas):
     self.drawBackground()
     self.canvas = Image.blend(self.canvas, self.bg, 0.1)
 
-  def update(self):
+  def update(self, data):
     self.coord = [self.coord[-1]]
-    for i in range(30):
-      self.coord.append(((noise.pnoise1(self.n)+1)*self.width/2, (noise.pnoise1(self.n*1.3+3)+1)*self.height/2))
-
-      self.n += 0.001
+    for point in data[0]:
+      self.coord.append((point[0] / self.scale * self.width/2, point[1] / self.scale * self.height/2))
 
     self.canvas = Image.blend(self.canvas, self.bg, 1/250)
     draw = ImageDraw.Draw(self.canvas)

+ 7 - 1
raspberry-pi/gui/mainWindow.py

@@ -30,7 +30,13 @@ class MainWindow(tk.Frame):
     cs.pack(side="top", fill="both", expand=True)
 
   def update(self):
-    self.graph.update()
+    ac_data = []
+    while self.up_queue.qsize() > 0:
+      name, data = self.up_queue.get()
+      if name == "ac_data":
+        ac_data.append(data)
+
+    self.graph.update([ac_data])
     self.csString.set(self.calibration_state.state_clearname())
     self.root.after(30, self.update)
 

+ 1 - 1
raspberry-pi/sensors.py

@@ -129,7 +129,7 @@ class AcusticSensor:
       traceback.print_exc()
 
   def pass_to_gui(self,data):
-    self.up_queue.put(data)
+    self.up_queue.put(("ac_data", data))
 
 class MagneticSensor:
   def __init__(self):