Pong: vibrator: Improve amplitude handling
Revert back to our old way of handling timeoutMs. Signed-off-by: Abhay Singh Gill <abhaygill017@gmail.com> Signed-off-by: Ghosuto <clash.raja10@gmail.com>
This commit is contained in:
committed by
Ghosuto
parent
c1cfcb781d
commit
1d906b6ffd
@@ -71,7 +71,6 @@ namespace vibrator {
|
||||
#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8)))
|
||||
|
||||
#define LED_DEVICE "/sys/class/leds/aw_vibrator"
|
||||
int32_t mTimeoutMs = 0;
|
||||
|
||||
InputFFDevice::InputFFDevice()
|
||||
{
|
||||
@@ -347,6 +346,7 @@ LedVibratorDevice::LedVibratorDevice() {
|
||||
}
|
||||
|
||||
mDetected = true;
|
||||
mTimeoutMs = 0;
|
||||
mLevel = 3;
|
||||
}
|
||||
|
||||
@@ -390,18 +390,36 @@ int LedVibratorDevice::write_value(const char *file, int value) {
|
||||
}
|
||||
|
||||
int LedVibratorDevice::on(int32_t timeoutMs) {
|
||||
char file[PATH_MAX];
|
||||
char value[32];
|
||||
int ret;
|
||||
|
||||
snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "duration");
|
||||
snprintf(value, sizeof(value), "%u\n", timeoutMs);
|
||||
ret = write_value(file, value);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
mTimeoutMs = timeoutMs;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
ALOGE("Failed to turn on vibrator ret: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LedVibratorDevice::setAmplitude(float amplitude) {
|
||||
int ret = 0;
|
||||
int gain = 0;
|
||||
|
||||
if (amplitude <= 0)
|
||||
return 0;
|
||||
|
||||
mLevel = amplitude * 3;
|
||||
|
||||
if (mTimeoutMs < 20) {
|
||||
gain = 4 + 4.6*mTimeoutMs;
|
||||
ret |= write_value(LED_DEVICE "/duration", mTimeoutMs);
|
||||
ret |= write_value(LED_DEVICE "/index", "1");
|
||||
ret |= write_value(LED_DEVICE "/loop", "0 0");
|
||||
ret |= write_value(LED_DEVICE "/vmax", "9408");
|
||||
@@ -409,7 +427,6 @@ int LedVibratorDevice::setAmplitude(float amplitude) {
|
||||
ret |= write_value(LED_DEVICE "/brightness", "1");
|
||||
} else if (mTimeoutMs < 40) {
|
||||
gain = 4 + 3.1*mTimeoutMs;
|
||||
ret |= write_value(LED_DEVICE "/duration", mTimeoutMs);
|
||||
ret |= write_value(LED_DEVICE "/index", "1");
|
||||
ret |= write_value(LED_DEVICE "/loop", "0 0");
|
||||
ret |= write_value(LED_DEVICE "/vmax", "9408");
|
||||
@@ -419,14 +436,12 @@ int LedVibratorDevice::setAmplitude(float amplitude) {
|
||||
gain = 4 + 2.5*mTimeoutMs;
|
||||
if (gain > 128)
|
||||
gain = 128; // 0x80 (Should never exceed this)
|
||||
ret |= write_value(LED_DEVICE "/duration", mTimeoutMs);
|
||||
ret |= write_value(LED_DEVICE "/index", "1");
|
||||
ret |= write_value(LED_DEVICE "/loop", "0 0");
|
||||
ret |= write_value(LED_DEVICE "/vmax", "9408");
|
||||
ret |= write_value(LED_DEVICE "/gain", gain);
|
||||
ret |= write_value(LED_DEVICE "/brightness", "1");
|
||||
} else {
|
||||
ret |= write_value(LED_DEVICE "/duration", mTimeoutMs);
|
||||
ret |= write_value(LED_DEVICE "/index", "4");
|
||||
ret |= write_value(LED_DEVICE "/vmax", "9408");
|
||||
ret |= write_value(LED_DEVICE "/gain", "0x7e");
|
||||
@@ -480,13 +495,11 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
|
||||
const std::shared_ptr<IVibratorCallback>& callback) {
|
||||
int ret;
|
||||
|
||||
mTimeoutMs = timeoutMs;
|
||||
|
||||
ALOGD("Vibrator on for timeoutMs: %d", mTimeoutMs);
|
||||
ALOGD("Vibrator on for timeoutMs: %d", timeoutMs);
|
||||
if (ledVib.mDetected)
|
||||
ret = ledVib.on(mTimeoutMs);
|
||||
ret = ledVib.on(timeoutMs);
|
||||
else
|
||||
ret = ff.on(mTimeoutMs);
|
||||
ret = ff.on(timeoutMs);
|
||||
|
||||
if (ret != 0)
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
@@ -494,7 +507,7 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
ALOGD("Starting on on another thread");
|
||||
usleep(mTimeoutMs * 1000);
|
||||
usleep(timeoutMs * 1000);
|
||||
ALOGD("Notifying on complete");
|
||||
if (!callback->onComplete().isOk()) {
|
||||
ALOGE("Failed to call onComplete");
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
int off();
|
||||
int setAmplitude(float amplitude);
|
||||
bool mDetected;
|
||||
int32_t mTimeoutMs;
|
||||
int32_t mLevel;
|
||||
int write_value(const char *file, const char *value);
|
||||
int write_value(const char *file, int value);
|
||||
|
||||
Reference in New Issue
Block a user