sm7125-common: vibrator: Switch from 0-255 to 0.0f-1.0f range for amplitude

* This was missed when converting to AIDL
* Fixes strength control for effects

Change-Id: Iedcdbb455b67b9466a76e53ca9273cbcdcede059
fourteen-wip
SamarV-121 2 years ago committed by Simon1511
parent 115d7d8e1e
commit 672f520c90
  1. 22
      vibrator/Vibrator.cpp
  2. 6
      vibrator/Vibrator.h

@ -86,7 +86,7 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibrat
ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) { ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) {
ndk::ScopedAStatus status; ndk::ScopedAStatus status;
uint8_t amplitude; float amplitude;
uint32_t ms; uint32_t ms;
amplitude = strengthToAmplitude(strength, &status); amplitude = strengthToAmplitude(strength, &status);
@ -129,16 +129,14 @@ ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_retu
ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
uint32_t intensity; uint32_t intensity;
if (amplitude == 0) { if (amplitude <= 0.0f || amplitude > 1.0f) {
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
} }
LOG(DEBUG) << "Setting amplitude: " << (uint32_t)amplitude; LOG(DEBUG) << "Setting amplitude: " << amplitude;
intensity = amplitude * INTENSITY_MAX;
intensity = std::lround((amplitude - 1) * INTENSITY_MAX / 254.0);
if (intensity > INTENSITY_MAX) {
intensity = INTENSITY_MAX;
}
LOG(DEBUG) << "Setting intensity: " << intensity; LOG(DEBUG) << "Setting intensity: " << intensity;
return writeNode(VIBRATOR_TIMEOUT_PATH, intensity); return writeNode(VIBRATOR_TIMEOUT_PATH, intensity);
@ -240,16 +238,16 @@ ndk::ScopedAStatus Vibrator::activate(uint32_t timeoutMs) {
return writeNode(VIBRATOR_TIMEOUT_PATH, timeoutMs); return writeNode(VIBRATOR_TIMEOUT_PATH, timeoutMs);
} }
uint8_t Vibrator::strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status) { float Vibrator::strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status) {
*status = ndk::ScopedAStatus::ok(); *status = ndk::ScopedAStatus::ok();
switch (strength) { switch (strength) {
case EffectStrength::LIGHT: case EffectStrength::LIGHT:
return 64; return AMPLITUDE_LIGHT;
case EffectStrength::MEDIUM: case EffectStrength::MEDIUM:
return 128; return AMPLITUDE_MEDIUM;
case EffectStrength::STRONG: case EffectStrength::STRONG:
return 255; return AMPLITUDE_STRONG;
} }
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); *status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);

@ -12,6 +12,10 @@
#define INTENSITY_MAX 10000 #define INTENSITY_MAX 10000
#define INTENSITY_DEFAULT INTENSITY_MAX #define INTENSITY_DEFAULT INTENSITY_MAX
#define AMPLITUDE_LIGHT 0.25
#define AMPLITUDE_MEDIUM 0.5
#define AMPLITUDE_STRONG 1
#define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable" #define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable"
#define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity" #define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity"
@ -59,7 +63,7 @@ public:
private: private:
ndk::ScopedAStatus activate(uint32_t ms); ndk::ScopedAStatus activate(uint32_t ms);
static uint32_t effectToMs(Effect effect, ndk::ScopedAStatus* status); static uint32_t effectToMs(Effect effect, ndk::ScopedAStatus* status);
static uint8_t strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status); static float strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status);
bool mEnabled{false}; bool mEnabled{false};
bool mExternalControl{false}; bool mExternalControl{false};

Loading…
Cancel
Save