summaryrefslogtreecommitdiff
path: root/digital/io/tools/io/io.py
diff options
context:
space:
mode:
authorNicolas Schodet2010-04-13 00:22:14 +0200
committerNicolas Schodet2010-04-13 00:22:14 +0200
commit04749eb8e89617ffeb616ac3bbc4f9f7219504de (patch)
treef601b8a9954b620c15b31989ac1ea13633f21998 /digital/io/tools/io/io.py
parentd91aa09bc6744ae8181b8507162c0c0ba94b2f93 (diff)
digital/io/tools: add distance sensor dump tool
Diffstat (limited to 'digital/io/tools/io/io.py')
-rw-r--r--digital/io/tools/io/io.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/digital/io/tools/io/io.py b/digital/io/tools/io/io.py
index ffd1e2e5..a98f0c9e 100644
--- a/digital/io/tools/io/io.py
+++ b/digital/io/tools/io/io.py
@@ -30,6 +30,7 @@ class Proto:
self.async = False
self.param = param
self.send_param ()
+ self.proto.register ('U', 'HHHH', self.__handle_usdist)
def send_param (self):
p = self.param
@@ -42,8 +43,6 @@ class Proto:
self.proto.wait (lambda: True)
def reset (self):
- self.proto.send ('w')
- self.proto.send ('w', 'H', 0)
self.proto.send ('z')
self.proto.send ('z')
@@ -56,9 +55,24 @@ class Proto:
def pwm_set (self, value, timer):
self.proto.send ('w', 'Hh', value, timer)
+ def stats_usdist (self, cb):
+ self.proto.send ('U', 'B', 2 * 4 * 2)
+ self.usdist_cb = cb
+ while True:
+ self.proto.wait ()
+
+ def __handle_usdist (self, *val):
+ l = [ ]
+ for v in val:
+ if v == 0xffff:
+ l.append (None)
+ else:
+ l.append (v)
+ self.usdist_cb (*l)
+
def close (self):
self.reset ()
- self.wait (lambda: True)
+ self.proto.wait (lambda: True)
self.proto.file.close ()
def fileno (self):