示例#1
0
        //Xbox stream app keeps disconnecting
        //I think having this keepalive function sending
        //a useless but real message with prevent the random
        //disconnection happening
        private void keepalive()
        {
            X360Controller p2 = new X360Controller();

            while (true)
            {
                controller.RightStickY ^= 1;
                scpbus.Report(1, controller.GetReport());
                Thread.Sleep(50);
            }
        }
示例#2
0
        public void UnplugAll()
        {
            // Reset all inputs
            foreach (var index in Program.KeyboardMapperInstance.MappedControllerIndexes)
            {
                Bus.Report(index + 1, new X360Controller().GetReport());
            }

            System.Threading.Thread.Sleep(250);
            Bus.UnplugAll();
            System.Threading.Thread.Sleep(250);
        }
        public static void SendtoController(X360Controller controller)
        {
            byte[] report = controller.GetReport();
            byte[] output = new byte[8];

            scpbus.Report(CONTROLLER_NUMBER, report, output);
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("|-------------------------------|");
            Console.WriteLine("| Switch XBOX Controller Server |");
            Console.WriteLine("|-------------------------------|");
            Console.WriteLine();

            System.Timers.Timer timer;

            _handler += new EventHandler(onExitHandler);
            SetConsoleCtrlHandler(_handler, true);

            detectSwitch();

            Console.WriteLine("Running...");

            controller = new X360Controller();
            scpBus     = new ScpBus();
            scpBus.PlugIn(1);

            timer           = new System.Timers.Timer(1);
            timer.Elapsed  += (s, e) => scpBus.Report(1, controller.GetReport());
            timer.AutoReset = true;
            timer.Start();

            networkThread = new Thread(() => networking());
            displayThread = new Thread(() => displayButtons());

            networkThread.Start();
            displayThread.Start();

            Console.ReadLine();
        }
示例#5
0
        public static void SendtoController(X360Controller controller)
        {
            byte[] report = controller.GetReport();
            byte[] output = new byte[8];

            // Send our data back to the virtual scp bus.
            scpbus.Report(CONTROLLER_NUMBER, report, output);
        }
示例#6
0
        static void applyInputs()
        {
            // Logic goes here

            gamepad.Buttons &= ~previousInputs;
            previousInputs   = gamepad.Buttons;

            scp.Report(gamepadIndex, gamepad.GetReport());
        }
示例#7
0
        private void KeyboardWatcher_OnKeyInput(object sender, KeyInputEventArgs e)
        {
            KeyToXboxButton button = keyboardToController.ListButtons.FirstOrDefault(x => x.Key == e.KeyData.Keyname);

            if (button != null) //We do have a bind for this key
            {
                controller.Buttons ^= button.x360Buttons;
                _scpBus.Report((int)1, controller.GetReport(), _outputReport);
            }
        }
        private bool HandleButton(Button button)
        {
            bool result = _scpBus.Report((int)controllerNum.Value, _controller.GetReport(), _outputReport);

            CheckRumble();
            status.Text = result.ToString();

            if (!result)
            {
                return(false);
            }

            if (button.BackColor == Color.Transparent)
            {
                button.BackColor = Color.Salmon;
            }
            else
            {
                button.BackColor = Color.Transparent;
            }

            return(true);
        }
示例#9
0
        /// <summary>
        /// Sets status of all buttons in specified controller
        /// </summary>
        /// <param name="message">PAD_ID|BTN_STAT...</param>
        public byte[] SetControllers(string message)
        {
            var    m       = message.Split(separator).ToList <string>();
            string phoneId = m[0];
            int?   controllerId;

            byte[] outputReport = new byte[8];
            byte[] motors       = new byte[3]; // state, big motor, small motor

            if (m.Count == 2)
            {
                switch (m[1])
                {
                case "disconnect": UnplugController(phoneId); break;

                case "connect": CheckController(phoneId); break;
                }
                return(motors);
            }

            controllerId = CheckController(phoneId);

            if (controllerId.HasValue)
            {
                m.Remove(m.First());
                xpad.SetFromString(m);
                scpBus.Report(controllerId.Value, xpad.GetReport(), outputReport);

                motors[0] = outputReport[1];

                if (outputReport[1] == 0x08)
                {
                    motors[1] = outputReport[3]; // big motor
                    motors[2] = outputReport[4]; // small motor
                }
            }

            return(motors);
        }
