Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Release 0.40.10
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Oct 29, 2020
2 parents 784f345 + ddb0e62 commit b8be2ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
31 changes: 28 additions & 3 deletions zigate/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('\r{0} |{1}| {2}% {3}'.format(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
Expand All @@ -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')


Expand Down Expand Up @@ -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')


Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.40.9'
__version__ = '0.40.10'

0 comments on commit b8be2ff

Please sign in to comment.