Exemplo n.º 1
0
        /// <summary>
        /// Parses a standard button report into the ButtonState struct
        /// </summary>
        /// <param name="buff">Data buffer</param>
        protected int ParseButtons(byte[] buff, int offset)
        {
            WiimoteButtons buttons =
                ((buff[offset + 1] & 0x08) == 0 ? WiimoteButtons.None : WiimoteButtons.A) |
                ((buff[offset + 1] & 0x04) == 0 ? WiimoteButtons.None : WiimoteButtons.B) |
                ((buff[offset + 1] & 0x10) == 0 ? WiimoteButtons.None : WiimoteButtons.Minus) |
                ((buff[offset + 1] & 0x80) == 0 ? WiimoteButtons.None : WiimoteButtons.Home) |
                ((buff[offset + 0] & 0x10) == 0 ? WiimoteButtons.None : WiimoteButtons.Plus) |
                ((buff[offset + 1] & 0x02) == 0 ? WiimoteButtons.None : WiimoteButtons.One) |
                ((buff[offset + 1] & 0x01) == 0 ? WiimoteButtons.None : WiimoteButtons.Two) |
                ((buff[offset + 0] & 0x08) == 0 ? WiimoteButtons.None : WiimoteButtons.Up) |
                ((buff[offset + 0] & 0x04) == 0 ? WiimoteButtons.None : WiimoteButtons.Down) |
                ((buff[offset + 0] & 0x01) == 0 ? WiimoteButtons.None : WiimoteButtons.Left) |
                ((buff[offset + 0] & 0x02) == 0 ? WiimoteButtons.None : WiimoteButtons.Right);

            _Buttons = buttons;
            return(2);
        }
Exemplo n.º 2
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            IWiimote wiimote = (IWiimote)sender;

            Console.WriteLine("The following buttons are held down: {0}", wiimote.Buttons);

            // To check if button 'A' is held down, we can do the following.
            // Note: this might look strange, but this is how C# works with flagged enumerations. 'WiimoteButtons' is a flagged enumeration.
            if ((wiimote.Buttons & WiimoteButtons.A) != WiimoteButtons.None)
            {
                Console.WriteLine("Button A is held down.");
            }

            // Here's an example of how to check if buttons were just pressed or released?
            // To understand what is happening here, some knowledge of flagged enumerations is required.
            WiimoteButtons changedButtons  = oldWiimoteButtons ^ wiimote.Buttons;
            WiimoteButtons pressedButtons  = changedButtons & wiimote.Buttons;
            WiimoteButtons releasedButtons = changedButtons & oldWiimoteButtons;

            oldWiimoteButtons = wiimote.Buttons;
        }
Exemplo n.º 3
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            IWiimote wiimote = (IWiimote)sender;

            Console.WriteLine("The following buttons are held down: {0}", wiimote.Buttons);

            // To check if button 'A' is held down, we can do the following.
            // Note: this might look strange, but this is how C# works with flagged enumerations. 'WiimoteButtons' is a flagged enumeration.
            if ((wiimote.Buttons & WiimoteButtons.A) != WiimoteButtons.None)
            {
                Console.WriteLine("Button A is held down.");
            }

            // Here's an example of how to check if buttons were just pressed or released?
            // To understand what is happening here, some knowledge of flagged enumerations is required.
            WiimoteButtons changedButtons = oldWiimoteButtons ^ wiimote.Buttons;
            WiimoteButtons pressedButtons = changedButtons & wiimote.Buttons;
            WiimoteButtons releasedButtons = changedButtons & oldWiimoteButtons;
            oldWiimoteButtons = wiimote.Buttons;
        }
Exemplo n.º 4
0
 public bool button_pressed(WiimoteButtons b)
 {
     return(buttonPressed.IsPressed(b));
 }
Exemplo n.º 5
0
 public bool button_down(WiimoteButtons b, bool value = false)
 {
     return(data.IsButtonPressed(b));
 }
Exemplo n.º 6
0
 public bool button_down(WiimoteButtons b)
 {
     return(data.IsButtonPressed(b));
 }
Exemplo n.º 7
0
        public bool IsButtonPressed(WiimoteButtons b)
        {
            UInt16 value = (UInt16)b;

            return((data.button_state & value) == value);
        }
