theoctal / octalbonescript

A more stable, continuously tested and better node.js library for scripting your BeagleBone
MIT License
57 stars 9 forks source link

Multiple i2c Devices same device #68

Closed Andrewiski closed 8 years ago

Andrewiski commented 8 years ago

I2c allows multiple i2c devices onsame linux device with different i2c addresses. Current code base is indexing the internal i2c by device "'/dev/i2c-1" and not '/dev/i2c-1' + i2c address calls to open multiple i2c slaves with different address causes all previous devices to have the address of the last device opened. Can be displayed by console.log(port) of the returned port object. If multiple calls are made the expected result should be the same as i2c in that the returned port object retain there address and can be used as separate instances of port + address

In its current implementation before every i2c call the port.address property would need to be set first. This is not how i2c.open is implemented in https://github.com/kelly/node-i2c

internally we should be indexing the open calls by both path and address.

ie

i2c.openPorts[path + ':' + address] = port;

`open: function(path, address, handler, callback) { debug("i2c.open(" + path + ", " + address + ")");

    if (!i2c.ports[path]) {
        throw new verror("Supplied path:" + path + " is not a vaild i2c port path.");
    }

    if (typeof handler != "function" || typeof callback != 'function') {
        throw new verror("handler and callback must be provided to i2c.open and both should be functions");
    }

    module.exports.enable(path, onI2CEnable);

    function onI2CEnable(err) {
        if (err) {
            throw new verror(err);
        }

        if (!i2c.openPorts[path]) {
            var port = new i2cPort(address, {
                device: i2c.ports[path].path
            });
            debug('opened i2c port: ' + path);
            port.on('data', handler);
            i2c.openPorts[path] = port;
            if (callback) callback(null, i2c.openPorts[path]);
        } else {
            if (callback) callback(null, i2c.openPorts[path]);
        }
    }
},`
adityapatadia commented 8 years ago

Can you please create PR if you are sure how to solve this issue?

Andrewiski commented 8 years ago

Sure I can make a Pull Request for fixing multiple I2c on same device. Would you like me to have a go at fixing the loading of universial capes using
@RobertCNelson logic from his boot script as well

https://github.com/RobertCNelson/boot-scripts/blob/master/boot/am335x_evm.sh#L321-L407

RobertNelson commented 8 years ago

Hey guys,

@RobertNelson is NOT @RobertCNelson. :-)

While I have the deepest respect for boot scripts, I can’t be of much help writing or modifying them.

Thanks,

@RobertNelson

On May 31, 2016, at 11:25 AM, Andrew DeVries notifications@github.com wrote:

Sure I can make a Pull Request for fixing multiple I2c on same device. Would you like me to have a go at fixing the loading of universial capes using

@RobertNelson https://github.com/RobertNelson logic from his boot script as well

https://github.com/RobertCNelson/boot-scripts/blob/master/boot/am335x_evm.sh#L321-L407 https://github.com/RobertCNelson/boot-scripts/blob/master/boot/am335x_evm.sh#L321-L407 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/theoctal/octalbonescript/issues/68#issuecomment-222776518, or mute the thread https://github.com/notifications/unsubscribe/AANHN-i27nIuQD_lBRdF6prdeTXQKGlOks5qHHz8gaJpZM4IqGKY.

adityapatadia commented 8 years ago

Hi @Andrewiski what do you mean by fixing universal cape loading? You can work and create PR if you feel it will improve OBS. I almost always merge PRs which are crafted well.

Andrewiski commented 8 years ago

Pull request https://github.com/theoctal/octalbonescript/pull/69 posted. Note breaking change on some i2c methods methods as address must be passed in with path but suspect most users of the open function just use the returned port objects calls not call your exposed methods anyways.

Andrewiski commented 8 years ago

@adityapatadia Did you get a chance to look over my suggested changes to fix multiple calls to i2c and fix for Universal Cape already being loaded?

adityapatadia commented 8 years ago

I am sorry I could not get time. I will give a shot this weekend.

Andrewiski commented 8 years ago

@adityapatadia Any update on this pull request or should I just start using my own branch in my applications.