controller_leds(3)

πŸ“¦
version 0.7.1 Β· 2 versions
, in nixos 26.05

πŸ’– 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