Skip to content

Commit

Permalink
AP_RangeFinder: fix Lua timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
clydemcqueen authored and tridge committed May 13, 2024
1 parent bd3e58c commit b853fe3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions libraries/AP_RangeFinder/AP_RangeFinder_Lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ bool AP_RangeFinder_Lua::handle_script_msg(float dist_m) {

WITH_SEMAPHORE(_sem);

// Time out on incoming data; if we don't get new data in 500ms, dump it
if (now - _state_pending.last_reading_ms > AP_RANGEFINDER_LUA_TIMEOUT_MS) {
set_status(_state_pending, RangeFinder::Status::NoData);
} else {
_state_pending.last_reading_ms = now;
_state_pending.distance_m = dist_m;
_state_pending.signal_quality_pct = RangeFinder::SIGNAL_QUALITY_UNKNOWN;
_state_pending.voltage_mv = 0;
update_status(_state_pending);
}
_state_pending.last_reading_ms = now;
_state_pending.distance_m = dist_m;
_state_pending.signal_quality_pct = RangeFinder::SIGNAL_QUALITY_UNKNOWN;
_state_pending.voltage_mv = 0;
update_status(_state_pending);

return true;
}
Expand All @@ -66,6 +61,12 @@ bool AP_RangeFinder_Lua::handle_script_msg(float dist_m) {
void AP_RangeFinder_Lua::update(void)
{
WITH_SEMAPHORE(_sem);

// Time out on incoming data
if (_state_pending.status != RangeFinder::Status::NotConnected &&
AP_HAL::millis() - _state_pending.last_reading_ms > AP_RANGEFINDER_LUA_TIMEOUT_MS) {
set_status(_state_pending, RangeFinder::Status::NoData);
}
state = _state_pending;
}

Expand Down

0 comments on commit b853fe3

Please sign in to comment.