|
|
@ -11,6 +11,7 @@ |
|
|
|
#include <cmath> |
|
|
|
#include <cmath> |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
#include <map> |
|
|
|
#include <thread> |
|
|
|
#include <thread> |
|
|
|
|
|
|
|
|
|
|
|
namespace aidl { |
|
|
|
namespace aidl { |
|
|
@ -18,6 +19,14 @@ namespace android { |
|
|
|
namespace hardware { |
|
|
|
namespace hardware { |
|
|
|
namespace vibrator { |
|
|
|
namespace vibrator { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static std::map<Effect, int> CP_TRIGGER_EFFECTS { |
|
|
|
|
|
|
|
{ Effect::CLICK, 10 }, |
|
|
|
|
|
|
|
{ Effect::DOUBLE_CLICK, 14 }, |
|
|
|
|
|
|
|
{ Effect::HEAVY_CLICK, 23 }, |
|
|
|
|
|
|
|
{ Effect::TEXTURE_TICK, 50 }, |
|
|
|
|
|
|
|
{ Effect::TICK, 50 } |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Write value to path and close file. |
|
|
|
* Write value to path and close file. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -48,6 +57,7 @@ static bool nodeExists(const std::string& path) { |
|
|
|
Vibrator::Vibrator() { |
|
|
|
Vibrator::Vibrator() { |
|
|
|
mIsTimedOutVibrator = nodeExists(VIBRATOR_TIMEOUT_PATH); |
|
|
|
mIsTimedOutVibrator = nodeExists(VIBRATOR_TIMEOUT_PATH); |
|
|
|
mHasTimedOutIntensity = nodeExists(VIBRATOR_INTENSITY_PATH); |
|
|
|
mHasTimedOutIntensity = nodeExists(VIBRATOR_INTENSITY_PATH); |
|
|
|
|
|
|
|
mHasTimedOutEffect = nodeExists(VIBRATOR_CP_TRIGGER_PATH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { |
|
|
|
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { |
|
|
@ -68,13 +78,18 @@ ndk::ScopedAStatus Vibrator::off() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) { |
|
|
|
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) { |
|
|
|
ndk::ScopedAStatus status = activate(timeoutMs); |
|
|
|
ndk::ScopedAStatus status; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mHasTimedOutEffect) |
|
|
|
|
|
|
|
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear all effects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status = activate(timeoutMs); |
|
|
|
|
|
|
|
|
|
|
|
if (callback != nullptr) { |
|
|
|
if (callback != nullptr) { |
|
|
|
std::thread([=] { |
|
|
|
std::thread([=] { |
|
|
|
LOG(INFO) << "Starting on on another thread"; |
|
|
|
LOG(DEBUG) << "Starting on on another thread"; |
|
|
|
usleep(timeoutMs * 1000); |
|
|
|
usleep(timeoutMs * 1000); |
|
|
|
LOG(INFO) << "Notifying on complete"; |
|
|
|
LOG(DEBUG) << "Notifying on complete"; |
|
|
|
if (!callback->onComplete().isOk()) { |
|
|
|
if (!callback->onComplete().isOk()) { |
|
|
|
LOG(ERROR) << "Failed to call onComplete"; |
|
|
|
LOG(ERROR) << "Failed to call onComplete"; |
|
|
|
} |
|
|
|
} |
|
|
@ -86,26 +101,34 @@ 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; |
|
|
|
uint32_t amplitude = strengthToAmplitude(strength, &status); |
|
|
|
uint32_t ms; |
|
|
|
uint32_t ms = 1000; |
|
|
|
|
|
|
|
|
|
|
|
amplitude = strengthToAmplitude(strength, &status); |
|
|
|
if (!status.isOk()) |
|
|
|
if (!status.isOk()) { |
|
|
|
|
|
|
|
return status; |
|
|
|
return status; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
activate(0); |
|
|
|
setAmplitude(amplitude); |
|
|
|
setAmplitude(amplitude); |
|
|
|
|
|
|
|
|
|
|
|
ms = effectToMs(effect, &status); |
|
|
|
if (mHasTimedOutEffect && CP_TRIGGER_EFFECTS.find(effect) != CP_TRIGGER_EFFECTS.end()) { |
|
|
|
if (!status.isOk()) { |
|
|
|
writeNode(VIBRATOR_CP_TRIGGER_PATH, CP_TRIGGER_EFFECTS[effect]); |
|
|
|
return status; |
|
|
|
} else { |
|
|
|
|
|
|
|
if (mHasTimedOutEffect) |
|
|
|
|
|
|
|
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear previous effect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ms = effectToMs(effect, &status); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!status.isOk()) |
|
|
|
|
|
|
|
return status; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
status = activate(ms); |
|
|
|
status = activate(ms); |
|
|
|
|
|
|
|
|
|
|
|
if (callback != nullptr) { |
|
|
|
if (callback != nullptr) { |
|
|
|
std::thread([=] { |
|
|
|
std::thread([=] { |
|
|
|
LOG(INFO) << "Starting perform on another thread"; |
|
|
|
LOG(DEBUG) << "Starting perform on another thread"; |
|
|
|
usleep(ms * 1000); |
|
|
|
usleep(ms * 1000); |
|
|
|
LOG(INFO) << "Notifying perform complete"; |
|
|
|
LOG(DEBUG) << "Notifying perform complete"; |
|
|
|
callback->onComplete(); |
|
|
|
callback->onComplete(); |
|
|
|
}).detach(); |
|
|
|
}).detach(); |
|
|
|
} |
|
|
|
} |
|
|
@ -255,19 +278,18 @@ uint8_t Vibrator::strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatu |
|
|
|
|
|
|
|
|
|
|
|
uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { |
|
|
|
uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { |
|
|
|
*status = ndk::ScopedAStatus::ok(); |
|
|
|
*status = ndk::ScopedAStatus::ok(); |
|
|
|
|
|
|
|
|
|
|
|
switch (effect) { |
|
|
|
switch (effect) { |
|
|
|
case Effect::CLICK: |
|
|
|
case Effect::CLICK: |
|
|
|
return 20; |
|
|
|
return 10; |
|
|
|
case Effect::DOUBLE_CLICK: |
|
|
|
case Effect::DOUBLE_CLICK: |
|
|
|
return 25; |
|
|
|
return 15; |
|
|
|
case Effect::HEAVY_CLICK: |
|
|
|
|
|
|
|
return 30; |
|
|
|
|
|
|
|
case Effect::TICK: |
|
|
|
case Effect::TICK: |
|
|
|
case Effect::TEXTURE_TICK: |
|
|
|
case Effect::TEXTURE_TICK: |
|
|
|
case Effect::THUD: |
|
|
|
case Effect::THUD: |
|
|
|
case Effect::POP: |
|
|
|
case Effect::POP: |
|
|
|
return 15; |
|
|
|
return 5; |
|
|
|
|
|
|
|
case Effect::HEAVY_CLICK: |
|
|
|
|
|
|
|
return 10; |
|
|
|
case Effect::RINGTONE_1: |
|
|
|
case Effect::RINGTONE_1: |
|
|
|
case Effect::RINGTONE_2: |
|
|
|
case Effect::RINGTONE_2: |
|
|
|
case Effect::RINGTONE_3: |
|
|
|
case Effect::RINGTONE_3: |
|
|
@ -283,9 +305,8 @@ uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { |
|
|
|
case Effect::RINGTONE_13: |
|
|
|
case Effect::RINGTONE_13: |
|
|
|
case Effect::RINGTONE_14: |
|
|
|
case Effect::RINGTONE_14: |
|
|
|
case Effect::RINGTONE_15: |
|
|
|
case Effect::RINGTONE_15: |
|
|
|
return 300; |
|
|
|
return 30000; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
|
|
|
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|