172 @param menu reference to the context menu |
172 @param menu reference to the context menu |
173 @type QMenu |
173 @type QMenu |
174 """ |
174 """ |
175 connected = self.microPython.isConnected() |
175 connected = self.microPython.isConnected() |
176 |
176 |
177 act = menu.addAction(self.tr("Flash MicroPython Firmware"), |
177 act = menu.addAction(self.tr("Flash MicroPython"), |
178 self.__flashMicroPython) |
178 self.__flashMicroPython) |
|
179 act.setEnabled(not connected) |
|
180 act = menu.addAction(self.tr("Flash Firmware"), |
|
181 lambda: self.__flashMicroPython(firmware=True)) |
179 act.setEnabled(not connected) |
182 act.setEnabled(not connected) |
180 menu.addSeparator() |
183 menu.addSeparator() |
181 act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice) |
184 act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice) |
182 act.setToolTip(self.tr( |
185 act.setToolTip(self.tr( |
183 "Save the current script to the selected device")) |
186 "Save the current script to the selected device")) |
191 act = menu.addAction(self.tr("Reset {0}").format(self.deviceName()), |
194 act = menu.addAction(self.tr("Reset {0}").format(self.deviceName()), |
192 self.__resetDevice) |
195 self.__resetDevice) |
193 act.setEnabled(connected) |
196 act.setEnabled(connected) |
194 |
197 |
195 @pyqtSlot() |
198 @pyqtSlot() |
196 def __flashMicroPython(self): |
199 def __flashMicroPython(self, firmware=False): |
197 """ |
200 """ |
198 Private slot to flash the default MicroPython firmware to the device. |
201 Private slot to flash MicroPython or the DAPLink firmware to the |
199 """ |
202 device. |
200 # Attempts to find the path on the filesystem that represents the |
203 |
201 # plugged in micro:bit board in maintenance mode or Calliope mini |
204 @param firmware flag indicating to flash the DAPLink firmware |
202 # board in standard mode. |
205 @type bool |
203 if self.__deviceType == "bbc_microbit": |
206 """ |
204 # BBC micro:bit |
207 # Attempts to find the path on the file system that represents the |
205 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
208 # plugged in micro:bit board. To flash the DAPLink firmware, it must be |
|
209 # in maintenance mode, for MicroPython in standard mode. |
|
210 # The Calliope mini board must be in standard mode. |
|
211 if self.__deviceType == "bbc_microbit": |
|
212 # BBC micro:bit |
|
213 if firmware: |
|
214 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
|
215 else: |
|
216 deviceDirectory = Utilities.findVolume("MICROBIT") |
206 else: |
217 else: |
207 # Calliope mini |
218 # Calliope mini |
208 deviceDirectory = Utilities.findVolume("MINI") |
219 deviceDirectory = Utilities.findVolume("MINI") |
209 if not deviceDirectory: |
220 if not deviceDirectory: |
210 if self.__deviceType == "bbc_microbit": |
221 if self.__deviceType == "bbc_microbit": |
211 # BBC micro:bit is not ready or not mounted |
222 # BBC micro:bit is not ready or not mounted |
212 E5MessageBox.critical( |
223 if firmware: |
213 self.microPython, |
224 E5MessageBox.critical( |
214 self.tr("Flash MicroPython Firmware"), |
225 self.microPython, |
215 self.tr( |
226 self.tr("Flash MicroPython/Firmware"), |
216 '<p>The BBC micro:bit is not ready for flashing.' |
227 self.tr( |
217 ' Follow these instructions.</p>' |
228 '<p>The BBC micro:bit is not ready for flashing' |
218 '<ul>' |
229 ' the DAPLink firmware. Follow these' |
219 '<li>unplug USB cable and any batteries</li>' |
230 ' instructions. </p>' |
220 '<li>keep RESET button pressed an plug USB cable back' |
231 '<ul>' |
221 ' in</li>' |
232 '<li>unplug USB cable and any batteries</li>' |
222 '<li>a drive called MAINTENANCE should be available' |
233 '<li>keep RESET button pressed an plug USB cable' |
223 '</li>' |
234 ' back in</li>' |
224 '</ul>' |
235 '<li>a drive called MAINTENANCE should be' |
225 '<p>See the ' |
236 ' available</li>' |
226 '<a href="https://microbit.org/guide/firmware/">' |
237 '</ul>' |
227 'micro:bit web site</a> for details.</p>' |
238 '<p>See the ' |
228 )) |
239 '<a href="https://microbit.org/guide/firmware/">' |
|
240 'micro:bit web site</a> for details.</p>' |
|
241 ) |
|
242 ) |
|
243 else: |
|
244 E5MessageBox.critical( |
|
245 self.microPython, |
|
246 self.tr("Flash MicroPython/Firmware"), |
|
247 self.tr( |
|
248 '<p>The BBC micro:bit is not ready for flashing' |
|
249 ' the MicroPython firmware. Please make sure,' |
|
250 ' that a drive called MICROBIT is available.' |
|
251 '</p>' |
|
252 ) |
|
253 ) |
229 else: |
254 else: |
230 # Calliope mini is not ready or not mounted |
255 # Calliope mini is not ready or not mounted |
231 E5MessageBox.warning( |
256 E5MessageBox.warning( |
232 self.microPython, |
257 self.microPython, |
233 self.tr("Flash MicroPython Firmware"), |
258 self.tr("Flash MicroPython/Firmware"), |
234 self.tr("Could not find an attached {0}.\n\n" |
259 self.tr("Could not find an attached {0}.\n\n" |
235 "Please make sure the device is plugged " |
260 "Please make sure the device is plugged " |
236 "into this computer.").format(self.deviceName())) |
261 "into this computer.").format(self.deviceName())) |
237 else: |
262 else: |
238 downloadsPath = QStandardPaths.standardLocations( |
263 downloadsPath = QStandardPaths.standardLocations( |
239 QStandardPaths.DownloadLocation)[0] |
264 QStandardPaths.DownloadLocation)[0] |
240 firmware = E5FileDialog.getOpenFileName( |
265 firmware = E5FileDialog.getOpenFileName( |
241 self.microPython, |
266 self.microPython, |
242 self.tr("Flash MicroPython Firmware"), |
267 self.tr("Flash MicroPython/Firmware"), |
243 downloadsPath, |
268 downloadsPath, |
244 self.tr("MicroPython Firmware Files (*.hex);;All Files (*)")) |
269 self.tr("MicroPython/Firmware Files (*.hex);;All Files (*)")) |
245 if firmware and os.path.exists(firmware): |
270 if firmware and os.path.exists(firmware): |
246 shutil.copy2(firmware, deviceDirectory) |
271 shutil.copy2(firmware, deviceDirectory) |
247 |
272 |
248 @pyqtSlot() |
273 @pyqtSlot() |
249 def __saveMain(self): |
274 def __saveMain(self): |