示例#1
0
        public void Update(byte[] data)
        {
            int offset = Utils.GetExtensionOffset((InputReport)data[0]);

            if (offset > 0)
            {
                // Buttons
                A      = (data[offset + 9] & 0x10) == 0;
                B      = (data[offset + 9] & 0x40) == 0;
                X      = (data[offset + 9] & 0x08) == 0;
                Y      = (data[offset + 9] & 0x20) == 0;
                L      = (data[offset + 8] & 0x20) == 0;
                R      = (data[offset + 8] & 0x02) == 0;
                ZL     = (data[offset + 9] & 0x80) == 0;
                ZR     = (data[offset + 9] & 0x04) == 0;
                Plus   = (data[offset + 8] & 0x04) == 0;
                Minus  = (data[offset + 8] & 0x10) == 0;
                Home   = (data[offset + 8] & 0x08) == 0;
                LStick = (data[offset + 10] & 0x02) == 0;
                RStick = (data[offset + 10] & 0x01) == 0;

                // DPad
                Up    = (data[offset + 9] & 0x01) == 0;
                Down  = (data[offset + 8] & 0x40) == 0;
                Left  = (data[offset + 9] & 0x02) == 0;
                Right = (data[offset + 8] & 0x80) == 0;

                // Joysticks
                LJoy.rawX = BitConverter.ToInt16(data, offset);
                LJoy.rawY = BitConverter.ToInt16(data, offset + 4);
                RJoy.rawX = BitConverter.ToInt16(data, offset + 2);
                RJoy.rawY = BitConverter.ToInt16(data, offset + 6);

                // Other
                charging     = (data[offset + 10] & 0x04) == 0;
                usbConnected = (data[offset + 10] & 0x08) == 0;

                // Normalize
                LJoy.Normalize();
                RJoy.Normalize();
            }
            else if (Utils.ReportContainsCoreButtons((InputReport)data[0]))
            {
                Plus  = (data[1] & 0x04) == 0;
                Home  = (data[1] & 0x08) == 0;
                Minus = (data[1] & 0x10) == 0;
                Down  = (data[1] & 0x40) == 0;
                Right = (data[1] & 0x80) == 0;
                Up    = (data[2] & 0x01) == 0;
                Left  = (data[2] & 0x02) == 0;
                A     = (data[2] & 0x10) == 0;
                B     = (data[2] & 0x40) == 0;
            }
        }
示例#2
0
        public void SetCalibration(INintrollerState from)
        {
            if (from.CalibrationEmpty)
            {
                // don't apply empty calibrations
                return;
            }

            if (from.GetType() == typeof(ProController))
            {
                LJoy.Calibrate(((ProController)from).LJoy);
                RJoy.Calibrate(((ProController)from).RJoy);
            }
        }
