public bool Equals(SwitchInputState other)
 {
     return(Buttons == other.Buttons &&
            DPad == other.DPad &&
            LeftX == other.LeftX &&
            LeftY == other.LeftY &&
            RightX == other.RightX &&
            RightY == other.RightY);
 }
        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);
        }
        public SwitchInputSink(string portName)
        {
            _state        = new SwitchInputState();
            _queuedFrames = new ConcurrentQueue <InputFrame>();
            var 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
            });
        }
 private void ApplyFrameToState(InputFrame frame)
 {
     try
     {
         _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
         };
     }
     catch (Exception ex)
     {
         Program.form.ApplyLog(ex.Message);
     }
 }