Пример #1
0
 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);
     }
 }
Пример #2
0
 private void ForwardState(object sender, BinaryStateChangedEventArgs e)
 {
     if (e.NewState == BinaryState.High)
     {
         StateChanged?.Invoke(this, new ButtonAdapterStateChangedEventArgs(AdapterButtonState.Pressed));
     }
     else if (e.NewState == BinaryState.Low)
     {
         StateChanged?.Invoke(this, new ButtonAdapterStateChangedEventArgs(AdapterButtonState.Released));
     }
 }
Пример #3
0
        private void HandleInputStateChanged(object sender, BinaryStateChangedEventArgs e)
        {
            bool buttonIsPressed  = e.NewState == BinaryState.High;
            bool buttonIsReleased = e.NewState == BinaryState.Low;

            if (buttonIsReleased)
            {
                SetState(ButtonState.Released);
            }
            else if (buttonIsPressed)
            {
                SetState(ButtonState.Pressed);
            }
            else
            {
                throw new NotSupportedException();
            }

            if (!Settings.IsEnabled.Value)
            {
                return;
            }

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

                _stopwatch.Stop();
                if (_stopwatch.Elapsed >= TimeoutForPressedLongActions)
                {
                    OnPressedLong();
                }
                else
                {
                    OnPressedShort();
                }
            }
        }
 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)
     {
         MotionDetectionBegin?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         MotionDetectionEnd?.Invoke(this, EventArgs.Empty);
     }
 }
 private void ForwardState(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)
     {
         StateChanged?.Invoke(this, new MotionDetectorAdapterStateChangedEventArgs(AdapterMotionDetectionState.MotionDetected));
     }
     else
     {
         StateChanged?.Invoke(this, new MotionDetectorAdapterStateChangedEventArgs(AdapterMotionDetectionState.Idle));
     }
 }
Пример #6
0
 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)
     {
         UpdateState(MotionDetectorState.MotionDetected);
     }
     else
     {
         UpdateState(MotionDetectorState.Idle);
     }
 }
Пример #7
0
        private void HandleInterrupt(object sender, BinaryStateChangedEventArgs e)
        {
            Task.Run(() =>
            {
                List <Action> callbacks;
                lock (_callbacks)
                {
                    callbacks = new List <Action>(_callbacks);
                }

                foreach (var callback in callbacks)
                {
                    TryExecuteCallback(callback);
                }
            });

            _log.Info("Detected interrupt at monitor '" + _id + "'.");
        }