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