From 04749eb8e89617ffeb616ac3bbc4f9f7219504de Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 13 Apr 2010 00:22:14 +0200 Subject: digital/io/tools: add distance sensor dump tool --- digital/io/tools/io/io.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'digital/io/tools/io/io.py') 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): -- cgit v1.2.3