@@ -229,11 +229,15 @@ def select_file(bin_files):
229
229
confirm = input (f"👀 Found one bin file: { bin_files [0 ]} . Do you want to flash it? (yes/no) " )
230
230
if confirm .lower () == 'yes' :
231
231
return bin_files [0 ]
232
+ else :
233
+ return None
232
234
else :
233
235
print ("👀 Found bin files:" )
234
236
for index , file in enumerate (bin_files ):
235
237
print (f"{ index + 1 } . { file } " )
236
238
choice = int (input ("Select the file to flash (number): " ))
239
+ if choice < 1 or choice > len (bin_files ):
240
+ return None
237
241
return bin_files [choice - 1 ]
238
242
239
243
def select_i2c_device ():
@@ -247,6 +251,8 @@ def select_i2c_device():
247
251
for index , device in enumerate (devices ):
248
252
print (f"{ index + 1 } . Address: { hex (device )} " )
249
253
choice = int (input ("Select the I2C device to flash (number): " ))
254
+ if choice < 1 or choice > len (devices ):
255
+ return None
250
256
return devices [choice - 1 ]
251
257
252
258
def run ():
@@ -260,9 +266,16 @@ def run():
260
266
print ("❌ No .bin files found in the root directory." )
261
267
return
262
268
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
264
278
265
- device_address = 30 # select_i2c_device()
266
279
if send_reset (device_address ):
267
280
print ("✅ Device reset successfully" )
268
281
else :
0 commit comments