@@ -108,6 +108,45 @@ def setDefaultProductForTarget(target_name: str, product_name: str) -> None:
108108 with open ('.pio/default_target_config.json' , 'w' ) as f :
109109 json .dump (data , f , indent = 4 )
110110
111+ def interactiveProductSelect (targets : dict , target_name : str , moduletype : str , frequency : str , platform : str ) -> dict :
112+ products = []
113+ for k in jmespath .search (f'[*."{ moduletype } _{ frequency } ".*][][?platform==`{ platform } `][]' , targets ):
114+ products .append (k )
115+ if frequency == 'dual' :
116+ for k in jmespath .search (f'[*."{ moduletype } _2400".*][][?platform==`{ platform } `][]' , targets ):
117+ if '_LR1121_' in k ['firmware' ]:
118+ products .append (k )
119+ for k in jmespath .search (f'[*."{ moduletype } _900".*][][?platform==`{ platform } `][]' , targets ):
120+ if '_LR1121_' in k ['firmware' ]:
121+ products .append (k )
122+
123+ if not products :
124+ return None
125+
126+ # Sort the list by product name, case insensitive, and print the list
127+ products = sorted (products , key = lambda p : p ['product_name' ].casefold ())
128+ print (f'0) Leave bare (no configuration)' )
129+ for i , p in enumerate (products ):
130+ print (f"{ i + 1 } ) { p ['product_name' ]} " )
131+ default_prod = getDefaultProductForTarget (target_name )
132+ # Make sure default_conf is a valid product name, set to '0' if not or default_prod is blank
133+ default_prod = default_prod if any (p ['product_name' ] == default_prod for p in products ) else '0'
134+ print (f'default) { default_prod } ' )
135+ print ('Choose a configuration to load into the firmware file' )
136+
137+ choice = input ()
138+ if choice == '' :
139+ choice = default_prod
140+ if choice == '0' :
141+ return None
142+
143+ # First see if choice is a valid product name from the list
144+ config = next ((p for p in products if p ['product_name' ] == choice ), None )
145+ # else choice is an integer
146+ config = config if config else products [int (choice )- 1 ]
147+
148+ return config
149+
111150def doConfiguration (file , defines , config , target_name , moduletype , frequency , platform , device_name , rx_as_tx ):
112151 product_name = "Unified"
113152 lua_name = "Unified"
@@ -125,35 +164,7 @@ def doConfiguration(file, defines, config, target_name, moduletype, frequency, p
125164 print ('The current compile options (user defines) have been included.' )
126165 print ('You will be able to configure the hardware via the web UI on the device.' )
127166 else :
128- products = []
129- for k in jmespath .search (f'[*."{ moduletype } _{ frequency } ".*][][?platform==`{ platform } `][]' , targets ):
130- products .append (k )
131- if frequency == 'dual' :
132- for k in jmespath .search (f'[*."{ moduletype } _2400".*][][?platform==`{ platform } `][]' , targets ):
133- if '_LR1121_' in k ['firmware' ]:
134- products .append (k )
135- for k in jmespath .search (f'[*."{ moduletype } _900".*][][?platform==`{ platform } `][]' , targets ):
136- if '_LR1121_' in k ['firmware' ]:
137- products .append (k )
138- # Sort the list by product name, case insensitive, and print the list
139- products = sorted (products , key = lambda p : p ['product_name' ].casefold ())
140- print (f'0) Leave bare (no configuration)' )
141- for i , p in enumerate (products ):
142- print (f"{ i + 1 } ) { p ['product_name' ]} " )
143- default_prod = getDefaultProductForTarget (target_name )
144- # Make sure default_conf is a valid product name, set to '0' if not or default_prod is blank
145- default_prod = default_prod if any (p ['product_name' ] == default_prod for p in products ) else '0'
146- print (f'default) { default_prod } ' )
147- print ('Choose a configuration to load into the firmware file' )
148-
149- choice = input ()
150- if choice == '' :
151- choice = default_prod
152- if choice != '0' :
153- # First see if choice is a valid product name from the list
154- config = next ((p for p in products if p ['product_name' ] == choice ), None )
155- # else choice is an integer
156- config = config if config else products [int (choice )- 1 ]
167+ config = interactiveProductSelect (targets , target_name , moduletype , frequency , platform )
157168
158169 if config is not None :
159170 product_name = config ['product_name' ]
0 commit comments