Black Lives Matter - Action and Equality.
0

How to use Adafruit VL53L0X API
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to use Adafruit VL53L0X API

by paynterf on Fri May 22, 2020 11:34 pm

Hi,

I am using your wonderful Adafruit library with an array of three VL53L0X sensors, and I'm trying to figure out how to use some of functions declared in vl53l0x_api.h. I have been reading through the source code and see that many functions take a 'Device Handle' parameter, but for the life of me I don't see where/how the device handle is acquired in the first place.

Is there any demo code or examples that show how to use API functions?

TIA,

Frank

paynterf
 
Posts: 67
Joined: Sat Mar 07, 2015 6:41 pm

Re: How to use Adafruit VL53L0X API

by adafruit_support_bill on Sat May 23, 2020 6:29 am

MyDevice and pMyDevice are class members defined in the .h file. The pointer member is initialized by default, the device members are initialized in the begin function.
Code: Select all | TOGGLE FULL SIZE
private:
  VL53L0X_Dev_t MyDevice;
  VL53L0X_Dev_t *pMyDevice = &MyDevice;

adafruit_support_bill
 
Posts: 77478
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit VL53L0X API

by paynterf on Sat May 23, 2020 8:37 am

Thanks for the quick reply!

OK, I see this in Adafruit_V53L0X.h


Code: Select all | TOGGLE FULL SIZE
private:
  VL53L0X_Dev_t MyDevice;
  VL53L0X_Dev_t *pMyDevice = &MyDevice;
  VL53L0X_DeviceInfo_t DeviceInfo;


And in Adafruit_VL53L0X.cpp I see several places where pMyDevice is used as an argument to an API function call, like

Code: Select all | TOGGLE FULL SIZE
    Status = VL53L0X_SetDeviceMode(
        pMyDevice,
        VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode


Unfortunately, I don't see any way to call any of the API functions directly, as pMyDevice is a private class variable visible only inside the class definition. For instance, how would I obtain a filled &DeviceInfo structure in a user program? I can write

Code: Select all | TOGGLE FULL SIZE
int status =  VL53L0X_GetDeviceInfo(my_lox.MyDevice, my_lox.DeviceInfo)


but how do I provide the required device handle and pVL53L0X_DeviceInfo pointer?

TIA,

Frank

paynterf
 
Posts: 67
Joined: Sat Mar 07, 2015 6:41 pm

Re: How to use Adafruit VL53L0X API

by adafruit_support_bill on Sat May 23, 2020 8:52 am

You would have to edit the library to make those members public.

adafruit_support_bill
 
Posts: 77478
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit VL53L0X API

by paynterf on Sat May 23, 2020 10:38 am

adafruit_support_bill wrote:You would have to edit the library to make those members public.


Not to be disrespectful or anything, but you could have saved me a lot of time and effort by making that point the first time. I am well aware that private member functions in a C++ class cannot be accessed from outside the class definition, so I don't quite understand why you went to the trouble of giving me a completely useless answer the first time.

Regards,

Frank

paynterf
 
Posts: 67
Joined: Sat Mar 07, 2015 6:41 pm

Please be positive and constructive with your questions and comments.