eric6/MicroPython/MicrobitDevices.py

changeset 7552
b62e73df71dd
parent 7551
b159c55ea6dd
child 7780
41420f82c0ac
equal deleted inserted replaced
7551:b159c55ea6dd 7552:b62e73df71dd
187 self.__saveMain) 187 self.__saveMain)
188 act.setToolTip(self.tr( 188 act.setToolTip(self.tr(
189 "Save the current script as 'main.py' on the connected device")) 189 "Save the current script as 'main.py' on the connected device"))
190 act.setEnabled(connected) 190 act.setEnabled(connected)
191 menu.addSeparator() 191 menu.addSeparator()
192 act = menu.addAction(self.tr("Reset micro:bit"), self.__resetDevice) 192 act = menu.addAction(self.tr("Reset {0}").format(self.deviceName()),
193 self.__resetDevice)
193 act.setEnabled(connected) 194 act.setEnabled(connected)
194 195
195 @pyqtSlot() 196 @pyqtSlot()
196 def __flashMicroPython(self): 197 def __flashMicroPython(self):
197 """ 198 """
198 Private slot to flash the default MicroPython firmware to the device. 199 Private slot to flash the default MicroPython firmware to the device.
199 """ 200 """
200 # Attempts to find the path on the filesystem that represents the 201 # Attempts to find the path on the filesystem that represents the
201 # plugged in micro:bit board in maintenance mode. 202 # plugged in micro:bit board in maintenance mode or Calliope mini
202 deviceDirectory = Utilities.findVolume("MAINTENANCE") 203 # board in standard mode.
204 if self.__deviceType == "bbc_microbit":
205 # BBC micro:bit
206 deviceDirectory = Utilities.findVolume("MAINTENANCE")
207 else:
208 # Calliope mini
209 deviceDirectory = Utilities.findVolume("MINI")
203 if not deviceDirectory: 210 if not deviceDirectory:
204 if self.__deviceType == "bbc_microbit": 211 if self.__deviceType == "bbc_microbit":
205 # BBC micro:bit is not ready or not mounted 212 # BBC micro:bit is not ready or not mounted
206 E5MessageBox.critical( 213 E5MessageBox.critical(
207 self.microPython, 214 self.microPython,
220 '<a href="https://microbit.org/guide/firmware/">' 227 '<a href="https://microbit.org/guide/firmware/">'
221 'micro:bit web site</a> for details.</p>' 228 'micro:bit web site</a> for details.</p>'
222 )) 229 ))
223 else: 230 else:
224 # Calliope mini is not ready or not mounted 231 # Calliope mini is not ready or not mounted
225 E5MessageBox.critical( 232 E5MessageBox.warning(
226 self.microPython, 233 self.microPython,
227 self.tr("Flash MicroPython Firmware"), 234 self.tr("Flash MicroPython Firmware"),
228 self.tr( 235 self.tr("Could not find an attached {0}.\n\n"
229 '<p>The Calliope mini is not ready for flashing.' 236 "Please make sure the device is plugged "
230 ' Follow these instructions.</p>' 237 "into this computer.").format(self.deviceName()))
231 '<ul>'
232 '<li>unplug USB cable and any batteries</li>'
233 '<li>keep RESET button pressed an plug USB cable back'
234 ' in</li>'
235 '<li>a drive called MAINTENANCE should be available'
236 '</li>'
237 '</ul>'
238 ))
239 else: 238 else:
240 downloadsPath = QStandardPaths.standardLocations( 239 downloadsPath = QStandardPaths.standardLocations(
241 QStandardPaths.DownloadLocation)[0] 240 QStandardPaths.DownloadLocation)[0]
242 firmware = E5FileDialog.getOpenFileName( 241 firmware = E5FileDialog.getOpenFileName(
243 self.microPython, 242 self.microPython,
332 self.microPython.commandsInterface().execute([ 331 self.microPython.commandsInterface().execute([
333 "import microbit", 332 "import microbit",
334 "microbit.reset()", 333 "microbit.reset()",
335 ]) 334 ])
336 else: 335 else:
337 # TODO: try this branch with a Calliope mini
338 # Calliope mini 336 # Calliope mini
339 self.microPython.commandsInterface().execute([ 337 self.microPython.commandsInterface().execute([
340 "import calliope_mini", 338 "import calliope_mini",
341 "calliope_mini.reset()", 339 "calliope_mini.reset()",
342 ]) 340 ])

eric ide

mercurial