From a798ba06dea61fd2b6f348c6fcdbf7b0bec45ba9 Mon Sep 17 00:00:00 2001 From: Blackaddr Date: Fri, 9 Apr 2021 15:55:03 -0400 Subject: [PATCH] Improved potentiometer getValue() function --- src/effects/AudioEffectSOS.cpp | 2 +- src/peripherals/BAPhysicalControls.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/effects/AudioEffectSOS.cpp b/src/effects/AudioEffectSOS.cpp index 2512261..7999ac6 100644 --- a/src/effects/AudioEffectSOS.cpp +++ b/src/effects/AudioEffectSOS.cpp @@ -62,7 +62,7 @@ void AudioEffectSOS::enable(void) if (m_externalMemory) { // Because we hold the previous output buffer for an update cycle, the maximum delay is actually // 1 audio block mess then the max delay returnable from the memory. - m_maxDelaySamples = m_memory->getMaxDelaySamples(); + m_maxDelaySamples = m_memory->getMaxDelaySamples() - AUDIO_BLOCK_SAMPLES; Serial.println(String("SOS Enabled with delay length ") + m_maxDelaySamples + String(" samples")); } m_delaySamples = m_maxDelaySamples; diff --git a/src/peripherals/BAPhysicalControls.cpp b/src/peripherals/BAPhysicalControls.cpp index 0a81c9d..32c16c3 100644 --- a/src/peripherals/BAPhysicalControls.cpp +++ b/src/peripherals/BAPhysicalControls.cpp @@ -265,12 +265,22 @@ bool Potentiometer::getValue(float &value) { return false; } } - m_lastValidValue = m_lastValue; // Convert the integer reading to a float value range 0.0 to 1.0f - if (valFilter < m_minCalibrationThresholded) { value = 0.0f; } - else if (valFilter > m_maxCalibrationThresholded) { value = 1.0f; } + if (valFilter < m_minCalibrationThresholded) { + m_lastValue = m_minCalibrationThresholded; + if (m_lastValidValue == m_minCalibrationThresholded) { return false; } + m_lastValidValue = m_lastValue; + value = 0.0f; + } + else if (valFilter > m_maxCalibrationThresholded) { + m_lastValue = m_maxCalibrationThresholded; + if (m_lastValidValue == m_maxCalibrationThresholded) { return false; } + m_lastValidValue = m_lastValue; + value = 1.0f; + } else { + m_lastValidValue = m_lastValue; value = static_cast(valFilter - m_minCalibrationThresholded) / static_cast(m_rangeThresholded); }