public async Task Start() { var spheros = await SpheroConnectionProvider.DiscoverSpheros(); var sphero = spheros.FirstOrDefault(); if (sphero != null) { var connection = await SpheroConnectionProvider.CreateConnection(sphero); if (connection != null) { connection.OnDisconnection += () => Tracer.Trace("Sphero disconnected"); _device = new SpheroDevice(connection); Tracer.Trace("Sphero connected"); _device.ReinitMacroExecutive(response => { if (response == MessageResponseCode.ORBOTIX_RSP_CODE_OK) { var flipMacro = new Macro(MacroType.Permanent, FLIP_MACRO); flipMacro.Commands.Add(new SendRawMotorMacroCommand { LeftMode = MotorMode.Forward, LeftPower = 255, RightMode = MotorMode.Forward, RightPower = 255, PCD = 255 }); flipMacro.Commands.Add(new DelayMacroCommand { Time = 150 }); flipMacro.Commands.Add(new SendRawMotorMacroCommand { LeftMode = MotorMode.Off, LeftPower = 0, RightMode = MotorMode.Off, RightPower = 0, PCD = 255 }); flipMacro.Commands.Add(new SetStabilizationMacroCommand { Flag = StabilizationStatus.OnWithoutReset, PCD = 255 }); _device.SaveMacro(flipMacro, null); Tracer.Trace("Flip macro stored"); } }); return; } } Tracer.Error("Sphero not found"); }
public MacroPage() { InitializeComponent(); if (App.CurrentConnection != null) { MessageBox.Show(string.Format("Connected to {0}", App.CurrentConnection.BluetoothName)); _spheroDevice = new SpheroDevice(App.CurrentConnection); _spheroDevice.ReinitMacroExecutive(response => { if (response == MessageResponseCode.ORBOTIX_RSP_CODE_OK) { Macro flipMacro = new Macro(MacroType.Permanent, 102); flipMacro.Commands.Add(new SendRawMotorMacroCommand { LeftMode = MotorMode.Forward, LeftPower = 255, RightMode = MotorMode.Forward, RightPower = 255, PCD = 255 }); flipMacro.Commands.Add(new DelayMacroCommand { Time = 150 }); flipMacro.Commands.Add(new SendRawMotorMacroCommand { LeftMode = MotorMode.Off, LeftPower = 0, RightMode = MotorMode.Off, RightPower = 0, PCD = 255 }); flipMacro.Commands.Add(new SetStabilizationMacroCommand { Flag = StabilizationStatus.OnWithoutReset, PCD = 255 }); _spheroDevice.SaveMacro(flipMacro, null); } }); } else { NavigationService.GoBack(); } }