예제 #1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            HidControllerKeys CurrentButton = 0;
            JoystickPosition  LeftJoystick;
            JoystickPosition  RightJoystick;

            //RightJoystick
            int LeftJoystickDX = 0;
            int LeftJoystickDY = 0;

            //RightJoystick
            int RightJoystickDX = 0;
            int RightJoystickDY = 0;

            LeftJoystick = new JoystickPosition
            {
                DX = LeftJoystickDX,
                DY = LeftJoystickDY
            };

            RightJoystick = new JoystickPosition
            {
                DX = RightJoystickDX,
                DY = RightJoystickDY
            };

            //We just need one pair of JoyCon because it's emulate by the keyboard.
            Ns.Hid.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);
        }
예제 #2
0
파일: Hid.cs 프로젝트: proflylab/MonoNX
        public void SendControllerButtons(HidControllerID ControllerId,
                                          HidControllerLayouts Layout,
                                          HidControllerKeys Buttons,
                                          JoystickPosition LeftJoystick,
                                          JoystickPosition RightJoystick)
        {
            uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader)) +
                               (uint)Marshal.SizeOf(typeof(HidTouchScreen)) +
                               (uint)Marshal.SizeOf(typeof(HidMouse)) +
                               (uint)Marshal.SizeOf(typeof(HidKeyboard)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection1)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection2)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection3)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection4)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection5)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection6)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection7)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection8)) +
                               (uint)Marshal.SizeOf(typeof(HidControllerSerials)) +
                               ((uint)(Marshal.SizeOf(typeof(HidController)) * (int)ControllerId)) +
                               (uint)Marshal.SizeOf(typeof(HidControllerHeader)) +
                               (uint)Layout * (uint)Marshal.SizeOf(typeof(HidControllerLayout));

            IntPtr HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);

            HidControllerLayoutHeader OldControllerHeaderLayout = (HidControllerLayoutHeader)Marshal.PtrToStructure(HidPtr, typeof(HidControllerLayoutHeader));

            HidControllerLayoutHeader ControllerLayoutHeader = new HidControllerLayoutHeader
            {
                TimestampTicks = (ulong)Environment.TickCount,
                NumEntries     = (ulong)Hid_Num_Entries,
                MaxEntryIndex  = (ulong)Hid_Num_Entries - 1,
                LatestEntry    = (OldControllerHeaderLayout.LatestEntry < (ulong)Hid_Num_Entries ? OldControllerHeaderLayout.LatestEntry + 1 : 0)
            };

            Marshal.StructureToPtr(ControllerLayoutHeader, HidPtr, false);

            InnerOffset += (uint)Marshal.SizeOf(typeof(HidControllerLayoutHeader)) + (uint)((uint)(ControllerLayoutHeader.LatestEntry) * Marshal.SizeOf(typeof(HidControllerInputEntry)));
            HidPtr       = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);

            HidControllerInputEntry ControllerInputEntry = new HidControllerInputEntry();

            ControllerInputEntry.Timestamp   = (ulong)Environment.TickCount;
            ControllerInputEntry.Timestamp_2 = (ulong)Environment.TickCount;
            ControllerInputEntry.Buttons     = (ulong)Buttons;
            ControllerInputEntry.Joysticks   = new JoystickPosition[(int)HidControllerJoystick.Joystick_Num_Sticks];
            ControllerInputEntry.Joysticks[(int)HidControllerJoystick.Joystick_Left]  = LeftJoystick;
            ControllerInputEntry.Joysticks[(int)HidControllerJoystick.Joystick_Right] = RightJoystick;
            ControllerInputEntry.ConnectionState = (ulong)(HidControllerConnectionState.Controller_State_Connected | HidControllerConnectionState.Controller_State_Wired);

            Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false);
        }
예제 #3
0
        private void Render()
        {
            while (true)
            {
                // Update

                HidControllerKeys CurrentButton = 0;
                JoystickPosition  LeftJoystick;
                JoystickPosition  RightJoystick;

                int LeftJoystickDX = 0;
                int LeftJoystickDY = 0;

                int RightJoystickDX = 0;
                int RightJoystickDY = 0;

                LeftJoystick = new JoystickPosition
                {
                    DX = LeftJoystickDX,
                    DY = LeftJoystickDY
                };

                RightJoystick = new JoystickPosition
                {
                    DX = RightJoystickDX,
                    DY = RightJoystickDY
                };

                Ns.Hid.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);

                // Draw

                ScreenTex.UploadBitmap();

                Renderer.RunActions();
                Renderer.BindTexture(0);
                Renderer.Render();

                if (ScreenTex.Pixels != null)
                {
                    ImageBitmap.CopyPixelsFromBuffer(IntBuffer.Wrap(ScreenTex.Pixels));
                }

                RunOnUiThread(() => ImageView.SetImageBitmap(ImageBitmap));
            }
        }