summaryrefslogtreecommitdiff
path: root/lights.c (plain)
blob: f0c1cb5f67ed0640286e575db2931c499e7b4f76
1#include <stdio.h>
2#include <unistd.h>
3#include <fcntl.h>
4#include <errno.h>
5#include <hardware/lights.h>
6#include <hardware/hardware.h>
7
8
9#define BACKLIGHT "/sys/class/backlight/aml-bl/brightness"
10static int set_light_backlight(struct light_device_t* dev,
11 struct light_state_t const* state)
12{
13 int nwr, ret, fd;
14 char value[20];
15 int light_level;
16 light_level =state->color&0xff;
17
18 fd = open(BACKLIGHT, O_RDWR);
19 nwr = sprintf(value, "%d\n", light_level);
20 ret = write(fd, value, nwr);
21 close(fd);
22
23 return ret;
24}
25
26static int open_lights(const struct hw_module_t* module, char const* name,
27 struct hw_device_t** device)
28{
29 int res = -EINVAL;
30 int (*set_light)(struct light_device_t* dev,
31 struct light_state_t const* state);
32
33 if (strcmp(LIGHT_ID_BACKLIGHT, name) == 0) {
34 struct light_device_t *dev = malloc(sizeof(struct light_device_t));
35 if (!dev) {
36 return res;
37 }
38
39 set_light = set_light_backlight;
40
41 memset(dev, 0, sizeof(*dev));
42 dev->common.tag = HARDWARE_DEVICE_TAG;
43 dev->common.version = 0;
44 dev->common.module = (struct hw_module_t*)module;
45 dev->common.close = NULL;
46 dev->set_light = set_light;
47
48 *device = (struct hw_device_t*)dev;
49 res = 0;
50 }
51 return res;
52}
53
54
55
56
57static struct hw_module_methods_t lights_module_methods = {
58 .open = open_lights,
59};
60const struct hw_module_t HAL_MODULE_INFO_SYM = {
61 .tag = HARDWARE_MODULE_TAG,
62 .version_major = 1,
63 .version_minor = 0,
64 .id = LIGHTS_HARDWARE_MODULE_ID,
65 .name = "lights Module",
66 .author = "",
67 .methods = &lights_module_methods,
68};
69
70
71