HomeWaterLeaksDetection
PulseCounter Class Reference

#include <PulseCounter.h>

Public Member Functions

 PulseCounter (int inputPin)
 Constructor of the class. More...
 
void update ()
 Updates the class. More...
 
int isActive () const
 Returns information if a pulse has been detected. More...
 
time_t getLastPulseTime () const
 Return the time when the last pulse was detected. More...
 
const String getHTMLData (const int id) const
 Since this class is registered as a source of data for the HTML content, it needs return the appropriate value according to the id given as a parameter. More...
 

Private Attributes

int inputPin
 number of the input pin More...
 
time_t lastPulseTime
 time when the last pulse was detected More...
 
int previousInputValue
 previous state of the input pin More...
 
int pulseDown
 flag if a pulse just occurred More...
 
std::map< int, String(*)(const PulseCounter &pulseCounter)> htmlData
 A map of different values (keys) and their associated functions which returns the appropriate values. More...
 

Friends

String HTML_lastPulseTime (const PulseCounter &pulseCounter)
 Associated function for returing the last pulse time. More...
 
String HTML_currentTime (const PulseCounter &pulseCounter)
 Associated function for returing the current time. More...
 
String HTML_currentDate (const PulseCounter &pulseCounter)
 Associated function for returing the current date. More...
 

Additional Inherited Members

- Static Public Attributes inherited from HTMLDataSource
static const String UNDEFINED_DATA = String("UNDEFINED")
 string "UNDEFINED" More...
 

Detailed Description

Author
silhavyj A17B0362P

This class represents the main input of the system. It keeps counting the pulses occuring on the input pin. A pulse is understood as the level of voltage going from high to low.

Definition at line 25 of file PulseCounter.h.

Constructor & Destructor Documentation

◆ PulseCounter()

PulseCounter::PulseCounter ( int  inputPin)

Constructor of the class.

Parameters
inputPinnumber of the input pin the flow sensor is connected to

Definition at line 9 of file PulseCounter.cpp.

9  {
10  this->inputPin = inputPin;
11 
12  // initialize the variables
13  lastPulseTime = 0;
14  previousInputValue = LOW;
15  pulseDown = LOW;
16 
17  #ifdef WEB_SERVER
18  // functions providing data to the webserver
21  htmlData[115] = &HTML_currentDate;
22  #endif
23 }

References HTML_currentDate, HTML_currentTime, HTML_lastPulseTime, htmlData, inputPin, lastPulseTime, previousInputValue, and pulseDown.

Member Function Documentation

◆ getHTMLData()

const String PulseCounter::getHTMLData ( const int  id) const
virtual

Since this class is registered as a source of data for the HTML content, it needs return the appropriate value according to the id given as a parameter.

Parameters
id- the id of the piece of data
Returns
If the class holds this piece of information, it will return it. Otherwise, "UNDEFINED" will be returned.

Implements HTMLDataSource.

◆ getLastPulseTime()

time_t PulseCounter::getLastPulseTime ( ) const

Return the time when the last pulse was detected.

Returns
time when the last pulse was detected

Definition at line 44 of file PulseCounter.cpp.

44  {
45  return lastPulseTime;
46 }

References lastPulseTime.

Referenced by LowLeakDetection::getPercentLeakDetectionReset(), HighLeakDetection::getPercentLeakDetectionReset(), LowLeakDetection::testResetLeak(), HighLeakDetection::testResetLeak(), and LowLeakDetection::update().

◆ isActive()

int PulseCounter::isActive ( ) const

Returns information if a pulse has been detected.

Returns
true if a pulse has been detected, false otherwise

Definition at line 40 of file PulseCounter.cpp.

40  {
41  return pulseDown;
42 }

References pulseDown.

Referenced by Consumption::update(), LowLeakDetection::update(), and HighLeakDetection::update().

◆ update()

void PulseCounter::update ( )

Updates the class.

It reads the current state of the input pin and if it has gone from high to low, the flag will be set. This method is supposed to be called as frequently as possible so every pulse occurred will be detected.

Definition at line 25 of file PulseCounter.cpp.

25  {
26  time_t currentTime = millis();
27  int currentInputValue = digitalRead(inputPin);
28 
29  // if the signal has gone from HIGH to LOW, a pulse
30  // just occurred
31  if (currentInputValue == LOW && previousInputValue == HIGH) {
32  lastPulseTime = currentTime;
33  pulseDown = HIGH;
34  } else {
35  pulseDown = LOW;
36  }
37  previousInputValue = currentInputValue;
38 }

References inputPin, lastPulseTime, previousInputValue, and pulseDown.

Referenced by LeaksController::update().

Friends And Related Function Documentation

◆ HTML_currentDate

String HTML_currentDate ( const PulseCounter pulseCounter)
friend

Associated function for returing the current date.

Parameters
pulseCounter- the instance of the PulseCounter class
Returns
the current date in a string format

Referenced by PulseCounter().

◆ HTML_currentTime

String HTML_currentTime ( const PulseCounter pulseCounter)
friend

Associated function for returing the current time.

Parameters
pulseCounter- the instance of the PulseCounter class
Returns
the current time in a string format

Referenced by PulseCounter().

◆ HTML_lastPulseTime

String HTML_lastPulseTime ( const PulseCounter pulseCounter)
friend

Associated function for returing the last pulse time.

Parameters
pulseCounter- the instance of the PulseCounter class
Returns
the last pulse time in a string format

Referenced by PulseCounter().

Member Data Documentation

◆ htmlData

std::map<int, String (*)(const PulseCounter& pulseCounter)> PulseCounter::htmlData
private

A map of different values (keys) and their associated functions which returns the appropriate values.

Definition at line 65 of file PulseCounter.h.

Referenced by PulseCounter().

◆ inputPin

int PulseCounter::inputPin
private

number of the input pin

Definition at line 32 of file PulseCounter.h.

Referenced by PulseCounter(), and update().

◆ lastPulseTime

time_t PulseCounter::lastPulseTime
private

time when the last pulse was detected

Definition at line 33 of file PulseCounter.h.

Referenced by getLastPulseTime(), PulseCounter(), and update().

◆ previousInputValue

int PulseCounter::previousInputValue
private

previous state of the input pin

Definition at line 34 of file PulseCounter.h.

Referenced by PulseCounter(), and update().

◆ pulseDown

int PulseCounter::pulseDown
private

flag if a pulse just occurred

Definition at line 35 of file PulseCounter.h.

Referenced by isActive(), PulseCounter(), and update().


The documentation for this class was generated from the following files:
PulseCounter::inputPin
int inputPin
number of the input pin
Definition: PulseCounter.h:32
PulseCounter::previousInputValue
int previousInputValue
previous state of the input pin
Definition: PulseCounter.h:34
PulseCounter::HTML_lastPulseTime
friend String HTML_lastPulseTime(const PulseCounter &pulseCounter)
Associated function for returing the last pulse time.
PulseCounter::HTML_currentDate
friend String HTML_currentDate(const PulseCounter &pulseCounter)
Associated function for returing the current date.
time_t
unsigned long time_t
Referring to the data type unsigned long as time_t.
Definition: DateTime.h:20
PulseCounter::lastPulseTime
time_t lastPulseTime
time when the last pulse was detected
Definition: PulseCounter.h:33
PulseCounter::HTML_currentTime
friend String HTML_currentTime(const PulseCounter &pulseCounter)
Associated function for returing the current time.
PulseCounter::pulseDown
int pulseDown
flag if a pulse just occurred
Definition: PulseCounter.h:35
PulseCounter::htmlData
std::map< int, String(*)(const PulseCounter &pulseCounter)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
Definition: PulseCounter.h:65