Skip to content

Commit

Permalink
Merge pull request #70 from amperka/i2c-hub
Browse files Browse the repository at this point in the history
add i2c_hub module
  • Loading branch information
PSVM-J authored Aug 27, 2018
2 parents e6bb6a5 + 45096b7 commit ff0a367
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/@amperka/i2c-hub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function TroykaI2CHub(opts) {
opts = opts || {}
var _channel = 0;
var _address = opts.address || 0x70;
var _i2c = opts.i2c || PrimaryI2C;
var _enableMask = 0x08;

this.setBusChannel = function(channel) {
if ((channel < 0) || (channel >= 8)) {
return;
}
_channel = channel;
_i2c.writeTo(_address, _channel | _enableMask);
};

this.getBusChannel = function() {
return _channel;
};
this.setBusChannel(0);
}

exports.connect = function(opts) {
return new TroykaI2CHub(opts);
};

0 comments on commit ff0a367

Please sign in to comment.