Skip to content

A few issues... #2

@Pecacheu

Description

@Pecacheu

This is a great Node.js module! I was able to get it working on my Odroid C1+, after installing gpio-admin (you might want to make that step bold, it's kind-of essential). However, I did encounter a small few issues with it...

  1. First the simple problem... Theres stray references to the Raspberry Pi in the documentation. This is confusing, because obviously, the Odroid is a completely unique and original product that doesn't steal from anything else in any way. Yep. Totally not a Raspberry Pi.
  2. Pins that are open when Node is stopped with process.exit() aren't closed, and open throws an error when trying to open the pin again.
  3. When functions error out, sometimes they they throw a Javascript error, even though a callback is registered.
  4. getDirection has no way of telling you that a pin isn't open. In my make-shift openPin wrapper function, I put getDirection in a try/catch statement to determine if a pin was opened by something else (I use an array to store pins opened by the application though). But theres a problem with this method too. getDirection will print some stuff about "no such file or directory" into the terminal when it errors out, which looks kind-of ugly, and makes it obvious that this wrapper function isn't very stable.
  5. This one is more of a feature request, but what about the ADC, SPI, I2C, and UART pins? The one I'd consider most important here is probably I2C, because the ADC pins are only 1.8v, making them fairly useless, but the I2C bus could be used to interface with a 3.3v or 5v ADC chip, or a serial-based I/O expander, or an LED driver, or even an Arduino!

BTW, heres my openPin function:

function openPin(pin, inOut, callback) {
    if(openPins[pin]) pChgLogic(openPins[pin], true);
    else try { gpio.getDirection(pin, function(err, cInOut) {
        if(err) { if(callback) callback(err); } else pChgLogic(cInOut, true);
    }); } catch(e) {pChgLogic(cInOut, false)} //getDirection errors out if the pin isn't open.
    function pChgLogic(cVal, isOpen) {
        if(!isOpen) {
            try { gpio.open(pin, inOut, function(err) {
                if(!err) openPins[pin] = inOut;
                if(callback) callback(err);
            }); } catch(e) {if(callback) callback(e)}
        } else if(cVal != inOut) {
            try { gpio.setDirection(pin, inOut, function(err) {
                if(!err) openPins[pin] = inOut;
                if(callback) callback(err);
            }); } catch(e) {if(callback) callback(e)}
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions