protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (await _droneClient.ConnectAsync()) { TakeOffButton.IsEnabled = true; ResetEmergencyButton.IsEnabled = true; FlatTrimButton.IsEnabled = true; TakePictureButton.IsEnabled = true; RecordVideoButton.IsEnabled = true; FlipButton.IsEnabled = true; RollPitchJoystick.StartJoystick(); YawGazJoystick.StartJoystick(); //Outlined to avoid unwanted takoff during debug //await Task.Run(async () => //{ // try // { // if (_speechRecognizer == null) // { // _speechRecognizer = new SpeechRecognizer(); // _speechRecognizer.Grammars.AddGrammarFromList("DroneCommands", new List<string> // { // "Take off", "Take off the drone", "Take the drone off", // "Land", "Land the drone" // }); // } // try // { // while (true) // { // Dispatcher.BeginInvoke(() => // { // if (TextRecognizer.Text != "Voice: listening...") // { // TextRecognizer.Foreground = new SolidColorBrush(Colors.Green); // TextRecognizer.Text = "Voice: listening..."; // } // }); // var result = await _speechRecognizer.RecognizeAsync(); // //if (result.TextConfidence == SpeechRecognitionConfidence.High) // if (result.Text.Length > 0) // { // Dispatcher.BeginInvoke(() => // { // switch (result.Text) // { // case "Take off": // case "Take off the drone": // case "Take the drone off": // _droneClient.TakeOff(); // break; // case "Land": // case "Land the drone": // _droneClient.Land(); // break; // } // }); // await Task.Delay(1000); // } // else // await Task.Delay(500); // } // } // catch (Exception ex) // { // Debug.WriteLine(ex); // } // Dispatcher.BeginInvoke(() => // { // TextRecognizer.Foreground = new SolidColorBrush(Colors.Red); // TextRecognizer.Text = "Voice: unknown"; // }); // } // catch (Exception ex) // { // Debug.WriteLine(ex); // } //}); } }