Ejemplo n.º 1
0
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            // It is recommended to always set the leds to a value, so that they will stop flashing.
            Console.WriteLine("Notice that when we are connected to the wiimote and have not yet set the leds to any value, the leds will keep on flashing.");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We set the first and fourth leds on, the rest off.
            // Notice that we only supply the leds that must be on. All others will be off.
            wiimote.Leds = WiimoteLeds.Led1 | WiimoteLeds.Led4;

            Console.WriteLine("Leds: X . . X");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We can 'add' leds that must be on.
            wiimote.Leds |= WiimoteLeds.Led3;

            Console.WriteLine("Leds: X . X X");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We can 'remove' leds that must be on.
            wiimote.Leds ^= WiimoteLeds.Led4;

            Console.WriteLine("Leds: X . X .");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            IWiimote wiimote = (IWiimote)sender;

            // The code in this method will now be called many times, since the accelerometer, ir-camera and extension are changing constantly.
            Console.WriteLine("The following buttons are held down: {0}", wiimote.Buttons);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        static void deviceProvider_DeviceFound(object sender, DeviceInfoEventArgs e)
        {
            IDeviceProvider deviceProvider = (IDeviceProvider)sender;

            Console.WriteLine("A device has been found.");
            IDeviceInfo foundDeviceInfo = e.DeviceInfo;

            IDevice device = deviceProvider.Connect(foundDeviceInfo);

            Console.WriteLine("Connected to the device.");

            device.Disconnected += device_Disconnected;

            if (device is IWiimote)
            {
                IWiimote wiimote = (IWiimote)device;
                Console.WriteLine("We have connected to a Wiimote device.");
                // Here we have access to all the operations that we can perform on a Wiimote.

                OnWiimoteConnected(wiimote);
            }

            // If we don't want to be connected to the device, we can disconnect like this:
            device.Disconnect();
        }
Ejemplo n.º 6
0
 static void OnWiimoteConnected(IWiimote wiimote)
 {
     wiimote.Updated += wiimote_Updated;
     wiimote.ExtensionAttached += wiimote_ExtensionAttached;
     wiimote.ExtensionDetached += wiimote_ExtensionDetached;
     
     wiimote.SetReportingMode(ReportingMode.Buttons10Ir9Extension);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 static void wiimote_Updated(object sender, EventArgs e)
 {
     IWiimote wiimote = (IWiimote)sender;
     if(wiimote.Extension is NunchukExtension)
     {
         NunchukExtension nunchuk = (NunchukExtension)wiimote.Extension;
         Console.Write("Buttons pushed down: {0} ",  nunchuk.Buttons);
         Console.Write("Stick: X={0,5:0.00} Y={1,5:0.00} ", nunchuk.Stick.Calibrated.X, nunchuk.Stick.Calibrated.Y);
         Console.WriteLine("Accelerometer: X={0,5:0.00} Y={1,5:0.00} Z={2,5:0.00}",  nunchuk.Accelerometer.Calibrated.X, nunchuk.Accelerometer.Calibrated.Y, nunchuk.Accelerometer.Calibrated.Z);
         
     }
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public WiimoteInformation(Gtk.Window parent, IWiimote wiimote)
        {
            _Parent  = parent;
            _Wiimote = wiimote;
            if (_Wiimote.Extension != null)
            {
                ExtensionAttached(_Wiimote, new WiimoteExtensionEventArgs(_Wiimote.Extension));
            }

            _Wiimote.ExtensionAttached += new EventHandler <WiimoteExtensionEventArgs>(ExtensionAttached);
            _Wiimote.ExtensionDetached += new EventHandler <WiimoteExtensionEventArgs>(ExtensionDetached);
            this.Build();
            foreach (ReportingMode reportingMode in Enum.GetValues(typeof(ReportingMode)))
            {
                comboboxReportingMode.AppendText(reportingMode.ToString());
            }
        }
Ejemplo n.º 11
0
        static void deviceProvider_DeviceFound(object sender, DeviceInfoEventArgs e)
        {
            IDeviceProvider deviceProvider = (IDeviceProvider)sender;

            Console.WriteLine("A device has been found.");
            IDeviceInfo foundDeviceInfo = e.DeviceInfo;

            // Example 2. Connecting to a discovered device.
            // When you connect to a discovered device, it will result in a IDevice.
            // IDevice represents the device when connected.
            Console.WriteLine("Connecting to the device...");
            IDevice device = deviceProvider.Connect(foundDeviceInfo);

            Console.WriteLine("Connected to the device.");

            // You have connected to the device,
            // and can now use 'device' to interact with the connected device.
            // Note that 'device.DeviceInfo' is refering to 'foundDeviceInfo', which we used to connect to the device.
            // We can use the Disconnected event to stay informed if we can still use the device.
            device.Disconnected += device_Disconnected;

            // When the 'device' is an 'IDevice' you can only access properties that are common to
            // all Devices (Wiimote, BalanceBoard, etc...).
            // These devices have their own types in WiiDeviceLibrary: IWiimote and IBalanceBoard. Both of these types inherit from IDevice.
            // To use properties specific to the devices you will have to cast the 'device' to the proper interface.

            // First we check if the device is the desired type.
            if (device is IWiimote)
            {
                IWiimote wiimote = (IWiimote)device;
                Console.WriteLine("We have connected to a Wiimote device.");
                // Here we have access to all the operations that we can perform on a Wiimote.
                // That's it for connecting to Wii devices.
            }
            else if (device is IBalanceBoard)
            {
                IBalanceBoard balanceboard = (IBalanceBoard)device;
                Console.WriteLine("We have connected to a BalanceBoard device.");
                // Here we have access to all the operations that we can perform on a BalanceBoard.
            }

            // If we don't want to be connected to the device, we can disconnect like this:
            device.Disconnect();
        }
Ejemplo n.º 12
0
        static void wiimote_Updated(object sender, EventArgs e)
        {
            IWiimote wiimote = (IWiimote)sender;

            // The accelerometer data can be read out either raw or calibrated. The
            // calibrated values present a more usable form that can be used directly.
            // Normally you will use the calibrated values because they are the same for every Wii device.
            // The range of the calibrated values is 0.0 to 1.0. In contrast the range of the raw
            // values is different for each Wii device.


            // Using the raw data:
            // On their own these values are pretty useless, you could however calibrate them yourself using
            // the calibration-values available in 'wiimote.Accelerometer.Calibration', but luckily WiiDeviceLibrary does that for you :)
            Console.WriteLine("Raw values: X={0} Y={1} Z={2}", wiimote.Accelerometer.Raw.X, wiimote.Accelerometer.Raw.Y, wiimote.Accelerometer.Raw.Z);


            // Using the calibrated data:
            Console.WriteLine("Calibrated values: X={0} Y={1} Z={2}", wiimote.Accelerometer.Calibrated.X, wiimote.Accelerometer.Calibrated.Y, wiimote.Accelerometer.Calibrated.Z);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
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);
        }
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return new ClassicControllerExtension(wiimote);
 }