Exemplo n.º 8
0
 public bool IsButtonPressed(WiimoteButtons b)
 {
     UInt16 value = (UInt16)b;
     return (data.button_state & value) == value;
 }
Exemplo n.º 9
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            // There are several reporting modes that provide ir information. Choosing the
            // right one depends on the desired level of ir accuracy and other device information that is required.
            // The ir device has three different accuracy levels:
            // 1. Buttons10Ir9Extension / ButtonsAcceleromter10Ir6Extension provide the lowest level of accuracy,
            //    but also provide more information about other parts of the wiimote.
            // 2. ButtonsAccelerometer12Ir provides an increased level of accuracy
            //    by supplying additional data (the size of the beacon) at the cost of extension information.
            // 3. ButtonsAccelerometer36Ir provides the highest level of accuracy
            //    by supplying the intensity and the ... of the beacons
            //    but it is delivered in two seperate messages and is therefore two times slower than the other modes.

            IWiimote wiimote = (IWiimote)sender;

            switch (wiimote.ReportingMode)
            {
                case ReportingMode.Buttons10Ir9Extension:
                case ReportingMode.ButtonsAccelerometer10Ir6Extension:
                    Console.WriteLine("Basic IR ({0})", wiimote.ReportingMode);
                    foreach (BasicIRBeacon beacon in wiimote.IRBeacons)
                    {
                        // When a beacon is not found, the value will be null.
                        if (beacon != null)
                            Console.WriteLine("BasicBeacon: X={0} Y={1}", beacon.X, beacon.Y);
                    }
                    break;
                case ReportingMode.ButtonsAccelerometer12Ir:
                    Console.WriteLine("Extended IR ({0})", wiimote.ReportingMode);
                    foreach (ExtendedIRBeacon beacon in wiimote.IRBeacons)
                    {
                        if (beacon != null)
                            Console.WriteLine("ExtendedBeacon: X={0} Y={1} Size={2}", beacon.X, beacon.Y, beacon.Size);
                    }
                    break;
                case ReportingMode.ButtonsAccelerometer36Ir:
                    Console.WriteLine("Full IR ({0})", wiimote.ReportingMode);
                    foreach (FullIRBeacon beacon in wiimote.IRBeacons)
                    {
                        if (beacon != null)
                            Console.WriteLine("FullBeacon: X={0} Y={1} Size={2} XMin={3} XMax={4} YMin={5} YMax={6} Intensity={7}",
                            beacon.X, beacon.Y, beacon.Size, beacon.XMin, beacon.XMax, beacon.YMin, beacon.YMax, beacon.Intensity);
                    }
                    break;
            }

            // The following code is not part of the example, it is merely to switch between the different ReportingModes.
            WiimoteButtons changedButtons = oldWiimoteButtons ^ wiimote.Buttons;
            WiimoteButtons pressedButtons = changedButtons & wiimote.Buttons;
            oldWiimoteButtons = wiimote.Buttons;

            if((pressedButtons & WiimoteButtons.Plus) != WiimoteButtons.None)
            {
                modeIndex = (modeIndex + 1) % 4;
                wiimote.SetReportingMode(irReportingModes[modeIndex]);
            }
            if((pressedButtons & WiimoteButtons.Minus) != WiimoteButtons.None)
            {
                modeIndex = ((modeIndex - 1) + 4) % 4;
                wiimote.SetReportingMode(irReportingModes[modeIndex]);
            }
        }
Exemplo n.º 10
0
 public bool button_pressed(WiimoteButtons b)
 {
     return buttonPressed.IsPressed(b);
 }
Exemplo n.º 11
0
 public bool button_down(WiimoteButtons b)
 {
     return data.IsButtonPressed(b);
 }