示例#10
0
        private void input_thread(HidDevice Device, ScpBus scpBus, int index)
        {
            scpBus.PlugIn(index);
            X360Controller controller     = new X360Controller();
            int            timeout        = 30;
            long           last_changed   = 0;
            long           last_mi_button = 0;

            while (true)
            {
                HidDeviceData data         = Device.Read(timeout);
                var           currentState = data.Data;
                bool          changed      = false;
                if (data.Status == HidDeviceData.ReadStatus.Success && currentState.Length >= 21 && currentState[0] == 4)
                {
                    //Console.WriteLine(Program.ByteArrayToHexString(currentState));
                    X360Buttons Buttons = X360Buttons.None;
                    if ((currentState[1] & 1) != 0)
                    {
                        Buttons |= X360Buttons.A;
                    }
                    if ((currentState[1] & 2) != 0)
                    {
                        Buttons |= X360Buttons.B;
                    }
                    if ((currentState[1] & 8) != 0)
                    {
                        Buttons |= X360Buttons.X;
                    }
                    if ((currentState[1] & 16) != 0)
                    {
                        Buttons |= X360Buttons.Y;
                    }
                    if ((currentState[1] & 64) != 0)
                    {
                        Buttons |= X360Buttons.LeftBumper;
                    }
                    if ((currentState[1] & 128) != 0)
                    {
                        Buttons |= X360Buttons.RightBumper;
                    }

                    if ((currentState[2] & 32) != 0)
                    {
                        Buttons |= X360Buttons.LeftStick;
                    }
                    if ((currentState[2] & 64) != 0)
                    {
                        Buttons |= X360Buttons.RightStick;
                    }

                    if (currentState[4] != 15)
                    {
                        if (currentState[4] == 0 || currentState[4] == 1 || currentState[4] == 7)
                        {
                            Buttons |= X360Buttons.Up;
                        }
                        if (currentState[4] == 4 || currentState[4] == 3 || currentState[4] == 5)
                        {
                            Buttons |= X360Buttons.Down;
                        }
                        if (currentState[4] == 6 || currentState[4] == 5 || currentState[4] == 7)
                        {
                            Buttons |= X360Buttons.Left;
                        }
                        if (currentState[4] == 2 || currentState[4] == 1 || currentState[4] == 3)
                        {
                            Buttons |= X360Buttons.Right;
                        }
                    }

                    if ((currentState[2] & 8) != 0)
                    {
                        Buttons |= X360Buttons.Start;
                    }
                    if ((currentState[2] & 4) != 0)
                    {
                        Buttons |= X360Buttons.Back;
                    }



                    if ((currentState[20] & 1) != 0)
                    {
                        last_mi_button = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                        Buttons       |= X360Buttons.Logo;
                    }
                    if (last_mi_button != 0)
                    {
                        Buttons |= X360Buttons.Logo;
                    }


                    if (controller.Buttons != Buttons)
                    {
                        changed            = true;
                        controller.Buttons = Buttons;
                    }

                    short LeftStickX = (short)((Math.Max(-127.0, currentState[5] - 128) / 127) * 32767);
                    if (LeftStickX != controller.LeftStickX)
                    {
                        changed = true;
                        controller.LeftStickX = LeftStickX;
                    }

                    short LeftStickY = (short)((Math.Max(-127.0, currentState[6] - 128) / 127) * -32767);
                    if (LeftStickY != controller.LeftStickY)
                    {
                        changed = true;
                        controller.LeftStickY = LeftStickY;
                    }

                    short RightStickX = (short)((Math.Max(-127.0, currentState[7] - 128) / 127) * 32767);
                    if (RightStickX != controller.RightStickX)
                    {
                        changed = true;
                        controller.RightStickX = RightStickX;
                    }

                    short RightStickY = (short)((Math.Max(-127.0, currentState[8] - 128) / 127) * -32767);
                    if (RightStickY != controller.RightStickY)
                    {
                        changed = true;
                        controller.RightStickY = RightStickY;
                    }

                    if (controller.LeftTrigger != currentState[11])
                    {
                        changed = true;
                        controller.LeftTrigger = currentState[11];
                    }

                    if (controller.RightTrigger != currentState[12])
                    {
                        changed = true;
                        controller.RightTrigger = currentState[12];
                    }
                }

                if (data.Status == HidDeviceData.ReadStatus.WaitTimedOut || (!changed && ((last_changed + timeout) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))))
                {
                    changed = true;
                }

                if (changed)
                {
                    //Console.WriteLine("changed");
                    //Console.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
                    byte[] outputReport = new byte[8];
                    scpBus.Report(index, controller.GetReport(), outputReport);

                    if (outputReport[1] == 0x08)
                    {
                        byte bigMotor   = outputReport[3];
                        byte smallMotor = outputReport[4];
                        rumble_mutex.WaitOne();
                        if (bigMotor != Vibration[2] || Vibration[1] != smallMotor)
                        {
                            Vibration[1] = smallMotor;
                            Vibration[2] = bigMotor;
                        }
                        rumble_mutex.ReleaseMutex();
                    }

                    if (last_mi_button != 0)
                    {
                        if ((last_mi_button + 100) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))
                        {
                            last_mi_button      = 0;
                            controller.Buttons ^= X360Buttons.Logo;
                        }
                    }

                    last_changed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }
            }
        }
