/
WeatherRack.h
151 lines (95 loc) · 2.69 KB
/
WeatherRack.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
boolean fuzzyCompare(float compareValue, float value)
{
#define VARYVALUE 0.05
if ( (value > (compareValue * (1.0 - VARYVALUE))) && (value < (compareValue * (1.0 + VARYVALUE))) )
{
return true;
}
return false;
}
float voltageToDegrees(float value, float defaultWindDirection)
{
// Note: The original documentation for the wind vane says 16 positions. Typically only recieve 8 positions. And 315 degrees was wrong.
// For 5V, use 1.0. For 3.3V use 0.66
#define ADJUST3OR5 1.00
#define PowerVoltage 5.0
if (fuzzyCompare(3.84 * ADJUST3OR5 , value))
return 0.0;
if (fuzzyCompare(1.98 * ADJUST3OR5, value))
return 22.5;
if (fuzzyCompare(2.25 * ADJUST3OR5, value))
return 45;
if (fuzzyCompare(0.41 * ADJUST3OR5, value))
return 67.5;
if (fuzzyCompare(0.45 * ADJUST3OR5, value))
return 90.0;
if (fuzzyCompare(0.32 * ADJUST3OR5, value))
return 112.5;
if (fuzzyCompare(0.90 * ADJUST3OR5, value))
return 135.0;
if (fuzzyCompare(0.62 * ADJUST3OR5, value))
return 157.5;
if (fuzzyCompare(1.40 * ADJUST3OR5, value))
return 180;
if (fuzzyCompare(1.19 * ADJUST3OR5, value))
return 202.5;
if (fuzzyCompare(3.08 * ADJUST3OR5, value))
return 225;
if (fuzzyCompare(2.93 * ADJUST3OR5, value))
return 247.5;
if (fuzzyCompare(4.62 * ADJUST3OR5, value))
return 270.0;
if (fuzzyCompare(4.04 * ADJUST3OR5, value))
return 292.5;
if (fuzzyCompare(4.34 * ADJUST3OR5, value)) // chart in documentation wrong
return 315.0;
if (fuzzyCompare(3.43 * ADJUST3OR5, value))
return 337.5;
//Serial.print(" FAIL WIND DIRECTION");
return defaultWindDirection; // return previous value if not found
}
void serviceInterruptRain()
{
unsigned long currentTime = (unsigned long) (micros() - lastRainTime);
// lastRainTime = micros();
// if (currentTime > 500) // debounce
// {
TotalRainClicks++;
wakeState = RAIN_INTERRUPT;
// interrupt_count[19]++;
// if(currentTime<currentRainMin)
// {
// currentRainMin=currentTime;
// }
return;
//}
//wakeState = IGNORE_INTERRUPT;
}
void serviceInterruptAnem()
{
wakeState = ANEMOMETER_INTERRUPT;
// software debounce for 17 msec (limits us to 90 MPH)!
if (ignore_anemometer_interrupt== true)
{
return;
}
unsigned long currentTime = (unsigned long)(micros() - lastWindTime);
if (currentTime < shortestWindTime)
{
shortestWindTime = currentTime;
}
windClicks++;
/*
if (currentTime > 500) // debounce
{
wakeState = ANEMOMETER_INTERRUPT;
windClicks++;
if (currentTime < shortestWindTime)
{
shortestWindTime = currentTime;
}
return;
}
wakeState = IGNORE_INTERRUPT;
*/
}