usb: musb: Fix trying to free already-free IRQ 4
[linux/fpc-iii.git] / tools / leds / uledmon.c
blob25cbc7acf50a04e8e54378332513163f6c8721e3
1 /*
2 * uledmon.c
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
10 * CTRL+C will exit.
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <time.h>
17 #include <unistd.h>
19 #include <linux/uleds.h>
21 int main(int argc, char const *argv[])
23 struct uleds_user_dev uleds_dev;
24 int fd, ret;
25 int brightness;
26 struct timespec ts;
28 if (argc != 2) {
29 fprintf(stderr, "Requires <device-name> argument\n");
30 return 1;
33 strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
34 uleds_dev.max_brightness = 100;
36 fd = open("/dev/uleds", O_RDWR);
37 if (fd == -1) {
38 perror("Failed to open /dev/uleds");
39 return 1;
42 ret = write(fd, &uleds_dev, sizeof(uleds_dev));
43 if (ret == -1) {
44 perror("Failed to write to /dev/uleds");
45 close(fd);
46 return 1;
49 while (1) {
50 ret = read(fd, &brightness, sizeof(brightness));
51 if (ret == -1) {
52 perror("Failed to read from /dev/uleds");
53 close(fd);
54 return 1;
56 clock_gettime(CLOCK_MONOTONIC, &ts);
57 printf("[%ld.%09ld] %u\n", ts.tv_sec, ts.tv_nsec, brightness);
60 close(fd);
62 return 0;