ESP_IOT
v2.5
IOT ESP Coding
PIRSensorClass.cpp
Go to the documentation of this file.
1
2
#include "
PIRSensorClass.h
"
3
#include "../../Defines.h"
4
//! minimal sensors are a sugset of sensors...
5
#if defined(ESP_M5) && !defined(ESP_M5_MINIMAL_SENSORS)
6
//#include <iostream>
7
#include <string.h>
8
#include <stdio.h>
9
PIRSensorClass::PIRSensorClass
(
char
*config) :
SensorClassType
(config)
10
{
11
12
printf(
"PIRSensorClass init %s\n"
, config);
13
}
14
15
//! 11.27.25 bringing in the M5 code for the HAT
16
//!
17
//#define PIR_PIN 36 //passive IR Hat
18
const
uint32_t
SLEEP_DURATION_PIRSensorClass
= 1 * 1000000;
19
20
//unsigned long _PrevSampleTime_PIRSensorClass = 0;
21
//unsigned long _PrevTriggerTime_PIRSensorClass = 0;
22
//unsigned long _InactivityTimeOut_PIRSensorClass = 0;
23
24
#define Elapsed3secs 3000
25
#define Elapsed4secs 4000
26
27
#define Elapsed3mins 180000
// 3 minutes in milliseconds
28
29
//!Return "true" on PIR (over sensitivity) and false otherwise
30
//!This is just a sensor (if plugged in) - so any timing is on the caller of this
31
bool
PIRSensorClass::checkPIR_ButtonProcessing()
32
{
33
// if (!getPreferenceBoolean_mainModule(PREFERENCE_SENSOR_PIR_VALUE))
34
// return false;
35
36
boolean
triggeredPIR = digitalRead(
_pin2
);
37
if
(triggeredPIR)
38
{
39
if
((
millis
()-_PrevTriggerTime_PIRSensorClass)>
Elapsed4secs
)
40
{
41
triggeredPIR =
true
;
42
_PrevTriggerTime_PIRSensorClass =
millis
();
43
SerialTemp.println(
"triggeredPIR = true"
);
44
}
45
else
46
triggeredPIR =
false
;
47
}
48
return
triggeredPIR;
49
}
50
51
//!@see https://www.w3schools.com/cpp/cpp_class_methods.asp
52
void
PIRSensorClass::loop
()
53
{
54
//printf("PIRSensorClass::loop()\n");
55
56
//! call the check
57
long
triggered = checkPIR_ButtonProcessing();
58
//! what to do with trigger?
59
//! call feed
60
if
(triggered)
61
//! 11.26.25 send status as well .. so we can hear what's happening
62
//! 8.16.25 MQTT
63
//!also send a #STATUS
64
sendMessageMQTT
((
char
*)
"#STATUS"
);
65
}
66
67
void
PIRSensorClass::setup
()
68
{
69
SerialDebug.printf(
"PIRSensorClass::setup(%d,%d)\n"
,
_pin1
,
_pin2
);
70
71
72
if
(
_pin1
== 0)
73
{
74
//! default to 21,33
75
//! PIRSensorClass,23,33
76
_pin1
= 23;
77
_pin2
= 33;
78
}
79
80
//https://www.reddit.com/r/arduino/comments/1g89dlo/esp32_crashing_due_to_pinmode_and_fastled/
81
// pinMode(_pin1, OUTPUT);
82
// pinMode(_pin2, OUTPUT);
83
pinMode(
_pin2
,INPUT_PULLUP);
84
85
registerPinUse_mainModule
(
_pin1
,
"Pin1"
,
"PIRSensorClass"
,
false
);
86
registerPinUse_mainModule
(
_pin2
,
"Pin2"
,
"PIRSensorClass"
,
false
);
87
88
//! turn off..
89
// digitalWrite(_pin1, LOW);
90
// digitalWrite(_pin2, LOW);
91
92
SerialDebug.println(
"DONE PIRSensorClass::setup"
);
93
}
94
95
96
#ifdef NOT_USED
97
//! adding the messages as well
98
//! 5.14.25 (Laura/Paul flying). 5.14.74 great Dead
99
//! 8.28.23 Adding a way for others to get informed on messages that arrive
100
//! for the set,val
101
//! 12.27.23 support setName == "socket"
102
//! 1.10.24 if deviceNameSpecified then this matches this device, otherwise for all.
103
//! It's up to the receiver to decide if it has to be specified
104
void
PIRSensorClass::messageSetVal_SensorClassType
(
char
*setName,
char
* valValue,
boolean
deviceNameSpecified)
105
{
106
107
}
108
109
//! 5.15.25 try a special command local to this class
110
void
PIRSensorClass::messageLocal_SensorClassType
(
char
*message)
111
{
112
113
}
114
//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
115
//! for the send -
116
void
PIRSensorClass::messageSend_SensorClassType
(
char
*sendValue)
117
{
118
119
}
120
121
//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
122
//! for the cmd
123
void
PIRSensorClass::messageCmd_SensorClassType
(
char
*cmdValue)
124
{
125
126
}
127
#endif
128
129
130
#endif
sendMessageMQTT
void sendMessageMQTT(char *message)
Definition:
MQTTNetworking.cpp:2101
registerPinUse_mainModule
void registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
Definition:
MainModule.cpp:3980
Elapsed4secs
#define Elapsed4secs
Definition:
PIRSensorClass.cpp:25
SLEEP_DURATION_PIRSensorClass
const uint32_t SLEEP_DURATION_PIRSensorClass
Definition:
PIRSensorClass.cpp:18
PIRSensorClass.h
millis
unsigned long millis()
Definition:
TinyGPS.cpp:35
PIRSensorClass::setup
void setup()
Pure Virtual Function.
Definition:
PIRSensorClass.cpp:67
PIRSensorClass::PIRSensorClass
PIRSensorClass(char *config)
constructor
Definition:
PIRSensorClass.cpp:9
PIRSensorClass::loop
void loop()
Pure Virtual Function.
Definition:
PIRSensorClass.cpp:52
SensorClassType
Definition:
SensorClassType.h:26
SensorClassType::messageCmd_SensorClassType
virtual void messageCmd_SensorClassType(char *cmdValue)
Definition:
SensorClassType.h:106
SensorClassType::_pin1
int _pin1
Definition:
SensorClassType.h:113
SensorClassType::_pin2
int _pin2
pin2
Definition:
SensorClassType.h:115
SensorClassType::messageSend_SensorClassType
virtual void messageSend_SensorClassType(char *sendValue)
Definition:
SensorClassType.h:102
SensorClassType::messageSetVal_SensorClassType
virtual void messageSetVal_SensorClassType(char *setName, char *valValue, boolean deviceNameSpecified)
Definition:
SensorClassType.h:98
SensorClassType::messageLocal_SensorClassType
virtual void messageLocal_SensorClassType(char *message)
5.15.25 try a special command local to this class
Definition:
SensorClassType.h:109
src
SensorClass
PIRSensorClass.cpp
Generated on Fri Jan 30 2026 12:52:10 for ESP_IOT by
1.9.5