Split toggle2nist component - #4350
Conversation
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.
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.
90aeed6 to
d6070be
Compare
| if (( debounce < 1 ) || ( debounce > 10000 )) { | ||
| debounce_val = 2; // set a sane value | ||
| } else { | ||
| debounce_val = debounce; | ||
| } |
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.
| variable int state; | ||
|
|
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?
| variable unsigned debounce_val; | ||
| variable unsigned pulse_length; |
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).
|
@BsAtHome I'm a bit fuzzy on the variable types. Question: Also, should I change these things in 'toggle2nist.comp' as well? |
|
The pin type is Going from signed to unsigned or unsigned to signed is most of the time an error. There are legitimate constructs that would require it, but usually, an unsigned construct remains unsigned and a signed construct remains signed. Please note that the old documentation is not yet up-to-date with all the changes that have been going on in HAL. Working on it... |
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.