LED(4)

πŸ’… LED(4) β€” the Kernel Interfaces Manual, but make it cute πŸ’…

okay bestie, gather round, we're talking about led(4) β€” the kernel's whole entire API for manipulating LEDs, lamps and other annunciators. yes, annunciators. it's giving fancy word for "little blinky light." slay. ✨


✨ NAME ✨

led β€” API for manipulating LED's, lamps and other annunciators πŸš¨πŸ’‘


πŸŽ€ SYNOPSIS πŸŽ€

like, here's the tea, copy-paste it exactly, do not freestyle:

#include <dev/led/led.h>

typedef void led_t(void *priv, int onoff);

struct cdev *
led_create_state(led_t *func, void *priv, char const *name, int state);

struct cdev *
led_create(led_t *func, void *priv, char const *name);

void
led_destroy(struct cdev *);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the led driver is basically the generic support system for handling LEDs, lamps and other annunciators. main character energy for tiny lights. πŸ’–

your hardware driver has to bring two things to the party: a function that turns the annunciator on and off, and the device name of the annunciator, which lives relative to /dev/led/. the priv argument gets passed right back to that on/off function, and the hardware driver can use it however it sees fit. no rules, just vibes (well, the vibes of a void *). 🫢

you control the lamp by opening and writing ASCII strings to the /dev/led/bla device. that's it. that's the whole thing.

in the following, we use this special notation to indicate the resulting output of the annunciator:

*       The annunciator is on for 1/10th second.
_       The annunciator is off for 1/10th second.

state can be set directly, and because the change happens immediately, you can flash the annunciator with very short periods and synchronize it with program events. iconic, honestly. but heads up bestie β€” there's a non-trivial overhead, so this may not be usable for benchmarking or measuring short intervals. πŸ’€

0       Turn the annunciator off immediately.
1       Turn the annunciator on immediately.

flashing can be set with a given period, and the pattern continues endlessly. forever. no cap. ♾️

f       _*
f1      _*
f2      __**
f3      ___***
...
f9      _________*********

three high-level commands are available, and they ate:

d%d     Numbers.  Each digit is blinked out at 1/10th second, zero
        as ten pulses.  Between digits a one second pause and
        after the last digit a two second pause after which the
        sequence is repeated.

s%s     String.  This gives full control over the annunciator.
        Letters β€˜A’ ... β€˜J’ turn the annunciator on for from
        1/10th to one full second.  Letters β€˜a’ ... β€˜j’ turn the
        annunciator off for 1/10th to one full second.  Letters
        β€˜u’ and β€˜U’ turn the annunciator off and on respectively
        when the next UTC second starts.  Unless terminated with a
        β€˜.’, the sequence is immediately repeated.

m%s     Morse.

              β€˜.’     becomes β€˜_*’
              β€˜-’     becomes β€˜_***’
              β€˜ ’     becomes β€˜__’
              β€˜\n’    becomes β€˜____’

the sequence is repeated after a one second pause. 🧚


🌸 FILES 🌸

  • /dev/led/*

🌈 EXAMPLES 🌈

a d12 flashes the lamp:

*__________*_*______________________________

a sAaAbBa flashes:

*_*__**_

and this one right here? chef's kiss. obsessed:

/usr/bin/morse -l "Soekris rocks" > /dev/led/error

⭐ SEE ALSO ⭐


πŸ’œ HISTORY πŸ’œ

the led driver first appeared in FreeBSD 5.2. a legend was born. πŸ‘‘


πŸ‘‘ AUTHORS πŸ‘‘

this software was written by Poul-Henning Kamp <phk@FreeBSD.org>.

this manual page was written by Sergey A. Osokin <osa@FreeBSD.org> and Poul-Henning Kamp <phk@FreeBSD.org>.


and that's the whole page bestie, ty for coming to my ted talk πŸŽ€ this one's from the Debian crew, dated April 24, 2007, and it's LED(4) β€” mwah, periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from