Support combined vibration effects with input device.
Support combined vibration effects with multi-channel FF effect input
device.
Bug: 161629089
Test: atest InputDeviceVibratorTest
Change-Id: I566f6cdd601f716b34c2f70e3705340ef8906897
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index ffd8bf2..6cce8ec 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -101,10 +101,14 @@
virtual void requestRefreshConfiguration(uint32_t changes) = 0;
/* Controls the vibrator of a particular input device. */
- virtual void vibrate(int32_t deviceId, const std::vector<VibrationElement>& pattern,
- ssize_t repeat, int32_t token) = 0;
+ virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
+ int32_t token) = 0;
virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
+ virtual bool isVibrating(int32_t deviceId) = 0;
+
+ virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
+
/* Return true if the device can send input events to the specified display. */
virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
};
diff --git a/services/inputflinger/include/VibrationElement.h b/services/inputflinger/include/VibrationElement.h
index b60ffac..736041e 100644
--- a/services/inputflinger/include/VibrationElement.h
+++ b/services/inputflinger/include/VibrationElement.h
@@ -21,6 +21,7 @@
#include <chrono>
#include <cstdint>
#include <string>
+#include <vector>
namespace android {
@@ -32,13 +33,43 @@
struct VibrationElement {
std::chrono::milliseconds duration;
// Channel amplitude range 0-255.
- std::array<uint8_t, CHANNEL_SIZE> channels = {0, 0};
+ std::vector<std::pair<int32_t /*vibratorId*/, uint8_t /*amplitude*/>> channels;
+
+ explicit VibrationElement(size_t channelNum);
+
+ VibrationElement(const VibrationElement& other);
+
+ bool operator==(const VibrationElement& other) const;
+
+ bool operator!=(const VibrationElement& other) const;
+
+ void addChannel(int32_t vibratorId, uint8_t amplitude);
const std::string toString() const;
- uint16_t getMagnitude(size_t channelIndex) const;
+
+ uint16_t getMagnitude(int32_t vibratorId) const;
+
bool isOn() const;
};
+/*
+ * Describes a sequence of rumble effect
+ */
+struct VibrationSequence {
+ // Pattern of vibration elements
+ std::vector<VibrationElement> pattern;
+
+ explicit VibrationSequence(size_t length);
+
+ void operator=(const VibrationSequence& other);
+
+ bool operator==(const VibrationSequence& other) const;
+
+ void addElement(VibrationElement element);
+
+ const std::string toString() const;
+};
+
} // namespace android
#endif // _VIBRATION_ELEMENT_H