Ejemplo n.º 17
0
 protected DummyExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
 }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
 protected DummyExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
 }
Ejemplo n.º 21
0
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return(new GuitarExtension(wiimote));
 }
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return(new NunchukExtension(wiimote));
 }
Ejemplo n.º 23
0
 public WiimoteUpdateEventArgs(IWiimote wiimote1, IWiimote wiimote2)
 {
     Wiimote1 = wiimote1;
     Wiimote2 = wiimote2;
 }
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return new NunchukExtension(wiimote);
 }
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return new GuitarExtension(wiimote);
 }
 internal ClassicControllerExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
     ReadCalibrationData();
 }
Ejemplo n.º 27
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]);
            }
        }
Ejemplo n.º 28
0
 public UnknownExtension(IWiimote wiimote)
     : base(wiimote)
 {
 }
Ejemplo n.º 29
0
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            wiimote.Updated += wiimote_Updated;
            wiimote.ExtensionAttached += wiimote_ExtensionAttached;
            wiimote.ExtensionDetached += wiimote_ExtensionDetached;

            wiimote.SetReportingMode(ReportingMode.Buttons10Ir9Extension);
        }
 public IWiimoteExtension Create(IWiimote wiimote)
 {
     return(new ClassicControllerExtension(wiimote));
 }
Ejemplo n.º 31
0
 internal GuitarExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
 }
Ejemplo n.º 32
0
 public UnknownExtension(IWiimote wiimote)
     : base(wiimote)
 {
 }
Ejemplo n.º 33
0
        static void OnWiimoteConnected(IWiimote wiimote)
        {
            // It is recommended to always set the leds to a value, so that they will stop flashing.
            Console.WriteLine("Notice that when we are connected to the wiimote and have not yet set the leds to any value, the leds will keep on flashing.");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We set the first and fourth leds on, the rest off.
            // Notice that we only supply the leds that must be on. All others will be off.
            wiimote.Leds = WiimoteLeds.Led1 | WiimoteLeds.Led4;

            Console.WriteLine("Leds: X . . X");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We can 'add' leds that must be on.
            wiimote.Leds |= WiimoteLeds.Led3;

            Console.WriteLine("Leds: X . X X");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            // We can 'remove' leds that must be on.
            wiimote.Leds ^= WiimoteLeds.Led4;

            Console.WriteLine("Leds: X . X .");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
 internal ClassicControllerExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
     ReadCalibrationData();
 }
Ejemplo n.º 35
0
 public WiimoteUpdateEventArgs(IWiimote wiimote1, IWiimote wiimote2)
 {
     Wiimote1 = wiimote1;
     Wiimote2 = wiimote2;
 }
Ejemplo n.º 36
0
 internal NunchukExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
     ReadCalibrationData();
 }
Ejemplo n.º 37
0
 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;
 }
Ejemplo n.º 38
0
 internal NunchukExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
     ReadCalibrationData();
 }
Ejemplo n.º 39
0
 public WiimoteSpeakerStream(IWiimote wiimote)
 {
     this.wiimote = wiimote;
 }
Ejemplo n.º 40
0
 public InvalidExtension(IWiimote wiimote)
     : base(wiimote)
 {
 }
Ejemplo n.º 41
0
 public WiimoteSpeakerStream(IWiimote wiimote)
 {
     this.wiimote = wiimote;
 }
Ejemplo n.º 42
0
 internal GuitarExtension(IWiimote wiimote)
 {
     _Wiimote = wiimote;
 }
Ejemplo n.º 43
0
 public InvalidExtension(IWiimote wiimote)
     : base(wiimote)
 {
 }
Ejemplo n.º 44
0
 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;
 }