first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
25
Software/NodeJS/libs/sensors/base/digitalSensor.js
Normal file
25
Software/NodeJS/libs/sensors/base/digitalSensor.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
var util = require('util')
|
||||
var Sensor = require('./sensor')
|
||||
var commands = require('../../commands')
|
||||
|
||||
function DigitalSensor(pin) {
|
||||
Sensor.apply(this, Array.prototype.slice.call(arguments))
|
||||
this.pin = pin
|
||||
}
|
||||
util.inherits(DigitalSensor, Sensor)
|
||||
DigitalSensor.prototype = new DigitalSensor()
|
||||
|
||||
DigitalSensor.prototype.read = function() {
|
||||
var writeRet = this.board.writeBytes(commands.dRead.concat([this.pin, commands.unused, commands.unused]))
|
||||
if (writeRet) {
|
||||
this.board.wait(100)
|
||||
return this.board.readBytes(2)[1]
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
DigitalSensor.prototype.write = function(value) {
|
||||
return this.board.writeBytes(commands.dWrite.concat([this.pin, value, commands.unused]))
|
||||
}
|
||||
|
||||
module.exports = DigitalSensor
|
||||
Loading…
Add table
Add a link
Reference in a new issue