4 * This program creates a new userspace LED class device and monitors it. A
5 * timestamp and brightness value is printed each time the brightness changes.
7 * Usage: uledmon <device-name>
9 * <device-name> is the name of the LED class device to be created. Pressing
19 #include <linux/uleds.h>
21 int main(int argc
, char const *argv
[])
23 struct uleds_user_dev uleds_dev
;
29 fprintf(stderr
, "Requires <device-name> argument\n");
33 strncpy(uleds_dev
.name
, argv
[1], LED_MAX_NAME_SIZE
);
34 uleds_dev
.max_brightness
= 100;
36 fd
= open("/dev/uleds", O_RDWR
);
38 perror("Failed to open /dev/uleds");
42 ret
= write(fd
, &uleds_dev
, sizeof(uleds_dev
));
44 perror("Failed to write to /dev/uleds");
50 ret
= read(fd
, &brightness
, sizeof(brightness
));
52 perror("Failed to read from /dev/uleds");
56 clock_gettime(CLOCK_MONOTONIC
, &ts
);
57 printf("[%ld.%09ld] %u\n", ts
.tv_sec
, ts
.tv_nsec
, brightness
);