The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | #include <hardware/flashlight.h> |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <unistd.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <errno.h> |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 7 | #include "qemu.h" |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 8 | |
| 9 | #define FLASHLIGHT "/sys/class/leds/spotlight/brightness" |
| 10 | #define CAMERA_FLASH "/sys/class/timed_output/flash/enable" |
| 11 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 12 | #ifdef QEMU_HARDWARE |
| 13 | int qemu_get_flashlight_enabled() |
| 14 | { |
| 15 | char question[256]; |
| 16 | char answer[256]; |
| 17 | int len; |
| 18 | |
| 19 | len = qemu_command_format( question, sizeof question, |
| 20 | "get_flashlight_enabled" ); |
| 21 | |
| 22 | len = qemu_control_query( question, len, answer, sizeof answer ); |
| 23 | if (len <= 0) return 0; |
| 24 | |
| 25 | /* we expect an answer of 0 or 1 */ |
| 26 | return (answer[0] == '1'); |
| 27 | } |
| 28 | |
| 29 | int qemu_set_flashlight_enabled(int on) |
| 30 | { |
| 31 | return qemu_control_command( "set_flashlight_enabled:%d", on ); |
| 32 | } |
| 33 | |
| 34 | int qemu_enable_camera_flash(int milliseconds) |
| 35 | { |
| 36 | return qemu_control_command( "enable_camera_flash:%d", milliseconds ); |
| 37 | } |
| 38 | #endif |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | |
| 40 | int get_flashlight_enabled() |
| 41 | { |
| 42 | int fd; |
| 43 | int ret = 0; |
| 44 | char value; |
| 45 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 46 | QEMU_FALLBACK(get_flashlight_enabled()); |
| 47 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | fd = open(FLASHLIGHT, O_RDONLY); |
| 49 | if(fd && read(fd, &value, 1) == 1) { |
| 50 | ret = (value == '1'); |
| 51 | } |
| 52 | close(fd); |
| 53 | |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | int set_flashlight_enabled(int on) |
| 58 | { |
| 59 | int nwr, ret, fd; |
| 60 | char value[20]; |
| 61 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 62 | QEMU_FALLBACK(set_flashlight_enabled(on)); |
| 63 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | fd = open(FLASHLIGHT, O_RDWR); |
| 65 | if(fd < 0) |
| 66 | return errno; |
| 67 | |
| 68 | nwr = sprintf(value, "%d\n", !!on); |
| 69 | ret = write(fd, value, nwr); |
| 70 | |
| 71 | close(fd); |
| 72 | |
| 73 | return (ret == nwr) ? 0 : -1; |
| 74 | } |
| 75 | |
| 76 | int enable_camera_flash(int milliseconds) |
| 77 | { |
| 78 | int nwr, ret, fd; |
| 79 | char value[20]; |
| 80 | |
The Android Open Source Project | 51704be | 2008-12-17 18:05:50 -0800 | [diff] [blame^] | 81 | QEMU_FALLBACK(enable_camera_flash(milliseconds)); |
| 82 | |
The Android Open Source Project | d6054a3 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 83 | fd = open(CAMERA_FLASH, O_RDWR); |
| 84 | if(fd < 0) |
| 85 | return errno; |
| 86 | |
| 87 | nwr = sprintf(value, "%d\n", milliseconds); |
| 88 | ret = write(fd, value, nwr); |
| 89 | |
| 90 | close(fd); |
| 91 | |
| 92 | return (ret == nwr) ? 0 : -1; |
| 93 | } |