예제 #1
0
        private void btnRainbow_Click(object sender, RoutedEventArgs e)
        {
            Macro rainbowMacro = new Macro(MacroType.Temporary, 255);
           
            rainbowMacro.Commands.Add(new LoopStartMacroCommand() { Count = 5 });
            rainbowMacro.Commands.Add(new FadeToLEDOverTimeMacroCommand()
            {
                Red = 0xFF,
                Green = 0,
                Blue = 0,
                Time = 200
            });
            rainbowMacro.Commands.Add(new DelayMacroCommand { Time = 200 });
            rainbowMacro.Commands.Add(new FadeToLEDOverTimeMacroCommand()
            {
                Red = 0xFF,
                Green = 0x7E,
                Blue = 0x6D,
                Time = 200
            });
            rainbowMacro.Commands.Add(new DelayMacroCommand { Time = 200 });
            rainbowMacro.Commands.Add(new FadeToLEDOverTimeMacroCommand()
            {
                Red = 0x7F,
                Green = 0xFF,
                Blue = 0x00,
                Time = 200
            });
            rainbowMacro.Commands.Add(new DelayMacroCommand { Time = 200 });
            rainbowMacro.Commands.Add(new FadeToLEDOverTimeMacroCommand()
            {
                Red = 0x00,
                Green = 0xFF,
                Blue = 0x00,
                Time = 200
            });
            rainbowMacro.Commands.Add(new DelayMacroCommand { Time = 200 });
            rainbowMacro.Commands.Add(new FadeToLEDOverTimeMacroCommand()
            {
                Red = 0xDE,
                Green = 0x00,
                Blue = 0xFF,
                Time = 200
            });
            rainbowMacro.Commands.Add(new DelayMacroCommand { Time = 200 });
            rainbowMacro.Commands.Add(new LoopEndMacroCommand());

            
            _spheroDevice.SaveTemporaryMacro(rainbowMacro, response =>
            {
                if(response == MessageResponseCode.ORBOTIX_RSP_CODE_OK)
                {
                    _spheroDevice.RunTemporaryMacro(null);
                }
            });
        }
예제 #2
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");
        }
예제 #3
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();
        }
예제 #4
0
        public void Spin()
        {
            if (_device == null)
            {
                throw new InvalidOperationException("Sphero not connected yet...");
            }

            //_device.RunMacro(FLIP_MACRO, null);

            var spinMacro = new Macro(MacroType.Temporary, 255);
            spinMacro.Commands.Add(new LoopStartMacroCommand
            {
                Count = 30
            });
            spinMacro.Commands.Add(new RotateOverTimeMacroCommand
            {
                Angle = 360,
                Time = 200
            });
            spinMacro.Commands.Add(new DelayMacroCommand
            {
                Time = 200
            });
            spinMacro.Commands.Add(new LoopEndMacroCommand { });


            _device.SaveTemporaryMacro(spinMacro, response =>
            {
                if (response == MessageResponseCode.ORBOTIX_RSP_CODE_OK)
                {
                    _device.RunTemporaryMacro(code => Tracer.Trace($"RunTemporaryMacro {code}"));
                }
            });
        }
예제 #5
0
 /// <summary>
 /// This stores the attached macro definition into the temporary RAM buffer for later execution.
 /// </summary>
 /// <param name="macro">Macro to save temporary</param>
 public void SaveTemporaryMacro(Macro macro, Action<MessageResponseCode> callback)
 {
     CommandPacket command = new CommandPacket(0xFF, DeviceIDs.SPHERO, CommandIDs.Sphero.SAVE_TEMPORARY_MACRO, macro.ToArray());
     _connection.SendCommand(command, response =>
     {
         if(callback != null)
         {
             callback(response.ResponseCode);
         }
     });
 }