6 """ |
6 """ |
7 Module implementing the device interface class for ESP32 and ESP8266 based |
7 Module implementing the device interface class for ESP32 and ESP8266 based |
8 boards. |
8 boards. |
9 """ |
9 """ |
10 |
10 |
11 import sys |
|
12 |
|
13 from PyQt6.QtCore import pyqtSlot, QProcess |
11 from PyQt6.QtCore import pyqtSlot, QProcess |
14 from PyQt6.QtWidgets import QDialog |
12 from PyQt6.QtWidgets import QDialog |
15 |
13 |
16 from EricWidgets import EricMessageBox |
14 from EricWidgets import EricMessageBox |
17 from EricWidgets.EricProcessDialog import EricProcessDialog |
15 from EricWidgets.EricProcessDialog import EricProcessDialog |
18 from EricWidgets.EricApplication import ericApp |
16 from EricWidgets.EricApplication import ericApp |
19 |
17 |
20 from .MicroPythonDevices import MicroPythonDevice |
18 from .MicroPythonDevices import MicroPythonDevice |
21 from .MicroPythonWidget import HAS_QTCHART |
19 from .MicroPythonWidget import HAS_QTCHART |
22 |
20 |
|
21 import Globals |
23 import Preferences |
22 import Preferences |
24 |
23 |
25 |
24 |
26 class EspDevice(MicroPythonDevice): |
25 class EspDevice(MicroPythonDevice): |
27 """ |
26 """ |
185 "erase_flash", |
184 "erase_flash", |
186 ] |
185 ] |
187 dlg = EricProcessDialog(self.tr("'esptool erase_flash' Output"), |
186 dlg = EricProcessDialog(self.tr("'esptool erase_flash' Output"), |
188 self.tr("Erase Flash"), |
187 self.tr("Erase Flash"), |
189 showProgress=True) |
188 showProgress=True) |
190 res = dlg.startProcess(sys.executable, flashArgs) |
189 res = dlg.startProcess(Globals.getPythonExecutable(), flashArgs) |
191 if res: |
190 if res: |
192 dlg.exec() |
191 dlg.exec() |
193 |
192 |
194 @pyqtSlot() |
193 @pyqtSlot() |
195 def __flashMicroPython(self): |
194 def __flashMicroPython(self): |
220 firmware, |
219 firmware, |
221 ] |
220 ] |
222 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
221 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
223 self.tr("Flash MicroPython Firmware"), |
222 self.tr("Flash MicroPython Firmware"), |
224 showProgress=True) |
223 showProgress=True) |
225 res = dlg.startProcess(sys.executable, flashArgs) |
224 res = dlg.startProcess(Globals.getPythonExecutable(), flashArgs) |
226 if res: |
225 if res: |
227 dlg.exec() |
226 dlg.exec() |
228 |
227 |
229 @pyqtSlot() |
228 @pyqtSlot() |
230 def __flashAddons(self): |
229 def __flashAddons(self): |
255 firmware, |
254 firmware, |
256 ] |
255 ] |
257 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
256 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
258 self.tr("Flash Additional Firmware"), |
257 self.tr("Flash Additional Firmware"), |
259 showProgress=True) |
258 showProgress=True) |
260 res = dlg.startProcess(sys.executable, flashArgs) |
259 res = dlg.startProcess(Globals.getPythonExecutable(), flashArgs) |
261 if res: |
260 if res: |
262 dlg.exec() |
261 dlg.exec() |
263 |
262 |
264 @pyqtSlot() |
263 @pyqtSlot() |
265 def __backupFlash(self): |
264 def __backupFlash(self): |
283 firmware, |
282 firmware, |
284 ] |
283 ] |
285 dlg = EricProcessDialog(self.tr("'esptool read_flash' Output"), |
284 dlg = EricProcessDialog(self.tr("'esptool read_flash' Output"), |
286 self.tr("Backup Firmware"), |
285 self.tr("Backup Firmware"), |
287 showProgress=True) |
286 showProgress=True) |
288 res = dlg.startProcess(sys.executable, flashArgs) |
287 res = dlg.startProcess(Globals.getPythonExecutable(), flashArgs) |
289 if res: |
288 if res: |
290 dlg.exec() |
289 dlg.exec() |
291 |
290 |
292 @pyqtSlot() |
291 @pyqtSlot() |
293 def __restoreFlash(self): |
292 def __restoreFlash(self): |
321 firmware, |
320 firmware, |
322 ]) |
321 ]) |
323 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
322 dlg = EricProcessDialog(self.tr("'esptool write_flash' Output"), |
324 self.tr("Restore Firmware"), |
323 self.tr("Restore Firmware"), |
325 showProgress=True) |
324 showProgress=True) |
326 res = dlg.startProcess(sys.executable, flashArgs) |
325 res = dlg.startProcess(Globals.getPythonExecutable(), flashArgs) |
327 if res: |
326 if res: |
328 dlg.exec() |
327 dlg.exec() |
329 |
328 |
330 @pyqtSlot() |
329 @pyqtSlot() |
331 def __showChipID(self): |
330 def __showChipID(self): |
338 "--port", self.microPython.getCurrentPort(), |
337 "--port", self.microPython.getCurrentPort(), |
339 "chip_id" |
338 "chip_id" |
340 ] |
339 ] |
341 dlg = EricProcessDialog(self.tr("'esptool chip_id' Output"), |
340 dlg = EricProcessDialog(self.tr("'esptool chip_id' Output"), |
342 self.tr("Show Chip ID")) |
341 self.tr("Show Chip ID")) |
343 res = dlg.startProcess(sys.executable, args) |
342 res = dlg.startProcess(Globals.getPythonExecutable(), args) |
344 if res: |
343 if res: |
345 dlg.exec() |
344 dlg.exec() |
346 |
345 |
347 @pyqtSlot() |
346 @pyqtSlot() |
348 def __showFlashID(self): |
347 def __showFlashID(self): |
355 "--port", self.microPython.getCurrentPort(), |
354 "--port", self.microPython.getCurrentPort(), |
356 "flash_id" |
355 "flash_id" |
357 ] |
356 ] |
358 dlg = EricProcessDialog(self.tr("'esptool flash_id' Output"), |
357 dlg = EricProcessDialog(self.tr("'esptool flash_id' Output"), |
359 self.tr("Show Flash ID")) |
358 self.tr("Show Flash ID")) |
360 res = dlg.startProcess(sys.executable, args) |
359 res = dlg.startProcess(Globals.getPythonExecutable(), args) |
361 if res: |
360 if res: |
362 dlg.exec() |
361 dlg.exec() |
363 |
362 |
364 @pyqtSlot() |
363 @pyqtSlot() |
365 def __showMACAddress(self): |
364 def __showMACAddress(self): |
372 "--port", self.microPython.getCurrentPort(), |
371 "--port", self.microPython.getCurrentPort(), |
373 "read_mac" |
372 "read_mac" |
374 ] |
373 ] |
375 dlg = EricProcessDialog(self.tr("'esptool read_mac' Output"), |
374 dlg = EricProcessDialog(self.tr("'esptool read_mac' Output"), |
376 self.tr("Show MAC Address")) |
375 self.tr("Show MAC Address")) |
377 res = dlg.startProcess(sys.executable, args) |
376 res = dlg.startProcess(Globals.getPythonExecutable(), args) |
378 if res: |
377 if res: |
379 dlg.exec() |
378 dlg.exec() |
380 |
379 |
381 @pyqtSlot() |
380 @pyqtSlot() |
382 def __resetDevice(self): |
381 def __resetDevice(self): |
396 "-m", "esptool", |
395 "-m", "esptool", |
397 "--port", self.microPython.getCurrentPort(), |
396 "--port", self.microPython.getCurrentPort(), |
398 "flash_id" |
397 "flash_id" |
399 ] |
398 ] |
400 proc = QProcess() |
399 proc = QProcess() |
401 proc.start(sys.executable, args) |
400 proc.start(Globals.getPythonExecutable(), args) |
402 procStarted = proc.waitForStarted(10000) |
401 procStarted = proc.waitForStarted(10000) |
403 if procStarted: |
402 if procStarted: |
404 proc.waitForFinished(10000) |
403 proc.waitForFinished(10000) |
405 |
404 |
406 @pyqtSlot() |
405 @pyqtSlot() |
407 def __installEspTool(self): |
406 def __installEspTool(self): |
408 """ |
407 """ |
409 Private slot to install the esptool package via pip. |
408 Private slot to install the esptool package via pip. |
410 """ |
409 """ |
411 pip = ericApp().getObject("Pip") |
410 pip = ericApp().getObject("Pip") |
412 pip.installPackages(["esptool"], interpreter=sys.executable) |
411 pip.installPackages(["esptool"], |
|
412 interpreter=Globals.getPythonExecutable()) |
413 |
413 |
414 def getDocumentationUrl(self): |
414 def getDocumentationUrl(self): |
415 """ |
415 """ |
416 Public method to get the device documentation URL. |
416 Public method to get the device documentation URL. |
417 |
417 |