uci-i2c-bus/lib/device.js

50 lines
962 B
JavaScript
Raw Normal View History

2017-01-12 19:50:06 -08:00
'use strict'
// **********************************
class Device {
2017-01-13 21:13:39 -08:00
// bus is i2c-bus bus object
constructor(bus, address, opts) {
this.bus = bus.methods // artifact of adapting ic2-bus to class format
this.address = address
if (opts) {
this.id = opts.id // must be unique within a bus
this.desc = opts.desc
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
readRaw(length, buffer) {
return this.bus.i2cRead_p(this.address, length, buffer)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
writeRaw(length, buffer) {
return this.bus.i2cWrite_p(this.address, length, buffer)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
read(cmd) {
return this.bus.readByte_p(this.address, cmd)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
write(cmd, byte) {
return this.bus.writeByte_p(this.address, cmd, byte)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
read2(cmd) {
return this.bus.readWord_p(this.address, cmd)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
write2(cmd, bytes) {
return this.bus.writeWord_p(this.address, cmd, bytes)
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
// command with more than two bytes following
readBytes() {}
writeBytes() {}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
module.exports = {
Device
}