Source: examples/servers/node/managers/node_modules/EspruinoEmulationLayer.js

/**
 * @classdesc Class representing an Espruino Pin.
 * @author Loris Tissino (http://loris.tissino.it)
 * @release 0.71
 * @license MIT
 * @see http://www.espruino.com/Reference#Pin
 * @constructor
 */
var Pin = function ( value ) {
    this._info = { port: value.charAt(0), num: parseInt(value.substr(1)) };
    this._mode = undefined
    this._inputState = undefined;
    this._outputState = undefined;
}

/**
 * Get information about this pin and its capabilities.
 * @returns {Object} An object containing information about this pin
 */
Pin.prototype.getInfo = function getInfo () {
    return this._info;
}

/**
 * Returns the current mode of the given pin.
 * @returns {string} The pin mode, as a string
 */
Pin.prototype.getMode = function getMode () {
    return this._mode;
}

/**
 * Set the mode of the given pin.
 * @param {string} mode - The mode, a string that is either 'analog',
 * 'input', 'input_pullup', 'input_pulldown', 'output', 'opendrain',
 * 'af_output' or 'af_opendrain'
 */
Pin.prototype.mode = function mode ( mode ) {
    if ( [
        'analog',
        'input',
        'input_pullup',
        'input_pulldown',
        'output',
        'opendrain',
        'af_output',
        'af_opendrain'
        ].indexOf ( mode ) < 0 ) {
        throw "Mode not allowed";
    }
    
    this._mode = mode;
}

/**
 * Returns the input state of the pin as a boolean.
 * @returns {boolean} The input state
 */
Pin.prototype.read = function read () {
    if ( typeof this.mode === 'undefined' ) {
        this._mode = 'input';
    }
    return this._inputState;
}

/**
 * Sets the output state of the pin to a 0.
 */
Pin.prototype.reset = function reset () {
    this.write ( 0 );
}

/**
 * Sets the output state of the pin to a 1.
 */
Pin.prototype.set = function set () {
    this.write ( 1 );
}

/**
 * Sets the output state of the pin to the parameter given.
 * @param {mixed} value - Whether to set output high (true/1) or low (false/0)
 */
Pin.prototype.write = function write ( value ) {
    if ( typeof this._mode === 'undefined' ) {
        this._mode = 'output';
    }
    this._outputState = value;
}

/**
 * Sets the output state of the pin to the parameter given at the specified time.
 * @param {mixed} - Whether to set output high (true/1) or low (false/0)
 * @param {float} - Time at which to write
 * @throws "Not implemented"
 */
Pin.prototype.writeAtTime = function writeAtTime ( value, time ) {
    throw "Not implemented.";
}

/**
 * Returns the last output to the Pin.
 * @returns {boolean} The last output
 */
Pin.prototype.xGetLastOutput = function () {
    return this._outputState;
}

/**
 * @classdesc This is the emulation of the built-in JavaScript class for Espruino utility functions.
 * @author Loris Tissino (http://loris.tissino.it)
 * @release 0.71
 * @license MIT
 * @see http://www.espruino.com/Reference#E
 * @constructor
 */
var E = function () {}

/**
 * Clip a number to be between min and max (inclusive).
 * @param {float} x - A floating point value to clip
 * @param {float} min - The smallest the value should be
 * @param {float} max - The largest the value should be
 * @returns {float} The value of x, clipped so as not to be below min or above max.
 */
E.clip = function (x, min, max) {
    return Math.max(min, Math.min(x, max));
}

exports.Pin = Pin;
exports.E = E;

/**
 * Get the analog value of the given pin.
 * @param {Pin} pin - The pin to use
 */
exports.analogRead = function (pin) {
    return pin.read ( );
}

/**
 * Set the analog Value of a pin. It will be output using PWM.
 * @param {Pin} pin - The pin to use
 * @param {float} value - A value between 0 and 1
 * @param {Object} options - An object containing options for analog output
 */
exports.analogWrite = function (pin, value, options) {
    pin.write ( value );
    // TODO: check whether we should consider the options (probably the value between 0 and 1 will suffice)
}

/**
 * Pulse the pin with the value for the given time in milliseconds.
 * @param {Pin} pin - The pin to use
 * @param {mixed} - Whether to set output high (true/1) or low (false/0)
 * @param {float} - A time in milliseconds
 * @throws "Not implemented"
 */
exports.digitalPulse = function (pin, value, time) {
    throw "Not implemented";
}

/**
 * Get the digital value of the given pin.
 * @param {Pin} pin - The pin to use
 * @return {boolean} The digital Value of the Pin
 */
exports.digitalRead = function (pin) {
    return pin.read ( );
    // TODO: implement the 'array of pins' signature
}

/**
 * Get the digital value of the given pin.
 * @param {Pin} pin - The pin to use
 * @return {boolean} The digital Value of the Pin
 */
exports.digitalWrite = function (pin, value) {
    pin.write ( value );
    // TODO: implement the 'array of pins' signature
}

/**
 * Returns the current mode of the given pin.
 * @param {Pin} pin - The pin to check
 * @return {string} The pin mode, as a string
 */
exports.getPinMode = function ( pin ) {
    return pin.getMode();
}

/**
 * Set the mode of the given pin.
 * @param {Pin} pin - The pin to set pin mode for
 * @param {string} mode - The mode
 */
exports.pinMode = function ( pin, mode ) {
    pin.mode( mode );
}

exports.getTime = function () {
    throw "Not implemented";
}

exports.HIGH = 1;

exports.LOW = 0;

exports.print = function ( text ) {
    throw "Not implemented";
}

exports.reset = function () {
    throw "Not implemented";
}

exports.setBusyIndicator = function ( pin ) {
    throw "Not implemented";
}

exports.setDeepSleep = function ( sleep ) {
    throw "Not implemented";
}

exports.changeInterval = function ( id, time ) {
    throw "Not implemented";
}

exports.clearWatch = function ( id ) {
    throw "Not implemented";
}

exports.getSerial = function () {
    throw "Not implemented";
}

exports.setSleepIndicator = function (pin) {
    throw "Not implemented";
}

exports.setTime = function ( time ) {
    throw "Not implemented";
}

exports.setWatch = function ( f, pin, options ) {
    throw "Not implemented";
}

exports.shiftOut = function ( pins, options, data ) {
    throw "Not implemented";
}