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
Bug: 180932901
Test: m
Change-Id: I55f8996f78fc3cbb0666e834566cd5eaaf50b047
diff --git a/vibrator/drv2624/Vibrator.cpp b/vibrator/drv2624/Vibrator.cpp
index fbc6f9a..aa8cc7a 100644
--- a/vibrator/drv2624/Vibrator.cpp
+++ b/vibrator/drv2624/Vibrator.cpp
@@ -418,6 +418,7 @@
if (mHwApi->hasRtpInput()) {
ret |= IVibrator::CAP_AMPLITUDE_CONTROL;
}
+ ret |= IVibrator::CAP_GET_RESONANT_FREQUENCY;
*_aidl_return = ret;
return ndk::ScopedAStatus::ok();
}
@@ -678,6 +679,24 @@
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
+static float freqPeriodFormulaFloat(std::uint32_t in) {
+ return static_cast<float>(1000000000) / static_cast<float>(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 @@
ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect> *_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;