Improved potentiometer getValue() function

pull/14/head
Blackaddr 3 years ago
parent 398e419f92
commit a798ba06de
  1. 2
      src/effects/AudioEffectSOS.cpp
  2. 16
      src/peripherals/BAPhysicalControls.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;

@ -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<float>(valFilter - m_minCalibrationThresholded) / static_cast<float>(m_rangeThresholded);
}

Loading…
Cancel
Save