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>
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
18const 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
31bool 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
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
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
104void 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
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 -
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
124{
125
126}
127#endif
128
129
130#endif
void sendMessageMQTT(char *message)
void registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
#define Elapsed4secs
const uint32_t SLEEP_DURATION_PIRSensorClass
unsigned long millis()
Definition: TinyGPS.cpp:35
void setup()
Pure Virtual Function.
PIRSensorClass(char *config)
constructor
void loop()
Pure Virtual Function.
virtual void messageCmd_SensorClassType(char *cmdValue)
virtual void messageSend_SensorClassType(char *sendValue)
virtual void messageSetVal_SensorClassType(char *setName, char *valValue, boolean deviceNameSpecified)
virtual void messageLocal_SensorClassType(char *message)
5.15.25 try a special command local to this class