main.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if self.state == self.WAITING_POS_1 or self.state == self.WAITING_POS_2:
  39. self.next_state()
  40. def get_state(self):
  41. return self.state
  42. def reset_state(self):
  43. self.state = 0
  44. def main():
  45. up_queue = queue.Queue()
  46. down_queue = queue.Queue()
  47. calibration_state = CalibrationStateMashine()
  48. ac_sensor = sensors.AcusticSensor(conf,up_queue,down_queue,calibration_state)
  49. sensor_thread = threading.Thread(target=ac_sensor.start)
  50. try:
  51. sensor_thread.start()
  52. root = tk.Tk()
  53. root.title("Tracking System")
  54. view = MainWindow(root,up_queue,down_queue,calibration_state)
  55. view.pack(side="top", fill="both", expand=True)
  56. view.update()
  57. root.mainloop()
  58. except KeyboardInterrupt:
  59. print("stop")
  60. except Exception as e:
  61. print("Error: ",e)
  62. finally:
  63. down_queue.put("stop")
  64. main()