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) |