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);
        }
示例#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);
        }
 public void Calibrate(AccelerometerAxes<ushort> raw, AccelerometerAxes<float> calibrating)
 {
     calibrating.X = CalibrateValue(raw.X, XZero, XOne); // 131 158
     calibrating.Y = CalibrateValue(raw.Y, YZero, YOne); // 131 158
     calibrating.Z = CalibrateValue(raw.Z, ZZero, ZOne); // 129 155
 }
示例#4
0
 public Accelerometer(AccelerometerCalibration calibration)
 {
     _Calibration = calibration;
     _Raw = new AccelerometerAxes<ushort>();
     _Calibrated = new AccelerometerAxes<float>();
 }