2 * led_hw_brightness_mon.c
4 * This program monitors LED brightness level changes having its origin
5 * in hardware/firmware, i.e. outside of kernel control.
6 * A timestamp and brightness value is printed each time the brightness changes.
8 * Usage: led_hw_brightness_mon <device-name>
10 * <device-name> is the name of the LED class device to be monitored. Pressing
23 #include <linux/uleds.h>
25 int main(int argc
, char const *argv
[])
28 char brightness_file_path
[LED_MAX_NAME_SIZE
+ 11];
34 fprintf(stderr
, "Requires <device-name> argument\n");
38 snprintf(brightness_file_path
, LED_MAX_NAME_SIZE
,
39 "/sys/class/leds/%s/brightness_hw_changed", argv
[1]);
41 fd
= open(brightness_file_path
, O_RDONLY
);
43 printf("Failed to open %s file\n", brightness_file_path
);
48 * read may fail if no hw brightness change has occurred so far,
49 * but it is required to avoid spurious poll notifications in
52 read(fd
, buf
, sizeof(buf
));
55 pollfd
.events
= POLLPRI
;
58 ret
= poll(&pollfd
, 1, -1);
60 printf("Failed to poll %s file (%d)\n",
61 brightness_file_path
, ret
);
66 clock_gettime(CLOCK_MONOTONIC
, &ts
);
68 ret
= read(fd
, buf
, sizeof(buf
));
72 ret
= lseek(pollfd
.fd
, 0, SEEK_SET
);
74 printf("lseek failed (%d)\n", ret
);
78 printf("[%ld.%09ld] %d\n", ts
.tv_sec
, ts
.tv_nsec
, atoi(buf
));