summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFenglin Wu <fenglinw@codeaurora.org>2020-04-09 13:58:32 +0800
committerFenglin Wu <fenglinw@codeaurora.org>2020-04-25 09:30:21 +0800
commit6dc9ddef7d444b47327fda77dc77cdb025777723 (patch)
treef900abb3ee77833dbd738b746f4af75d5c676426
parentadda2bc784be8d94c5267ce0efa91a5e874549ab (diff)
vibrator: add support to play effect data stream
Currently, only effectId is given to the input device and the effect details need to be defined in the device driver. And an option to define the effect in the HAL with a data structure contains data stream and play-rate information. When playing an effect, the play() calling will give corresponding effect data structure to the device driver for playing. Change-Id: I36d4dc47dadce63a29e39cdb94367c2e1ce0dda8
-rw-r--r--1.2/Android.bp13
-rw-r--r--1.2/Vibrator.cpp20
-rw-r--r--1.2/effect.cpp77
-rw-r--r--1.2/effect.h43
4 files changed, 152 insertions, 1 deletions
diff --git a/1.2/Android.bp b/1.2/Android.bp
index 61d1667..0118073 100644
--- a/1.2/Android.bp
+++ b/1.2/Android.bp
@@ -2,6 +2,18 @@ Common_CFlags = ["-Wall"]
Common_CFlags += ["-Werror"]
cc_library_shared {
+ name: "libqtivibratoreffect",
+ vendor: true,
+ cflags: Common_CFlags,
+ srcs: ["effect.cpp"],
+ shared_libs: [
+ "libcutils",
+ "libutils",
+ ],
+ export_include_dirs: ["."]
+}
+
+cc_library_shared {
name: "vendor.qti.hardware.vibrator@1.2-impl",
vendor: true,
cflags: Common_CFlags,
@@ -14,6 +26,7 @@ cc_library_shared {
"libutils",
"libhardware",
"libhidlbase",
+ "libqtivibratoreffect",
"android.hardware.vibrator@1.0",
"android.hardware.vibrator@1.1",
"android.hardware.vibrator@1.2",
diff --git a/1.2/Vibrator.cpp b/1.2/Vibrator.cpp
index 1732a55..b699704 100644
--- a/1.2/Vibrator.cpp
+++ b/1.2/Vibrator.cpp
@@ -39,6 +39,9 @@
#include <sys/ioctl.h>
#include "Vibrator_1_2.h"
+#ifdef USE_EFFECT_STREAM
+#include "effect.h"
+#endif
namespace android {
namespace hardware {
@@ -138,6 +141,9 @@ Return<Status> InputFFDevice::play(int effectId, uint32_t timeoutMs, long *playL
#define CUSTOM_DATA_LEN 3
int16_t data[CUSTOM_DATA_LEN] = {0, 0, 0};
int ret;
+#ifdef USE_EFFECT_STREAM
+ const struct effect_stream *stream;
+#endif
/* For QMAA compliance, return OK even if vibrator device doesn't exist */
if (mVibraFd == INVALID_VALUE) {
@@ -164,6 +170,13 @@ Return<Status> InputFFDevice::play(int effectId, uint32_t timeoutMs, long *playL
effect.u.periodic.magnitude = mCurrMagnitude;
effect.u.periodic.custom_data = data;
effect.u.periodic.custom_len = sizeof(int16_t) * CUSTOM_DATA_LEN;
+#ifdef USE_EFFECT_STREAM
+ stream = get_effect_stream(effectId);
+ if (stream != NULL) {
+ effect.u.periodic.custom_data = (int16_t *)stream;
+ effect.u.periodic.custom_len = sizeof(*stream);
+ }
+#endif
} else {
effect.type = FF_CONSTANT;
effect.u.constant.level = mCurrMagnitude;
@@ -180,8 +193,13 @@ Return<Status> InputFFDevice::play(int effectId, uint32_t timeoutMs, long *playL
}
mCurrAppId = effect.id;
- if (effectId != INVALID_VALUE && playLengthMs != NULL)
+ if (effectId != INVALID_VALUE && playLengthMs != NULL) {
*playLengthMs = data[1] * 1000 + data[2];
+#ifdef USE_EFFECT_STREAM
+ if (stream != NULL && stream->play_rate_hz != 0)
+ *playLengthMs = ((stream->length * 1000) / stream->play_rate_hz) + 1;
+#endif
+ }
play.value = 1;
play.type = EV_FF;
diff --git a/1.2/effect.cpp b/1.2/effect.cpp
new file mode 100644
index 0000000..ea8cd78
--- /dev/null
+++ b/1.2/effect.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "effect.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
+/* ~170 HZ sine waveform */
+static const int8_t effect_0[] = {
+ 17, 34, 50, 65, 79, 92, 103, 112, 119, 124,
+ 127, 127, 126, 122, 116, 108, 98, 86, 73, 58,
+ 42, 26, 9, -8, -25, -41, -57, -72, -85, -97,
+ -108, -116, -122, -126, -127, -127, -125, -120,
+ -113, -104, -93, -80, -66, -51, -35, -18, -1,
+};
+
+static const int8_t effect_1[] = {
+ -1, -18, -35, -51, -66, -80, -93, -104, -113,
+ -120, -125, -127, -127, -126, -122, -116, -108,
+ -97, -85, -72, -57, -41, -25, -8, 9, 26, 42,
+ 58, 73, 86, 98, 108, 116, 122, 126, 127, 127,
+ 124, 119, 112, 103, 92, 79, 65, 50, 34, 17,
+};
+
+static const struct effect_stream effects[] = {
+ {
+ .effect_id = 0,
+ .data = effect_0,
+ .length = ARRAY_SIZE(effect_0),
+ .play_rate_hz = 8000,
+ },
+
+ {
+ .effect_id = 1,
+ .data = effect_1,
+ .length = ARRAY_SIZE(effect_1),
+ .play_rate_hz = 8000,
+ },
+};
+
+const struct effect_stream *get_effect_stream(uint32_t effect_id)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(effects); i++) {
+ if (effect_id == effects[i].effect_id)
+ return &effects[i];
+ }
+
+ return NULL;
+}
diff --git a/1.2/effect.h b/1.2/effect.h
new file mode 100644
index 0000000..a588e22
--- /dev/null
+++ b/1.2/effect.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef QTI_VIBRATOR_EFFECT_STREAM_H
+#define QTI_VIBRATOR_EFFECT_STREAM_H
+#include <sys/types.h>
+
+struct effect_stream {
+ uint32_t effect_id;
+ uint32_t length;
+ uint32_t play_rate_hz;
+ const int8_t *data;
+};
+
+const struct effect_stream *get_effect_stream(uint32_t effect_id);
+
+#endif