def readNode (self, node): """ Reads all queued events from the given node (file descriptor), and sends them for processing. Returns a list of event objects for the received inputs. """ partials = self._partialReadData data = partials[node] eventSize = self.Event.size events = [] bytesToRead = eventSize - len(data) while bytesToRead: try: data = data + os.read(node, bytesToRead) except OSError: # Nothing to read, probably pass if len(data) < eventSize: partials[node] = data bytesToRead = 0 else: event = self.Event(data) if self.receive (event): events.append(event) bytesToRead = eventSize data = '' return events
def readNode(self, node): """ Reads all queued events from the given node (file descriptor), and sends them for processing. Returns a list of event objects for the received inputs. """ partials = self._partialReadData data = partials[node] eventSize = self.Event.size events = [] bytesToRead = eventSize - len(data) while bytesToRead: try: data = data + node.read(bytesToRead) except OSError: # Nothing to read, probably pass if len(data) < eventSize: partials[node] = data bytesToRead = 0 else: event = self.Event(data) if self.receive(event): events.append(event) bytesToRead = eventSize data = '' return events
def read(self, node=None): """ Check device node/s for any new input. Uses either the passed-in node, or the object's list of relevant nodes if none is given. Returns a list of event objects for the received inputs. """ if node is not None: # Only need to return the given event return self.readNode(node) events = [] for node in self._nodes: events.append(self.readNode(node)) return events
def read (self, node=None): """ Check device node/s for any new input. Uses either the passed-in node, or the object's list of relevant nodes if none is given. Returns a list of event objects for the received inputs. """ if node is not None: # Only need to return the given event return self.readNode(node) events = [] for node in self._nodes: events.append(self.readNode(node)) return events
def _relayCombo(self, combo, value=0, target=None): """ Relays all the events in the given combo to another device, either the passed-in target parameter or the output object specified on init. If delay is set, the events will be delayed by that many *milli*seconds. """ if target is None: target = self._outputNode # Check for, and then remove, any delays in the combo # Only the last delay is used, # though we could make it cumulative. delay = 0 newCombo = tuple() for index in xrange(0, len(combo)): key = combo[index] if isinstance(key, (int, long)): delay = key / 1000.0 else: newCombo += (key, ) combo = newCombo # Send out all the keys in the combo events = [] for key in combo: evType, evCode = getattr(const, str(key), (None, None)) if not evType: continue ## Dirty hack alert! # Skip 0-valued EV_RELs (they do nothing anyway) if evType == const.EV_REL and value == 0: continue timestamp = time.time() + delay event = self.Event(type=evType, code=evCode, value=value, timestamp=timestamp) target.receive(event) events.append(event) return events
def _relayCombo(self, combo, value=0): """ Relays all the events in the given combo to whichever device is destined to process them (either an output node, or one of this object's own nodes for feedback events). If delay is set, the events will be delayed by that many *milli*seconds. """ # Check for, and then remove, any delays in the combo # Only the last delay is used, # though we could make it cumulative. delay = 0 newCombo = tuple() for index in xrange(0, len(combo)): key = combo[index] if isinstance(key, (int, long)): delay = key / 1000.0 else: newCombo += (key, ) combo = newCombo # Send out all the keys in the combo events = [] for key in combo: evType, evCode = getattr(const, str(key), (None, None)) if not evType: continue if key.min is not None and key.max == key.min: # Use the value from the key if we can keyValue = key.min else: keyValue = value timestamp = time.time() + delay event = self.Event(type=evType, code=evCode, value=keyValue, timestamp=timestamp) self._relayEvent(event) events.append(event) return events
def _relayCombo (self, combo, value=0, target=None): """ Relays all the events in the given combo to another device, either the passed-in target parameter or the output object specified on init. If delay is set, the events will be delayed by that many *milli*seconds. """ if target is None: target = self._outputNode # Check for, and then remove, any delays in the combo # Only the last delay is used, # though we could make it cumulative. delay = 0 newCombo = tuple() for index in xrange(0, len(combo)): key = combo[index] if isinstance(key, (int, long)): delay = key / 1000.0 else: newCombo += (key,) combo = newCombo # Send out all the keys in the combo events = [] for key in combo: evType, evCode = getattr(const, str(key), (None, None)) if not evType: continue ## Dirty hack alert! # Skip 0-valued EV_RELs (they do nothing anyway) if evType == const.EV_REL and value == 0: continue timestamp = time.time() + delay event = self.Event(type=evType, code=evCode, value=value, timestamp=timestamp) target.receive(event) events.append(event) return events
def _relayCombo (self, combo, value=0): """ Relays all the events in the given combo to whichever device is destined to process them (either an output node, or one of this object's own nodes for feedback events). If delay is set, the events will be delayed by that many *milli*seconds. """ # Check for, and then remove, any delays in the combo # Only the last delay is used, # though we could make it cumulative. delay = 0 newCombo = tuple() for index in xrange(0, len(combo)): key = combo[index] if isinstance(key, (int, long)): delay = key / 1000.0 else: newCombo += (key,) combo = newCombo # Send out all the keys in the combo events = [] for key in combo: evType, evCode = getattr(const, str(key), (None, None)) if not evType: continue if key.min is not None and key.max == key.min: # Use the value from the key if we can keyValue = key.min else: keyValue = value timestamp = time.time() + delay event = self.Event(type=evType, code=evCode, value=keyValue, timestamp=timestamp) self._relayEvent(event) events.append(event) return events