rpi-gpio.js
function setRaspberryVersion() {
        if (currentPins) {
            return Promise.resolve();
        }

        return new Promise(function(resolve, reject) {
            fs.readFile('/proc/cpuinfo', 'utf8', function(err, data) {
                if (err) {
                    return reject(err);
                }

                // Match the last 4 digits of the number following "Revision:"
                var match = data.match(/Revision\s*:\s*[0-9a-f]*([0-9a-f]{4})/);

                if (!match) {
                    var errorMessage = 'Unable to match Revision in /proc/cpuinfo: ' + data;
                    return reject(new Error(errorMessage));
                }

                var revisionNumber = parseInt(match[1], 16);
                var pinVersion = (revisionNumber < 4) ? 'v1' : 'v2';

                debug(
                    'seen hardware revision %d; using pin mode %s',
                    revisionNumber,
                    pinVersion
                );

                // Create a list of valid BCM pins for this Raspberry Pi version.
                // This will be used to validate channel numbers in getPinBcm
                currentValidBcmPins = []
                Object.keys(PINS[pinVersion]).forEach(
                  function(pin) {
                    // Lookup the BCM pin for the RPI pin and add it to the list
                    currentValidBcmPins.push(PINS[pinVersion][pin]);
                  }
                );

                currentPins = PINS[pinVersion];

                return resolve();
            });
        });
    }
function setRaspberryVersion() {
        if (currentPins) {
            return Promise.resolve();
        }

        return new Promise(function(resolve, reject) {
            fs.readFile('/proc/cpuinfo', 'utf8', function(err, data) {
                if (err) {
                    return reject(err);
                }

                // Match the last 4 digits of the number following "Revision:"
                var match = data.match(/Revision\s*:\s*[0-9a-f]*([0-9a-f]{4})/);

                if (!match) {
                    var errorMessage = 'Unable to match Revision in /proc/cpuinfo: ' + data;
                    return reject(new Error(errorMessage));
                }

                var revisionNumber = parseInt(match[1], 16);
                var pinVersion = (revisionNumber < 4) ? 'v1' : 'v2';

                debug(
                    'seen hardware revision %d; using pin mode %s',
                    revisionNumber,
                    pinVersion
                );

                // Create a list of valid BCM pins for this Raspberry Pi version.
                // This will be used to validate channel numbers in getPinBcm
                currentValidBcmPins = []
                Object.keys(PINS[pinVersion]).forEach(
                  function(pin) {
                    // Lookup the BCM pin for the RPI pin and add it to the list
                    currentValidBcmPins.push(PINS[pinVersion][pin]);
                  }
                );

                currentPins = PINS[pinVersion];

                return resolve();
            });
        });
    }
function setRaspberryVersion ( ) { if ( currentPins ) { return Promise . resolve ( ) ; } return new Promise ( function ( resolve , reject ) { fs . readFile ( '/proc/cpuinfo' , 'utf8' , function ( err , data ) { if ( err ) { return reject ( err ) ; } // Match the last 4 digits of the number following "Revision:" var match = data . match ( / Revision\s*:\s*[0-9a-f]*([0-9a-f]{4}) / ) ; if ( ! match ) { var errorMessage = 'Unable to match Revision in /proc/cpuinfo: ' + data ; return reject ( new Error ( errorMessage ) ) ; } var revisionNumber = parseInt ( match [ 1 ] , 16 ) ; var pinVersion = ( revisionNumber < 4 ) ? 'v1' : 'v2' ; debug ( 'seen hardware revision %d; using pin mode %s' , revisionNumber , pinVersion ) ; // Create a list of valid BCM pins for this Raspberry Pi version. // This will be used to validate channel numbers in getPinBcm currentValidBcmPins = [ ] Object . keys ( PINS [ pinVersion ] ) . forEach ( function ( pin ) { // Lookup the BCM pin for the RPI pin and add it to the list currentValidBcmPins . push ( PINS [ pinVersion ] [ pin ] ) ; } ) ; currentPins = PINS [ pinVersion ] ; return resolve ( ) ; } ) ; } ) ; }
Private functions requring access to state
Private functions requring access to state