示例#11
0
        public void Frame()
        {
            if (!currentInput.active)
            {
                if (currentSeries.Any())
                {
                    currentInput        = currentSeries.Dequeue();
                    currentInput.active = true;
                }
                else
                {
                    try
                    {
                        var response = webClient.DownloadString($"{newInputEndpoint}?client=xbox");
                        ConsoleLogger.Debug(response);
                        var nextInput = JsonConvert.DeserializeObject <TPPInput>(response);
                        if (!((currentInput.Hold || !currentInput.IsExpired) && nextInput.IsEmpty))
                        {
                            currentInput = nextInput;
                        }
                    }
                    catch (Exception e)
                    {
                        ConsoleLogger.Warning($"Error communicating with core: {e.Message}");
                    }
                    if (currentInput.Series != null)
                    {
                        currentSeries = new Queue <TPPInput>(currentInput.Series);
                        Frame();
                        return;
                    }
                    else if (!string.IsNullOrWhiteSpace(currentInput.Macro))
                    {
                        var inputs = JsonConvert.DeserializeObject <List <TPPInput> >(JsonConvert.SerializeObject((MacroBank.Macros.FirstOrDefault(m => m.Name.ToLower() == currentInput.Macro.ToLower()) ?? new MacroBank.Macro()
                        {
                            Inputs = new List <TPPInput>()
                        }).Inputs));
                        foreach (var input in inputs)
                        {
                            input.Held_Frames  = input.Held_Frames == 0 ? Math.Max(4, currentInput.Held_Frames / inputs.Count()) : input.Held_Frames;
                            input.Sleep_Frames = input.Sleep_Frames == 0 ? Math.Max(4, currentInput.Sleep_Frames / inputs.Count()) : input.Sleep_Frames;
                        }
                        currentSeries = new Queue <TPPInput>(inputs);
                        Frame();
                        return;
                    }
                    else
                    {
                        currentInput.active = true;
                        var frameLength = currentInput.Held_Frames + currentInput.Sleep_Frames;
                        currentInput.Held_Frames  = Math.Min(Math.Min(Math.Max(currentInput.Held_Frames, minHeld), maxHeld), frameLength - 1);
                        currentInput.Sleep_Frames = Math.Min(Math.Min(currentInput.Sleep_Frames, maxSleep), frameLength - currentInput.Held_Frames);

                        if (currentInput.Hold && !HoldForever)
                        {
                            currentInput.Hold = false;
                            var shiftFrames = maxHoldDuration - currentInput.Held_Frames;
                            currentInput.Held_Frames  += shiftFrames;
                            currentInput.Sleep_Frames -= shiftFrames;
                            if (currentInput.Sleep_Frames < 0) // input total duration was lower than maxHold
                            {
                                currentInput.Held_Frames   += currentInput.Sleep_Frames;
                                currentInput.Expire_Frames -= currentInput.Sleep_Frames;
                            }
                        }
                    }
                }
            }
            if (currentInput.active)
            {
                if (currentInput.Held_Frames-- <= 0)
                {
                    if (currentInput.Sleep_Frames-- <= 0)
                    {
                        try
                        {
                            webClient.DownloadString($"{doneInputEndpoint}?client=xbox");
                            currentInput.active = false;
                        }
                        catch (Exception e)
                        {
                            ConsoleLogger.Warning($"Error communicating with core: {e.Message}");
                        }
                    }
                }
            }
            if (currentInput.active && (currentInput.Held_Frames > 0 || currentInput.Expire_Frames > 0))
            {
                var input = currentInput.ToX360();

                if (input.Buttons != 0 && !String.IsNullOrWhiteSpace(forceFocus))
                {
                    ForceFocus.BringMainWindowToFront(forceFocus);
                }

                scpBus.Report(scpController, input.GetReport());
                ConsoleLogger.Info($"Buttons: {input.Buttons}");
                if (currentInput.Held_Frames <= 0)
                {
                    currentInput.Expire_Frames--;
                }
            }
            else if (!currentInput.Hold)
            {
                var input = new TPPInput().ToX360();
                scpBus.Report(scpController, input.GetReport());
                ConsoleLogger.Info($"Buttons: {input.Buttons}");
            }
        }
