Skip to content

Commit 60c4d43

Browse files
PaulZCnseidle
authored andcommitted
Uploader GUI v1.2 - using v3.3 of esptool.py
1 parent 0aa92f4 commit 60c4d43

File tree

2 files changed

+2731
-515
lines changed

2 files changed

+2731
-515
lines changed

Uploader_GUI/RTK_Firmware_Uploader_GUI.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
RTK_Firmware_Uploader_GUI.py (this file!)
2222
RTK.ico (icon file for the .exe)
2323
RTK.png (icon for the GUI widget)
24-
esptool.py (copied from https://github.com/tasmota/tasmota-pyflasher)
24+
esptool.py (v3.3, copied from https://github.com/espressif/esptool/releases/tag/v3.3)
2525
RTK_Surveyor.ino.partitions.bin
2626
RTK_Surveyor.ino.bootloader.bin
2727
boot_app0.bin
@@ -47,15 +47,17 @@
4747

4848
import esptool
4949
from esptool import ESPLoader
50+
from esptool import UnsupportedCommandError
51+
from esptool import NotSupportedError
5052
from esptool import NotImplementedInROMError
5153
from esptool import FatalError
5254

5355
# Setting constants
5456
SETTING_PORT_NAME = 'port_name'
55-
SETTING_FILE_LOCATION = 'message'
56-
SETTING_BAUD_RATE = '921600' # Default to 921600 for upload
57+
SETTING_FILE_LOCATION = 'file_location'
58+
SETTING_BAUD_RATE = 'baud'
5759

58-
guiVersion = 'v1.1'
60+
guiVersion = 'v1.2'
5961

6062
def gen_serial_ports() -> Iterator[Tuple[str, str, str]]:
6163
"""Return all available serial ports."""
@@ -74,8 +76,6 @@ class messageRedirect:
7476
def __init__(self, edit, out=None) -> None:
7577
self.edit = edit
7678
self.out = out
77-
self.edit.setReadOnly(True)
78-
self.edit.clear()
7979

8080
def write(self, msg) -> None:
8181
if msg.startswith("\r"):
@@ -92,6 +92,9 @@ def write(self, msg) -> None:
9292
def flush(self) -> None:
9393
None
9494

95+
def isatty(self):
96+
return True
97+
9598
# noinspection PyArgumentList
9699

97100
class MainWidget(QWidget):
@@ -100,13 +103,15 @@ class MainWidget(QWidget):
100103
def __init__(self, parent: QWidget = None) -> None:
101104
super().__init__(parent)
102105

106+
self.timer=QTimer()
107+
self.timer.timeout.connect(self.repaintMessageBox)
108+
103109
# File location line edit
104110
self.msg_label = QLabel(self.tr('Firmware File:'))
105111
self.fileLocation_lineedit = QLineEdit()
106112
self.msg_label.setBuddy(self.fileLocation_lineedit)
107113
self.fileLocation_lineedit.setEnabled(False)
108-
self.fileLocation_lineedit.returnPressed.connect(
109-
self.on_browse_btn_pressed)
114+
self.fileLocation_lineedit.returnPressed.connect(self.on_browse_btn_pressed)
110115

111116
# Browse for new file button
112117
self.browse_btn = QPushButton(self.tr('Browse'))
@@ -141,6 +146,8 @@ def __init__(self, parent: QWidget = None) -> None:
141146

142147
# Messages Window
143148
self.messageBox = QPlainTextEdit()
149+
self.messageBox.setReadOnly(True)
150+
self.messageBox.clear()
144151

145152
# Arrange Layout
146153
layout = QGridLayout()
@@ -162,8 +169,8 @@ def __init__(self, parent: QWidget = None) -> None:
162169

163170
self.setLayout(layout)
164171

165-
#self._clean_settings() # This will delete all existing settings! Use with caution!
166-
172+
self.settings = QSettings()
173+
#self._clean_settings() # This will delete all existing settings! Use with caution!
167174
self._load_settings()
168175

169176
def writeMessage(self, msg) -> None:
@@ -173,10 +180,18 @@ def writeMessage(self, msg) -> None:
173180
self.messageBox.ensureCursorVisible()
174181
self.messageBox.repaint()
175182

183+
def startTimer(self) -> None:
184+
self.timer.start(1000)
185+
186+
def endTimer(self) -> None:
187+
self.timer.stop()
188+
189+
def repaintMessageBox(self) -> None:
190+
self.messageBox.ensureCursorVisible()
191+
self.messageBox.repaint()
192+
176193
def _load_settings(self) -> None:
177194
"""Load settings on startup."""
178-
self.settings = QSettings()
179-
180195
port_name = self.settings.value(SETTING_PORT_NAME)
181196
if port_name is not None:
182197
index = self.port_combobox.findData(port_name)
@@ -195,14 +210,12 @@ def _load_settings(self) -> None:
195210

196211
def _save_settings(self) -> None:
197212
"""Save settings on shutdown."""
198-
self.settings = QSettings()
199213
self.settings.setValue(SETTING_PORT_NAME, self.port)
200-
self.settings.setValue(SETTING_FILE_LOCATION, self.fileLocation_lineedit.text())
214+
self.settings.setValue(SETTING_FILE_LOCATION, self.theFileName)
201215
self.settings.setValue(SETTING_BAUD_RATE, self.baudRate)
202216

203217
def _clean_settings(self) -> None:
204218
"""Clean (remove) all existing settings."""
205-
self.settings = QSettings()
206219
self.settings.clear()
207220

208221
def show_error_message(self, msg: str) -> None:
@@ -258,6 +271,8 @@ def closeEvent(self, event: QCloseEvent) -> None:
258271
except:
259272
pass
260273

274+
self.endTimer()
275+
261276
event.accept()
262277

263278
def on_refresh_btn_pressed(self) -> None:
@@ -298,9 +313,15 @@ def on_upload_btn_pressed(self) -> None:
298313
return
299314
f.close()
300315

316+
try:
317+
self._save_settings() # Save the settings in case the upload crashes
318+
except:
319+
pass
320+
301321
self.writeMessage("Uploading firmware\n")
302322

303323
command = []
324+
#command.extend(["--trace"]) # Useful for debugging
304325
command.extend(["--chip","esp32"])
305326
command.extend(["--port",self.port])
306327
command.extend(["--baud",self.baudRate])
@@ -312,7 +333,16 @@ def on_upload_btn_pressed(self) -> None:
312333

313334
self.writeMessage("Command: esptool.main(%s)\n\n" % " ".join(command))
314335

315-
esptool.main(command)
336+
#print("python esptool.py %s\n\n" % " ".join(command)) # Useful for debugging - cut and paste into a command prompt
337+
338+
self.startTimer()
339+
340+
try:
341+
esptool.main(command)
342+
except (ValueError, IOError, FatalError, ImportError, NotImplementedInROMError, UnsupportedCommandError, NotSupportedError, RuntimeError) as err:
343+
self.writeMessage(str(err))
344+
345+
self.endTimer()
316346

317347
if __name__ == '__main__':
318348
from sys import exit as sysExit
@@ -321,7 +351,7 @@ def on_upload_btn_pressed(self) -> None:
321351
app.setApplicationName('SparkFun RTK Firmware Uploader ' + guiVersion)
322352
app.setWindowIcon(QIcon(resource_path("RTK.png")))
323353
w = MainWidget()
324-
if 1:
354+
if 1: # Change to 0 to have the messages echoed on stdout
325355
sys.stdout = messageRedirect(w.messageBox) # Divert stdout to messageBox
326356
sys.stderr = messageRedirect(w.messageBox) # Divert stderr to messageBox
327357
else:

0 commit comments

Comments
 (0)