controller_leds(3)
π controller_leds(3) β Arcan Lua API π
okay so bestie, welcome to controller_leds from the Arcan Lua API β the little function that lets you peek at (or re-hunt for) your LED controllers. yes, the glowy ones. we love a light show β¨
πΈ NAME πΈ
controller_leds β query or rescan for LED controllers. that's it, that's the vibe check π
π¦ SYNOPSIS π¦
[nleds, variable, rgb] or [nctrls, low32, high32]
controller_leds( ctrlid )
like, notice how it's giving two possible return shapes? main character energy fr fr π
π DESCRIPTION π
So here's the tea, bestie π΅ β if ctrlid is set, you get the values back for that specific controller. simple. iconic.
And where do you even get a controller id, you ask? great question. You can grab it as part of your _input event handler, on status == "added" events β either straight up when devkind == "led", or for some other devices through the devref field. _display_state events may also hand you a ledctrl,ledind. iykyk π
But wait β if ctrlid is not set, or it's set to -1, then a rescan gets queued instead π³ and that rescan might generate additional device status events. so like, heads up, more events may be incoming, no cap.
In that rescan-ish case it also returns the number of active controllers plus two bitmasks β and those bitmasks are capped to 64 controllers, so don't come for me if your 65th controller isn't in there π
π₯ EXAMPLE π₯
function controller_leds0()
local do_ctrl = function(i)
local nleds, shift, rgb = controller_leds(i);
print("controller", i, "leds:", nleds,
"intensity:", intensity and "yes" or "no",
"rgb:", rgb and "yes" or "no");
end
-- due to the double size restriction, this had to be split
local count, first, second = controller_leds();
print("# controllers:", count);
for i=0, 31 do
if (bit.band(first, bit.lshift(1, i))) then
do_ctrl(i);
end
end
for i=0, 31 do
if (bit.band(first, bit.lshift(1, i))) then
do_ctrl(32, i);
end
end
end
literally the sweetest little loop ever β it walks the bitmask, checks each bit with bit.band + bit.lshift, and calls do_ctrl on the ones that are lit up. obsessed π
ngl, the comment in there is real: "due to the double size restriction, this had to be split" β that's why you're getting two loops over 0, 31 instead of one big slay loop. it's giving "we did our best and it works" π«Ά
π the cute sign-off π
and that's the whole page, bestie! brought to you by iodev, dated October 2026, living in section 3 of the manual as controller_leds(3). go forth and light up those LEDs π‘π
β¨
π¦ where this page comes from
- nixos 26.05: arcan 0.7.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms