Calculation number of lightning events during last sensor update cycle and during last hour (past 60 minutes); storing timestamp and distance of last event.
More...
#include <Lightning.h>
|
| Lightning (const int quality_threshold=DEFAULT_QUALITY_THRESHOLD) |
|
void | reset (void) |
|
void | hist_init (int16_t count=-1) |
|
void | prefs_load (void) |
|
void | prefs_save (void) |
|
void | update (time_t timestamp, int16_t count, uint8_t distance, bool startup=false) |
| Update lightning data.
|
|
int | pastHour (bool *valid=nullptr, int *quality=nullptr) |
| Get number of lightning events during past 60 minutes.
|
|
int | lastCycle (void) |
|
bool | lastEvent (time_t ×tamp, int &events, uint8_t &distance) |
|
Calculation number of lightning events during last sensor update cycle and during last hour (past 60 minutes); storing timestamp and distance of last event.
◆ Lightning()
Lightning::Lightning |
( |
const int |
quality_threshold = DEFAULT_QUALITY_THRESHOLD | ) |
|
|
inline |
Constructor
- Parameters
-
quality_threshold | number of valid hist entries required for valid pastHour() result |
◆ hist_init()
void Lightning::hist_init |
( |
int16_t |
count = -1 | ) |
|
Initialize histogram of hourly (past 60 minutes) events
- Parameters
-
◆ pastHour()
Lightning::pastHour |
( |
bool * |
valid = nullptr , |
|
|
int * |
quality = nullptr |
|
) |
| |
Get number of lightning events during past 60 minutes.
- Parameters
-
valid | number of valid entries in hist >= qualityThreshold |
quality | number of valid entries in hist |
- Returns
- number of events during past 60 minutes
◆ reset()
void Lightning::reset |
( |
void |
| ) |
|
Initialize/reset non-volatile data
◆ update()
Lightning::update |
( |
time_t |
timestamp, |
|
|
int16_t |
count, |
|
|
uint8_t |
distance, |
|
|
bool |
startup = false |
|
) |
| |
Update lightning data.
- Parameters
-
timestamp | timestamp (epoch) |
count | accumulated number of events |
startup | sensor startup flag |
lightningCountMax | overflow value; when reached, the sensor's counter is reset to zero |
* Total number of events during past 60 minutes
* ----------------------------------------------
*
* In each update():
* - timestamp (time_t) -> t (localtime, struct tm)
* - calculate index into hist[]: idx = t.tm_min / LIGHTNING_UPD_RATE
* - expired time since last update: t_delta = timestamp - nvLightning.lastUpdate
* - number of events since last update: delta = currCount - nvLightning.prevCount
* - t_delta
* < 0: something is wrong, e.g. RTC was not set correctly -> ignore, return
* t_delta < expected update rate:
* idx same as in previous cycle: hist[idx] += delta
* idx changed by 1: hist[idx] = delta
* t_delta >= history size: mark all history entries as invalid
* else (index changed > 1): mark all history entries in interval [expected_index, current_index) as invalid
* hist[idx] = delta
*
* --------------- -----------
* | | | | |...| | | | hist[LIGHTNING_HIST_SIZE]
* --------------- -----------
* ^
* |
* idx = t.tm_min / LIGHTNING_UPD_RATE
*
* - Calculate hourly rate:
* pastHour = sum of all valid hist[] entries
*
*
The documentation for this class was generated from the following files: