eric6/MicroPython/EspDevices.py

branch
micropython
changeset 7108
4f6133a01c6a
parent 7100
c4d9c28ebcd8
child 7114
f416440c8be1
equal deleted inserted replaced
7103:aea236dc8002 7108:4f6133a01c6a
8 class. 8 class.
9 """ 9 """
10 10
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 12
13 import sys
14
13 from PyQt5.QtCore import pyqtSlot 15 from PyQt5.QtCore import pyqtSlot
16 from PyQt5.QtWidgets import QDialog
17
18 from E5Gui import E5MessageBox
19 from E5Gui.E5ProcessDialog import E5ProcessDialog
20 from E5Gui.E5Application import e5App
14 21
15 from .MicroPythonDevices import MicroPythonDevice 22 from .MicroPythonDevices import MicroPythonDevice
16 from .MicroPythonReplWidget import HAS_QTCHART 23 from .MicroPythonReplWidget import HAS_QTCHART
17 24
18 25
103 def handleDataFlood(self): 110 def handleDataFlood(self):
104 """ 111 """
105 Public slot handling a data flood from the device. 112 Public slot handling a data flood from the device.
106 """ 113 """
107 self.microPython.setActionButtons(files=True) 114 self.microPython.setActionButtons(files=True)
115
116 def addDeviceMenuEntries(self, menu):
117 """
118 Public method to add device specific entries to the given menu.
119
120 @param menu reference to the context menu
121 @type QMenu
122 """
123 connected = self.microPython.isConnected()
124
125 act = menu.addAction(self.tr("Erase Flash"),
126 self.__eraseFlash)
127 act.setEnabled(not connected)
128 act = menu.addAction(self.tr("Flash MicroPython Firmware"),
129 self.__flashMicroPython)
130 act.setEnabled(not connected)
131 menu.addSeparator()
132 act = menu.addAction(self.tr("Flash Additional Firmware"),
133 self.__flashAddons)
134 act.setEnabled(not connected)
135 menu.addSeparator()
136 menu.addAction(self.tr("Install 'esptool.py'"), self.__installEspTool)
137
138 @pyqtSlot()
139 def __eraseFlash(self):
140 """
141 Private slot to erase the device flash memory.
142 """
143 ok = E5MessageBox.yesNo(
144 self,
145 self.tr("Erase Flash"),
146 self.tr("""Shall the flash of the selected device really be"""
147 """ erased?"""))
148 if ok:
149 flashArgs = [
150 "-u",
151 "-m", "esptool",
152 "--port", self.microPython.getCurrentPort(),
153 "erase_flash",
154 ]
155 dlg = E5ProcessDialog(self.tr("'esptool erase_flash' Output"),
156 self.tr("Erase Flash"))
157 res = dlg.startProcess(sys.executable, flashArgs)
158 if res:
159 dlg.exec_()
160
161 @pyqtSlot()
162 def __flashMicroPython(self):
163 """
164 Private slot to flash a MicroPython firmware to the device.
165 """
166 from .EspFirmwareSelectionDialog import EspFirmwareSelectionDialog
167 dlg = EspFirmwareSelectionDialog()
168 if dlg.exec_() == QDialog.Accepted:
169 chip, firmware, _ = dlg.getData()
170 if chip == "esp8266":
171 flashAddress = "0x0000"
172 elif chip == "esp32":
173 flashAddress = "0x1000"
174 else:
175 raise ValueError(self.tr("Unsupported chip type '{0}'.")
176 .format(chip))
177 flashArgs = [
178 "-u",
179 "-m", "esptool",
180 "--chip", chip,
181 "--port", self.microPython.getCurrentPort(),
182 "write_flash",
183 flashAddress,
184 firmware,
185 ]
186 dlg = E5ProcessDialog(self.tr("'esptool write_flash' Output"),
187 self.tr("Flash MicroPython Firmware"))
188 res = dlg.startProcess(sys.executable, flashArgs)
189 if res:
190 dlg.exec_()
191
192 @pyqtSlot()
193 def __flashAddons(self):
194 """
195 Private slot to flash some additional firmware images.
196 """
197 from .EspFirmwareSelectionDialog import EspFirmwareSelectionDialog
198 dlg = EspFirmwareSelectionDialog(addon=True)
199 if dlg.exec_() == QDialog.Accepted:
200 chip, firmware, flashAddress = dlg.getData()
201 flashArgs = [
202 "-u",
203 "-m", "esptool",
204 "--chip", chip,
205 "--port", self.microPython.getCurrentPort(),
206 "write_flash",
207 flashAddress.lower(),
208 firmware,
209 ]
210 dlg = E5ProcessDialog(self.tr("'esptool write_flash' Output"),
211 self.tr("Flash Additional Firmware"))
212 res = dlg.startProcess(sys.executable, flashArgs)
213 if res:
214 dlg.exec_()
215
216 @pyqtSlot()
217 def __installEspTool(self):
218 """
219 Private slot to install the esptool package via pip.
220 """
221 pip = e5App().getObject("Pip")
222 pip.installPackages(["esptool"], interpreter=sys.executable)

eric ide

mercurial