ManualControlSelector: is InputValid refactor with switch case for code readability

This commit is contained in:
Matthias Grob
2025-07-29 18:35:01 +02:00
parent a09352c079
commit 461433d7f6
@@ -74,20 +74,40 @@ bool ManualControlSelector::isInputValid(const manual_control_setpoint_s &input,
const bool sample_newer_than_timeout = now < input.timestamp_sample + _timeout;
// Check if source matches the configuration
const bool source_rc_matched = (_rc_in_mode == 0) && isRc(input.data_source);
const bool source_mavlink_matched = (_rc_in_mode == 1) && isMavlink(input.data_source);
const bool source_any_matched = (_rc_in_mode == 2);
const bool source_first_matched = (_rc_in_mode == 3) &&
(input.data_source == _first_valid_source
|| _first_valid_source == manual_control_setpoint_s::SOURCE_UNKNOWN);
const bool source_rc_priority = (_rc_in_mode == 5)
&& (isRc(input.data_source) || (now > _timestamp_last_rc + _timeout));
const bool source_mavlink_priority = (_rc_in_mode == 6)
&& (isMavlink(input.data_source) || (now > _timestamp_last_mavlink + _timeout));
bool match = false;
return sample_from_the_past && sample_newer_than_timeout && input.valid
&& (source_rc_matched || source_mavlink_matched || source_any_matched || source_first_matched || source_rc_priority
|| source_mavlink_priority);
switch (_rc_in_mode) { // COM_RC_IN_MODE
case 0: // RC Transmitter only
match = isRc(input.data_source);
break;
case 1: // Joystick only
match = isMavlink(input.data_source);
break;
case 2: // RC and Joystick with fallback
match = true;
break;
case 3: // RC or Joystick keep first
match = (input.data_source == _first_valid_source)
|| (_first_valid_source == manual_control_setpoint_s::SOURCE_UNKNOWN);
break;
case 5: // RC priority, Joystick fallback
match = isRc(input.data_source) || (now > _timestamp_last_rc + _timeout);
break;
case 6: // Joystick priority, RC fallback
match = isMavlink(input.data_source) || (now > _timestamp_last_mavlink + _timeout);
break;
case 4: // Stick input disabled
default:
break;
}
return sample_from_the_past && sample_newer_than_timeout && input.valid && match;
}
manual_control_setpoint_s &ManualControlSelector::setpoint()