magneticSensor.py 896 B

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