sensors.py 822 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from connection import ArduinoSlave
  2. import time
  3. conn = ArduinoSlave()
  4. class AcusticSensor:
  5. def __init__(self):
  6. pass
  7. def start(self):
  8. if not conn.isConnected():
  9. conn.open()
  10. conn.addRecvCallback(self._readCb)
  11. def _readCb(self, raw):
  12. print("acc: ", conn.getAcusticRTTs())
  13. def calibrate(self, x, y):
  14. pass
  15. def read(self):
  16. return (0, 0)
  17. class MagneticSensor:
  18. def __init__(self):
  19. pass
  20. def start(self):
  21. if not conn.isConnected():
  22. conn.open()
  23. conn.addRecvCallback(self._readCb)
  24. def _readCb(self, raw):
  25. print("mag: ", conn.getMagneticField())
  26. def calibrate(self, x, y):
  27. pass
  28. def read(self):
  29. return (0, 0)
  30. if __name__ == "__main__":
  31. acc = AcusticSensor()
  32. acc.start()
  33. mag = MagneticSensor()
  34. mag.start()
  35. while True:
  36. time.sleep(1)