loadCells.py 835 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from .GSV4BT import GSV4BT
  2. import time
  3. import bluetooth
  4. class LoadCells():
  5. def __init__(self):
  6. self.cells = (
  7. GSV4BT("addr1"),
  8. GSV4BT("addr2"),
  9. GSV4BT("addr3"),
  10. )
  11. def connect(self):
  12. success = True
  13. for cell in self.cells:
  14. if not cell.connect():
  15. success = False
  16. return success
  17. def getForces(self):
  18. return (
  19. self.cells[0].getForces(),
  20. self.cells[1].getForces(),
  21. self.cells[2].getForces()
  22. )
  23. if __name__ == "__main__":
  24. cells = LoadCells()
  25. while True:
  26. nearby_devices = bluetooth.discover_devices(lookup_names=True)
  27. print("Found {} devices.".format(len(nearby_devices)))
  28. for addr, name in nearby_devices:
  29. print(" {} - {}".format(addr, name))
  30. cells.connect()
  31. print(cells.getForces())
  32. cells.scan()
  33. time.sleep(1)