index.js
function raspi_i2c_devname()
{
    try {
        var revisionBuffer = fs.readFileSync('/sys/module/bcm2708/parameters/boardrev');
        var revisionInt = parseInt(revisionBuffer.toString(), 10);
        //console.log('Raspberry Pi board revision: ', revisionInt);
        // Older boards use i2c-0, newer boards use i2c-1
        if ((revisionInt === 2) || (revisionInt === 3)) {
            return '/dev/i2c-0';
        }
        else {
            return '/dev/i2c-1';
        }
    }
    catch(e) {
        if (e.code === 'ENOENT') {
            //console.log('Not a Raspberry Pi');
            return '';
        }
        else {
            throw e;
        }
    }
}
function raspi_i2c_devname()
{
    try {
        var revisionBuffer = fs.readFileSync('/sys/module/bcm2708/parameters/boardrev');
        var revisionInt = parseInt(revisionBuffer.toString(), 10);
        //console.log('Raspberry Pi board revision: ', revisionInt);
        // Older boards use i2c-0, newer boards use i2c-1
        if ((revisionInt === 2) || (revisionInt === 3)) {
            return '/dev/i2c-0';
        }
        else {
            return '/dev/i2c-1';
        }
    }
    catch(e) {
        if (e.code === 'ENOENT') {
            //console.log('Not a Raspberry Pi');
            return '';
        }
        else {
            throw e;
        }
    }
}
function raspi_i2c_devname ( ) { try { var revisionBuffer = fs . readFileSync ( '/sys/module/bcm2708/parameters/boardrev' ) ; var revisionInt = parseInt ( revisionBuffer . toString ( ) , 10 ) ; //console.log('Raspberry Pi board revision: ', revisionInt); // Older boards use i2c-0, newer boards use i2c-1 if ( ( revisionInt === 2 ) || ( revisionInt === 3 ) ) { return '/dev/i2c-0' ; } else { return '/dev/i2c-1' ; } } catch ( e ) { if ( e . code === 'ENOENT' ) { //console.log('Not a Raspberry Pi'); return '' ; } else { throw e ; } } }
If the system is a Raspberry Pi return the correct i2c device name. Else return empty string.
If the system is a Raspberry Pi return the correct i2c device name . Else return empty string .