Пример #1
0
 normalize(pin) {
   const normalizedPin = getPinNumber(pin);
   if (typeof normalizedPin == 'undefined') {
     throw new Error('Unknown pin "' + pin + '"');
   }
   return normalizedPin;
 }
Пример #2
0
 pins.map((pin) => {
   pin = getPinNumber(pin);
   this.pins.push(pin);
   if (registeredPins[pin]) {
     registeredPins[pin].destroy();
   }
   registeredPins[pin] = this;
 });
Пример #3
0
 pins.map(function (pin) {
   pin = getPinNumber(pin);
   _this.pins.push(pin);
   if (registeredPins[pin]) {
     registeredPins[pin].destroy();
   }
   registeredPins[pin] = _this;
 });
Пример #4
0
 pins.map((alias) => {
   const pin = getPinNumber(alias);
   if (pin === null) {
     throw new Error('Invalid pin: ' + alias);
   }
   this.pins.push(pin);
   if (registeredPins[pin]) {
     registeredPins[pin].destroy();
   }
   registeredPins[pin] = this;
 });
Пример #5
0
 normalize(pin) {
   return getPinNumber(pin);
 }
Пример #6
0
function RaspiIO({ includePins, excludePins, enableSerial, enableI2C = true } = {}) {
    const options = {
        pluginName: 'Raspi IO',
        pinInfo: clone(raspi_board_1.getPins()),
        platform: {
            base: raspi_1.module,
            gpio: raspi_gpio_1.module,
            led: raspi_led_1.module,
            pwm: raspi_soft_pwm_1.module
        }
    };
    if (enableI2C) {
        options.platform.i2c = raspi_i2c_1.module;
        options.i2cIds = {
            DEFAULT: raspi_board_1.getBoardRevision() === raspi_board_1.VERSION_1_MODEL_B_REV_1 ? 0 : 1
        };
    }
    if (typeof enableSerial === 'undefined') {
        enableSerial =
            raspi_board_1.getBoardRevision() !== raspi_board_1.VERSION_3_MODEL_B &&
                raspi_board_1.getBoardRevision() !== raspi_board_1.VERSION_3_MODEL_A_PLUS &&
                raspi_board_1.getBoardRevision() !== raspi_board_1.VERSION_3_MODEL_B_PLUS &&
                raspi_board_1.getBoardRevision() !== raspi_board_1.VERSION_1_MODEL_ZERO_W;
    }
    if (enableSerial) {
        options.platform.serial = raspi_serial_1.module;
        options.serialIds = {
            DEFAULT: raspi_serial_1.DEFAULT_PORT
        };
    }
    // Clone the pins so the internal object in raspi-board isn't mutated
    if (Array.isArray(includePins)) {
        const newPinMappings = {};
        for (const pin of includePins) {
            const normalizedPin = raspi_board_1.getPinNumber(pin);
            if (normalizedPin === null) {
                throw new Error(`Invalid pin "${pin}" specified in includePins`);
            }
            newPinMappings[normalizedPin] = options.pinInfo[normalizedPin];
        }
        options.pinInfo = newPinMappings;
    }
    else if (Array.isArray(excludePins)) {
        for (const pin of excludePins) {
            const normalizedPin = raspi_board_1.getPinNumber(pin);
            if (normalizedPin === null) {
                throw new Error(`Invalid pin "${pin}" specified in excludePins`);
            }
            delete options.pinInfo[normalizedPin];
        }
    }
    // I2C pins need to be dedicated in Raspi IO, so filter out any peripherals other than I2C on I2C pins
    if (enableI2C) {
        for (const pin in options.pinInfo) {
            if (options.pinInfo[pin].peripherals.indexOf(j5_io_types_1.PeripheralType.I2C) !== -1) {
                options.pinInfo[pin].peripherals = [j5_io_types_1.PeripheralType.I2C];
            }
        }
    }
    // UART pins need to be dedicated in Raspi IO, so filter out any peripherals other than UART on UART pins
    if (enableSerial) {
        for (const pin in options.pinInfo) {
            if (options.pinInfo[pin].peripherals.indexOf(j5_io_types_1.PeripheralType.UART) !== -1) {
                options.pinInfo[pin].peripherals = [j5_io_types_1.PeripheralType.UART];
            }
        }
    }
    return new j5_io_1.J5IO(options);
}