Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/hal/components/dbounce.comp
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
component dbounce """alternative debounce component""";
description """
This component is similar to the *debounce*(9) component but uses settable
delay pins for each instance and supports *count*= or *names*= parameters
(groups are not used)
component dbounce """alternative debounce component\n
This component is similar to the \\fBdebounce\\fR component
(man \\fBdebounce\\fR) but uses settable delay pins for each instance
and supports \\fBcount\\fR= or \\fBnames\\fR= parameters
(groups are not used). It also supports an instant-hit mode for probing moves
where the output changes immediately but further changes (bounces)
are ignored until stable.
""";

pin in bit in;
pin out bit out;
pin in u32 delay = 5;
pin in u32 delay = 5 "delay in cycles when not probing";
pin in u32 probedelay = 0 "delay in cycles when probing (if unconnected, uses delay)";
pin in s32 motiontype = -1 """connect to motion.motion-type -
when equal to 5 it means probing""";

variable unsigned state;
option period no;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a reason why the option period no is present. The code does not use the period argument in the _ function and it would therefore result in a warning, which are now treated as errors.

function _;
/*variable int state;*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to keep this as a comment?

pin out u32 state;
function _ nofp;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There no longer is a difference between fp and nofp. All threads are now floating point because newer compilers use sophisticated optimizations using special (floating point) registers. The nofp must not be used anymore and you should not change this line.

license "GPL";
author "Dewey Garrett";
;;
FUNCTION(_) {
int d = (motiontype == 5 && probedelay > 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using an int results in line 33 with a signdness mismatch.

The reason is that the variable d is declared an int, which should have been rtapi_u32 to make it consistent with the underlying types used in delay and probedelay.

? probedelay : delay;

if (in) {
/* probing, trigger on first edge. */
if (motiontype == 5 && state == 0) {
state = d / 2;
out = 1;
/* input true, is state at threshold? */
if (state < delay) {
} else if (state < d) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a comparison with different signedness.

/* no, increment */
state++;
} else {
/* yes, set output */
out = 1;
}
} else {
/* probing, trigger on first edge. */
if (motiontype == 5 && state >= d) {
state = d / 2;
out = 0;
/* input false, is state at zero? */
if (state > 0) {
} else if (state > 0) {
/* no, decrement */
state--;
} else {
Expand Down
Loading