Split toggle2nist component - #4350
Open
Sigma1912 wants to merge 2 commits into
Open
Conversation
Sigma1912
marked this pull request as draft
August 7, 2026 14:29
This component does what the legacy 'toggle2nist' man page described plus added debounce on input pins and a maximum output pulse length to recover if the 'is-on' signal does not change state.
Sigma1912
force-pushed
the
split_toggle2nist_component
branch
from
August 7, 2026 15:13
3fd56d3 to
90aeed6
Compare
Restores the legacy functionality (as in 2.9) plus added input debounce and and a maximum output pulse length to recover if the 'is-on' signal does not change state. Also fixes the description so it matches actual (legacy) behavior.
Sigma1912
force-pushed
the
split_toggle2nist_component
branch
from
August 7, 2026 15:15
90aeed6 to
d6070be
Compare
Sigma1912
marked this pull request as ready for review
August 7, 2026 15:29
BsAtHome
reviewed
Aug 7, 2026
Comment on lines
+48
to
+52
| if (( debounce < 1 ) || ( debounce > 10000 )) { | ||
| debounce_val = 2; // set a sane value | ||
| } else { | ||
| debounce_val = debounce; | ||
| } |
Contributor
There was a problem hiding this comment.
May I suggest (reads debounce only once):
rtapi_u32 debounce_val = debounce;
if(debounce_val < 1 || debounce_val > 10000) {
debounce_val = 2; // set a sane value
}You may also want to cache is_on and in:
rtapi_bool inval = in;
rtapi_bool isonval = is_on;and then use the cached values.
Comment on lines
+39
to
+40
| variable int state; | ||
|
|
Contributor
There was a problem hiding this comment.
statefollows in, which is a bool. Why isn't state a bool? Is there a specific reason for state to be an integer?
Comment on lines
+37
to
+38
| variable unsigned debounce_val; | ||
| variable unsigned pulse_length; |
Contributor
There was a problem hiding this comment.
debounce_val is unconditionally overwritten in the function. Having it as as variable here is expensive. Better use a local variable (see also other comment).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Creates separate components for handling toggle buttons and momentary buttons
Background
Before #3193 'toggle2nist' component docs described the functionality as converting
momentary inputs to nist outputs but the actual functionality was converting toggled
inputs to nist outputs. This required using a preceding 'toggle' component to match
documented behavior.
The fix in #3193 changed the behavior to match the documentation (and added debouncing
to the inputs). While this fixed the issues reported on the forum it breaks functionality
for hal files that use the preceeding 'toggle' component as a workaround.
Also the name 'toggle2nist' does no longer reflect the actual function.
What is 'nist'
The term 'nist' seems to have been invented by the original author of the 'toggle2nist' component.
From the description:
Alternative
The 'toggle' and 'momentary' functionality could be combined in a single component.
However, due to the very descriptive component name, this new component should probably not be called 'toggle2nist'. Changing the name would then of course require an update to existing hal files.
See previous discussion: #4223
Tested
Both components have been tested on real hard ware using mechanical switches.