BresserWeatherSensorReceiver
Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101 or SX1276/RFM95W
All Classes Functions Variables Typedefs Modules
Lightning Class Reference

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>

Public Member Functions

 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 &timestamp, int &events, uint8_t &distance)
 

Detailed Description

Calculation number of lightning events during last sensor update cycle and during last hour (past 60 minutes); storing timestamp and distance of last event.

Constructor & Destructor Documentation

◆ Lightning()

Lightning::Lightning ( const int  quality_threshold = DEFAULT_QUALITY_THRESHOLD)
inline

Constructor

Parameters
quality_thresholdnumber of valid hist entries required for valid pastHour() result

Member Function Documentation

◆ hist_init()

void Lightning::hist_init ( int16_t  count = -1)

Initialize histogram of hourly (past 60 minutes) events

Parameters
countnumber of events

◆ pastHour()

Lightning::pastHour ( bool *  valid = nullptr,
int *  quality = nullptr 
)

Get number of lightning events during past 60 minutes.

Parameters
validnumber of valid entries in hist >= qualityThreshold
qualitynumber 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
timestamptimestamp (epoch)
countaccumulated number of events
startupsensor startup flag
lightningCountMaxoverflow 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: