summaryrefslogtreecommitdiff
path: root/vibrator
diff options
context:
space:
mode:
authorVince Leung <leungv@google.com>2021-02-04 18:59:58 +0000
committerVince Leung <leungv@google.com>2021-02-11 21:29:45 +0000
commit7516cedb9ab62d9376f405a2bc1018575c1e0619 (patch)
treed9a1b53290c7319b5a3f497ab3feac1bd2eee56c /vibrator
parent05b78e7b42a2d8169dc5b51abda0a387f3f77c3c (diff)
downloadbramble-7516cedb9ab62d9376f405a2bc1018575c1e0619.tar.gz
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
Diffstat (limited to 'vibrator')
-rw-r--r--vibrator/drv2624/Vibrator.cpp19
-rw-r--r--vibrator/drv2624/Vibrator.h2
2 files changed, 21 insertions, 0 deletions
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<CompositeEffect> & /*comp
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 @@ class Vibrator : public BnVibrator {
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;