From b5ebe20d096e3b9e5058c0070c1de48a4c45bbe9 Mon Sep 17 00:00:00 2001 From: kekcheburec Date: Fri, 17 Sep 2021 14:44:31 +0300 Subject: [PATCH 1/3] Translation of all comments --- modules/@amperka/Sim900r.js | 52 +++++++++++++------------- modules/@amperka/accelerometer.js | 16 ++++---- modules/@amperka/bluetooth.js | 2 +- modules/@amperka/card-reader.js | 5 +-- modules/@amperka/current.js | 6 +-- modules/@amperka/gas-sensor.js | 62 +++++++++++++++---------------- modules/@amperka/gpio-expander.js | 26 ++++++------- modules/@amperka/magnetometer.js | 14 +++---- modules/@amperka/relay.js | 12 +++--- modules/@amperka/rtc.js | 8 ++-- modules/@amperka/stepper.js | 26 ++++++------- modules/@amperka/x-fet.js | 2 +- 12 files changed, 115 insertions(+), 116 deletions(-) diff --git a/modules/@amperka/Sim900r.js b/modules/@amperka/Sim900r.js index cb943b6..8113bf7 100644 --- a/modules/@amperka/Sim900r.js +++ b/modules/@amperka/Sim900r.js @@ -22,7 +22,7 @@ var Sim900r = function(options) { var self = this; /** - * Настройка триггера пина статуса + * Configuring a status pin trigger */ pinMode(this._statusPin, 'input_pulldown'); setWatch( @@ -42,9 +42,9 @@ var Sim900r = function(options) { ); /** - * При поступлении данные на порт, суммируем их в буффер - * и разделяем по переходу на новую строку, после чего - * обрабатываем их построчно. + * When the data arrives at the port, + * we sum them up in a buffer and divide them by line break, + * after which we process them line by line. */ var dataBuffer = ''; this._serial.on('data', function(data) { @@ -93,17 +93,17 @@ Sim900r.prototype._onDataLine = function(line) { case 'Call Ready': this.emit('simNetwork'); break; - // Если строка равна строке запроса команды, - // то дальше будут передаваться данные + // If the string is equal to the command query string, + // then data will be transmitted further case this._currentCommand: this._currentCommandResponse = true; break; - // Конец ответа на команду + // End of command response case 'OK': this._currentCommandResponse = false; this._currentCommandCallback(undefined, this._currentCommandData); break; - // Ошибка при выполнении команды + // Error while executing command case 'ERROR': this._currentCommandResponse = false; this._currentCommandCallback(new Error('CMD Error')); @@ -118,14 +118,14 @@ Sim900r.prototype._onDataLine = function(line) { }; /* - * Стук к пину включения/выключения + * Knock on the on/off pin */ Sim900r.prototype.power = function() { digitalPulse(this._powerPin, 1, 1000); }; /** - * Включение модуля + * Enabling the module */ Sim900r.prototype.powerOn = function() { if (!this.isReady()) { @@ -143,17 +143,17 @@ Sim900r.prototype.powerOff = function() { }; /** - * Состояние готовности к взаимодейтвию + * Interoperability state */ Sim900r.prototype.isReady = function() { return !!digitalRead(this._statusPin); }; /** - * Вызов команды + * Command call */ Sim900r.prototype.cmd = function(command, callback) { - // Нельзя отправлять новую команду, пока данные от предыдущей не получены + // You can not send a new command until data from the previous one has not been received if (!this.isReady()) { callback(new Error('powerOff')); } else if (!this._currentCommandResponse) { @@ -172,7 +172,7 @@ Sim900r.prototype.cmd = function(command, callback) { }; /** - * Отправка СМС на номер + * Sending SMS to the number */ Sim900r.prototype.smsSend = function(phone, text, callback) { var serial = this._serial; @@ -183,7 +183,7 @@ Sim900r.prototype.smsSend = function(phone, text, callback) { }; /** - * Получение списка SMS + * Retrieving SMS List */ Sim900r.prototype.smsList = function(callback) { var self = this; @@ -208,7 +208,7 @@ Sim900r.prototype.smsList = function(callback) { }; /** - * Чтение СМС с SIM-карты + * Reading SMS from a SIM card */ Sim900r.prototype.smsRead = function(index, callback) { var self = this; @@ -222,7 +222,7 @@ Sim900r.prototype.smsRead = function(index, callback) { }; /** - * Удаление СМС с SIM-карты + * Removing SMS from SIM-card */ Sim900r.prototype.smsDelete = function(index) { var command = 'AT+CMGD=' + index; @@ -235,56 +235,56 @@ Sim900r.prototype.smsDelete = function(index) { }; /** - * Набор номера + * Dialing a number */ Sim900r.prototype.call = function(phone, callback) { this.cmd('ATD' + phone + ';', callback); }; /** - * Ответ на входящий звонок + * Answering an incoming call */ Sim900r.prototype.answer = function(callback) { this.cmd('ATA', callback); }; /** - * Разрыв соединения + * Break the connection */ Sim900r.prototype.cancel = function(callback) { this.cmd('ATH0', callback); }; /** - * Отправка USSD команды + * Sending a USSD command */ Sim900r.prototype.ussd = function(phone, callback) { this.cmd('AT+CUSD=1,"' + phone + '"', callback); }; /** - * Оператор SIM-карты + * SIM card operator */ Sim900r.prototype.netProvider = function(callback) { this.cmd('AT+CSPN?', callback); }; /** - * Оператор, в сети которого зарегистрирована SIM-карта + * Operator in whose network the SIM card is registered */ Sim900r.prototype.netCurrent = function(callback) { this.cmd('AT+COPS?', callback); }; /** - * Статус регистрации в сети + * Online registration status */ Sim900r.prototype.netStatus = function(callback) { this.cmd('AT+CREG?', callback); }; /** - * Качество приема сигнала + * Signal reception quality */ Sim900r.prototype.netQuality = function(callback) { this.cmd('AT+CSQ', callback); @@ -333,7 +333,7 @@ Sim900r.prototype.getCallerID = function(callback) { }; /** - * Методы обработки ответов + * Response processing methods */ Sim900r.prototype.parseSMS = function(fLine, lLine, index) { diff --git a/modules/@amperka/accelerometer.js b/modules/@amperka/accelerometer.js index 2bc12db..9057d1c 100644 --- a/modules/@amperka/accelerometer.js +++ b/modules/@amperka/accelerometer.js @@ -1,19 +1,19 @@ -// Инициализация класса +// Class initialization var LIS331DLH = function(i2c, address) { this._i2c = i2c; address === undefined ? (this._address = 0x18) : (this._address = address); this._sensitivity = 2 / 32767; }; -// Значение ускорения свободного падения +// The value of the acceleration of gravity LIS331DLH.prototype.G = 9.81; -// Метод записывает данные data в регистр reg +// The method writes data to the reg register LIS331DLH.prototype.writeI2C = function(reg, data) { this._i2c.writeTo(this._address, [reg, data]); }; -// Метод производит чтение из регистра reg количестов байт count +// The method reads from the reg register the number of bytes count LIS331DLH.prototype.readI2C = function(reg, count) { if (count === undefined) { count = 1; @@ -22,7 +22,7 @@ LIS331DLH.prototype.readI2C = function(reg, count) { return this._i2c.readFrom(this._address, count); }; -// Метод включает акселерометр +// Method includes accelerometer LIS331DLH.prototype.init = function(opts) { // Normal power, 50Hz, enable X, Y, Z; var config20 = 0x27; /* 00100111 */ @@ -69,7 +69,7 @@ LIS331DLH.prototype.init = function(opts) { this.writeI2C(0x23, config23); }; -// Метод возвращает массив показаний акселерометра +// The method returns an array of accelerometer readings LIS331DLH.prototype.read = function(units) { var d = this.readI2C(0x28, 6); // reconstruct 16 bit data @@ -105,12 +105,12 @@ LIS331DLH.prototype.read = function(units) { return res; }; -// Метод возвращает идентификатор устройства +// The method returns the device identifier LIS331DLH.prototype.whoAmI = function() { return this.readI2C(0x0f)[0]; }; -// Экспортируем класс +// Exporting the class exports.connect = function(i2c, address) { return new LIS331DLH(i2c, address); }; diff --git a/modules/@amperka/bluetooth.js b/modules/@amperka/bluetooth.js index d163cd6..c1a9b5c 100644 --- a/modules/@amperka/bluetooth.js +++ b/modules/@amperka/bluetooth.js @@ -71,7 +71,7 @@ HC05.prototype.command = function(cmd, callback) { this._buffer = ''; var timeout = 0; var self = this; - // Запускать выполнение команды можно только через секунду после старта + // You can run the command only a second after the start if (getTime() - this._lastDataTime < 1) { timeout = this._commandDelay + 1 - (getTime() - this._lastDataTime) * 1000; } diff --git a/modules/@amperka/card-reader.js b/modules/@amperka/card-reader.js index c940a27..750a60e 100644 --- a/modules/@amperka/card-reader.js +++ b/modules/@amperka/card-reader.js @@ -6,9 +6,8 @@ var CardReader = function(opts) { } else { E.connectSDCard(opts.spi, opts.cs); } - // Некоторые модели SD-карт начинают рагировать только со - // второго запроса. Делаем холостой перебор корневой директории, - // чтобы “прогреть” карту в таких случаях + // Some models of SD cards start responding only from the second request. + // We do an idle search of the root directory to “warm up” the map in such cases this._fs.readdirSync(); }; diff --git a/modules/@amperka/current.js b/modules/@amperka/current.js index c0ee7b2..ccce978 100644 --- a/modules/@amperka/current.js +++ b/modules/@amperka/current.js @@ -38,9 +38,9 @@ ACS712.prototype.readEffective = function(period, units) { sqrSum += value * value; } - // Исходная формула — действующее значение переменного тока в интегральном виде. - // Преобразована для дискретного вида, и упрощена по свойству дистрибутивности - // умножения. + // The initial formula is the rms value of the alternating current in integral form. + // Transformed for discrete form, and simplified by the property of + // distributiveness of multiplication var I = Math.sqrt( (sqrSum * this._dividerSQR + this._sumKoef * sum) / numberOfMeasurements + this._constSQR diff --git a/modules/@amperka/gas-sensor.js b/modules/@amperka/gas-sensor.js index c65c7ec..07787ed 100644 --- a/modules/@amperka/gas-sensor.js +++ b/modules/@amperka/gas-sensor.js @@ -3,62 +3,62 @@ var Sensors = { rLoad: 5000, rClear: 9.83, gas: { - LPG: { coef: [-0.45, 2.95], ppm: 1 }, // Сжиженный газ - CH4: { coef: [-0.38, 3.21], ppm: 1 }, // Метан - H2: { coef: [-0.48, 3.32], ppm: 1 }, // Водород - SMOKE: { coef: [-0.42, 3.54], ppm: 1 } // Дым + LPG: { coef: [-0.45, 2.95], ppm: 1 }, // Liquefied gas + CH4: { coef: [-0.38, 3.21], ppm: 1 }, // Methane + H2: { coef: [-0.48, 3.32], ppm: 1 }, // Hydrogen + SMOKE: { coef: [-0.42, 3.54], ppm: 1 } // Smoke } }, MQ3: { rLoad: 200000, rClear: 60, gas: { - C2H5OH: { coef: [-0.66, -0.62], ppm: 1 } // Пары спирта + C2H5OH: { coef: [-0.66, -0.62], ppm: 1 } // Alcohol vapors } }, MQ4: { rLoad: 20000, rClear: 4.4, gas: { - CH4: { coef: [-0.36, 2.54], ppm: 1 } // Метан + CH4: { coef: [-0.36, 2.54], ppm: 1 } // Methane } }, MQ5: { rLoad: 20000, rClear: 6.5, gas: { - LPG: { coef: [-0.39, 1.73], ppm: 1 }, // Сжиженный газ - CH4: { coef: [-0.42, 2.91], ppm: 1 } // Метан + LPG: { coef: [-0.39, 1.73], ppm: 1 }, // Liquefied gas + CH4: { coef: [-0.42, 2.91], ppm: 1 } // Methane } }, MQ6: { rLoad: 20000, rClear: 10, gas: { - LPG: { coef: [-0.42, 2.91], ppm: 1 } // Сжиженный газ + LPG: { coef: [-0.42, 2.91], ppm: 1 } // Liquefied gas } }, MQ7: { rLoad: 10000, rClear: 27, gas: { - CO: { coef: [-0.77, 3.38], ppm: 1 } // Угарный газ; + CO: { coef: [-0.77, 3.38], ppm: 1 } // Carbon monoxide } }, MQ8: { rLoad: 10000, rClear: 70, gas: { - H2: { coef: [-1.52, 10.49], ppm: 1 } // Водород + H2: { coef: [-1.52, 10.49], ppm: 1 } // Hydrogen } }, MQ9: { rLoad: 10000, rClear: 9.8, gas: { - LPG: { coef: [-0.48, 3.33], ppm: 1 }, // Сжиженный газ - CH4: { coef: [-0.38, 3.21], ppm: 1 }, // Метан - CO: { coef: [-0.48, 3.1], ppm: 1 } // Угарный газ; + LPG: { coef: [-0.48, 3.33], ppm: 1 }, // Liquefied gas + CH4: { coef: [-0.38, 3.21], ppm: 1 }, // Methane + CO: { coef: [-0.48, 3.1], ppm: 1 } // Carbon monoxide } }, MQ135: { @@ -91,13 +91,13 @@ var GasSensor = function(opts) { this._model = Sensors[opts.model]; this._intId = null; - this._coef = 1; // Соотношение текущих показаний к показаниям по даташиту - this._times = 5; // Количество считываний для фильтрации - this._preheat = 30; // Время в секундах для разогрева + this._coef = 1; // The ratio of current readings to readings by datasheet + this._times = 5; // Number of reads to filter + this._preheat = 30; // Warm-up time in seconds }; -// Функция калибрует датчик, если значение coef не передано -// Возвращается соотношение текущего сопротивления к сопротивлению по даташиту +// The function calibrates the sensor if no coef value is passed +// Returns the ratio of the current resistance to the resistance according to the datasheet GasSensor.prototype.calibrate = function(coef) { if (coef) { this._coef = coef; @@ -108,7 +108,7 @@ GasSensor.prototype.calibrate = function(coef) { return this._coef; }; -// Метод возвращает возвращает отфильтрованное сопротивление датчика +// The method returns the filtered resistance of the sensor GasSensor.prototype.calculateResistance = function() { var r = 0; for (var i = 0; i < this._times; i++) { @@ -118,7 +118,7 @@ GasSensor.prototype.calculateResistance = function() { return r; }; -// Метод возвращает сопротивление датчика +// The method returns the resistance of the sensor GasSensor.prototype.getResistance = function() { var vTemp = E.getAnalogVRef(); var v = vTemp * analogRead(this._dataPin); @@ -126,7 +126,7 @@ GasSensor.prototype.getResistance = function() { return r; }; -// Возвращает значение в PPM для газа gas +// Returns the PPM value for gas GasSensor.prototype.read = function(gas) { if (gas && this._model.gas[gas] === undefined) { return Error('Gas is undefined'); @@ -142,12 +142,12 @@ GasSensor.prototype.read = function(gas) { return res * this._model.gas[gas].ppm; }; -// Принудительно управляет нагревом c использованием PWM +// Forcibly controls heating using PWM GasSensor.prototype.heat = function(pwr) { analogWrite(this._heatPin, pwr); }; -// Включает предварительный разогрев датчика, после чего выполняет callback +// Turns on the preliminary heating of the sensor, after which it executes a callback GasSensor.prototype.preheat = function(callback) { this.heat(1); if (callback) { @@ -157,28 +157,28 @@ GasSensor.prototype.preheat = function(callback) { } }; -// Функция циклического разогрева для MQ-7 и MQ-9 -// Реализована через setTimeout для того, чтобы не ждать 150 секунд до запуска +// Warm-up function for MQ-7 and MQ-9 +// Implemented via setTimeout to avoid waiting 150 seconds before starting GasSensor.prototype.cycleHeat = function(callback) { if (!callback) { try { clearTimeout(this._intId); this.heat(0); } catch (e) { - // Нет у нас запущенного таймаута + // We have no running timeout } return; } - // Запускаем нагрев от 5 вольт + // We start heating from 5 volts this.heat(1); this._intId = setTimeout(function() { - // Через 60 секунд запускаем нагрев от 1.5 вольт + // After 60 seconds, we start heating from 1.5 volts this.heat(0.294); this._intId = setTimeout(function() { - // Через 90 секунд выполняем + // After 90 seconds, we execute callback(); - // И запускаем цикл повторно + // And we start the cycle again this.cycleHeat(callback); }, 90000); }, 60000); diff --git a/modules/@amperka/gpio-expander.js b/modules/@amperka/gpio-expander.js index bafaa8f..c001b14 100644 --- a/modules/@amperka/gpio-expander.js +++ b/modules/@amperka/gpio-expander.js @@ -1,18 +1,18 @@ var IOcommand = { - WHO_AM_I: 0, // Отдали UID - RESET: 1, // сброс - CHANGE_I2C_ADDR: 2, // сменить I2C-адрес вручную - SAVE_I2C_ADDR: 3, // Сохранить текущий адрес во флэш, чтобы стартовать при последующих включениях с него - PORT_MODE_INPUT: 4, // настроили пины на вход - PORT_MODE_PULLUP: 5, // .. вход с поддтяжкой вверх + WHO_AM_I: 0, // Gave the UID + RESET: 1, // Discharge + CHANGE_I2C_ADDR: 2, // Change I2C address manually + SAVE_I2C_ADDR: 3, // Save the current address to flash to start on subsequent power-ups from it + PORT_MODE_INPUT: 4, // Set up pins to enter + PORT_MODE_PULLUP: 5, // .. entrance with pull up PORT_MODE_PULLDOWN: 6, - PORT_MODE_OUTPUT: 7, // .. на выход - DIGITAL_READ: 8, // считали состояние виртуального порта - DIGITAL_WRITE_HIGH: 9, // Выставили пины виртуального порта в высокий уровень - DIGITAL_WRITE_LOW: 10, // .. в низкий уровень - ANALOG_WRITE: 11, // Запустить ШИМ - ANALOG_READ: 12, // Считать значениие с АЦП - PWM_FREQ: 13, // установка частоты ШИМ (общая для всех PWM-пинов) + PORT_MODE_OUTPUT: 7, // .. to the exit + DIGITAL_READ: 8, // Read the state of the virtual port + DIGITAL_WRITE_HIGH: 9, // Set the pins of the virtual port to a high level + DIGITAL_WRITE_LOW: 10, // .. to a low level + ANALOG_WRITE: 11, // Start PWM + ANALOG_READ: 12, // Read value from ADC + PWM_FREQ: 13, // Setting the PWM frequency (common to all PWM pins) ADC_SPEED: 14 }; diff --git a/modules/@amperka/magnetometer.js b/modules/@amperka/magnetometer.js index f7b7f16..c40b5bb 100644 --- a/modules/@amperka/magnetometer.js +++ b/modules/@amperka/magnetometer.js @@ -5,12 +5,12 @@ var LIS3MDL = function(i2c, address) { address === undefined ? (this._address = 0x1c) : (this._address = address); }; -// Метод записывает данные data в регистр reg +// The method writes data to the reg register LIS3MDL.prototype.write = function(reg, data) { this._i2c.writeTo(this._address, [reg, data]); }; -// Метод производит чтение из регистра reg количестов байт count +// The method reads from the reg register the number of bytes count LIS3MDL.prototype.read = function(reg, count) { if (count === undefined) { count = 1; @@ -19,7 +19,7 @@ LIS3MDL.prototype.read = function(reg, count) { return this._i2c.readFrom(this._address, count); }; -// Старт модуля +// Module start LIS3MDL.prototype.init = function(opts) { // Temp compensation ON, X-axis, Y-axis in High perfomance var config20 = 0xcc; /* 11001100 */ @@ -61,7 +61,7 @@ LIS3MDL.prototype.init = function(opts) { this.write(0x23, 0x8 /* 00001000 */); }; -// Метод возвращает данные с магнитометра +// The method returns data from the magnetometer LIS3MDL.prototype._getRaw = function() { var data = this.read(0x28, 6); var result = { @@ -81,7 +81,7 @@ LIS3MDL.prototype._getRaw = function() { return result; }; -// Метод возвращает данные магнитометра в гуссах +// The method returns the magnetometer data in gauss LIS3MDL.prototype.get = function(units) { var m = this._getRaw(); if (units !== undefined && units === 'G') { @@ -93,12 +93,12 @@ LIS3MDL.prototype.get = function(units) { return m; }; -// Метод возвращает идентификатор устройства +// The method returns the device identifier LIS3MDL.prototype.whoAmI = function() { return this.read(0x0f)[0]; }; -// Экспортируем класс +// Exporting the class exports.connect = function(i2c, address) { return new LIS3MDL(i2c, address); }; diff --git a/modules/@amperka/relay.js b/modules/@amperka/relay.js index de087ca..4f34e85 100644 --- a/modules/@amperka/relay.js +++ b/modules/@amperka/relay.js @@ -7,7 +7,7 @@ var Relay = function(pin) { this._pin.mode('output'); }; -// Переключает реле на противоположное значение и значение val +// Switches the relay to the opposite value and val value Relay.prototype.toggle = function(val) { if (val === undefined) { this._blinkStop(); @@ -19,24 +19,24 @@ Relay.prototype.toggle = function(val) { return this; }; -// Включает реле +// Turns on the relay Relay.prototype.turnOn = function() { this._blinkStop(); this.toggle(true); }; -// Отключает реле +// Disables the relay Relay.prototype.turnOff = function() { this._blinkStop(); this.toggle(false); }; -// Возвращает текущее состояние реле +// Returns the current state of the relay Relay.prototype.isOn = function() { return this._on; }; -// Останавливает действия по таймауту +// Stops actions by timeout Relay.prototype._blinkStop = function() { if (this._blinkTimeoutID) { clearTimeout(this._blinkTimeoutID); @@ -44,7 +44,7 @@ Relay.prototype._blinkStop = function() { } }; -// Включает реле на onTime секунд раз в period секунд +// Turns on relay on onTime seconds once in period seconds Relay.prototype.blink = function(onTime, period) { if (onTime < 0.2) { return new Error('onTime must be > 0.2s'); diff --git a/modules/@amperka/rtc.js b/modules/@amperka/rtc.js index 620365d..8b6382a 100644 --- a/modules/@amperka/rtc.js +++ b/modules/@amperka/rtc.js @@ -1,4 +1,4 @@ -// Инициализация класса +// Class initialization var Rtc = function(i2c) { this._time = undefined; if (i2c) { @@ -11,12 +11,12 @@ var Rtc = function(i2c) { this.start(); }; -// Метод записывает данные data в регистр reg +// The method writes data to the reg register Rtc.prototype.write = function(reg, data) { this._i2c.writeTo(this._address, [reg, data]); }; -// Метод производит чтение из регистра reg количестов байт count +// The method reads from the reg register the number of bytes count Rtc.prototype.read = function(reg, count) { if (count === undefined) { count = 1; @@ -123,7 +123,7 @@ Rtc.prototype.stop = function() { } }; -// Экспортируем класс +// Exporting the class exports.connect = function(i2c) { return new Rtc(i2c); }; diff --git a/modules/@amperka/stepper.js b/modules/@amperka/stepper.js index 71f5479..521bdf7 100644 --- a/modules/@amperka/stepper.js +++ b/modules/@amperka/stepper.js @@ -1,8 +1,8 @@ /** - * Конструктор объекта stepper + * Stepper object constructor * @constructor - * @param {object} pins - объект со свойствами step, direction, enable типа Pin - * @param {Object} opts - объект со свойствами pps (скорость) и holdPower (pwm) + * @param {object} pins - an object with properties step, direction, enable of type Pin + * @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties */ var Stepper = function(pins, opts) { this._pins = pins; @@ -21,8 +21,8 @@ var Stepper = function(pins, opts) { }; /** - * Регулирует ШИМ подачи питания на двигатель - * @param {float} power - Скважность ШИМ от 0 до 1 + * Adjusts the PWM power supply to the motor + * @param {float} power - PWM duty cycle from 0 to 1 */ Stepper.prototype.hold = function(power) { if (this._intervalId !== null) { @@ -37,9 +37,9 @@ Stepper.prototype.hold = function(power) { analogWrite(this._pins.enable, power); }; /** - * Проворачивает вал на step шагов, после чего выполняет callback. - * @param {number} steps - количество шагов. При отрицательном значении происходит движение назад - * @param {function} callback - функция, выполняемая после проворота вала + * Turns the shaft step by step, and then executes a callback. + * @param {number} steps - number of steps. If the value is negative, it moves backwards. + * @param {function} callback - function performed after turning the shaft */ Stepper.prototype.rotate = function(steps, callback) { this.hold(1); @@ -70,7 +70,7 @@ Stepper.prototype.rotate = function(steps, callback) { }; /** - * Регулирует количество шагов в секунду + * Adjusts the number of steps per second */ Stepper.prototype.pps = function(pps) { if (pps === undefined) return this._pps; @@ -79,7 +79,7 @@ Stepper.prototype.pps = function(pps) { }; /** - * Переустанавливает значение удержания вала заданное при инициализации + * Resets the shaft holding value set during initialization */ Stepper.prototype.holdPower = function(holdPower) { if (holdPower === undefined) return this._holdPower; @@ -88,9 +88,9 @@ Stepper.prototype.holdPower = function(holdPower) { }; /** - * Экспорт функции создания объекта Stepper - * @param {object} pins - объект со свойствами step, direction, enable типа Pin - * @param {Object} opts - объект со свойствами pps (скорость) и holdPower (pwm) + * Exporting the Stepper Object Creation Function + * @param {object} pins - an object with properties step, direction, enable of type Pin + * @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties */ exports.connect = function(pins, opts) { return new Stepper(pins, opts); diff --git a/modules/@amperka/x-fet.js b/modules/@amperka/x-fet.js index 1a791ab..6f94cfd 100644 --- a/modules/@amperka/x-fet.js +++ b/modules/@amperka/x-fet.js @@ -3,7 +3,7 @@ var defaultOpts = { spi: SPI2, qtyMod: 1 }; -// + var X_fet = function(opts) { if (typeof opts === 'number') { defaultOpts.cs = opts; From 522b5c6faa7119f62b7cc143658ef42d905cfa41 Mon Sep 17 00:00:00 2001 From: kekcheburec Date: Fri, 17 Sep 2021 15:33:02 +0300 Subject: [PATCH 2/3] Format all comments --- modules/@amperka/Sim900r.js | 84 ++++++++----------------------- modules/@amperka/accelerometer.js | 12 ++--- modules/@amperka/barometer.js | 5 +- modules/@amperka/button.js | 2 +- modules/@amperka/card-reader.js | 6 +-- modules/@amperka/magnetometer.js | 20 ++++---- modules/@amperka/nfc.js | 2 +- modules/@amperka/octoliner.js | 46 ++++++++--------- modules/@amperka/quaddisplay2.js | 2 +- modules/@amperka/stepper.js | 41 ++++++--------- modules/@amperka/telegram.js | 8 +-- modules/@amperka/ultrasonic.js | 12 +---- modules/@amperka/usb-keyboard.js | 4 +- modules/@amperka/wifi.js | 16 +++--- 14 files changed, 97 insertions(+), 163 deletions(-) diff --git a/modules/@amperka/Sim900r.js b/modules/@amperka/Sim900r.js index 8113bf7..df18c93 100644 --- a/modules/@amperka/Sim900r.js +++ b/modules/@amperka/Sim900r.js @@ -21,9 +21,7 @@ var Sim900r = function(options) { var self = this; - /** - * Configuring a status pin trigger - */ + // Configuring a status pin trigger pinMode(this._statusPin, 'input_pulldown'); setWatch( function(e) { @@ -41,11 +39,9 @@ var Sim900r = function(options) { } ); - /** - * When the data arrives at the port, - * we sum them up in a buffer and divide them by line break, - * after which we process them line by line. - */ + // When the data arrives at the port, + // we sum them up in a buffer and divide them by line break, + // after which we process them line by line. var dataBuffer = ''; this._serial.on('data', function(data) { dataBuffer += data; @@ -117,41 +113,31 @@ Sim900r.prototype._onDataLine = function(line) { } }; -/* - * Knock on the on/off pin - */ +// Knock on the on/off pin Sim900r.prototype.power = function() { digitalPulse(this._powerPin, 1, 1000); }; -/** - * Enabling the module - */ +// Enabling the module Sim900r.prototype.powerOn = function() { if (!this.isReady()) { this.power(); } }; -/** - * Выключение модуля - */ +// Выключение модуля Sim900r.prototype.powerOff = function() { if (this.isReady()) { this.power(); } }; -/** - * Interoperability state - */ +// Interoperability state Sim900r.prototype.isReady = function() { return !!digitalRead(this._statusPin); }; -/** - * Command call - */ +// Command call Sim900r.prototype.cmd = function(command, callback) { // You can not send a new command until data from the previous one has not been received if (!this.isReady()) { @@ -171,9 +157,7 @@ Sim900r.prototype.cmd = function(command, callback) { } }; -/** - * Sending SMS to the number - */ +// Sending SMS to the number Sim900r.prototype.smsSend = function(phone, text, callback) { var serial = this._serial; this.cmd('AT+CMGS="' + phone + '"', callback); @@ -182,9 +166,7 @@ Sim900r.prototype.smsSend = function(phone, text, callback) { }, 500); }; -/** - * Retrieving SMS List - */ +// Retrieving SMS List Sim900r.prototype.smsList = function(callback) { var self = this; this.cmd('AT+CMGF=1', function(error) { @@ -207,9 +189,7 @@ Sim900r.prototype.smsList = function(callback) { }); }; -/** - * Reading SMS from a SIM card - */ +// Reading SMS from a SIM card Sim900r.prototype.smsRead = function(index, callback) { var self = this; this.cmd('AT+CMGR=' + index, function(error, result) { @@ -221,9 +201,7 @@ Sim900r.prototype.smsRead = function(index, callback) { }); }; -/** - * Removing SMS from SIM-card - */ +// Removing SMS from SIM-card Sim900r.prototype.smsDelete = function(index) { var command = 'AT+CMGD=' + index; if (index === 'all') { @@ -234,58 +212,42 @@ Sim900r.prototype.smsDelete = function(index) { }); }; -/** - * Dialing a number - */ +// Dialing a number Sim900r.prototype.call = function(phone, callback) { this.cmd('ATD' + phone + ';', callback); }; -/** - * Answering an incoming call - */ +// Answering an incoming call Sim900r.prototype.answer = function(callback) { this.cmd('ATA', callback); }; -/** - * Break the connection - */ +// Break the connection Sim900r.prototype.cancel = function(callback) { this.cmd('ATH0', callback); }; -/** - * Sending a USSD command - */ +// Sending a USSD command Sim900r.prototype.ussd = function(phone, callback) { this.cmd('AT+CUSD=1,"' + phone + '"', callback); }; -/** - * SIM card operator - */ +// SIM card operator Sim900r.prototype.netProvider = function(callback) { this.cmd('AT+CSPN?', callback); }; -/** - * Operator in whose network the SIM card is registered - */ +// Operator in whose network the SIM card is registered Sim900r.prototype.netCurrent = function(callback) { this.cmd('AT+COPS?', callback); }; -/** - * Online registration status - */ +// Online registration status Sim900r.prototype.netStatus = function(callback) { this.cmd('AT+CREG?', callback); }; -/** - * Signal reception quality - */ +// Signal reception quality Sim900r.prototype.netQuality = function(callback) { this.cmd('AT+CSQ', callback); }; @@ -332,9 +294,7 @@ Sim900r.prototype.getCallerID = function(callback) { this.cmd('AT+CLIP?', callback); }; -/** - * Response processing methods - */ +// Response processing methods Sim900r.prototype.parseSMS = function(fLine, lLine, index) { var data = fLine.split('"'); diff --git a/modules/@amperka/accelerometer.js b/modules/@amperka/accelerometer.js index 9057d1c..ef21ff2 100644 --- a/modules/@amperka/accelerometer.js +++ b/modules/@amperka/accelerometer.js @@ -42,13 +42,13 @@ LIS331DLH.prototype.init = function(opts) { if (opts !== undefined && opts.highPassFilter !== undefined) { if (opts.highPassFilter === 8) { - config21 = 0x10; /* 00010000 */ + config21 = 0x10; // 00010000 } else if (opts.highPassFilter === 16) { - config21 = 0x11; /* 00010001 */ + config21 = 0x11; // 00010001 } else if (opts.highPassFilter === 32) { - config21 = 0x12; /* 00010010 */ + config21 = 0x12; // 00010010 } else if (opts.highPassFilter === 64) { - config21 = 0x13; /* 00010011 */ + config21 = 0x13; // 00010011 } } this.writeI2C(0x21, config21); @@ -58,11 +58,11 @@ LIS331DLH.prototype.init = function(opts) { this._sensitivity = 2 / 32767; if (opts !== undefined && opts.maxAccel !== undefined) { if (opts.maxAccel === 4) { - config23 = 0x11; /* 00010001 */ + config23 = 0x11; // 00010001 this._sensitivity = 4 / 32767; } if (opts.maxAccel === 8) { - config23 = 0x31; /* 00110001 */ + config23 = 0x31; // 00110001 this._sensitivity = 8 / 32767; } } diff --git a/modules/@amperka/barometer.js b/modules/@amperka/barometer.js index 929a90f..4b069d9 100644 --- a/modules/@amperka/barometer.js +++ b/modules/@amperka/barometer.js @@ -1,6 +1,5 @@ -/** - * Pressure sensor class - */ +// Pressure sensor class + // Class initialization var Barometer = function(opts) { opts = opts || {}; diff --git a/modules/@amperka/button.js b/modules/@amperka/button.js index 28756bb..e59e4f4 100644 --- a/modules/@amperka/button.js +++ b/modules/@amperka/button.js @@ -16,7 +16,7 @@ var Button = function(pin, opts) { }); }; -/* Deprecated: use `isPressed` intead */ +// Deprecated: use `isPressed` intead Button.prototype.read = function() { return this.isPressed() ? 'down' : 'up'; }; diff --git a/modules/@amperka/card-reader.js b/modules/@amperka/card-reader.js index 750a60e..890920e 100644 --- a/modules/@amperka/card-reader.js +++ b/modules/@amperka/card-reader.js @@ -20,11 +20,7 @@ CardReader.prototype.appendFile = function(fileName, data) { }; CardReader.prototype.pipe = function(source, destination, options) { - return this._fs.pipe( - source, - destination, - options - ); + return this._fs.pipe(source, destination, options); }; CardReader.prototype.readRandomFile = function(path) { diff --git a/modules/@amperka/magnetometer.js b/modules/@amperka/magnetometer.js index c40b5bb..8381ec3 100644 --- a/modules/@amperka/magnetometer.js +++ b/modules/@amperka/magnetometer.js @@ -1,4 +1,4 @@ -// Инициализация класса +// Class initialization var LIS3MDL = function(i2c, address) { this._i2c = i2c; this._sensitivity = 1 / 6842; @@ -22,17 +22,17 @@ LIS3MDL.prototype.read = function(reg, count) { // Module start LIS3MDL.prototype.init = function(opts) { // Temp compensation ON, X-axis, Y-axis in High perfomance - var config20 = 0xcc; /* 11001100 */ + var config20 = 0xcc; // 11001100 if (opts !== undefined && opts.frequency !== undefined) { if (opts.frequency === 10) { - config20 = 0xd0; /* 11010000 */ + config20 = 0xd0; // 11010000 } else if (opts.frequency === 20) { - config20 = 0xd4; /* 11010100 */ + config20 = 0xd4; // 11010100 } else if (opts.frequency === 40) { - config20 = 0xd8; /* 11011000 */ + config20 = 0xd8; // 11011000 } else if (opts.frequency === 80) { - config20 = 0xdc; /* 11011100 */ + config20 = 0xdc; // 11011100 } } this.write(0x20, config20); @@ -42,13 +42,13 @@ LIS3MDL.prototype.init = function(opts) { if (opts !== undefined && opts.sensitivity !== undefined) { if (opts.sensitivity === 8) { - config21 = 0x20; /* 00100000 */ + config21 = 0x20; // 00100000 this._sensitivity = 1 / 3421; } else if (opts.sensitivity === 12) { - config21 = 0x40; /* 01000000 */ + config21 = 0x40; // 01000000 this._sensitivity = 1 / 2281; } else if (opts.sensitivity === 16) { - config21 = 0x60; /* 01100000 */ + config21 = 0x60; // 01100000 this._sensitivity = 1 / 1711; } } @@ -58,7 +58,7 @@ LIS3MDL.prototype.init = function(opts) { this.write(0x22, 0x0); // Z-axis in High perfomance - this.write(0x23, 0x8 /* 00001000 */); + this.write(0x23, 0x8); }; // The method returns data from the magnetometer diff --git a/modules/@amperka/nfc.js b/modules/@amperka/nfc.js index a94394a..896071b 100644 --- a/modules/@amperka/nfc.js +++ b/modules/@amperka/nfc.js @@ -147,7 +147,7 @@ PN532.prototype.writePage = function(page, data, callback) { } this._packetBuffer[0] = this._COMMAND_INDATAEXCHANGE; - this._packetBuffer[1] = 1; /* Card number */ + this._packetBuffer[1] = 1; // Card number this._packetBuffer[2] = this._MIFARE_ULTRALIGHT_CMD_WRITE; this._packetBuffer[3] = page; this._packetBuffer[4] = data[0]; diff --git a/modules/@amperka/octoliner.js b/modules/@amperka/octoliner.js index 7d1dfcf..3f5a059 100644 --- a/modules/@amperka/octoliner.js +++ b/modules/@amperka/octoliner.js @@ -79,51 +79,51 @@ Octoliner.prototype.mapAnalogToPattern = function(analogArray) { Octoliner.prototype.mapPatternToLine = function(pattern) { switch (pattern) { - case 0x18 /*0b00011000*/: + case 0x18: // 0b00011000 return 0; - case 0x10 /*0b00010000*/: + case 0x10: // 0b00010000 return 0.25; - case 0x38 /*0b00111000*/: + case 0x38: // 0b00111000 return 0.25; - case 0x08 /*0b00001000*/: + case 0x08: // 0b00001000 return -0.25; - case 0x1c /*0b00011100*/: + case 0x1c: // 0b00011100 return -0.25; - case 0x30 /*0b00110000*/: + case 0x30: // 0b00110000 return 0.375; - case 0x0c /*0b00001100*/: + case 0x0c: // 0b00001100 return -0.375; - case 0x20 /*0b00100000*/: + case 0x20: // 0b00100000 return 0.5; - case 0x70 /*0b01110000*/: + case 0x70: // 0b01110000 return 0.5; - case 0x04 /*0b00000100*/: + case 0x04: // 0b00000100 return -0.5; - case 0x0e /*0b00001110*/: + case 0x0e: // 0b00001110 return -0.5; - case 0x60 /*0b01100000*/: + case 0x60: // 0b01100000 return 0.625; - case 0xe0 /*0b11100000*/: + case 0xe0: // 0b11100000 return 0.625; - case 0x06 /*0b00000110*/: + case 0x06: // 0b00000110 return -0.625; - case 0x07 /*0b00000111*/: + case 0x07: // 0b00000111 return -0.625; - case 0x40 /*0b01000000*/: + case 0x40: // 0b01000000 return 0.75; - case 0xf0 /*0b11110000*/: + case 0xf0: // 0b11110000 return 0.75; - case 0x02 /*0b00000010*/: + case 0x02: // 0b00000010 return -0.75; - case 0x0f /*0b00001111*/: + case 0x0f: // 0b00001111 return -0.75; - case 0xc0 /*0b11000000*/: + case 0xc0: // 0b11000000 return 0.875; - case 0x03 /*0b00000011*/: + case 0x03: // 0b00000011 return -0.875; - case 0x80 /*0b10000000*/: + case 0x80: // 0b10000000 return 1.0; - case 0x01 /*0b00000001*/: + case 0x01: // 0b00000001 return -1.0; default: return NaN; diff --git a/modules/@amperka/quaddisplay2.js b/modules/@amperka/quaddisplay2.js index 1785c87..d77e14b 100644 --- a/modules/@amperka/quaddisplay2.js +++ b/modules/@amperka/quaddisplay2.js @@ -97,7 +97,7 @@ QuadDisplay.prototype.display = function(str, alignRight) { this._data[d] = SYMBOLS[s[i]]; } else { // prevent dot-dot and space-dot collapsing - if (d !== -1 && (this._data[d] !== 0xfe && this._data[d] !== 0xff)) { + if (d !== -1 && this._data[d] !== 0xfe && this._data[d] !== 0xff) { this._data[d] &= 0xfe; } else { d++; diff --git a/modules/@amperka/stepper.js b/modules/@amperka/stepper.js index 521bdf7..b43f501 100644 --- a/modules/@amperka/stepper.js +++ b/modules/@amperka/stepper.js @@ -1,9 +1,7 @@ -/** - * Stepper object constructor - * @constructor - * @param {object} pins - an object with properties step, direction, enable of type Pin - * @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties - */ +// Stepper object constructor +// @constructor +// @param {object} pins - an object with properties step, direction, enable of type Pin +// @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties var Stepper = function(pins, opts) { this._pins = pins; opts = opts || {}; @@ -20,10 +18,8 @@ var Stepper = function(pins, opts) { this._intervalId = null; }; -/** - * Adjusts the PWM power supply to the motor - * @param {float} power - PWM duty cycle from 0 to 1 - */ +// Adjusts the PWM power supply to the motor +// @param {float} power - PWM duty cycle from 0 to 1 Stepper.prototype.hold = function(power) { if (this._intervalId !== null) { clearInterval(this._intervalId); @@ -36,11 +32,10 @@ Stepper.prototype.hold = function(power) { analogWrite(this._pins.enable, power); }; -/** - * Turns the shaft step by step, and then executes a callback. - * @param {number} steps - number of steps. If the value is negative, it moves backwards. - * @param {function} callback - function performed after turning the shaft - */ + +// Turns the shaft step by step, and then executes a callback. +// @param {number} steps - number of steps. If the value is negative, it moves backwards. +// @param {function} callback - function performed after turning the shaft Stepper.prototype.rotate = function(steps, callback) { this.hold(1); @@ -69,29 +64,23 @@ Stepper.prototype.rotate = function(steps, callback) { }, 1000 / this._pps); }; -/** - * Adjusts the number of steps per second - */ +// Adjusts the number of steps per second Stepper.prototype.pps = function(pps) { if (pps === undefined) return this._pps; this._pps = pps; return this; }; -/** - * Resets the shaft holding value set during initialization - */ +// Resets the shaft holding value set during initialization Stepper.prototype.holdPower = function(holdPower) { if (holdPower === undefined) return this._holdPower; this._holdPower = holdPower; return this; }; -/** - * Exporting the Stepper Object Creation Function - * @param {object} pins - an object with properties step, direction, enable of type Pin - * @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties - */ +// Exporting the Stepper Object Creation Function +// @param {object} pins - an object with properties step, direction, enable of type Pin +// @param {Object} opts - an object with pps (speed) and holdPower (pwm) properties exports.connect = function(pins, opts) { return new Stepper(pins, opts); }; diff --git a/modules/@amperka/telegram.js b/modules/@amperka/telegram.js index b4e3a53..fdba8af 100644 --- a/modules/@amperka/telegram.js +++ b/modules/@amperka/telegram.js @@ -75,7 +75,7 @@ Telegram.prototype.keyboard = function(arrayOfButtons, opts) { }; Telegram.prototype.inlineButton = function(text, opt) { - /* eslint-disable camelcase */ + // eslint-disable camelcase opt = opt || {}; var markup = { text: text }; if (opt.url) { @@ -88,7 +88,7 @@ Telegram.prototype.inlineButton = function(text, opt) { markup.callback_data = String(opt.callback); } return markup; - /* eslint-enable camelcase */ + // eslint-enable camelcase }; Telegram.prototype.inlineKeyboard = function(arrayOfButtons) { @@ -115,7 +115,7 @@ Telegram.prototype._event = function(eventName, params, eventType) { }; Telegram.prototype._addPreparedPayload = function(payload, dest) { - /* eslint-disable camelcase */ + // eslint-disable camelcase if (payload) { if (payload.reply) { dest.reply_to_message_id = payload.reply; @@ -134,7 +134,7 @@ Telegram.prototype._addPreparedPayload = function(payload, dest) { } } return dest; - /* eslint-enable camelcase */ + // eslint-enable camelcase }; Telegram.prototype.sendMessage = function(chatId, text, payload) { diff --git a/modules/@amperka/ultrasonic.js b/modules/@amperka/ultrasonic.js index c363df9..1655543 100644 --- a/modules/@amperka/ultrasonic.js +++ b/modules/@amperka/ultrasonic.js @@ -26,11 +26,7 @@ function convertUnits(s, units) { } } -/* - * - * Class Ultrasonic - * - */ +// Class Ultrasonic var Ultrasonic = function(pins) { this._trigPin = pins.trigPin; this._echoPin = pins.echoPin; @@ -99,11 +95,7 @@ Ultrasonic.prototype.ping = function(cb, units) { return this; }; -/* - * - * module exports - * - */ +// module exports exports.connect = function(pins) { return new Ultrasonic(pins); }; diff --git a/modules/@amperka/usb-keyboard.js b/modules/@amperka/usb-keyboard.js index b7f0640..3b5a17a 100644 --- a/modules/@amperka/usb-keyboard.js +++ b/modules/@amperka/usb-keyboard.js @@ -1,6 +1,4 @@ -/* Copyright (c) 2015 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. */ -/* - */ +// Copyright (c) 2015 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. E.setUSBHID({ // prettier-ignore reportDescriptor: [ diff --git a/modules/@amperka/wifi.js b/modules/@amperka/wifi.js index 27bfa93..8b21498 100644 --- a/modules/@amperka/wifi.js +++ b/modules/@amperka/wifi.js @@ -6,8 +6,8 @@ var ENCR_FLAGS = ['open', 'wep', 'wpa_psk', 'wpa2_psk', 'wpa_wpa2_psk']; var netCallbacks = { create: function(host, port) { - /* Create a socket and return its index, host is a string, port is an integer. - If host isn't defined, create a server socket */ + // Create a socket and return its index, host is a string, port is an integer. + // If host isn't defined, create a server socket var sckt; var self = this; if (host === undefined) { @@ -69,7 +69,7 @@ var netCallbacks = { } return sckt; }, - /* Close the socket. returns nothing */ + // Close the socket. returns nothing close: function(sckt) { if (socks[sckt] === 'Wait') { socks[sckt] = 'WaitClose'; @@ -86,7 +86,7 @@ var netCallbacks = { ); } }, - /* Accept the connection on the server socket. Returns socket number or -1 if no connection */ + // Accept the connection on the server socket. Returns socket number or -1 if no connection accept: function() { for (var i = 0; i < MAXSOCKETS; i++) { if (sockData[i] && socks[i] === undefined) { @@ -96,8 +96,8 @@ var netCallbacks = { } return -1; }, - /* Receive data. Returns a string (even if empty). - If non-string returned, socket is then closed */ + // Receive data. Returns a string (even if empty). + // If non-string returned, socket is then closed recv: function(sckt, maxLen) { if (at.isBusy() || socks[sckt] === 'Wait') { return ''; @@ -118,8 +118,8 @@ var netCallbacks = { } return ''; }, - /* Send data. Returns the number of bytes sent - 0 is ok. - Less than 0 */ + // Send data. Returns the number of bytes sent - 0 is ok. + // Less than 0 send: function(sckt, data) { if (at.isBusy() || socks[sckt] === 'Wait') { return 0; From 49095e8d1ce54c28a44d9d053014da46dc06b876 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 17 Sep 2021 19:36:39 +0700 Subject: [PATCH 3/3] Update quaddisplay2.js --- modules/@amperka/quaddisplay2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/@amperka/quaddisplay2.js b/modules/@amperka/quaddisplay2.js index d77e14b..1785c87 100644 --- a/modules/@amperka/quaddisplay2.js +++ b/modules/@amperka/quaddisplay2.js @@ -97,7 +97,7 @@ QuadDisplay.prototype.display = function(str, alignRight) { this._data[d] = SYMBOLS[s[i]]; } else { // prevent dot-dot and space-dot collapsing - if (d !== -1 && this._data[d] !== 0xfe && this._data[d] !== 0xff) { + if (d !== -1 && (this._data[d] !== 0xfe && this._data[d] !== 0xff)) { this._data[d] &= 0xfe; } else { d++;