Repository navigation
Expand file tree
/
Copy pathMwaveSensorModule.hpp
More file actions
67 lines (54 loc) · 1.8 KB
/
Copy pathMwaveSensorModule.hpp
File metadata and controls
67 lines (54 loc) · 1.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef MWAVE_SENSOR_MODULE_HPP
#define MWAVE_SENSOR_MODULE_HPP
#include <Arduino.h>
#include <vector>
#include "PsramUtils.hpp"
#include "webconfig.hpp"
#include "HardwareConfig.hpp"
// Enum für den Sensortyp
enum SensorEventType { EVENT_ON, EVENT_OFF };
// Struct für ein Sensor-Event
struct SensorEvent {
time_t timestamp;
SensorEventType type;
};
// Struct für den Log-Eintrag
struct DisplayStateLogEntry {
time_t timestamp;
bool state; // true = AN, false = AUS
};
class MwaveSensorModule {
public:
MwaveSensorModule(DeviceConfig& deviceConf, HardwareConfig& hardwareConf, HardwareSerial& serial);
void begin();
void update(time_t now_utc);
bool isDisplayOn() const;
time_t getLastOnTime() const;
time_t getLastOffTime() const;
float getOnPercentage() const;
const PsramVector<DisplayStateLogEntry>& getDisplayStateLog() const;
private:
DeviceConfig& config;
HardwareConfig& hwConfig;
HardwareSerial& sensorSerial;
bool isDisplayOnState = true;
time_t lastStateChangeToOnTime = 0;
time_t lastStateChangeToOffTime = 0;
bool initialStateSet = false;
float currentOnPercentage = 100.0f;
PsramVector<SensorEvent> slidingEventHistory;
PsramVector<DisplayStateLogEntry> displayStateLog;
time_t offCheckWindowStartTime = 0;
unsigned int onCountInOffWindow = 0;
unsigned int offCountInOffWindow = 0;
time_t firstOffTimeInOffWindow = 0;
void sendHexData(const char* hexString);
void processSensorData(const char* data, time_t now);
void handleSensorSerial(time_t now);
void resetOffCheckWindowCounters();
void logStateChange(bool state, time_t timestamp);
// Statische Member nur deklarieren
static char sensorDataBuffer[256];
static int sensorDataIndex;
};
#endif // MWAVE_SENSOR_MODULE_HPP