subDesTagesMitExtraKaese 4 gadi atpakaļ
vecāks
revīzija
54cd96955e

+ 2 - 1
.gitignore

@@ -1,3 +1,4 @@
 *.code-workspace
 __pycache__/
-.vscode
+.vscode
+*.csv

+ 22 - 2
software/appWindow.py

@@ -1,7 +1,9 @@
 # The code for changing pages was derived from: http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter
 # License: http://creativecommons.org/licenses/by-sa/3.0/	
 
+from database import Table
 from analogPressure.sdpArray import SdpArray
+from analogPressure.mcp3008 import MCP3008
 from digitalPressure.sdp610Array import Spd610Array
 from wirelessLoadCell.loadCells import LoadCells
 from ui import *
@@ -11,12 +13,26 @@ import tk_tools
 from time import *
 
 
-class Main(tk.Tk):
+class Main(tk.Tk, Table):
   def __init__(self, *args, **kwargs):
     tk.Tk.__init__(self, *args, **kwargs)
     tk.Tk.wm_title(self, "Windkanal-Tool")
+
+    self.adc = MCP3008(0,0)
+    self.pressureSensors = Spd610Array()
+    self.forceSensors = LoadCells()
+    self.motorController = None
     
+    Table.__init__(self, 
+    ["time", "windspeed", "motor_pwm"] + 
+    [f"pressure_{i}" for i in range(8)] + 
+    [f"adc_{i}" for i in range(8)] + 
+    [f"force_X_1", f"force_Y_1", f"force_Z_1"] +
+    [f"force_X_2", f"force_Y_2", f"force_Z_2"] + 
+    [f"force_X_3", f"force_Y_3", f"force_Z_3"])
     
+    self.saveAsCsv("test.csv")
+
     container = tk.Frame(self)
     container.pack(side="top", fill="both", expand = True)
     container.grid_rowconfigure(0, weight=1)
@@ -64,6 +80,8 @@ class Main(tk.Tk):
 
     self.show_frame(Page_1)
 
+    self.interval()
+
   def show_frame(self, cont):
     frame = self.frames[cont]
     frame.tkraise()
@@ -76,7 +94,9 @@ class Main(tk.Tk):
       b1 = tk.Button(popup, text="Okay", command=popup.destroy)
       b1.pack()
   def interval(self):
-    
+    adcValues = self.adc.read()
+
+    self.addRow([time.time()] + adcValues)
     for frame in self.frames:
       frame.update()
 

+ 27 - 0
software/database.py

@@ -0,0 +1,27 @@
+
+import csv
+
+class Table:
+  columnNames = []
+  rows = []
+  def __init__(self, columns):
+    self.columnNames = columns
+
+  def addRow(self, values):
+    self.rows.append(values)
+
+  def getLastRow(self):
+    if len(self.rows) > 0:
+      return rows[len(self.rows)-1]
+    else:
+      return [0] * len(self.columnNames)
+
+  def getLastValue(self, column):
+    col = self.columnNames.index(column)
+    return self.getLastRow(col)
+
+  def saveAsCsv(self, filename):
+    with open(filename,"w+", newline='') as my_csv:
+      csvWriter = csv.writer(my_csv,delimiter=',')
+      csvWriter.writerow(self.columnNames)
+      csvWriter.writerows(self.rows)

+ 1 - 1
software/ui/Page_1.py

@@ -43,5 +43,5 @@ class Page_1(tk.Frame):
     label3.pack()
 
   def update(self):
-    self.serialPlot.update(3)
+    self.serialPlot.update(controller.getLastValue("force_X_1"))
     self.label4.config(text="{:3d} Nm".format(3))

+ 3 - 1
software/ui/Page_2.py

@@ -11,4 +11,6 @@ class Page_2(tk.Frame):
     button1 = tk.Button(self, text="Page_0", command=lambda: controller.show_frame(Page_0))
     button1.pack()
     button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
-    button2.pack()
+    button2.pack()
+  def update(self):
+    pass

+ 2 - 0
software/ui/Page_3.py

@@ -12,3 +12,5 @@ class Page_3(tk.Frame):
     button1.pack()
     button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
     button2.pack()
+  def update(self):
+    pass

+ 3 - 1
software/ui/Page_4.py

@@ -10,4 +10,6 @@ class Page_4(tk.Frame):
     button1 = tk.Button(self, text="Page_0", command=lambda: controller.show_frame(Page_0))
     button1.pack()
     button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
-    button2.pack()
+    button2.pack()
+  def update(self):
+    pass