The following is the simplest example of a Ruff app：
In ruff, a
device object is an abstraction of a real-world hardware device.
We need to find a device in order to operate it. Ruff provides following API to select a device.
Using the format $(‘led-0’), we locate a device with the ID
In order to make the selector work, we must first add the device and set up its ID. If you don’t know your device’s model name, please check our RAP repository.
Add a device using a
rap command as follows：
rap device add your-device-id
Here we define
your-device-id, which will be used within $(‘your-device-id’) selector in your code.
When you add a device, you must enter the correct model name and install the corresponding drivers and dependencies.
This command will also add a device’s information such as ID and model name into
Packages are like libraries or utilities. They allow Ruff developers to share and re-use their work so that others don’t waste time trying to re-invent wheels.
There are a few types of packages in Ruff：
- Drivers allow software to control hardware such as sensors, servos, etc.
- Boards and drivers for boards (e.g., Ruff board).
Check our RAP repository for packages contributed by other developers.
There are two basic approaches to installing packages.
rap is always the easiest way to install.
rap install your-package-name --save
rap will find
your-package-name in the RAP reopsitory. If the package exists it will be automatically downloaded and installed, and
package.json will be updated.
If you want to install multiple packages, an alternative solution would be modify
package.json, add all the dependencies, and then install using following command:
This will allow you to install multiple packages simultaneously.
Another type of dependencies, devDependencies, will not be deployed on the board. They will only be used to develop.
You may add a devDependency using the following command：
rap install your-rap-name --save-dev
Alternatively, you may declare
package.json and execute installation as follows：
Currently a Ruff dev board can only run one application. Each app will have its own process. As an application developer, you can code in application functions that execute upon events. For example:
// do initialization work
// do cleanup work
Ruff supports the following events by default：
readyallows you to specify a function to execute when the application process starts.
endallows you to specify a function to execute before the application process stops.