import queue import time import threading import random from sensors.calibration import CalibrationStateMashine from sensors.connection import globalArduinoSlave import logHandler conn = globalArduinoSlave() class MagneticSensor: def __init__(self, conf): self.conf = conf self.queue = queue.Queue() self.calibration_state = CalibrationStateMashine() self.log_handler = logHandler.get_log_handler() # neu self.success = False self.field_height = float(conf["field"]["y"]) self.field_width = float(conf["field"]["x"]) self.n = 0 #pass def start(self): self.log_handler.log_and_print("start acoustic sensor") if not conn.isConnected(): conn.open() conn.addRecvCallback(self._readCb) self.dummyActive = True dummyThread = threading.Thread(target=self._readCb_dummy) dummyThread.start() def _readCb(self, raw): print("mag: ", conn.getMagneticField()) def _readCb_dummy(self): self.log_handler.log_and_print("acoustic sensor: generating test values") while self.dummyActive: dummyValue = 250 position = 20 self.pass_to_gui(position + dummyValue) def calibrate(self, x, y): pass def read(self): return conn.getMagneticField() def stop(self): # neu self.log_handler.log_and_print("stop magnetic sensor") conn.close() def pass_to_gui(self, data): self.queue.put(("data", data))