Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ba04a2
commit c1e61b6
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |