Hello,
I have successfully added the AirQuality and Motion Sensor with nodejs and just want to share the code with you.
AirQuality:
var AnalogSensor = require('./base/analogSensor')
var commands = require('../commands')
function AirQualityAnalogSensor(pin) {
AnalogSensor.apply(this, Array.prototype.slice.call(arguments))
}
AirQualityAnalogSensor.prototype = new AnalogSensor()
AirQualityAnalogSensor.prototype.read = function() {
this.board.pinMode(this.board.INPUT)
var res = AnalogSensor.prototype.read.call(this)
return parseInt(res)
}
module.exports = AirQualityAnalogSensor
MotionSensor:
var DigitalSensor = require('./base/digitalSensor')
var commands = require('../commands')
function MotionDigitalSensor(pin) {
DigitalSensor.apply(this, Array.prototype.slice.call(arguments))
}
MotionDigitalSensor.prototype = new DigitalSensor()
MotionDigitalSensor.prototype.read = function()
{
var write = this.board.writeBytes(commands.dRead.concat([this.pin, commands.unused, commands.unused]))
if (write) {
this.board.wait(200)
var singleByte = this.board.readByte()
var bytes = this.board.readBytes();
return bytes[0];
}
}
module.exports = MotionDigitalSensor