magneticSensor.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import queue
  2. import time
  3. import threading
  4. from sensors.calibration import CalibrationStateMashine
  5. from sensors.connection import globalArduinoSlave
  6. import logHandler
  7. conn = globalArduinoSlave()
  8. class MagneticSensor:
  9. def __init__(self, conf):
  10. self.conf = conf
  11. self.queue = queue.Queue()
  12. self.calibration_state = CalibrationStateMashine()
  13. self.log_handler = logHandler.get_log_handler() # neu
  14. self.field_height = float(conf["field"]["y"])
  15. self.field_width = float(conf["field"]["x"])
  16. self.n = 0
  17. #pass
  18. def start(self):
  19. self.log_handler.log_and_print("start acoustic sensor")
  20. if not conn.isConnected():
  21. conn.open()
  22. conn.addRecvCallback(self._readCb)
  23. self.dummyActive = True
  24. dummyThread = threading.Thread(target=self._readCb_dummy)
  25. def _readCb(self, raw):
  26. print("mag: ", conn.getMagneticField())
  27. def _readCb_dummy(self):
  28. pass
  29. def calibrate(self, x, y):
  30. pass
  31. def read(self):
  32. return conn.getMagneticField()
  33. def stop(self): # neu
  34. self.log_handler.log_and_print("stop magnetic sensor")
  35. conn.close