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);
        }
Exemple #2
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);
        }