32 static PIRSensor _instance;
42 pinMode(
intPin, INPUT_PULLDOWN);
51 attachInterrupt(
intPin, pirISR, RISING);
73 if (!_motionDetected) {
78 _motionDetected =
false;
79 unsigned long nowMs = millis();
80 if (nowMs - _lastEventMs < 500) {
85 _data.timestamp = Time.now();
86 _data.hasNewData =
true;
117 strncpy(_data.sensorType,
"PIR",
sizeof(_data.sensorType) - 1);
118 _data.sensorType[
sizeof(_data.sensorType) - 1] =
'\0';
120 _motionDetected =
false;
140 Log.info(
"PIR sensor powered down for sleep");
155 pinMode(
intPin, INPUT_PULLDOWN);
160 attachInterrupt(
intPin, pirISR, RISING);
163 Log.info(
"PIR sensor powered up after wake (interrupt attached)");
175 PIRSensor(
const PIRSensor&) =
delete;
176 PIRSensor& operator=(
const PIRSensor&) =
delete;
182 unsigned long _lastEventMs = 0;
185 static volatile bool _motionDetected;
186 static volatile uint32_t _isrCount;
189 static void pirISR();
Persistent Data Storage Structures - EEPROM/Retained Memory Management.
Abstract interface for all sensors.
PIR (Passive Infrared) Motion Sensor Implementation.
void reset() override
Reset sensor state.
static PIRSensor & instance()
Get singleton instance.
bool loop() override
Poll the PIR sensor for motion detection.
bool isReady() const override
Check if sensor is ready.
SensorData getData() const override
Get latest sensor reading.
bool setup() override
Initialize the PIR sensor.
const char * getSensorType() const override
Get sensor type identifier.
bool onWake() override
Wake sensor from deep sleep: power up and re-attach ISR.
bool usesInterrupt() const override
This sensor uses a hardware interrupt for motion events.
void onSleep() override
Prepare sensor for deep sleep: detach ISR and power down.
const pin_t disableModule
Pinout definitions for the carrier board and sensors.
Generic sensor data structure.
char sensorType[16]
Type of sensor ("PIR", "Ultrasonic", etc.).