Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle2nist fix race conditions #3193

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

Sigma1912
Copy link
Contributor

@Sigma1912 Sigma1912 force-pushed the toggle2nist_fix_race_conditions branch from b08f99e to 83afcad Compare November 27, 2024 08:58
function _ nofp;
license "GPL";
author "Anders Wallin";
author "David Mueller, Based on work by Anders Wallin and John Kasunich";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Anders Wallin still the author? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really keen on having my name there. The reason I changed that is that I believe the 'author' is the person who could be contacted when questions arise. Since I completely changed the function it seems pointless to contact Anders Wallin.

To be honest, it has always been a mystery to me as to who the 'author' is supposed to be for something that is substantially changed. Is the original author still the 'author' if somebody changes half of the content?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care, but I think maybe just a list of authors, like author "Anders Wallin, David Mueller"; ?


""";

pin in bit in;
pin in bit is_on;
pin out bit on;
pin out bit off;
variable int old_in;
variable int to_state=0;
param rw u32 debounce = 2 "debounce delay in cycles";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we disable debouncing? With debounce = 0 ?
However, isn't it better to have a default value without debouncing to not eventually change the behaviour of existing configurations and add a note like "if you connect a physical button, a debounce value of minimum 2 is strongly recommend!" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied that over from the 'toggle' component which I presumed to be a good example.
As for existing configs, since the current component is buggy people had to find workarounds (see links above). So if somebody has put an additional 'toggle' component between the button and the 'toggle2nist' component to make it work then the fixed version of it will now require two button presses which is actually what one would expect when we read the description of the component. Not sure how to circumvent this unless we want to keep the broken things and just add the fixed things to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the debounce is a good think, I agree.
Only thinking that it adds some very little delay but I guess that would hurt nobody.
To be 100% safe we could use the update-ini script to disable the debouncing, but that would be cracking a walnut with a sledgehammer...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get your point and I have no problem with setting the default to 0. The only reason I chose 2 was to make the two 'toggle' components consistent.

@Sigma1912 Sigma1912 force-pushed the toggle2nist_fix_race_conditions branch from 83afcad to adf5743 Compare November 27, 2024 11:51
@andypugh
Copy link
Collaborator

andypugh commented Nov 27, 2024

"param"s used to be a way to save HAL shared memory, but we have increased it so many times now that it probably isn't worth the bother. It's just about possible that someone might want to alter the debounce in HAL logic, so I suggest making it a pin.
(edit) Also many HAL components malloc everything including params into HAL shared memory anyway, so until they sort themselves out it's probably best to use pins except for things that really never need to change.

@Sigma1912 Sigma1912 force-pushed the toggle2nist_fix_race_conditions branch from adf5743 to c4d1540 Compare November 27, 2024 13:12

\[bu] On a rising edge on pin \\fIin\\fR when \\fIis-on\\fR is low: It sets \\fIon\\fR until \\fIis-on\\fR becomes high.

\[bu] On a rising edge on pin \\fIin\\fR when \\fIis-on\\fR is high: It sets \\fIoff\\fR until \\fIis-on\\fR becomes low.


       ┐     ┌─────xxxxxxxxxxxx┐           ┌─────xxxxxxxxxxxx┐
┌─────xxxxxxxxxxxx┐ ┌─────xxxxxxxxxxxx┐
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for curiosity - what has changed here?

Copy link
Contributor Author

@Sigma1912 Sigma1912 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have asked myself the same as I have not changed anything in those lines. . I noticed there is something about this in the commit history:
https://github.com/LinuxCNC/linuxcnc/pull/3007/files

So not sure what this means, @petterreinholdtsen would probably know but if saving the file in a text editor breaks the diagram then it may be better to just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to fix this by copying the spacing from the 'toggle' component.

@andypugh
Copy link
Collaborator

Just a comment, rather than something that needs to be changed, but it is preferred to use "signed" and "unsigned" as the type designators for integer pins. (as it says in the docs). The reason I mention this is that I hope to convert all integer hal pins to 64 bits before 2.10 is released. There is no point having 32 and 64 bit, in my opinion. Behind the scenes this will also involve widening some of the step and encoder internal values, hopefully making wrap-around impossible, rather than just unlikely.

@andypugh
Copy link
Collaborator

Comment here when you think that this is finished and ready.

@Sigma1912 Sigma1912 force-pushed the toggle2nist_fix_race_conditions branch 3 times, most recently from 36d943d to 1f13544 Compare November 28, 2024 07:45
@Sigma1912 Sigma1912 force-pushed the toggle2nist_fix_race_conditions branch from 1f13544 to 0bc97e6 Compare November 28, 2024 07:54
@Sigma1912
Copy link
Contributor Author

Ready, as far as I'm concerned.

@andypugh andypugh merged commit 1cb514c into LinuxCNC:master Nov 28, 2024
10 checks passed
@andypugh
Copy link
Collaborator

Thanks

@Sigma1912 Sigma1912 deleted the toggle2nist_fix_race_conditions branch November 29, 2024 08:02
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.

3 participants