|
| 1 | +#ifndef VL53L1GPIOINTERFACE_HPP_ |
| 2 | +#define VL53L1GPIOINTERFACE_HPP_ |
| 3 | + |
| 4 | +#include <vl53l1_class.h> |
| 5 | +#include <cstdint> |
| 6 | + |
| 7 | +class TwoWire; |
| 8 | +class GpioInterface; |
| 9 | + |
| 10 | +class VL53L1GpioInterface : public VL53L1 { |
| 11 | +public: |
| 12 | + /** Calls end(). */ |
| 13 | + virtual ~VL53L1GpioInterface(); |
| 14 | + |
| 15 | + /** |
| 16 | + * Sets default values for members. |
| 17 | + * @param i2cDevice Is the I2C interface to be used. |
| 18 | + * It must be initialized and started. |
| 19 | + * @param xshutdownPin Is the digital output connected to XSHUT. |
| 20 | + */ |
| 21 | + VL53L1GpioInterface(TwoWire * const i2cDevice, GpioInterface& xshutdownPin); |
| 22 | + |
| 23 | + /** The 7 bits of the default address value right aligned. */ |
| 24 | + static constexpr std::uint8_t defaultAddressValue = VL53L1_DEFAULT_DEVICE_ADDRESS >> 1; |
| 25 | + |
| 26 | + /** |
| 27 | + * Initializes the sensor and sets it's address. |
| 28 | + * @param addressValue 7 bits of the address right aligned. |
| 29 | + * @return VL53L1_ERROR_NONE on success |
| 30 | + */ |
| 31 | + virtual VL53L1_Error initSensorWithAddressValue(const std::uint8_t addressValue = defaultAddressValue); |
| 32 | + |
| 33 | + /** |
| 34 | + * Sets the address of the sensor. |
| 35 | + * @param newValue is the 7 bits of the address value right aligned. |
| 36 | + */ |
| 37 | + virtual void VL53L1_SetDeviceAddressValue(const std::uint8_t newValue); |
| 38 | + |
| 39 | + /** |
| 40 | + * Gets the address which has been written to the sensor. |
| 41 | + * |
| 42 | + * @return The 7 bits of the address value right-aligned. |
| 43 | + */ |
| 44 | + virtual std::uint8_t VL53L1_GetDeviceAddressValue() const; |
| 45 | + |
| 46 | + /** |
| 47 | + * Sets the mode of the xshutdownPin to OUTPUT. |
| 48 | + * @return 0 |
| 49 | + */ |
| 50 | + virtual int begin() override; |
| 51 | + |
| 52 | + /** |
| 53 | + * Sets the mode of XShutdown pin to INPUT. |
| 54 | + * @return 0 |
| 55 | + */ |
| 56 | + virtual int end() override; |
| 57 | + |
| 58 | + /** |
| 59 | + * Switches on the sensor. |
| 60 | + * |
| 61 | + * The digital output connected to XSHUT is set to high. |
| 62 | + */ |
| 63 | + virtual void VL53L1_On() override; |
| 64 | + |
| 65 | + /** |
| 66 | + * Switches off the sensor. |
| 67 | + * |
| 68 | + * The digital output connected to XSHUT is set to low. |
| 69 | + */ |
| 70 | + virtual void VL53L1_Off() override; |
| 71 | + |
| 72 | +protected: |
| 73 | + GpioInterface& xshutdown; |
| 74 | +}; |
| 75 | + |
| 76 | +#endif /* VL53L1GPIOINTERFACE_HPP_ */ |
0 commit comments