Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 517a16b9 authored by Koushik Dutta's avatar Koushik Dutta Committed by Gerrit Code Review
Browse files

Merge "minui: Add haptic feedback to virtual keys" into froyo

parents 9397e322 44bd4947
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }