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; }
private void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) { if (Detector.ProcessFrame((Bitmap)eventArgs.Frame.Clone()) > DetectionThreshold) { MotionDetected?.Invoke(); } }
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); } }
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); } }
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; }
/// <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); } } }); }
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)); } }
/// <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)); }
protected virtual void OnMotionDetected(EventArgs e) { MotionDetected?.Invoke(this, e); }
public void DetectMotion() { MotionDetected?.Invoke(this, EventArgs.Empty); }
private void OnMotionDetected() { MotionDetected?.Invoke(); }