123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- # 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 motorController.pwmOutput import PWM
- from motorController.pidController import PID
- from ui import *
- import tkinter as tk
- import tk_tools
- import time
- class Main(tk.Tk, Table):
- def __init__(self, *args, **kwargs):
- print('initializing window...')
- tk.Tk.__init__(self, *args, **kwargs)
- tk.Tk.wm_title(self, "Windkanal-Tool")
- #early response to user
- self.update_idletasks()
- print('initializing sensors...')
- self.adc = MCP3008(0,0)
- self.pressureSensors = Spd610Array()
- self.forceSensors = LoadCells()
- self.forceSensors.start()
- self.motorController = PWM(32)
- self.pid = PID()
- self.motorEnabled = False
-
- print('initializing database...')
- Table.__init__(self,
- ["windspeed", "motor_pwm"] +
- ["pressure_{}".format(i) for i in range(8)] +
- ["adc_{}".format(i) for i in range(1)] +
- ["force_X_1", "force_Y_1", "force_Z_1"] +
- ["force_X_2", "force_Y_2", "force_Z_2"] +
- ["force_X_3", "force_Y_3", "force_Z_3"])
- print('initializing GUI...')
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand = True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- menubar = tk.Menu(container)
- filemenu = tk.Menu(menubar, tearoff=0)
- filemenu.add_command(label="Save settings", command = lambda: self.popupmsg("Not supported just yet!"))
- filemenu.add_separator()
- filemenu.add_command(label="Exit", command=quit)
- menubar.add_cascade(label="File", menu=filemenu)
- tk.Tk.config(self, menu=menubar)
- label = tk.Label(self, text="Bedienelemente", font=LARGE_FONT)
- label.pack(pady=10,padx=10)
- # top menu
- top = tk.Frame(self, borderwidth=2, relief="solid")
- button1 = tk.Button(top, text="Bedienelemente", command=lambda: self.show_frame(Page_1))
- button1.pack(side=tk.LEFT)
- button2 = tk.Button(top, text="Kräfte", command=lambda: self.show_frame(Page_2))
- button2.pack(side=tk.LEFT)
- button3 = tk.Button(top, text="Druck", command=lambda: self.show_frame(Page_3))
- button3.pack(side=tk.LEFT)
- button4 = tk.Button(top,text="Einstellungen",command=lambda: self.show_frame(Page_4))
- button4.pack(side=tk.LEFT)
- button5 = tk.Button(top, text="QUIT", fg="red",command=quit)
- button5.pack(side=tk.LEFT)
- top.pack(side="top", expand=True, fill="both")
- self.frames = {}
- for F in (Page_1, Page_2, Page_3, Page_4):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame(Page_1)
- self.after(5000,self.interval)
- print('program ready!')
- def show_frame(self, cont):
- self.currentFrame = self.frames[cont]
- self.currentFrame.tkraise()
- def popupmsg(self, msg=""):
- popup = tk.Toplevel(self.master)
- popup.wm_title("Error!")
- label = tk.Label(popup, text=msg, font=LARGE_FONT)
- label.pack(side="top", fill="x", pady=10)
- b1 = tk.Button(popup, text="Okay", command=popup.destroy)
- b1.pack()
-
- def interval(self):
- self.after(300,self.interval)
- start = time.time()
- adcValue = self.adc.getVoltage(0)
- windSpeed = adcValue * 1337
- pwmValue = self.pid.update(windSpeed)
- if not self.motorEnabled:
- pwmValue = 0
- self.motorController.setDutyCycle(pwmValue)
- i2cValues = self.pressureSensors.getValues()
- self.addRow(
- [windSpeed, pwmValue] +
- i2cValues +
- [adcValue] +
- self.forceSensors.getForces(0) +
- self.forceSensors.getForces(1) +
- self.forceSensors.getForces(2)
- )
- print("sensors: {:8.3f} ms".format((time.time() - start)*1000))
- start = time.time()
- for frame in self.frames:
- self.frames[frame].update(self.frames[frame] == self.currentFrame)
- print("draw: {:8.3f} ms".format((time.time() - start)*1000))
-
-
|