def _tick(self): if self._state == 0: newDevs = Meta.listSerials() - self._devices if newDevs: # XXXTODO: support multiple devices ? Would be hard since they disappear after a few seconds... self._devname = newDevs.pop() self.setSubTitle( _('Found Leonardo at {path}.').format(path=self._devname)) self._state = 1 if self._state == 1: # Reset error = None for unused in range(5): try: with serial.Serial(self._devname, 2000): pass except serial.SerialException as exc: error = exc time.sleep(0.5) # Retry else: break else: self.setSubTitle( _('Error resetting the device: {error}').format( error=str(error))) self._finished = True self._timer.stop() self.completeChanged.emit() return self._state = 2 if self._state == 2: self._state = 3 self._timer.stop() self._launchUpdate()
def initializePage(self): self.setTitle(_('Looking for Leonardo')) self.setSubTitle(_('Release the <b>reset</b> button now.')) self._state = 0 self._finished = False self._devices = Meta.listSerials() self._devname = None self._process = None self._timer.start(200)