Last active
March 12, 2017 15:16
-
-
Save DrewDahlman/8d48b3fb4e06730fab75c066f230fe95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const REGISTRY = require('./registry'); | |
class i2cInterface { | |
/* | |
------------------------------------------ | |
| construct:void (-) | |
------------------------------------------ */ | |
constructor(){ | |
this._readRegisters( REGISTRY.OSC_CALIBRATE_VAL, 16, (err, data) => { | |
console.log(data.readInt16BE(8)); | |
}); | |
} | |
/* | |
------------------------------------------ | |
| _readRegisters:void (-) | |
| | |
| Read the registers via I2C. | |
------------------------------------------ */ | |
_readRegisters(addressToRead, bytesToRead, callback){ | |
this.queue.place( () => { | |
this.i2c.transfer( new Buffer([addressToRead]), bytesToRead, (err, data) => { | |
this.queue.next(); | |
if( callback ){ | |
callback(err, data); | |
} | |
}) | |
}); | |
} | |
/* | |
------------------------------------------ | |
| _writeRegisters:void (-) | |
| | |
| Write to the register via I2C. | |
------------------------------------------ */ | |
_writeRegisters(addressToRead, dataToWrite, callback){ | |
// console.log(addressToRead, dataToWrite, callback); | |
this.queue.place( () => { | |
this.i2c.send( new Buffer([addressToRead, dataToWrite]), (err, data) => { | |
this.queue.next(); | |
if( callback ){ | |
callback(err, data); | |
} | |
}) | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment