uci-i2c-device/lib/device.js

46 lines
795 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
2017-01-13 21:13:39 -08:00
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.readRaw(this.address, length, buffer)
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
writeRaw(length, buffer) {
return this.bus.writeRaw(this.address, length, buffer)
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
read(cmd) {
return this.bus.read(this.address, cmd)
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
write(cmd, byte) {
return this.bus.write(this.address, cmd, byte)
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
read2(cmd) {
return this.bus.read2(this.address, cmd)
2017-01-13 21:13:39 -08:00
}
2017-01-12 19:50:06 -08:00
2017-01-13 21:13:39 -08:00
write2(cmd, bytes) {
return this.bus.write2(this.address, cmd, bytes)
2017-01-13 21:13:39 -08:00
}
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
}