fix(sim): Consistent steps for 6POS (#2831)

* Fix for issue #2827.
Ensure consistent values for the TX16, 6 position switch, in the simulator.

* Adjust 'value' to achieve alignment of raw values to step positions.

Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
philmoz
2022-12-11 10:43:09 +10:00
committed by GitHub
co-authored by Phil Mitchell
parent 78f75c5656
commit f67b3257c1
2 changed files with 11 additions and 2 deletions
@@ -100,7 +100,11 @@ class RadioKnobWidget : public RadioWidget
void setValue(int value)
{
if (m_stepSize > 1) {
value = value / m_stepSize * m_stepSize;
value = ((value + m_stepSize / 2) / m_stepSize) * m_stepSize;
// Fix values to account for lack of precision from using integer step size
// This makes the values more symmetrical around the center point
// Note: this is specific to the TX16 6 position switch which is currently the only use case here
if (value > 1024) value += 3;
}
QDial::setValue(value);
}
@@ -66,8 +66,13 @@ void RadioWidget::setValue(const int & value)
if (value != m_value || m_valueReset) {
m_value = value;
m_valueReset = false;
// This 'emit valueChanged()' call can trigger another call into this function if the value is altered.
// This can happen with the TX16 6 Position switch control.
emit valueChanged(value);
emit valueChange(m_type, m_index, value);
// If actual value was changed by the 'emit valueChanged()' call above, then
// skip the 'valueChange' signal that would send the original value. We have already sent the signal with the updated value.
if (value == getValue())
emit valueChange(m_type, m_index, value);
}
}