-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseSensor.cpp
101 lines (90 loc) · 2.16 KB
/
BaseSensor.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "BaseSensor.h"
BaseSensor::BaseSensor(int p,long sid, int f)
{
ppu = p;
SID = sid;
Factor = f;
}
void BaseSensor::Begin(byte i)
{
Actual = 0;
Peak = 0;
Today = 0;
ee = (i+20) * 4; // the eeprom address of this sensor where the last value is saved
todayCnt = eeprom_read_dword((uint32_t*) ee);
ee2 = (i+40) * 4; // the eeprom address for the total counters
Midnight = eeprom_read_dword((uint32_t*) ee2);
pulseLength = 0;
lastMillis = 0;
}
void BaseSensor::CheckSensor()
{
// Check sensor must be done by the derived sensor
}
void BaseSensor::Loop(int m)
{
// Derived sensors can execute non time critical actions here
}
void BaseSensor::Save()
{
eeprom_write_dword((uint32_t*) ee, todayCnt);
}
void BaseSensor::Update(long Value)
{
todayCnt = Value;
Save();
}
void BaseSensor::NewTotal(long value)
{
// store the value of totalcounter at last midnight
Midnight = value - Today;
eeprom_write_dword((uint32_t*) ee2, Midnight);
}
void BaseSensor::Reset()
{
// update the totals
Midnight += Today;
// store the new totalcounter
eeprom_write_dword((uint32_t*) ee2, Midnight);
// reset the day counter
todayCnt = 0;
Today = 0;
}
void BaseSensor::ResetPeak()
{
Peak = 0;
}
void BaseSensor::CalculateActuals()
{
// Was the last BaseSensor pulse more than 5 minutes ago?
if(millis() - lastMillis > 300000)
{
Actual = 0; // then we have no output
}
else
{
if(pulseLength != 0) // prevent division by zero
{
// convert to W
Actual = 3600000000 / ppu;
Actual /= pulseLength;
if(Peak < abs(Actual)) Peak = Actual;
}
}
Today = todayCnt * 1000 / ppu;
}
void BaseSensor::Status(Print& client)
{
const char* td = "<td>";
client << td << SID;
//client << td << Type;
client << td << Actual;
client << td << Peak;
client << td << Today;
// client << td << Midnight + Today;
// client << td << Factor;
client << td << todayCnt;
// client << td << (long)eeprom_read_dword((uint32_t*) ee);
// client << td << ppu;
// client << td << pulseLength;
}