-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateStore.cpp
33 lines (29 loc) · 909 Bytes
/
StateStore.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
#include "StateStore.h"
StateStore::StateStore(Subscriber *subscriber, Logger *logger)
{
this->state = new State();
this->subscriber = subscriber;
this->logger = logger;
}
void StateStore::dispatch(char type, unsigned long timestamp, String data)
{
this->logger->info(String(type) + " " + data);
bool stateHasChanged = false;
switch (type) {
case ATMOS_PRESSURE_WAS_MEASURED:
if (this->lastTimestamps[0] == 0 || timestamp - this->lastTimestamps[0] >= 108 * 1000) {
this->state->addPressure(data.toInt());
this->lastTimestamps[0] = timestamp;
stateHasChanged = true;
}
if (timestamp - this->lastTimestamps[1] >= 3600 * 1000) {
this->state->addDelta(data.toInt());
this->lastTimestamps[1] = timestamp;
stateHasChanged = true;
}
break;
}
if (stateHasChanged) {
this->subscriber->handle(this->state);
}
}