I have a userspace application which interacts with a kernel-space driver in a Linux environment. The driver, in this case, is an LED driver. In typical *nix fashion, the driver exposes a file in /sys/class/leds/actled1:green/
called value
. When the value of value
exceeds a threshold, the LED turns on.
So, my question is, what is the best-practice way of updating value
from user-space in C?
My current approach is to simply write to the file, with a hardcoded filepath:
int value = 0;
FILE *fp;
/* update value here... */
fp = fopen("/sys/class/leds/actled1:green/value", "w");
if(fp != NULL) fprintf(fp, "%d", value);
fclose(fp);
Is there a better way to do this? It seems that there should be a standard POSIX C api for this, perhaps one that allows for driver lookup (so that I don't need to hard-code the filepath).
value
, or is it reallybrightness
?value
which indicates the amount of activity on the peripheral being monitored as well as abrightness
which indicates whether the LED is on.brightness
changed from 0 to 255 whenvalue
reached a certain threshold.value
attribute.cat trigger
to see what trigger is in use.