示例#12
0
        private static void ConvertTo360(Input i)
        {
            BindList b            = Preset.Current.m_BindList;
            bool     bPastUpdated = false;

            for (int idx = 0; idx < i.m_InputState.Count; idx++)
            {
                if (!m_DisabledButtons.Contains("A") && i.m_InputType == b.AButton.m_InputType && i.Code[idx] == b.AButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.A;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.A;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.A;
                        ImpulseRelease(X360Buttons.A);
                    }
                }

                if (!m_DisabledButtons.Contains("X") && i.m_InputType == b.XButton.m_InputType && i.Code[idx] == b.XButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.X;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.X;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.X;
                        ImpulseRelease(X360Buttons.X);
                    }
                }

                if (!m_DisabledButtons.Contains("Y") && i.m_InputType == b.YButton.m_InputType && i.Code[idx] == b.YButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Y;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Y;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Y;
                        ImpulseRelease(X360Buttons.Y);
                    }
                }

                if (!m_DisabledButtons.Contains("B") && i.m_InputType == b.BButton.m_InputType && i.Code[idx] == b.BButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.B;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.B;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.B;
                        ImpulseRelease(X360Buttons.B);
                    }
                }

                if (!m_DisabledButtons.Contains("START") && i.m_InputType == b.StartButton.m_InputType && i.Code[idx] == b.StartButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Start;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Start;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Start;
                        ImpulseRelease(X360Buttons.Start);
                    }
                }

                if (!m_DisabledButtons.Contains("BACK") && i.m_InputType == b.BackButton.m_InputType && i.Code[idx] == b.BackButton.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Back;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Back;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Back;
                        ImpulseRelease(X360Buttons.Back);
                    }
                }

                if (!m_DisabledButtons.Contains("UP") && i.m_InputType == b.DPadUp.m_InputType && i.Code[idx] == b.DPadUp.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Up;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Up;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Up;
                        ImpulseRelease(X360Buttons.Up);
                    }
                }

                if (!m_DisabledButtons.Contains("DOWN") && i.m_InputType == b.DPadDown.m_InputType && i.Code[idx] == b.DPadDown.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Down;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Down;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Down;
                        ImpulseRelease(X360Buttons.Down);
                    }
                }

                if (!m_DisabledButtons.Contains("RIGHT") && i.m_InputType == b.DPadRight.m_InputType && i.Code[idx] == b.DPadRight.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Right;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Right;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Right;
                        ImpulseRelease(X360Buttons.Right);
                    }
                }

                if (!m_DisabledButtons.Contains("LEFT") && i.m_InputType == b.DPadLeft.m_InputType && i.Code[idx] == b.DPadLeft.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Left;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.Left;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.Left;
                        ImpulseRelease(X360Buttons.Left);
                    }
                }

                if (!m_DisabledButtons.Contains("LB") && i.m_InputType == b.LeftBumper.m_InputType && i.Code[idx] == b.LeftBumper.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.LeftBumper;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.LeftBumper;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.LeftBumper;
                        ImpulseRelease(X360Buttons.LeftBumper);
                    }
                }

                if (!m_DisabledButtons.Contains("RB") && i.m_InputType == b.RightBumper.m_InputType && i.Code[idx] == b.RightBumper.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.RightBumper;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.RightBumper;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.RightBumper;
                        ImpulseRelease(X360Buttons.RightBumper);
                    }
                }

                if (!m_DisabledButtons.Contains("LT") && i.m_InputType == b.LeftTrigger.m_InputType && i.Code[idx] == b.LeftTrigger.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.LeftTrigger = 255;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.LeftTrigger = 0;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.LeftTrigger = 255;
                        Task.Run(() =>
                        {
                            Thread.Sleep(10);
                            m_Ctrlr.LeftTrigger = 0;
                            m_Bus.Report(2, m_Ctrlr.GetReport());
                        });
                    }
                }

                if (!m_DisabledButtons.Contains("RT") && i.m_InputType == b.RightTrigger.m_InputType && i.Code[idx] == b.RightTrigger.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.RightTrigger = 255;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.RightTrigger = 0;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.RightTrigger = 255;
                        Task.Run(() =>
                        {
                            Thread.Sleep(10);
                            m_Ctrlr.RightTrigger = 0;
                            m_Bus.Report(2, m_Ctrlr.GetReport());
                        });
                    }
                }

                if (!m_DisabledButtons.Contains("LJOY") && i.m_InputType == b.LeftJoyPress.m_InputType && i.Code[idx] == b.LeftJoyPress.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.LeftStick;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.LeftStick;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.LeftStick;
                        ImpulseRelease(X360Buttons.LeftStick);
                    }
                }

                if (!m_DisabledButtons.Contains("RJOY") && i.m_InputType == b.RightJoyPress.m_InputType && i.Code[idx] == b.RightJoyPress.Code)
                {
                    if (i.m_InputState[idx] == Input.InputState.Down)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.RightStick;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Up)
                    {
                        m_Ctrlr.Buttons &= ~X360Buttons.RightStick;
                    }
                    else if (i.m_InputState[idx] == Input.InputState.Impulse)
                    {
                        m_Ctrlr.Buttons |= X360Buttons.RightStick;
                        ImpulseRelease(X360Buttons.RightStick);
                    }
                }

                if (b.RightJoyType == Input.InputType.Keyboard)
                {
                    if ((i.m_InputType == b.RightJoyUp.m_InputType && i.Code[idx] == b.RightJoyUp.Code) ||
                        (i.m_InputType == b.RightJoyDown.m_InputType && i.Code[idx] == b.RightJoyDown.Code))
                    {
                        short y = 0;
                        if (Input.GetKeyState(b.RightJoyUp))
                        {
                            y += short.MaxValue;
                        }

                        if (Input.GetKeyState(b.RightJoyDown))
                        {
                            y -= short.MinValue;
                        }

                        m_Ctrlr.RightStickY = y;
                    }

                    if ((i.m_InputType == b.RightJoyRight.m_InputType && i.Code[idx] == b.RightJoyRight.Code) ||
                        (i.m_InputType == b.RightJoyLeft.m_InputType && i.Code[idx] == b.RightJoyLeft.Code))
                    {
                        short x = 0;
                        if (Input.GetKeyState(b.RightJoyLeft))
                        {
                            x -= short.MinValue;
                        }

                        if (Input.GetKeyState(b.RightJoyRight))
                        {
                            x += short.MaxValue;
                        }

                        m_Ctrlr.RightStickX = x;
                    }
                }

                if (b.LeftJoyType == Input.InputType.Keyboard)
                {
                    if ((i.m_InputType == b.LeftJoyUp.m_InputType && i.Code[idx] == b.LeftJoyUp.Code) ||
                        (i.m_InputType == b.LeftJoyDown.m_InputType && i.Code[idx] == b.LeftJoyDown.Code))
                    {
                        short y = 0;
                        if (Input.GetKeyState(b.LeftJoyUp))
                        {
                            y += short.MaxValue;
                        }

                        if (Input.GetKeyState(b.LeftJoyDown))
                        {
                            y -= short.MinValue;
                        }

                        m_Ctrlr.LeftStickY = y;
                    }

                    if ((i.m_InputType == b.LeftJoyRight.m_InputType && i.Code[idx] == b.LeftJoyRight.Code) ||
                        (i.m_InputType == b.LeftJoyLeft.m_InputType && i.Code[idx] == b.LeftJoyLeft.Code))
                    {
                        short x = 0;
                        if (Input.GetKeyState(b.LeftJoyLeft))
                        {
                            x -= short.MinValue;
                        }

                        if (Input.GetKeyState(b.LeftJoyRight))
                        {
                            x += short.MaxValue;
                        }

                        m_Ctrlr.LeftStickX = x;
                    }
                }
            }

            if (b.RightJoyType == Input.InputType.Mouse && i.m_InputType == Input.InputType.Mouse)
            {
                UpdatePast(i);
                bPastUpdated = true;
                CalcJoy(value => m_Ctrlr.RightStickX = value, value => m_Ctrlr.RightStickY = value);
            }

            if (b.LeftJoyType == Input.InputType.Mouse && i.m_InputType == Input.InputType.Mouse)
            {
                if (!bPastUpdated)
                {
                    UpdatePast(i);
                }
                CalcJoy(value => m_Ctrlr.LeftStickX = value, value => m_Ctrlr.LeftStickY = value);
            }

            m_Bus.Report(2, m_Ctrlr.GetReport());
        }
示例#13
0
        private static void Main(string[] args)
        {
            var scp  = new ScpBus();
            var ctrl = new X360Controller();

            scp.PlugIn(1);

            using (var Context = new UsbCtx())
            {
                while (true)
                {
                    WriteScreen(Context);

                    var pkg = ReadPkg(Context);

                    void map(InputKeys inkey, X360Buttons outkey)
                    {
                        if ((pkg.HeldKeys & (ulong)inkey) > 0)
                        {
                            ctrl.Buttons |= outkey;
                        }
                        else
                        {
                            ctrl.Buttons &= ~outkey;
                        }
                    }

                    map(InputKeys.A, X360Buttons.B);
                    map(InputKeys.B, X360Buttons.A);
                    map(InputKeys.X, X360Buttons.Y);
                    map(InputKeys.Y, X360Buttons.X);

                    map(InputKeys.L, X360Buttons.LeftBumper);
                    map(InputKeys.R, X360Buttons.RightBumper);

                    map(InputKeys.LS, X360Buttons.LeftStick);
                    map(InputKeys.RS, X360Buttons.RightStick);

                    map(InputKeys.Plus, X360Buttons.Start);
                    map(InputKeys.Minus, X360Buttons.Back);

                    map(InputKeys.Up, X360Buttons.Up);
                    map(InputKeys.Down, X360Buttons.Down);
                    map(InputKeys.Left, X360Buttons.Left);
                    map(InputKeys.Right, X360Buttons.Right);

                    if ((pkg.HeldKeys & (ulong)InputKeys.ZL) > 0)
                    {
                        ctrl.LeftTrigger = byte.MaxValue;
                    }
                    else
                    {
                        ctrl.LeftTrigger = byte.MinValue;
                    }

                    if ((pkg.HeldKeys & (ulong)InputKeys.ZR) > 0)
                    {
                        ctrl.RightTrigger = byte.MaxValue;
                    }
                    else
                    {
                        ctrl.RightTrigger = byte.MinValue;
                    }

                    ctrl.LeftStickX = pkg.LJoyX;
                    ctrl.LeftStickY = pkg.LJoyY;

                    ctrl.RightStickX = pkg.RJoyX;
                    ctrl.RightStickY = pkg.RJoyY;

                    scp.Report(1, ctrl.GetReport());
                }
            }
        }
示例#14
0
        private void InputLoop()
        {
            while (true)
            {
                if (!started)
                {
                    Thread.Sleep(100);
                    continue;
                }

                try
                {
                    client = new TcpClient();
                    client.Connect(ip, 2223);
                    serverStream             = client.GetStream();
                    serverStream.ReadTimeout = 2000;
                }
                catch { continue; }

                while (true)
                {
                    InputPkg pkg;

                    try { pkg = ReadPkg(); }
                    catch { break; }

                    void map(InputKeys inkey, X360Buttons outkey)
                    {
                        if ((pkg.HeldKeys & (ulong)inkey) > 0)
                        {
                            ctrl.Buttons |= outkey;
                        }
                        else
                        {
                            ctrl.Buttons &= ~outkey;
                        }
                    }

                    map(InputKeys.A, X360Buttons.B);
                    map(InputKeys.B, X360Buttons.A);
                    map(InputKeys.X, X360Buttons.Y);
                    map(InputKeys.Y, X360Buttons.X);

                    map(InputKeys.L, X360Buttons.LeftBumper);
                    map(InputKeys.R, X360Buttons.RightBumper);

                    map(InputKeys.LS, X360Buttons.LeftStick);
                    map(InputKeys.RS, X360Buttons.RightStick);

                    map(InputKeys.Plus, X360Buttons.Start);
                    map(InputKeys.Minus, X360Buttons.Back);

                    map(InputKeys.Up, X360Buttons.Up);
                    map(InputKeys.Down, X360Buttons.Down);
                    map(InputKeys.Left, X360Buttons.Left);
                    map(InputKeys.Right, X360Buttons.Right);

                    if ((pkg.HeldKeys & (ulong)InputKeys.ZL) > 0)
                    {
                        ctrl.LeftTrigger = byte.MaxValue;
                    }
                    else
                    {
                        ctrl.LeftTrigger = byte.MinValue;
                    }

                    if ((pkg.HeldKeys & (ulong)InputKeys.ZR) > 0)
                    {
                        ctrl.RightTrigger = byte.MaxValue;
                    }
                    else
                    {
                        ctrl.RightTrigger = byte.MinValue;
                    }

                    ctrl.LeftStickX = pkg.LJoyX;
                    ctrl.LeftStickY = pkg.LJoyY;

                    ctrl.RightStickX = pkg.RJoyX;
                    ctrl.RightStickY = pkg.RJoyY;

                    scp.Report(1, ctrl.GetReport());
                }
            }
        }
