[DO NOT MERGE] vibrator/cs40l26: Adding minimum scale for composition primitives

Adding minimum scale for composition primitives to make 0 scale
primitives perform similarly to C10.

Bug: 260611234
Test: Flashed to device and played compositions with idlcli
Change-Id: Iaf872011b79de9da46de0de3ca770b794f67cd88
Signed-off-by: Nathan Kulczak <nathankulczak@google.com>
This commit is contained in:
Nathan Kulczak 2022-12-14 04:26:16 +00:00
parent b9f6c727e2
commit 6346fec3af
2 changed files with 10 additions and 2 deletions

View file

@ -529,6 +529,8 @@ Vibrator::Vibrator(std::unique_ptr<HwApi> hwApiDefault, std::unique_ptr<HwCal> h
mSupportedPrimitives = defaultSupportedPrimitives; mSupportedPrimitives = defaultSupportedPrimitives;
} }
mPrimitiveMinScale = {0.0f, 0.01f, 0.11f, 0.23f, 0.0f, 0.25f, 0.02f, 0.03f, 0.16f};
// ====== Get GPIO status and init it ================ // ====== Get GPIO status and init it ================
mGPIOStatus = mHwGPIO->getGPIO(); mGPIOStatus = mHwGPIO->getGPIO();
if (!mGPIOStatus || !mHwGPIO->initGPIO()) { if (!mGPIOStatus || !mHwGPIO->initGPIO()) {
@ -758,17 +760,22 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect> &composi
auto &e_curr = composite[i_curr]; auto &e_curr = composite[i_curr];
uint32_t effectIndex = 0; uint32_t effectIndex = 0;
uint32_t effectVolLevel = 0; uint32_t effectVolLevel = 0;
if (e_curr.scale < 0.0f || e_curr.scale > 1.0f) { float effectScale = e_curr.scale;
if (effectScale < 0.0f || effectScale > 1.0f) {
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
} }
if(effectScale < mPrimitiveMinScale[static_cast<uint32_t>(e_curr.primitive)]) {
effectScale = mPrimitiveMinScale[static_cast<uint32_t>(e_curr.primitive)];
}
if (e_curr.primitive != CompositePrimitive::NOOP) { if (e_curr.primitive != CompositePrimitive::NOOP) {
ndk::ScopedAStatus status; ndk::ScopedAStatus status;
status = getPrimitiveDetails(e_curr.primitive, &effectIndex); status = getPrimitiveDetails(e_curr.primitive, &effectIndex);
if (!status.isOk()) { if (!status.isOk()) {
return status; return status;
} }
effectVolLevel = intensityToVolLevel(e_curr.scale, effectIndex); effectVolLevel = intensityToVolLevel(effectScale, effectIndex);
totalDuration += mEffectDurations[effectIndex]; totalDuration += mEffectDurations[effectIndex];
} }

View file

@ -231,6 +231,7 @@ class Vibrator : public BnVibrator {
bool mIsChirpEnabled; bool mIsChirpEnabled;
uint32_t mSupportedPrimitivesBits = 0x0; uint32_t mSupportedPrimitivesBits = 0x0;
std::vector<CompositePrimitive> mSupportedPrimitives; std::vector<CompositePrimitive> mSupportedPrimitives;
std::vector<float> mPrimitiveMinScale;
bool mConfigHapticAlsaDeviceDone{false}; bool mConfigHapticAlsaDeviceDone{false};
bool mGPIOStatus; bool mGPIOStatus;
bool mIsDual{false}; bool mIsDual{false};