diff options
-rw-r--r-- | device-bonito.mk | 2 | ||||
-rw-r--r-- | device-sargo.mk | 4 | ||||
-rw-r--r-- | init.hardware.rc | 1 | ||||
-rw-r--r-- | vibrator/Vibrator.cpp | 13 | ||||
-rw-r--r-- | vibrator/Vibrator.h | 7 | ||||
-rw-r--r-- | vibrator/service.cpp | 27 |
6 files changed, 36 insertions, 18 deletions
diff --git a/device-bonito.mk b/device-bonito.mk index fef2d1e7..1759ffb8 100644 --- a/device-bonito.mk +++ b/device-bonito.mk @@ -32,7 +32,7 @@ PRODUCT_SYSTEM_DEFAULT_PROPERTIES +=\ ro.vibrator.hal.click.duration=7 \ ro.vibrator.hal.tick.duration=4 \ ro.vibrator.hal.heavyclick.duration=10 \ - ro.vibrator.hal.short.voltage=125 \ + ro.vibrator.hal.short.voltage=120 \ ro.vibrator.hal.long.voltage=75 \ ro.vibrator.hal.long.lra.period=262 diff --git a/device-sargo.mk b/device-sargo.mk index c8363205..279d148c 100644 --- a/device-sargo.mk +++ b/device-sargo.mk @@ -34,8 +34,8 @@ PRODUCT_SYSTEM_DEFAULT_PROPERTIES +=\ ro.vibrator.hal.click.duration=6 \ ro.vibrator.hal.tick.duration=4 \ ro.vibrator.hal.heavyclick.duration=10 \ - ro.vibrator.hal.short.voltage=105 \ - ro.vibrator.hal.long.voltage= 75 \ + ro.vibrator.hal.short.voltage=110 \ + ro.vibrator.hal.long.voltage=75 \ ro.vibrator.hal.long.lra.period=262 # DRV2624 Haptics Waveform diff --git a/init.hardware.rc b/init.hardware.rc index b0a5ea0a..8213c336 100644 --- a/init.hardware.rc +++ b/init.hardware.rc @@ -409,6 +409,7 @@ on early-boot chown system system /sys/class/leds/vibrator/device/ol_lra_period chown system system /sys/class/leds/vibrator/device/autocal chown system system /sys/class/leds/vibrator/device/lp_trigger_effect + chown system system /sys/class/leds/vibrator/device/lra_wave_shape # Permission for LED driver chown system system /sys/class/leds/red/on_off_ms diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index fcfef5f0..1ff0f6c1 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -43,6 +43,8 @@ static constexpr char RTP_MODE[] = "rtp"; static constexpr char WAVEFORM_MODE[] = "waveform"; static constexpr uint32_t LOOP_MODE_OPEN = 1; +static constexpr uint32_t SINE_WAVE = 1; +static constexpr uint32_t SQUARE_WAVE = 0; // Default max voltage 2.15V static constexpr uint32_t VOLTAGE_MAX = 107; @@ -73,8 +75,8 @@ 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&& odclamp, std::ofstream&& ollraperiod, - std::uint32_t lra_period) : + std::ofstream&& lrawaveshape, std::ofstream&& odclamp, std::ofstream&& ollraperiod, + std::uint32_t short_lra_period) : mActivate(std::move(activate)), mDuration(std::move(duration)), mState(std::move(state)), @@ -84,9 +86,10 @@ Vibrator::Vibrator(std::ofstream&& activate, std::ofstream&& duration, mScale(std::move(scale)), mCtrlLoop(std::move(ctrlloop)), mLpTriggerEffect(std::move(lptrigger)), + mLraWaveShape(std::move(lrawaveshape)), mOdClamp(std::move(odclamp)), mOlLraPeriod(std::move(ollraperiod)), - mLraPeriod(lra_period) { + mShortLraPeriod(short_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); @@ -115,10 +118,12 @@ Return<Status> Vibrator::on(uint32_t timeoutMs, bool isWaveform) { if (isWaveform) { mMode << WAVEFORM_MODE << std::endl; + mLraWaveShape << SINE_WAVE << std::endl; mOdClamp << mShortVoltageMax << std::endl; - mOlLraPeriod << mLraPeriod << std::endl; + mOlLraPeriod << mShortLraPeriod << std::endl; } else { mMode << RTP_MODE << std::endl; + mLraWaveShape << SQUARE_WAVE << std::endl; mOdClamp << mLongVoltageMax << std::endl; mOlLraPeriod << mLongLraPeriod << std::endl; } diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h index 08aa90d1..91a63443 100644 --- a/vibrator/Vibrator.h +++ b/vibrator/Vibrator.h @@ -33,8 +33,8 @@ public: std::ofstream&& state, std::ofstream&& rtpinput, std::ofstream&& mode, std::ofstream&& sequencer, std::ofstream&& scale, std::ofstream&& ctrlloop, std::ofstream&& lptrigger, - std::ofstream&& odclamp, std::ofstream&& ollraperiod, - std::uint32_t lra_period); + std::ofstream&& lrawaveshape, std::ofstream&& odclamp, std::ofstream&& ollraperiod, + std::uint32_t short_lra_period); // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. using Status = ::android::hardware::vibrator::V1_0::Status; @@ -62,9 +62,10 @@ private: std::ofstream mScale; std::ofstream mCtrlLoop; std::ofstream mLpTriggerEffect; + std::ofstream mLraWaveShape; std::ofstream mOdClamp; std::ofstream mOlLraPeriod; - std::uint32_t mLraPeriod; + std::uint32_t mShortLraPeriod; int32_t mClickDuration; int32_t mTickDuration; int32_t mHeavyClickDuration; diff --git a/vibrator/service.cpp b/vibrator/service.cpp index 7289f79e..675b000f 100644 --- a/vibrator/service.cpp +++ b/vibrator/service.cpp @@ -40,7 +40,8 @@ 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"; +static constexpr char LRA_WAVE_SHAPE_PATH[] = "/sys/class/leds/vibrator/device/lra_wave_shape"; +static constexpr char OD_CLAMP_PATH[] = "/sys/class/leds/vibrator/device/od_clamp"; // File path to the calibration file static constexpr char CALIBRATION_FILEPATH[] = "/persist/haptics/drv2624.cal"; @@ -51,6 +52,9 @@ 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"; +// Set a default lra period in case there is no calibration file +static constexpr uint32_t DEFAULT_LRA_PERIOD = 262; + static std::string trim(const std::string& str, const std::string& whitespace = " \t") { const auto str_begin = str.find_first_not_of(whitespace); @@ -64,7 +68,7 @@ static std::string trim(const std::string& str, return str.substr(str_begin, str_range); } -static bool loadCalibrationData(std::uint32_t& lra_period) { +static bool loadCalibrationData(std::uint32_t& short_lra_period) { std::map<std::string, std::string> config_data; std::ofstream autocal{AUTOCAL_FILEPATH}; @@ -114,7 +118,7 @@ static bool loadCalibrationData(std::uint32_t& lra_period) { 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]); + short_lra_period = std::stoul(config_data[LRA_PERIOD_CONFIG]); } return true; @@ -122,7 +126,7 @@ static bool loadCalibrationData(std::uint32_t& lra_period) { status_t registerVibratorService() { // Calibration data: lra period 262(i.e. 155Hz) - std::uint32_t lra_period(262); + std::uint32_t short_lra_period(DEFAULT_LRA_PERIOD); // ostreams below are required std::ofstream activate{ACTIVATE_PATH}; @@ -190,10 +194,16 @@ status_t registerVibratorService() { ALOGW("Failed to open %s (%d): %s", LP_TRIGGER_PATH, error, strerror(error)); } - std::ofstream odclamp{OD_CLAMP_FILEPATH}; + std::ofstream lrawaveshape{LRA_WAVE_SHAPE_PATH}; + if (!lrawaveshape) { + int error = errno; + ALOGW("Failed to open %s (%d): %s", LRA_WAVE_SHAPE_PATH, error, strerror(error)); + } + + std::ofstream odclamp{OD_CLAMP_PATH}; if (!odclamp) { int error = errno; - ALOGW("Failed to open %s (%d): %s", OD_CLAMP_FILEPATH, error, strerror(error)); + ALOGW("Failed to open %s (%d): %s", OD_CLAMP_PATH, error, strerror(error)); } std::ofstream ollraperiod{OL_LRA_PERIOD_FILEPATH}; @@ -202,14 +212,15 @@ status_t registerVibratorService() { ALOGW("Failed to open %s (%d): %s", OL_LRA_PERIOD_FILEPATH, error, strerror(error)); } - if (!loadCalibrationData(lra_period)) { + if (!loadCalibrationData(short_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(odclamp), std::move(ollraperiod), lra_period); + std::move(lrawaveshape), std::move(odclamp), std::move(ollraperiod), + short_lra_period); return vibrator->registerAsService(); } |