first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
43
Software/NodeJS/libs/sensors/encoderDigitalSensor.js
Normal file
43
Software/NodeJS/libs/sensors/encoderDigitalSensor.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// TODO: call disable function on exit
|
||||
var DigitalSensor = require('./base/digitalSensor')
|
||||
var commands = require('../commands')
|
||||
|
||||
function EncoderDigitalSensor(pin) {
|
||||
DigitalSensor.apply(this, Array.prototype.slice.call(arguments))
|
||||
}
|
||||
EncoderDigitalSensor.prototype = new DigitalSensor()
|
||||
|
||||
EncoderDigitalSensor.prototype.read = function() {
|
||||
var write = this.board.writeBytes(commands.encoderRead.concat([this.pin, commands.unused, commands.unused]))
|
||||
if (write) {
|
||||
this.board.wait(200)
|
||||
this.board.readByte()
|
||||
var bytes = this.board.readBytes()
|
||||
if (bytes instanceof Buffer && bytes[1] != 255)
|
||||
return [bytes[1], bytes[2]]
|
||||
else
|
||||
return false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
EncoderDigitalSensor.prototype.enable = function() {
|
||||
var write = this.board.writeBytes(commands.encoderEn.concat([commands.unused, commands.unused, commands.unused]))
|
||||
if (write) {
|
||||
this.board.wait(200)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
EncoderDigitalSensor.prototype.disable = function() {
|
||||
var write = this.board.writeBytes(commands.encoderDis.concat([commands.unused, commands.unused, commands.unused]))
|
||||
if (write) {
|
||||
this.board.wait(200)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EncoderDigitalSensor
|
||||
Loading…
Add table
Add a link
Reference in a new issue