2 * Copyright (C) 2013 Paul Kocialkowski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <linux/ioctl.h>
25 #include <linux/input.h>
27 #define LOG_TAG "piranha_sensors"
28 #include <utils/Log.h>
30 #include "piranha_sensors.h"
32 int64_t input_timestamp(struct input_event *event)
37 return event->time.tv_sec*1000000000LL + event->time.tv_usec*1000;
40 int input_open(char *name)
45 char input_name[80] = { 0 };
53 d = opendir("/dev/input");
57 while ((di = readdir(d))) {
58 if (di == NULL || strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0)
61 snprintf(path, PATH_MAX, "/dev/input/%s", di->d_name);
62 fd = open(path, O_RDONLY | O_NONBLOCK);
66 rc = ioctl(fd, EVIOCGNAME(sizeof(input_name) - 1), &input_name);
70 if (strcmp(input_name, name) == 0)
79 int sysfs_path_prefix(char *name, char *path_prefix)
84 char input_name[80] = { 0 };
88 if (name == NULL || path_prefix == NULL)
91 d = opendir("/sys/class/input");
95 while ((di = readdir(d))) {
96 if (di == NULL || strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0)
99 snprintf(path, PATH_MAX, "/sys/class/input/%s/name", di->d_name);
101 fd = open(path, O_RDONLY);
105 read(fd, &input_name, sizeof(input_name));
108 if (strncmp(input_name, name, strlen(name)) == 0) {
109 snprintf(path_prefix, PATH_MAX, "/sys/class/input/%s", di->d_name);