summaryrefslogtreecommitdiff
path: root/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/inputflinger/reader/mapper/VibratorInputMapper.cpp')
-rw-r--r--services/inputflinger/reader/mapper/VibratorInputMapper.cpp59
1 files changed, 39 insertions, 20 deletions
diff --git a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
index 7665680feb..3df6f36db5 100644
--- a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
@@ -21,7 +21,7 @@
namespace android {
VibratorInputMapper::VibratorInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mVibrating(false) {}
+ : InputMapper(deviceContext), mVibrating(false), mSequence(0) {}
VibratorInputMapper::~VibratorInputMapper() {}
@@ -39,27 +39,22 @@ void VibratorInputMapper::process(const RawEvent* rawEvent) {
// TODO: Handle FF_STATUS, although it does not seem to be widely supported.
}
-void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+void VibratorInputMapper::vibrate(const VibrationSequence& sequence, ssize_t repeat,
int32_t token) {
#if DEBUG_VIBRATOR
- std::string patternStr;
- for (size_t i = 0; i < patternSize; i++) {
- if (i != 0) {
- patternStr += ", ";
- }
- patternStr += StringPrintf("%" PRId64, pattern[i]);
- }
ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", getDeviceId(),
- patternStr.c_str(), repeat, token);
+ sequence.toString().c_str(), repeat, token);
#endif
mVibrating = true;
- memcpy(mPattern, pattern, patternSize * sizeof(nsecs_t));
- mPatternSize = patternSize;
+ mSequence = sequence;
mRepeat = repeat;
mToken = token;
mIndex = -1;
+ // Request InputReader to notify InputManagerService for vibration started.
+ NotifyVibratorStateArgs args(getContext()->getNextId(), systemTime(), getDeviceId(), true);
+ getListener()->notifyVibratorState(&args);
nextStep();
}
@@ -73,6 +68,14 @@ void VibratorInputMapper::cancelVibrate(int32_t token) {
}
}
+bool VibratorInputMapper::isVibrating() {
+ return mVibrating;
+}
+
+std::vector<int32_t> VibratorInputMapper::getVibratorIds() {
+ return getDeviceContext().getVibratorIds();
+}
+
void VibratorInputMapper::timeoutExpired(nsecs_t when) {
if (mVibrating) {
if (when >= mNextStepTime) {
@@ -84,8 +87,11 @@ void VibratorInputMapper::timeoutExpired(nsecs_t when) {
}
void VibratorInputMapper::nextStep() {
+#if DEBUG_VIBRATOR
+ ALOGD("nextStep: index=%d, vibrate deviceId=%d", (int)mIndex, getDeviceId());
+#endif
mIndex += 1;
- if (size_t(mIndex) >= mPatternSize) {
+ if (size_t(mIndex) >= mSequence.pattern.size()) {
if (mRepeat < 0) {
// We are done.
stopVibrating();
@@ -94,13 +100,14 @@ void VibratorInputMapper::nextStep() {
mIndex = mRepeat;
}
- bool vibratorOn = mIndex & 1;
- nsecs_t duration = mPattern[mIndex];
- if (vibratorOn) {
+ const VibrationElement& element = mSequence.pattern[mIndex];
+ if (element.isOn()) {
#if DEBUG_VIBRATOR
- ALOGD("nextStep: sending vibrate deviceId=%d, duration=%" PRId64, getDeviceId(), duration);
+ std::string description = element.toString();
+ ALOGD("nextStep: sending vibrate deviceId=%d, element=%s", getDeviceId(),
+ description.c_str());
#endif
- getDeviceContext().vibrate(duration);
+ getDeviceContext().vibrate(element);
} else {
#if DEBUG_VIBRATOR
ALOGD("nextStep: sending cancel vibrate deviceId=%d", getDeviceId());
@@ -108,10 +115,12 @@ void VibratorInputMapper::nextStep() {
getDeviceContext().cancelVibrate();
}
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
- mNextStepTime = now + duration;
+ std::chrono::nanoseconds duration =
+ std::chrono::duration_cast<std::chrono::nanoseconds>(element.duration);
+ mNextStepTime = now + duration.count();
getContext()->requestTimeoutAtTime(mNextStepTime);
#if DEBUG_VIBRATOR
- ALOGD("nextStep: scheduled timeout in %0.3fms", duration * 0.000001f);
+ ALOGD("nextStep: scheduled timeout in %lldms", element.duration.count());
#endif
}
@@ -121,11 +130,21 @@ void VibratorInputMapper::stopVibrating() {
ALOGD("stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId());
#endif
getDeviceContext().cancelVibrate();
+
+ // Request InputReader to notify InputManagerService for vibration complete.
+ NotifyVibratorStateArgs args(getContext()->getNextId(), systemTime(), getDeviceId(), false);
+ getListener()->notifyVibratorState(&args);
}
void VibratorInputMapper::dump(std::string& dump) {
dump += INDENT2 "Vibrator Input Mapper:\n";
dump += StringPrintf(INDENT3 "Vibrating: %s\n", toString(mVibrating));
+ if (mVibrating) {
+ dump += INDENT3 "Pattern: ";
+ dump += mSequence.toString();
+ dump += "\n";
+ dump += StringPrintf(INDENT3 "Repeat Index: %zd\n", mRepeat);
+ }
}
} // namespace android