rap init driver
Enter driver information
This will automatically generate package.json and driver.json.
- Declare device information in driver.json.
For example, suppose we need to create a driver with GPIO:
As you can see, we declared a
gpio type driver. We also set up additional arguments relating to direction and edge. We defined edge as
both, which means it will be triggered on both positive and negative edges.
We need to code a simple driver which reads GPIO values.
var driver = require('ruff-driver');
Notice the Ruff built-in methods used in the above example:
attachexecutes a function when other Ruff resources are ready.
detachexecutes a function before the application ends and usually does some clean-up work.
exportscontains customized functions defined by developers. Here we defined a
Once we finish coding, we should write test scripts to make sure the driver works. For more information, refer to Driver Programming Model。
Ruff provides a test framework that allows you to test your drivers on your PC:
var runner = require('ruff-driver-runner').runner;
Notice the test modules that are included:
test: a test framework that complies with CommonJS and Unit Testing standards.
ruff-mock: a mock framework by Ruff
ruff-driver-runner: a test automation runner powered by Ruff, which simulates all physical devices on your development machine.
Run the following command to test your driver：
For more information, please refer to Driver Testing。
The above example reflects a driver test on a development machine. You will still need to test your driver in a production environment.
Instead of downloading a driver, you will need to add a device by including a local driver.
rap device add -i <device-id> -l /path/to/driver
Now you can deploy and test the application with our customized driver.
After development and testing, the driver is ready for use. Please publish the driver to our repository to benefit other application developers.
If you haven’t signed up for an account at our site, please sign up here.
Run the following command to add your user info of repository：
Run the following command to publish your driver：
That’s it! Thank you for contributing your first driver to our repository!