示例#15
0
        private void input_thread(HidDevice Device, ScpBus scpBus, int index)
        {
            scpBus.PlugIn(index);
            X360Controller controller   = new X360Controller();
            int            timeout      = 30;
            long           last_changed = 0;

            //long last_mi_button = 0;
            while (true)
            {
                HidDeviceData data         = Device.Read(timeout);
                var           currentState = data.Data;
                bool          changed      = false;

                string str = Program.ByteArrayToHexString(currentState);
                if (!string.IsNullOrEmpty(str))
                {
                    Console.WriteLine(Program.ByteArrayToHexString(currentState));
                }

                if (data.Status == HidDeviceData.ReadStatus.Success && currentState.Length >= 10 && currentState[0] == 0x02)
                {
                    // Console.WriteLine(Program.ByteArrayToHexString(currentState));
                    X360Buttons Buttons = X360Buttons.None;
                    if ((currentState[1] & 0x01) != 0)
                    {
                        Buttons |= X360Buttons.A;
                    }
                    if ((currentState[1] & 0x02) != 0)
                    {
                        Buttons |= X360Buttons.B;
                    }
                    if ((currentState[1] & 0x08) != 0)
                    {
                        Buttons |= X360Buttons.X;
                    }
                    if ((currentState[1] & 0x10) != 0)
                    {
                        Buttons |= X360Buttons.Y;
                    }
                    if ((currentState[1] & 0x40) != 0)
                    {
                        Buttons |= X360Buttons.LeftBumper;
                    }
                    if ((currentState[1] & 0x80) != 0)
                    {
                        Buttons |= X360Buttons.RightBumper;
                    }

                    if ((currentState[2] & 0x20) != 0)
                    {
                        Buttons |= X360Buttons.LeftStick;
                    }
                    if ((currentState[2] & 0x40) != 0)
                    {
                        Buttons |= X360Buttons.RightStick;
                    }

                    if (currentState[3] != 0x0F)
                    {
                        if (currentState[3] == 0 || currentState[3] == 1 || currentState[3] == 7)
                        {
                            Buttons |= X360Buttons.Up;
                        }
                        if (currentState[3] == 4 || currentState[3] == 3 || currentState[3] == 5)
                        {
                            Buttons |= X360Buttons.Down;
                        }
                        if (currentState[3] == 6 || currentState[3] == 5 || currentState[3] == 7)
                        {
                            Buttons |= X360Buttons.Left;
                        }
                        if (currentState[3] == 2 || currentState[3] == 1 || currentState[3] == 3)
                        {
                            Buttons |= X360Buttons.Right;
                        }
                    }

                    if ((currentState[2] & 0x04) != 0)
                    {
                        Buttons |= X360Buttons.Start;
                    }
                    if ((currentState[2] & 0x08) != 0)
                    {
                        Buttons |= X360Buttons.Back;
                    }

                    if ((currentState[2] & 0x10) != 0)
                    {
                        Buttons |= X360Buttons.Logo;
                    }
                    //按下Fuze Logo键一下是不触发任何按键的,0x10是短按并松开fuze键时触发的按键
                    if ((currentState[2] & 0x01) != 0)
                    {
                        Buttons |= X360Buttons.Logo;
                    }
                    //长按会触发0x01按键,在GNU/Linux系统下,会触发关机键

                    /*
                     * //if ((currentState[20] & 1) != 0)
                     * //{
                     * //    last_mi_button = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                     * //    Buttons |= X360Buttons.Logo;
                     * //}
                     * //if (last_mi_button != 0) Buttons |= X360Buttons.Logo;
                     */

                    if (controller.Buttons != Buttons)
                    {
                        changed            = true;
                        controller.Buttons = Buttons;
                    }

                    short LeftStickX = (short)((Math.Max(-127.0, currentState[4] - 128) / 127) * 32767);
                    if (LeftStickX == -32767)
                    {
                        LeftStickX = -32768;
                    }

                    if (LeftStickX != controller.LeftStickX)
                    {
                        changed = true;
                        controller.LeftStickX = LeftStickX;
                    }

                    short LeftStickY = (short)((Math.Max(-127.0, currentState[5] - 128) / 127) * -32767);
                    if (LeftStickY == -32767)
                    {
                        LeftStickY = -32768;
                    }

                    if (LeftStickY != controller.LeftStickY)
                    {
                        changed = true;
                        controller.LeftStickY = LeftStickY;
                    }

                    short RightStickX = (short)((Math.Max(-127.0, currentState[6] - 128) / 127) * 32767);
                    if (RightStickX == -32767)
                    {
                        RightStickX = -32768;
                    }

                    if (RightStickX != controller.RightStickX)
                    {
                        changed = true;
                        controller.RightStickX = RightStickX;
                    }

                    short RightStickY = (short)((Math.Max(-127.0, currentState[7] - 128) / 127) * -32767);
                    if (RightStickY == -32767)
                    {
                        RightStickY = -32768;
                    }

                    if (RightStickY != controller.RightStickY)
                    {
                        changed = true;
                        controller.RightStickY = RightStickY;
                    }

                    if (controller.LeftTrigger != currentState[8])
                    {
                        changed = true;
                        controller.LeftTrigger = currentState[8];
                    }

                    if (controller.RightTrigger != currentState[9])
                    {
                        changed = true;
                        controller.RightTrigger = currentState[9];
                    }
                }

                if (data.Status == HidDeviceData.ReadStatus.WaitTimedOut || (!changed && ((last_changed + timeout) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))))
                {
                    changed = true;
                }

                if (changed)
                {
                    //Console.WriteLine("changed");
                    //Console.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
                    byte[] outputReport = new byte[8];
                    scpBus.Report(index, controller.GetReport(), outputReport);

                    //TODO: 震动
                    //if (outputReport[1] == 0x08)
                    //{
                    //    byte bigMotor = outputReport[3];
                    //    byte smallMotor = outputReport[4];
                    //    rumble_mutex.WaitOne();
                    //    if (bigMotor != Vibration[2] || Vibration[1] != smallMotor)
                    //    {
                    //        Vibration[1] = smallMotor;
                    //        Vibration[2] = bigMotor;
                    //    }
                    //    rumble_mutex.ReleaseMutex();
                    //}

                    /*
                     * //if (last_mi_button != 0)
                     * //{
                     * //    if ((last_mi_button + 100) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))
                     * //    {
                     * //        last_mi_button = 0;
                     * //        controller.Buttons ^= X360Buttons.Logo;
                     * //    }
                     * //}
                     *
                     * //last_changed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                     */
                }
            }
        }
示例#16
0
 private void SendData(object state)
 {
     bus.Report(1, controller.GetReport());
 }
