def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.isRunning = True self.setWindowTitle('Linkbot Firmware Programmer') self.linkbotDetectedSignal.connect(self.startProgramming) # Try and find the latest firmware file self.hexfiles = glob.glob( os.environ['HOME'] + '/.local/share/Barobo/LinkbotLabs/firmware/*.hex') self.hexfiles += glob.glob( '/usr/share/Barobo/LinkbotLabs/firmware/*.hex') #self.hexfiles += [fallback_hex_file] def _form_abs_path(filename): return resource_filename(__name__, os.path.join('hexfiles', filename) ) abs_firmware_files = map(_form_abs_path, firmware_files) self.hexfiles += abs_firmware_files def sortkey(x): basename = os.path.basename(x) m = re.search(r'v(\d+).(\d+).(\d+).hex', basename) if m is None: print(basename) m = re.search(r'v(\d+).(\d+).(\d+).(\d+).hex', basename) try: tweak = int(m.group(4)) except: tweak = 0 try: major = int(m.group(1)) minor = int(m.group(2)) patch = int(m.group(3)) return (major, minor, patch, tweak) except: return (0,0,0,0) self.hexfiles = reversed(sorted(self.hexfiles, key=sortkey)) for h in self.hexfiles: self.ui.comboBox_filename.addItem(h) try: self._daemon = linkbot3.Daemon() except: self._daemon = None
class StartQT4(QtGui.QDialog): linkbotDetectedSignal = QtCore.pyqtSignal(str) def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.isRunning = True self.setWindowTitle('Linkbot Firmware Programmer') self.linkbotDetectedSignal.connect(self.startProgramming) # Try and find the latest firmware file self.hexfiles = glob.glob( os.environ['HOME'] + '/.local/share/Barobo/LinkbotLabs/firmware/*.hex') self.hexfiles += glob.glob( '/usr/share/Barobo/LinkbotLabs/firmware/*.hex') #self.hexfiles += [fallback_hex_file] def _form_abs_path(filename): return resource_filename(__name__, os.path.join('hexfiles', filename) ) abs_firmware_files = map(_form_abs_path, firmware_files) self.hexfiles += abs_firmware_files def sortkey(x): basename = os.path.basename(x) m = re.search(r'v(\d+).(\d+).(\d+).hex', basename) if m is None: print(basename) m = re.search(r'v(\d+).(\d+).(\d+).(\d+).hex', basename) try: tweak = int(m.group(4)) except: tweak = 0 try: major = int(m.group(1)) minor = int(m.group(2)) patch = int(m.group(3)) return (major, minor, patch, tweak) except: return (0,0,0,0) self.hexfiles = reversed(sorted(self.hexfiles, key=sortkey)) for h in self.hexfiles: self.ui.comboBox_filename.addItem(h) try: self._daemon = linkbot3.Daemon() except: self._daemon = None def accept(self): self.waiting_overlay.show() #QtCore.QCoreApplication.instance().quit() self.startProgramming('/dev/null') def reject(self): self.isRunning = False QtCore.QCoreApplication.instance().quit() def distractBaromeshThread(self): while self.isRunning: if self._daemon: self._daemon.cycle(2) time.sleep(1) else: return def listenerThread(self): prevDevices = glob.glob('/dev/ttyACM*') while self.isRunning: devices = glob.glob('/dev/ttyACM*') if len(devices) > len(prevDevices): time.sleep(1.5) #self.startProgramming((set(devices)-set(prevDevices)).pop()) self.linkbotDetectedSignal.emit((set(devices)-set(prevDevices)).pop()) prevDevices = devices time.sleep(0.5) def startProgramming(self, serialPortPath): try: hexfile = self.ui.comboBox_filename.currentText() self.ui.label.setText(programming_text) self.ui.buttonBox.setEnabled(False) self.programmer = LinkbotProgrammer(serialPortPath) self.programmer.loadFlashHexFile(hexfile) try: basename,_ = os.path.splitext(hexfile) eepromFile = basename + '.eeprom' self.programmer.loadEepromHexFile(eepromFile) except OSError: pass # Don't worry if we can't find this file self.programmer.loadProgramAsync() self.updateProgressTimer = QtCore.QTimer(self) self.updateProgressTimer.timeout.connect(self.updateProgress) self.updateProgressTimer.start(500) except Exception as e: print(e) def updateProgress(self): if not self.programmer.isProgramming(): self.ui.label.setText(instructions_text) self.ui.buttonBox.setEnabled(True) self.updateProgressTimer.stop() self.ui.progressBar.setValue(self.programmer.getProgress()*100)