4 The uleds driver supports userspace LEDs. This can be useful for testing
5 triggers and can also be used to implement virtual LEDs.
11 When the driver is loaded, a character device is created at /dev/uleds. To
12 create a new LED class device, open /dev/uleds and write a uleds_user_dev
13 structure to it (found in kernel public header file linux/uleds.h).
15 #define ULEDS_MAX_NAME_SIZE 80
17 struct uleds_user_dev {
18 char name[ULEDS_MAX_NAME_SIZE];
21 A new LED class device will be created with the name given. The name can be
22 any valid file name, but consider using the LED class naming convention of
23 "devicename:color:function".
25 The current brightness is found by reading a single byte from the character
26 device. Values are unsigned: 0 to 255. Reading does not block and always returns
27 the most recent brightness value. The device node can also be polled to notify
28 when the brightness value changes.
30 The LED class device will be removed when the open file handle to /dev/uleds
40 * This program creates a new userspace LED class device and monitors it. A
41 * timestamp and brightness value is printed each time the brightness changes.
43 * Usage: uledmon <device-name>
45 * <device-name> is the name of the LED class device to be created. Pressing
56 #include <linux/uleds.h>
58 int main(int argc, char const *argv[])
60 struct uleds_user_dev uleds_dev;
63 unsigned char brightness;
67 fprintf(stderr, "Requires <device-name> argument\n");
71 strncpy(uleds_dev.name, argv[1], ULEDS_MAX_NAME_SIZE);
73 fd = open("/dev/uleds", O_RDWR);
75 perror("Failed to open /dev/uleds");
79 ret = write(fd, &uleds_dev, sizeof(uleds_dev));
81 perror("Failed to write to /dev/uleds");
90 while (!(pfd.revents & (POLLERR | POLLHUP | POLLNVAL))) {
91 ret = read(fd, &brightness, 1);
93 perror("Failed to read from /dev/uleds");
97 clock_gettime(CLOCK_MONOTONIC, &ts);
98 printf("[%ld.%09ld] %u\n", ts.tv_sec, ts.tv_nsec, brightness);