I have the following code:
regRead8: function(address){
wire.write([address & 0xFF, address >> 8], function(err){
if (!err == null) {
console.log(err)
}
})
wire.read(1, function(err, res){
if (!err == null) {
console.log(err)
}
})
}
regRead8 is a function that takes a parameter (address) and is doing two things:
- Is writing to an FPGA the address from where the next command should read.
- The read command reads 1 byte of information from the latter selected register
Now, I want that function regRead8() to return the value obtained in the second function (i.e wire.read()...
regRead8(registerValueGoesHere) will be part another function that would return the value of the register specified.
I'm using a library called i2c that forces me to use this way of function with a callback, otherwise it errors.
What should I do?