def __init__(self, av_loop, name): AV_SerialDevice.__init__(self, av_loop, name) self.input_handler = None for subcmd in self.Commands: self.av_loop.add_cmd_handler("%s %s" % (self.name, subcmd), self.handle_cmd)
def __init__(self, av_loop, name): AV_SerialDevice.__init__(self, av_loop, name) self.input_handler = None for subcmd in self.Commands: self.av_loop.add_cmd_handler( "%s %s" % (self.name, subcmd), self.handle_cmd)
def __init__(self, av_loop, name): AV_SerialDevice.__init__(self, av_loop, name) for subcmd in self.Commands: self.av_loop.add_cmd_handler("%s %s" % (self.name, subcmd), self.handle_cmd) self.status_handler = None self.readbuf = bytes() # Don't start writing until a status update is received. self.write_ready = False # Write enabling needs to be delayed. See ready_to_write() self.write_timer = None # or (timeout_handle, deadline) self.state = AVR_State(self.name, self.av_loop)
def __init__(self, av_loop, name): AV_SerialDevice.__init__(self, av_loop, name) for subcmd in self.Commands: self.av_loop.add_cmd_handler( "%s %s" % (self.name, subcmd), self.handle_cmd) self.status_handler = None self.readbuf = bytes() # Don't start writing until a status update is received. self.write_ready = False # Write enabling needs to be delayed. See ready_to_write() self.write_timer = None # or (timeout_handle, deadline) self.state = AVR_State(self.name, self.av_loop)
def ready_to_write(self, assign=None): if assign is None: if self.state.off: return False return AV_SerialDevice.ready_to_write(self) # assign == False indicates that we've just written to the AVR. # In that case, we should nominally delay the next write for # about a second. # # assign == True indicates that we've just received an updated # status from the AVR. In that case, we can reduce the # remaining time-to-next-write down to about a quarter second # (value determined by unscientific experiments). deadline = time.time() + (assign and 0.25 or 1.0) if assign is False: # Disable writes for 1.0s self.write_ready = False # Disable writes immediately self._setup_write_timer(deadline) elif assign is True: # Shorten write_timeout if self.write_timer and deadline > self.write_timer[1]: pass # Keep current timer elif self.write_timer or not self.write_ready: # Shorten existing timer or setup new timer self._setup_write_timer(deadline)
def ready_to_write(self, assign=None): if assign is None: if self.state.off: return False return AV_SerialDevice.ready_to_write(self) # assign == False indicates that we've just written to the AVR. # In that case, we should nominally delay the next write for # about a second. # # assign == True indicates that we've just received an updated # status from the AVR. In that case, we can reduce the # remaining time-to-next-write down to about a quarter second # (value determined by unscientific experiments). deadline = time.time() + (assign and 0.25 or 1.0) if assign is False: # Disable writes for 1.0s self.write_ready = False # Disable writes immediately self._setup_write_timer(deadline) elif assign is True: # Shorten write_timeout if self.write_timer and deadline > self.write_timer[1]: pass # Keep current timer elif self.write_timer or not self.write_ready: # Shorten existing timer or setup new timer self._setup_write_timer(deadline)
def _delayed_ready(self): self.write_timer = None AV_SerialDevice.ready_to_write(self, True)
def _delayed_ready(self): self.write_timer = None AV_SerialDevice.ready_to_write(self, True)