UNPKG

obniz

Version:

obniz sdk for javascript

42 lines (35 loc) 996 B
class _24LC256 { constructor() { this.requiredKeys = ['address']; this.keys = ['sda', 'scl', 'clock', 'pull', 'i2c', 'address']; } static info() { return { name: '24LC256', }; } wired(obniz) { this.params.mode = this.params.mode || 'master'; //for i2c this.params.clock = this.params.clock || 400 * 1000; //for i2c this.i2c = obniz.getI2CWithConfig(this.params); } // Module functions set(address, data) { let array = []; array.push((address >> 8) & 0xff); array.push(address & 0xff); array.push.apply(array, data); this.i2c.write(0x50, array); this.obniz.wait(4 + 1); // write cycle time = 4ms for 24XX00, 1.5ms for 24C01C, 24C02C } async getWait(address, length) { let array = []; array.push((address >> 8) & 0xff); array.push(address & 0xff); this.i2c.write(0x50, array); return await this.i2c.readWait(0x50, length); } } if (typeof module === 'object') { module.exports = _24LC256; }