5 |
5 |
6 """ |
6 """ |
7 Module implementing the device interface class for Teensy boards with MicroPython. |
7 Module implementing the device interface class for Teensy boards with MicroPython. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import QProcess, QUrl, pyqtSlot |
10 from PyQt6.QtCore import QCoreApplication, QProcess, QUrl, pyqtSlot |
11 from PyQt6.QtNetwork import QNetworkRequest |
11 from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest |
12 from PyQt6.QtWidgets import QMenu |
12 from PyQt6.QtWidgets import QMenu |
13 |
13 |
14 from eric7 import Globals, Preferences |
14 from eric7 import Globals, Preferences |
15 from eric7.EricWidgets import EricMessageBox |
15 from eric7.EricWidgets import EricMessageBox |
16 from eric7.EricWidgets.EricApplication import ericApp |
16 from eric7.EricWidgets.EricApplication import ericApp |
146 self.__showMpyAct = self.__teensyMenu.addAction( |
146 self.__showMpyAct = self.__teensyMenu.addAction( |
147 self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
147 self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
148 ) |
148 ) |
149 self.__teensyMenu.addSeparator() |
149 self.__teensyMenu.addSeparator() |
150 self.__teensyMenu.addAction( |
150 self.__teensyMenu.addAction( |
151 self.tr("MicroPython Flash Instructions"), self.__showFlashInstructions |
151 self.tr("MicroPython Flash Instructions"), showTeensyFlashInstructions |
152 ) |
152 ) |
153 self.__flashMpyAct = self.__teensyMenu.addAction( |
153 self.__flashMpyAct = self.__teensyMenu.addAction( |
154 self.tr("Flash MicroPython Firmware"), self.__startTeensyLoader |
154 self.tr("Flash MicroPython Firmware"), startTeensyLoader |
155 ) |
155 ) |
156 self.__flashMpyAct.setToolTip( |
156 self.__flashMpyAct.setToolTip( |
157 self.tr("Start the 'Teensy Loader' application to flash the Teensy device.") |
157 self.tr("Start the 'Teensy Loader' application to flash the Teensy device.") |
158 ) |
158 ) |
159 |
159 |
193 ui = ericApp().getObject("UserInterface") |
193 ui = ericApp().getObject("UserInterface") |
194 request = QNetworkRequest(QUrl(FirmwareGithubUrls["micropython"])) |
194 request = QNetworkRequest(QUrl(FirmwareGithubUrls["micropython"])) |
195 reply = ui.networkAccessManager().head(request) |
195 reply = ui.networkAccessManager().head(request) |
196 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) |
196 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) |
197 |
197 |
|
198 @pyqtSlot(QNetworkReply) |
198 def __firmwareVersionResponse(self, reply): |
199 def __firmwareVersionResponse(self, reply): |
199 """ |
200 """ |
200 Private method handling the response of the latest version request. |
201 Private slot handling the response of the latest version request. |
201 |
202 |
202 @param reply reference to the reply object |
203 @param reply reference to the reply object |
203 @type QNetworkReply |
204 @type QNetworkReply |
204 """ |
205 """ |
205 latestUrl = reply.url().toString() |
206 latestUrl = reply.url().toString() |
229 EricMessageBox.information( |
230 EricMessageBox.information( |
230 None, |
231 None, |
231 self.tr("MicroPython Version"), |
232 self.tr("MicroPython Version"), |
232 msg, |
233 msg, |
233 ) |
234 ) |
234 |
|
235 def __showFlashInstructions(self): |
|
236 """ |
|
237 Private method to show a message box with instruction to flash the Teensy. |
|
238 """ |
|
239 EricMessageBox.information( |
|
240 self.microPython, |
|
241 self.tr("Flash MicroPython Firmware"), |
|
242 self.tr( |
|
243 """<p>Teensy 4.0 and Teensy 4.1 are flashed using the 'Teensy Loader'""" |
|
244 """ application. Make sure you downloaded the MicroPython or""" |
|
245 """ CircuitPython .hex file.</p>""" |
|
246 """<p>See <a href="{0}">the PJRC Teensy web site</a>""" |
|
247 """ for details.</p>""" |
|
248 ).format("https://www.pjrc.com/teensy/loader.html"), |
|
249 ) |
|
250 |
|
251 def __startTeensyLoader(self): |
|
252 """ |
|
253 Private method to start the 'Teensy Loader' application. |
|
254 |
|
255 Note: The application must be accessible via the application search path. |
|
256 """ |
|
257 ok, _ = QProcess.startDetached("teensy") |
|
258 if not ok: |
|
259 EricMessageBox.warning( |
|
260 self.microPython, |
|
261 self.tr("Start 'Teensy Loader'"), |
|
262 self.tr( |
|
263 """<p>The 'Teensy Loader' application <b>teensy</b> could not""" |
|
264 """ be started. Ensure it is in the application search path or""" |
|
265 """ start it manually.</p>""" |
|
266 ), |
|
267 ) |
|
268 |
235 |
269 ################################################################## |
236 ################################################################## |
270 ## time related methods below |
237 ## time related methods below |
271 ################################################################## |
238 ################################################################## |
272 |
239 |
320 @type str |
287 @type str |
321 @return reference to the instantiated device object |
288 @return reference to the instantiated device object |
322 @rtype PyBoardDevice |
289 @rtype PyBoardDevice |
323 """ |
290 """ |
324 return TeensyDevice(microPythonWidget, deviceType) |
291 return TeensyDevice(microPythonWidget, deviceType) |
|
292 |
|
293 |
|
294 @pyqtSlot() |
|
295 def showTeensyFlashInstructions(): |
|
296 """ |
|
297 Slot to show a message box with instruction to flash the Teensy. |
|
298 """ |
|
299 EricMessageBox.information( |
|
300 None, |
|
301 QCoreApplication.translate("TeensyDevice", "Flash MicroPython Firmware"), |
|
302 QCoreApplication.translate( |
|
303 "TeensyDevice", |
|
304 """<p>Teensy 4.0 and Teensy 4.1 are flashed using the 'Teensy Loader'""" |
|
305 """ application. Make sure you downloaded the MicroPython or""" |
|
306 """ CircuitPython .hex file.</p>""" |
|
307 """<p>See <a href="{0}">the PJRC Teensy web site</a>""" |
|
308 """ for details.</p>""", |
|
309 ).format("https://www.pjrc.com/teensy/loader.html"), |
|
310 ) |
|
311 |
|
312 |
|
313 @pyqtSlot() |
|
314 def startTeensyLoader(): |
|
315 """ |
|
316 Slot to start the 'Teensy Loader' application. |
|
317 |
|
318 Note: The application must be accessible via the application search path. |
|
319 """ |
|
320 ok, _ = QProcess.startDetached("teensy") |
|
321 if not ok: |
|
322 EricMessageBox.warning( |
|
323 None, |
|
324 QCoreApplication.translate("TeensyDevice", "Start 'Teensy Loader'"), |
|
325 QCoreApplication.translate( |
|
326 "TeensyDevice", |
|
327 """<p>The 'Teensy Loader' application <b>teensy</b> could not""" |
|
328 """ be started. Ensure it is in the application search path or""" |
|
329 """ start it manually.</p>""", |
|
330 ), |
|
331 ) |