src/eric7/MicroPython/Devices/EspDevices.py

branch
mpy_network
changeset 9820
67597e003373
parent 9808
b68af9fd6a7a
child 9827
21803aa6c3e2
equal deleted inserted replaced
9817:640b6c23d97b 9820:67597e003373
11 import ast 11 import ast
12 import binascii 12 import binascii
13 import json 13 import json
14 import os 14 import os
15 15
16 from PyQt6.QtCore import QProcess, QUrl, pyqtSlot 16 from PyQt6.QtCore import QCoreApplication, QProcess, QUrl, pyqtSlot
17 from PyQt6.QtNetwork import QNetworkRequest 17 from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest
18 from PyQt6.QtWidgets import QDialog, QMenu 18 from PyQt6.QtWidgets import QDialog, QMenu
19 19
20 from eric7 import Globals, Preferences 20 from eric7 import Globals, Preferences
21 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor 21 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor
22 from eric7.EricWidgets import EricMessageBox 22 from eric7.EricWidgets import EricMessageBox
228 @pyqtSlot() 228 @pyqtSlot()
229 def __eraseFlash(self): 229 def __eraseFlash(self):
230 """ 230 """
231 Private slot to erase the device flash memory. 231 Private slot to erase the device flash memory.
232 """ 232 """
233 ok = EricMessageBox.yesNo( 233 eraseFlash(self.microPython.getCurrentPort())
234 self.microPython,
235 self.tr("Erase Flash"),
236 self.tr("""Shall the flash of the selected device really be erased?"""),
237 )
238 if ok:
239 flashArgs = [
240 "-u",
241 "-m",
242 "esptool",
243 "--port",
244 self.microPython.getCurrentPort(),
245 "erase_flash",
246 ]
247 dlg = EricProcessDialog(
248 self.tr("'esptool erase_flash' Output"),
249 self.tr("Erase Flash"),
250 showProgress=True,
251 )
252 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
253 if res:
254 dlg.exec()
255 234
256 @pyqtSlot() 235 @pyqtSlot()
257 def __flashMicroPython(self): 236 def __flashMicroPython(self):
258 """ 237 """
259 Private slot to flash a MicroPython firmware to the device. 238 Private slot to flash a MicroPython firmware to the device.
260 """ 239 """
261 from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog 240 flashPythonFirmware(self.microPython.getCurrentPort())
262
263 dlg = EspFirmwareSelectionDialog()
264 if dlg.exec() == QDialog.DialogCode.Accepted:
265 chip, firmware, baudRate, flashMode, flashAddress = dlg.getData()
266 flashArgs = [
267 "-u",
268 "-m",
269 "esptool",
270 "--chip",
271 chip,
272 "--port",
273 self.microPython.getCurrentPort(),
274 ]
275 if baudRate != "115200":
276 flashArgs += ["--baud", baudRate]
277 flashArgs.append("write_flash")
278 if flashMode:
279 flashArgs += ["--flash_mode", flashMode]
280 flashArgs += [
281 flashAddress,
282 firmware,
283 ]
284 dlg = EricProcessDialog(
285 self.tr("'esptool write_flash' Output"),
286 self.tr("Flash MicroPython Firmware"),
287 showProgress=True,
288 )
289 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
290 if res:
291 dlg.exec()
292 241
293 @pyqtSlot() 242 @pyqtSlot()
294 def __flashAddons(self): 243 def __flashAddons(self):
295 """ 244 """
296 Private slot to flash some additional firmware images. 245 Private slot to flash some additional firmware images.
297 """ 246 """
298 from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog 247 flashAddonFirmware(self.microPython.getCurrentPort())
299
300 dlg = EspFirmwareSelectionDialog(addon=True)
301 if dlg.exec() == QDialog.DialogCode.Accepted:
302 chip, firmware, baudRate, flashMode, flashAddress = dlg.getData()
303 flashArgs = [
304 "-u",
305 "-m",
306 "esptool",
307 "--chip",
308 chip,
309 "--port",
310 self.microPython.getCurrentPort(),
311 ]
312 if baudRate != "115200":
313 flashArgs += ["--baud", baudRate]
314 flashArgs.append("write_flash")
315 if flashMode:
316 flashArgs += ["--flash_mode", flashMode]
317 flashArgs += [
318 flashAddress.lower(),
319 firmware,
320 ]
321 dlg = EricProcessDialog(
322 self.tr("'esptool write_flash' Output"),
323 self.tr("Flash Additional Firmware"),
324 showProgress=True,
325 )
326 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
327 if res:
328 dlg.exec()
329 248
330 @pyqtSlot() 249 @pyqtSlot()
331 def __backupFlash(self): 250 def __backupFlash(self):
332 """ 251 """
333 Private slot to backup the currently flashed firmware. 252 Private slot to backup the currently flashed firmware.
442 ui = ericApp().getObject("UserInterface") 361 ui = ericApp().getObject("UserInterface")
443 request = QNetworkRequest(url) 362 request = QNetworkRequest(url)
444 reply = ui.networkAccessManager().head(request) 363 reply = ui.networkAccessManager().head(request)
445 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) 364 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply))
446 365
366 @pyqtSlot(QNetworkReply)
447 def __firmwareVersionResponse(self, reply): 367 def __firmwareVersionResponse(self, reply):
448 """ 368 """
449 Private method handling the response of the latest version request. 369 Private slot handling the response of the latest version request.
450 370
451 @param reply reference to the reply object 371 @param reply reference to the reply object
452 @type QNetworkReply 372 @type QNetworkReply
453 """ 373 """
454 latestUrl = reply.url().toString() 374 latestUrl = reply.url().toString()
1131 @type str 1051 @type str
1132 @return reference to the instantiated device object 1052 @return reference to the instantiated device object
1133 @rtype EspDevice 1053 @rtype EspDevice
1134 """ 1054 """
1135 return EspDevice(microPythonWidget, deviceType) 1055 return EspDevice(microPythonWidget, deviceType)
1056
1057
1058 ################################################################################
1059 ## Functions below implement flashing related functionality needed elsewhere ##
1060 ## as well. ##
1061 ################################################################################
1062
1063
1064 @pyqtSlot()
1065 def eraseFlash(port):
1066 """
1067 Slot to erase the device flash memory.
1068
1069 @param port name of the serial port device to be used
1070 @type str
1071 """
1072 ok = EricMessageBox.yesNo(
1073 None,
1074 QCoreApplication.translate("EspDevice", "Erase Flash"),
1075 QCoreApplication.translate(
1076 "EspDevice", """Shall the flash of the selected device really be erased?"""
1077 ),
1078 )
1079 if ok:
1080 flashArgs = [
1081 "-u",
1082 "-m",
1083 "esptool",
1084 "--port",
1085 port,
1086 "erase_flash",
1087 ]
1088 dlg = EricProcessDialog(
1089 QCoreApplication.translate("EspDevice", "'esptool erase_flash' Output"),
1090 QCoreApplication.translate("EspDevice", "Erase Flash"),
1091 showProgress=True,
1092 )
1093 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
1094 if res:
1095 dlg.exec()
1096
1097
1098 @pyqtSlot()
1099 def flashPythonFirmware(port):
1100 """
1101 Slot to flash a MicroPython firmware to the device.
1102
1103 @param port name of the serial port device to be used
1104 @type str
1105 """
1106 from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog
1107
1108 dlg = EspFirmwareSelectionDialog()
1109 if dlg.exec() == QDialog.DialogCode.Accepted:
1110 chip, firmware, baudRate, flashMode, flashAddress = dlg.getData()
1111 flashArgs = [
1112 "-u",
1113 "-m",
1114 "esptool",
1115 "--chip",
1116 chip,
1117 "--port",
1118 port,
1119 ]
1120 if baudRate != "115200":
1121 flashArgs += ["--baud", baudRate]
1122 flashArgs.append("write_flash")
1123 if flashMode:
1124 flashArgs += ["--flash_mode", flashMode]
1125 flashArgs += [
1126 flashAddress,
1127 firmware,
1128 ]
1129 dlg = EricProcessDialog(
1130 QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"),
1131 QCoreApplication.translate("EspDevice", "Flash µPy/CPy Firmware"),
1132 showProgress=True,
1133 )
1134 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
1135 if res:
1136 dlg.exec()
1137
1138
1139 @pyqtSlot()
1140 def flashAddonFirmware(port):
1141 """
1142 Slot to flash some additional firmware images.
1143
1144 @param port name of the serial port device to be used
1145 @type str
1146 """
1147 from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog
1148
1149 dlg = EspFirmwareSelectionDialog(addon=True)
1150 if dlg.exec() == QDialog.DialogCode.Accepted:
1151 chip, firmware, baudRate, flashMode, flashAddress = dlg.getData()
1152 flashArgs = [
1153 "-u",
1154 "-m",
1155 "esptool",
1156 "--chip",
1157 chip,
1158 "--port",
1159 port,
1160 ]
1161 if baudRate != "115200":
1162 flashArgs += ["--baud", baudRate]
1163 flashArgs.append("write_flash")
1164 if flashMode:
1165 flashArgs += ["--flash_mode", flashMode]
1166 flashArgs += [
1167 flashAddress.lower(),
1168 firmware,
1169 ]
1170 dlg = EricProcessDialog(
1171 QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"),
1172 QCoreApplication.translate("EspDevice", "Flash Additional Firmware"),
1173 showProgress=True,
1174 )
1175 res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs)
1176 if res:
1177 dlg.exec()

eric ide

mercurial