Initial release.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: X_NUCLEO_53L1A1_mbed X_NUCLEO_53L1A1_mbed VL53L1X_Ranging_With_Standalone_Satellite_MbedOS X_NUCLEO_53L1A1
Diff: vl53l1x_class.cpp
- Revision:
- 6:aa13392d16bb
- Parent:
- 5:f16727052990
--- a/vl53l1x_class.cpp Mon Jan 28 10:14:03 2019 +0000
+++ b/vl53l1x_class.cpp Fri May 17 09:07:55 2019 +0000
@@ -62,8 +62,8 @@
{
VL53L1X_ERROR status = 0;
+ status = VL53L1_WrByte(Device, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, new_address >> 1);
Device->I2cDevAddr = new_address;
- status = VL53L1_WrByte(Device, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, new_address >> 1);
return status;
}
@@ -152,13 +152,7 @@
VL53L1X_ERROR VL53L1X::VL53L1X_StartRanging()
{
VL53L1X_ERROR status = 0;
-/*
- uint8_t Addr = 0x00;
- for (Addr = 0x2D; Addr <= 0x87; Addr++){
- status = VL53L1_WrByte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
- }
-*/
status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x40); /* Enable VL53L1X */
return status;
}
@@ -592,7 +586,7 @@
VL53L1X_ERROR VL53L1X::VL53L1X_SetXtalk(uint16_t XtalkValue)
{
-/* XTalkValue in count per second to avoid float type */
+ /* XTalkValue in count per second to avoid float type */
VL53L1X_ERROR status = 0;
status = VL53L1_WrWord(Device,
@@ -955,7 +949,6 @@
int ret;
ret = dev_i2c->v53l1x_i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
- //ret = dev_i2c->i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
if (ret) {
return -1;
@@ -972,7 +965,6 @@
VL53L1X_ERROR status = VL53L1_ERROR_NONE;
- //*ptick_count_ms = timeGetTime();
*ptick_count_ms = 0;
return status;
@@ -982,16 +974,12 @@
VL53L1X_ERROR VL53L1X::VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us)
{
- //(void)pdev;
- //wait_ms(wait_us/1000);
return VL53L1_ERROR_NONE;
}
VL53L1X_ERROR VL53L1X::VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms)
{
- //(void)pdev;
- //wait_ms(wait_ms);
return VL53L1_ERROR_NONE;
}
@@ -1070,5 +1058,58 @@
return status;
}
+int VL53L1X::handle_irq(uint16_t *distance)
+{
+ int status;
+ status = get_measurement(distance);
+ enable_interrupt_measure_detection_irq();
+ return status;
+}
+int VL53L1X::get_measurement(uint16_t *distance)
+{
+ int status = 0;
+ status = VL53L1X_GetDistance(distance);
+ status = VL53L1X_ClearInterrupt();
+
+ return status;
+}
+
+int VL53L1X::start_measurement(void (*fptr)(void))
+{
+ int status = 0;
+
+ if (_gpio1Int == NULL) {
+ printf("GPIO1 Error\r\n");
+ return 1;
+ }
+
+ status = VL53L1X_StopRanging(); // it is safer to do this while sensor is stopped
+
+ if (status == 0) {
+ attach_interrupt_measure_detection_irq(fptr);
+ enable_interrupt_measure_detection_irq();
+ }
+
+ if (status == 0) {
+ status = VL53L1X_StartRanging();
+ }
+
+ return status;
+}
+
+int VL53L1X::stop_measurement()
+{
+ int status = 0;
+
+ if (status == 0) {
+ printf("Call of VL53L0X_StopMeasurement\n");
+ status = VL53L1X_StopRanging();
+ }
+
+ if (status == 0)
+ status = VL53L1X_ClearInterrupt();
+
+ return status;
+}