The Android Open Source Project | 52d4c30 | 2009-03-03 19:29:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Vibrating notification device. |
| 5 | */ |
| 6 | #include "Common.h" |
| 7 | |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | #include <ctype.h> |
| 11 | |
| 12 | #include <unistd.h> |
| 13 | |
| 14 | |
| 15 | /* |
| 16 | * The user will write a decimal integer indicating the time, in milliseconds, |
| 17 | * that the device should vibrate. In current usage, this is either -1 |
| 18 | * (meaning vibrate forever) or 0 (don't vibrate). |
| 19 | */ |
| 20 | static ssize_t writeVibrator(FakeDev* dev, int fd, const void* buf, |
| 21 | size_t count) |
| 22 | { |
| 23 | if (count == 2 && memcmp(buf, "0\n", 2) == 0) { |
| 24 | wsEnableVibration(0); |
| 25 | } else if (count == 3 && memcmp(buf, "-1\n", 3) == 0) { |
| 26 | wsEnableVibration(1); |
| 27 | } else { |
| 28 | wsLog("%s: got %d bytes: '%*s'\n", |
| 29 | dev->debugName, count, count, (const char*) buf); |
| 30 | } |
| 31 | |
| 32 | return count; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * Open the vibration control device. |
| 37 | */ |
| 38 | FakeDev* wsOpenDevVibrator(const char* pathName, int flags) |
| 39 | { |
| 40 | FakeDev* newDev = wsCreateFakeDev(pathName); |
| 41 | if (newDev != NULL) { |
| 42 | newDev->write = writeVibrator; |
| 43 | } |
| 44 | |
| 45 | return newDev; |
| 46 | } |
| 47 | |