Manages the consumption statistics.
More...
|
| ConsumptionData (void) |
| Default constructor.
|
|
void | begin (void) |
| Initializes this instance.
|
|
void | updateTime (void) |
| Updates the time data.
|
|
void | updateConsumption (const uint32_t current_liters) |
| Updates the consumption if necessary.
|
|
uint32_t | getConsumption1h (void) const |
| Gives the total consumption in the last hour.
|
|
uint32_t | getConsumption12h (void) const |
| Gives the total consumption in the last 12 hours.
|
|
uint32_t | getConsumption1d (void) const |
| Gives the total consumption in the last day.
|
|
uint32_t | getConsumption3d (void) const |
| Gives the total consumption in the last 3 days.
|
|
|
uint32_t | sumSamples (const uint32_t back_time) const |
| Sums the consumption samples.
|
|
void | updateBuffer (void) |
| Updates the consumptions buffer.
|
|
void | updateIndex (void) |
| Updates the buffer index.
|
|
|
static const uint16_t | STAT_SIZE = (24U * 3U) + 1U |
| The sample dimension (3 days).
|
|
static const uint32_t | LITERS_THRESHOLD = 15U |
| Minimum consumption threshold to be inserted as sample.
|
|
static const uint32_t | ONE_SECOND_MS = 1000U |
| 1 second constant.
|
|
static const uint32_t | ONE_HOUR_S = (60U * 60U) |
| 1 hour constant.
|
|
Manages the consumption statistics.
◆ ConsumptionData()
ConsumptionData::ConsumptionData |
( |
void | | ) |
|
|
inline |
Default constructor.
Creates and instance of this class.
◆ begin()
void ConsumptionData::begin |
( |
void | | ) |
|
|
inline |
Initializes this instance.
◆ getConsumption12h()
uint32_t ConsumptionData::getConsumption12h |
( |
void | | ) |
const |
|
inline |
Gives the total consumption in the last 12 hours.
Sums the stored data.
- Returns
- The water consumption in liters.
◆ getConsumption1d()
uint32_t ConsumptionData::getConsumption1d |
( |
void | | ) |
const |
|
inline |
Gives the total consumption in the last day.
Sums the stored data.
- Returns
- The water consumption in liters.
◆ getConsumption1h()
uint32_t ConsumptionData::getConsumption1h |
( |
void | | ) |
const |
|
inline |
Gives the total consumption in the last hour.
Sums the stored data.
- Returns
- The water consumption in liters.
◆ getConsumption3d()
uint32_t ConsumptionData::getConsumption3d |
( |
void | | ) |
const |
|
inline |
Gives the total consumption in the last 3 days.
Sums the stored data.
- Returns
- The water consumption in liters.
◆ sumSamples()
uint32_t ConsumptionData::sumSamples |
( |
const uint32_t | back_time | ) |
const |
|
inlineprivate |
Sums the consumption samples.
- Parameters
-
[in] | back_time | The hours passed. |
- Returns
- 9999 if back_time is >= STAT_SIZE (3d) otherwise the total consumption in liters.
- Attention
- Assumption: The tank(s) contain(s) 1000L maximum and there no more than 2 fillings per day.
◆ updateBuffer()
void ConsumptionData::updateBuffer |
( |
void | | ) |
|
|
inlineprivate |
Updates the consumptions buffer.
Updates the consumption accumulated in the last hour.
◆ updateConsumption()
void ConsumptionData::updateConsumption |
( |
const uint32_t | current_liters | ) |
|
|
inline |
Updates the consumption if necessary.
Computes the current consumption and updates buffer.
- Parameters
-
[in] | current_liters | The water volume in the tank(s). |
- Attention
- It shall be called in loop function when new measurement updates are available.
◆ updateIndex()
void ConsumptionData::updateIndex |
( |
void | | ) |
|
|
inlineprivate |
Updates the buffer index.
Updates the buffer index and reset the older values to 0.
◆ updateTime()
void ConsumptionData::updateTime |
( |
void | | ) |
|
|
inline |
Updates the time data.
Computes seconds, minutes, hours and days passed from power on. Every hours it updates the current consumption (an estimation).
- Attention
- It must be invoked it the loop function.
◆ consumption
volatile uint32_t ConsumptionData::consumption |
|
private |
The last hour water consumption.
◆ consumption_samples
uint32_t ConsumptionData::consumption_samples[STAT_SIZE] |
|
private |
◆ index
uint32_t ConsumptionData::index |
|
private |
◆ last_liters
volatile uint32_t ConsumptionData::last_liters |
|
private |
The last known volume of water in the tank (in liters).
◆ last_millis
volatile uint32_t ConsumptionData::last_millis |
|
private |
Last timestamp (value from power-on).
◆ LITERS_THRESHOLD
const uint32_t ConsumptionData::LITERS_THRESHOLD = 15U |
|
staticprivate |
Minimum consumption threshold to be inserted as sample.
◆ millis_passed
volatile uint32_t ConsumptionData::millis_passed |
|
private |
Passed milliseconds from last invocation of updateTime.
◆ ONE_HOUR_S
const uint32_t ConsumptionData::ONE_HOUR_S = (60U * 60U) |
|
staticprivate |
◆ ONE_SECOND_MS
const uint32_t ConsumptionData::ONE_SECOND_MS = 1000U |
|
staticprivate |
◆ seconds_passed
volatile uint32_t ConsumptionData::seconds_passed |
|
private |
Passed seconds from last invocation of updateTime.
◆ STAT_SIZE
const uint16_t ConsumptionData::STAT_SIZE = (24U * 3U) + 1U |
|
staticprivate |
The sample dimension (3 days).
The documentation for this class was generated from the following file: