Skip to content

Commit c2612e8

Browse files
committed
AP_RangeFinder: MaxsonarI2CXL: hold bus semaphore while taking reading in
1 parent 37b0fe3 commit c2612e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarI2CXL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ bool AP_RangeFinder_MaxsonarI2CXL::init(void)
5757
return true;
5858
}
5959

60-
// start_reading() - ask sensor to make a range reading
60+
// start_reading() - ask sensor to make a range reading - must be
61+
// called with semaphore held
6162
bool AP_RangeFinder_MaxsonarI2CXL::start_reading()
6263
{
6364
uint8_t cmd = AP_RANGE_FINDER_MAXSONARI2CXL_COMMAND_TAKE_RANGE_READING;
@@ -69,9 +70,9 @@ bool AP_RangeFinder_MaxsonarI2CXL::start_reading()
6970
// read - return last value measured by sensor
7071
bool AP_RangeFinder_MaxsonarI2CXL::get_reading(uint16_t &reading_cm)
7172
{
72-
be16_t val;
73-
73+
WITH_SEMAPHORE(dev.get_semaphore());
7474
// take range reading and read back results
75+
be16_t val;
7576
bool ret = dev.transfer(nullptr, 0, (uint8_t *) &val, sizeof(val));
7677

7778
if (ret) {

0 commit comments

Comments
 (0)