main.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.READY_ON_POS_1 = 1
  16. self.ACCUMULATING_1 = 2
  17. self.FINISHED_POS_1 = 3
  18. self.READY_ON_POS_2 = 4
  19. self.ACCUMULATING_2 = 5
  20. self.FINISHED_POS_2 = 6
  21. self.CALIBRATION_DONE = 7
  22. def state_clearname(self):
  23. if self.state == self.NOT_CALIBRATED:
  24. return "not calibrated"
  25. elif self.state == self.READY_ON_POS_1:
  26. return "ready on position one"
  27. elif self.state == self.ACCUMULATING_1:
  28. return "gathering values on position one"
  29. elif self.state == self.FINISHED_POS_1:
  30. return "finished gathering values from position one"
  31. elif self.state == self.READY_ON_POS_2:
  32. return "ready on position two"
  33. elif self.state == self.ACCUMULATING_2:
  34. return "gathering values on position two"
  35. elif self.state == self.FINISHED_POS_2:
  36. return "calculating calibration values"
  37. elif self.state == self.CALIBRATION_DONE:
  38. return "calibration done"
  39. def next_state(self):
  40. if self.state < 7:
  41. self.state += 1
  42. print(self.state_clearname())
  43. def add_value(self):
  44. self.value_count += 1
  45. def return_state(self):
  46. return self.state
  47. def return_value_count(self):
  48. return self.value_count
  49. def reset_state(self):
  50. self.state = 0
  51. def reset_value_count(self):
  52. self.value_count = 0
  53. def main():
  54. up_queue = queue.Queue()
  55. down_queue = queue.Queue()
  56. calibration_state = CalibrationStateMashine()
  57. ac_sensor = sensors.AcusticSensor(conf,up_queue,down_queue,calibration_state)
  58. sensor_thread = threading.Thread(target=ac_sensor.start)
  59. try:
  60. sensor_thread.start()
  61. root = tk.Tk()
  62. root.title("Tracking System")
  63. view = MainWindow(root,up_queue,down_queue,calibration_state)
  64. view.pack(side="top", fill="both", expand=True)
  65. view.update()
  66. root.mainloop()
  67. except KeyboardInterrupt:
  68. print("stop")
  69. except Exception as e:
  70. print("Error: ",e)
  71. finally:
  72. down_queue.put("stop")
  73. main()