1 // SPDX-License-Identifier: GPL-2.0
5 * This program creates a new userspace LED class device and monitors it. A
6 * timestamp and brightness value is printed each time the brightness changes.
8 * Usage: uledmon <device-name>
10 * <device-name> is the name of the LED class device to be created. Pressing
20 #include <linux/uleds.h>
22 int main(int argc
, char const *argv
[])
24 struct uleds_user_dev uleds_dev
;
30 fprintf(stderr
, "Requires <device-name> argument\n");
34 strncpy(uleds_dev
.name
, argv
[1], LED_MAX_NAME_SIZE
);
35 uleds_dev
.max_brightness
= 100;
37 fd
= open("/dev/uleds", O_RDWR
);
39 perror("Failed to open /dev/uleds");
43 ret
= write(fd
, &uleds_dev
, sizeof(uleds_dev
));
45 perror("Failed to write to /dev/uleds");
51 ret
= read(fd
, &brightness
, sizeof(brightness
));
53 perror("Failed to read from /dev/uleds");
57 clock_gettime(CLOCK_MONOTONIC
, &ts
);
58 printf("[%ld.%09ld] %u\n", ts
.tv_sec
, ts
.tv_nsec
, brightness
);