Esempio n. 1
0
 public bool Equals(SwitchInputState other)
 {
     return(Buttons == other.Buttons &&
            DPad == other.DPad &&
            LeftX == other.LeftX &&
            LeftY == other.LeftY &&
            RightX == other.RightX &&
            RightY == other.RightY);
 }
Esempio n. 2
0
 private void ApplyFrameToState(InputFrame frame)
 {
     _state = new SwitchInputState
     {
         Buttons = (_state.Buttons | (frame.PressedButtons ?? Button.None)) & ~(frame.ReleasedButtons ?? Button.None), // & ~(Button.Home | Button.Share),
         DPad    = frame.DPad ?? _state.DPad,
         LeftX   = frame.LeftX ?? _state.LeftX,
         LeftY   = frame.LeftY ?? _state.LeftY,
         RightX  = frame.RightX ?? _state.RightX,
         RightY  = frame.RightY ?? _state.RightY
     };
 }
Esempio n. 3
0
        private byte[] TranslateState(SwitchInputState state)
        {
            var buf = new byte[9];

            buf[0] = (byte)(((int)state.Buttons & 0xFF00) >> 8);
            buf[1] = (byte)((int)state.Buttons & 0xFF);
            buf[2] = (byte)state.DPad;
            buf[3] = state.LeftX;
            buf[4] = state.LeftY;
            buf[5] = state.RightX;
            buf[6] = state.RightY;
            buf[7] = 0;
            buf[8] = Utils.CalculateCrc8(buf, 0, buf.Length - 1);
            return(buf);
        }
Esempio n. 4
0
        public SwitchInputSink(string portName)
        {
            _state        = new SwitchInputState();
            _queuedFrames = new ConcurrentQueue <InputFrame>();

            workerThread = new Thread(ThreadLoop);
            workerThread.Start(portName);
            Update(new InputFrame
            {
                PressedButtons  = Button.None,
                ReleasedButtons = Button.All,
                DPad            = DPad.None,
                LeftX           = 128,
                LeftY           = 128,
                RightX          = 128,
                RightY          = 128
            });
        }