From 7a61808f476930ca4dbaae51a2dd963e50b3d142 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Sat, 26 Jul 2025 00:55:41 -0700 Subject: [PATCH] fix positions --- contact/ui/control_ui.py | 2 +- contact/utilities/input_handlers.py | 14 +++++++++++--- contact/utilities/validation_rules.py | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/contact/ui/control_ui.py b/contact/ui/control_ui.py index 39e67c7..613293b 100644 --- a/contact/ui/control_ui.py +++ b/contact/ui/control_ui.py @@ -427,7 +427,7 @@ def settings_menu(stdscr: object, interface: object) -> None: elif selected_option in ["latitude", "longitude", "altitude"]: new_value = get_text_input( - f"{human_readable_name} is currently: {current_value}", selected_option, None + f"{human_readable_name} is currently: {current_value}", selected_option, float ) new_value = current_value if new_value is None else new_value menu_state.current_menu[selected_option] = (field, new_value) diff --git a/contact/utilities/input_handlers.py b/contact/utilities/input_handlers.py index d09366c..2196337 100644 --- a/contact/utilities/input_handlers.py +++ b/contact/utilities/input_handlers.py @@ -102,12 +102,16 @@ def get_text_input(prompt: str, selected_config: str, input_type: str) -> Option elif input_type is float: try: - float(user_input) + float_val = float(user_input) + if not (min_value <= float_val <= max_value): + invalid_input(input_win, f"Enter a number between {min_value} and {max_value}.") + continue except ValueError: invalid_input(input_win, "Must be a valid floating point number.") continue else: - break + curses.curs_set(0) + return float_val else: break @@ -123,7 +127,11 @@ def get_text_input(prompt: str, selected_config: str, input_type: str) -> Option if char.isdigit(): user_input += char elif input_type is float: - if char.isdigit() or (char == "." and "." not in user_input): + if ( + char.isdigit() + or (char == "." and "." not in user_input) + or (char == "-" and len(user_input) == 0) + ): user_input += char else: user_input += char diff --git a/contact/utilities/validation_rules.py b/contact/utilities/validation_rules.py index 1c5701f..c135201 100644 --- a/contact/utilities/validation_rules.py +++ b/contact/utilities/validation_rules.py @@ -5,6 +5,13 @@ validation_rules = { "position_flags": {"max_length": 3}, "enabled_protocols": {"max_value": 2}, "hop_limit": {"max_value": 7}, + "latitude": {"min_value": -90, "max_value": 90}, + "longitude": {"min_value": -180, "max_value": 180}, + "altitude": {"min_value": -4294967295, "max_value": 4294967295}, + "red": {"max_value": 255}, + "green": {"max_value": 255}, + "blue": {"max_value": 255}, + "current": {"max_value": 255}, }