Conversation
setRGBLedColor() assumed the custom switch LEDs follow each other in
switch order from CFS_LED_STRIP_START. PA01 maps them through
ledMapping = {4, 6, 0, 2}, so a script checked whether one switch was
set to NONE but then wrote the LEDs of another, configured, switch.
fsGetLedRGB() made the same assumption, so the custom switch
diagnostics page showed the wrong colours on PA01, and getFSLedState()
ignored the strip offset altogether.
Add a weak fsLedFirstIndex() hook giving the first strip LED of a
custom switch, and use it for every custom switch LED access:
fsLedRGB(), fsGetLedRGB(), getFSLedState() and setRGBLedColor(). PA01
overrides it with its mapping. The generic fsLedRGB() now handles
CFS_LEDS_PER_SWITCH, so ST16's copy of the driver is removed.
Also check the switchGetSwitchFromCustomIdx() result before using it,
and fix the setRGBLedColor() parameter names in the luadoc.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LED_STRIP_LENGTH counts the decorative LEDs followed by the custom switch LEDs, which scripts can only set while that switch is set to NONE. Scripts had no way to tell the two ranges apart, or to find where the gimbal ring LEDs are without a hard-coded per-radio table. Without changing the meaning of LED_STRIP_LENGTH or setRGBLedColor(), add: - BLING_LED_STRIP_LENGTH, the number of decorative LEDs - FUNC_RGB_LED, missing from the Lua constants until now - getRGBLedInfo(), returning the strip length, the decorative and custom switch LED ranges, and named groups of decorative LEDs with their ring geometry The groups come from a new optional leds.bling_groups list in the hw_defs JSON, generated into lua_leds.inc, and are populated for the TX15, TX16S Mk3, GX15 and ST16 gimbal rings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@philmoz @3djc What do you think?? (Part B / second commit, Part A / first commit is just fixes for PA01 that I hit since I chose that as a test target lol) This allows for lua to readily determine "bling" vs cfs leds without changing things for older scripts, as well as allowing future lua scripts to "just work" with any radio's pre-defined gimbal leds. With a minor tweak to the sdcard content, there is also a flag at the top of the various RGBLED scripts that allows for them to be used on "disabled" CFS switches. i.e. thus allowing, for instance, for the |
|
With respect to the 'getRGBLedInfo' function, I considered this when I rewrote the gimbal script; but decided against it:
I don't have any serious objection if you want to add it. |
|
It is small, but increasing... it appears to be becoming somewhat a standard feature for most new radios, or at least the flagship version of a given model (the same could have been said a year ago about customisable switches). Agreed, the SD card content can be updated easier, but it should not be necessary for something the firmware itself knows about, and could (and should IMO) be informing of, so Lua authors don't need to handcraft the complex mapping tables ... no, not ranting on about that any further... I'll start griping about the should-be-unnecessary complex version and radios specific tables in lua scripts. As far as the fallback, no, it won't be needed for radios introduced from say 3.0 onwards if this only goes into 3.0 (if someone wants to add them, that's fine, but we certainly won't need to do it any more) - which is where part of this becomes is this 3.0 only or 2.12-backported question. |
Closes #7716, and follows on from the discussion in #7742.
Summary
LED_STRIP_LENGTHandsetRGBLedColor()keep their current meaning: Lua indexes0 .. BLING-1are the decorative LEDs, and the following indexes are the custom switch LEDs, which a script can only set while that switch is NONE. Nothing existing changes meaning.This PR has two commits:
fix(lua): custom switch LEDs mapped wrongly on PA01is a bug fix with no new Lua API. It will be cherry-picked into the 2.12.5 backport (chore: 2.12.5 backports #7817).feat(lua): describe the RGB LED layout to scriptsadds the new API, and is targeted at 3.0.hal.hrather than in the hw_defs JSON. The gimbal group data would therefore need a smallhal.h-based variant there.1. Fix: custom switch LED mapping
ledMapping = {4, 6, 0, 2}), butsetRGBLedColor()assumed they were. A script therefore checked whether one switch was NONE, then wrote the LEDs of another, configured, switch.fsGetLedRGB()made the same assumption, so the custom switch diagnostics page showed the wrong colours on PA01.getFSLedState(): this ignored the strip offset altogether.fsLedFirstIndex()hook is now used for every custom switch LED access (fsLedRGB,fsGetLedRGB,getFSLedState,setRGBLedColor), and PA01 overrides it with its mapping.fsLedRGB()now handlesCFS_LEDS_PER_SWITCH, so ST16's duplicate LED driver is removed.switchGetSwitchFromCustomIdx()is now checked before it is used.setRGBLedColor()parameter names.The firmware changes apply cleanly to 2.12. The only conflict is in
tests/lua.cpp, where the new test is appended after tests that only exist onmain.2. Feature: LED layout for scripts (3.0)
BLING_LED_STRIP_LENGTH: the number of decorative LEDs. The custom switch LED count isLED_STRIP_LENGTH - BLING_LED_STRIP_LENGTH, so it gets no constant of its own.FUNC_RGB_LED: this constant has been missing since feat: RGB leds supports #3909. Thanks to @davidbitton for spotting it.getRGBLedInfo()returns{ length, bling, cfs = { first, count, perSwitch }, groups = { <name> = { first, count, startAngle, direction } } }. The table is built only when called, so it adds one function entry to the ROTable.leds.bling_groupsin the hw_defs JSON: a new optional field, generated intolua_leds.inc. Each entry has a name, first, count, and optionallystart_angle/directionfor evenly spaced rings.gimbal.lua.start_angleanddirectionare given together.setRGBLedColor()index space.Scripts that want only the decorative LEDs, and must still run on older firmware, can use
(BLING_LED_STRIP_LENGTH or LED_STRIP_LENGTH).SD card scripts
The companion SD card PR is EdgeTX/edgetx-sdcard#306:
gimbal.luaprefersgetRGBLedInfo().groups, keeping its table as a fallback for older firmware.USE_FULL_STRIPoption. It defaults to the decorative LEDs only, and can be switched to also drive unused custom switch LEDs.Testing
hal_settings.his byte-identical tomainfor every board.Lua.RGBLedIndexes(fix commit) checks that bling writes land atBLING_LED_STRIP_START, that an unused custom switch slot is written through the mapping hook, and that a configured one is refused.Lua.RGBLedInfo(feature commit) checks the constants and the table shape.ledstep.luaandledmap.lua, Lua indexes 0-9 and 10-19 light the right and left gimbal rings, with the start LED and direction as reported bygetRGBLedInfo(). Indexes 20-25 are SW1-SW6, and only a switch set to NONE accepts writes.police.luaandgimbal.luafrom feat(rgbled): drive the decorative LEDs by default, use firmware LED groups edgetx-sdcard#306 were tested on the TX16S Mk3.police.luawas run with both the default andUSE_FULL_STRIP = true.Test scripts
ledstep.luais a Tools script (/SCRIPTS/TOOLS/). It lights one Lua index at a time and shows what that index is, and whatsetRGBLedColor()returned:ledmap.luais an RGBLED script (/SCRIPTS/RGBLED/, run from an "RGB leds" special function). It paints each group: the first LED white, the second full colour to show the direction, and the rest dim:🤖 Generated with Claude Code