コード例 #1
0
        private void ControllerDisconnected(object sender, EventArgs e)
        {
            currentSerialPortReader.ControllerStateChanged -= ControllerStateChanged;
            currentSerialPortReader.ControllerDisconnected -= ControllerDisconnected;

            currentSerialPortReader.Dispose();
            currentSerialPortReader = null;
            lastState = null;
        }
コード例 #2
0
 public void Detatch()
 {
     if (currentSerialPortReader is not null)
     {
         currentSerialPortReader.Dispose();
         currentSerialPortReader = null;
         lastState = null;
     }
 }
コード例 #3
0
 private void ControllerStateChanged(
     Readers.IControllerReader <Readers.SNESControllerState> reader,
     Readers.SNESControllerState newState)
 {
     if (lastState != newState)
     {
         //Handle new state
         controllerSpyHub.Clients.All.SendAsync("ControllerUpdate", newState);
         lastState = newState;
     }
 }
コード例 #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    currentSerialPortReader?.Dispose();
                    currentSerialPortReader = null;
                    lastState = null;
                }

                disposedValue = true;
            }
        }
コード例 #5
0
        public bool Attach(string port)
        {
            if (currentSerialPortReader is not null)
            {
                currentSerialPortReader.Dispose();
                currentSerialPortReader = null;
                lastState = null;
            }

            try
            {
                currentSerialPortReader = new Readers.SerialControllerReader <Readers.SNESControllerState>(port, Readers.SNESControllerState.Parse);
                currentSerialPortReader.ControllerStateChanged += ControllerStateChanged;
                currentSerialPortReader.ControllerDisconnected += ControllerDisconnected;
            }
            catch (Exception ex)
            {
                communication.SendWarningMessage($"Exception trying to bind ControllerManager to port {port}: {ex}");
                currentSerialPortReader = null;
            }

            return(currentSerialPortReader is not null);
        }