static void wiimote_ExtensionAttached(object sender, WiimoteExtensionEventArgs e)
 {
     IWiimote wiimote = (IWiimote)sender;
     
     // We can retrieve the attached extension by doing the following:
     IWiimoteExtension extension = e.Extension;
     // The extension is also available through 'wiimote.Extension'.
     
     // Here we can check what type of extension the attached extension is.
     // In this example we will only cover the Nunchuk, but we can also check for other available extensions.
     if (extension is NunchukExtension)
     {
         wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer16Extension);
         Console.WriteLine("A nunchuk attached to the Wiimote.");
     }
     // A few 'dummy-extensions' are available to detect various undefined situations.
     else if (extension is InvalidExtension)
     {
         Console.WriteLine("An extension was partially connected or the extension was erroneous.");
     }
     
     // UnknownExtension is a dummy-extension that that the attached extension
     // is not supported by Wii Device Library (or any other extension that is registered in WiimoteExtensionRegistry).
     else if (extension is UnknownExtension)
     {
         Console.WriteLine("An extension was connected, but was not recognized by Wii Device Library.");
     }
     else
     {
         Console.WriteLine("An extension was connected, but was not recognized by this example.");
     }
     wiimote.SetReportingMode(wiimote.ReportingMode);
 }
Exemple #2
0
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            wiimote.Updated += wiimote_Updated;

            // In this example we will need Accelerometer-data. For this, we change the ReportingMode to ButtonsAccelerometer.
            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer);
        }
 static void OnWiimoteConnected(IWiimote wiimote)
 {
     wiimote.Updated += wiimote_Updated;
     wiimote.ExtensionAttached += wiimote_ExtensionAttached;
     wiimote.ExtensionDetached += wiimote_ExtensionDetached;
     
     wiimote.SetReportingMode(ReportingMode.Buttons10Ir9Extension);
 }
 static void wiimote_ExtensionDetached(object sender, WiimoteExtensionEventArgs e)
 {
     IWiimote wiimote = (IWiimote)sender;
     IWiimoteExtension extension = e.Extension;
     if (extension is NunchukExtension)
     {
         Console.WriteLine("A nunchuk was detached from the Wiimote.");
     }
     wiimote.SetReportingMode(wiimote.ReportingMode);
 }
        private void CalibrateWiimote()
        {
            IWiimote      wiimote          = (IWiimote)Device;
            ReportingMode oldReportingMode = wiimote.ReportingMode;

            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer);
            AccelerometerAxes <ushort> raw = wiimote.Accelerometer.Raw;

            Gtk.MessageDialog dialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Info, Gtk.ButtonsType.OkCancel, false, "Place the wiimote on a table.", new object[0]);
            if (dialog.Run() == -5)
            {
                ushort xZero, yZero, zZero, xOne, yOne, zOne = 0;
                xZero         = raw.X;
                yZero         = raw.Y;
                zOne          = raw.Z;
                dialog.Markup = "Place the wiimote on its left side.";
                if (dialog.Run() == -5)
                {
                    xOne  = raw.X;
                    zZero = raw.Z;

                    // Invert zOne (so that the values are negated).
                    zOne = (ushort)(zZero - (zOne - zZero));

                    dialog.Markup = "Place the wiimote on its lower side, so that it points up.";
                    if (dialog.Run() == -5)
                    {
                        yOne = raw.Y;

                        wiimote.WriteMemory(0x16, new byte[] {
                            (byte)xZero, (byte)yZero, (byte)zZero, 0,
                            (byte)xOne, (byte)yOne, (byte)zOne, 0
                        }, 0, 8);

                        wiimote.Initialize();
                    }
                }
            }
            dialog.Destroy();
            wiimote.SetReportingMode(oldReportingMode);
        }
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            // To be informed about changes of the wiimote's status, we can use the Updated event:
            wiimote.Updated += wiimote_Updated;

            // The ReportingMode is the way the Wiimote keeps us up-to-date. With this value,
            // we can change what data we would like to receive and how precise this data is.

            // In this example we will demonstrate that changing the ReportingMode of the Wiimote, will result in different behaviour of updates.
            // We are changing the ReportingMode from 'Buttons' to 'ButtonsAccelerometer10Ir6Extension'.
            // This mode means that we will receive updates about changes in the button-state, accelerometer-state, ir-state and extension-state.
            // This will result in many updates and cause a 'stream' of data.
            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer10Ir6Extension);
        }
Exemple #7
0
        private void calibrateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IWiimote      wiimote          = Wiimote;
            ReportingMode oldReportingMode = wiimote.ReportingMode;

            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer);
            AccelerometerAxes <ushort> raw = wiimote.Accelerometer.Raw;

            if (MessageBox.Show("Place the wiimote on a table.", "Calibration", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                ushort xZero, yZero, zZero, xOne, yOne, zOne = 0;
                xZero = raw.X;
                yZero = raw.Y;
                zOne  = raw.Z;
                if (MessageBox.Show("Place the wiimote on its left side.", "Calibration", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    xOne  = raw.X;
                    zZero = raw.Z;

                    // Invert zOne (so that the values are negated).
                    zOne = (ushort)(zZero - (zOne - zZero));

                    if (MessageBox.Show("Place the wiimote on its lower side, so that it points up.", "Calibration", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        yOne = raw.Y;

                        wiimote.WriteMemory(0x16, new byte[] {
                            (byte)xZero, (byte)yZero, (byte)zZero, 0,
                            (byte)xOne, (byte)yOne, (byte)zOne, 0
                        }, 0, 8);

                        wiimote.Initialize();
                    }
                }
            }
            wiimote.SetReportingMode(oldReportingMode);
        }
 protected virtual void OnComboboxReportingModeChanged(object sender, System.EventArgs e)
 {
     foreach (ReportingMode reportingMode in Enum.GetValues(typeof(ReportingMode)))
     {
         if (reportingMode == ReportingMode.None)
         {
             continue;
         }
         if (comboboxReportingMode.ActiveText == reportingMode.ToString())
         {
             if (reportingMode != _Wiimote.ReportingMode)
             {
                 _Wiimote.SetReportingMode(reportingMode);
             }
         }
     }
 }
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            // To be informed about changes of the wiimote's status, we can use the Updated event:
            wiimote.Updated += wiimote_Updated;

            // The ReportingMode is the way the Wiimote keeps us up-to-date. With this value,
            // we can change what data we would like to receive and how precise this data is.

            // In this example we will demonstrate that changing the ReportingMode of the Wiimote, will result in different behaviour of updates.
            // We are changing the ReportingMode from 'Buttons' to 'ButtonsAccelerometer10Ir6Extension'.
            // This mode means that we will receive updates about changes in the button-state, accelerometer-state, ir-state and extension-state.
            // This will result in many updates and cause a 'stream' of data.
            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer10Ir6Extension);
        }
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            wiimote.Updated += wiimote_Updated;

            // In this example we will need Accelerometer-data. For this, we change the ReportingMode to ButtonsAccelerometer.
            wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer);
        }
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            wiimote.Updated += wiimote_Updated;
            wiimote.ExtensionAttached += wiimote_ExtensionAttached;
            wiimote.ExtensionDetached += wiimote_ExtensionDetached;

            wiimote.SetReportingMode(ReportingMode.Buttons10Ir9Extension);
        }
Exemple #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]);
            }
        }