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

HCSR04.device.nut - busy loop timeout? #46

Open
jmcgnh opened this issue Apr 13, 2017 · 3 comments
Open

HCSR04.device.nut - busy loop timeout? #46

jmcgnh opened this issue Apr 13, 2017 · 3 comments

Comments

@jmcgnh
Copy link

jmcgnh commented Apr 13, 2017

What are the considerations for having a busy loop timeout of 500ms? Isn't this long enough to potentially interfere with other ImpOS functions? I realize that this method may give better accuracy, but how bad would it be to rely on an interrupt and callback instead?

I was thinking of implementing it along the lines of

https://gist.github.com/cat-haines/5492082

But given that the range of the HC-SR04 is not more than 4 meters, my calculation says that the timeout value should only need to be something like 25ms.

@ppetrosh
Copy link

I have no clue on why 500ms was used. And having looked at the code, I really think it can be improved.

If you play with the code and find a better solution which reliably works, please feel free to file a PR with your changes.

@jmcgnh
Copy link
Author

jmcgnh commented Apr 18, 2017

I've done a few experiments today, relying entirely on callbacks rather than busy loops. It "sort of" works, but my experimental/exploratory code is quite messy and there are a few unresolved problems. In particular, the instrumentation to watch how it's working is interfering with the ability to catch events on the 100-microsecond scale. Thank you for the invitation to contribute. I'll keep working on this until I have something worth showing.

@jmcgnh jmcgnh closed this as completed Apr 18, 2017
@jmcgnh jmcgnh reopened this Apr 18, 2017
@jmcgnh
Copy link
Author

jmcgnh commented Apr 18, 2017

Didn't intend to close.

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

No branches or pull requests

2 participants