summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/hardware_legacy/vibrator.h7
-rw-r--r--vibrator/vibrator.c17
2 files changed, 24 insertions, 0 deletions
diff --git a/include/hardware_legacy/vibrator.h b/include/hardware_legacy/vibrator.h
index 15fd942..7994f62 100644
--- a/include/hardware_legacy/vibrator.h
+++ b/include/hardware_legacy/vibrator.h
@@ -22,6 +22,13 @@ extern "C" {
#endif
/**
+ * Return whether the device has a vibrator.
+ *
+ * @return 1 if a vibrator exists, 0 if it doesn't.
+ */
+int vibrator_exists();
+
+/**
* Turn on vibrator
*
* @param timeout_ms number of milliseconds to vibrate
diff --git a/vibrator/vibrator.c b/vibrator/vibrator.c
index 22cc506..f946ce1 100644
--- a/vibrator/vibrator.c
+++ b/vibrator/vibrator.c
@@ -23,6 +23,23 @@
#define THE_DEVICE "/sys/class/timed_output/vibrator/enable"
+int vibrator_exists()
+{
+ int fd;
+
+#ifdef QEMU_HARDWARE
+ if (qemu_check()) {
+ return 1;
+ }
+#endif
+
+ fd = open(THE_DEVICE, O_RDWR);
+ if(fd < 0)
+ return 0;
+ close(fd);
+ return 1;
+}
+
static int sendit(int timeout_ms)
{
int nwr, ret, fd;