@@ -585,7 +585,14 @@ def write_file(self, file: typing.BinaryIO, remote_file: str, file_len: int = -1
585
585
if compress and self .status ['system_version' ] in Spec ('>=1.0.5' ):
586
586
logger (__name__ ).info ('Closing gzip file' )
587
587
file .close ()
588
- self .ft_complete (options = run_after )
588
+ # The time to write the file to flash isn't exactly linear with the file size,
589
+ # but it's okay even if we slightly underestimate as long as we get a response back
590
+ # on one of the 3 tries of ft_complete.
591
+ # The point is to set our timeout window so we aren't waiting too long for a response
592
+ # that will never happen if, for example, the brain turned off.
593
+ ft_timeout = max (file_len / 200000 , 1.0 )
594
+ logger (__name__ ).debug (f'Setting file transfer timeout as { ft_timeout :.2f} seconds' )
595
+ self .ft_complete (options = run_after , timeout = ft_timeout )
589
596
590
597
@with_download_channel
591
598
def capture_screen (self ) -> Tuple [List [List [int ]], int , int ]:
@@ -688,12 +695,12 @@ def ft_initialize(self, file_name: str, **kwargs) -> Dict[str, Any]:
688
695
return rx
689
696
690
697
@retries
691
- def ft_complete (self , options : FTCompleteOptions = FTCompleteOptions .DONT_RUN ):
698
+ def ft_complete (self , options : FTCompleteOptions = FTCompleteOptions .DONT_RUN , timeout : float = 1.0 ):
692
699
logger (__name__ ).debug ('Sending ext 0x12 command' )
693
700
if isinstance (options , bool ):
694
701
options = self .FTCompleteOptions .RUN_IMMEDIATELY if options else self .FTCompleteOptions .DONT_RUN
695
702
tx_payload = struct .pack ("<B" , options .value )
696
- ret = self ._txrx_ext_packet (0x12 , tx_payload , 0 , timeout = self . default_timeout * 10 )
703
+ ret = self ._txrx_ext_packet (0x12 , tx_payload , 0 , timeout = timeout )
697
704
logger (__name__ ).debug ('Completed ext 0x12 command' )
698
705
return ret
699
706
0 commit comments