Skip to content

demux: bargraph turns on its highest output; man page array ranges (#3519) - #4687

Open
tzuohann wants to merge 2 commits into
LinuxCNC:masterfrom
tzuohann:fix-demux-bargraph-3519
Open

tzuohann wants to merge 2 commits into
LinuxCNC:masterfrom
tzuohann:fix-demux-bargraph-3519

Conversation

@tzuohann

@tzuohann tzuohann commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3519.

With bargraph set, a selection of personality or more should turn every output on. Instead the top output never comes on:

loadrt demux personality=4
setp demux.0.bargraph 1
setp demux.0.sel-uint 4   (out-00..02 on, out-03 stays off)

Fix (demux.comp):

  • Bargraph clamps the selection to personality, not personality-1. No config can depend on the old behaviour, since the top output could never come on.
  • sel-uint is clamped before it is added to the bit inputs. Before, a value of 2^31 or more went negative and turned every output off, in both modes. That is the only change to one-hot.

halcompile (separate commit): man pages showed array pins as 00..personality; the last index is personality-1. This fixes 13 components' man pages.

Test: tests/demux-bargraph checks every output in both modes. It fails without the fix and passes with it.

Not in this PR: demux_generic has a similar cast at 2^63 or more; that needs its own issue.

tzuohann and others added 2 commits October 15, 2026 09:16
…inuxCNC#3519)

In bargraph mode the selection was clamped to personality-1 as in one-hot
mode, so the top output never came on. Bargraph has personality+1 states
(none .. all on); one-hot still clamps to the last output.

sel-uint is a 64-bit pin but was summed into an int, so large values
truncated (0xFFFFFFFF read as -1: every output off). It is now clamped
to personality before the bit inputs are added, so no selection can wrap.

tests/demux-bargraph checks every output for selections 0..5 in both
modes, a bit input, the largest 32- and 64-bit sel-uint values, and a
1-output demux.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Pins and params of an array sized by an expression were documented as
00..personality; the last index is personality-1. Expressions that are
not a plain name are bracketed: 00..(personality & 0xff)-1. Affects the
man pages of bitmerge, bitslice, carousel, demux, gantry, limit_axis,
lincurve, logic, max31855, moveoff, multiswitch, output_buffer and
radiobutton.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@BsAtHome

Copy link
Copy Markdown
Contributor

Why is this touching halcompile with such complexity? If you say it should read 0..personality-1 instead of 0..personality, then why isn't it a one-liner? Or am I missing something?

There is an additional problem in the bargraph mode. Using the bit inputs, you cannot select all on with personality at 32 because the bargraph has 33 states but only 5 bits as input. Additionally using the sel-uint input would need to be done as a boolean, but that is very messy. In this light, the bargraph mode should not have personality to bound to 32, but to 31.

But looking at the changes,... The change in demux should also be more structured. The change is rather complicated IMO and the luster casting is unnecessary when the proper types are used (rtapi_u64 is not the right type). In that sense, it would also be better to fix the forced ternary evaluation with bg and to split the loop properly. That should also fix the bad indent style in the if and else if construct.

Why is this adding a test? Are there any suspicions that an unrelated change somewhere in the codebase breaks this? That would be exceptionally bad because then probably everything breaks or is broken.

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.

demux component bargraph mode never turns on highest output

2 participants