mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_RangeFinder_PulsedLightLRF: Fix driver after I2CDevice conversion
* Fix wrong semaphore->take check in ::get_reading * Simplify semaphore releasing * Fix typos and trailing whitespace
This commit is contained in:
parent
e1342eb533
commit
0dc33410ff
@ -21,7 +21,7 @@
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
/*
|
||||
The constructor also initialises the rangefinder. Note that this
|
||||
The constructor also initializes the rangefinder. Note that this
|
||||
constructor is not called until detect() returns true, so we
|
||||
already know that we should setup the rangefinder
|
||||
*/
|
||||
@ -67,38 +67,32 @@ bool AP_RangeFinder_PulsedLightLRF::start_reading()
|
||||
}
|
||||
|
||||
// send command to take reading
|
||||
if (!_dev->write_register(AP_RANGEFINDER_PULSEDLIGHTLRF_MEASURE_REG,
|
||||
AP_RANGEFINDER_PULSEDLIGHTLRF_MSRREG_ACQUIRE)) {
|
||||
bool ret = _dev->write_register(AP_RANGEFINDER_PULSEDLIGHTLRF_MEASURE_REG,
|
||||
AP_RANGEFINDER_PULSEDLIGHTLRF_MSRREG_ACQUIRE);
|
||||
_dev->get_semaphore()->give();
|
||||
return false;
|
||||
}
|
||||
|
||||
// return semaphore
|
||||
_dev->get_semaphore()->give();
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// read - return last value measured by sensor
|
||||
bool AP_RangeFinder_PulsedLightLRF::get_reading(uint16_t &reading_cm)
|
||||
{
|
||||
if (_dev->get_semaphore()->take(1)) {
|
||||
uint8_t buff[2];
|
||||
|
||||
if (!_dev->get_semaphore()->take(1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t buff[2];
|
||||
// read the high and low byte distance registers
|
||||
if (!_dev->read_registers(AP_RANGEFINDER_PULSEDLIGHTLRF_DISTHIGH_REG, buff, sizeof(buff))) {
|
||||
bool ret = _dev->read_registers(AP_RANGEFINDER_PULSEDLIGHTLRF_DISTHIGH_REG, buff, sizeof(buff));
|
||||
_dev->get_semaphore()->give();
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// combine results into distance
|
||||
reading_cm = ((uint16_t)buff[0]) << 8 | buff[1];
|
||||
|
||||
// return semaphore
|
||||
_dev->get_semaphore()->give();
|
||||
|
||||
// kick off another reading for next time
|
||||
// To-Do: replace this with continuous mode
|
||||
hal.scheduler->delay_microseconds(200);
|
||||
|
Loading…
Reference in New Issue
Block a user