blob: b736f75194bc7a3b87896674733e222568a976a5 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001/*
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 */
20static 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 */
38FakeDev* 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