Ruff 1.1.0 Documentation
Table of Contents
ADC#
The ADC
module allows you to create your own device driver with ADC output.Following line of code includes the ADC module: require('adc');
.
ADC driver developers may extend this module by adding more functions.
Create ADC driver#
Using Ruff Framework, you just need to write some easy implementation
Below is an example of an ADC driver:
var adc = require('adc');
AdcDriverClass = adc.driver({
attach: function(options) {
...
},
exports: {
getRawValue: function() {
// raw value from your device
...
},
getResolution: function() {
// your resolution is here
...
},
}
});
As you can see, getRawValue
and getResolution
are the only two functions you have to implement. getCurrent
and getVoltage
functions are Ruff built-in functions. Other functions may be provided by ADC driver developers.
Use ADC interface#
Driver developers who use ADC need first to declare the device as ADC type in driver.json
.
type
: There are to valid ADC channel types:current
: current type,voltage
: voltage type
min
: min value for ADC channelmax
: max value for ADC channelresistance
: resistance value for ADC channel, only works when ADC channel type iscurrent
{
"inputs": {
"adc": {
"type" : "adc",
"args" : {
"type": "current",
"min": 0,
"max": 5
}
}
}
}
(driver.json)
You may obtain an ADC instance in your driver code:
var driver = require('ruff-driver');
module.exports = driver({
attach: function(options) {
adc = options.getRequired('adc');
}
...
});
API#
adc.getCurrent()#
return the current value specified by your driver.
Example:
try {
var value = channel.getCurrent();
console.log(value);
} catch(error) {
console.log(error);
}
adc.getVoltage()#
return voltage value.
adc.getRawValue()#
return ADC channel raw value.
adc.getResolution()#
return ADC resolution, which is significance bits, e.g. 12 bit.