Page_1.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import tkinter as tk
  2. import tk_tools
  3. import numpy as np
  4. from datetime import datetime
  5. from .Plot import Plot
  6. from .globals import *
  7. class Page_1(tk.Frame):
  8. plotLen = 100
  9. def __init__(self, parent, controller):
  10. tk.Frame.__init__(self, parent)
  11. self.controller = controller
  12. # graph
  13. self.serialPlot = Plot(xaxis=(0, self.plotLen * .3), yaxis=(0, 25),
  14. ytitle="Windgeschwindigkeit m/s",
  15. xtitle="vergangene Zeit in s",
  16. title="Geschwindigkeitsverlauf",
  17. line_colors=GRAPH_COLORS)
  18. canvas = self.serialPlot.create_canvas(self)
  19. canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  20. # legend
  21. container = tk.Frame(self, relief="solid")
  22. container.pack(side="bottom", fill="both", padx=20, pady=20)
  23. tk.Label(container, text="Ist-Geschwindigkeit").grid(row=0, column=1)
  24. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[0]).grid(row=0, column=0)
  25. tk.Label(container, text="Soll-Geschwindigkeit").grid(row=1, column=1)
  26. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[1]).grid(row=1, column=0)
  27. tk.Label(container, text="PWM-Wert, skaliert auf 0-25").grid(row=2, column=1)
  28. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[2]).grid(row=2, column=0)
  29. # right menu
  30. rightFrame = tk.LabelFrame(self, text="Bedienelemente")
  31. rightFrame.pack(side="left", fill="both", padx=5, pady=5)
  32. self.droLabel = tk.Label(rightFrame,font=("Arial","30"),fg="red")
  33. self.droLabel.pack(side="top", fill="both")
  34. # controls
  35. self.speedSlider = tk.Scale(rightFrame, from_=0, to=22, resolution=0.1, orient=tk.HORIZONTAL, width=50)
  36. self.speedSlider.pack(side="top", fill="both", padx=5, pady=5)
  37. label2 = tk.Label(rightFrame, text="Ventilator Soll-Wert in m/s")
  38. label2.pack()
  39. def update(self, visible):
  40. if visible:
  41. self.serialPlot.setTimeScale(self.plotLen, self.controller.intervalDelay)
  42. timestamps = (np.datetime64(datetime.now()) - self.controller.getLastValues(self.plotLen, "datetime")) / np.timedelta64(1,'s')
  43. self.serialPlot.plot_data(
  44. xs=[timestamps, timestamps, timestamps],
  45. ys=[
  46. self.controller.getLastValues(self.plotLen, "windspeed"),
  47. self.controller.getLastValues(self.plotLen, "set_value"),
  48. self.controller.getLastValues(self.plotLen, "motor_pwm") / 4
  49. ]
  50. )
  51. self.droLabel.config(text="{:5.3f} V - {:5.2} m/s".format(self.controller.getLastValue("adc_0"), self.controller.getLastValue("windspeed")))