private bool Initialize() { if (!_initialized) { try { // initialize PiCar _piCar = PiCarClientFactory.CreatePiCar(_controlTopic.Server, _controlTopic.Credential); if (_piCar != null) { _piCar.Initialize(_controlTopic.ServerAddress, _controlTopic.VideoPort); _cameraHorizontalServo = new ServoStat { Servo = _piCar.HeadHorizontalServo }; _cameraVertialServo = new ServoStat { Servo = _piCar.HeadVerticalServo }; _rightLed = new LedState { Led = _piCar.RightLed }; _leftLed = new LedState { Led = _piCar.LeftLed }; // initialize AppServiceHost DeviceSettings settings = DeviceSettings.Instance; _host = new AppServiceHost(settings.ServerPrefix, settings.ServiceRootPath, settings.ServiceActionRootPath, settings.ServiceCredentials); _host.Init(); _initialized = true; } } catch (Exception err) { responseLabel.Text = "Failed to initialize PiCar \n" + err.ToString(); } } if (_initialized) { CommandButton.IsEnabled = true; GpioButton.IsEnabled = true; ServiceOnOffButton.IsEnabled = true; } else { CommandButton.IsEnabled = false; GpioButton.IsEnabled = false; ServiceOnOffButton.IsEnabled = false; } return(_initialized); }
private async void ChangingServoAngle(ServoStat servo, int increment) { servo.ButtonPressed = true; while (servo.ButtonPressed) { string msg = servo.Servo.GoBy(increment); DisplayServerStatus(msg); await Task.Run(async() => { await Task.Delay(500); // in milliseconds }).ConfigureAwait(true); } }