main.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import sensors
  2. from gui.mainWindow import MainWindow
  3. import time
  4. import threading
  5. import queue
  6. import configparser
  7. import tkinter as tk
  8. conf = configparser.ConfigParser()
  9. conf.read('config.ini')
  10. class CalibrationStateMashine():
  11. def __init__(self):
  12. self.state = 0
  13. self.value_count = 0
  14. self.NOT_CALIBRATED = 0
  15. self.WAITING_POS_1 = 1
  16. self.ACCUMULATING_1 = 2
  17. self.WAITING_POS_2 = 3
  18. self.ACCUMULATING_2 = 4
  19. self.CALIBRATION_DONE = 5
  20. def state_clearname(self):
  21. if self.state == self.NOT_CALIBRATED:
  22. return "not calibrated"
  23. elif self.state == self.WAITING_POS_1:
  24. return "ready on position one"
  25. elif self.state == self.ACCUMULATING_1:
  26. return "gathering values on position one"
  27. elif self.state == self.WAITING_POS_2:
  28. return "ready on position two"
  29. elif self.state == self.ACCUMULATING_2:
  30. return "gathering values on position two"
  31. elif self.state == self.CALIBRATION_DONE:
  32. return "calibration done"
  33. def next_state(self):
  34. if self.state < self.CALIBRATION_DONE:
  35. self.state += 1
  36. print(self.state_clearname())
  37. def next_state_gui(self):
  38. print("next_state_gui",self.state)
  39. if self.state == self.WAITING_POS_1 or self.state == self.WAITING_POS_2:
  40. self.next_state()
  41. def get_state(self):
  42. return self.state
  43. def reset_state(self):
  44. self.state = 0
  45. def main():
  46. up_queue = queue.Queue()
  47. down_queue = queue.Queue()
  48. calibration_state = CalibrationStateMashine()
  49. ac_sensor = sensors.AcusticSensor(conf,up_queue,down_queue,calibration_state)
  50. sensor_thread = threading.Thread(target=ac_sensor.start)
  51. try:
  52. sensor_thread.start()
  53. root = tk.Tk()
  54. root.title("Tracking System")
  55. view = MainWindow(root,up_queue,down_queue,calibration_state)
  56. view.pack(side="top", fill="both", expand=True)
  57. view.update()
  58. root.mainloop()
  59. except KeyboardInterrupt:
  60. print("stop")
  61. except Exception as e:
  62. print("Error: ",e)
  63. finally:
  64. down_queue.put("stop")
  65. main()