@@ -229,11 +229,15 @@ def select_file(bin_files):
229229 confirm = input (f"👀 Found one bin file: { bin_files [0 ]} . Do you want to flash it? (yes/no) " )
230230 if confirm .lower () == 'yes' :
231231 return bin_files [0 ]
232+ else :
233+ return None
232234 else :
233235 print ("👀 Found bin files:" )
234236 for index , file in enumerate (bin_files ):
235237 print (f"{ index + 1 } . { file } " )
236238 choice = int (input ("Select the file to flash (number): " ))
239+ if choice < 1 or choice > len (bin_files ):
240+ return None
237241 return bin_files [choice - 1 ]
238242
239243def select_i2c_device ():
@@ -247,6 +251,8 @@ def select_i2c_device():
247251 for index , device in enumerate (devices ):
248252 print (f"{ index + 1 } . Address: { hex (device )} " )
249253 choice = int (input ("Select the I2C device to flash (number): " ))
254+ if choice < 1 or choice > len (devices ):
255+ return None
250256 return devices [choice - 1 ]
251257
252258def run ():
@@ -260,9 +266,16 @@ def run():
260266 print ("❌ No .bin files found in the root directory." )
261267 return
262268
263- bin_file = "node_base.bin" # select_file(bin_files)
269+ bin_file = select_file (bin_files )
270+ if bin_file is None :
271+ print ("❌ No file selected" )
272+ return
273+
274+ device_address = select_i2c_device ()
275+ if device_address is None :
276+ print ("❌ No device selected" )
277+ return
264278
265- device_address = 30 # select_i2c_device()
266279 if send_reset (device_address ):
267280 print ("✅ Device reset successfully" )
268281 else :
0 commit comments