From: SamarV-121 Date: Mon, 8 May 2023 10:47:17 +0000 (+0530) Subject: vibrator: Add support for duration based amplitude control X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e37874d4a34f8ffa4238b6adcddc3794c165b47f;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung.git vibrator: Add support for duration based amplitude control * Similar to what samsung is doing on devices without hardware intensity control. * Add `$(call soong_config_set,samsungVibratorVars,duration_amplitude,true)` in BoardConfig.mk to enable. Change-Id: I87a767e00363c36f8bd4d61cb6dd23b5c033a3d3 --- diff --git a/aidl/vibrator/Android.bp b/aidl/vibrator/Android.bp index 0a255a1..bcd6a66 100644 --- a/aidl/vibrator/Android.bp +++ b/aidl/vibrator/Android.bp @@ -1,11 +1,31 @@ // -// Copyright (C) 2021 The LineageOS Project +// Copyright (C) 2021-2023 The LineageOS Project // // SPDX-License-Identifier: Apache-2.0 // +soong_config_module_type { + name: "samsung_vibrator", + module_type: "cc_defaults", + config_namespace: "samsungVibratorVars", + bool_variables: ["duration_amplitude"], + properties: ["cflags"], +} + +samsung_vibrator { + name: "samsung_vibrator_defaults", + soong_config_variables: { + duration_amplitude: { + cflags: [ + "-DVIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL", + ], + }, + }, +} + cc_binary { name: "android.hardware.vibrator-service.samsung", + defaults: ["samsung_vibrator_defaults"], relative_install_path: "hw", init_rc: ["android.hardware.vibrator-service.samsung.rc"], vintf_fragments: ["android.hardware.vibrator-service.samsung.xml"], diff --git a/aidl/vibrator/Vibrator.cpp b/aidl/vibrator/Vibrator.cpp index c2159a3..6818f77 100644 --- a/aidl/vibrator/Vibrator.cpp +++ b/aidl/vibrator/Vibrator.cpp @@ -31,6 +31,14 @@ static std::map CP_TRIGGER_EFFECTS { { Effect::TICK, 50 } }; +#ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL +static std::map DURATION_AMPLITUDE = { + { EffectStrength::LIGHT, DURATION_AMPLITUDE_LIGHT }, + { EffectStrength::MEDIUM, DURATION_AMPLITUDE_MEDIUM }, + { EffectStrength::STRONG, DURATION_AMPLITUDE_STRONG } +}; +#endif + /* * Write value to path and close file. */ @@ -73,10 +81,12 @@ ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS | IVibrator::CAP_ALWAYS_ON_CONTROL*/; - if (mHasTimedOutIntensity) { - *_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL | - IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL; - } +#ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL + *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL; +#else + if (mHasTimedOutIntensity) + *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL; +#endif return ndk::ScopedAStatus::ok(); } @@ -91,6 +101,10 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr= 0.5) { + return DURATION_AMPLITUDE_MEDIUM; + } + + return DURATION_AMPLITUDE_LIGHT; +} +#endif + } // namespace vibrator } // namespace hardware } // namespace android diff --git a/aidl/vibrator/Vibrator.h b/aidl/vibrator/Vibrator.h index db91b98..09e88d3 100644 --- a/aidl/vibrator/Vibrator.h +++ b/aidl/vibrator/Vibrator.h @@ -16,6 +16,12 @@ #define AMPLITUDE_MEDIUM 0.5 #define AMPLITUDE_STRONG 1 +#ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL +#define DURATION_AMPLITUDE_LIGHT 0.65 +#define DURATION_AMPLITUDE_MEDIUM 0.8 +#define DURATION_AMPLITUDE_STRONG 1 +#endif + #define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable" #define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity" #define VIBRATOR_CP_TRIGGER_PATH "/sys/class/timed_output/vibrator/cp_trigger_index" @@ -66,6 +72,11 @@ private: uint32_t effectToMs(Effect effect, ndk::ScopedAStatus* status); static float strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status); +#ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL + static float durationAmplitude(float amplitude); + float mDurationAmplitude; +#endif + bool mEnabled{false}; bool mExternalControl{false}; std::mutex mMutex;