Skip to content

Commit acf63d6

Browse files
committed
Fix progress bar function
1 parent 70ca732 commit acf63d6

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/modulino/firmware_flasher.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def execute_command(opcode, command_data, response_length = 0, verbose=True):
9191

9292
data = i2c.readfrom(BOOTLOADER_I2C_ADDRESS, response_length)
9393
amount_of_bytes = data[0] + 1
94-
print(f"Retrieved {amount_of_bytes} bytes")
94+
print(f"Retrieved {amount_of_bytes} bytes") # TODO: Remove this line
9595

9696
if not wait_for_ack():
9797
print("Failed completing command")
@@ -126,28 +126,28 @@ def flash_firmware(firmware_path, verbose=True):
126126
chip_id = (data[0] << 8) | data[1] # Chip ID: Byte 1 = MSB, Byte 2 = LSB
127127
print(f"Chip ID: {chip_id}")
128128

129-
return True # Debug. Remove when done
130-
131129
print("Erasing memory...")
132130
erase_params = bytearray([0xFF, 0xFF, 0x0]) # Mass erase flash
133-
execute_command(CMD_ERASE, erase_params, 0, verbose)
131+
#execute_command(CMD_ERASE, erase_params, 0, verbose)
134132

135133
with open(firmware_path, 'rb') as file:
136134
firmware_data = file.read()
135+
total_bytes = len(firmware_data)
137136

138-
for i in range(0, len(firmware_data), 128):
139-
progress_bar(i, length)
137+
print(f"Flashing {total_bytes} bytes of firmware")
138+
for i in range(0, total_bytes, 128):
139+
progress_bar(i, total_bytes)
140140
write_buffer = bytearray([8, 0, i // 256, i % 256])
141-
if write_firmware_page(write_buffer, 5, firmware_data[i:i + 128], 128, verbose) < 0:
142-
print(f"Failed to write page {hex(i)}")
143-
return False
141+
# if write_firmware_page(write_buffer, 5, firmware_data[i:i + 128], 128, verbose) < 0:
142+
# print(f"Failed to write page {hex(i)}")
143+
# return False
144144
time.sleep(0.01)
145145

146-
progress_bar(length, length) # Complete the progress bar
146+
progress_bar(total_bytes, total_bytes) # Complete the progress bar
147147

148148
print("Starting firmware")
149149
go_params = bytearray([0x8, 0x00, 0x00, 0x00, 0x8])
150-
execute_command(CMD_GO, go_params, 0, verbose) # Jump to the application
150+
#execute_command(CMD_GO, go_params, 0, verbose) # Jump to the application
151151

152152
return True
153153

@@ -201,10 +201,11 @@ def progress_bar(current, total, bar_length=40):
201201
:param bar_length: The length of the progress bar in characters.
202202
"""
203203
percent = float(current) / total
204-
arrow = '-' * int(round(percent * bar_length) - 1) + '>'
204+
arrow = '-' * int(round(percent * bar_length))
205205
spaces = ' ' * (bar_length - len(arrow))
206206
sys.stdout.write(f"\rProgress: [{arrow}{spaces}] {int(round(percent * 100))}%")
207-
sys.stdout.flush()
207+
if current == total:
208+
sys.stdout.write('\n')
208209

209210
def find_bin_files():
210211
"""

0 commit comments

Comments
 (0)