Compare commits

...

4 Commits

Author SHA1 Message Date
pdxlocations
088d13c88b reinit after region set 2025-02-12 16:03:57 -08:00
pdxlocations
c83ccea4ef use protubuf number when setting region 2025-02-12 15:27:33 -08:00
pdxlocations
d7f0bee54c try setting region earlier 2025-02-12 15:22:02 -08:00
pdxlocations
fb60773ae6 don't close interface after region set 2025-02-12 15:18:58 -08:00
2 changed files with 20 additions and 11 deletions

14
main.py
View File

@@ -52,7 +52,12 @@ def main(stdscr):
logging.info("Initializing interface %s", args)
with globals.lock:
globals.interface = initialize_interface(args)
if globals.interface.localNode.localConfig.lora.region == 0:
confirmation = get_list_input("Your region is UNSET. Set it now?", "Yes", ["Yes", "No"])
if confirmation == "Yes":
set_region()
globals.interface.close()
globals.interface = initialize_interface(args)
logging.info("Interface initialized")
globals.myNodeNum = get_nodeNum()
globals.channel_list = get_channels()
@@ -61,13 +66,6 @@ def main(stdscr):
init_nodedb()
load_messages_from_db()
logging.info("Starting main UI")
if globals.interface.localNode.localConfig.lora.region == 0:
confirmation = get_list_input("Your region is UNSET. Set it now?", "Yes", ["Yes", "No"])
if confirmation == "Yes":
set_region()
globals.interface.close()
globals.interface = initialize_interface(args)
main_ui(stdscr)
except Exception as e:

View File

@@ -352,9 +352,20 @@ def settings_menu(stdscr, interface):
def set_region():
node = globals.interface.getNode('^local')
device_config = node.localConfig
regions = [region.name for region in device_config.lora.DESCRIPTOR.fields_by_name["region"].enum_type.values]
new_region = get_list_input('Select your region:', 'UNSET', regions)
node.localConfig.lora.region = new_region
lora_descriptor = device_config.lora.DESCRIPTOR
# Get the enum mapping of region names to their numerical values
region_enum = lora_descriptor.fields_by_name["region"].enum_type
region_name_to_number = {v.name: v.number for v in region_enum.values}
regions = list(region_name_to_number.keys())
new_region_name = get_list_input('Select your region:', 'UNSET', regions)
# Convert region name to corresponding enum number
new_region_number = region_name_to_number.get(new_region_name, 0) # Default to 0 if not found
node.localConfig.lora.region = new_region_number
node.writeConfig("lora")