/// <summary> /// Start a new control command and sends it /// </summary> /// <returns></returns> private bool NewControlCmd() { //Change the user interface if (SzenarioController.Changed) { foreach (var t in RobotController.Robots) { if (Convert.ToInt32(Robot.Identification.Id) != t.Identification.Id) { continue; } Robot = new RobotModel(t); break; } SzenarioController.Changed = false; } if (!SzenarioController.Refresh) { //stop sensors CrossDeviceMotion.Current.Stop(MotionSensorType.Accelerometer); //set object active -> false foreach (var t in Client.Szenario.Robots) { t.Active = false; } Client.Device.Active = false; //remove the szenario SzenarioController.Szenarios.Remove(Client.Szenario); //Send the control end command Client.Szenario.Command = ControlType.Undefinied.ToString(); var cmd = new SzenarioCommand(CommandType.Szenario.ToString(), SzenarioCommandType.End.ToString(), Client.Identification, Client.Szenario); Client.SendCmd(JsonConvert.SerializeObject(cmd)); Client.Szenario = null; //navigate to startpage var page = FreshMvvm.FreshPageModelResolver.ResolvePageModel <HomePageModel>(); var navigation = new FreshMvvm.FreshNavigationContainer(page) { BarBackgroundColor = Color.FromHex("#008B8B"), BarTextColor = Color.White }; Application.Current.MainPage = navigation; return(false); } Client.Szenario.Command = ControlType.Control.ToString(); Client.Szenario.Steering = new Steering((int)_direction, (int)_speed); var command = new SzenarioCommand(CommandType.Szenario.ToString(), Client.Szenario.Type, Client.Identification, Client.Szenario); Client.SendCmd(command.ToJsonString()); return(true); }
protected override void ViewIsDisappearing(object sender, EventArgs e) { if (!accept) { foreach (var t in Szenario.Robots) { t.Active = false; } //Send szenario end command Szenario.Command = SzenarioCommandType.Undefined.ToString(); var command = new SzenarioCommand(CommandType.Szenario.ToString(), SzenarioCommandType.End.ToString(), Client.Identification, Szenario); Client.SendCmd(command.ToJsonString()); } base.ViewIsDisappearing(sender, e); }