first commit

This commit is contained in:
pandacraft 2025-03-21 16:04:17 +01:00
commit a5a0434432
1126 changed files with 439481 additions and 0 deletions

View file

@ -0,0 +1,33 @@
var util = require('util')
var Sensor = require('./sensor')
var commands = require('../../commands')
function AnalogSensor(pin) {
Sensor.apply(this, Array.prototype.slice.call(arguments))
this.pin = pin
}
util.inherits(AnalogSensor, Sensor)
AnalogSensor.prototype = new AnalogSensor()
AnalogSensor.prototype.read = function(length) {
if (typeof length == 'undefined')
length = this.board.BYTESLEN
var writeRet = this.board.writeBytes(commands.aRead.concat([this.pin, commands.unused, commands.unused]))
if (writeRet) {
this.board.readByte()
var bytes = this.board.readBytes(length)
if (bytes instanceof Buffer) {
return bytes[1] * 256 + bytes[2]
} else {
return false
}
} else {
return false
}
}
AnalogSensor.prototype.write = function(value) {
return this.board.writeBytes(commands.aWrite.concat([this.pin, value, commands.unused]))
}
module.exports = AnalogSensor