ModularSensors > Classes > VariableArray
ModularSensors > Modules > Primary Object Classes > VariableArray


VariableArray class

The variable array class defines the logic for iterating through many variable objects.

This takes advantage of various time stamps within the Sensor class to optimize the timing of communications with many sensors.

In general, the order of the variables in the variable list or array should not matter. The library attempts to minimize sensor on time as much as possible by requesting data from the each sensor as soon as it is able to report a result, regardless of its position in the array. The only place the order of the variables will be reflected is in the order of the data columns in data saved by a logger or when sending data to ThingSpeak.

To use the VariableArray module, you must first create the array of pointers. This should be done outside of the setup() or loop() functions. Remember that for measured variables you must first create a new sensor instance and then one or more new variable instances for that sensor (depending on how many values it can return). The sensor functions for sensors within a variable array take advantage of all of the timestamps and status bits within the sensor object to minimize the amount of time that all sensors are powered and the processor is awake. That is, the first sensor to be warmed up will be set up or activated first; the first sensor to stabilize will be asked for values first. All calculations for any calculated variables happen after all the sensor updating has finished. The order of the variables within the array should not matter, though for code readability, I strongly suggest putting all the variables attached to a single sensor next to each other in the array. When creating a logger, the order of variables in the array determines the order the values will be written to the data file.

Constructors, destructors, conversion operators

VariableArray()
Construct a new Variable Array object.
VariableArray(uint8_t variableCount, Variable*[] variableList)
Construct a new Variable Array object.
VariableArray(uint8_t variableCount, Variable*[] variableList, const char*[] uuids)
Construct a new Variable Array object.
~VariableArray()
Destroy the Variable Array object - no action taken.

Public functions

void begin(uint8_t variableCount, Variable*[] variableList)
Begins the VariableArray. Suppiles a variable array, checks the validity of all UUID and outputs the results.
void begin(uint8_t variableCount, Variable*[] variableList, const char*[] uuids)
Begins the VariableArray. Suppiles a variable array and UUIDs, checks the validity of all UUID and outputs the results.
void begin()
Begins the VariableArray. Checks the validity of all UUID and outputs the results.
uint8_t getVariableCount(void )
Get the count of variables in the variable array.
uint8_t getCalculatedVariableCount(void )
Get the number of calculated variables.
uint8_t getSensorCount(void )
Get the number of sensors associated with the variables in the array.
void matchUUIDs(const char*[] uuids)
Match UUID's from the given variables in the variable array.
bool setupSensors(void )
Set up all of the sensors in the tied to variables in the array.
void sensorsPowerUp(void )
Power up each sensor.
bool sensorsWake(void )
Wake up each sensor.
bool sensorsSleep(void )
Put all sensors to sleep.
void sensorsPowerDown(void )
Cut power to all sensors. Runs the powerDown sensor function for each unique sensor.
bool updateAllSensors(void )
Update the values for all connected sensors.
bool completeUpdate(void )
Update the values for all connected sensors including powering them and waking and putting them to sleep.
void printSensorData(Stream* stream = &Serial)
Print out the results for all connected sensors to a stream.

Public variables

Variable** arrayOfVars
Pointer to the array of variable pointers.

Protected variables

uint8_t _variableCount
The count of variables in the array.
uint8_t _sensorCount
The count of unique sensors tied to variables in the array.
uint8_t _maxSamplestoAverage
The maximum number of samples to average of an single sensor.

Function documentation

VariableArray(uint8_t variableCount, Variable*[] variableList)

Construct a new Variable Array object.

Parameters
variableCount The number of variables in the array
variableList An array of pointers to variable objects. The pointers may be to calculated or measured variable objects.

VariableArray(uint8_t variableCount, Variable*[] variableList, const char*[] uuids)

Construct a new Variable Array object.

Parameters
variableCount The number of variables in the array
variableList An array of pointers to variable objects. The pointers may be to calculated or measured variable objects.
uuids An array of UUID's. These are linked 1-to-1 with the variables by array position.

voidbegin(uint8_t variableCount, Variable*[] variableList)

Begins the VariableArray. Suppiles a variable array, checks the validity of all UUID and outputs the results.

Parameters
variableCount The number of variables in the array. Supercedes any value given in the constructor.
variableList An array of pointers to variable objects. The pointers may be to calculated or measured variable objects. Supercedes any value given in the constructor.

voidbegin(uint8_t variableCount, Variable*[] variableList, const char*[] uuids)

Begins the VariableArray. Suppiles a variable array and UUIDs, checks the validity of all UUID and outputs the results.

Parameters
variableCount The number of variables in the array. Supercedes any value given in the constructor.
variableList An array of pointers to variable objects. The pointers may be to calculated or measured variable objects. Supercedes any value given in the constructor.
uuids An array of UUID's. These are linked 1-to-1 with the variables by array position.

uint8_tgetVariableCount(void )

Get the count of variables in the variable array.

Returns uint8_t the number of variables

uint8_tgetCalculatedVariableCount(void )

Get the number of calculated variables.

Returns uint8_t The number of calculated (ie, not measured by a sensor) variables

uint8_tgetSensorCount(void )

Get the number of sensors associated with the variables in the array.

Returns uint8_t The number of sensors

This will often be different from the number of variables because many sensors can return multiple variables.


voidmatchUUIDs(const char*[] uuids)

Match UUID's from the given variables in the variable array.

Parameters
uuids An array of UUID's

This over-writes all UUID's previously assigned to every variable. The match is 1-to-1 based on array position.


boolsetupSensors(void )

Set up all of the sensors in the tied to variables in the array.

Returns bool True indicates all sensors have been set up successfully.

This sets up all of the variables in the array and their respective sensors by running all of their setup() functions. A single sensor attached to may variables is only set up one time. If a sensor doesn't respond to its setup command, the command is called 5 times in attempt to make a connection. If all sensors are set up successfully, returns true.


voidsensorsPowerUp(void )

Power up each sensor.

Runs the powerUp sensor function for each unique sensor.


boolsensorsWake(void )

Wake up each sensor.

Returns bool True if all wake functions were run successfully.

Runs the wake sensor function for each unique sensor. Repeatedly checks each sensor's readiness state to optimize timing.


boolsensorsSleep(void )

Put all sensors to sleep.

Returns bool True if all sleep functions were run successfully.

Runs the sleep sensor function for each unique sensor.


boolupdateAllSensors(void )

Update the values for all connected sensors.

Returns bool True if all steps of the update succeeded.

Does not power or wake/sleep sensors. Returns a boolean indication the overall success. Does NOT return any values. Repeatedly checks each sensor's readiness state to optimize timing.


boolcompleteUpdate(void )

Update the values for all connected sensors including powering them and waking and putting them to sleep.

Returns bool True if all steps of the update succeeded.

Returns a boolean indication the overall success. Does NOT return any values. Repeatedly checks each sensor's readiness state to optimize timing.


voidprintSensorData(Stream* stream = &Serial)

Print out the results for all connected sensors to a stream.

Parameters
stream An Arduino Stream instance

This prints current sensor values along with meta-data to a stream (either hardware or software serial). By default, it will print to the first Serial port. Note that the input is a pointer to a stream instance

  • to use a hardware serial instance you must use an ampersand before the serial name (ie, &Serial1).