public void Proccess(MotionDetected message) { _lastMovement = DateTime.Now; _win.Screen.TurnOn(); _monitorOn = true; Debug.WriteLine("Monitor ON"); }
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); } }
public async Task Handle(MotionDetected motionDetected, CancellationToken cancellationToken) { _logger.LogDebug($"Received {motionDetected} event."); if (!Started) { return; } var command = new StartPlayingSoundEffect(HighSoundFrequency); await _mediator.Send(command); }
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); } }
public async Task Handle_MotionDetected_requests_a_sound_effect_being_played() { // Arrange await _sut.Handle(new StartMotionDetection(), _defaultCancellationToken); var motionDetected = new MotionDetected(); // Act await _sut.Handle(motionDetected, _defaultCancellationToken); // Assert A.CallTo(() => _mediator.Send(A <StartPlayingSoundEffect> ._, A <CancellationToken> ._)) .MustHaveHappenedOnceExactly(); }
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; }
private void Sensor_Hcsr501ValueChanged(object sender, Hcsr501ValueChangedEventArgs e) { BaseEvent @event; if (e.PinValue == PinValue.High) { @event = new MotionDetected(); } else { @event = new MotionStopped(); } Task.Run(async() => await _mediator.Publish(@event)); }
/// <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(); }