private void ControllerDisconnected(object sender, EventArgs e) { currentSerialPortReader.ControllerStateChanged -= ControllerStateChanged; currentSerialPortReader.ControllerDisconnected -= ControllerDisconnected; currentSerialPortReader.Dispose(); currentSerialPortReader = null; lastState = null; }
public void Detatch() { if (currentSerialPortReader is not null) { currentSerialPortReader.Dispose(); currentSerialPortReader = null; lastState = null; } }
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; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { currentSerialPortReader?.Dispose(); currentSerialPortReader = null; lastState = null; } disposedValue = true; } }
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); }