Skip to content

Commit

Permalink
Implement list command
Browse files Browse the repository at this point in the history
Co-Authored-By: Wind-stormger <76462385+Wind-stormger@users.noreply.github.com>
  • Loading branch information
2 people authored and AmirHmZz committed Jan 13, 2023
1 parent e61bc33 commit 1068b3d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ You can use `mpbridge` in several ways based on your needs:
* Run `mpbridge clear <PORT>`
* This command deletes all files and directories from `MicroPython` board and exits.

#### ⚜️ List all connected devices

* Run `mpbridge list`
* This command lists all connected devices.

**Note** : `<PORT>` can be the **full port path** or one of the **short forms** below :

* `c[n]` for `COM[n]` (`c3` is equal to `COM3`)
Expand Down
19 changes: 19 additions & 0 deletions mpbridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
from argparse import Namespace

import serial.tools.list_ports
from colorama import Fore
from mpremote.main import State, argparse_repl
from watchdog.observers import Observer
Expand Down Expand Up @@ -111,3 +112,21 @@ def push_deletes(pyb, path, old_ls: tuple):
pyb.fs_verbose_rm(file)
for ddir in sorted(set(new_ls[0]).difference(new_ls[0]), reverse=True):
pyb.fs_verbose_rmdir(ddir)


def list_devices():
ports = sorted(serial.tools.list_ports.comports())
if ports:
for i, port in enumerate(ports):
print(Fore.LIGHTYELLOW_EX,
"{}. {} {} {:04x}:{:04x} {} {}".format(
i + 1,
port.device,
port.serial_number or "null",
port.vid if isinstance(port.vid, int) else 0,
port.pid if isinstance(port.pid, int) else 0,
port.manufacturer or "null",
port.product or "null"))
else:
print(Fore.LIGHTYELLOW_EX, "Couldn't find any connected devices")
utils.reset_term_color()
9 changes: 9 additions & 0 deletions mpbridge/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ def clear(port):
c[n] connect to serial port "COM[n]"
"""
bridge.clear(port=port)


@main.command("list", short_help='List available devices')
def list_devices():
"""List available devices
[device] [serial_number] [vid]:[pid] [manufacturer] [product]
"""
bridge.list_devices()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ requires-python = ">=3.7"
dependencies = [
"watchdog>=2.2.0",
"colorama>=0.4.0",
"mpremote>=0.4.0",
"mpremote==0.4.0",
"click"
]
classifiers = [
Expand Down

0 comments on commit 1068b3d

Please sign in to comment.