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 ChangeColorPage()
        {
            InitializeComponent();

            if (App.CurrentConnection != null)
            {
                MessageBox.Show(string.Format("Connected to {0}", App.CurrentConnection.BluetoothName));
                _spheroDevice = new SpheroDevice(App.CurrentConnection);
            }
            else
                NavigationService.GoBack();
        }
Exemple #3
0
        public DrivePage()
        {
            InitializeComponent();

            if (App.CurrentConnection != null)
            {
                MessageBox.Show(string.Format("Connected to {0}", App.CurrentConnection.BluetoothName));
                _spheroDevice = new SpheroDevice(App.CurrentConnection);
                _spheroDevice.SetBackLED(1.0f);
                spheroJoystick.Start();
            }
            else
                NavigationService.GoBack();
        }
Exemple #4
0
        public GamePlayPage()
        {
            this.InitializeComponent();
            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += navigationHelper_LoadState;
            this.navigationHelper.SaveState += navigationHelper_SaveState;

            //Initizlizes Bluetooth connection
            if (App.CurrentConnection != null)
            {
                _spheroDevice = new SpheroDevice(App.CurrentConnection);
                _spheroDevice.SetBackLED(1.0f);
                spheroJoystick.Start();
            }

        }
        public CalibrationPage()
        {
            InitializeComponent();

            if (App.CurrentConnection != null)
            {
                _spheroDevice = new SpheroDevice(App.CurrentConnection);

                // OFF Stabilization et set LEDs
                _spheroDevice.StabilizationOFF();
                _spheroDevice.SetRGBLED(0.5f, 0, 0);
                _spheroDevice.SetBackLED(1.0f);
            }
            else
                NavigationService.GoBack();
        }
Exemple #6
0
        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();
        }
        public IMUReadingPage()
        {
            InitializeComponent();

            if (App.CurrentConnection != null)
            {
                MessageBox.Show(string.Format("Connected to {0}", App.CurrentConnection.BluetoothName));
                _spheroDevice = new SpheroDevice(App.CurrentConnection);

                // Initialize SensorData streaming Masks
                _spheroDevice.SetDataStreaming(20, 1, Masks.FilteredIMU, 1);

                // Subscribe to SensorData event
                _spheroDevice.SensorDataNotification += _spheroDevice_SensorDataNotification;
            }
            else
                NavigationService.GoBack();
        }
Exemple #8
0
        public DrivePage()
        {
            InitializeComponent();

            if (App.CurrentConnection != null)
            {
                MessageBox.Show(string.Format("Connected to {0}", App.CurrentConnection.BluetoothName));
                _spheroDevice = new SpheroDevice(App.CurrentConnection);
                _spheroDevice.SetBackLED(1.0f);

                // Configure collision detection and subscribe to detection event
                _spheroDevice.ConfigureCollisionDetection(CollisionMethod.Enable, 125, 125, 125, 125, 50);
                _spheroDevice.CollisionDetected += _spheroDevice_CollisionDetected;

                spheroJoystick.Start();
            }
            else
                NavigationService.GoBack();
        }
Exemple #9
0
 internal void SetSphero(SpheroDevice sphero)
 {
     this._sphero = sphero;
 }