Ejemplo n.º 1
0
        private void btnIdentify_Click(object sender, RoutedEventArgs e)
        {
            bool wasConnected = Connected;

            if (wasConnected || ((device.DataStream as WinBtStream).OpenConnection() && device.DataStream.CanRead))
            {
                if (!wasConnected)
                {
                    device.BeginReading();
                }

                identifying          = true;
                device.RumbleEnabled = true;
                Delay(2000).ContinueWith(o =>
                {
                    identifying          = false;
                    device.RumbleEnabled = false;
                    if (!wasConnected)
                    {
                        device.StopReading();
                    }
                });

                // light show
                device.SetBinaryLEDs(0b1010);
                Delay(250).ContinueWith(o => device.SetBinaryLEDs(0b0101));
                Delay(500).ContinueWith(o => device.SetBinaryLEDs(0b1010));
                Delay(750).ContinueWith(o => device.SetBinaryLEDs(0b0101));
                Delay(1000).ContinueWith(o => device.SetBinaryLEDs(0b1010));
                Delay(1250).ContinueWith(o => device.SetBinaryLEDs(0b0101));
                Delay(1500).ContinueWith(o => device.SetBinaryLEDs(0b0000));
                if (state == DeviceState.Discovered)
                {
                    Delay(1750).ContinueWith(o => device.SetBinaryLEDs(15));
                }
                else if (targetXDevice != 0)
                {
                    Delay(1750).ContinueWith(o => device.SetPlayerLED(targetXDevice));
                }
            }
        }