From f67b3257c13787da413dbfbe3ba0ca21b707512f Mon Sep 17 00:00:00 2001 From: philmoz Date: Sun, 11 Dec 2022 11:43:09 +1100 Subject: [PATCH] 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 --- companion/src/simulation/widgets/radioknobwidget.h | 6 +++++- companion/src/simulation/widgets/radiowidget.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/companion/src/simulation/widgets/radioknobwidget.h b/companion/src/simulation/widgets/radioknobwidget.h index d66eddf18..dffd14f6a 100644 --- a/companion/src/simulation/widgets/radioknobwidget.h +++ b/companion/src/simulation/widgets/radioknobwidget.h @@ -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); } diff --git a/companion/src/simulation/widgets/radiowidget.cpp b/companion/src/simulation/widgets/radiowidget.cpp index 9e4d9177a..894f642ff 100644 --- a/companion/src/simulation/widgets/radiowidget.cpp +++ b/companion/src/simulation/widgets/radiowidget.cpp @@ -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); } }