private async void DiscoverSpheros() { try { // Discover paired Spheros IEnumerable <SpheroInformation> spheroInformations = await SpheroConnectionProvider.DiscoverSpheros(); if (spheroInformations != null && spheroInformations.Any()) { // Populate list with Discovered Spheros SpherosDiscovered.ItemsSource = spheroInformations; } else { // No sphero Paired MessageBox.Show("No sphero Paired"); } } catch (BluetoothDeactivatedException) { // Bluetooth deactivated MessageBox.Show("Bluetooth deactivated"); } }
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 static async Task <JediSphero> GetSpheroAsync() { IEnumerable <SpheroInformation> spheros = await SpheroConnectionProvider.DiscoverSpheros(); SpheroInformation spheroInfo = spheros.FirstOrDefault(); if (spheroInfo == null) { return(null); } SpheroConnection connection = await SpheroConnectionProvider.CreateConnection(spheroInfo); if (connection == null) { return(null); } var spheroDevice = new JediSphero(connection); return(spheroDevice); }
private async void DiscoverSpheros() { try { // Discover paired Spheros List <SpheroInformation> spheroInformations = new List <SpheroInformation>(await SpheroConnectionProvider.DiscoverSpheros()); if (spheroInformations != null && spheroInformations.Count > 0) { // Populate list with Discovered Spheros SpherosDiscovered.ItemsSource = spheroInformations; } else { // No sphero Paired MessageDialog dialogNSP = new MessageDialog("No sphero Paired"); await dialogNSP.ShowAsync(); } } catch (NoSpheroFoundException) { MessageDialog dialogNSF = new MessageDialog("No sphero Found"); dialogNSF.ShowAsync(); } catch (BluetoothDeactivatedException) { // Bluetooth deactivated MessageDialog dialogBD = new MessageDialog("Bluetooth deactivated"); dialogBD.ShowAsync(); } }