From b9d8c9ad443d0f684b768554b016e7a631bef059 Mon Sep 17 00:00:00 2001 From: pdxlocations <117498748+pdxlocations@users.noreply.github.com> Date: Thu, 30 Jan 2025 22:33:42 -0800 Subject: [PATCH] Add Lat/Lon/Alt to Position Settings (#96) * add lat/lon/alt * fix types and conditions --- save_to_radio.py | 19 +++++++++++++++---- settings.py | 9 +++++++++ ui/menus.py | 28 +++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/save_to_radio.py b/save_to_radio.py index e690949..1484f88 100644 --- a/save_to_radio.py +++ b/save_to_radio.py @@ -15,10 +15,10 @@ def settings_shutdown(interface): def settings_factory_reset(interface): interface.localNode.factoryReset() -def settings_set_owner(interface, long_name=None, short_name=None, is_licensed=False): - if isinstance(is_licensed, str): - is_licensed = is_licensed.lower() == 'true' - interface.localNode.setOwner(long_name, short_name, is_licensed) +# def settings_set_owner(interface, long_name=None, short_name=None, is_licensed=False): +# if isinstance(is_licensed, str): +# is_licensed = is_licensed.lower() == 'true' +# interface.localNode.setOwner(long_name, short_name, is_licensed) def save_changes(interface, menu_path, modified_settings): @@ -38,13 +38,24 @@ def save_changes(interface, menu_path, modified_settings): if menu_path[1] == "Radio Settings" or menu_path[1] == "Module Settings": config_category = menu_path[2].lower() # for radio and module configs + if {'latitude', 'longitude', 'altitude'} & modified_settings.keys(): + lat = float(modified_settings.get('latitude', 0.0)) + lon = float(modified_settings.get('longitude', 0.0)) + alt = int(modified_settings.get('altitude', 0)) + + interface.localNode.setFixedPosition(lat, lon, alt) + logging.info(f"Updated {config_category} with Latitude: {lat} and Longitude {lon} and Altitude {alt}") + return + elif menu_path[1] == "User Settings": # for user configs config_category = "User Settings" long_name = modified_settings.get("longName") short_name = modified_settings.get("shortName") is_licensed = modified_settings.get("isLicensed") is_licensed = is_licensed == "True" or is_licensed is True + node.setOwner(long_name, short_name, is_licensed) + logging.info(f"Updated {config_category} with Long Name: {long_name} and Short Name {short_name} and Licensed Mode {is_licensed}") return diff --git a/settings.py b/settings.py index 8898430..d86a73e 100644 --- a/settings.py +++ b/settings.py @@ -215,6 +215,15 @@ def settings_menu(stdscr, interface): for option, (field, value) in current_menu.items(): modified_settings[option] = value + elif selected_option in ['latitude', 'longitude', 'altitude']: + new_value = get_user_input(f"Current value for {selected_option}: {current_value}") + new_value = current_value if new_value is None else new_value + current_menu[selected_option] = (field, new_value) + + for option in ['latitude', 'longitude', 'altitude']: + if option in current_menu: + modified_settings[option] = current_menu[option][1] + elif field.type == 8: # Handle boolean type new_value = get_bool_selection(selected_option, str(current_value)) new_value = new_value == "True" or new_value is True diff --git a/ui/menus.py b/ui/menus.py index 32b4405..2fe107e 100644 --- a/ui/menus.py +++ b/ui/menus.py @@ -1,7 +1,9 @@ -from meshtastic.protobuf import config_pb2, module_config_pb2, channel_pb2 +from collections import OrderedDict +from meshtastic.protobuf import config_pb2, module_config_pb2, channel_pb2, mesh_pb2 from save_to_radio import settings_reboot, settings_factory_reset, settings_reset_nodedb, settings_shutdown import logging, traceback import base64 +import globals def extract_fields(message_instance, current_config=None): if isinstance(current_config, dict): # Handle dictionaries @@ -82,6 +84,30 @@ def generate_menu_from_protobuf(interface): current_radio_config = interface.localNode.localConfig if interface else None menu_structure["Main Menu"]["Radio Settings"] = extract_fields(radio, current_radio_config) + # Add Lat/Lon/Alt + position_data = { + "latitude": (None, current_node_info["position"].get("latitude", 0.0)), + "longitude": (None, current_node_info["position"].get("longitude", 0.0)), + "altitude": (None, current_node_info["position"].get("altitude", 0)) + } + + # Get existing position menu items + existing_position_menu = menu_structure["Main Menu"]["Radio Settings"].get("position", {}) + + # Create an ordered position menu with Lat/Lon/Alt inserted in the middle + ordered_position_menu = OrderedDict() + + for key, value in existing_position_menu.items(): + if key == "fixed_position": # Insert before or after a specific key + ordered_position_menu[key] = value + ordered_position_menu.update(position_data) # Insert Lat/Lon/Alt **right here** + else: + ordered_position_menu[key] = value + + # Update the menu with the new order + menu_structure["Main Menu"]["Radio Settings"]["position"] = ordered_position_menu + + # Add Module Settings module = module_config_pb2.ModuleConfig() current_module_config = interface.localNode.moduleConfig if interface else None