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;