From 7516cedb9ab62d9376f405a2bc1018575c1e0619 Mon Sep 17 00:00:00 2001 From: Vince Leung Date: Thu, 4 Feb 2021 18:59:58 +0000 Subject: Add APIs to get resonant frequency and Q factor Actuators can have resonant frequency and Q factor information. Exposing this information can allow for better optimized audio generated haptics. Bug: 178826612 Test: m Change-Id: I55f8996f78fc3cbb0666e834566cd5eaaf50b047 --- vibrator/drv2624/Vibrator.cpp | 19 +++++++++++++++++++ vibrator/drv2624/Vibrator.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'vibrator') diff --git a/vibrator/drv2624/Vibrator.cpp b/vibrator/drv2624/Vibrator.cpp index c2658df..d7b54de 100644 --- a/vibrator/drv2624/Vibrator.cpp +++ b/vibrator/drv2624/Vibrator.cpp @@ -415,6 +415,7 @@ ndk::ScopedAStatus Vibrator::getCapabilities(int32_t *_aidl_return) { if (mHwApi->hasRtpInput()) { ret |= IVibrator::CAP_AMPLITUDE_CONTROL; } + ret |= IVibrator::CAP_GET_RESONANT_FREQUENCY; *_aidl_return = ret; return ndk::ScopedAStatus::ok(); } @@ -668,6 +669,24 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector & /*comp return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } +static float freqPeriodFormulaFloat(std::uint32_t in) { + return static_cast(1000000000) / static_cast(24615 * in); +} + +ndk::ScopedAStatus Vibrator::getResonantFrequency(float *resonantFreqHz) { + uint32_t lraPeriod; + if(!mHwCal->getLraPeriod(&lraPeriod)) { + ALOGE("Failed to get resonant frequency (%d): %s", errno, strerror(errno)); + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); + } + *resonantFreqHz = freqPeriodFormulaFloat(lraPeriod); + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::getQFactor(float * /*qFactor*/) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); +} + } // namespace vibrator } // namespace hardware } // namespace android diff --git a/vibrator/drv2624/Vibrator.h b/vibrator/drv2624/Vibrator.h index 969269d..9b5e630 100644 --- a/vibrator/drv2624/Vibrator.h +++ b/vibrator/drv2624/Vibrator.h @@ -173,6 +173,8 @@ class Vibrator : public BnVibrator { ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector *_aidl_return) override; ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; + ndk::ScopedAStatus getResonantFrequency(float *resonantFreqHz) override; + ndk::ScopedAStatus getQFactor(float *qFactor) override; binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; -- cgit v1.2.3