38 @type QObject |
38 @type QObject |
39 """ |
39 """ |
40 super(CircuitPythonDevice, self).__init__(microPythonWidget, parent) |
40 super(CircuitPythonDevice, self).__init__(microPythonWidget, parent) |
41 |
41 |
42 self.__workspace = self.__findWorkspace() |
42 self.__workspace = self.__findWorkspace() |
|
43 |
|
44 self.__nonUF2devices = { |
|
45 "teensy": self.__flashTeensy, |
|
46 } |
43 |
47 |
44 def setButtons(self): |
48 def setButtons(self): |
45 """ |
49 """ |
46 Public method to enable the supported action buttons. |
50 Public method to enable the supported action buttons. |
47 """ |
51 """ |
135 Private method to check, if the device volume is mounted. |
139 Private method to check, if the device volume is mounted. |
136 |
140 |
137 @return flag indicated a mounted device |
141 @return flag indicated a mounted device |
138 @rtype bool |
142 @rtype bool |
139 """ |
143 """ |
140 self.__workspace = "" # reset before checking |
144 if self.__workspace and not os.path.exists(self.__workspace): |
|
145 self.__workspace = "" # reset |
|
146 |
141 return self.DeviceVolumeName in self.getWorkspace(silent=True) |
147 return self.DeviceVolumeName in self.getWorkspace(silent=True) |
142 |
148 |
143 def getWorkspace(self, silent=False): |
149 def getWorkspace(self, silent=False): |
144 """ |
150 """ |
145 Public method to get the workspace directory. |
151 Public method to get the workspace directory. |
211 @pyqtSlot() |
217 @pyqtSlot() |
212 def __flashCircuitPython(self): |
218 def __flashCircuitPython(self): |
213 """ |
219 """ |
214 Private slot to flash a CircuitPython firmware to the device. |
220 Private slot to flash a CircuitPython firmware to the device. |
215 """ |
221 """ |
216 button = E5MessageBox.information( |
222 lBoardName = self.microPython.getCurrentBoard().lower() |
|
223 if lBoardName: |
|
224 for name in self.__nonUF2devices: |
|
225 if name in lBoardName: |
|
226 self.__nonUF2devices[name]() |
|
227 break |
|
228 else: |
|
229 button = E5MessageBox.information( |
|
230 self.microPython, |
|
231 self.tr("Flash CircuitPython Firmware"), |
|
232 self.tr("Please reset the device to bootloader mode and" |
|
233 " confirm when ready."), |
|
234 E5MessageBox.StandardButtons( |
|
235 E5MessageBox.Abort | |
|
236 E5MessageBox.Ok)) |
|
237 if button == E5MessageBox.Ok: |
|
238 from .CircuitPythonFirmwareSelectionDialog import ( |
|
239 CircuitPythonFirmwareSelectionDialog) |
|
240 dlg = CircuitPythonFirmwareSelectionDialog() |
|
241 if dlg.exec() == QDialog.Accepted: |
|
242 cpyPath, devicePath = dlg.getData() |
|
243 shutil.copy2(cpyPath, devicePath) |
|
244 |
|
245 def __flashTeensy(self): |
|
246 """ |
|
247 Private method to show a message box because Teens does not support |
|
248 the UF2 bootloader yet. |
|
249 """ |
|
250 E5MessageBox.information( |
217 self.microPython, |
251 self.microPython, |
218 self.tr("Flash CircuitPython Firmware"), |
252 self.tr("Flash CircuitPython Firmware"), |
219 self.tr("Please reset the device to bootloader mode and confirm" |
253 self.tr("""<p>Teensy 4.0 and Teensy 4.1 do not support the UF2""" |
220 " when ready."), |
254 """ bootloader. Please use the 'Teensy Loader'""" |
221 E5MessageBox.StandardButtons( |
255 """ application to flash CircuitPython. Make sure you""" |
222 E5MessageBox.Abort | |
256 """ downloaded the CircuitPython .hex file.</p>""" |
223 E5MessageBox.Ok)) |
257 """<p>See <a href="{0}">the PJRC Teensy web site</a>""" |
224 if button == E5MessageBox.Ok: |
258 """ for details.</p>""") |
225 from .CircuitPythonFirmwareSelectionDialog import ( |
259 .format("https://www.pjrc.com/teensy/loader.html")) |
226 CircuitPythonFirmwareSelectionDialog) |
|
227 dlg = CircuitPythonFirmwareSelectionDialog() |
|
228 if dlg.exec() == QDialog.Accepted: |
|
229 cpyPath, devicePath = dlg.getData() |
|
230 shutil.copy2(cpyPath, devicePath) |
|
231 |
260 |
232 @pyqtSlot() |
261 @pyqtSlot() |
233 def __installLibraryFiles(self): |
262 def __installLibraryFiles(self): |
234 """ |
263 """ |
235 Private slot to install Python files into the onboard library. |
264 Private slot to install Python files into the onboard library. |