3030
3131MEDIA_TYPE_AUDIO = 1
3232MEDIA_TYPE_VIDEO = 2
33- MEDIA_TYPE_VIDEO_AUDIO = 3
33+
3434
3535
3636COLOR_WHITE = 0xFFFFFF # 白色
7272COMMAND_SET_MULTI_ALGORITHM = 0x0C
7373COMMAND_SET_MULTI_ALGORITHM_RATIO = 0x0D
7474COMMAND_SET_ALGO_PARAMS = 0x0E
75- COMMAND_UPDATE_ALGORITHM_PARAMS = 0x0F ,
75+ COMMAND_UPDATE_ALGORITHM_PARAMS = 0x0F
7676
7777COMMAND_RETURN_ARGS = 0x1A
7878COMMAND_RETURN_INFO = 0x1B
@@ -346,12 +346,11 @@ def knock(self):
346346 return ret ;
347347
348348 def getResult (self , algo ):
349- self .husky_lens_protocol_write_begin (ALGORITHM_ANY , COMMAND_GET_RESULT )
349+ self .husky_lens_protocol_write_begin (algo , COMMAND_GET_RESULT )
350350 self .husky_lens_protocol_write_end ()
351351
352352 ret ,_ ,_ = self .executeCommand (wait_cmd = COMMAND_RETURN_INFO )
353353 if ret == False :
354- time .sleep (1 )
355354 return None
356355 if self .receive_index != CONTENT_INDEX + 10 :
357356 return None
@@ -401,6 +400,7 @@ def getResult(self, algo):
401400 ret = Result (self .receive_buffer [0 :L ])
402401
403402 self .result [algo ]["blocks" ].append (ret )
403+ return self .result [algo ]["info" ].total_results
404404
405405 def wait (self , command ):
406406 receiving = True
@@ -558,10 +558,11 @@ def learnBlock(self, algo, x, y, width, height):
558558 self .husky_lens_protocol_write_int16 (width )
559559 self .husky_lens_protocol_write_int16 (height )
560560 self .husky_lens_protocol_write_end ()
561+ ret ,argInt ,_ = self .executeCommand (wait_cmd = COMMAND_RETURN_ARGS )
562+ if not ret :
563+ return 0
564+ return argInt [0 ] if argInt else 0
561565
562- ret ,_ ,_ = self .executeCommand (wait_cmd = COMMAND_RETURN_ARGS )
563- return ret
564-
565566 def switchAlgorithm (self ,algo ):
566567 self .husky_lens_protocol_write_begin (ALGORITHM_ANY , COMMAND_SET_ALGORITHM );
567568 self .husky_lens_protocol_write_uint8 (algo );
@@ -713,13 +714,13 @@ def setNameByID(self, algo : int, ID : int, name: str):
713714 return ret
714715
715716 def setMultiAlgorithms (self , algos :list ):
716- if len (algos ) > 3 :
717+ if len (algos ) > 3 or len ( algos ) < 2 :
717718 return False
718719 customAlgoNum = 0 ;
719720 self .customId = [None ,None ,None ]
720721 for algo in algos :
721722 if algo >= ALGORITHM_CUSTOM_BEGIN :
722- self .customId [customAlgoNum ] = algo0
723+ self .customId [customAlgoNum ] = algo
723724 customAlgoNum = + customAlgoNum + 1
724725
725726 self .husky_lens_protocol_write_begin (ALGORITHM_ANY , COMMAND_SET_MULTI_ALGORITHM );
@@ -736,6 +737,8 @@ def setMultiAlgorithms(self, algos:list):
736737 return ret
737738
738739 def setMultiAlgorithmRatios (self ,ratios : list ):
740+ if len (ratios ) > 3 or len (ratios ) < 2 :
741+ return False
739742 self .husky_lens_protocol_write_begin (ALGORITHM_ANY , COMMAND_SET_MULTI_ALGORITHM_RATIO )
740743 self .husky_lens_protocol_write_uint8 (len (ratios ))
741744 self .husky_lens_protocol_write_uint8 (0 )
@@ -752,13 +755,13 @@ def setMultiAlgorithmRatios(self,ratios : list):
752755
753756 def setAlgorithmParams (self ,algo , params = {"show_name" :False }):
754757 for k , v in params .items ():
755- self .husky_lens_protocol_write_begin (algo , COMMAND_SET_ALGO_PARAMS );
758+ self .husky_lens_protocol_write_begin (algo , COMMAND_SET_ALGO_PARAMS )
756759
757760 if isinstance (v , bool ):
758761 self .husky_lens_protocol_write_uint8 (1 );
759762 self .husky_lens_protocol_write_uint8 (0 );
760763 self .husky_lens_protocol_write_int16 (v );
761- self .husky_lens_protocol_write_zero_bytes (6 );
764+ self .husky_lens_protocol_write_zero_bytes (6 )
762765 self .husky_lens_protocol_write_string (k );
763766 elif isinstance (v , float ):
764767 float_bytes = struct .pack ("<f" , v )
@@ -767,10 +770,10 @@ def setAlgorithmParams(self,algo, params={"show_name":False}):
767770 self .husky_lens_protocol_write_uint8 (0 );
768771 self .husky_lens_protocol_write_int16 (v0 );
769772 self .husky_lens_protocol_write_int16 (v1 );
770- self .husky_lens_protocol_write_zero_bytes (4 );
773+ self .husky_lens_protocol_write_zero_bytes (4 )
771774 self .husky_lens_protocol_write_string (k );
772775 elif isinstance (v , str ):
773- self .husky_lens_protocol_write_zero_bytes (10 );
776+ self .husky_lens_protocol_write_zero_bytes (10 )
774777 self .husky_lens_protocol_write_string (k );
775778 self .husky_lens_protocol_write_string (v );
776779 else :
@@ -782,6 +785,12 @@ def setAlgorithmParams(self,algo, params={"show_name":False}):
782785 return False
783786 return True
784787
788+ def updateAlgoParams (self , algo ):
789+ self .husky_lens_protocol_write_begin (algo , COMMAND_UPDATE_ALGORITHM_PARAMS )
790+ self .husky_lens_protocol_write_end ()
791+ ret ,_ ,_ = self .executeCommand (wait_cmd = COMMAND_RETURN_ARGS )
792+ return ret
793+
785794 def getAlgorithmParams (self , algo , param_keys ):
786795 params = {}
787796 for k in param_keys :
0 commit comments