HomeWaterLeaksDetection
Consumption.cpp
Go to the documentation of this file.
1
#include "
Consumption.h
"
2
3
Consumption::Consumption
(
PulseCounter
*
pulseCounter
,
Type
type) {
4
this->pulseCounter =
pulseCounter
;
5
this->type =
type
;
6
7
initialDateTime
=
DateTime::getInstance
()->
getDateTime
();
8
count
= 0;
9
}
10
11
void
Consumption::update
() {
12
bool
timeToReset = 0;
13
RTCDateTime currentDateTime =
DateTime::getInstance
()->
getDateTime
();
14
15
// check if it's time to reset the counter as the
16
// monitoring period might be over
17
switch
(
type
) {
18
case
DAY
:
19
// test if the current day is different
20
if
(currentDateTime.day !=
initialDateTime
.day)
21
timeToReset = 1;
22
break
;
23
// test if the current week is different
24
case
WEEK
:
25
if
(currentDateTime.dayOfWeek == 1 &&
initialDateTime
.dayOfWeek == 7)
26
timeToReset = 1;
27
break
;
28
// test if the current month is different
29
case
MONTH
:
30
if
(currentDateTime.month !=
initialDateTime
.month)
31
timeToReset = 1;
32
break
;
33
}
34
// if it's time to reset the counter, do so
35
if
(timeToReset) {
36
initialDateTime
=
DateTime::getInstance
()->
getDateTime
();
37
count
= 0;
38
}
39
// if there's a pulse, increment the counter
40
if
(
pulseCounter
->
isActive
())
41
count
++;
42
}
43
44
int
Consumption::getConsumptionCount
()
const
{
45
return
count
;
46
}
Consumption.h
pulseCounter
PulseCounter pulseCounter(SENSOR_PIN)
Consumption::pulseCounter
PulseCounter * pulseCounter
instance of PulseCounter (input [l])
Definition:
Consumption.h:27
Consumption::MONTH
@ MONTH
monthly water consumption
Definition:
Consumption.h:22
Consumption::Type
Type
Type of the monitoring period.
Definition:
Consumption.h:19
Consumption::getConsumptionCount
int getConsumptionCount() const
Returns the current number of pulses detected so far within the monitoring period.
Definition:
Consumption.cpp:44
Consumption::type
Type type
type of the monitoring period
Definition:
Consumption.h:30
Consumption::initialDateTime
RTCDateTime initialDateTime
instance of RTCDateTime (real-time module)
Definition:
Consumption.h:28
Consumption::update
void update()
Updates the variables.
Definition:
Consumption.cpp:11
DateTime::getInstance
static DateTime * getInstance()
Returns the instance of the class.
Definition:
DateTime.cpp:26
PulseCounter
Definition:
PulseCounter.h:29
PulseCounter::isActive
int isActive() const
Returns information if a pulse has been detected.
Definition:
PulseCounter.cpp:40
DateTime::getDateTime
RTCDateTime getDateTime() const
Returns the current datatime.
Definition:
DateTime.cpp:51
Consumption::WEEK
@ WEEK
weekly water consumption
Definition:
Consumption.h:21
Consumption::Consumption
Consumption(PulseCounter *pulseCounter, Type type)
Constructor of the class.
Definition:
Consumption.cpp:3
Consumption::count
int count
number of pulses detected within the monitoring period
Definition:
Consumption.h:29
Consumption::DAY
@ DAY
daily water consumption
Definition:
Consumption.h:20
src
Consumption.cpp
Generated on Thu May 13 2021 08:42:38 for HomeWaterLeaksDetection by
1.8.18