magneticSensor.py 690 B

12345678910111213141516171819202122232425262728293031323334
  1. import queue
  2. import time
  3. from sensors.connection import globalArduinoSlave
  4. import logHandler
  5. conn = globalArduinoSlave()
  6. class MagneticSensor:
  7. def __init__(self, conf):
  8. self.conf = conf
  9. self.queue = queue.Queue()
  10. self.success = False
  11. self.log_handler = logHandler.get_log_handler() # neu
  12. #pass
  13. def start(self):
  14. if not conn.isConnected():
  15. conn.open()
  16. conn.addRecvCallback(self._readCb)
  17. def _readCb(self, raw):
  18. print("mag: ", conn.getMagneticField())
  19. def calibrate(self, x, y):
  20. pass
  21. def read(self):
  22. return conn.getMagneticField()
  23. def stop(self): # neu
  24. self.log_handler.log_and_print("stop magnetic sensor")
  25. conn.close