diff --git a/examples/v4LED/v4LED_I2C/v4LED_I2C.ino b/examples/v4LED/v4LED_I2C/v4LED_I2C.ino index 7115035..3801892 100644 --- a/examples/v4LED/v4LED_I2C/v4LED_I2C.ino +++ b/examples/v4LED/v4LED_I2C/v4LED_I2C.ino @@ -252,7 +252,7 @@ uint8_t distanceSingle(uint16_t * distance) uint8_t distanceSingleGpio(uint16_t * distance) { // 1. Trigger range measurement. - myLidarLite.takeRangeGpio(TriggerPin); + myLidarLite.takeRangeGpio(TriggerPin, MonitorPin); // 2. Wait for busyFlag to indicate device is idle. myLidarLite.waitForBusyGpio(MonitorPin); @@ -315,7 +315,7 @@ uint8_t distanceContinuousGpio(uint16_t * distance) if (myLidarLite.getBusyFlagGpio(MonitorPin) == 0) { // Trigger the next range measurement - myLidarLite.takeRangeGpio(TriggerPin); + myLidarLite.takeRangeGpio(TriggerPin, MonitorPin); // Read new distance data from device registers *distance = myLidarLite.readDistance(); diff --git a/src/LIDARLite_v4LED.cpp b/src/LIDARLite_v4LED.cpp index f09cd48..b31183b 100644 --- a/src/LIDARLite_v4LED.cpp +++ b/src/LIDARLite_v4LED.cpp @@ -199,13 +199,23 @@ uint8_t LIDARLite_v4LED::getBusyFlag(uint8_t lidarliteAddress) Parameters ------------------------------------------------------------------------------ triggerPin: digital output pin connected to trigger input of LIDAR-Lite + monitorPin: digital input pin connected to monitor output of LIDAR-Lite ------------------------------------------------------------------------------*/ -void LIDARLite_v4LED::takeRangeGpio(uint8_t triggerPin) +void LIDARLite_v4LED::takeRangeGpio(uint8_t triggerPin, uint8_t monitorPin) { + uint8_t busyFlag; + if (digitalRead(triggerPin)) digitalWrite(triggerPin, LOW); else digitalWrite(triggerPin, HIGH); + + // When LLv4 receives trigger command it will drive monitor pin low. + // Wait for LLv4 to acknowledge receipt of command before moving on. + do + { + busyFlag = getBusyFlagGpio(monitorPin); + } while (!busyFlag); } /* LIDARLite_v4LED::takeRangeGpio */ /*------------------------------------------------------------------------------ @@ -395,4 +405,3 @@ void LIDARLite_v4LED::correlationRecordRead( correlationArray[i] = correlationValue; } } /* LIDARLite_v4LED::correlationRecordRead */ - diff --git a/src/LIDARLite_v4LED.h b/src/LIDARLite_v4LED.h index 40f535a..f753d6e 100644 --- a/src/LIDARLite_v4LED.h +++ b/src/LIDARLite_v4LED.h @@ -42,7 +42,7 @@ class LIDARLite_v4LED void takeRange (uint8_t lidarliteAddress = LIDARLITE_ADDR_DEFAULT); void waitForBusyGpio (uint8_t monitorPin); uint8_t getBusyFlagGpio (uint8_t monitorPin); - void takeRangeGpio (uint8_t triggerPin); + void takeRangeGpio (uint8_t triggerPin, uint8_t monitorPin); void write (uint8_t regAddr, uint8_t * dataBytes, uint8_t numBytes, uint8_t lidarliteAddress = LIDARLITE_ADDR_DEFAULT); void read (uint8_t regAddr, uint8_t * dataBytes, uint8_t numBytes, uint8_t lidarliteAddress = LIDARLITE_ADDR_DEFAULT);