async Task <bool> TryConnectToLemuria(string ip) { var hasConnected = false; try { IPAddress = ip; var hubConnection = new HubConnection(ip); LemurianHub = hubConnection.CreateHubProxy("LemuriaHub"); LemurianHub.On <bool>("NotifyTopLeftIR", NotifyTopLeftIRCallback); LemurianHub.On <bool>("NotifyTopRightIR", NotifyTopRightIRCallback); LemurianHub.On <bool>("NotifyBottomLeftIR", NotifyBottomLeftIRCallback); LemurianHub.On <bool>("NotifyBottomRightIR", NotifyBottomRightIRCallback); LemurianHub.On <double>("NotifySonarDistance", NotifySonarDistanceCallback); LemurianHub.On <double, double>("NotifyTemperatureHumidity", NotifyTemperatureHumidityCallback); await hubConnection.Start(new LongPollingTransport()); // Start the Lemuria hasConnected = await LemurianHub.Invoke <bool>("LemurianSignal", "master"); } catch (Exception) { hasConnected = false; } return(hasConnected); }
private async void ConnectButton_Click(object sender, RoutedEventArgs e) { var ip = ""; if (IPAddressText.Text == "" || IPAddressText.Text == "default") { ip = IPAddress; } else { ip = IPAddressText.Text; } ConnectStatusText.Text = "Loading..."; if (await TryConnectToLemuria(ip)) { SelectPage("main"); CoreWindow.GetForCurrentThread().KeyDown += MainPage_KeyDown; CoreWindow.GetForCurrentThread().KeyUp += MainPage_KeyUp; UpdateSettingsPage(await LemurianHub.Invoke <SettingsModels>("GetLemurianSettings", "master")); ConnectStatusText.Text = "Connect to the server"; } else { ConnectStatusText.Text = "Please check the IP Address and try again"; } }
// Motor private async void StartMotorBSpeed_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { await LemurianHub.Invoke <bool>("SetStartMotorBSpeed", (int)e.NewValue); }
private async void TopLeftIRSensor_Toggled(object sender, RoutedEventArgs e) { UpdateIRStatus(); await LemurianHub.Invoke <bool>("SetTopLeftIRSensor", ((ToggleSwitch)sender).IsOn); }
private async void FrontSonarSensor_Toggled(object sender, RoutedEventArgs e) { await LemurianHub.Invoke <bool>("SetFrontSonarSensor", ((ToggleSwitch)sender).IsOn); }
// Temperature private async void TemperatureHumiditySensor_Toggled(object sender, RoutedEventArgs e) { await LemurianHub.Invoke <bool>("SetTemperatureHumiditySensor", ((ToggleSwitch)sender).IsOn); }
// Face detection private async void FaceDetectionCamera_Toggled(object sender, RoutedEventArgs e) { await LemurianHub.Invoke <bool>("SetFaceDetectionCamera", ((ToggleSwitch)sender).IsOn); }
private async void LemurianMove(string direction, MotorSpeedModels speed) { // Send this data to the Server await LemurianHub.Invoke("LemurianMove", new object[] { direction, speed }); }