Voffcon NodeMcu device server
 All Classes Functions
PinWatchList Class Reference

PinWatchList allows you to add one or more timers and/or monitor value changes on multiple pins More...

Inheritance diagram for PinWatchList:
LinkedList< PinWatch * >

Public Member Functions

bool add (PinWatch pinWatch)
 Add an pinWatch to the list More...
 
bool add (PinWatch *ptrPinWatch)
 Adds a T object in the end of the LinkedList; Increment _size; More...
 
bool update (int index, PinWatch pinWatch)
 Updates an existing PinWatch More...
 
bool addOrUpdate (PinWatch pinWatch)
 Adds or Updates PinWatch If a PinWatch with a specific GPin number already exists in the list the values of the existing PinWatch are updated. If a PinWatch with a specific GPin number does NOT exist in the list a new PinWatch is added to the list. More...
 
bool addTimer (unsigned long minLogInterval)
 Adds a timer with a specific interval. Timer will get the pin number -1. So when deleting or updating timer use the pin number -1. More...
 
bool addPinValueMonitoring (GPin *gPin, int pinValueMargin, int sampleTotalCount, unsigned long sampleInterval)
 Adds and a pinWatch that monitors the value of the pin and checks if it changes same or more than is specified in the pinValueMargin parameter More...
 
bool addPinValueMonitoringAndTimer (GPin *gPin, int pinValueMargin, int sampleTotalCount, unsigned long sampleInterval, unsigned long minLogInterval)
 Adds and a pinWatch that monitors the value of the pin and checks if it changes same or more than is specified in the pinValueMargin parameter More...
 
bool exists (int pinNumber)
 Checks if a pinWatch with pinNumber exists in the list More...
 
int indexOfPin (int pinNumber)
 Searches for the index of pinWatch with a given pin number in the list. More...
 
bool isEmpty ()
 Is the list empty? More...
 
bool removePin (int pinNumber)
 Removes a PinWatch for a pin with a specific number from the list. More...
 
bool isAnyPinWatchDo ()
 Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do. More...
 
int getFirstPinWatchDo ()
 Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do and returns the index of that pin. More...
 
int getNextPinWatchDo (int index)
 Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do and returns the index of that pin. More...
 
void resetAllChecks ()
 Resets all checks by updateing timers and resetting sampleSum and sampleCounts More...
 
int updateMonitorFromJsonObject (JsonData *root, GPins *devicePins)
 Updates the list with item values from Json More...
 
int deleteMonitorFromJsonObject (JsonData *root)
 Deletes list items provided by from Json array More...
 
String toJson ()
 Exports all pinWatch values of the list to A Json array string. More...
 
 ~PinWatchList ()
 The deconstructor, which cleans up when the list is no longer needed. More...
 
- Public Member Functions inherited from LinkedList< PinWatch * >
 LinkedList ()
 The list constructor More...
 
virtual int size ()
 Returns current size of LinkedList More...
 
virtual bool add (int index, PinWatch *)
 Adds a T object in the specified index; Unlinkand link the LinkedList correcly; Increment _size More...
 
virtual bool unshift (PinWatch *)
 Adds a T object in the start of the LinkedList; Increment _size; More...
 
virtual bool set (int index, PinWatch *)
 Set the object at index, with T; Increment _size; More...
 
virtual PinWatchremove (int index)
 Remove object at index; If index is not reachable, returns false; else, decrement _size More...
 
virtual PinWatchpop ()
 Remove last object; More...
 
virtual PinWatchshift ()
 Remove first object; More...
 
virtual PinWatchget (int index)
 Get the index'th element on the list; Return Element if accessible, else, return false; More...
 
virtual void clear ()
 Clear the entire array That is remove all objects from the list and delete them from memory More...
 

Additional Inherited Members

- Protected Member Functions inherited from LinkedList< PinWatch * >
ListNode< PinWatch * > * getNode (int index)
 
- Protected Attributes inherited from LinkedList< PinWatch * >
int _size
 
ListNode< PinWatch * > * root
 
ListNode< PinWatch * > * last
 
ListNode< PinWatch * > * lastNodeGot
 
int lastIndexGot
 
bool isCached
 

Detailed Description

PinWatchList allows you to add one or more timers and/or monitor value changes on multiple pins

Example:

1 PinWatchList watchList;
2 void setup(void) {
3  watchList.addPinValueMonitoring(devicePins.get(D0), 1, 1, 1000);
4  watchList.addPinValueMonitoringAndTimer(devicePins.get(D1), 2, 2, 1000, 1000 * 60 * 3);
5  watchList.addTimer(1000 * 30 * 9);
6 }
7 
8 void loop(void) {
9  if (watchList.isAnyPinWatchDo()) {
10  // One item did trigger so you could log
11  watchList.resetAllChecks();
12  }
13 }

Constructor & Destructor Documentation

PinWatchList::~PinWatchList ( )

The deconstructor, which cleans up when the list is no longer needed.

Member Function Documentation

bool PinWatchList::add ( PinWatch  pinWatch)

Add an pinWatch to the list

