def _handle(self, kind, size, body): if not (kind or size or body): return message = protocol.parse_body(kind, size, body) if not message: print('WARNING: jsonwire parse_body() produced NOTHING!') return message.wire = self self.out_queue.put(message)
def _handle(self, kind, size, body): if not (kind or size or body): # if we wake up for any non-exceptional reason and there is a # tactile event in escrow, check if it has expired and if so # send its negative version as a signal that the key has been # released. this isn't completely fool proof, because the event # can be overwritten by one for another key before it expires. # i.e. first press '1' for a while and then quickly change to # pressing '2'. not sure if this is really a problem. if self.escrow and self.escrow[1] < datetime.now(): code = -self.escrow[0].code stress = self.escrow[0].stress self.out_queue.put(protocol.Tactile(code, stress)) self.escrow = None return '' message = protocol.parse_body(kind, size, body) if not message: print('WARNING: slimwire parse_body() produced NOTHING!') return if isinstance(message, protocol.Ureq): print 'Ureq' self.state = STARTING # must set this before sending UPDN to the # device or race conditions come crashing in. time.sleep(1.0) self._send(Updn().serialize(), force=True) elif isinstance(message, protocol.Tactile): if message.code in [IR.FORWARD, IR.REWIND, IR.POWER]: timeout = datetime.now() + timedelta(milliseconds=300) self.escrow = (message, timeout) if message.stress < 5: # don't post an event since we can't tell # yet if the user wants a tap or a long press. return self.out_queue.put(message) else: self.out_queue.put(message)