Browse Source

added device classes

subDesTagesMitExtraKaese 4 years ago
parent
commit
f8461c7145

+ 12 - 4
software/analogPressure/sdpArray.py

@@ -1,16 +1,24 @@
-from MCP3008 import MCP3008
+from mcp3008 import MCP3008
+import time
 
 class SdpArray():
-  __init__(self):
+  def __init__(self):
     self.adcs = (
       MCP3008(0, 0), 
       MCP3008(0, 1)
     )
 
-  read(self, channel):
+  def getVoltage(self, channel):
     if channel < 8:
       value = adc[0].read(channel) 
     else:
       value = adc[1].read(channel-8)
 
-    print("Anliegende Spannung: %.2f" % (value / 1023.0 * 3.3) )
+    voltage = value / 1023.0 * 3.3
+    return voltage
+
+if __name__ == "__main__":
+  sdps = SdpArray()
+  while True:
+    print("Anliegende Spannung:", sdps.getVoltage(0))
+    time.sleep(1)

+ 0 - 8
software/digitalPressure/sdp610.py

@@ -1,8 +0,0 @@
-
-class Spd610():
-  i2cAddress = 12
-
-  __init__(self, i2cAddress):
-    self.i2cAddress = i2cAddress
-
-  readValue(self):

+ 36 - 0
software/digitalPressure/sdp610Array.py

@@ -0,0 +1,36 @@
+import smbus
+import time
+
+class Spd610Array():
+  i2cAddresses = (
+    0x21,
+    0x41,
+    0x61,
+    0x31,
+    0x39,
+    0x29,
+    0x35,
+    0x40
+  )
+  def __init__(self):
+    self.bus = smbus.SMBus(0)
+
+  def readValue(self, addr):
+    self.bus.write_byte_data(addr, 0, 0xF1)
+    block = self.bus.read_i2c_block_data(addr, 0, 3)
+    value = (block[0] * 256 + block[1]) / 240.0
+    crc = block[2]
+    return value
+
+  def getValues(self):
+    values = ()
+    for addr in self.i2cAddresses:
+      values.append(self.readValue(addr))
+    return values
+
+if __name__ == "__main__":
+  sdp = Spd610Array()
+  while True:
+    print(sdp.getValues())
+    time.sleep(1)
+

+ 0 - 20
software/wirelessLoadCell/GSV4-BT.py

@@ -1,20 +0,0 @@
-
-
-
-# simple inquiry example
-import bluetooth
-
-nearby_devices = bluetooth.discover_devices(lookup_names=True)
-print("Found {} devices.".format(len(nearby_devices)))
-
-for addr, name in nearby_devices:
-  print("  {} - {}".format(addr, name))
-
-
-class GSV4-BT():
-  __init__(self):
-
-    pass
-
-  scan(self):
-   

+ 40 - 0
software/wirelessLoadCell/GSV4BT.py

@@ -0,0 +1,40 @@
+import sys
+import bluetooth
+
+class GSV4BT():
+  def __init__(self, addr):
+    self.addr = addr
+    self.uuid = None
+    self.sock = None
+
+  def connect(self):
+    if self.sock:
+      return True
+
+    service_matches = bluetooth.find_service(address=self.addr)
+    if len(service_matches) == 0:
+      print("BT device {} not found.".format(self.addr))
+      return False
+    
+    first_match = service_matches[0]
+    self.uuid = first_match["uuid"]
+    self.port = first_match["port"]
+    self.name = first_match["name"]
+    self.host = first_match["host"]
+
+    print("Connecting to \"{}\" on {}".format(self.name, self.host))
+
+    self.sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
+    return self.sock.connect((self.host, self.port))
+  
+  def sendRaw(self, data):
+    self.sock.send(data)
+
+  def recvRaw(self):
+    return self.sock.recv(1024)
+
+  def getForces(self):
+    return (0, 0, 0)
+
+  def close(self):
+    self.sock.close()

+ 41 - 0
software/wirelessLoadCell/loadCells.py

@@ -0,0 +1,41 @@
+from GSV4BT import GSV4BT
+import time
+import bluetooth
+
+class LoadCells():
+  def __init__(self):
+    self.cells = (
+      GSV4BT("addr1"),
+      GSV4BT("addr2"),
+      GSV4BT("addr3"),
+    )
+  
+  def connect(self):
+    success = True
+    for cell in self.cells:
+      if not cell.connect():
+        success = False
+    return success
+
+  def getForces(self):
+    return (
+      self.cells[0].getForces(),
+      self.cells[1].getForces(),
+      self.cells[2].getForces()
+    )
+
+
+if __name__ == "__main__":
+  cells = LoadCells()
+
+  while True:
+    nearby_devices = bluetooth.discover_devices(lookup_names=True)
+    print("Found {} devices.".format(len(nearby_devices)))
+
+    for addr, name in nearby_devices:
+      print("  {} - {}".format(addr, name))
+
+    cells.connect()
+    print(cells.getForces())
+    cells.scan()
+    time.sleep(1)