Skip to content

common: lua: correct the serialLED library documentation - #8014

Open
Hwurzburg wants to merge 2 commits into
ArduPilot:masterfrom
Hwurzburg:lua-serialled-api-update
Open

common: lua: correct the serialLED library documentation#8014
Hwurzburg wants to merge 2 commits into
ArduPilot:masterfrom
Hwurzburg:lua-serialled-api-update

Conversation

@Hwurzburg

Copy link
Copy Markdown
Contributor

The serialLED: section of the Lua bindings page documented an API that no longer exists. A script written from it would not run.

Page said Actually
set_num_LEDs( output_number , number_of_LEDs ) no such function - it is set_num_neopixel(), set_num_neopixel_rgb() or set_num_profiled(), depending on LED type
set_RGB( ... ) with LED_number (1-32) led_index is zero based, -1 sets the whole string, and the limit is not 32
send() send( chan ) - it takes the output channel
"WS8212B RGB LED strings" any RGB string: NeoPixel, NeoPixel RGB or ProfiLED

The zero-based indexing is the one most likely to bite: a script following the old page would silently skip the first LED and run one off the end.

The 32 LED limit

Lifting it is the outstanding checkbox on #2783 ("changed LED scripting API to allow more than 32 LEDs on a pin"). AP_SERIALLED_MAX_LEDS is 128, but not uniformly - set_num_neopixel() and set_num_neopixel_rgb() accept the full 128, while set_num_profiled() is capped at 126 (AP_SERIALLED_MAX_LEDS - 2), since ProfiLED reserves two for framing. Both figures are documented rather than quoting a single number.

Also added

set_num_profiled() returns false unless an output has SERVOx_FUNCTION = 132 (ProfiLEDClock) assigned - it checks function_assigned(k_ProfiLED_Clock) and bails out. That was not mentioned anywhere and is easy to hit. The function label is taken from generated apm.pdef.xml so it matches the GCS dropdown.

Verification

Checked against libraries/AP_Scripting/docs/docs.lua (signatures and the led_index semantics), libraries/AP_SerialLED/AP_SerialLED.cpp (the limits and the clock check), and libraries/AP_Scripting/generator/description/bindings.desc (the declared argument ranges).

Built with python3 update.py --fast --site copter.

Note this does not close #2783 - its other remaining item is the R9Pilot autopilot, which has an hwdef in ArduPilot but no wiki page and no README.md in its hwdef directory, so that one needs board information rather than an edit.

🤖 Generated with Claude Code

The documented API did not match the code. set_num_LEDs() does not
exist - the length of a string is set with set_num_neopixel(),
set_num_neopixel_rgb() or set_num_profiled(), depending on the LED type.
send() was shown with no argument when it takes the output channel.

set_RGB was described as taking "LED_number (1-32)". The index is zero
based, not one based, -1 sets the whole string, and the 32 LED limit is
long gone: AP_SERIALLED_MAX_LEDS is 128, which set_num_neopixel and
set_num_neopixel_rgb accept in full while set_num_profiled is capped two
lower at 126. Lifting that 32 LED limit is the outstanding item on
issue ArduPilot#2783.

Also record that set_num_profiled() fails unless an output has
SERVOx_FUNCTION = 132 (ProfiLEDClock) assigned, and drop the claim that
the library is specific to WS8212B strings.

Verified against libraries/AP_Scripting/docs/docs.lua, AP_SerialLED.cpp
and the ranges declared in AP_Scripting/generator/description/bindings.desc.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Hwurzburg
Hwurzburg requested a review from IamPete1 August 29, 2026 17:06
Comment thread common/source/docs/common-lua-scripts.rst Outdated
Co-authored-by: Peter Hall <33176108+IamPete1@users.noreply.github.com>
@Hwurzburg
Hwurzburg requested a review from IamPete1 August 31, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plane 4.0.6 Wiki topics

2 participants