Skip to content

Commit

Permalink
use esptool to get port list
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 committed Jun 28, 2024
1 parent e3d5c3c commit 67f18fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
14 changes: 7 additions & 7 deletions esp_flasher/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import time

import esp_flasher.own_esptool as esptool
from esp_flasher.own_esptool import get_port_list

import serial

from esp_flasher import const
Expand All @@ -23,8 +25,6 @@
ESP32_DEFAULT_OTA_DATA,
ESP32_SAFEBOOT_SERVER
)
from esp_flasher.helpers import list_serial_ports


def parse_args(argv):
parser = argparse.ArgumentParser(prog=f"esp_flasher {const.__version__}")
Expand Down Expand Up @@ -78,17 +78,17 @@ def select_port(args):
if args.port is not None:
print(f"Using '{args.port}' as serial port.")
return args.port
ports = list_serial_ports()
ports = get_port_list()
if not ports:
raise Esp_flasherError("No serial port found!")
if len(ports) != 1:
print("Found more than one serial port:")
for port, desc in ports:
print(f" * {port} ({desc})")
for port in ports:
print(f" * {port}")
print("Please choose one with the --port argument.")
raise Esp_flasherError
print(f"Auto-detected serial port: {ports[0][0]}")
return ports[0][0]
print(f"Auto-detected serial port: {ports}")
return ports


def show_logs(serial_port):
Expand Down
6 changes: 3 additions & 3 deletions esp_flasher/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from PyQt5.QtGui import QColor, QTextCursor, QPalette, QColor
from PyQt5.QtCore import pyqtSignal, QObject

from esp_flasher.helpers import list_serial_ports
from esp_flasher.own_esptool import get_port_list
from esp_flasher.const import __version__

COLOR_RE = re.compile(r'(?:\033)(?:\[(.*?)[@-~]|\].*?(?:\007|\033\\))')
Expand Down Expand Up @@ -143,10 +143,10 @@ def init_ui(self):

def reload_ports(self):
self.port_combobox.clear()
ports = [port for port, desc in list_serial_ports()]
ports = get_port_list()
if ports:
self.port_combobox.addItems(ports)
self._port = ports[0]
self._port = ports
else:
self.port_combobox.addItem("")

Expand Down
15 changes: 0 additions & 15 deletions esp_flasher/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
DEVNULL = open(os.devnull, 'w')


def list_serial_ports():
# from https://github.com/pyserial/pyserial/blob/master/serial/tools/list_ports.py
from serial.tools.list_ports import comports
result = []
for port, desc, info in comports():
if not port or "VID:PID" not in info:
continue
split_desc = desc.split(' - ')
if len(split_desc) == 2 and split_desc[0] == split_desc[1]:
desc = split_desc[0]
result.append((port, desc))
result.sort()
return result


def prevent_print(func, *args, **kwargs):
orig_sys_stdout = sys.stdout
sys.stdout = DEVNULL
Expand Down

0 comments on commit 67f18fa

Please sign in to comment.