diff options
Diffstat (limited to 'pybot/drivers/hotplug')
-rw-r--r-- | pybot/drivers/hotplug/button.py | 25 | ||||
-rw-r--r-- | pybot/drivers/hotplug/distanc.py | 21 | ||||
-rw-r--r-- | pybot/drivers/hotplug/grey.py | 21 | ||||
-rw-r--r-- | pybot/drivers/hotplug/led.py | 22 | ||||
-rw-r--r-- | pybot/drivers/hotplug/light.py | 24 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modActA.py | 15 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modActB.py | 15 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modActC.py | 15 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modSenA.py | 14 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modSenB.py | 14 | ||||
-rw-r--r-- | pybot/drivers/hotplug/modSenC.py | 14 | ||||
-rw-r--r-- | pybot/drivers/hotplug/res.py | 24 | ||||
-rw-r--r-- | pybot/drivers/hotplug/temp.py | 19 | ||||
-rw-r--r-- | pybot/drivers/hotplug/volt.py | 26 |
14 files changed, 178 insertions, 91 deletions
diff --git a/pybot/drivers/hotplug/button.py b/pybot/drivers/hotplug/button.py index f714ecf..4bf99ee 100644 --- a/pybot/drivers/hotplug/button.py +++ b/pybot/drivers/hotplug/button.py @@ -1,19 +1,18 @@ RD_VERSION = 0x00 GET_VALUE = 0x01 +ERROR = -1 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 2 -} +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(2) + if not(raw[1] == 255): + return (1 - raw[1]) + else: + return ERROR -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/distanc.py b/pybot/drivers/hotplug/distanc.py index db7e1c1..6148171 100644 --- a/pybot/drivers/hotplug/distanc.py +++ b/pybot/drivers/hotplug/distanc.py @@ -2,18 +2,13 @@ RD_VERSION = 0x00 GET_VALUE = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 3 -} +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/grey.py b/pybot/drivers/hotplug/grey.py index db7e1c1..6148171 100644 --- a/pybot/drivers/hotplug/grey.py +++ b/pybot/drivers/hotplug/grey.py @@ -2,18 +2,13 @@ RD_VERSION = 0x00 GET_VALUE = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 3 -} +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/led.py b/pybot/drivers/hotplug/led.py index 0703d54..fde6b3e 100644 --- a/pybot/drivers/hotplug/led.py +++ b/pybot/drivers/hotplug/led.py @@ -2,18 +2,14 @@ RD_VERSION = 0x00 TURN = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -f2 = { - 'name': 'turn', - 'call': TURN, - 'params': 1, - 'read': 1 -} +def turn(dev, on): + msg = [TURN, on] + dev.send(msg) + raw = dev.read(1) + return raw[0] -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/light.py b/pybot/drivers/hotplug/light.py index db7e1c1..dbcb71a 100644 --- a/pybot/drivers/hotplug/light.py +++ b/pybot/drivers/hotplug/light.py @@ -2,18 +2,16 @@ RD_VERSION = 0x00 GET_VALUE = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +VCC = 65536 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + val = raw[1] + raw[2] * 256 + return (VCC - val) -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/modActA.py b/pybot/drivers/hotplug/modActA.py new file mode 100644 index 0000000..fde6b3e --- /dev/null +++ b/pybot/drivers/hotplug/modActA.py @@ -0,0 +1,15 @@ + +RD_VERSION = 0x00 +TURN = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def turn(dev, on): + msg = [TURN, on] + dev.send(msg) + raw = dev.read(1) + return raw[0] + diff --git a/pybot/drivers/hotplug/modActB.py b/pybot/drivers/hotplug/modActB.py new file mode 100644 index 0000000..fde6b3e --- /dev/null +++ b/pybot/drivers/hotplug/modActB.py @@ -0,0 +1,15 @@ + +RD_VERSION = 0x00 +TURN = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def turn(dev, on): + msg = [TURN, on] + dev.send(msg) + raw = dev.read(1) + return raw[0] + diff --git a/pybot/drivers/hotplug/modActC.py b/pybot/drivers/hotplug/modActC.py new file mode 100644 index 0000000..fde6b3e --- /dev/null +++ b/pybot/drivers/hotplug/modActC.py @@ -0,0 +1,15 @@ + +RD_VERSION = 0x00 +TURN = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def turn(dev, on): + msg = [TURN, on] + dev.send(msg) + raw = dev.read(1) + return raw[0] + diff --git a/pybot/drivers/hotplug/modSenA.py b/pybot/drivers/hotplug/modSenA.py new file mode 100644 index 0000000..6148171 --- /dev/null +++ b/pybot/drivers/hotplug/modSenA.py @@ -0,0 +1,14 @@ + +RD_VERSION = 0x00 +GET_VALUE = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + diff --git a/pybot/drivers/hotplug/modSenB.py b/pybot/drivers/hotplug/modSenB.py new file mode 100644 index 0000000..6148171 --- /dev/null +++ b/pybot/drivers/hotplug/modSenB.py @@ -0,0 +1,14 @@ + +RD_VERSION = 0x00 +GET_VALUE = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + diff --git a/pybot/drivers/hotplug/modSenC.py b/pybot/drivers/hotplug/modSenC.py new file mode 100644 index 0000000..6148171 --- /dev/null +++ b/pybot/drivers/hotplug/modSenC.py @@ -0,0 +1,14 @@ + +RD_VERSION = 0x00 +GET_VALUE = 0x01 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + diff --git a/pybot/drivers/hotplug/res.py b/pybot/drivers/hotplug/res.py index db7e1c1..0dc43a9 100644 --- a/pybot/drivers/hotplug/res.py +++ b/pybot/drivers/hotplug/res.py @@ -2,18 +2,16 @@ RD_VERSION = 0x00 GET_VALUE = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +VCC = 65536 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 3 -} +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + val = raw[1] + raw[2] * 256 + return val * 6800.0 / (VCC - val) -FUNCTIONS = [f1, f2] diff --git a/pybot/drivers/hotplug/temp.py b/pybot/drivers/hotplug/temp.py new file mode 100644 index 0000000..7fa55a1 --- /dev/null +++ b/pybot/drivers/hotplug/temp.py @@ -0,0 +1,19 @@ + +import math + +RD_VERSION = 0x00 +GET_VALUE = 0x01 + +VCC = 65536 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 + +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + volt = (raw[1] + raw[2] * 256) * 5.0 / VCC + return math.floor(volt * 1000.0) / 10 + diff --git a/pybot/drivers/hotplug/volt.py b/pybot/drivers/hotplug/volt.py index db7e1c1..10866a6 100644 --- a/pybot/drivers/hotplug/volt.py +++ b/pybot/drivers/hotplug/volt.py @@ -1,19 +1,19 @@ +import math + RD_VERSION = 0x00 GET_VALUE = 0x01 -f1 = { - 'name': 'getVersion', - 'call': RD_VERSION, - 'params': 0, - 'read': 3 -} +VCC = 65536 + +def getVersion(dev): + dev.send([RD_VERSION]) + raw = dev.read(3) + return raw[1] + raw[2] * 256 -f2 = { - 'name': 'getValue', - 'call': GET_VALUE, - 'params': 0, - 'read': 3 -} +def getValue(dev): + dev.send([GET_VALUE]) + raw = dev.read(3) + volt = (raw[1] + raw[2] * 256) * 5.0 / VCC + return math.floor(volt * 1000.0) / 1000 -FUNCTIONS = [f1, f2] |