Skip to content

Instantly share code, notes, and snippets.

@seriousManual
Last active August 29, 2015 13:58
Show Gist options
  • Save seriousManual/10037972 to your computer and use it in GitHub Desktop.
Save seriousManual/10037972 to your computer and use it in GitHub Desktop.
i2c blocking
console.log('init');
var bar = new Foo();
console.log('bind');
bar.on('initialize', function() {
console.log('init received');
});
function Foo() {
Emitter.call(this);
this._init(function(error) {
console.log('init done');
if (error) {
that.emit('error', error);
} else {
that.emit('initialize');
}
});
}
util.inherits(Foo, Emitter);
Foo.prototype._init = function(callback) {
this._wire = new I2c(FOO_ADDRESS, {device: '/dev/i2c-1'});
that._wire.writeBytes(CMD_ENABLE_OUTPUT, [0x01], function(error) {
if(error) return callback(error);
that._wire.writeBytes(FOO_CMD, [0xFF, 0xFF, 0xFF], callback);
});
}
actual outcome:
-----------------
init
init done
bind
expected outcome:
-----------------
init
bind
init done
init received
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment