summaryrefslogtreecommitdiff
path: root/flashlight/flashlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'flashlight/flashlight.c')
-rw-r--r--flashlight/flashlight.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/flashlight/flashlight.c b/flashlight/flashlight.c
new file mode 100644
index 00000000..028a1dcc
--- /dev/null
+++ b/flashlight/flashlight.c
@@ -0,0 +1,59 @@
+#include <hardware/flashlight.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define FLASHLIGHT "/sys/class/leds/spotlight/brightness"
+#define CAMERA_FLASH "/sys/class/timed_output/flash/enable"
+
+
+int get_flashlight_enabled()
+{
+ int fd;
+ int ret = 0;
+ char value;
+
+ fd = open(FLASHLIGHT, O_RDONLY);
+ if(fd && read(fd, &value, 1) == 1) {
+ ret = (value == '1');
+ }
+ close(fd);
+
+ return ret;
+}
+
+int set_flashlight_enabled(int on)
+{
+ int nwr, ret, fd;
+ char value[20];
+
+ fd = open(FLASHLIGHT, O_RDWR);
+ if(fd < 0)
+ return errno;
+
+ nwr = sprintf(value, "%d\n", !!on);
+ ret = write(fd, value, nwr);
+
+ close(fd);
+
+ return (ret == nwr) ? 0 : -1;
+}
+
+int enable_camera_flash(int milliseconds)
+{
+ int nwr, ret, fd;
+ char value[20];
+
+ fd = open(CAMERA_FLASH, O_RDWR);
+ if(fd < 0)
+ return errno;
+
+ nwr = sprintf(value, "%d\n", milliseconds);
+ ret = write(fd, value, nwr);
+
+ close(fd);
+
+ return (ret == nwr) ? 0 : -1;
+}