diff options
Diffstat (limited to 'vibrator/vibrator.c')
-rw-r--r-- | vibrator/vibrator.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/vibrator/vibrator.c b/vibrator/vibrator.c new file mode 100644 index 0000000..fcea21c --- /dev/null +++ b/vibrator/vibrator.c @@ -0,0 +1,36 @@ +#include <hardware/vibrator.h> + +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +#define THE_DEVICE "/sys/class/timed_output/vibrator/enable" + +static int sendit(int timeout_ms) +{ + int nwr, ret, fd; + char value[20]; + + fd = open(THE_DEVICE, O_RDWR); + if(fd < 0) + return errno; + + nwr = sprintf(value, "%d\n", timeout_ms); + ret = write(fd, value, nwr); + + close(fd); + + return (ret == nwr) ? 0 : -1; +} + +int vibrator_on() +{ + /* constant on, up to maximum allowed time */ + return sendit(-1); +} + +int vibrator_off() +{ + return sendit(0); +} |