Skip to content

Commit

Permalink
Merge pull request #88 from JohnMarzulli/automatic_declination
Browse files Browse the repository at this point in the history
Add GPS based declination detection
  • Loading branch information
JohnMarzulli authored Jul 5, 2021
2 parents f032607 + 779bd1c commit a13f4bc
Show file tree
Hide file tree
Showing 12 changed files with 65,218 additions and 73 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Temporary Items
.pytest_cache/
StratuxHud.egg-info
stratux_hud.log.*
*.csv
*.xlsx

# Stuff from TypeScript for Traffic Manager
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"aithre": true,
"data_source": "stratux",
"declination": 0.0,
"enable_declination": true,
"declination": 15.0,
"degrees_of_pitch": 90,
"distance_units": "statute",
"flip_horizontal": false,
Expand Down
40 changes: 37 additions & 3 deletions configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Configuration(object):
OWNSHIP_KEY = "ownship"
MAX_MINUTES_BEFORE_REMOVING_TRAFFIC_REPORT_KEY = "traffic_report_removal_minutes"
DISTANCE_UNITS_KEY = "distance_units"
ENABLE_DECLINATION_KEY = "enable_declination"
DECLINATION_KEY = "declination"
DEGREES_OF_PITCH_KEY = 'degrees_of_pitch'
PITCH_DEGREES_DISPLAY_SCALER_KEY = 'pitch_degrees_scaler'
Expand Down Expand Up @@ -203,6 +204,7 @@ def get_json_from_config(
Configuration.FLIP_VERTICAL_KEY: self.flip_vertical,
Configuration.MAX_MINUTES_BEFORE_REMOVING_TRAFFIC_REPORT_KEY: self.max_minutes_before_removal,
Configuration.DISTANCE_UNITS_KEY: self.get_units(),
Configuration.ENABLE_DECLINATION_KEY: self.__is_declination_enabled__,
Configuration.DECLINATION_KEY: self.get_declination(),
Configuration.DEGREES_OF_PITCH_KEY: self.get_degrees_of_pitch(),
Configuration.PITCH_DEGREES_DISPLAY_SCALER_KEY: self.get_pitch_degrees_display_scaler(),
Expand Down Expand Up @@ -274,6 +276,10 @@ def set_from_json(
self.__configuration__[
Configuration.DISTANCE_UNITS_KEY] = self.units

if Configuration.ENABLE_DECLINATION_KEY in json_config:
self.__is_declination_enabled__ = bool(json_config[Configuration.ENABLE_DECLINATION_KEY])
self.__configuration__[Configuration.ENABLE_DECLINATION_KEY] = self.__is_declination_enabled__

if Configuration.DECLINATION_KEY in json_config:
self.declination = float(
json_config[Configuration.DECLINATION_KEY])
Expand Down Expand Up @@ -335,6 +341,32 @@ def get_pitch_degrees_display_scaler(

return self.pitch_degrees_display_scaler

def is_declination_enabled(
self
) -> bool:
"""
Returns TRUE if declination calculations should be enabled
to headings and things.
Returns:
bool: True if declination calculations should be enabled.
"""

return self.__is_declination_enabled__

def set_declination_enabled(
self,
is_enabled: bool
):
"""
Set if declination calculations are enabled or not.
Args:
is_enabled (bool): True if declination calculations are enabled.
"""

self.__is_declination_enabled__ = is_enabled

def get_declination(
self
) -> float:
Expand Down Expand Up @@ -523,9 +555,7 @@ def __load_config_from_json_file__(
try:
with open(json_config_file) as json_config_file:
json_config_text = json_config_file.read()
json_config = json.loads(json_config_text)

return json_config
return json.loads(json_config_text)
except Exception:
return {}

Expand Down Expand Up @@ -584,6 +614,9 @@ def __init__(
self.flip_vertical = self.__get_config_value__(
Configuration.FLIP_VERTICAL_KEY,
False)
self.__is_declination_enabled__ = self.__get_config_value__(
Configuration.ENABLE_DECLINATION_KEY,
True)
self.declination = self.__get_config_value__(
Configuration.DECLINATION_KEY,
0.0)
Expand Down Expand Up @@ -619,6 +652,7 @@ def __init__(
# "flip_vertical": false,
# "ownship": "N701GV",
# "data_source": "stratux",
# "declination_enabled": true,
# "declination": 0.0


Expand Down
28 changes: 13 additions & 15 deletions configuration/configuration_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def get_settings(
"""
Handles a get-the-settings request.
"""
if configuration.CONFIGURATION is not None:
print("settings/GET")
return configuration.CONFIGURATION.get_json_from_config()
else:
if configuration.CONFIGURATION is None:
return ERROR_JSON

print("settings/GET")
return configuration.CONFIGURATION.get_json_from_config()


def set_settings(
handler
Expand All @@ -80,15 +80,14 @@ def set_settings(
Handles a set-the-settings request.
"""

if configuration.CONFIGURATION is not None:
payload = handler.get_payload()
print("settings/PUT:")
print(payload)
response = configuration.CONFIGURATION.update_configuration(payload)
return response
else:
if configuration.CONFIGURATION is None:
return ERROR_JSON

payload = handler.get_payload()
print("settings/PUT:")
print(payload)
return configuration.CONFIGURATION.update_configuration(payload)


def set_views(
handler
Expand Down Expand Up @@ -265,11 +264,10 @@ def __handle_request__(
if 'media_type' in route:
self.send_header('Content-type', route['media_type'])
self.end_headers()
elif 'file' in route:
self.__handle_file_request__(route, method)
else:
if 'file' in route:
self.__handle_file_request__(route, method)
else:
self.__finish_request__(route, method)
self.__finish_request__(route, method)

def handle_method(
self,
Expand Down
Loading

0 comments on commit a13f4bc

Please sign in to comment.