Skip to content

Commit

Permalink
v4 LED - Wait for LLv4LED to acknowledge GPIO cmd
Browse files Browse the repository at this point in the history
After toggling trigger pin, wait for LLv4 to acknowledge receipt of
command before moving on. Otherwise, we could falsely detect 'not-busy'
if we check for busy via GPIO too quickly.

Change-Id: I7447f79e7a91a8a2c5e38afb0a6bec7851094d82
  • Loading branch information
jmseitz committed Sep 12, 2019
1 parent f78eaeb commit 485bf05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/v4LED/v4LED_I2C/v4LED_I2C.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions src/LIDARLite_v4LED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -395,4 +405,3 @@ void LIDARLite_v4LED::correlationRecordRead(
correlationArray[i] = correlationValue;
}
} /* LIDARLite_v4LED::correlationRecordRead */

2 changes: 1 addition & 1 deletion src/LIDARLite_v4LED.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 485bf05

Please sign in to comment.