示例#17
0
        public void Read()
        {
            if (_serialPort.BytesToRead != 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    fast[i] = (byte)_serialPort.ReadByte();
                }
                // string message = _serialPort.ReadLine();

                switch ((char)fast[0])
                {
                case 'A':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.A;
                        A.BackColor         = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.A;
                        A.BackColor         = Color.ForestGreen;
                    }
                    break;
                }

                case 'X':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.X;
                        X.BackColor         = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.X;
                        X.BackColor         = Color.ForestGreen;
                    }
                    break;
                }

                case 'Y':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.Y;
                        Y.BackColor         = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.Y;
                        Y.BackColor         = Color.ForestGreen;
                    }
                    break;
                }

                case 'B':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.B;
                        B.BackColor         = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.B;
                        B.BackColor         = Color.ForestGreen;
                    }
                    break;
                }

                case 'S':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.Start;
                        start.BackColor     = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.Start;
                        start.BackColor     = Color.ForestGreen;
                    }
                    break;
                }

                case 'R':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.Back;
                        back.BackColor      = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.Back;
                        back.BackColor      = Color.ForestGreen;
                    }
                    break;
                }

                case 'U':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.RightBumper;
                        RB.BackColor        = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.RightBumper;
                        RB.BackColor        = Color.ForestGreen;
                    }
                    break;
                }

                case 'D':
                {
                    if (fast[1] == 48)
                    {
                        controller.Buttons -= X360Buttons.LeftBumper;
                        LB.BackColor        = Color.Red;
                    }
                    else
                    {
                        controller.Buttons ^= X360Buttons.LeftBumper;
                        LB.BackColor        = Color.ForestGreen;
                    }
                    break;
                }

                case 'Z':
                {
                    controller.LeftTrigger = (byte)fast[1];

                    break;
                }

                case 'V':
                {
                    controller.RightTrigger = (byte)fast[1];

                    break;
                }

                case 'W':
                {
                    if (fast[1] == 48)
                    {
                        controller.LeftStickX = (sbyte)(fast[2] * 255 / 2);
                    }
                    else
                    {
                        controller.LeftStickX = (sbyte)(fast[2] * 255 / -2);
                    }


                    break;
                }
                }
            }

            // progressBar1.Value = fast[0] *  100 / 255;
            bool result = scpBus.Report(1, controller.GetReport());
        }
