private void inputModule_InputValueChanged(object sender, InputValueChangedEventArgs e) { IEnumerable <InputEffectMap> inputEffects = _inputEffects.Where(x => x.IsMappedTo(e.InputModule, e.Input)); IEnumerable <EffectNode> effectNodes = inputEffects.Select(x => x.GenerateEffect(e.Input, EffectTimeSpan)); OnInputsChanged(new InputsChangedEventArgs(effectNodes)); }
private void FtInterfaceOnInputValueChanged(object sender, InputValueChangedEventArgs inputValueChangedEventArgs) { // Go throught every changed input port and update the displayed value foreach (int inputPort in inputValueChangedEventArgs.InputPorts) { UpdateInputValue(inputPort); } }
private static void ControllerOnInputValueChanged(object sender, InputValueChangedEventArgs inputValueChangedEventArgs) { Console.SetCursorPosition(0, Console.CursorTop - 1); for (int i = 0; i < _controller.GetInputCount(); i++) { Console.Write("I{0,1} {1, 5} |", i + 1, _controller.GetInputValue(i)); } Console.WriteLine(); }
public void UpdateValues() { ThrowWhenNotConnected(); if (_configurationChanged) { UpdateConfiguration(); _configurationChanged = false; } var outputPacket = new OutputPacket(); var inputPacket = new InputPacket(); for (int i = 0; i < _masterInterface.OutputValues.Length; i++) { outputPacket.PwmOutputValues[i] = (short)_masterInterface.OutputValues[i]; } try { TxCommunication.SendPacket(outputPacket, inputPacket); } catch (Exception e) { HandleException(e); return; } IList <int> valueChanged = new List <int>(); for (int i = 0; i < inputPacket.UniversalInputs.Length; i++) { var newInputValue = inputPacket.UniversalInputs[i]; if (_masterInterface.GetInputValue(i) != newInputValue) { _masterInterface.SetInputValue(i, (short)newInputValue); valueChanged.Add(i); } } if (valueChanged.Count > 0) { // Fire an event when an input value has changed InputValueChangedEventArgs eventArgs = new InputValueChangedEventArgs(valueChanged); _inputValueChanged?.Invoke(this, eventArgs); } }
public void StartOnlineMode() { LogMessage("Starting online mode"); if (Connection == ConnectionStatus.Online) { throw new InvalidOperationException("Already in online mode"); } ThrowWhenNotConnected(); _updateValuesTimer = new Timer(UpdateInterval); _updateValuesTimer.Elapsed += UpdateValuesTimerTick; _updateValuesTimer.AutoReset = true; try { // Send an echo packet to obtain the session id var echoResponsePacket = new EchoResponsePacket(); TxCommunication.SendPacket(new EchoPacket(), echoResponsePacket); Connection = ConnectionStatus.Online; // Start update timer _updateValuesTimer.Start(); // Fire event to notify that online mode has started _onlineStarted?.Invoke(this, new EventArgs()); // Fire InputValueChanged event with default values List <int> inputPorts = new List <int>(); for (int i = 0; i < UniversalInputs; i++) { inputPorts.Add(i); } InputValueChangedEventArgs eventArgs = new InputValueChangedEventArgs(inputPorts); _inputValueChanged?.Invoke(this, eventArgs); } catch (Exception e) { LogMessage($"Exception while starting online mode: {e.Message}"); Connection = ConnectionStatus.Invalid; HandleException(e); } LogMessage("Online mode started"); }
public void StartOnlineMode() { LogMessage("Starting online mode"); if (Connection == ConnectionStatus.Online) { throw new InvalidOperationException("Already in online mode"); } ThrowWhenNotConnected(); _updateValuesTimer = new Timer(UpdateInterval); _updateValuesTimer.Elapsed += UpdateValuesTimerTick; _updateValuesTimer.AutoReset = true; _soundPlayIndex = 0; _configurationIndex = 0; var responseStartOnline = new ResponseStartOnline(); try { TxtCommunication.SendCommand(new CommandStartOnline(), responseStartOnline); Connection = ConnectionStatus.Online; _updateValuesTimer.Start(); _onlineStarted?.Invoke(this, new EventArgs()); List <int> inputPorts = new List <int>(); for (int i = 0; i < UniversalInputs; i++) { inputPorts.Add(i); } InputValueChangedEventArgs eventArgs = new InputValueChangedEventArgs(inputPorts); _inputValueChanged?.Invoke(this, eventArgs); } catch (Exception e) { LogMessage($"Exception while starting online mode: {e.Message}"); Connection = ConnectionStatus.Invalid; HandleException(e); } LogMessage("Online mode started"); }
public void UpdateValues() { ThrowWhenNotConnected(); if (_configurationChanged) { UpdateConfiguration(); _configurationChanged = false; } var commandExchangeData = new CommandExchangeData(); var responseExchangeData = new ResponseExchangeData(); for (int i = 0; i < _masterInterface.OutputValues.Length; i++) { commandExchangeData.PwmOutputValues[i] = (short)_masterInterface.OutputValues[i]; } commandExchangeData.SoundCommandId = (ushort)_soundPlayIndex; if (_soundChanged) { commandExchangeData.SoundCommandId = (ushort)++_soundPlayIndex; commandExchangeData.SoundIndex = _masterInterface.SoundIndex; commandExchangeData.SoundRepeat = _masterInterface.SountRepeatCount; _soundChanged = false; _soundPlaying = true; } try { TxtCommunication.SendCommand(commandExchangeData, responseExchangeData); } catch (Exception e) { HandleException(e); return; } IList <int> valueChanged = new List <int>(); for (int i = 0; i < responseExchangeData.UniversalInputs.Length; i++) { var newInputValue = responseExchangeData.UniversalInputs[i]; if (_masterInterface.GetInputValue(i) != newInputValue) { _masterInterface.SetInputValue(i, newInputValue); valueChanged.Add(i); } } if (valueChanged.Count > 0) { // Fire an event when an input value has changed InputValueChangedEventArgs eventArgs = new InputValueChangedEventArgs(valueChanged); _inputValueChanged?.Invoke(this, eventArgs); } if (responseExchangeData.SoundCommandId != _soundPlayIndex - 1 && _soundPlaying) { _soundPlaying = false; // Fire an event when the sound playback has finished _soundPlaybackFinished?.Invoke(this, new EventArgs()); } }