コード例 #1
0
        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");
        }
コード例 #2
0
ファイル: MacroPage.xaml.cs プロジェクト: xesf/sphero-sdk
        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();
            }
        }