Skip to content

Commit fa7f324

Browse files
dlechjanaszewski
authored andcommitted
tools/leds: Add uledmon program for monitoring userspace LEDs
The uleds driver provides userspace LED devices. This tool is used to create one of these devices and monitor the changes in brighness for testing purposes. Signed-off-by: David Lechner <david@lechnology.com> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
1 parent eb1ce74 commit fa7f324

4 files changed

Lines changed: 81 additions & 3 deletions

File tree

‎tools/Makefile‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ help:
1717
@echo ' hv - tools used when in Hyper-V clients'
1818
@echo ' iio - IIO tools'
1919
@echo ' kvm_stat - top-like utility for displaying kvm statistics'
20+
@echo ' leds - LEDs tools'
2021
@echo ' lguest - a minimal 32-bit x86 hypervisor'
2122
@echo ' net - misc networking tools'
2223
@echo ' perf - Linux performance measurement and analysis tool'
@@ -56,7 +57,7 @@ acpi: FORCE
5657
cpupower: FORCE
5758
$(call descend,power/$@)
5859

59-
cgroup firewire hv guest spi usb virtio vm net iio gpio objtool: FORCE
60+
cgroup firewire hv guest spi usb virtio vm net iio gpio objtool leds: FORCE
6061
$(call descend,$@)
6162

6263
liblockdep: FORCE
@@ -126,7 +127,7 @@ acpi_clean:
126127
cpupower_clean:
127128
$(call descend,power/cpupower,clean)
128129

129-
cgroup_clean hv_clean firewire_clean lguest_clean spi_clean usb_clean virtio_clean vm_clean net_clean iio_clean gpio_clean objtool_clean:
130+
cgroup_clean hv_clean firewire_clean lguest_clean spi_clean usb_clean virtio_clean vm_clean net_clean iio_clean gpio_clean objtool_clean leds_clean:
130131
$(call descend,$(@:_clean=),clean)
131132

132133
liblockdep_clean:
@@ -164,6 +165,6 @@ clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean lguest_cle
164165
perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \
165166
vm_clean net_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
166167
freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \
167-
gpio_clean objtool_clean
168+
gpio_clean objtool_clean leds_clean
168169

169170
.PHONY: FORCE

‎tools/leds/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uledmon

‎tools/leds/Makefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Makefile for LEDs tools
2+
3+
CC = $(CROSS_COMPILE)gcc
4+
CFLAGS = -Wall -Wextra -g -I../../include/uapi
5+
6+
all: uledmon
7+
%: %.c
8+
$(CC) $(CFLAGS) -o $@ $^
9+
10+
clean:
11+
$(RM) uledmon
12+
13+
.PHONY: all clean

‎tools/leds/uledmon.c‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* uledmon.c
3+
*
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.
6+
*
7+
* Usage: uledmon <device-name>
8+
*
9+
* <device-name> is the name of the LED class device to be created. Pressing
10+
* CTRL+C will exit.
11+
*/
12+
13+
#include <fcntl.h>
14+
#include <stdio.h>
15+
#include <string.h>
16+
#include <time.h>
17+
#include <unistd.h>
18+
19+
#include <linux/uleds.h>
20+
21+
int main(int argc, char const *argv[])
22+
{
23+
struct uleds_user_dev uleds_dev;
24+
int fd, ret;
25+
int brightness;
26+
struct timespec ts;
27+
28+
if (argc != 2) {
29+
fprintf(stderr, "Requires <device-name> argument\n");
30+
return 1;
31+
}
32+
33+
strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
34+
uleds_dev.max_brightness = 100;
35+
36+
fd = open("/dev/uleds", O_RDWR);
37+
if (fd == -1) {
38+
perror("Failed to open /dev/uleds");
39+
return 1;
40+
}
41+
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;
47+
}
48+
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;
55+
}
56+
clock_gettime(CLOCK_MONOTONIC, &ts);
57+
printf("[%ld.%09ld] %u\n", ts.tv_sec, ts.tv_nsec, brightness);
58+
}
59+
60+
close(fd);
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)