mirror of
https://github.com/marcelstoer/nodemcu-pyflasher.git
synced 2025-07-21 10:16:32 +00:00
Reintroduce the serial port dropdown, add auto-select option
This commit is contained in:
parent
861f75415c
commit
0e5e250ade
54
Main.py
54
Main.py
@ -33,6 +33,8 @@ __flash_help__ = '''
|
|||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
'''
|
'''
|
||||||
|
__auto_select__ = "Auto-select"
|
||||||
|
__auto_select_explanation__ = "(first port with Espressif device)"
|
||||||
__supported_baud_rates__ = [9600, 57600, 74880, 115200, 230400, 460800, 921600]
|
__supported_baud_rates__ = [9600, 57600, 74880, 115200, 230400, 460800, 921600]
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -75,7 +77,10 @@ class FlashingThread(threading.Thread):
|
|||||||
print("esptool.py v%s" % esptool.__version__)
|
print("esptool.py v%s" % esptool.__version__)
|
||||||
initial_baud = min(ESPLoader.ESP_ROM_BAUD, self._config.baud)
|
initial_baud = min(ESPLoader.ESP_ROM_BAUD, self._config.baud)
|
||||||
|
|
||||||
esp = self.connect_to_esp(initial_baud)
|
if self._config.port.startswith(__auto_select__):
|
||||||
|
esp = self.connect_to_esp(initial_baud)
|
||||||
|
else:
|
||||||
|
esp = ESPLoader.detect_chip(self._config.port, initial_baud)
|
||||||
|
|
||||||
print("Chip is %s" % (esp.get_chip_description()))
|
print("Chip is %s" % (esp.get_chip_description()))
|
||||||
print("Features: %s" % ", ".join(esp.get_chip_features()))
|
print("Features: %s" % ", ".join(esp.get_chip_features()))
|
||||||
@ -145,6 +150,7 @@ class FlashConfig:
|
|||||||
self.erase_before_flash = False
|
self.erase_before_flash = False
|
||||||
self.mode = "dio"
|
self.mode = "dio"
|
||||||
self.firmware_path = None
|
self.firmware_path = None
|
||||||
|
self.port = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, file_path):
|
def load(cls, file_path):
|
||||||
@ -152,6 +158,7 @@ class FlashConfig:
|
|||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
with open(file_path, 'r') as f:
|
with open(file_path, 'r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
conf.port = data['port']
|
||||||
conf.baud = data['baud']
|
conf.baud = data['baud']
|
||||||
conf.mode = data['mode']
|
conf.mode = data['mode']
|
||||||
conf.erase_before_flash = data['erase']
|
conf.erase_before_flash = data['erase']
|
||||||
@ -159,6 +166,7 @@ class FlashConfig:
|
|||||||
|
|
||||||
def safe(self, file_path):
|
def safe(self, file_path):
|
||||||
data = {
|
data = {
|
||||||
|
'port': self.port,
|
||||||
'baud': self.baud,
|
'baud': self.baud,
|
||||||
'mode': self.mode,
|
'mode': self.mode,
|
||||||
'erase': self.erase_before_flash,
|
'erase': self.erase_before_flash,
|
||||||
@ -167,7 +175,7 @@ class FlashConfig:
|
|||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
def is_complete(self):
|
def is_complete(self):
|
||||||
return self.firmware_path is not None
|
return self.firmware_path is not None and self.port is not None
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -190,8 +198,13 @@ class NodeMcuFlasher(wx.Frame):
|
|||||||
self.SetMinSize((640, 480))
|
self.SetMinSize((640, 480))
|
||||||
self.Centre(wx.BOTH)
|
self.Centre(wx.BOTH)
|
||||||
self.Show(True)
|
self.Show(True)
|
||||||
|
print("Connect your device")
|
||||||
|
print("\nIf you chose the serial port auto-select feature you might want to ")
|
||||||
|
print("turn off Bluetooth")
|
||||||
|
|
||||||
def _init_ui(self):
|
def _init_ui(self):
|
||||||
|
def on_reload(event):
|
||||||
|
self.choice.SetItems(self._get_serial_ports())
|
||||||
|
|
||||||
def on_baud_changed(event):
|
def on_baud_changed(event):
|
||||||
radio_button = event.GetEventObject()
|
radio_button = event.GetEventObject()
|
||||||
@ -216,6 +229,10 @@ class NodeMcuFlasher(wx.Frame):
|
|||||||
worker = FlashingThread(self, self._config)
|
worker = FlashingThread(self, self._config)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
|
def on_select_port(event):
|
||||||
|
choice = event.GetEventObject()
|
||||||
|
self._config.port = choice.GetString(choice.GetSelection())
|
||||||
|
|
||||||
def on_pick_file(event):
|
def on_pick_file(event):
|
||||||
self._config.firmware_path = event.GetPath().replace("'", "")
|
self._config.firmware_path = event.GetPath().replace("'", "")
|
||||||
|
|
||||||
@ -225,9 +242,23 @@ class NodeMcuFlasher(wx.Frame):
|
|||||||
|
|
||||||
fgs = wx.FlexGridSizer(7, 2, 10, 10)
|
fgs = wx.FlexGridSizer(7, 2, 10, 10)
|
||||||
|
|
||||||
|
self.choice = wx.Choice(panel, choices=self._get_serial_ports())
|
||||||
|
self.choice.Bind(wx.EVT_CHOICE, on_select_port)
|
||||||
|
self._select_configured_port()
|
||||||
|
bmp = images.Reload.GetBitmap()
|
||||||
|
reload_button = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bmp,
|
||||||
|
size=(bmp.GetWidth() + 7, bmp.GetHeight() + 7))
|
||||||
|
reload_button.Bind(wx.EVT_BUTTON, on_reload)
|
||||||
|
reload_button.SetToolTip("Reload serial device list")
|
||||||
|
|
||||||
file_picker = wx.FilePickerCtrl(panel, style=wx.FLP_USE_TEXTCTRL)
|
file_picker = wx.FilePickerCtrl(panel, style=wx.FLP_USE_TEXTCTRL)
|
||||||
file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, on_pick_file)
|
file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, on_pick_file)
|
||||||
|
|
||||||
|
serial_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
serial_boxsizer.Add(self.choice, 1, wx.EXPAND)
|
||||||
|
serial_boxsizer.AddStretchSpacer(0)
|
||||||
|
serial_boxsizer.Add(reload_button, 0, wx.ALIGN_RIGHT, 20)
|
||||||
|
|
||||||
baud_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
baud_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
|
||||||
def add_baud_radio_button(sizer, index, baud_rate):
|
def add_baud_radio_button(sizer, index, baud_rate):
|
||||||
@ -282,6 +313,7 @@ class NodeMcuFlasher(wx.Frame):
|
|||||||
self.console_ctrl.SetForegroundColour(wx.RED)
|
self.console_ctrl.SetForegroundColour(wx.RED)
|
||||||
self.console_ctrl.SetDefaultStyle(wx.TextAttr(wx.RED))
|
self.console_ctrl.SetDefaultStyle(wx.TextAttr(wx.RED))
|
||||||
|
|
||||||
|
port_label = wx.StaticText(panel, label="Serial port")
|
||||||
file_label = wx.StaticText(panel, label="NodeMCU firmware")
|
file_label = wx.StaticText(panel, label="NodeMCU firmware")
|
||||||
baud_label = wx.StaticText(panel, label="Baud rate")
|
baud_label = wx.StaticText(panel, label="Baud rate")
|
||||||
flashmode_label = wx.StaticText(panel, label="Flash mode")
|
flashmode_label = wx.StaticText(panel, label="Flash mode")
|
||||||
@ -309,17 +341,33 @@ class NodeMcuFlasher(wx.Frame):
|
|||||||
console_label = wx.StaticText(panel, label="Console")
|
console_label = wx.StaticText(panel, label="Console")
|
||||||
|
|
||||||
fgs.AddMany([
|
fgs.AddMany([
|
||||||
|
port_label, (serial_boxsizer, 1, wx.EXPAND),
|
||||||
file_label, (file_picker, 1, wx.EXPAND),
|
file_label, (file_picker, 1, wx.EXPAND),
|
||||||
baud_label, baud_boxsizer,
|
baud_label, baud_boxsizer,
|
||||||
flashmode_label_boxsizer, flashmode_boxsizer,
|
flashmode_label_boxsizer, flashmode_boxsizer,
|
||||||
erase_label, erase_boxsizer,
|
erase_label, erase_boxsizer,
|
||||||
(wx.StaticText(panel, label="")), (button, 1, wx.EXPAND),
|
(wx.StaticText(panel, label="")), (button, 1, wx.EXPAND),
|
||||||
(console_label, 1, wx.EXPAND), (self.console_ctrl, 1, wx.EXPAND)])
|
(console_label, 1, wx.EXPAND), (self.console_ctrl, 1, wx.EXPAND)])
|
||||||
fgs.AddGrowableRow(5, 1)
|
fgs.AddGrowableRow(6, 1)
|
||||||
fgs.AddGrowableCol(1, 1)
|
fgs.AddGrowableCol(1, 1)
|
||||||
hbox.Add(fgs, proportion=2, flag=wx.ALL | wx.EXPAND, border=15)
|
hbox.Add(fgs, proportion=2, flag=wx.ALL | wx.EXPAND, border=15)
|
||||||
panel.SetSizer(hbox)
|
panel.SetSizer(hbox)
|
||||||
|
|
||||||
|
def _select_configured_port(self):
|
||||||
|
count = 0
|
||||||
|
for item in self.choice.GetItems():
|
||||||
|
if item == self._config.port:
|
||||||
|
self.choice.Select(count)
|
||||||
|
break
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_serial_ports():
|
||||||
|
ports = [__auto_select__ + " " + __auto_select_explanation__]
|
||||||
|
for port, desc, hwid in sorted(list_ports.comports()):
|
||||||
|
ports.append(port)
|
||||||
|
return ports
|
||||||
|
|
||||||
def _set_icons(self):
|
def _set_icons(self):
|
||||||
self.SetIcon(images.Icon.GetIcon())
|
self.SetIcon(images.Icon.GetIcon())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user