From: Jeff E. <cv...@cv...> - 2007-02-27 01:42:51
|
Modified file emc2/src/hal/user_comps/hal_input.py Full file: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/user_comps/hal_input.py?rev=1.6> Difference: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/user_comps/hal_input.py.diff?r1=1.5;r2=1.6> Branch: TRUNK Log: revision 1.6 date: 2007/02/27 01:42:48; author: jepler; state: Exp; lines: +86 -32 make hal_input's items act more like the HAL canonical interfaces they resemble --- hal_input.py 2007/02/26 03:47:01 1.5 +++ hal_input.py 2007/02/27 01:42:48 1.6 @@ -18,90 +18,144 @@ def tohalname(s): return str(s).lower().replace("_", "-") +class HalWrapper: + def __init__(self, comp): + self._comp = comp + self._drive = {} + self._pins = set() + self._params = set() + + def drive(self): + for k, v in self._drive.items(): setattr(self._comp, k, v) + + def newpin(self, *args): + self._pins.add(args[0]) + return self._comp.newpin(*args) + def newparam(self, *args): + print args[0] + self._params.add(args[0]) + return self._comp.newparam(*args) + + def __getitem__(self, k): + if k in self._drive: return self._drive[k] + return self._comp[k] + + def __setitem__(self, k, v): + if k in self._params: + self._comp[k] = v; return + if k not in self._pins: raise KeyError, k + self._drive[k] = v + class HalInputDevice: def __init__(self, comp, idx, name): self.device = linux_event.InputDevice(name) self.idx = idx - self.drive = {} - self.abs = {} + self.codes = set() self.last = {} self.rel_items = [] self.comp = comp for key in self.device.get_bits('EV_KEY'): key = tohalname(key) + self.codes.add(key) comp.newpin("%s.%s" % (idx, key), hal.HAL_BIT, hal.HAL_OUT) - self.drive[key] = 0 + comp.newpin("%s.%s-not" % (idx, key), hal.HAL_BIT, hal.HAL_OUT) + self.set(key + "-not", 1) for axis in self.device.get_bits('EV_REL'): name = tohalname(axis) - comp.newpin("%s.%s" % (idx, name), hal.HAL_FLOAT, hal.HAL_OUT) + self.codes.add(name) + comp.newpin("%s.%s-position" % (idx, name), hal.HAL_FLOAT, hal.HAL_OUT) + comp.newpin("%s.%s-counts" % (idx, name), hal.HAL_S32, hal.HAL_OUT) comp.newpin("%s.%s-reset" % (idx, name), hal.HAL_BIT, hal.HAL_IN) + comp.newparam("%s.%s-position-scale" % (idx, name), hal.HAL_FLOAT, hal.HAL_RW) + self.set(name + '-position-scale', 1.) self.rel_items.append(name) - self.drive[name] = 0 for axis in self.device.get_bits('EV_ABS'): name = tohalname(axis) - self.abs[name] = self.device.get_absinfo(axis) - comp.newpin("%s.%s" % (idx, name), hal.HAL_FLOAT, hal.HAL_OUT) - self.drive[name] = 0 + self.codes.add(name) + absinfo = self.device.get_absinfo(axis) + comp.newpin("%s.%s-position" % (idx, name), hal.HAL_FLOAT, hal.HAL_OUT) + comp.newpin("%s.%s-counts" % (idx, name), hal.HAL_S32, hal.HAL_OUT) + comp.newparam("%s.%s-position-scale" % (idx, name), hal.HAL_FLOAT, hal.HAL_RW) + comp.newparam("%s.%s-fuzz" % (idx, name), hal.HAL_FLOAT, hal.HAL_RW) + comp.newparam("%s.%s-flat" % (idx, name), hal.HAL_FLOAT, hal.HAL_RW) + self.set(name + "-position-scale", float(max(-absinfo.minimum, absinfo.maximum))) + self.set(name + "-fuzz", absinfo.fuzz) + self.set(name + "-flat", absinfo.flat) + self.ledmap = {} for led in self.device.get_bits('EV_LED'): name = tohalname(led) + self.ledmap[name] = led comp.newpin("%s.%s" % (idx, name), hal.HAL_BIT, hal.HAL_IN) + comp.newparam("%s.%s-invert" % (idx, name), hal.HAL_BIT, hal.HAL_RW) self.last[name] = 0 self.device.write_event('EV_LED', led, 0) + def get(self, name): + name = "%s.%s" % (self.idx, name) + return self.comp[name] + + def set(self, name, value): + name = "%s.%s" % (self.idx, name) |