From d3c6012abe3b59ba88c8c83b2ffcb467b472f00d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 7 Apr 2010 23:51:42 +0200 Subject: digital/io, host/simu: add position report tool --- digital/io/tools/io/mex.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'digital/io/tools/io/mex.py') diff --git a/digital/io/tools/io/mex.py b/digital/io/tools/io/mex.py index 8f951f91..16c8eef6 100644 --- a/digital/io/tools/io/mex.py +++ b/digital/io/tools/io/mex.py @@ -33,6 +33,7 @@ ID_ADC = 0xb3 ID_PATH = 0xb4 ID_PWM = 0xb5 ID_CONTACT = 0xb6 +ID_POS_REPORT = 0xb7 SERVO_NB = 6 SERVO_VALUE_MAX = 255 @@ -198,6 +199,27 @@ class Mex: m.push ('B', self.contacts) self.node.send (m) + class PosReport (Observable): + """General purpose position report. + + - pos: dict of sequence of (x, y) coordinates (millimeters). The dict + is indexed by position identifier. + + """ + + def __init__ (self, node): + Observable.__init__ (self) + self.pos = { } + node.register (ID_POS_REPORT, self.__handle) + + def __handle (self, msg): + p = [ ] + id, = msg.pop ('b') + while len (msg) >= 4: + p.append (msg.pop ('hh')) + self.pos[id] = p + self.notify () + def __init__ (self, node): self.jack = self.Switch (node, ID_JACK) self.color_switch = self.Switch (node, ID_COLOR) @@ -211,4 +233,5 @@ class Mex: self.__contact_pack = self.Contact.Pack (node) self.contact = tuple (self.Contact (self.__contact_pack, i) for i in range (CONTACT_NB)) + self.pos_report = self.PosReport (node) -- cgit v1.2.3