From 3b2b23e5e28aa3cd453c84f4c7b92295191a9fbd Mon Sep 17 00:00:00 2001 From: Chris Paulo Date: Wed, 7 Aug 2024 15:05:09 -0700 Subject: [PATCH] vibrator: Fix scaling logic for felix vibrator Felix vibrator has stricter primitive effect scaling values. We need to update the logic to assure that we apply the upper and lower bounds of the voltage range to avoid brownout and to maximize the usable range. Bug: 344037610 Flag: EXEMPT bugfix Test: atest PtsVibratorHalTestSuite \ PtsHapticsTestCases \ VibratorHalCs40l26TestSuite \ VtsHalVibratorManagerTargetTest \ VtsHalVibratorTargetTest \ CtsVibratorTestCases Test: Verify scale values Change-Id: Iba8b8115fea01e56105b43f520d32c63ffcf7fd4 --- vibrator/cs40l26/Vibrator.cpp | 48 ++++++++++++++++++++++++----------- vibrator/cs40l26/Vibrator.h | 4 +-- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index d045bce..507e247 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -677,8 +677,21 @@ Vibrator::Vibrator(std::unique_ptr hwApiDefault, std::unique_ptr h mSupportedPrimitives = defaultSupportedPrimitives; } - mPrimitiveMaxScale = {1.0f, 0.95f, 0.75f, 0.9f, 1.0f, 1.0f, 1.0f, 0.75f, 0.75f}; - mPrimitiveMinScale = {0.0f, 0.01f, 0.11f, 0.23f, 0.0f, 0.25f, 0.02f, 0.03f, 0.16f}; + mPrimitiveMaxScale.resize(WAVEFORM_MAX_INDEX, 100); + mPrimitiveMaxScale[WAVEFORM_CLICK_INDEX] = 95; + mPrimitiveMaxScale[WAVEFORM_THUD_INDEX] = 75; + mPrimitiveMaxScale[WAVEFORM_SPIN_INDEX] = 90; + mPrimitiveMaxScale[WAVEFORM_LIGHT_TICK_INDEX] = 75; + mPrimitiveMaxScale[WAVEFORM_LOW_TICK_INDEX] = 75; + + mPrimitiveMinScale.resize(WAVEFORM_MAX_INDEX, 0); + mPrimitiveMinScale[WAVEFORM_CLICK_INDEX] = 1; + mPrimitiveMinScale[WAVEFORM_THUD_INDEX] = 11; + mPrimitiveMinScale[WAVEFORM_SPIN_INDEX] = 23; + mPrimitiveMinScale[WAVEFORM_SLOW_RISE_INDEX] = 25; + mPrimitiveMinScale[WAVEFORM_QUICK_FALL_INDEX] = 2; + mPrimitiveMinScale[WAVEFORM_LIGHT_TICK_INDEX] = 3; + mPrimitiveMinScale[WAVEFORM_LOW_TICK_INDEX] = 16; // ====== Get GPIO status and init it ================ mGPIOStatus = mHwGPIO->getGPIO(); @@ -904,14 +917,6 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector &composi if (!status.isOk()) { return status; } - // Add a max and min threshold to prevent the device crash(overcurrent) or no - // feeling - if (effectScale > mPrimitiveMaxScale[static_cast(e_curr.primitive)]) { - effectScale = mPrimitiveMaxScale[static_cast(e_curr.primitive)]; - } - if (effectScale < mPrimitiveMinScale[static_cast(e_curr.primitive)]) { - effectScale = mPrimitiveMinScale[static_cast(e_curr.primitive)]; - } effectVolLevel = intensityToVolLevel(effectScale, effectIndex); totalDuration += mEffectDurations[effectIndex]; } @@ -1412,7 +1417,13 @@ binder_status_t Vibrator::dump(int fd, const char **args, uint32_t numArgs) { } } - dprintf(fd, "Base: OWT waveform:\n"); + dprintf(fd, "==== Scales ====\n\tId\tMinScale\tMaxScale\n"); + for (effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) { + dprintf(fd, "\t%d\t%d\t\t%d\n", effectId, mPrimitiveMinScale[effectId], + mPrimitiveMaxScale[effectId]); + } + + dprintf(fd, "\nBase: OWT waveform:\n"); dprintf(fd, "\tId\tBytes\tData\tt\ttrigger button\n"); for (effectId = WAVEFORM_MAX_PHYSICAL_INDEX; effectId < WAVEFORM_MAX_INDEX; effectId++) { uint32_t numBytes = mFfEffects[effectId].u.periodic.custom_len * 2; @@ -1520,10 +1531,6 @@ ndk::ScopedAStatus Vibrator::getSimpleDetails(Effect effect, EffectStrength stre case Effect::HEAVY_CLICK: effectIndex = WAVEFORM_CLICK_INDEX; intensity *= 1.0f; - // WAVEFORM_CLICK_INDEX is 2, but the primitive CLICK index is 1. - if (intensity > mPrimitiveMaxScale[WAVEFORM_CLICK_INDEX - 1]) { - intensity = mPrimitiveMaxScale[WAVEFORM_CLICK_INDEX - 1]; - } break; default: return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); @@ -1765,6 +1772,17 @@ uint32_t Vibrator::intensityToVolLevel(float intensity, uint32_t effectIndex) { volLevel = calc(intensity, mClickEffectVol); break; } + + // The waveform being played must fall within the allowable scale range + if (effectIndex < WAVEFORM_MAX_INDEX) { + if (volLevel > mPrimitiveMaxScale[effectIndex]) { + volLevel = mPrimitiveMaxScale[effectIndex]; + } + if (volLevel < mPrimitiveMinScale[effectIndex]) { + volLevel = mPrimitiveMinScale[effectIndex]; + } + } + return volLevel; } diff --git a/vibrator/cs40l26/Vibrator.h b/vibrator/cs40l26/Vibrator.h index 8f89713..20f45d7 100644 --- a/vibrator/cs40l26/Vibrator.h +++ b/vibrator/cs40l26/Vibrator.h @@ -233,8 +233,8 @@ class Vibrator : public BnVibrator { bool mIsChirpEnabled; uint32_t mSupportedPrimitivesBits = 0x0; std::vector mSupportedPrimitives; - std::vector mPrimitiveMaxScale; - std::vector mPrimitiveMinScale; + std::vector mPrimitiveMaxScale; + std::vector mPrimitiveMinScale; bool mConfigHapticAlsaDeviceDone{false}; bool mGPIOStatus; bool mIsDual{false};