-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from amperka/i2c-hub
add i2c_hub module
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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
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); | ||
}; |