-
Notifications
You must be signed in to change notification settings - Fork 124
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
Debounce #51
Comments
Are you using |
It's a signal from a light stack that goes though a optocopler. |
Note that
If this can be used to resolve the issue then it should be possible to achieve this without modifying |
Correct I can add the check to my code. It just seemed the |
The problem here is the bounce on the interrupt input. |
The |
yo. i just made a debouncer based on watch: https://gist.github.com/GottZ/e4be78c928817c6701155f6ae910d841 @fivdi if you'd want me to, i could clean it up and create a pull request. just let me know 👍 video of it in action: https://usercontent.irccloud-cdn.com/file/c8pO8syE/VID-20160729-WA0001.mp4 i'm not using any resistor at all. this button goes directly to ground and gpio 3 any idea how i should name this function? i'm thinking about something like .watch(func, delay) where delay is 0 ms by default wich means no debouncing. |
Hi guys, var last = 0;
sensor.watch(_.throttle(function (err, value) {
if (err) {
// ...
}
if (value != last) {
last = value;
// ...
}
}, 100)); // throttle value |
In my use case I chose debounce over throttle and it worked great. @fivdi I'd say there is no reason to keep your debounce code if an alternate solution works fine. So I'd close this issue but with a mention of these lodash options in the readme though. debounce = require('lodash/debounce')
switchPortIntr.watch(
debounce(function(err, value) {
if (err) {
throw err;
}
// whatever you need to do when interrupt happens, but only do it once without "bouncing"
}, 200, {
'leading': false,
'trailing': true
})
) leading false and trailing true will do it at the end of the 200ms. If you need a faster response try leading true and tailing false. If your interrupting device is really sloppy you might need more that 200ms. I could have used was less 200ms but that is plenty fast enough for a human actuated switch even with trailing true. |
Although |
besides lodash there is this one off package by Sindre Sorhus. He has a throttle as well |
I did a package with a node module adding watchFilter usage with onoff package. I believe it can help others developers with the same problems https://www.npmjs.com/package/inputmonitor https://github.com/rafaelquines/inputmonitor ;) |
It took a while but this issue has been resolved and onoff v3.0.0 has an effective implementation for debouncing based lodash.debounce. For more details see here. An example showing how to debounce buttons can be seen at Debouncing Buttons Sorry for taking so long to fix this. |
I am having an issue with a nosy input.
The interrupts are firing very fast but reading the same value (I think because of the noise).
For example I have an input the is low but the watch listeners are firing always reading 0.
I have tried setting debounceTimeout but this only delays the interrupt and cause them to occur less often.
Can the code be changed to add a readSync after the timeout and fire the watch listeners if the value changed.
Also don't know if the help but it is on a bealge bone black.
The text was updated successfully, but these errors were encountered: