HomeWaterLeaksDetection
LeaksController.h
Go to the documentation of this file.
1 #ifndef LEAKS_CONTROLLER_H
2 #define LEAKS_CONTROLLER_H
3 
4 #include "Arduino.h"
5 #include "map"
6 
7 #include "Setup.h"
8 #include "Pins.h"
9 #include "Button.h"
10 #include "IControllable.h"
11 #include "ALeakDetectable.h"
12 #include "PulseCounter.h"
13 #include "LimitsDefinition.h"
14 
15 //====================debugging=========================
16 
17 // if debugging is enabled,
18 // include this file as well
19 #ifdef DEBUG
20 # include <ILoggable.h>
21 #endif
22 
23 //====================web server========================
24 
25 // if the webserver is enabled,
26 // include these files as well
27 #ifdef WEB_SERVER
28 # include <HTMLDataSource.h>
29 # include <Consumption.h>
30 #endif
31 
32 //================email notifications===================
33 
34 // if email-notifications are
35 // enabled, include this file
36 // as well
37 #ifdef EMAIL_NOTIFICATION
38 # include <EmailSender.h>
39 #endif
40 
41 //==================LCD display=========================
42 
43 // if the LCD display is enabled,
44 // include this file as well
45 #ifdef LCD_DISPLAY
46 # include <IDisplayable.h>
47 #endif
48 
49 //==============ALeakDetectable class===================
50 
58 #ifdef DEBUG
59  , public ILoggable
60 #endif
61 #ifdef WEB_SERVER
62  , public HTMLDataSource
63 #endif
64 #ifdef LCD_DISPLAY
65  , public IDisplayable
66 #endif
67 {
68 //====================private data======================
69 private:
71  std::map<ALeakDetectable::Type, ALeakDetectable*> leaks;
73 
74  int valveState;
78 
79 //==================private methods=====================
80 private:
83 
86 
88  LeaksController& operator=(LeaksController const&) { return *this; }
89 
90 //==================public methods======================
91 public:
98  static LeaksController* getInstance();
99 
107 
114  int getNumberOfLeakDetections() const;
115 
121  void changeSettings(ALeakDetectable::Type type, unsigned long detected, unsigned long reset, bool alarm);
122 
129 
136  void update() override;
137 
144  String getFormatOfSettingsToSave();
145 
146 //==================UNIT testing========================
147 #ifdef UNIT_TEST
148  int getValveState() const { return valveState; }
155 #endif
156 
157 //====================debugging=========================
158 #ifdef DEBUG
159 public:
162  const String getLogDescription() const;
163 
166  const String getLogID() const;
167 #endif
168 
169 //==================LCD display=========================
170 #ifdef LCD_DISPLAY
171  const String getRow(int row) const override;
180 #endif
181 
182 //====================web server========================
183 #ifdef WEB_SERVER
184 private:
187 
190  std::map<int, String (*)(const LeaksController& leaksController)> htmlData;
191 
192 public:
200  const String getHTMLData(const int id) const override;
201 
205 
209 
210 private:
214  friend String HTML_valve(const LeaksController& leaksController);
215 
219  friend String HTML_alarm(const LeaksController& leaksController);
220 
224  friend String HTML_manualClose(const LeaksController& leaksController);
225 
229  friend String HTML_dailyConsumption(const LeaksController& leaksController);
230 
234  friend String HTML_monthlyConsumption(const LeaksController& leaksController);
235 #endif
236 };
237 
238 #endif
Pins.h
LeaksController::HTML_monthlyConsumption
friend String HTML_monthlyConsumption(const LeaksController &leaksController)
Associated function for returing the monthly water consumption in liters.
LeaksController::addLeakDetection
void addLeakDetection(ALeakDetectable::Type type, ALeakDetectable *leak)
Adds another water leak detection algorithm to the collection.
Definition: LeaksController.cpp:33
LeaksController::leaks
std::map< ALeakDetectable::Type, ALeakDetectable * > leaks
collection (map) of water leak detection algorithms
Definition: LeaksController.h:71
LeaksController::valveState
int valveState
state of the main valve
Definition: LeaksController.h:74
LeaksController::monthlyConsumptionCounter
Consumption * monthlyConsumptionCounter
monthly water consumption
Definition: LeaksController.h:186
Consumption.h
IDisplayable.h
LeaksController::LeaksController
LeaksController()
Constructor of the class.
Definition: LeaksController.cpp:13
LeaksController::manualValveClose
int manualValveClose
state of the "manual close" button
Definition: LeaksController.h:76
LeaksController::getNumberOfLeakDetections
int getNumberOfLeakDetections() const
Return the number of water leak detection algorithm.
Definition: LeaksController.cpp:37
LeaksController::LeaksController
LeaksController(LeaksController const &)
Copy constructor of the class.
Definition: LeaksController.h:85
LeaksController::HTML_valve
friend String HTML_valve(const LeaksController &leaksController)
Associated function for returing the current state of the main valve.
ILoggable.h
LeaksController::setMonthlyConsumptionCounter
void setMonthlyConsumptionCounter(Consumption *monthlyConsumptionCounter)
Sets an instance of Consumption (monthly water consumption)
Button.h
LeaksController::stateOfHomeAlarm
int stateOfHomeAlarm
state of the home alarm
Definition: LeaksController.h:75
LeaksController::operator=
LeaksController & operator=(LeaksController const &)
Assignment operator of the class.
Definition: LeaksController.h:88
ALeakDetectable.h
ALeakDetectable
Definition: ALeakDetectable.h:52
HTMLDataSource.h
LeaksController::htmlData
std::map< int, String(*)(const LeaksController &leaksController)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
Definition: LeaksController.h:190
EmailSender.h
Setup.h
LimitsDefinition.h
LeaksController::HTML_manualClose
friend String HTML_manualClose(const LeaksController &leaksController)
Associated function for returing the current state of the "manual close" button.
Button
Definition: Button.h:13
Consumption
Definition: Consumption.h:13
LeaksController::setDailyConsumptionCounter
void setDailyConsumptionCounter(Consumption *dailyConsumptionCounter)
Sets an instance of Consumption (daily water consumption)
LeaksController::instance
static LeaksController * instance
the instance of the class
Definition: LeaksController.h:70
LeaksController::update
void update() override
Updates the class.
Definition: LeaksController.cpp:94
RESET_PIN
#define RESET_PIN
reset button
Definition: Pins.h:19
LeaksController::getHTMLData
const String getHTMLData(const int id) const override
Since this class is registered as a source of data for the HTML content, it needs return the appropri...
ALeakDetectable::Type
Type
The type of the water leak detection algorithm.
Definition: ALeakDetectable.h:57
LeaksController::setPulseCounter
void setPulseCounter(PulseCounter *pulseCounter)
Sets an instance of PulseCounter.
Definition: LeaksController.cpp:90
ILoggable
Definition: ILoggable.h:13
IDisplayable
Definition: IDisplayable.h:12
LeaksController::HTML_alarm
friend String HTML_alarm(const LeaksController &leaksController)
Associated function for returing the current state of the home alarm.
PulseCounter
Definition: PulseCounter.h:29
LeaksController::dailyConsumptionCounter
Consumption * dailyConsumptionCounter
daily water consumption
Definition: LeaksController.h:185
LeaksController::manualResetButton
Button manualResetButton
instance of Button (the reset buttton)
Definition: LeaksController.h:72
LeaksController::getFormatOfSettingsToSave
String getFormatOfSettingsToSave()
Returns all settings.
Definition: LeaksController.cpp:84
HTMLDataSource
Definition: HTMLDataSource.h:15
IControllable.h
PulseCounter.h
LeaksController
Definition: LeaksController.h:67
IControllable
Definition: IControllable.h:13
LeaksController::getRow
const String getRow(int row) const override
Returns the content of the row given as a parameter.
LeaksController::HTML_dailyConsumption
friend String HTML_dailyConsumption(const LeaksController &leaksController)
Associated function for returing the daily water consumption in liters.
LeaksController::getInstance
static LeaksController * getInstance()
Returns the instance of the class.
Definition: LeaksController.cpp:27
LeaksController::changeSettings
void changeSettings(ALeakDetectable::Type type, unsigned long detected, unsigned long reset, bool alarm)
Changes settings of a water leak detection algorithm.
Definition: LeaksController.cpp:51
LeaksController::pulseCounter
PulseCounter * pulseCounter
instance of PulseCounter (output from the sensor)
Definition: LeaksController.h:77