'use strict' // ********************************** class Device { // bus is i2c-bus bus object constructor(bus, address, opts) { this.bus = bus this.address = address if (opts) { this.id = opts.id // must be unique within a bus this.desc = opts.desc } } // for devices needing a buffer/stream readRaw(length, buffer) { return this.bus.readRaw(this.address, length, buffer) } writeRaw(length, buffer) { return this.bus.writeRaw(this.address, length, buffer) } // both cmd and byte should be a single byte as a decimal or hex read(cmd) { return this.bus.read(this.address, cmd) } write(cmd, byte) { return this.bus.write(this.address, cmd, byte) } // for I2C devices that use a word length packackage read2(cmd) { return this.bus.read2(this.address, cmd) } write2(cmd, bytes) { return this.bus.write2(this.address, cmd, bytes) } } module.exports = { Device }