Description

getValue_x() – returns the current value of the variable at the given index casted to the desired type. (int32_t, uint32_t, float or the data bytes [0..3]).

Note: you can check if the variable was initialised with ‘getVariableStatus()’

Syntax

getValue_int32( ou8_variable_index );
getValue_uint32( ou8_variable_index );
getValue_float( ou8_variable_index );
getValue_byte( ou8_variable_index, ou8_byte_pos );

Parameters

uint8_t ou8_variable_index: the number of the variable that should be read
uin8_t ou8_byte_pos: the position of the byte to be read [0…3] – 0: LSB / 3: MSB

Syntax examples

int32_t i32_val = getValue_int32( 5 ); // the signed int32 interpretation of variable 5
uint32_t u32_val = getValue_uint32( 2 ); // the unsigned int interpretation of variable 2
float f_val = getValue_float( 1 ); // the float value of variable 1
uint8_t u8_val = getValue_byte( 7, 0 ); // the value of the least signif. byte of variable 7

Returns

uint32_t, int32_t, float, or uint8_t: value of the variable
NOTE: the function returns 0 if the given index is out of range or the data pool is not initialised
-> Be aware that this could be misinterpreted with the value 0 ! You can check if the variable was initialised with ‘getVariableStatus()’.

Example Codes:

The following code example defines a data pool including an callback function that is called whenever a variable is modified by another peer.

#include "Datapool.h"

#define NB_OF_VARIABLES 3
#define POOL_NAME "A_SimplePool_V1_0"
void myCallBack(uint8_t ou8_NbOfUpdatedVariable);
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING, POOL_NAME, NB_OF_VARIABLES, myCallBack );

void setup() {
  while(!Serial);
  myPool.begin();
  Serial.println("Enter new value of Var1");
}

int8_t s8_modVar = -1;
void loop() 
{
  if(Serial.peek() != -1)
  {
    int i_new = Serial.readStringUntil('n').toInt();
    myPool.setValue( 1, (int32_t) i_new ); 
  }
  if(s8_modVar > -1)
  {
    Serial.println("Var"+String(s8_modVar)+": "+
         String( myPool.getValue_int32(s8_modVar) ));
    s8_modVar = -1;
  }
}
void myCallBack(uint8_t ou8_NbOfUpdatedVariable)
{
  s8_modVar = ou8_NbOfUpdatedVariable;
}

Notes and Warnings

Examples can be found in the Arduino IDE menu:
File -> Examples -> Datapool ->

See also

Device addressing
getVariableStatus()
setValue()