The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | #include <hardware/vibrator.h> |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <unistd.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <errno.h> |
| 7 | |
| 8 | #define THE_DEVICE "/sys/class/timed_output/vibrator/enable" |
| 9 | |
| 10 | static int sendit(int timeout_ms) |
| 11 | { |
| 12 | int nwr, ret, fd; |
| 13 | char value[20]; |
| 14 | |
| 15 | fd = open(THE_DEVICE, O_RDWR); |
| 16 | if(fd < 0) |
| 17 | return errno; |
| 18 | |
| 19 | nwr = sprintf(value, "%d\n", timeout_ms); |
| 20 | ret = write(fd, value, nwr); |
| 21 | |
| 22 | close(fd); |
| 23 | |
| 24 | return (ret == nwr) ? 0 : -1; |
| 25 | } |
| 26 | |
| 27 | int vibrator_on() |
| 28 | { |
| 29 | /* constant on, up to maximum allowed time */ |
| 30 | return sendit(-1); |
| 31 | } |
| 32 | |
| 33 | int vibrator_off() |
| 34 | { |
| 35 | return sendit(0); |
| 36 | } |