VL53L0X API Specification: Strings

VL53L0X API

Strings

The API uses character strings to inform the user about the state of the API, the meaning of the error or about the name of a particular mode.

1. String can be removed

At compilation stage a DEFINE can be used to remove all the strings to save some space on device. Strings will be replaced with empty string.
The Define to be used is USE_EMPTY_STRING:

  • if USE_EMPTY_STRING is defined: all the strings are replaced with empty string.
  • if USE_EMPTY_STRING is NOT defined: all the strings are well defined and not empty.

2. Max Lenght String

The API uses the macro VL53L0X_COPYSTRING to copy strings. For example the following code from get device info

  VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Type,
         VL53L0X_STRING_DEVICE_INFO_TYPE);

This MACRO is defined inside platform code. This means that is the responsibility of the customer to use the right function to copy the string. In the Platform gives as example this is:

     #define VL53L0X_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__)

In previous example we copy the string defined in VL53L0X_STRING_DEVICE_INFO_TYPE in a field in a structure pVL53L0X_DeviceInfo->Type. This is defined with a max lenght:

     char Type[VL53L0X_MAX_STRING_LENGTH];

In that case by construction the Define:

     len(VL53L0X_STRING_DEVICE_INFO_TYPE) < VL53L0X_MAX_STRING_LENGTH.

In the API the max lenght is defined in the VL53L0X_api_def.h as follow:

     #define VL53L0X_MAX_STRING_LENGTH 32

In the API there are some functions which output directly the string like the following:

char *pRangeStatusString)

Even in that case a copy string is done. To avoid overflow problem when the copy is done, the string which will contains the one is copied, should be greather or equal to the max lenght described before.

void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){
uint8_t RangeStatus;
RangeStatus = pRangingMeasurementData->RangeStatus;
VL53L0X_GetRangeStatusString(RangeStatus, buf);
printf("Range Status: %i : %s\n", RangeStatus, buf);
}