Skip to content

Commit

Permalink
Added IR receiver support
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellobarile committed Jun 7, 2015
1 parent 0ba04a2 commit c1e61b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Software/NodeJS/libs/commands.js
Expand Up @@ -73,6 +73,12 @@ module.exports = {
// Sets leds similar to a bar graph, reversible
, chainableRgbLedSetLevel : [95]

// Grove IR sensor
// Read the button from IR sensor
, irRead : [21]
// Set pin for the IR reciever
, irRecvPin : [22]

// This allows us to be more specific about which commands contain unused bytes
, unused : 0
};
1 change: 1 addition & 0 deletions Software/NodeJS/libs/index.js
Expand Up @@ -18,5 +18,6 @@ module.exports.GrovePi = {
, RTCI2C: require('./sensors/rtcI2cSensor')
, TemperatureAnalog: require('./sensors/temperatureAnalogSensor')
, UltrasonicDigital: require('./sensors/ultrasonicDigitalSensor')
, IRReceiver: require('./sensors/IRReceiverSensor')
}
}
33 changes: 33 additions & 0 deletions Software/NodeJS/libs/sensors/IRReceiverSensor.js
@@ -0,0 +1,33 @@
var util = require('util')
var Sensor = require('./base/sensor')
var commands = require('../commands')

function IRReceiverSensor(pin) {
pin += 1
Sensor.apply(this, Array.prototype.slice.call(arguments))
this.pin = pin
}
util.inherits(IRReceiverSensor, Sensor);
IRReceiverSensor.prototype = new DigitalSensor()

IRReceiverSensor.prototype.read = function() {
this.write(commands.unused)
var writeRet = this.board.writeBytes(commands.irRead.concat([commands.unused, commands.unused, commands.unused]))
if (writeRet) {
this.board.readByte()
var bytes = this.board.readBytes(22)
if (bytes instanceof Buffer && bytes[1] != 255) {
bytes.slice(0,1)
return bytes
} else {
return false
}
} else {
return false
}
}
IRReceiverSensor.prototype.write = function(value) {
return this.board.writeBytes(commands.irRecvPin.concat([this.pin, value, commands.unused]))
}

module.exports = DigitalSensor

0 comments on commit c1e61b6

Please sign in to comment.