|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 The LineageOS Project |
|
|
|
* Copyright (C) 2021-2023 The LineageOS Project |
|
|
|
* |
|
|
|
* |
|
|
|
* SPDX-License-Identifier: Apache-2.0 |
|
|
|
* SPDX-License-Identifier: Apache-2.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -101,7 +101,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; |
|
|
|
uint32_t amplitude = strengthToAmplitude(strength, &status); |
|
|
|
float amplitude = strengthToAmplitude(strength, &status); |
|
|
|
uint32_t ms = 1000; |
|
|
|
uint32_t ms = 1000; |
|
|
|
|
|
|
|
|
|
|
|
if (!status.isOk()) |
|
|
|
if (!status.isOk()) |
|
|
@ -152,20 +152,13 @@ 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 = std::lround((amplitude - 1) * INTENSITY_MAX / 254.0); |
|
|
|
intensity = amplitude * INTENSITY_MAX; |
|
|
|
if (intensity > INTENSITY_MAX) { |
|
|
|
|
|
|
|
intensity = INTENSITY_MAX; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (intensity == 0) { |
|
|
|
|
|
|
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG(DEBUG) << "Setting intensity: " << intensity; |
|
|
|
LOG(DEBUG) << "Setting intensity: " << intensity; |
|
|
|
|
|
|
|
|
|
|
@ -265,16 +258,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); |
|
|
|