Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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()})");
        }
Exemplo n.º 4
0
        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})");
        }
Exemplo n.º 5
0
 private bool OnPinValueChanged(OnValueChangedEventArgs args)
 {
     return(true);
 }