@@ -97,29 +97,6 @@ def flash_firmware(device : Modulino, firmware_path, verbose=False):
9797 :return: True if the flashing was successful, otherwise False.
9898 """
9999 bus = device .i2c_bus
100- data = execute_command (bus , CMD_GET_VERSION , None , 1 , verbose )
101- if data is None :
102- print ("❌ Failed to get protocol version" )
103- return False
104- print (f"ℹ️ Protocol version: { data [0 ] & 0xF } .{ data [0 ] >> 4 } " )
105-
106- data = execute_command (bus , CMD_GET , None , CMD_GET_LENGTH_V12 , verbose )
107- if data is None :
108- print ("❌ Failed to get command list" )
109- return False
110-
111- print (f"ℹ️ Bootloader version: { (data [1 ] & 0xF )} .{ data [1 ] >> 4 } " )
112- print ("👀 Supported commands:" )
113- print (", " .join ([hex (byte ) for byte in data [2 :]]))
114-
115- data = execute_command (bus , CMD_GET_ID , None , 3 , verbose )
116- if data is None :
117- print ("❌ Failed to get device ID" )
118- return False
119-
120- chip_id = (data [0 ] << 8 ) | data [1 ] # Chip ID: Byte 1 = MSB, Byte 2 = LSB
121- print (f"ℹ️ Chip ID: { chip_id } " )
122-
123100 print ("🗑️ Erasing memory..." )
124101 erase_params = bytearray ([0xFF , 0xFF , 0x0 ]) # Mass erase flash
125102 execute_command (bus , CMD_ERASE_NO_STRETCH , erase_params , 0 , verbose )
@@ -263,6 +240,37 @@ def select_device(bus : I2C) -> Modulino:
263240 return None
264241 return devices [choice - 1 ]
265242
243+ def print_device_info (device : Modulino ):
244+ """
245+ Print information about the selected device.
246+
247+ :param device: The Modulino device.
248+ """
249+
250+ bus = device .i2c_bus
251+ data = execute_command (bus , CMD_GET_VERSION , None , 1 )
252+ if data is None :
253+ print ("❌ Failed to get protocol version" )
254+ return False
255+ print (f"ℹ️ Protocol version: { data [0 ] & 0xF } .{ data [0 ] >> 4 } " )
256+
257+ data = execute_command (bus , CMD_GET , None , CMD_GET_LENGTH_V12 )
258+ if data is None :
259+ print ("❌ Failed to get command list" )
260+ return False
261+
262+ print (f"ℹ️ Bootloader version: { (data [1 ] & 0xF )} .{ data [1 ] >> 4 } " )
263+ print ("👀 Supported commands:" )
264+ print (", " .join ([hex (byte ) for byte in data [2 :]]))
265+
266+ data = execute_command (bus , CMD_GET_ID , None , 3 )
267+ if data is None :
268+ print ("❌ Failed to get device ID" )
269+ return False
270+
271+ chip_id = (data [0 ] << 8 ) | data [1 ] # Chip ID: Byte 1 = MSB, Byte 2 = LSB
272+ print (f"ℹ️ Chip ID: { chip_id } " )
273+
266274def run (bus : I2C ):
267275 """
268276 Initialize the flashing process.
@@ -295,6 +303,8 @@ def run(bus: I2C):
295303
296304 print (f"🕵️ Flashing { bin_file } to device at address { hex (BOOTLOADER_I2C_ADDRESS )} " )
297305
306+ print_device_info (device )
307+
298308 if flash_firmware (device , bin_file ):
299309 print ("✅ Firmware flashed successfully" )
300310 else :
0 commit comments