diff options
author | chasewu <chasewu@google.com> | 2018-11-06 11:35:53 +0800 |
---|---|---|
committer | Chase Wu <chasewu@google.com> | 2018-11-15 12:52:51 +0000 |
commit | 1ebae380a1b784f4660a235b7cd36e3e3364e936 (patch) | |
tree | 953b797164362986619de11ddadb2de5eb3799f6 /vibrator | |
parent | 1a8589912e5ff0b9c709bf87316aa893b6c501fe (diff) | |
download | bonito-1ebae380a1b784f4660a235b7cd36e3e3364e936.tar.gz |
haptics: Add a dynmaic voltage and frequency switch mechanism
1. From haptics tuning meeting, this patch add a dynamic
voltage/frequency switch mechanism to make haptics feel better
under each kind of criteria.
S4
For short vibration: Voltage 2.1V, F0
For long vibration: Voltage 1.5V, F=155Hz
B4
For short vibration: Voltage 2.5V, F0
For long vibration: Voltage 1.5V, F=155Hz
Bug: 119149580
Test: manual check the voltage value after each haptics
Change-Id: I2c3e88fe0c4dcb9b164179d0ddb6504f059d077a
Signed-off-by: chasewu <chasewu@google.com>
Diffstat (limited to 'vibrator')
-rw-r--r-- | vibrator/Vibrator.cpp | 22 | ||||
-rw-r--r-- | vibrator/Vibrator.h | 10 | ||||
-rw-r--r-- | vibrator/service.cpp | 38 |
3 files changed, 64 insertions, 6 deletions
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index 002dd869..fcfef5f0 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -44,6 +44,12 @@ static constexpr char WAVEFORM_MODE[] = "waveform"; static constexpr uint32_t LOOP_MODE_OPEN = 1; +// Default max voltage 2.15V +static constexpr uint32_t VOLTAGE_MAX = 107; + +// Default lra period 262 (i.e. 155Hz) for long haptics +static constexpr uint32_t LONG_LRA_PERIOD = 262; + // Use effect #1 in the waveform library for CLICK effect static constexpr char WAVEFORM_CLICK_EFFECT_SEQ[] = "1 0"; static constexpr int32_t WAVEFORM_CLICK_EFFECT_MS = 6; @@ -66,7 +72,9 @@ using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength; 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&& ctrlloop, std::ofstream&& lptrigger) : + std::ofstream&& scale, std::ofstream&& ctrlloop, std::ofstream&& lptrigger, + std::ofstream&& odclamp, std::ofstream&& ollraperiod, + std::uint32_t lra_period) : mActivate(std::move(activate)), mDuration(std::move(duration)), mState(std::move(state)), @@ -75,12 +83,18 @@ Vibrator::Vibrator(std::ofstream&& activate, std::ofstream&& duration, mSequencer(std::move(sequencer)), mScale(std::move(scale)), mCtrlLoop(std::move(ctrlloop)), - mLpTriggerEffect(std::move(lptrigger)) { + mLpTriggerEffect(std::move(lptrigger)), + mOdClamp(std::move(odclamp)), + mOlLraPeriod(std::move(ollraperiod)), + mLraPeriod(lra_period) { mClickDuration = property_get_int32("ro.vibrator.hal.click.duration", WAVEFORM_CLICK_EFFECT_MS); mTickDuration = property_get_int32("ro.vibrator.hal.tick.duration", WAVEFORM_TICK_EFFECT_MS); mHeavyClickDuration = property_get_int32( "ro.vibrator.hal.heavyclick.duration", WAVEFORM_HEAVY_CLICK_EFFECT_MS); + mShortVoltageMax = property_get_int32("ro.vibrator.hal.short.voltage", VOLTAGE_MAX); + mLongVoltageMax = property_get_int32("ro.vibrator.hal.long.voltage", VOLTAGE_MAX); + mLongLraPeriod = property_get_int32("ro.vibrator.hal.long.lra.period", LONG_LRA_PERIOD); // This enables effect #1 from the waveform library to be triggered by SLPI // while the AP is in suspend mode @@ -101,8 +115,12 @@ Return<Status> Vibrator::on(uint32_t timeoutMs, bool isWaveform) { if (isWaveform) { mMode << WAVEFORM_MODE << std::endl; + mOdClamp << mShortVoltageMax << std::endl; + mOlLraPeriod << mLraPeriod << std::endl; } else { mMode << RTP_MODE << std::endl; + mOdClamp << mLongVoltageMax << std::endl; + mOlLraPeriod << mLongLraPeriod << std::endl; } mActivate << 1 << std::endl; diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h index ed6568c7..08aa90d1 100644 --- a/vibrator/Vibrator.h +++ b/vibrator/Vibrator.h @@ -32,7 +32,9 @@ 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&& ctrlloop, std::ofstream&& lptrigger); + std::ofstream&& scale, std::ofstream&& ctrlloop, std::ofstream&& lptrigger, + std::ofstream&& odclamp, std::ofstream&& ollraperiod, + std::uint32_t lra_period); // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. using Status = ::android::hardware::vibrator::V1_0::Status; @@ -60,9 +62,15 @@ private: std::ofstream mScale; std::ofstream mCtrlLoop; std::ofstream mLpTriggerEffect; + std::ofstream mOdClamp; + std::ofstream mOlLraPeriod; + std::uint32_t mLraPeriod; int32_t mClickDuration; int32_t mTickDuration; int32_t mHeavyClickDuration; + int32_t mShortVoltageMax; + int32_t mLongVoltageMax; + int32_t mLongLraPeriod; }; } // namespace implementation } // namespace V1_2 diff --git a/vibrator/service.cpp b/vibrator/service.cpp index 6404ed0b..7289f79e 100644 --- a/vibrator/service.cpp +++ b/vibrator/service.cpp @@ -40,13 +40,16 @@ static constexpr char SEQUENCER_PATH[] = "/sys/class/leds/vibrator/device/set_se static constexpr char SCALE_PATH[] = "/sys/class/leds/vibrator/device/scale"; static constexpr char CTRL_LOOP_PATH[] = "/sys/class/leds/vibrator/device/ctrl_loop"; static constexpr char LP_TRIGGER_PATH[] = "/sys/class/leds/vibrator/device/lp_trigger_effect"; +static constexpr char OD_CLAMP_FILEPATH[] = "/sys/class/leds/vibrator/device/od_clamp"; // File path to the calibration file static constexpr char CALIBRATION_FILEPATH[] = "/persist/haptics/drv2624.cal"; // Kernel ABIs for updating the calibration data static constexpr char AUTOCAL_CONFIG[] = "autocal"; +static constexpr char LRA_PERIOD_CONFIG[] = "lra_period"; static constexpr char AUTOCAL_FILEPATH[] = "/sys/class/leds/vibrator/device/autocal"; +static constexpr char OL_LRA_PERIOD_FILEPATH[] = "/sys/class/leds/vibrator/device/ol_lra_period"; static std::string trim(const std::string& str, const std::string& whitespace = " \t") { @@ -61,7 +64,7 @@ static std::string trim(const std::string& str, return str.substr(str_begin, str_range); } -static bool loadCalibrationData() { +static bool loadCalibrationData(std::uint32_t& lra_period) { std::map<std::string, std::string> config_data; std::ofstream autocal{AUTOCAL_FILEPATH}; @@ -72,6 +75,14 @@ static bool loadCalibrationData() { return false; } + std::ofstream ol_lra_period{OL_LRA_PERIOD_FILEPATH}; + if (!ol_lra_period) { + int error = errno; + ALOGE("Failed to open %s (%d): %s", OL_LRA_PERIOD_FILEPATH, error, + strerror(error)); + return false; + } + std::ifstream cal_data{CALIBRATION_FILEPATH}; if (!cal_data) { int error = errno; @@ -101,10 +112,18 @@ static bool loadCalibrationData() { autocal << config_data[AUTOCAL_CONFIG] << std::endl; } + if(config_data.find(LRA_PERIOD_CONFIG) != config_data.end()) { + ol_lra_period << config_data[LRA_PERIOD_CONFIG] << std::endl; + lra_period = std::stoul(config_data[LRA_PERIOD_CONFIG]); + } + return true; } status_t registerVibratorService() { + // Calibration data: lra period 262(i.e. 155Hz) + std::uint32_t lra_period(262); + // ostreams below are required std::ofstream activate{ACTIVATE_PATH}; if (!activate) { @@ -171,13 +190,26 @@ status_t registerVibratorService() { ALOGW("Failed to open %s (%d): %s", LP_TRIGGER_PATH, error, strerror(error)); } - if (!loadCalibrationData()) { + std::ofstream odclamp{OD_CLAMP_FILEPATH}; + if (!odclamp) { + int error = errno; + ALOGW("Failed to open %s (%d): %s", OD_CLAMP_FILEPATH, error, strerror(error)); + } + + std::ofstream ollraperiod{OL_LRA_PERIOD_FILEPATH}; + if (!ollraperiod) { + int error = errno; + ALOGW("Failed to open %s (%d): %s", OL_LRA_PERIOD_FILEPATH, error, strerror(error)); + } + + if (!loadCalibrationData(lra_period)) { ALOGW("Failed load calibration data"); } sp<IVibrator> 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(ctrlloop), std::move(lptrigger)); + std::move(sequencer), std::move(scale), std::move(ctrlloop), std::move(lptrigger), + std::move(odclamp), std::move(ollraperiod), lra_period); return vibrator->registerAsService(); } |