Refactor input device rumble support.
Change VibrationElement to fixed size array of uint8_t.
Move default amplitude handling to Java.
Address previous code review comments.
Bug: 136215622
Test: Connect game controller with rumble support and play game for
force feedback effect.
Change-Id: Ife7294bd829a2ca88354ffa09f523e43a1bc26dc
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 8f34e8a..cde977f 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -61,6 +61,9 @@
// v4l2 devices go directly into /dev
static const char* VIDEO_DEVICE_PATH = "/dev";
+static constexpr size_t FF_STRONG_MAGNITUDE_CHANNEL_IDX = 0;
+static constexpr size_t FF_WEAK_MAGNITUDE_CHANNEL_IDX = 1;
+
static inline const char* toString(bool value) {
return value ? "true" : "false";
}
@@ -834,8 +837,8 @@
effect.type = FF_RUMBLE;
effect.id = device->ffEffectId;
// evdev FF_RUMBLE effect only supports two channels of vibration.
- effect.u.rumble.strong_magnitude = element.getChannel(0);
- effect.u.rumble.weak_magnitude = element.getChannel(1);
+ effect.u.rumble.strong_magnitude = element.getMagnitude(FF_STRONG_MAGNITUDE_CHANNEL_IDX);
+ effect.u.rumble.weak_magnitude = element.getMagnitude(FF_WEAK_MAGNITUDE_CHANNEL_IDX);
effect.replay.length = element.duration.count();
effect.replay.delay = 0;
if (ioctl(device->fd, EVIOCSFF, &effect)) {