@@ -83,8 +83,11 @@ def __init__(self, options, text):
8383 def wait (self ):
8484 event , values = self .window .Read ()
8585 self .window .close ()
86- type = getattr (dai .DeviceBootloader .Type , values ['bootType' ])
87- return (str (event ) == "Submit" , type )
86+ if values is not None :
87+ type = getattr (dai .DeviceBootloader .Type , values ['bootType' ])
88+ return (str (event ) == "Submit" , type )
89+ else :
90+ return (False , None )
8891
8992class SelectIP :
9093 def __init__ (self ):
@@ -158,13 +161,8 @@ def wait(self) -> dai.DeviceInfo:
158161 self .window .close ()
159162 return deviceSelected
160163
161- def flashBootloader (device : dai .DeviceInfo ):
164+ def flashBootloader (device : dai .DeviceInfo , type : dai . DeviceBootloader . Type ):
162165 try :
163- sel = SelectBootloader (['AUTO' , 'USB' , 'NETWORK' ], "Select bootloader type to flash." )
164- ok , type = sel .wait ()
165- if not ok :
166- print ("Flashing bootloader canceled." )
167- return
168166
169167 pr = Progress ('Connecting...' )
170168
@@ -179,22 +177,19 @@ def flashBootloader(device: dai.DeviceInfo):
179177 PrintException ()
180178 sg .Popup (f'{ ex } ' )
181179
182- def factoryReset (bl : dai .DeviceBootloader ):
183- sel = SelectBootloader (['USB' , 'NETWORK' ], "Select bootloader type used for factory reset." )
184- ok , type = sel .wait ()
185- if not ok :
186- print ("Factory reset canceled." )
187- return
188-
180+ def factoryReset (device : dai .DeviceInfo , type : dai .DeviceBootloader .Type ):
189181 try :
182+ pr = Progress ('Preparing and connecting...' )
183+
190184 blBinary = dai .DeviceBootloader .getEmbeddedBootloaderBinary (type )
191185 # Clear 1 MiB for USB BL and 8 MiB for NETWORK BL
192186 mib = 1 if type == dai .DeviceBootloader .Type .USB else 8
193187 blBinary = blBinary + ([0xFF ] * ((mib * 1024 * 1024 + 512 ) - len (blBinary )))
194188 tmpBlFw = tempfile .NamedTemporaryFile (delete = False )
195189 tmpBlFw .write (bytes (blBinary ))
196190
197- pr = Progress ()
191+ bl = dai .DeviceBootloader (device , True )
192+
198193 progress = lambda p : pr .update (p )
199194 success , msg = bl .flashBootloader (progress , tmpBlFw .name )
200195 msg = "Factory reset was successful." if success else f"Factory reset failed. Error: { msg } "
@@ -217,9 +212,11 @@ def flashFromFile(file, bl: dai.DeviceBootloader):
217212def recoveryMode (bl : dai .DeviceBootloader ):
218213 try :
219214 bl .bootUsbRomBootloader ()
215+ return True
220216 except Exception as ex :
221217 PrintException ()
222218 sg .Popup (f'{ ex } ' )
219+ return False
223220
224221def connectToDevice (device : dai .DeviceInfo ) -> dai .DeviceBootloader :
225222 try :
@@ -343,9 +340,11 @@ def deviceStateTxt(state: dai.XLinkDeviceState) -> str:
343340 ],
344341 [sg .HSeparator ()],
345342 [
346- sg .Text ("" , size = (10 , 2 )),
343+ sg .Text ("" , size = (1 , 2 )),
347344 sg .Button ("Flash configuration" , size = (15 , 2 ), font = ('Arial' , 10 , 'bold' ), disabled = True ,
348345 button_color = '#FFA500' ),
346+ sg .Button ("Clear configuration" , size = (15 , 2 ), font = ('Arial' , 10 , 'bold' ), disabled = True ,
347+ button_color = '#FFA500' ),
349348 sg .Button ("Clear flash" , size = (15 , 2 ), font = ('Arial' , 10 , 'bold' ), disabled = True ,
350349 button_color = '#FFA500' ),
351350 sg .Button ("Flash DAP" , size = (15 , 2 ), font = ('Arial' , 10 , 'bold' ), disabled = True ,
@@ -444,13 +443,33 @@ def run(self) -> None:
444443 self .getConfigs ()
445444 self .unlockConfig ()
446445 elif event == "Flash newest Bootloader" :
447- # We will reconnect, as we need to set allowFlashingBootloader to True
448- self .closeDevice ()
449- flashBootloader (self .device )
450- # Device will reboot, close previous and reset GUI
451- self .closeDevice ()
452- self .resetGui ()
453- self .getDevices ()
446+ sel = SelectBootloader (['AUTO' , 'USB' , 'NETWORK' ], "Select bootloader type to flash." )
447+ ok , type = sel .wait ()
448+ if ok :
449+ # We will reconnect, as we need to set allowFlashingBootloader to True
450+ self .closeDevice ()
451+ flashBootloader (self .device , type )
452+ # Device will reboot, close previous and reset GUI
453+ self .closeDevice ()
454+ self .resetGui ()
455+ self .getDevices ()
456+ else :
457+ print ("Flashing bootloader cancelled." )
458+
459+ elif event == "Factory reset" :
460+ sel = SelectBootloader (['NETWORK' , 'USB' ], "Select bootloader type used for factory reset." )
461+ ok , type = sel .wait ()
462+ if ok :
463+ # We will reconnect, as we need to set allowFlashingBootloader to True
464+ self .closeDevice ()
465+ factoryReset (self .device , type )
466+ # Device will reboot, close previous and reset GUI
467+ self .closeDevice ()
468+ self .resetGui ()
469+ self .getDevices ()
470+ else :
471+ print ("Factory reset cancelled." )
472+
454473 elif event == "Flash configuration" :
455474 self .flashConfig ()
456475 self .getConfigs ()
@@ -460,8 +479,16 @@ def run(self) -> None:
460479 else :
461480 self .devices .clear ()
462481 self .window .Element ('devices' ).update ("Search for devices" , values = [])
463- elif event == "Factory reset" :
464- factoryReset (self .bl )
482+ elif event == "Clear configuration" :
483+ self .clearConfig ()
484+ self .getConfigs ()
485+ self .resetGui ()
486+ if self .isUsb ():
487+ self .unlockConfig ()
488+ else :
489+ self .devices .clear ()
490+ self .window .Element ('devices' ).update ("Search for devices" , values = [])
491+
465492 elif event == "Flash DAP" :
466493 file = sg .popup_get_file ("Select .dap file" , file_types = (('DepthAI Application Package' , '*.dap' ), ('All Files' , '*.* *' )))
467494 flashFromFile (file , self .bl )
@@ -472,7 +499,12 @@ def run(self) -> None:
472499 self .window ['-COL2-' ].update (visible = False )
473500 self .window ['-COL1-' ].update (visible = True )
474501 elif event == "recoveryMode" :
475- recoveryMode (self .bl )
502+ if recoveryMode (self .bl ):
503+ sg .Popup (f'Device successfully put into USB recovery mode.' )
504+ # Device will reboot, close previous and reset GUI
505+ self .closeDevice ()
506+ self .resetGui ()
507+ self .getDevices ()
476508 self .window .close ()
477509
478510 @property
@@ -545,6 +577,7 @@ def unlockConfig(self):
545577
546578 self .window ['Flash newest Bootloader' ].update (disabled = False )
547579 self .window ['Flash configuration' ].update (disabled = False )
580+ self .window ['Clear configuration' ].update (disabled = False )
548581 self .window ['Factory reset' ].update (disabled = False )
549582 # self.window['Clear flash'].update(disabled=False)
550583 self .window ['Flash DAP' ].update (disabled = False )
@@ -564,6 +597,7 @@ def resetGui(self):
564597
565598 self .window ['Flash newest Bootloader' ].update (disabled = True )
566599 self .window ['Flash configuration' ].update (disabled = True )
600+ self .window ['Clear configuration' ].update (disabled = True )
567601 self .window ['Factory reset' ].update (disabled = True )
568602 self .window ['Clear flash' ].update (disabled = True )
569603 self .window ['Flash DAP' ].update (disabled = True )
@@ -641,6 +675,17 @@ def flashConfig(self):
641675 except Exception as ex :
642676 PrintException ()
643677 sg .Popup (f'{ ex } ' )
678+ def clearConfig (self ):
679+ try :
680+ success , error = self .bl .flashConfigClear ()
681+ if not success :
682+ sg .Popup (f"Clearing configuration failed: { error } " )
683+ else :
684+ sg .Popup ("Successfully cleared configuration." )
685+ except Exception as ex :
686+ PrintException ()
687+ sg .Popup (f'{ ex } ' )
688+
644689
645690app = DeviceManager ()
646691app .run ()
0 commit comments