コード例 #1
0
        private void MotionSensorPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (currentValue == args.Edge) //TODO: Is it needed? the same edge should not happend twice, it is not state value but state change
            {
                return;
            }

            switch (args.Edge)
            {
            case GpioPinEdge.RisingEdge:
                if (MotionDetected == null)
                {
                    return;
                }
                MotionDetected.Invoke(this, null);
                break;

            case GpioPinEdge.FallingEdge:
                if (MotionUndetected == null)
                {
                    return;
                }
                MotionUndetected.Invoke(this, null);
                break;
            }

            currentValue = args.Edge;
        }
コード例 #2
0
 private void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     if (Detector.ProcessFrame((Bitmap)eventArgs.Frame.Clone()) > DetectionThreshold)
     {
         MotionDetected?.Invoke();
     }
 }
コード例 #3
0
        private void OnPinChanged(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
        {
            var value = gpioController.Read(InPinNumber);

            var duration = DateTime.Now - triggerTimestamp;

            if (duration.TotalMilliseconds < InterruptTime)
            {
                return;
            }

            //Console.WriteLine(duration);

            if (value == PinValue.Low)
            {
                triggerTimestamp = DateTime.Now;

                MotionNotDetected?.Invoke(this, EventArgs.Empty);
            }
            else if (value == PinValue.High)
            {
                triggerTimestamp = DateTime.Now;

                MotionDetected?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
        private async void _device_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            //detect motion
            if (DetectorConfiguration != null)
            {
                var result = await DetectMotionAsync(_previousFrame, eventArgs.Frame);

                if (result.Direction.X != MovementDirection.None && result.Direction.Y != MovementDirection.None)
                {
                    MotionDetected?.Invoke(this, result);
                }
            }
            _previousFrame = eventArgs.Frame;
        }
コード例 #6
0
 /// <summary>
 /// Start sensor's reading loop
 /// </summary>
 private async void Run()
 {
     await Task.Factory.StartNew(async() =>
     {
         while (true)
         {
             if (IsActive)
             {
                 var value = Pin.Read();
                 if (value == GpioPinValue.High)
                 {
                     MotionDetected?.Invoke(Pin.PinNumber);
                 }
                 await Task.Delay(1000);
             }
         }
     });
 }
コード例 #7
0
        public override void ParseData(JObject data)
        {
            if (data["status"] != null)
            {
                Status = data["status"].ToString();

                if (Status == "motion")
                {
                    LastMotionTimestamp = DateTime.Now;
                    MotionDetected?.Invoke(this, EventArgs.Empty);
                }
            }

            if (data["no_motion"] != null)
            {
                NoMotion = int.Parse(data["no_motion"].ToString());

                OnNoMotion?.Invoke(this, new NoMotionEventArgs(NoMotion));
            }
        }
コード例 #8
0
 /// <summary>
 /// Enables the sensor, and listens for motion detection
 /// </summary>
 /// <param name="sensorPin">The GPIO pin of the PIR Sensor</param>
 public PirSensor(GpioPin sensorPin)
 {
     sensorPin.PinMode = GpioPinDriveMode.Input;
     sensorPin.RegisterInterruptCallback(EdgeDetection.FallingEdge, () => MotionDetected.Invoke(this, EventArgs.Empty));
 }
コード例 #9
0
 protected virtual void OnMotionDetected(EventArgs e)
 {
     MotionDetected?.Invoke(this, e);
 }
コード例 #10
0
 public void DetectMotion()
 {
     MotionDetected?.Invoke(this, EventArgs.Empty);
 }
コード例 #11
0
 private void OnMotionDetected()
 {
     MotionDetected?.Invoke();
 }