private void OnPollResult(bool currentValue, GpioPinState currentState) { if (!IsPossible) { return; } bool isSame = PreviousValue.PinState == currentState; Pin pinConfig = Driver.GetPinConfig(Config.GpioPin); OnValueChangedEventArgs args; switch (Config.PinEventState) { case PinEventStates.Activated when currentState == GpioPinState.On && !isSame: args = new OnValueChangedEventArgs(Config.GpioPin, currentState, currentValue, Config.PinMode, PinEventStates.Activated, PreviousValue.PinState, PreviousValue.DigitalValue); Config.OnEvent?.Invoke(args); break; case PinEventStates.Deactivated when currentState == GpioPinState.Off && !isSame: args = new OnValueChangedEventArgs(Config.GpioPin, currentState, currentValue, Config.PinMode, PinEventStates.Deactivated, PreviousValue.PinState, PreviousValue.DigitalValue); Config.OnEvent?.Invoke(args); break; case PinEventStates.Both when PreviousValue.PinState != currentState: args = new OnValueChangedEventArgs(Config.GpioPin, currentState, currentValue, Config.PinMode, PinEventStates.Both, PreviousValue.PinState, PreviousValue.DigitalValue); Config.OnEvent?.Invoke(args); break; } PreviousValue.Set(currentState, currentValue); }
private void OnEventResult(ref PinEventConfiguration config) { if (config == null || !PinController.IsValidPin(config.GpioPin)) { return; } if (config.Current.Equals(config.Previous)) { return; } OnValueChangedEventArgs onValueChangedEventArgs = new OnValueChangedEventArgs(config.GpioPin, (CurrentValue)config.Current, (PreviousValue)config.Previous); switch (config.EventState) { case PinEventState.Activated when config.Current.DigitalValue: OnActivatedEventArgs onActivatedEventArgs = new OnActivatedEventArgs(config.GpioPin, (CurrentValue)config.Current); ParallelExecuteOnEach(config.EventState, (p) => p.OnActivated(this, onActivatedEventArgs)).RunSynchronously(); break; case PinEventState.Deactivated when !config.Current.DigitalValue: OnDeactivatedEventArgs onDeactivatedEventArgs = new OnDeactivatedEventArgs(config.GpioPin, (CurrentValue)config.Current); ParallelExecuteOnEach(config.EventState, (p) => p.OnDeactivated(this, onDeactivatedEventArgs)).RunSynchronously(); break; case PinEventState.Both: break; } ParallelExecuteOnEach(config.EventState, (p) => p.OnValueChanged(this, onValueChangedEventArgs)).RunSynchronously(); }
private void InputPinEvents(object sender, OnValueChangedEventArgs e) { if (sender == null) { return; } Logger.Info($"{e.CurrentMode.ToString()} | {e.Pin} has been set to {e.CurrentState.ToString()} state. ({e.PreviousPinState.ToString()})"); }
public void OnValueChanged(object sender, OnValueChangedEventArgs e) { if ((sender == null) || (e == null)) { return; } Logger.Warn($"[{nameof(OnValueChanged)}] | {e.TimeStamp} -> {e.Pin} -> {e.Current.State} ({e.Previous.State})"); }
private bool OnPinValueChanged(OnValueChangedEventArgs args) { return(true); }