main.py 1.9 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. import traceback
  9. conf = configparser.ConfigParser()
  10. conf.read('config.ini')
  11. class CalibrationStateMashine():
  12. def __init__(self):
  13. self.state = 0
  14. self.value_count = 0
  15. self.NOT_CALIBRATED = 0
  16. self.WAITING_POS_1 = 1
  17. self.ACCUMULATING_1 = 2
  18. self.WAITING_POS_2 = 3
  19. self.ACCUMULATING_2 = 4
  20. self.CALIBRATION_DONE = 5
  21. def state_clearname(self):
  22. if self.state == self.NOT_CALIBRATED:
  23. return "not calibrated"
  24. elif self.state == self.WAITING_POS_1:
  25. return "Waiting for Position one"
  26. elif self.state == self.ACCUMULATING_1:
  27. return "gathering values on position one"
  28. elif self.state == self.WAITING_POS_2:
  29. return "Waiting for position two"
  30. elif self.state == self.ACCUMULATING_2:
  31. return "gathering values on position two"
  32. elif self.state == self.CALIBRATION_DONE:
  33. return "calibration done"
  34. def next_state(self):
  35. if self.state < self.CALIBRATION_DONE:
  36. self.state += 1
  37. print(self.state_clearname())
  38. def next_state_gui(self):
  39. print("next_state_gui",self.state)
  40. if self.state == self.WAITING_POS_1 or self.state == self.WAITING_POS_2:
  41. self.next_state()
  42. def get_state(self):
  43. return self.state
  44. def reset_state(self):
  45. self.state = 0
  46. def main():
  47. ac_queue = queue.Queue()
  48. ac_calibration_state = CalibrationStateMashine()
  49. ac_sensor = sensors.AcusticSensor(conf, ac_queue, ac_calibration_state)
  50. try:
  51. ac_sensor.start()
  52. root = tk.Tk()
  53. root.title("Tracking System")
  54. view = MainWindow(root, ac_sensor, ac_queue, ac_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. traceback.print_exc()
  63. finally:
  64. ac_sensor.stop()
  65. main()