diff -r b356d92d4e02 -r 76375aa6bc04 eric6/MicroPython/MicrobitDevices.py --- a/eric6/MicroPython/MicrobitDevices.py Sat Jan 30 12:05:36 2021 +0100 +++ b/eric6/MicroPython/MicrobitDevices.py Sat Jan 30 19:11:02 2021 +0100 @@ -174,9 +174,12 @@ """ connected = self.microPython.isConnected() - act = menu.addAction(self.tr("Flash MicroPython Firmware"), + act = menu.addAction(self.tr("Flash MicroPython"), self.__flashMicroPython) act.setEnabled(not connected) + act = menu.addAction(self.tr("Flash Firmware"), + lambda: self.__flashMicroPython(firmware=True)) + act.setEnabled(not connected) menu.addSeparator() act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice) act.setToolTip(self.tr( @@ -193,44 +196,66 @@ act.setEnabled(connected) @pyqtSlot() - def __flashMicroPython(self): - """ - Private slot to flash the default MicroPython firmware to the device. + def __flashMicroPython(self, firmware=False): """ - # Attempts to find the path on the filesystem that represents the - # plugged in micro:bit board in maintenance mode or Calliope mini - # board in standard mode. + Private slot to flash MicroPython or the DAPLink firmware to the + device. + + @param firmware flag indicating to flash the DAPLink firmware + @type bool + """ + # Attempts to find the path on the file system that represents the + # plugged in micro:bit board. To flash the DAPLink firmware, it must be + # in maintenance mode, for MicroPython in standard mode. + # The Calliope mini board must be in standard mode. if self.__deviceType == "bbc_microbit": # BBC micro:bit - deviceDirectory = Utilities.findVolume("MAINTENANCE") + if firmware: + deviceDirectory = Utilities.findVolume("MAINTENANCE") + else: + deviceDirectory = Utilities.findVolume("MICROBIT") else: # Calliope mini deviceDirectory = Utilities.findVolume("MINI") if not deviceDirectory: if self.__deviceType == "bbc_microbit": # BBC micro:bit is not ready or not mounted - E5MessageBox.critical( - self.microPython, - self.tr("Flash MicroPython Firmware"), - self.tr( - '<p>The BBC micro:bit is not ready for flashing.' - ' Follow these instructions.</p>' - '<ul>' - '<li>unplug USB cable and any batteries</li>' - '<li>keep RESET button pressed an plug USB cable back' - ' in</li>' - '<li>a drive called MAINTENANCE should be available' - '</li>' - '</ul>' - '<p>See the ' - '<a href="https://microbit.org/guide/firmware/">' - 'micro:bit web site</a> for details.</p>' - )) + if firmware: + E5MessageBox.critical( + self.microPython, + self.tr("Flash MicroPython/Firmware"), + self.tr( + '<p>The BBC micro:bit is not ready for flashing' + ' the DAPLink firmware. Follow these' + ' instructions. </p>' + '<ul>' + '<li>unplug USB cable and any batteries</li>' + '<li>keep RESET button pressed an plug USB cable' + ' back in</li>' + '<li>a drive called MAINTENANCE should be' + ' available</li>' + '</ul>' + '<p>See the ' + '<a href="https://microbit.org/guide/firmware/">' + 'micro:bit web site</a> for details.</p>' + ) + ) + else: + E5MessageBox.critical( + self.microPython, + self.tr("Flash MicroPython/Firmware"), + self.tr( + '<p>The BBC micro:bit is not ready for flashing' + ' the MicroPython firmware. Please make sure,' + ' that a drive called MICROBIT is available.' + '</p>' + ) + ) else: # Calliope mini is not ready or not mounted E5MessageBox.warning( self.microPython, - self.tr("Flash MicroPython Firmware"), + self.tr("Flash MicroPython/Firmware"), self.tr("Could not find an attached {0}.\n\n" "Please make sure the device is plugged " "into this computer.").format(self.deviceName())) @@ -239,9 +264,9 @@ QStandardPaths.DownloadLocation)[0] firmware = E5FileDialog.getOpenFileName( self.microPython, - self.tr("Flash MicroPython Firmware"), + self.tr("Flash MicroPython/Firmware"), downloadsPath, - self.tr("MicroPython Firmware Files (*.hex);;All Files (*)")) + self.tr("MicroPython/Firmware Files (*.hex);;All Files (*)")) if firmware and os.path.exists(firmware): shutil.copy2(firmware, deviceDirectory)