示例#3
0
        public void Update(byte[] data)
        {
            int offset = Utils.GetExtensionOffset((InputReport)data[0]);

            if (offset > 0)
            {
                // Buttons
                A     = (data[offset + 5] & 0x10) == 0;
                B     = (data[offset + 5] & 0x40) == 0;
                X     = (data[offset + 5] & 0x08) == 0;
                Y     = (data[offset + 5] & 0x20) == 0;
                LFull = (data[offset + 4] & 0x20) == 0;  // Until the Click
                RFull = (data[offset + 4] & 0x02) == 0;  // Until the Click
                ZL    = (data[offset + 5] & 0x80) == 0;
                ZR    = (data[offset + 5] & 0x04) == 0;
                Plus  = (data[offset + 4] & 0x04) == 0;
                Minus = (data[offset + 4] & 0x10) == 0;
                Home  = (data[offset + 4] & 0x08) == 0;

                // Dpad
                Up    = (data[offset + 5] & 0x01) == 0;
                Down  = (data[offset + 4] & 0x40) == 0;
                Left  = (data[offset + 5] & 0x02) == 0;
                Right = (data[offset + 4] & 0x80) == 0;

                // Joysticks
                LJoy.rawX = (byte)(data[offset] & 0x3F);
                LJoy.rawY = (byte)(data[offset + 1] & 0x3F);
                RJoy.rawX = (byte)(data[offset + 2] >> 7 | (data[offset + 1] & 0xC0) >> 5 | (data[offset] & 0xC0) >> 3);
                RJoy.rawY = (byte)(data[offset + 2] & 0x1F);

                // Triggers
                L.rawValue = (byte)(((data[offset + 2] & 0x60) >> 2) | (data[offset + 3] >> 5));
                R.rawValue = (byte)(data[offset + 3] & 0x1F);
                L.full     = LFull;
                R.full     = RFull;

                // Normalize
                LJoy.Normalize();
                RJoy.Normalize();
                L.Normalize();
                R.Normalize();
            }

            wiimote = new Wiimote(data, wiimote);
        }
        public void SetCalibration(INintrollerState from)
        {
            if (from.CalibrationEmpty)
            {
                // don't apply empty calibrations
                return;
            }

            if (from.GetType() == typeof(ClassicControllerPro))
            {
                LJoy.Calibrate(((ClassicControllerPro)from).LJoy);
                RJoy.Calibrate(((ClassicControllerPro)from).RJoy);
            }
            else if (from.GetType() == typeof(Wiimote))
            {
                wiimote.SetCalibration(from);
            }
        }
        public void Update(byte[] data)
        {
            int offset = Utils.GetExtensionOffset((InputReport)data[0]);

            if (offset > 0)
            {
                // Buttons
                A     = (data[offset + 5] & 0x10) == 0;
                B     = (data[offset + 5] & 0x40) == 0;
                X     = (data[offset + 5] & 0x08) == 0;
                Y     = (data[offset + 5] & 0x20) == 0;
                L     = (data[offset + 4] & 0x20) == 0;
                R     = (data[offset + 4] & 0x02) == 0;
                ZL    = (data[offset + 5] & 0x80) == 0;
                ZR    = (data[offset + 5] & 0x04) == 0;
                Plus  = (data[offset + 4] & 0x04) == 0;
                Minus = (data[offset + 4] & 0x10) == 0;
                Home  = (data[offset + 4] & 0x08) == 0;

                // Dpad
                Up    = (data[offset + 5] & 0x01) == 0;
                Down  = (data[offset + 4] & 0x40) == 0;
                Left  = (data[offset + 5] & 0x02) == 0;
                Right = (data[offset + 4] & 0x80) == 0;

                // Joysticks
                LJoy.rawX = (byte)(data[offset] & 0x3F);
                LJoy.rawY = (byte)(data[offset + 1] & 0x3F);
                RJoy.rawX = (byte)(data[offset + 2] >> 7 | (data[offset + 1] & 0xC0) >> 5 | (data[offset] & 0xC0) >> 3);
                RJoy.rawY = (byte)(data[offset + 2] & 0x1F);

                // Normalize
                LJoy.Normalize();
                RJoy.Normalize();
            }

            // Simply calling the Update(data) method doesn't seem to be working.
            // the button data will get updated correctly but when stepping over this
            // statement in debug mode the button data is all set to its default values.
            wiimote = new Wiimote(data, wiimote);
        }
        public IEnumerator <KeyValuePair <string, float> > GetEnumerator()
        {
            foreach (var input in wiimote)
            {
                yield return(input);
            }

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.A, A ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.B, B ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.X, X ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.Y, Y ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.L, L ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.R, R ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.ZL, ZL ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.ZR, ZR ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.UP, Up ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.DOWN, Down ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LEFT, Left ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RIGHT, Right ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.START, Start ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.SELECT, Select ? 1.0f : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.HOME, Home ? 1.0f : 0.0f));

            LJoy.Normalize();
            RJoy.Normalize();
            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LX, LJoy.X));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LY, LJoy.Y));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RX, RJoy.X));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RY, RJoy.X));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LUP, LJoy.Y > 0f ? LJoy.Y : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LDOWN, LJoy.Y > 0f ? 0.0f : -LJoy.Y)); // These are inverted

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LLEFT, LJoy.X > 0f ? 0.0f : -LJoy.X)); // because they

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.LRIGHT, LJoy.X > 0f ? LJoy.X : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RUP, RJoy.Y > 0f ? RJoy.Y : 0.0f));

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RDOWN, RJoy.Y > 0f ? 0.0f : -RJoy.Y)); // represents how far the

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RLEFT, RJoy.X > 0f ? 0.0f : -RJoy.X)); // input is left or down

            yield return(new KeyValuePair <string, float>(INPUT_NAMES.CLASSIC_CONTROLLER_PRO.RRIGHT, RJoy.X > 0f ? RJoy.X : 0.0f));
        }