From d3bebd0926583ed9dbbf6829e12329a47228c47e Mon Sep 17 00:00:00 2001 From: merspieler Date: Mon, 5 Mar 2018 15:45:39 +0100 Subject: [PATCH] Added reset mechanism for profiles Signed-off-by: merspieler --- __init__.py | 182 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 154 insertions(+), 28 deletions(-) diff --git a/__init__.py b/__init__.py index ed13d64..4bce3e4 100644 --- a/__init__.py +++ b/__init__.py @@ -17,34 +17,10 @@ LOGGER = getLogger(__name__) class FlightGearCopilotSkill(MycroftSkill): def __init__(self): super(FlightGearCopilotSkill, self).__init__() + # Already existing options are here read only -> will not be overwritten self.settings['host'] = "localhost" self.settings['port'] = 8081 - # TODO add self.settings['profiles'] with default profiles (A32X and c172p) - -# DEFINITION of the settings['profiles'] structure -# [ -# { -# "name": "", -# "acid": -# [ -# " can be found in /???", -# ... -# ], -# flaps: -# [ -# { -# "id": " can be up|down|full|number", -# "min-spd": "", -# "max-spd": "", -# "value": "" -# }, -# ... -# ] -# "flaps-path": "" -# "gear-retractable": "" -# }, -# ... -# ] + self.write_default_profiles() ################################################################# # # @@ -966,7 +942,7 @@ class FlightGearCopilotSkill(MycroftSkill): wait_while_speaking() response = self.get_response("dummy") if response != None: - match = re.search("yes|afirm|ok", response, re.I) + match = re.search("yes|affirm|ok", response, re.I) if match != None: self.settings['host'] = "localhost" self.speak("New host " + self.settings['host'] + " is set") @@ -999,7 +975,7 @@ class FlightGearCopilotSkill(MycroftSkill): wait_while_speaking() response = self.get_response("dummy") if response != None: - match = re.search("yes|afirm|ok", response, re.I) + match = re.search("yes|affirm|ok", response, re.I) if match != None: self.settings['host'] = host self.speak("New host " + self.settings['host'] + " is set") @@ -1013,6 +989,18 @@ class FlightGearCopilotSkill(MycroftSkill): self.speak("I haven't found any running flightgear on port " + str(self.settings['port'])) + # load the default profile config + @intent_handler(IntentBuilder('Load DefaultProfilesIntent').require('load.default.profile')) + def handle_load_default_profile_intent(self, message): + self.speak("This will remove all profiles what you have added. Do you want to continue?") + wait_while_speaking() + response = self.get_response("dummy") + if response != None: + match = re.search("yes|affirm|ok", response, re.I) + if match != None: + self.write_default_profiles() + self.speak("Profiles reseted") + ################################################################# # # # Help functions # @@ -1072,6 +1060,144 @@ class FlightGearCopilotSkill(MycroftSkill): s.close() return IP + # write the defaults to the settings.json file + def write_default_profiles(self): + +# DEFINITION of the settings['profiles'] structure +# [ +# { +# "name": "", +# "acid": +# [ +# " can be found in /???", +# ... +# ], +# flaps: +# [ +# { +# "id": " can be up|down|full|number", +# "min-spd": "", +# "max-spd": "", +# "value": "" +# }, +# ... +# ] +# "flaps-path": "" +# "gear-retractable": "" +# }, +# ... +# ] + profiles = [] + + ################# + # Airbus A320 # + ################# + profile = {} + profile['name'] = "Airbus A320" + profile['gear-retractable'] = "true" + profile['flaps-path'] = "/controls/flight/flap-lever" + + # ACIDs + profile['acid'] = [] + profile['acid'].append("A320-200-CFM") + profile['acid'].append("A320-200-IAE") + profile['acid'].append("A320-100-CFM") + profile['acid'].append("A320neo-CFM") + profile['acid'].append("A320neo-PW") + + # Flaps settings + profile['flaps'] = [] + + # TODO use real min speeds + + # Flaps up + flaps = {} + flaps['id'] = "up" + flaps['min-spd'] = 210 + flaps['max-spd'] = 350 + flaps['value'] = 0 + profile['flaps'].append(flaps) + + # Flaps 1 + flaps = {} + flaps['id'] = 1 + flaps['min-spd'] = 180 + flaps['max-spd'] = 230 + flaps['value'] = 0 + profile['flaps'].append(flaps) + + # Flaps 2 + flaps = {} + flaps['id'] = 2 + flaps['min-spd'] = 165 + flaps['max-spd'] = 200 + flaps['value'] = 0 + profile['flaps'].append(flaps) + + # Flaps 3 + flaps = {} + flaps['id'] = 3 + flaps['min-spd'] = 150 + flaps['max-spd'] = 185 + flaps['value'] = 0 + profile['flaps'].append(flaps) + + # Flaps full + flaps = {} + flaps['id'] = "full" + flaps['min-spd'] = 140 + flaps['max-spd'] = 177 + flaps['value'] = 0 + profile['flaps'].append(flaps) + + profiles.append(profile) + + ################# + # c172p # + ################# + profile = {} + profile['name'] = "c172p" + profile['gear-retractable'] = "false" + profile['flaps-path'] = "" # TODO set correct value + + # ACIDs + profile['acid'] = [] + profile['acid'].append("c172p") + + # Flaps settings + profile['flaps'] = [] + + # TODO use real speeds + + # Flaps up + flaps = {} + flaps['id'] = "up" + flaps['min-spd'] = 54 + flaps['max-spd'] = 300 + flaps['value'] = 0 # TODO set correct value + profile['flaps'].append(flaps) + + # Flaps 1 + flaps = {} + flaps['id'] = 1 + flaps['min-spd'] = 48 + flaps['max-spd'] = 110 + flaps['value'] = 0 # TODO set correct value + profile['flaps'].append(flaps) + + # Flaps down + flaps = {} + flaps['id'] = "down" + flaps['min-spd'] = 43 + flaps['max-spd'] = 85 + flaps['value'] = 0 # TODO set correct value + profile['flaps'].append(flaps) + + profiles.append(profile) + + self.settings['profiles'] = profiles + pass + # exit routine to properly close the tn con def exit(self, tn): tn.close