'use strict';

var assert = require('expressive-assertion');
var exec   = require('child_process').exec;
var gpio   = require('../build/Release/gpio.node');
var ts     = require('typesystem');

var initCalled  = false;
var initialized = false;

var init = function (callback) {
    if (initCalled) {
        throw new Error('`gpio.init()` already called');
    }

    initCalled = true;

    exec('cat /proc/cpuinfo | grep Hardware', function (error, stdout) {
        if (error) {
            return callback(error);
        }

        var hardware;

        if (typeof stdout !== 'string' || !(hardware = stdout.trim())) {
            return callback(new Error('unable to detect hardware'));
        }

        if (hardware === 'BCM2708') {
            gpio.init(1);
        } else if (hardware === 'BCM2709') {
            gpio.init(2);
        } else {
            gpio.init(0);
        }

        initialized = true;

        callback(null);
    });
};

var assertIsPin = function (value) {
    assert(function () {
        return ts.isInteger(value) && value >= 0 && value <= 53;
    });
};

var createInput = function (pin, testMode) {
    if (!initialized && !testMode) {
        throw new Error('please call `gpio.init()` first');
    }

    assertIsPin(pin);

    gpio.configureAsInput(pin);

    return function () {
        return !!gpio.getLevel(pin);
    };
};

var createOutput = function (pin, testMode) {
    if (!initialized && !testMode) {
        throw new Error('please call `gpio.init()` first');
    }

    assertIsPin(pin);

    gpio.configureAsOutput(pin);

    return function (level) {
        gpio.setLevel(pin, !!level);
    };
};

exports.init         = init;
exports.createInput  = createInput;
exports.createOutput = createOutput;

@@ -389,13 +389,22 @@
     
-exec(
+var command = 
 'cat
@@ -437,117 +437,88 @@
 ware
-', function (error, stdout) %7B%0A        if (error) %7B%0A            return callback(error);%0A        %7D%0A%0A        var
+ %7C rev %7C cut -d %22:%22 -f 1 %7C rev %7C tr -d %22 %22';%0A%0A    exec(command, function (error,
  har
@@ -522,18 +522,19 @@
 hardware
-;%0A
+) %7B
 %0A       
@@ -542,135 +542,50 @@
 if (
-typeof stdout !== 'string' %7C%7C !(hardware = stdout.trim())) %7B%0A            return callback(new Error('unable to detect hardware')
+error) %7B%0A            return callback(error
 );%0A 

Fix hardware info command