Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add i2c_hub module #70

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok