-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pump.cpp
77 lines (60 loc) · 1.28 KB
/
Pump.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
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
68
69
70
71
72
73
74
75
76
#include <EEPROM.h>
#include "Pump.h"
Pump::Pump(int eepromOffset)
{
this->eepromOffset = eepromOffset;
currentCount = 0;
lastRunTime = 0;
lastRunDuration = 0;
currentRunStart = 0;
EEPROM.get(sizeof(NonVolatileStats) * eepromOffset, nv);
}
void Pump::OnStart(Event *e)
{
currentCount++;
currentRunStart = e->time;
nv.lifetimeCount++;
EEPROM.put(sizeof(NonVolatileStats) * eepromOffset, nv);
}
void Pump::OnStop(Event *e)
{
lastRunTime = currentRunStart;
lastRunDuration = e->time - lastRunTime;
currentRunStart = 0;
if(lastRunDuration < nv.shortestRun || nv.shortestRun == 0) {
nv.shortestRun = lastRunDuration;
}
if(lastRunDuration > nv.longestRun) {
nv.longestRun = lastRunDuration;
}
EEPROM.put(sizeof(NonVolatileStats) * eepromOffset, nv);
}
void Pump::ResetStatistics()
{
nv.shortestRun = 0;
nv.longestRun = 0;
currentCount = 0;
lastRunTime = 0;
lastRunDuration = 0;
EEPROM.put(sizeof(NonVolatileStats) * eepromOffset, nv);
}
long Pump::GetCurrentCount()
{
return currentCount;
}
long Pump::GetLifetimeCount()
{
return nv.lifetimeCount;
}
long Pump::GetShortestRun()
{
return nv.shortestRun;
}
long Pump::GetLongestRun()
{
return nv.longestRun;
}
long Pump::GetAverageRun()
{
return (nv.longestRun + nv.shortestRun) / 2;
}