Parameters
pinWatchThe PinWatch object to be added to the list
Returns
True if the add succeded, otherwise false
bool PinWatchList::add ( PinWatch )
virtual

Adds a T object in the end of the LinkedList; Increment _size;

Parameters
TThe object

Reimplemented from LinkedList< PinWatch * >.

bool PinWatchList::addOrUpdate ( PinWatch  pinWatch)

Adds or Updates PinWatch If a PinWatch with a specific GPin number already exists in the list the values of the existing PinWatch are updated. If a PinWatch with a specific GPin number does NOT exist in the list a new PinWatch is added to the list.

Parameters
pinWatchthe PinWatch values
Returns
Success: returns true if a PinWatch was added or updated. Fail: Returns false if unable to update or add.
bool PinWatchList::addPinValueMonitoring ( GPin gPin,
int  pinValueMargin,
int  sampleTotalCount,
unsigned long  sampleInterval 
)

Adds and a pinWatch that monitors the value of the pin and checks if it changes same or more than is specified in the pinValueMargin parameter

Parameters
gPinValid GPin to watch
Returns
True if the add succeded, otherwise false
Parameters
pinValueMarginHow mutch must a value of a pin change to recive a positive check
sampleTotalCountHow many samples of a pin value should be averaged
sampleIntervalHow many milliseconds must pass between a sample is taken from a pin value
Returns
True if a PinWatch is added to the list, otherwise false
bool PinWatchList::addPinValueMonitoringAndTimer ( GPin gPin,
int  pinValueMargin,
int  sampleTotalCount,
unsigned long  sampleInterval,
unsigned long  minLogInterval 
)

Adds and a pinWatch that monitors the value of the pin and checks if it changes same or more than is specified in the pinValueMargin parameter

Parameters
gPinValid GPin to watch
pinValueMarginHow mutch must a value of a pin change to recive a positive check
sampleTotalCountHow many samples of a pin value should be averaged
sampleIntervalHow many milliseconds must pass between a sample is taken from a pin value
minLogIntervalHow many milliseconds between forsed positive checks (f.example how many milliseconds between logs) Pin values are not taken into account here
Returns
true if a PinWatch is added to the list, otherwise false
bool PinWatchList::addTimer ( unsigned long  minLogInterval)

Adds a timer with a specific interval. Timer will get the pin number -1. So when deleting or updating timer use the pin number -1.

Parameters
minLogIntervalHow many milliseconds between positive checks (f.example how many milliseconds between logs)
Returns
True if a PinWatch is added to the list, otherwise false
int PinWatchList::deleteMonitorFromJsonObject ( JsonData root)

Deletes list items provided by from Json array

Parameters
rootThe root JsonData object (must be a JSONTYPE::JSONTYPE_ARRAY)
Returns
Number of items removed from the list.
bool PinWatchList::exists ( int  pinNumber)

Checks if a pinWatch with pinNumber exists in the list

Parameters
pinNumberThe pin number search for
Returns
True if a pinWatch with the given pin number was found in the list, otherwise false.
int PinWatchList::getFirstPinWatchDo ( )

Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do and returns the index of that pin.

Returns
success : Returns the index of the first PinWatch which is do fail : When No PinWatch is do, the return value is -1 /returns>
int PinWatchList::getNextPinWatchDo ( int  index)

Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do and returns the index of that pin.

Parameters
indexWhere to start the search from
Returns
success : Returns the index of the first PinWatch which is do fail : When No PinWatch is do, the return value is -1 /returns>
int PinWatchList::indexOfPin ( int  pinNumber)

Searches for the index of pinWatch with a given pin number in the list.

Parameters
pinNumberThe pin number to search for.
Returns
Success:The index of the pinWatch in the list. fail : -1 if the pin number was not found.
bool PinWatchList::isAnyPinWatchDo ( )

Checks if the value of of any pin in the list has changed enough. Checks also if any PinWatch for a pin has reached minimum time beetween checks. The function stops checking after the first PinWatch is do.

Returns
true : At least one PinWatch is do. false : No PinWatch is do. /returns>
bool PinWatchList::isEmpty ( )

Is the list empty?

bool PinWatchList::removePin ( int  pinNumber)

Removes a PinWatch for a pin with a specific number from the list.

Parameters
pinNumberThe pin to search for
Returns
true if pin was removed. false if it is not in the list
void PinWatchList::resetAllChecks ( )

Resets all checks by updateing timers and resetting sampleSum and sampleCounts

String PinWatchList::toJson ( )

Exports all pinWatch values of the list to A Json array string.

Returns
A string containing a valid JSON array of PinWatches.
bool PinWatchList::update ( int  index,
PinWatch  pinWatch 
)

Updates an existing PinWatch

Parameters
indexzero based list index location
pinWatchValues to copy from
Returns
int PinWatchList::updateMonitorFromJsonObject ( JsonData root,
GPins devicePins 
)

Updates the list with item values from Json

Parameters
rootThe root object which can be an JSONTYPE_ARRAY or a JSONTYPE_OBJECT
Returns
Success: the number of PinWatches updated. Fail: 0

The documentation for this class was generated from the following file: