Skip to content

Commit

Permalink
tools/pydfu.py: Remove default VID/PID values.
Browse files Browse the repository at this point in the history
As the new default behaviour, this allows PyDFU to be used with all
devices, not just the ones matching a specific set of VID/PID values.  But
it's still possible to specify VID/PID if needed to narrow down the
selection of the USB device.

Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
  • Loading branch information
Tobias Thyrrestrup authored and dpgeorge committed May 21, 2021
1 parent ea81bcf commit 247d7e2
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions tools/pydfu.py
Expand Up @@ -23,10 +23,6 @@
import usb.util
import zlib

# VID/PID
__VID = 0x0483
__PID = 0xDF11

# USB request __TIMEOUT
__TIMEOUT = 4000

Expand Down Expand Up @@ -112,10 +108,10 @@ def find_dfu_cfg_descr(descr):
return None


def init():
def init(**kwargs):
"""Initializes the found DFU device so that we can program it."""
global __dev, __cfg_descr
devices = get_dfu_devices(idVendor=__VID, idProduct=__PID)
devices = get_dfu_devices(**kwargs)
if not devices:
raise ValueError("No DFU device found")
if len(devices) > 1:
Expand Down Expand Up @@ -565,15 +561,13 @@ def cli_progress(addr, offset, size):
def main():
"""Test program for verifying this files functionality."""
global __verbose
global __VID
global __PID
# Parse CMD args
parser = argparse.ArgumentParser(description="DFU Python Util")
parser.add_argument(
"-l", "--list", help="list available DFU devices", action="store_true", default=False
)
parser.add_argument("--vid", help="USB Vendor ID", type=lambda x: int(x, 0), default=__VID)
parser.add_argument("--pid", help="USB Product ID", type=lambda x: int(x, 0), default=__PID)
parser.add_argument("--vid", help="USB Vendor ID", type=lambda x: int(x, 0), default=None)
parser.add_argument("--pid", help="USB Product ID", type=lambda x: int(x, 0), default=None)
parser.add_argument(
"-m", "--mass-erase", help="mass erase device", action="store_true", default=False
)
Expand All @@ -588,14 +582,18 @@ def main():

__verbose = args.verbose

__VID = args.vid
__PID = args.pid
kwargs = {}
if args.vid:
kwargs["idVendor"] = args.vid

if args.pid:
kwargs["idProduct"] = args.pid

if args.list:
list_dfu_devices(idVendor=__VID, idProduct=__PID)
list_dfu_devices(**kwargs)
return

init()
init(**kwargs)

command_run = False
if args.mass_erase:
Expand Down

0 comments on commit 247d7e2

Please sign in to comment.