From 9a0a8d2f4290c519f96311d4fc10f97203866a55 Mon Sep 17 00:00:00 2001 From: David Lin Date: Mon, 12 Jun 2017 09:28:44 -0700 Subject: [PATCH] haptics: move playback mode setting to on() This patch moves the device playback mode configuration from off() to on() to avoid the unnecessarily switching from rtp to waveform mode for consecutive waveform playbacks. Bug: 62507430 Test: vts, haptic stresss test Change-Id: I0f7c1f6263dcb4da59695c1619aade47f7381541 Signed-off-by: David Lin --- vibrator/Vibrator.cpp | 23 ++++++++++------------- vibrator/Vibrator.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index 7e303423..b6804dbd 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -77,7 +77,7 @@ Vibrator::Vibrator(std::ofstream&& activate, std::ofstream&& duration, mTickDuration = property_get_int32("ro.vibrator.hal.tick.duration", WAVEFORM_TICK_EFFECT_MS); } -Return Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop) { +Return Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop, bool isWaveform) { uint32_t loopMode = 1; // Open-loop mode is used for short click for over-drive @@ -93,6 +93,12 @@ Return Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop) { return Status::UNKNOWN_ERROR; } + if (isWaveform) { + mMode << WAVEFORM_MODE << std::endl; + } else { + mMode << RTP_MODE << std::endl; + } + mActivate << 1 << std::endl; if (!mActivate) { ALOGE("Failed to activate (%d): %s", errno, strerror(errno)); @@ -104,22 +110,15 @@ Return Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop) { // Methods from ::android::hardware::vibrator::V1_1::IVibrator follow. Return Vibrator::on(uint32_t timeoutMs) { - return on(timeoutMs, false); + return on(timeoutMs, false /* forceOpenLoop */, false /* isWaveform */); } Return Vibrator::off() { - mActivate << 0 << std::endl; if (!mActivate) { ALOGE("Failed to turn vibrator off (%d): %s", errno, strerror(errno)); return Status::UNKNOWN_ERROR; } - - mMode << RTP_MODE << std::endl; - if (!mMode) { - ALOGE("Failed to set RTP mode (%d): %s", errno, strerror(errno)); - return Status::UNKNOWN_ERROR; - } return Status::OK; } @@ -177,9 +176,8 @@ Return Vibrator::perform(Effect effect, EffectStrength strength, perform_c return Void(); } - mMode << WAVEFORM_MODE << std::endl; mScale << convertEffectStrength(strength) << std::endl; - on(timeMS, true); + on(timeMS, true /* forceOpenLoop */, true /* isWaveform */); _hidl_cb(status, timeMS); return Void(); @@ -200,9 +198,8 @@ Return Vibrator::perform_1_1(Effect_1_1 effect, EffectStrength strength, return Void(); } - mMode << WAVEFORM_MODE << std::endl; mScale << convertEffectStrength(strength) << std::endl; - on(timeMS, true); + on(timeMS, true /* forceOpenLoop */, true /* isWaveform */); _hidl_cb(status, timeMS); return Void(); diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h index 1132ca0b..920fb3e6 100644 --- a/vibrator/Vibrator.h +++ b/vibrator/Vibrator.h @@ -47,7 +47,7 @@ public: Return perform_1_1(Effect_1_1 effect, EffectStrength strength, perform_cb _hidl_cb) override; private: - Return on(uint32_t timeoutMs, bool forceOpenLoop); + Return on(uint32_t timeoutMs, bool forceOpenLoop, bool isWaveform); std::ofstream mActivate; std::ofstream mDuration; std::ofstream mState;