1919# Define the base directory to crawl
2020BASE_DIR = "../ardupilot/libraries/AP_HAL_ChibiOS/hwdef/"
2121
22+ hwdef_dict = dict [str , tuple [int , int , int , str , str , str ]]
23+
2224logging .basicConfig (level = "INFO" , format = "%(asctime)s - %(levelname)s - %(message)s" )
2325
2426# Add ../ardupilot/libraries/AP_HAL_ChibiOS/hwdef/scripts to the PYTHON path
@@ -50,8 +52,8 @@ def remove_suffixes(base_dirname: str, suffixes: list) -> str:
5052 return base_dirname
5153
5254
53- def process_hwdef_files (base_directory : str ) -> dict [ str , tuple [ int , int , int , str , str ]] :
54- hwdef_data : dict [ str , tuple [ int , int , int , str , str , str ]] = {}
55+ def process_hwdef_files (base_directory : str ) -> hwdef_dict :
56+ hwdef_data : hwdef_dict = {}
5557
5658 # Walk through the directory
5759 for dirpath , _dirnames , filenames in os .walk (base_directory ):
@@ -72,16 +74,18 @@ def process_hwdef_files(base_directory: str) -> dict[str, tuple[int, int, int, s
7274 dirname = os .path .basename (dirpath )
7375 numeric_board_id = int (c .get_numeric_board_id ())
7476 vid , pid = c .get_USB_IDs ()
77+ vid = int (vid )
78+ pid = int (pid )
7579 vid_name = str (c .get_config ("USB_STRING_MANUFACTURER" , default = "ArduPilot" )).strip ('"' ).strip ("'" )
7680 pid_name = str (c .get_config ("USB_STRING_PRODUCT" , default = dirname )).strip ('"' ).strip ("'" )
77- mcu_series = c .mcu_series
81+ mcu_series = str ( c .mcu_series )
7882 hwdef_data [dirname ] = (numeric_board_id , vid , pid , vid_name , pid_name , mcu_series )
7983 # Sort the dictionary by the (dirname) key, so that python 3.13 produces similar results to python 3.12
8084 return dict (sorted (hwdef_data .items (), key = lambda x : x [0 ].lower ()))
8185
8286
8387def create_dicts ( # pylint: disable=too-many-locals
84- hwdef_data : dict [ str , tuple [ int , int , int , str , str , str ]] ,
88+ hwdef_data : hwdef_dict ,
8589) -> tuple [dict [int , str ], dict [tuple [int , int ], str ], dict [int , str ], dict [int , str ], dict [int , str ]]:
8690 vid_vendor_dict : dict [int , str ] = {}
8791 vid_pid_product_dict : dict [tuple [int , int ], str ] = {}
@@ -223,7 +227,7 @@ def main() -> None:
223227 apj_board_id_vendor_dict : dict [int , str ] = {}
224228 mcu_series_dict : dict [int , str ] = {}
225229
226- hwdef_data : dict [ str , tuple [ int , int , int , str , str ]] = process_hwdef_files (BASE_DIR )
230+ hwdef_data : hwdef_dict = process_hwdef_files (BASE_DIR )
227231 vid_vendor_dict , vid_pid_product_dict , apj_board_id_name_dict , apj_board_id_vendor_dict , mcu_series_dict = create_dicts (
228232 hwdef_data
229233 )
0 commit comments