Beispiel #1
0
        /// <summary>
        /// Creates a string containing the calibration settings for the Wiimote.
        /// String is in the following format
        /// -wm:acc|centerX|minX|minY|deadX|centerY|[...]:ir
        /// </summary>
        /// <returns>String representing the Wiimote's calibration settings.</returns>
        public string GetCalibrationString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("-wm");
            sb.Append(":acc");
            sb.Append("|"); sb.Append(accelerometer.centerX);
            sb.Append("|"); sb.Append(accelerometer.minX);
            sb.Append("|"); sb.Append(accelerometer.maxX);
            sb.Append("|"); sb.Append(accelerometer.deadX);

            sb.Append("|"); sb.Append(accelerometer.centerY);
            sb.Append("|"); sb.Append(accelerometer.minY);
            sb.Append("|"); sb.Append(accelerometer.maxY);
            sb.Append("|"); sb.Append(accelerometer.deadY);

            sb.Append("|"); sb.Append(accelerometer.centerZ);
            sb.Append("|"); sb.Append(accelerometer.minZ);
            sb.Append("|"); sb.Append(accelerometer.maxZ);
            sb.Append("|"); sb.Append(accelerometer.deadZ);

            if (irSensor.boundingArea != null)
            {
                if (irSensor.boundingArea is SquareBoundry)
                {
                    SquareBoundry sqr = (SquareBoundry)irSensor.boundingArea;
                    sb.Append(":irSqr");
                    sb.Append("|"); sb.Append(sqr.center_x);
                    sb.Append("|"); sb.Append(sqr.center_y);
                    sb.Append("|"); sb.Append(sqr.width);
                    sb.Append("|"); sb.Append(sqr.height);
                }
                else if (irSensor.boundingArea is CircularBoundry)
                {
                    CircularBoundry cir = (CircularBoundry)irSensor.boundingArea;
                    sb.Append(":irCir");
                    sb.Append("|"); sb.Append(cir.center_x);
                    sb.Append("|"); sb.Append(cir.center_y);
                    sb.Append("|"); sb.Append(cir.radius);
                }
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public void SetCalibration(string calibrationString)
        {
            if (calibrationString.Count(c => c == '0') > 5)
            {
                // don't set empty calibrations
                return;
            }

            string[] components = calibrationString.Split(new char[] { ':' });

            foreach (string component in components)
            {
                if (component.StartsWith("acc"))
                {
                    string[] accConfig = component.Split(new char[] { '|' });

                    for (int a = 1; a < accConfig.Length; a++)
                    {
                        int value = 0;
                        if (int.TryParse(accConfig[a], out value))
                        {
                            switch (a)
                            {
                            case 1:  accelerometer.centerX = value; break;

                            case 2:  accelerometer.minX = value; break;

                            case 3:  accelerometer.maxX = value; break;

                            case 4:  accelerometer.deadX = value; break;

                            case 5:  accelerometer.centerY = value; break;

                            case 6:  accelerometer.minY = value; break;

                            case 7:  accelerometer.maxY = value; break;

                            case 8:  accelerometer.deadY = value; break;

                            case 9:  accelerometer.centerZ = value; break;

                            case 10: accelerometer.minZ = value; break;

                            case 11: accelerometer.maxZ = value; break;

                            case 12: accelerometer.deadZ = value; break;
                            }
                        }
                    }
                }
                else if (component.StartsWith("irSqr"))
                {
                    SquareBoundry sBoundry  = new SquareBoundry();
                    string[]      sqrConfig = component.Split(new char[] { '|' });

                    for (int s = 1; s < sqrConfig.Length; s++)
                    {
                        int value = 0;
                        if (int.TryParse(sqrConfig[s], out value))
                        {
                            switch (s)
                            {
                            case 1: sBoundry.center_x = value; break;

                            case 2: sBoundry.center_y = value; break;

                            case 3: sBoundry.width = value; break;

                            case 4: sBoundry.height = value; break;
                            }
                        }
                    }

                    irSensor.boundingArea = sBoundry;
                }
                else if (component.StartsWith("irCir"))
                {
                    CircularBoundry sBoundry  = new CircularBoundry();
                    string[]        cirConfig = component.Split(new char[] { '|' });

                    for (int c = 1; c < cirConfig.Length; c++)
                    {
                        int value = 0;
                        if (int.TryParse(cirConfig[c], out value))
                        {
                            switch (c)
                            {
                            case 1: sBoundry.center_x = value; break;

                            case 2: sBoundry.center_y = value; break;

                            case 3: sBoundry.radius = value; break;
                            }
                        }
                    }

                    irSensor.boundingArea = sBoundry;
                }
            }
        }