Exemplo n.º 12
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            // There are several reporting modes that provide ir information. Choosing the
            // right one depends on the desired level of ir accuracy and other device information that is required.
            // The ir device has three different accuracy levels:
            // 1. Buttons10Ir9Extension / ButtonsAcceleromter10Ir6Extension provide the lowest level of accuracy,
            //    but also provide more information about other parts of the wiimote.
            // 2. ButtonsAccelerometer12Ir provides an increased level of accuracy
            //    by supplying additional data (the size of the beacon) at the cost of extension information.
            // 3. ButtonsAccelerometer36Ir provides the highest level of accuracy
            //    by supplying the intensity and the ... of the beacons
            //    but it is delivered in two seperate messages and is therefore two times slower than the other modes.

            IWiimote wiimote = (IWiimote)sender;

            switch (wiimote.ReportingMode)
            {
            case ReportingMode.Buttons10Ir9Extension:
            case ReportingMode.ButtonsAccelerometer10Ir6Extension:
                Console.WriteLine("Basic IR ({0})", wiimote.ReportingMode);
                foreach (BasicIRBeacon beacon in wiimote.IRBeacons)
                {
                    // When a beacon is not found, the value will be null.
                    if (beacon != null)
                    {
                        Console.WriteLine("BasicBeacon: X={0} Y={1}", beacon.X, beacon.Y);
                    }
                }
                break;

            case ReportingMode.ButtonsAccelerometer12Ir:
                Console.WriteLine("Extended IR ({0})", wiimote.ReportingMode);
                foreach (ExtendedIRBeacon beacon in wiimote.IRBeacons)
                {
                    if (beacon != null)
                    {
                        Console.WriteLine("ExtendedBeacon: X={0} Y={1} Size={2}", beacon.X, beacon.Y, beacon.Size);
                    }
                }
                break;

            case ReportingMode.ButtonsAccelerometer36Ir:
                Console.WriteLine("Full IR ({0})", wiimote.ReportingMode);
                foreach (FullIRBeacon beacon in wiimote.IRBeacons)
                {
                    if (beacon != null)
                    {
                        Console.WriteLine("FullBeacon: X={0} Y={1} Size={2} XMin={3} XMax={4} YMin={5} YMax={6} Intensity={7}",
                                          beacon.X, beacon.Y, beacon.Size, beacon.XMin, beacon.XMax, beacon.YMin, beacon.YMax, beacon.Intensity);
                    }
                }
                break;
            }

            // The following code is not part of the example, it is merely to switch between the different ReportingModes.
            WiimoteButtons changedButtons = oldWiimoteButtons ^ wiimote.Buttons;
            WiimoteButtons pressedButtons = changedButtons & wiimote.Buttons;

            oldWiimoteButtons = wiimote.Buttons;

            if ((pressedButtons & WiimoteButtons.Plus) != WiimoteButtons.None)
            {
                modeIndex = (modeIndex + 1) % 4;
                wiimote.SetReportingMode(irReportingModes[modeIndex]);
            }
            if ((pressedButtons & WiimoteButtons.Minus) != WiimoteButtons.None)
            {
                modeIndex = ((modeIndex - 1) + 4) % 4;
                wiimote.SetReportingMode(irReportingModes[modeIndex]);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Parses a standard button report into the ButtonState struct
 /// </summary>
 /// <param name="buff">Data buffer</param>
 protected int ParseButtons(byte[] buff, int offset)
 {
     WiimoteButtons buttons =
         ((buff[offset + 1] & 0x08) == 0 ? WiimoteButtons.None : WiimoteButtons.A) |
         ((buff[offset + 1] & 0x04) == 0 ? WiimoteButtons.None : WiimoteButtons.B) |
         ((buff[offset + 1] & 0x10) == 0 ? WiimoteButtons.None : WiimoteButtons.Minus) |
         ((buff[offset + 1] & 0x80) == 0 ? WiimoteButtons.None : WiimoteButtons.Home) |
         ((buff[offset + 0] & 0x10) == 0 ? WiimoteButtons.None : WiimoteButtons.Plus) |
         ((buff[offset + 1] & 0x02) == 0 ? WiimoteButtons.None : WiimoteButtons.One) |
         ((buff[offset + 1] & 0x01) == 0 ? WiimoteButtons.None : WiimoteButtons.Two) |
         ((buff[offset + 0] & 0x08) == 0 ? WiimoteButtons.None : WiimoteButtons.Up) |
         ((buff[offset + 0] & 0x04) == 0 ? WiimoteButtons.None : WiimoteButtons.Down) |
         ((buff[offset + 0] & 0x01) == 0 ? WiimoteButtons.None : WiimoteButtons.Left) |
         ((buff[offset + 0] & 0x02) == 0 ? WiimoteButtons.None : WiimoteButtons.Right);
     _Buttons = buttons;
     return 2;
 }