-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSensorRain.cpp
88 lines (68 loc) · 2.81 KB
/
SensorRain.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
#include "SensorRain.h"
//Initialize
SensorRain::SensorRain(int interrupt_pin)
{
r_int_pin=interrupt_pin;
rain=0;
lastRainIRQ = millis();
control=0;
}
//----------------------------------------- Get Rain -------------------------------------------
float SensorRain::getRain()
{
return (float)rain*0.2794; // 1 interrup represent 0.011" iches of rain 1" --> 0.2794 mm
}
//----------------------------------------------------------------------------------------------
//--------------------------------------- Get Rain Clicks --------------------------------------
long SensorRain::getRainClicks()
{
return rain;
}
//----------------------------------------------------------------------------------------------
//-------------------------------- Rain Interrupt Routine --------------------------------------
void SensorRain::ISR_RAIN()
{
// Ignore switch-bounce glitches less than 10mS after initial edge
if (millis() - lastRainIRQ > 10)
{
rain++; //Each dump is 0.011" of water
lastRainIRQ = millis(); // Set up for next event
}
control=1; // (FINAL VERSION: TO BE DELETED)
}
//----------------------------------------------------------------------------------------------
//--------------------------------- Attach Rain Interrupt --------------------------------------
void SensorRain::attachRainInterrupt()
{
pinMode(r_int_pin, INPUT_PULLUP); // input from wind meters windspeed sensor
attachInterrupt(digitalPinToInterrupt(r_int_pin), isr1, FALLING); //FALLING
SensorRain_instance = this;
}
//----------------------------------------------------------------------------------------------
//----------------------------- Auxiliar Rain Interrupt ISR ------------------------------------
void SensorRain::isr1()
{
SensorRain_instance->ISR_RAIN();
}
//----------------------------------------------------------------------------------------------
SensorRain * SensorRain::SensorRain_instance; // Auxiliar instance to Rain Interrupt ISR
//----------------------------------Clear the Rain values --------------------------------------
void SensorRain::clearRain()
{
rain=0;
control=0; // (FINAL VERSION: TO BE DELETED)
}
//----------------------------------------------------------------------------------------------
// (FINAL VERSION: TO BE DELETED)
//-------------------------------------- Clear Rain Control ------------------------------------
void SensorRain::clearRainControl()
{
control=0;
}
//----------------------------------------------------------------------------------------------
//--------------------------------------- Get Rain Control -------------------------------------
int SensorRain::getRainControl()
{
return control;
}
//----------------------------------------------------------------------------------------------