DeskControl/src/lib/vl53l0x.h

53 lines
1.6 KiB
C++

/*
The Adafruit VL53L0X library is included because it's an easy way to get
access to the VL53L0X API headers. I will not be using the Adafruit library
however because it lacks a way to set the timing budget, which I found to be
very much required for accurate results.
*/
#ifndef __vl53l0x
#define __vl53l0x
#include "Arduino.h"
#include "Wire.h"
#include "vl53l0x_api.h"
typedef int8_t VL53L0XPosition;
typedef struct
{
VL53L0X_Error error;
VL53L0XPosition position;
} VL53L0XResult;
#define VL53L0X_POSITION_UNKNOWN ((VL53L0XPosition) 0)
// Positions for the init method
#define VL53L0X_POSITION_DATAINIT ((VL53L0XPosition) 1)
#define VL53L0X_POSITION_SETDEVICEADDRESS ((VL53L0XPosition) 2)
#define VL53L0X_POSITION_GETDEVICEINFO ((VL53L0XPosition) 3)
#define VL53L0X_POSITION_STATICINIT ((VL53L0XPosition) 4)
#define VL53L0X_POSITION_REFSPAD ((VL53L0XPosition) 5)
#define VL53L0X_POSITION_REFCAL ((VL53L0XPosition) 6)
#define VL53L0X_POSITION_DEVICEMODE ((VL53L0XPosition) 7)
#define VL53L0X_POSITION_LIMITRANGE ((VL53L0XPosition) 8)
#define VL53L0X_POSITION_LIMITRATE ((VL53L0XPosition) 9)
#define VL53L0X_POSITION_TRESHOLD1 ((VL53L0XPosition) 10)
#define VL53L0X_POSITION_TRESHOLD2 ((VL53L0XPosition) 11)
class VL53L0X
{
public:
bool init(uint8_t address, VL53L0XResult* result);
bool setMeasurementTimingBudget(uint32_t budget_us, VL53L0X_Error* error);
bool getSingleRangingMeasurement(VL53L0X_RangingMeasurementData_t* data, VL53L0X_Error* error);
bool getSingleRangingMeasurement(uint16_t* distanceMillimeters, VL53L0X_Error* error, uint16_t maxValidHeight);
private:
VL53L0X_Dev_t device;
};
#endif