Esempio n. 1
0
            public SwitchProControllerHIDInputState ToHIDInputReport()
            {
                ////TODO: calibration curve

                var leftXRaw  = (uint)(left0 | ((left1 & 0x0F) << 8));
                var leftYRaw  = (uint)(((left1 & 0xF0) >> 4) | (left2 << 4));
                var rightXRaw = (uint)(right0 | ((right1 & 0x0F) << 8));
                var rightYRaw = (uint)(((right1 & 0xF0) >> 4) | (right2 << 4));

                var leftXByte  = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(leftXRaw, 12, 8);
                var leftYByte  = (byte)(0xff - (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(leftYRaw, 12, 8));
                var rightXByte = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(rightXRaw, 12, 8);
                var rightYByte = (byte)(0xff - (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(rightYRaw, 12, 8));

                var state = new SwitchProControllerHIDInputState
                {
                    leftStickX  = leftXByte,
                    leftStickY  = leftYByte,
                    rightStickX = rightXByte,
                    rightStickY = rightYByte
                };

                state.Set(SwitchProControllerHIDInputState.Button.Y, (buttons0 & 0x01) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.X, (buttons0 & 0x02) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.B, (buttons0 & 0x04) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.A, (buttons0 & 0x08) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.R, (buttons0 & 0x40) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.ZR, (buttons0 & 0x80) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Minus, (buttons1 & 0x01) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Plus, (buttons1 & 0x02) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.StickR, (buttons1 & 0x04) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.StickL, (buttons1 & 0x08) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Home, (buttons1 & 0x10) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Capture, (buttons1 & 0x20) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Down, (buttons2 & 0x01) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Up, (buttons2 & 0x02) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Right, (buttons2 & 0x04) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Left, (buttons2 & 0x08) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.L, (buttons2 & 0x40) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.ZL, (buttons2 & 0x80) != 0);

                return(state);
            }
Esempio n. 2
0
            public SwitchProControllerHIDInputState ToHIDInputReport()
            {
                var leftXByte  = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(leftX, 16, 8);
                var leftYByte  = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(leftY, 16, 8);
                var rightXByte = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(rightX, 16, 8);
                var rightYByte = (byte)NumberHelpers.RemapUIntBitsToNormalizeFloatToUIntBits(rightY, 16, 8);

                var state = new SwitchProControllerHIDInputState
                {
                    leftStickX  = leftXByte,
                    leftStickY  = leftYByte,
                    rightStickX = rightXByte,
                    rightStickY = rightYByte
                };

                state.Set(SwitchProControllerHIDInputState.Button.B, (buttons0 & 0x01) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.A, (buttons0 & 0x02) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Y, (buttons0 & 0x04) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.X, (buttons0 & 0x08) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.L, (buttons0 & 0x10) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.R, (buttons0 & 0x20) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.ZL, (buttons0 & 0x40) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.ZR, (buttons0 & 0x80) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Minus, (buttons1 & 0x01) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Plus, (buttons1 & 0x02) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.StickL, (buttons1 & 0x04) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.StickR, (buttons1 & 0x08) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Home, (buttons1 & 0x10) != 0);
                state.Set(SwitchProControllerHIDInputState.Button.Capture, (buttons1 & 0x20) != 0);

                var left  = false;
                var up    = false;
                var right = false;
                var down  = false;

                switch (hat)
                {
                case 0:
                    up = true;
                    break;

                case 1:
                    up    = true;
                    right = true;
                    break;

                case 2:
                    right = true;
                    break;

                case 3:
                    down  = true;
                    right = true;
                    break;

                case 4:
                    down = true;
                    break;

                case 5:
                    down = true;
                    left = true;
                    break;

                case 6:
                    left = true;
                    break;

                case 7:
                    up   = true;
                    left = true;
                    break;
                }

                state.Set(SwitchProControllerHIDInputState.Button.Left, left);
                state.Set(SwitchProControllerHIDInputState.Button.Up, up);
                state.Set(SwitchProControllerHIDInputState.Button.Right, right);
                state.Set(SwitchProControllerHIDInputState.Button.Down, down);

                return(state);
            }