private void DispatchState(object sender, BinaryStateChangedEventArgs e)
 {
     if (e.NewState == BinaryState.High)
     {
         Pressed?.Invoke(this, EventArgs.Empty);
     }
     else if (e.NewState == BinaryState.Low)
     {
         Released?.Invoke(this, EventArgs.Empty);
     }
 }
 private void HandleInputStateChanged(BinaryStateChangedEventArgs eventArgs)
 {
     // The relay at the motion detector is awlays held to high.
     // The signal is set to false if motion is detected.
     if (eventArgs.NewState == BinaryState.Low)
     {
         OnMotionDetected();
     }
     else
     {
         OnDetectionCompleted();
     }
 }
 private void DispatchEvents(object sender, BinaryStateChangedEventArgs eventArgs)
 {
     // The relay at the motion detector is awlays held to high.
     // The signal is set to false if motion is detected.
     if (eventArgs.NewState == BinaryState.Low)
     {
         MotionDetected?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         DetectionCompleted?.Invoke(this, EventArgs.Empty);
     }
 }
Пример #4
0
        private void HandleInputStateChanged(object sender, BinaryStateChangedEventArgs e)
        {
            if (!IsEnabled)
            {
                return;
            }

            bool buttonIsPressed = e.NewState == BinaryState.High;
            bool buttonIsReleased = e.NewState == BinaryState.Low;

            if (buttonIsPressed)
            {
                if (!IsActionForPressedLongAttached)
                {
                    OnPressedShort();
                }
                else
                {
                    _stopwatch.Restart();
                }
            }
            else if (buttonIsReleased)
            {
                if (!_stopwatch.IsRunning)
                {
                    return;
                }

                _stopwatch.Stop();
                if (_stopwatch.Elapsed >= TimeoutForPressedLongActions)
                {
                    OnPressedLong();
                }
                else
                {
                    OnPressedShort();
                }
            }
        }
Пример #5
0
 private void ForwardStateChangedEvent(object sender, BinaryStateChangedEventArgs e)
 {
     StateChanged?.Invoke(sender, new BinaryStateChangedEventArgs(CoerceState(e.OldState), CoerceState(e.NewState)));
 }