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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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) {
|
2017-01-15 17:59:50 -08:00
|
|
|
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
|
|
|
|
}
|