ManualControlSelector: simplification refactoring

- clang tidy did't like {bool} == true in a condition
- setpoint_from_input() got small enough ot just put in line
This commit is contained in:
Matthias Grob 2021-10-13 15:01:40 +02:00
parent cc2ec09659
commit 48ed350b25
2 changed files with 3 additions and 11 deletions

View File

@ -50,12 +50,12 @@ void ManualControlSelector::updateWithNewInputSample(uint64_t now, const manual_
// First check if the chosen input got invalid, so it can get replaced
updateValidityOfChosenInput(now);
const bool update_existing_input = _setpoint.valid == true && input.data_source == _setpoint.chosen_input.data_source;
const bool start_using_new_input = _setpoint.valid == false;
const bool update_existing_input = _setpoint.valid && input.data_source == _setpoint.chosen_input.data_source;
const bool start_using_new_input = !_setpoint.valid;
// Switch to new input if it's valid and we don't already have a valid one
if (isInputValid(input, now) && (update_existing_input || start_using_new_input)) {
_setpoint = setpoint_from_input(input);
_setpoint.chosen_input = input;
_setpoint.valid = true;
_instance = instance;
}
@ -82,13 +82,6 @@ bool ManualControlSelector::isInputValid(const manual_control_input_s &input, ui
&& (source_rc_matched || source_mavlink_matched || source_any_matched);
}
manual_control_setpoint_s ManualControlSelector::setpoint_from_input(const manual_control_input_s &input)
{
manual_control_setpoint_s setpoint;
setpoint.chosen_input = input;
return setpoint;
}
manual_control_setpoint_s &ManualControlSelector::setpoint()
{
return _setpoint;

View File

@ -52,7 +52,6 @@ public:
private:
bool isInputValid(const manual_control_input_s &input, uint64_t now) const;
static manual_control_setpoint_s setpoint_from_input(const manual_control_input_s &input);
manual_control_setpoint_s _setpoint{};
uint64_t _timeout{0};