From ef2a6150ba0df3ca8ce2170905cae847b1515a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Thu, 29 Oct 2020 21:45:36 +0100 Subject: [PATCH 1/3] fix flasher --- README.md | 1 + zigate/flasher.py | 31 ++++++++++++++++++++++++++++--- zigate/version.py | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 82a0d0bf..bf1c418c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/doudz/zigate.svg)](http://isitmaintained.com/project/doudz/zigate "Percentage of issues still open") [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/sebramage) +[![Donate with Bitcoin](https://en.cryptobadges.io/badge/small/3DHvPBWyf5Vsp485tGFu7WfYSd6r5qgZdH)](https://en.cryptobadges.io/donate/3DHvPBWyf5Vsp485tGFu7WfYSd6r5qgZdH) Python library for [ZiGate](http://zigate.fr/). This library manage communication between python and zigate key, both USB and WiFi key are supported. diff --git a/zigate/flasher.py b/zigate/flasher.py index bc93e6e3..74edd26c 100644 --- a/zigate/flasher.py +++ b/zigate/flasher.py @@ -288,6 +288,28 @@ def select_flash(ser, flash_type): raise SystemExit(1) +def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"): + """ + Call in a loop to create terminal progress bar + @params: + iteration - Required : current iteration (Int) + total - Required : total iterations (Int) + prefix - Optional : prefix string (Str) + suffix - Optional : suffix string (Str) + decimals - Optional : positive number of decimals in percent complete (Int) + length - Optional : character length of bar (Int) + fill - Optional : bar fill character (Str) + printEnd - Optional : end character (e.g. "\r", "\r\n") (Str) + """ + percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) + filledLength = int(length * iteration // total) + bar = fill * filledLength + '-' * (length - filledLength) + print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd) + # Print New Line on Complete + if iteration == total: + print() + + def write_flash_to_file(ser, filename): # flash_start = cur = ZIGATE_FLASH_START cur = ZIGATE_FLASH_START @@ -308,8 +330,9 @@ def write_flash_to_file(ser, filename): if cur == 0: (flash_end,) = struct.unpack('>L', res.data[0x20:0x24]) fd.write(res.data) - print(int(cur*100/flash_end), '%', end='\r') + printProgressBar(cur, flash_end, 'Reading') cur += read_bytes + printProgressBar(flash_end, flash_end, 'Reading') logger.info('Backup firmware done') @@ -340,8 +363,9 @@ def write_file_to_flash(ser, filename): if not res.ok: print('writing failed at 0x%08x, status: 0x%x, data: %s' % (cur, res.status, data.hex())) raise SystemExit(1) - print(int(cur*100/flash_end), '%', end='\r') + printProgressBar(cur, flash_end, 'Writing') cur += read_bytes + printProgressBar(flash_end, flash_end, 'Writing') logger.info('Writing new firmware done') @@ -381,7 +405,8 @@ def flash(serialport='auto', write=None, save=None, erase=False, pdm_only=False) if erase: erase_EEPROM(ser, pdm_only) - # change_baudrate(ser, 38400) + change_baudrate(ser, 38400) + ser.close() def upgrade_firmware(port): diff --git a/zigate/version.py b/zigate/version.py index 3d7f98a5..ab448868 100644 --- a/zigate/version.py +++ b/zigate/version.py @@ -6,4 +6,4 @@ # -__version__ = '0.40.9' +__version__ = '0.40.10' From 51de2485d55d6387146fde8aa7d81cc5a5df49e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Thu, 29 Oct 2020 21:47:47 +0100 Subject: [PATCH 2/3] update flasher usage --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf1c418c..814d6d31 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ Thanks to Sander Hoentjen (tjikkun) we now have a flasher ! ### Flasher Usage ```bash -usage: python3 -m zigate.flasher [-h] -p {/dev/ttyUSB0} [-w WRITE] [-s SAVE] [-e] [--pdm-only] +usage: python3 -m zigate.flasher [-h] -p {/dev/ttyUSB0} [-w WRITE] [-s SAVE] [-u] [-d] [--gpio] [--din] optional arguments: -h, --help show this help message and exit @@ -298,6 +298,8 @@ optional arguments: -w WRITE, --write WRITE Firmware bin to flash onto the chip -s SAVE, --save SAVE File to save the currently loaded firmware to + -u, --upgrade Download and flash the lastest available firmware + -d, --debug Set log level to DEBUG --gpio Configure GPIO for PiZiGate flash --din Configure USB for ZiGate DIN flash From ddb0e623809675b79790b732f2a3254d289926cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Thu, 29 Oct 2020 21:50:56 +0100 Subject: [PATCH 3/3] py35 compat --- zigate/flasher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigate/flasher.py b/zigate/flasher.py index 74edd26c..abbdce3e 100644 --- a/zigate/flasher.py +++ b/zigate/flasher.py @@ -304,7 +304,7 @@ def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) filledLength = int(length * iteration // total) bar = fill * filledLength + '-' * (length - filledLength) - print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd) + print('\r{0} |{1}| {2}% {3}'.format(prefix, bar, percent, suffix), end = printEnd) # Print New Line on Complete if iteration == total: print()