From f349efff8007338e2bd5f856a02e7915123ef32e Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Mon, 10 Jan 2022 01:22:38 +0100 Subject: [PATCH] Add auto_int for range args --- tw88xx_util.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tw88xx_util.py b/tw88xx_util.py index 7562747..d35a9b8 100644 --- a/tw88xx_util.py +++ b/tw88xx_util.py @@ -3,6 +3,11 @@ import argparse from tw88xx import TW88xx parser = argparse.ArgumentParser(description='TW88xx debug utility.') + +def auto_int(x): + return int(x, 0) + + parser.add_argument('command', help='the command to execute', choices=('dump_flash', 'get_id', 'dump_regs', 'dump_lut') @@ -30,11 +35,13 @@ parser.add_argument('-t', '--type', ) parser.add_argument('--start', help='begin of reading range', - default='0' + type=auto_int, + default=0 ) parser.add_argument('--length', help='amount to read', - default='0' + type=auto_int, + default=0 ) args = parser.parse_args() @@ -78,9 +85,9 @@ elif args.command == 'dump_regs': if not args.start: tw88xx.dump_regs() else: - for r in range(args.start,args.start+args.length+1): + for r in range(args.start, args.start+args.length+1): if r in tw88xx.REGS: - v=tw88xx.read_reg(r) + v = tw88xx.read_reg(r) print(f'{r:03x} = {v:02x} ({tw88xx.REGS[r]})') elif args.command == 'dump_lut':