magneticSensor.py 665 B

123456789101112131415161718192021222324252627282930313233
  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.log_handler = logHandler.get_log_handler() # neu
  11. #pass
  12. def start(self):
  13. if not conn.isConnected():
  14. conn.open()
  15. conn.addRecvCallback(self._readCb)
  16. def _readCb(self, raw):
  17. print("mag: ", conn.getMagneticField())
  18. def calibrate(self, x, y):
  19. pass
  20. def read(self):
  21. return conn.getMagneticField()
  22. def stop(self): # neu
  23. self.log_handler.log_and_print("stop magnetic sensor")
  24. conn.close