From 44bd4947d29e3b4cab77e77ae184c1bbc3bef0db Mon Sep 17 00:00:00 2001 From: Christopher Lais Date: Sat, 27 Nov 2010 13:36:23 -0600 Subject: [PATCH] minui: Add haptic feedback to virtual keys Change-Id: Ibd9298513626092297bff83f4914b436c4ffbb3a --- minui/events.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/minui/events.c b/minui/events.c index 1a9bdea..25a6023 100644 --- a/minui/events.c +++ b/minui/events.c @@ -29,6 +29,9 @@ #define MAX_DEVICES 16 +#define VIBRATOR_TIMEOUT_FILE "/sys/class/timed_output/vibrator/enable" +#define VIBRATOR_TIME_MS 50 + enum { DOWN_NOT, DOWN_SENT, @@ -65,6 +68,26 @@ static inline int ABS(int x) { return x<0?-x:x; } +int vibrate(int timeout_ms) +{ + char str[20]; + int fd; + int ret; + + fd = open(VIBRATOR_TIMEOUT_FILE, O_WRONLY); + if (fd < 0) + return -1; + + ret = snprintf(str, sizeof(str), "%d", timeout_ms); + ret = write(fd, str, ret); + close(fd); + + if (ret < 0) + return -1; + + return 0; +} + /* Returns empty tokens */ static char *vk_strtok_r(char *str, const char *delim, char **save_str) { @@ -300,6 +323,8 @@ static int vk_modify(struct ev *e, struct input_event *ev) ev->type = EV_KEY; ev->code = e->vks[i].scancode; ev->value = 1; + + vibrate(VIBRATOR_TIME_MS); return 0; } }