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

Add promise- or callback-based notifications when motor actions are complete #12

Open
WasabiFan opened this issue Apr 3, 2016 · 3 comments
Labels

Comments

@WasabiFan
Copy link
Owner

Although there is no kernel interface for completion events, we can still poll the state with an interval timer. It would be relatively easy to register a setInterval callback that polls the necessary properties and resolves promises as needed. The three big considerations are:

  • It should use one universal timer which handles any and all pending promises
  • The timer should only be running when needed
  • Any promise library that is used must work in the version of Node that can run on the EV3
@WasabiFan
Copy link
Owner Author

I have decided to put this on hold until we have a real way of receiving event notifications from the kernel. To make a generic version of this API work, every motor start call would need to initiate a polling apparatus just in case the user decided to .then() on the promise. That's just too much overhead for the embedded processor to handle.

For now, I have implemented a polling system that lets the user register a predicate and callback on any generic Device instance. This API can be used if events are required.

@paulolc
Copy link

paulolc commented May 12, 2016

@WasabiFan, how can I use the polling system you refer? I can't seem to find the corresponding commit. How can I register the predicate and specify the callback? Thanks.

@WasabiFan
Copy link
Owner Author

These changes are on the develop branch and have been released in a beta release. If you haven't already installed it, you can do so by running (command untested but should work):

npm install ev3dev-lang@beta

I published this release as a beta because the documentation generator I use was having problems; this has since been resolved, so I plan to publish a full release and then update it for the most recent kernel soon. This version of the library supports the -10-ev3dev kernel. The newest kernel, -11-ev3dev, is not yet supported (sorry about that!) but it was only released a few days ago.

The diff of the addition of the polling feature can be found here. Primarily, the functions that you are looking for are registerEventCallback and registerEventPromise; you can look at their signatures in the source code to see what you need to pass them. I also have an example of the callback-based version of the function here. Note that, to use the promise-based version, you need to install bluebird from npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants