def __init__(self, window): MetaProtocolParser.__init__(self) self.window = window self.logger = logging.getLogger('parser') self.vibrate = threading.Event() self.active_timeout = None if 0: # Wing IDE type hints import metasimulator isinstance(self.window, metasimulator.MainFrame)
def handle_disableButton(self, *args, **kwargs): button_config = MetaProtocolParser.handle_disableButton(self, *args, **kwargs) if button_config in self.button_mapping: self.button_mapping.pop(button_config) self.update_button_colors() self.logger.info("Button mapping %r removed", [button_config]) else: self.logger.debug("Button mapping %r does not exist", [button_config])
def handle_disableButton(self, *args, **kwargs): button_config = MetaProtocolParser.handle_disableButton( self, *args, **kwargs) if button_config in self.button_mapping: self.button_mapping.pop(button_config) self.update_button_colors() self.logger.info("Button mapping %r removed", [button_config]) else: self.logger.debug("Button mapping %r does not exist", [button_config])
def handle_setLED(self, *args, **kwargs): state = MetaProtocolParser.handle_setLED(self, *args, **kwargs) if state: self.window.m_LEDNotice.Show() # Hardcoded, what does a real watch do? wx.CallLater(const.LED_TIMEOUT, self.window.m_LEDNotice.Hide) else: self.window.m_LEDNotice.Hide() self.logger.info("Changed LED state to %d", state)
def handle_setVibrate(self, *args, **kwargs): action, on_time, off_time, cycles = \ MetaProtocolParser.handle_setVibrate(self, *args, **kwargs) if action: self.vibrate.set() self.logger.info("Vibrate %d times for %d/%d msecs" % (cycles, on_time, off_time)) self._vibrateTimer(cycles + 2, on_time, off_time, 1) else: self.window.m_vibrateNotice.Hide() self.vibrate.clear()
def handle_setVibrate(self, *args, **kwargs): action, on_time, off_time, cycles = \ MetaProtocolParser.handle_setVibrate(self, *args, **kwargs) if action: self.vibrate.set() self.logger.info("Vibrate %d times for %d/%d msecs" % (cycles, on_time, off_time)) self._vibrateTimer(cycles+2, on_time, off_time, 1) else: self.window.m_vibrateNotice.Hide() self.vibrate.clear()
def handle_setRTC(self, *args, **kwargs): date, hrs12, dayFirst = \ MetaProtocolParser.handle_setRTC(self, *args, **kwargs) self.window.clock_offset = relativedelta(date, datetime.now()) if hrs12 != NotImplemented: # Inofficial protocol extension, see protocol parser self.window.nval_store['nval_2009'] = int(not hrs12) self.window.nval_store['nval_200A'] = int(dayFirst) self.logger.info("RTC time set (offset %d secs)", self.window.clock_offset.seconds) # Update live clock self.window.OnClock()
def handle_enableButton(self, *args, **kwargs): mode, btn_id, btn_type, cb, cb_data = \ MetaProtocolParser.handle_enableButton(self, *args, **kwargs) req_hash = (mode, btn_id, btn_type) if req_hash in self.button_mapping: self.logger.info("Re-registered %s", self._button_hash_repr(req_hash)) else: self.logger.info("Registered %s", self._button_hash_repr(req_hash)) data = self._init_option_bits(True) data.fromstring(chr(cb_data)) self.button_mapping[req_hash] = (cb, data) self.update_button_colors()
def handle_writeLCD(self, *args, **kwargs): mode, two_lines, line1, line2, index = \ MetaProtocolParser.handle_writeLCD(self, *args, **kwargs) lines = (line1, line2) if two_lines else (line1, ) # TODO: pass entire row to numpy for i, line1 in enumerate(lines): for n, byte in enumerate(line1.unpack(zero='\xff', one='\x00')): self.display_buffers[mode][index[i]][n] = ord(byte) # This will refresh the current view 'live' as data arrives, # not sure if the real watch does this as well. if (mode == self.active_buffer) and self.window.m_liveView.Value: self.refresh_bitmap(mode)
def handle_updateLCD(self, *args, **kwargs): mode = MetaProtocolParser.handle_updateLCD(self, *args, **kwargs) self.logger.info("Active buffer set to [%d] %s", mode, self.window.m_watchMode.GetItemLabel(mode)) if mode > 0: timeout = 'nval_0005' if mode == 1 else 'nval_0006' if self.active_timeout: self.active_timeout.Stop() self.active_timeout = wx.CallLater( self.window.nval_store[timeout] * 1000, self._reset_mode, 0) # TODO: correct buffer reset # TODO: interaction between timer and 'Manual mode' checkbox self.active_buffer = mode
def handle_updateLCD(self, *args, **kwargs): mode = MetaProtocolParser.handle_updateLCD(self, *args, **kwargs) self.logger.info("Active buffer set to [%d] %s", mode, self.window.m_watchMode.GetItemLabel(mode)) if mode > 0: timeout = 'nval_0005' if mode == 1 else 'nval_0006' if self.active_timeout: self.active_timeout.Stop() self.active_timeout = wx.CallLater(self.window.nval_store[timeout]*1000, self._reset_mode, 0) # TODO: correct buffer reset # TODO: interaction between timer and 'Manual mode' checkbox self.active_buffer = mode