diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index 3f6b0f1f..13a92406 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -43,27 +43,39 @@ static constexpr char WAVEFORM_MODE[] = "waveform"; // Use effect #1 in the waveform library static constexpr char WAVEFORM_CLICK_EFFECT_SEQ[] = "1 0"; -static constexpr uint32_t WAVEFORM_CLICK_EFFECT_MS = 45; +static constexpr uint32_t WAVEFORM_CLICK_EFFECT_MS = 6; // Make double click a single click and loop once static constexpr char WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ[] = "1 1"; static constexpr uint32_t WAVEFORM_DOUBLE_CLICK_EFFECT_MS = WAVEFORM_CLICK_EFFECT_MS * 2; +// Timeout threshold for selecting open or closed loop mode +static constexpr int8_t LOOP_MODE_THRESHOLD_MS = 20; + Vibrator::Vibrator(std::ofstream&& activate, std::ofstream&& duration, std::ofstream&& state, std::ofstream&& rtpinput, std::ofstream&& mode, std::ofstream&& sequencer, - std::ofstream&& scale) : + std::ofstream&& scale, std::ofstream&& ctrlloop) : mActivate(std::move(activate)), mDuration(std::move(duration)), mState(std::move(state)), mRtpInput(std::move(rtpinput)), mMode(std::move(mode)), mSequencer(std::move(sequencer)), - mScale(std::move(scale)) {} + mScale(std::move(scale)), + mCtrlLoop(std::move(ctrlloop)) {} // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. Return Vibrator::on(uint32_t timeout_ms) { + uint32_t loop_mode = 1; + // Open-loop mode is used for short click for over-drive + // Close-loop mode is used for long notification for stability + if (timeout_ms > LOOP_MODE_THRESHOLD_MS) { + loop_mode = 0; + } + + mCtrlLoop << loop_mode << std::endl; mDuration << timeout_ms << std::endl; if (!mDuration) { ALOGE("Failed to set duration (%d): %s", errno, strerror(errno)); @@ -109,7 +121,7 @@ Return Vibrator::setAmplitude(uint8_t amplitude) { std::round((amplitude - 1) / 254.0 * (MAX_RTP_INPUT - MIN_RTP_INPUT) + MIN_RTP_INPUT); - mRtpInput << rtp_input; + mRtpInput << rtp_input << std::endl; if (!mRtpInput) { ALOGE("Failed to set amplitude (%d): %s", errno, strerror(errno)); return Status::UNKNOWN_ERROR; @@ -123,12 +135,9 @@ static uint8_t convertEffectStrength(EffectStrength strength) { switch (strength) { case EffectStrength::LIGHT: - scale = 2; // 50% + scale = 1; // 50% break; case EffectStrength::MEDIUM: - scale = 1; // 75% - break; - default: case EffectStrength::STRONG: scale = 0; // 100% break; diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h index 7a366803..5871d82b 100644 --- a/vibrator/Vibrator.h +++ b/vibrator/Vibrator.h @@ -32,7 +32,7 @@ public: Vibrator(std::ofstream&& activate, std::ofstream&& duration, std::ofstream&& state, std::ofstream&& rtpinput, std::ofstream&& mode, std::ofstream&& sequencer, - std::ofstream&& scale); + std::ofstream&& scale, std::ofstream&& ctrlloop); // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. Return on(uint32_t timeoutMs) override; @@ -49,6 +49,7 @@ private: std::ofstream mMode; std::ofstream mSequencer; std::ofstream mScale; + std::ofstream mCtrlLoop; }; } // namespace implementation } // namespace V1_0 diff --git a/vibrator/service.cpp b/vibrator/service.cpp index 0d70cb77..3359a9b5 100644 --- a/vibrator/service.cpp +++ b/vibrator/service.cpp @@ -38,6 +38,7 @@ static const char *RTP_INPUT_PATH = "/sys/class/leds/vibrator/device/rtp_input"; static const char *MODE_PATH = "/sys/class/leds/vibrator/device/mode"; static const char *SEQUENCER_PATH = "/sys/class/leds/vibrator/device/set_sequencer"; static const char *SCALE_PATH = "/sys/class/leds/vibrator/device/scale"; +static const char *CTRL_LOOP_PATH = "/sys/class/leds/vibrator/device/ctrl_loop"; status_t registerVibratorService() { // ostreams below are required @@ -94,9 +95,15 @@ status_t registerVibratorService() { ALOGW("Failed to open %s (%d): %s", SCALE_PATH, error, strerror(error)); } + std::ofstream ctrlloop{CTRL_LOOP_PATH}; + if (!state) { + int error = errno; + ALOGW("Failed to open %s (%d): %s", CTRL_LOOP_PATH, error, strerror(error)); + } + sp vibrator = new Vibrator(std::move(activate), std::move(duration), std::move(state), std::move(rtpinput), std::move(mode), - std::move(sequencer), std::move(scale)); + std::move(sequencer), std::move(scale), std::move(ctrlloop)); vibrator->registerAsService();