-
Notifications
You must be signed in to change notification settings - Fork 0
/
pir.cpp
54 lines (44 loc) · 1.18 KB
/
pir.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @package Wildlife Camera
* Motion sensor (PIR)
* @author WizLab.it
* @board AI-Thinker ESP32-CAM
* @version 20240821.007
*/
#include "pir.h"
/**
* Pir
* Class constructor
* @param pinSignal Pin that receives the PIR signal
* @param enabled If true, PIR signal triggers photo shot
*/
Pir::Pir(bool enabled, gpio_num_t pinSignal) {
//Save configurations
_enabled = enabled;
_pinSignal = pinSignal;
//Signal pin is initially configured as INPUT to allow SD Card activation
pinMode(_pinSignal, INPUT);
}
/**
* Pir::enable
* Enable PIR
* @param isr Pointer to the external PIR interrupt function
*/
void Pir::enable(void (*isr)()) {
//Save interrupt function
_isr = isr;
//Signal pin changed to INPUT_PULLDOWN, then attach interrupt
pinMode(_pinSignal, INPUT_PULLDOWN);
attachInterrupt(_pinSignal, _isr, RISING);
Serial.println(" [+] Motion sensor activated");
}
/**
* Pir::prepareDeepSleep
* Prepare PIR for deep sleep
* @param enableWakeupByPir If true, PIR can wake up device from deep sleep
*/
void Pir::prepareDeepSleep(bool enableWakeupByPir) {
if(_enabled && enableWakeupByPir) {
esp_sleep_enable_ext0_wakeup(_pinSignal, HIGH);
}
}