From 45096b7050d2b5e0bd56848a34a306348d5e459e Mon Sep 17 00:00:00 2001 From: PSVM-J <39494832+PSVM-J@users.noreply.github.com> Date: Tue, 7 Aug 2018 20:11:05 +0300 Subject: [PATCH] add i2c_hub module --- modules/@amperka/i2c-hub.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 modules/@amperka/i2c-hub.js diff --git a/modules/@amperka/i2c-hub.js b/modules/@amperka/i2c-hub.js new file mode 100644 index 0000000..85330e4 --- /dev/null +++ b/modules/@amperka/i2c-hub.js @@ -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); +};