示例#18
0
        private void input_thread(HidDevice Device, ScpBus scpBus, int index)
        {
            scpBus.PlugIn(index);
            X360Controller controller = new X360Controller();
            int            timeout    = 10;
            //long last_changed = 0;
            //long last_mi_button = 0;
            bool ss_button_pressed = false;
            bool ss_button_held    = false;

            while (Running)
            {
                HidDeviceData data         = Device.Read(timeout);
                var           currentState = data.Data;
                //bool changed = false;
                if (data.Status == HidDeviceData.ReadStatus.Success && currentState.Length >= 10 && currentState[0] == 3)
                {
                    // NOTE: Console.WriteLine is blocking. If main thread sends a WriteLine while we do a WriteLine here, we're boned and will miss reports!
                    //Console.WriteLine(Program.ByteArrayToHexString(currentState));

                    X360Buttons Buttons = X360Buttons.None;
                    if ((currentState[3] & 64) != 0)
                    {
                        Buttons |= X360Buttons.A;
                    }
                    if ((currentState[3] & 32) != 0)
                    {
                        Buttons |= X360Buttons.B;
                    }
                    if ((currentState[3] & 16) != 0)
                    {
                        Buttons |= X360Buttons.X;
                    }
                    if ((currentState[3] & 8) != 0)
                    {
                        Buttons |= X360Buttons.Y;
                    }
                    if ((currentState[3] & 4) != 0)
                    {
                        Buttons |= X360Buttons.LeftBumper;
                    }
                    if ((currentState[3] & 2) != 0)
                    {
                        Buttons |= X360Buttons.RightBumper;
                    }
                    if ((currentState[3] & 1) != 0)
                    {
                        Buttons |= X360Buttons.LeftStick;
                    }
                    if ((currentState[2] & 128) != 0)
                    {
                        Buttons |= X360Buttons.RightStick;
                    }
                    ss_button_pressed = (currentState[2] & 1) != 0;
                    // [2] & 2 == Assistant, [2] & 1 == Screenshot

                    switch (currentState[1])
                    {
                    default:
                        break;

                    case 0:
                        Buttons |= X360Buttons.Up;
                        break;

                    case 1:
                        Buttons |= X360Buttons.UpRight;
                        break;

                    case 2:
                        Buttons |= X360Buttons.Right;
                        break;

                    case 3:
                        Buttons |= X360Buttons.DownRight;
                        break;

                    case 4:
                        Buttons |= X360Buttons.Down;
                        break;

                    case 5:
                        Buttons |= X360Buttons.DownLeft;
                        break;

                    case 6:
                        Buttons |= X360Buttons.Left;
                        break;

                    case 7:
                        Buttons |= X360Buttons.UpLeft;
                        break;
                    }

                    if ((currentState[2] & 32) != 0)
                    {
                        Buttons |= X360Buttons.Start;
                    }
                    if ((currentState[2] & 64) != 0)
                    {
                        Buttons |= X360Buttons.Back;
                    }

                    if ((currentState[2] & 16) != 0)
                    {
                        //last_mi_button = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                        Buttons |= X360Buttons.Logo;
                    }


                    //if (controller.Buttons != Buttons)
                    {
                        //changed = true;
                        controller.Buttons = Buttons;
                    }

                    // Note: The HID reports do not allow stick values of 00.
                    // This seems to make sense: 0x80 is center, so usable values are:
                    // 0x01 to 0x7F and 0x81 to 0xFF.
                    // For our purposes I believe this is undesirable. Subtract 1 from negative
                    // values to allow maxing out the stick values.
                    // TODO: Get an Xbox controller and verify this is standard behavior.
                    for (int i = 4; i <= 7; ++i)
                    {
                        if (currentState[i] <= 0x7F && currentState[i] > 0x00)
                        {
                            currentState[i] -= 0x01;
                        }
                    }

                    ushort LeftStickXunsigned = (ushort)(currentState[4] << 8 | (currentState[4] << 1 & 255));
                    if (LeftStickXunsigned == 0xFFFE)
                    {
                        LeftStickXunsigned = 0xFFFF;
                    }
                    short LeftStickX = (short)(LeftStickXunsigned - 0x8000);

                    //if (LeftStickX != controller.LeftStickX)
                    {
                        //	changed = true;
                        controller.LeftStickX = LeftStickX;
                    }

                    ushort LeftStickYunsigned = (ushort)(currentState[5] << 8 | (currentState[5] << 1 & 255));
                    if (LeftStickYunsigned == 0xFFFE)
                    {
                        LeftStickYunsigned = 0xFFFF;
                    }
                    short LeftStickY = (short)(-LeftStickYunsigned + 0x7FFF);
                    if (LeftStickY == -1)
                    {
                        LeftStickY = 0;
                    }
                    //if (LeftStickY != controller.LeftStickY)
                    {
                        //	changed = true;
                        controller.LeftStickY = LeftStickY;
                    }

                    ushort RightStickXunsigned = (ushort)(currentState[6] << 8 | (currentState[6] << 1 & 255));
                    if (RightStickXunsigned == 0xFFFE)
                    {
                        RightStickXunsigned = 0xFFFF;
                    }
                    short RightStickX = (short)(RightStickXunsigned - 0x8000);

                    //if (RightStickX != controller.RightStickX)
                    {
                        //	changed = true;
                        controller.RightStickX = RightStickX;
                    }

                    ushort RightStickYunsigned = (ushort)(currentState[7] << 8 | (currentState[7] << 1 & 255));
                    if (RightStickYunsigned == 0xFFFE)
                    {
                        RightStickYunsigned = 0xFFFF;
                    }
                    short RightStickY = (short)(-RightStickYunsigned + 0x7FFF);
                    if (RightStickY == -1)
                    {
                        RightStickY = 0;
                    }

                    //if (RightStickY != controller.RightStickY)
                    {
                        //	changed = true;
                        controller.RightStickY = RightStickY;
                    }

                    //if (controller.LeftTrigger != currentState[8])
                    {
                        //	changed = true;
                        controller.LeftTrigger = currentState[8];
                    }

                    //if (controller.RightTrigger != currentState[9])
                    {
                        //	changed = true;
                        controller.RightTrigger = currentState[9];
                    }
                }

                /*
                 * if (data.Status == HidDeviceData.ReadStatus.WaitTimedOut || (!changed && ((last_changed + timeout) < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))))
                 * {
                 *      changed = true;
                 * }*/

                //if (changed)
                {
                    //Console.WriteLine("changed");
                    //Console.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
                    byte[] outputReport = new byte[8];
                    scpBus.Report(index, controller.GetReport(), outputReport);

                    if (outputReport[1] == 0x08)
                    {
                        byte bigMotor   = outputReport[3];
                        byte smallMotor = outputReport[4];

                        if (smallMotor != Vibration[3] || Vibration[1] != bigMotor)
                        {
                            // We only need to take the mutex if we're modifying the data
                            rumble_mutex.WaitOne();
                            Vibration[1] = bigMotor;
                            Vibration[3] = smallMotor;
                            rumble_mutex.ReleaseMutex();
                            rumbleWaitHandle.Set();
                        }
                    }

                    //last_changed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                }

                if (ss_button_pressed && !ss_button_held)
                {
                    ss_button_held = true;
                    try
                    {
                        // TODO: Allow configuring this keybind.
                        ssThread = new Thread(() => System.Windows.Forms.SendKeys.SendWait("^+Z"));
                        ssThread.Start();
                    }
                    catch
                    {
                    }
                }
                else if (ss_button_held && !ss_button_pressed)
                {
                    ss_button_held = false;
                }
            }
        }
示例#19
0
        public static void setJoystick(GCNState input, int joystickID, ControllerDeadZones deadZones)
        {
            int            multiplier = 302;
            X360Controller controller = Controllers[joystickID - 1];

            //32767
            //analog stick
            controller.LeftStickX = (short)(multiplier * (128 - input.analogX));
            controller.LeftStickY = (short)(multiplier * (128 - input.analogY));

            //c stick
            controller.RightStickX = (short)(multiplier * (128 - input.cstickX));
            controller.RightStickY = (short)(multiplier * (128 - input.cstickY));

            //triggers
            controller.LeftTrigger  = (byte)input.analogL;
            controller.RightTrigger = (byte)input.analogR;

            controller.Buttons = 0;

            //dpad button mode for DDR pad support
            if (input.up)
            {
                controller.Buttons |= X360Buttons.Up;
            }
            if (input.down)
            {
                controller.Buttons |= X360Buttons.Down;
            }
            if (input.left)
            {
                controller.Buttons |= X360Buttons.Left;
            }
            if (input.right)
            {
                controller.Buttons |= X360Buttons.Right;
            }

            //buttons
            if (input.A)
            {
                controller.Buttons |= X360Buttons.A;
            }
            if (input.B)
            {
                controller.Buttons |= X360Buttons.X;
            }
            if (input.X)
            {
                controller.Buttons |= X360Buttons.B;
            }
            if (input.Y)
            {
                controller.Buttons |= X360Buttons.Y;
            }
            if (input.Z)
            {
                controller.Buttons |= X360Buttons.Logo;
            }
            if (input.R)
            {
                controller.Buttons |= X360Buttons.RightBumper;
            }
            if (input.L)
            {
                controller.Buttons |= X360Buttons.LeftBumper;
            }
            if (input.start)
            {
                controller.Buttons |= X360Buttons.Start;
            }

            scp.Report(joystickID, controller.GetReport());
        }