Last active
August 29, 2015 13:58
-
-
Save seriousManual/10037972 to your computer and use it in GitHub Desktop.
i2c blocking
This file contains 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
console.log('init'); | |
var bar = new Foo(); | |
console.log('bind'); | |
bar.on('initialize', function() { | |
console.log('init received'); | |
}); |
This file contains 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
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); | |
}); | |
} |
This file contains 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
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