[update] pigpio ライブラリを promise ベースに変更。

This commit is contained in:
ocogeclub 2021-11-25 23:23:54 +09:00
parent 034ba61198
commit e6fe8e303d
7 changed files with 571 additions and 555 deletions

View File

@ -4,23 +4,23 @@ const pig = require('@ocogeclub/pigpio');
let pi = -1;
let i2c_hand = -1;
exports.init = (i2c_bus, i2c_addr) => {
if (pi < 0) pi = pig._pigpio_start('', '');
if (i2c_hand < 0) pig._i2c_close(pi, i2c_hand);
i2c_hand = pig._i2c_open(pi, i2c_bus, i2c_addr);
pig._i2c_write_byte_data(pi, i2c_hand, 0x00, 0x00); //Normal mode
pig._i2c_write_byte_data(pi, i2c_hand, 0x02, 0x00); //10FPS
exports.init = async (i2c_bus, i2c_addr) => {
if (pi < 0) pi = await pig._pigpio_start('', '');
if (i2c_hand < 0) await pig._i2c_close(pi, i2c_hand);
i2c_hand = await pig._i2c_open(pi, i2c_bus, i2c_addr);
await pig._i2c_write_byte_data(pi, i2c_hand, 0x00, 0x00); //Normal mode
await pig._i2c_write_byte_data(pi, i2c_hand, 0x02, 0x00); //10FPS
}
exports.read_thermistor = () => {
let temp = pig._i2c_read_word_data(pi, i2c_hand, 0x0e);
exports.read_thermistor = async () => {
let temp = await pig._i2c_read_word_data(pi, i2c_hand, 0x0e);
return temp * 0.0625;
}
exports.read_temp_array = () => {
exports.read_temp_array = async () => {
let linedata = [];
for (let i = 0; i < 8; i++) {
let data = pig._i2c_read_i2c_block_data(pi, i2c_hand, 0x80 + 0x10 * i, 16);
let data = await pig._i2c_read_i2c_block_data(pi, i2c_hand, 0x80 + 0x10 * i, 16);
let oneline = [];
for (let j = 0; j < 8; j++) {
oneline.push(((data[2 * j + 1] & 0x07) * 256 + data[2 * j]) * 0.25);
@ -30,13 +30,13 @@ exports.read_temp_array = () => {
return linedata;
}
exports.stop = () => {
exports.stop = async () => {
if (i2c_hand >= 0) {
pig._i2c_close(pi, i2c_hand);
await pig._i2c_close(pi, i2c_hand);
i2c_hand = -1;
}
if (pi >= 0) {
pig._pigpio_stop(pi);
await pig._pigpio_stop(pi);
pi = -1;
}
}

View File

@ -41,24 +41,24 @@ this.REGISTER_PRESSURE_DATA = 0xF7;
this.REGISTER_TEMP_DATA = 0xFA;
this.REGISTER_HUMIDITY_DATA = 0xFD;
exports.init = (options) => {
exports.init = async (options) => {
this.pig = require('@ocogeclub/pigpio')
// console.log('pig= ' + this.pig)
this.pi = this.pig._pigpio_start('', '');
this.pi = await this.pig._pigpio_start('', '');
// console.log('pi= ' + this.pi)
// this.pi = require('@ocogeclub/lgpio');
this.i2cBusNo = (options && options.hasOwnProperty('i2cBusNo')) ? options.i2cBusNo : 1;
this.i2cAddress = (options && options.hasOwnProperty('i2cAddress')) ? options.i2cAddress : this.BME280_DEFAULT_I2C_ADDRESS();
this.i2cHand = this.pig._i2c_open(this.pi, this.i2cBusNo, this.i2cAddress);
this.i2cHand = await this.pig._i2c_open(this.pi, this.i2cBusNo, this.i2cAddress);
// console.log('i2cHand= ' + this.i2cHand)
// this.i2cHand = this.pi._i2c_open(this.i2cBusNo, this.i2cAddress);
let r;
r = this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID, 0);
r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID, 0);
// r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CHIPID, 0);
if (r < 0) return r;
let chipId = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID);
let chipId = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID);
// let chipId = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_CHIPID);
if (chipId !== this.CHIP_ID_BME280() &&
chipId !== this.CHIP_ID1_BMP280() &&
@ -67,18 +67,18 @@ exports.init = (options) => {
return `Unexpected BMx280 chip ID: 0x${chipId.toString(16).toUpperCase()}`;
}
// console.log(`Found BMx280 chip ID 0x${chipId.toString(16).toUpperCase()} on bus i2c-${this.i2cBusNo}, address 0x${this.i2cAddress.toString(16).toUpperCase()}`);
this.loadCalibration((err) => {
await this.loadCalibration(async (err) => {
if (err) {
return err;
}
// Humidity 16x oversampling
//
let r = this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
let r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
// let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
if (r < 0) return `Humidity 16x oversampling error: ${r}`;
// Temperture/pressure 16x oversampling, normal mode
//
r = this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
// r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
if (r < 0) return `Temperture/pressure 16x oversampling error: ${r}`;
@ -90,9 +90,9 @@ exports.init = (options) => {
//
// Perform a power-on reset procedure. You will need to call init() following a reset()
//
exports.reset = () => {
exports.reset = async () => {
const POWER_ON_RESET_CMD = 0xB6;
let r = this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
let r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
// let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
if (r < 0) return `cannot power-on reset: ${r}`;
else return 0;
@ -102,24 +102,24 @@ exports.reset = () => {
//
// Cancels the sensor and releases resources.
//
exports.cancel = () => {
exports.cancel = async () => {
if (this.i2cHand >= 0) {
this.pig._i2c_close(this.pi, this.i2cHand);
await this.pig._i2c_close(this.pi, this.i2cHand);
// this.pi._i2c_close(this.i2cHand);
this.i2cHand = null;
this.pig._pigpio_stop(this.pi);
await this.pig._pigpio_stop(this.pi);
this.pi = null;
}
}
exports.readSensorData = () => {
exports.readSensorData = async () => {
if (!this.cal) {
return 'You must first call bme280.init()';
}
// Grab temperature, humidity, and pressure in a single read
//
let buffer = this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
let buffer = await this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
// let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
if (!buffer) return `couldn't grab data`;
// Temperature (temperature first since we need t_fine for pressure and humidity)
@ -171,18 +171,18 @@ exports.readSensorData = () => {
};
}
exports.loadCalibration = (callback) => {
let buffer = this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_DIG_T1, 24);
exports.loadCalibration = async (callback) => {
let buffer = await this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_DIG_T1, 24);
// let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_DIG_T1, 24);
// for (let i = 0; i < 24; i++) console.log(parseInt(buffer[i], 16));
if (buffer) {
let h1 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H1);
let h2 = this.pig._i2c_read_word_data(this.pi, this.i2cHand, this.REGISTER_DIG_H2);
let h3 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H3);
let h4 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H4);
let h5 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5);
let h5_1 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5 + 1);
let h6 = this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H6);
let h1 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H1);
let h2 = await this.pig._i2c_read_word_data(this.pi, this.i2cHand, this.REGISTER_DIG_H2);
let h3 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H3);
let h4 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H4);
let h5 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5);
let h5_1 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5 + 1);
let h6 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H6);
// let h1 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H1);
// let h2 = this.pi._i2c_read_word_data(this.i2cHand, this.REGISTER_DIG_H2);
// let h3 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H3);
@ -215,7 +215,7 @@ exports.loadCalibration = (callback) => {
};
// console.log('BME280 cal = ' + JSON.stringify(this.cal, null, 2));
callback();
await callback();
}
}

View File

@ -317,18 +317,20 @@ let pi = -1;
let i2c_hand = -1;
//Initialize the sensors
exports.init = async (i2c_bus, i2c_addr) => {
if (pi < 0) pi = pig._pigpio_start('', '');
if (i2c_hand < 0) pig._i2c_close(pi, i2c_hand);
i2c_hand = pig._i2c_open(pi, i2c_bus, i2c_addr);
if (pi < 0) pi = await pig._pigpio_start('', '');
if (i2c_hand < 0) await pig._i2c_close(pi, i2c_hand);
i2c_hand = await pig._i2c_open(pi, i2c_bus, i2c_addr);
if (debug)
console.log("pi" + pi + "i2c_hand" + i2c_hand);
await sleep(.001);
paj7620SelectBank(BANK0);
paj7620SelectBank(BANK0);
await paj7620SelectBank(BANK0);
await paj7620SelectBank(BANK0);
let data0 = paj7620ReadReg(0, 1)[0];
let data1 = paj7620ReadReg(1, 1)[0];
let data0 = (await paj7620ReadReg(0, 1))[0];
let data1 = (await paj7620ReadReg(1, 1))[0];
if (debug)
console.log("data0" + data0 + "data1" + data1);
console.log("data0:" + data0 + ", data1:" + data1);
if (data0 != 0x20) //or data1 <> 0x76
console.log("Error with sensor");
//return 0xff
@ -336,27 +338,27 @@ exports.init = async (i2c_bus, i2c_addr) => {
console.log("wake-up finish.");
for (let i = 0; i < initRegisterArray.length; i += 1)
paj7620WriteReg(initRegisterArray[i][0], initRegisterArray[i][1]);
await paj7620WriteReg(initRegisterArray[i][0], initRegisterArray[i][1]);
paj7620SelectBank(BANK0);
await paj7620SelectBank(BANK0);
console.log("Paj7620 initialize register finished.");
}
// Write a byte to a register on the Gesture sensor
const paj7620WriteReg = (addr, cmd) =>
pig._i2c_write_word_data(pi, i2c_hand, addr, cmd);
const paj7620WriteReg = async (addr, cmd) =>
await pig._i2c_write_word_data(pi, i2c_hand, addr, cmd);
//Select a register bank on the Gesture Sensor
const paj7620SelectBank = bank => {
const paj7620SelectBank = async bank => {
if (bank == BANK0)
paj7620WriteReg(PAJ7620_REGITER_BANK_SEL, PAJ7620_BANK0);
await paj7620WriteReg(PAJ7620_REGITER_BANK_SEL, PAJ7620_BANK0);
}
//Read a block of bytes of length "qty" starting at address "addr" from the Gesture sensor
const paj7620ReadReg = (addr, qty) => {
return pig._i2c_read_i2c_block_data(pi, i2c_hand, addr, qty);
const paj7620ReadReg = async (addr, qty) => {
return await pig._i2c_read_i2c_block_data(pi, i2c_hand, addr, qty);
}
//Return a vlaue from the gestire sensor which can be used in a program
@ -372,10 +374,10 @@ const paj7620ReadReg = (addr, qty) => {
// 9:wave
exports.return_gesture = async () => {
let data = paj7620ReadReg(0x43, 1)[0];
let data = (await paj7620ReadReg(0x43, 1))[0];
if (data == GES_RIGHT_FLAG) {
await sleep(GES_ENTRY_TIME);
data = paj7620ReadReg(0x43, 1)[0];
data = (await paj7620ReadReg(0x43, 1))[0];
if (data == GES_FORWARD_FLAG) {
return 1;
// await sleep(GES_QUIT_TIME);
@ -390,7 +392,7 @@ exports.return_gesture = async () => {
else if (data == GES_LEFT_FLAG) {
await sleep(GES_ENTRY_TIME);
data = paj7620ReadReg(0x43, 1)[0];
data = (await paj7620ReadReg(0x43, 1))[0];
if (data == GES_FORWARD_FLAG) {
return 1;
// await sleep(GES_QUIT_TIME);
@ -405,7 +407,7 @@ exports.return_gesture = async () => {
else if (data == GES_UP_FLAG) {
await sleep(GES_ENTRY_TIME);
data = paj7620ReadReg(0x43, 1)[0];
data = (await paj7620ReadReg(0x43, 1))[0];
if (data == GES_FORWARD_FLAG) {
return 1;
// await sleep(GES_QUIT_TIME);
@ -420,7 +422,7 @@ exports.return_gesture = async () => {
else if (data == GES_DOWN_FLAG) {
await sleep(GES_ENTRY_TIME);
data = paj7620ReadReg(0x43, 1)[0];
data = (await paj7620ReadReg(0x43, 1))[0];
if (data == GES_FORWARD_FLAG) {
return 1;
// await sleep(GES_QUIT_TIME);
@ -449,20 +451,20 @@ exports.return_gesture = async () => {
return 8;
else {
let data1 = paj7620ReadReg(0x44, 1)[0];
let data1 = (await paj7620ReadReg(0x44, 1))[0];
if (data1 == GES_WAVE_FLAG)
return 9;
}
return 0;
}
exports.stop = () => {
exports.stop = async () => {
if (i2c_hand >= 0) {
pig._i2c_close(pi, i2c_hand);
await pig._i2c_close(pi, i2c_hand);
i2c_hand = -1;
}
if (pi >= 0) {
pig._pigpio_stop(pi);
await pig._pigpio_stop(pi);
pi = -1;
}
}

View File

@ -13,82 +13,82 @@ module.exports.PULL_NONE = 0;
let pi = -1;
let i2c_hand = -1;
let ser_hand = -1;
module.exports.gpio_open = () => {
if (pi < 0) pi = module.exports._pigpio_start('', '');
module.exports.gpio_open = async () => {
if (pi < 0) pi = await module.exports._pigpio_start('', '');
return pi;
}
module.exports.gpio_close = () => {
if (pi >= 0) module.exports._pigpio_stop(pi);
module.exports.gpio_close = async () => {
if (pi >= 0) await module.exports._pigpio_stop(pi);
pi = -1;
}
module.exports.gpio_set_output = gpio => {
if (pi >= 0) return module.exports._set_mode(pi, gpio, 1);
module.exports.gpio_set_output = async gpio => {
if (pi >= 0) return await module.exports._set_mode(pi, gpio, 1);
}
module.exports.gpio_set_input = (gpio, mode) => {
module.exports.gpio_set_input = async (gpio, mode) => {
if (pi >= 0) {
let r = module.exports._set_mode(pi, gpio, 0);
let r = await module.exports._set_mode(pi, gpio, 0);
if (r == 0)
return module.exports._set_pull_up_down(pi, gpio, mode);
return await module.exports._set_pull_up_down(pi, gpio, mode);
else
return r;
}
}
module.exports.gpio_read = gpio => {
if (pi >= 0) return module.exports._gpio_read(pi, gpio);
module.exports.gpio_read = async gpio => {
if (pi >= 0) return await module.exports._gpio_read(pi, gpio);
}
module.exports.gpio_write = (gpio, value) => {
if (pi >= 0) return module.exports._gpio_write(pi, gpio, value);
module.exports.gpio_write = async (gpio, value) => {
if (pi >= 0) return await module.exports._gpio_write(pi, gpio, value);
}
module.exports.servo = (gpio, pulse_width) => {
if (pi >= 0) return module.exports._set_servo_pulsewidth(pi, gpio, pulse_width);
module.exports.servo = async (gpio, pulse_width) => {
if (pi >= 0) return await module.exports._set_servo_pulsewidth(pi, gpio, pulse_width);
}
module.exports.pwm = (gpio, pwm_frequency, pwm_duty_cycle) => {
module.exports.pwm = async (gpio, pwm_frequency, pwm_duty_cycle) => {
if (pi >= 0) {
module.exports._set_PWM_frequency(pi, gpio, pwm_frequency);
module.exports._set_PWM_dutycycle(pi, gpio, pwm_duty_cycle);
await module.exports._set_PWM_frequency(pi, gpio, pwm_frequency);
await module.exports._set_PWM_dutycycle(pi, gpio, pwm_duty_cycle);
}
}
module.exports.serial_open = (tty, baud) => {
if (ser_hand >= 0) module.exports._serial_close(pi, ser_hand); // 勝手に閉じる
ser_hand = module.exports._serial_open(pi, tty, baud);
module.exports.serial_open = async (tty, baud) => {
if (ser_hand >= 0) await module.exports._serial_close(pi, ser_hand); // 勝手に閉じる
ser_hand = await module.exports._serial_open(pi, tty, baud);
return ser_hand;
}
module.exports.serial_close = () => {
if (ser_hand >= 0) module.exports._serial_close(pi, ser_hand);
module.exports.serial_close = async () => {
if (ser_hand >= 0) await module.exports._serial_close(pi, ser_hand);
ser_hand = -1;
}
module.exports.serial_write = data => {
if (ser_hand >= 0) return module.exports._serial_write(pi, ser_hand, Buffer.from(data));
module.exports.serial_write = async data => {
if (ser_hand >= 0) return await module.exports._serial_write(pi, ser_hand, Buffer.from(data));
}
module.exports.serial_read = count => {
if (ser_hand >= 0) return module.exports._serial_read(pi, ser_hand, count).toString('utf8');
module.exports.serial_read = async count => {
if (ser_hand >= 0) return await module.exports._serial_read(pi, ser_hand, count).toString('utf8');
}
module.exports.i2c_open = (i2c_bus, i2c_address) => {
if (i2c_hand >= 0) module.exports._i2c_close(pi, i2c_hand); // 勝手に閉じる
i2c_hand = module.exports._i2c_open(pi, i2c_bus, i2c_address);
module.exports.i2c_open = async (i2c_bus, i2c_address) => {
if (i2c_hand >= 0) await module.exports._i2c_close(pi, i2c_hand); // 勝手に閉じる
i2c_hand = await module.exports._i2c_open(pi, i2c_bus, i2c_address);
return i2c_hand;
}
module.exports.i2c_close = () => {
if (i2c_hand >= 0) module.exports._i2c_close(pi, i2c_hand);
module.exports.i2c_close = async () => {
if (i2c_hand >= 0) await module.exports._i2c_close(pi, i2c_hand);
i2c_hand = -1;
}
module.exports.i2c_write_byte_data = (reg, byte_val) => {
if (i2c_hand >= 0) return module.exports._i2c_write_byte_data(pi, i2c_hand, reg, byte_val);
module.exports.i2c_write_byte_data = async (reg, byte_val) => {
if (i2c_hand >= 0) return await module.exports._i2c_write_byte_data(pi, i2c_hand, reg, byte_val);
}
module.exports.i2c_read_byte_data = reg => {
if (i2c_hand >= 0) return module.exports._i2c_read_byte_data(pi, i2c_hand, reg);
module.exports.i2c_read_byte_data = async reg => {
if (i2c_hand >= 0) return await module.exports._i2c_read_byte_data(pi, i2c_hand, reg);
}
module.exports.i2c_write_i2c_block_data = (reg, data) => {
if (i2c_hand >= 0) return module.exports._i2c_write_i2c_block_data(pi, i2c_hand, reg, Buffer.from(data));
module.exports.i2c_write_i2c_block_data = async (reg, data) => {
if (i2c_hand >= 0) return await module.exports._i2c_write_i2c_block_data(pi, i2c_hand, reg, Buffer.from(data));
}
module.exports.i2c_read_word_data = reg => {
if (i2c_hand >= 0) return module.exports._i2c_read_word_data(pi, i2c_hand, reg);
module.exports.i2c_read_word_data = async reg => {
if (i2c_hand >= 0) return await module.exports._i2c_read_word_data(pi, i2c_hand, reg);
}
module.exports.i2c_read_device = count => {
if (i2c_hand >= 0) return module.exports._i2c_read_device(pi, i2c_hand, count).toString('utf8');
module.exports.i2c_read_device = async count => {
if (i2c_hand >= 0) return await module.exports._i2c_read_device(pi, i2c_hand, count).toString('utf8');
}
module.exports.i2c_write_device = data => {
if (i2c_hand >= 0) return module.exports._i2c_write_device(pi, i2c_hand, Buffer.from(data));
module.exports.i2c_write_device = async data => {
if (i2c_hand >= 0) return await module.exports._i2c_write_device(pi, i2c_hand, Buffer.from(data));
}
// 終了処理
module.exports.close_all_handle = () => {

File diff suppressed because it is too large Load Diff

19
package-lock.json generated
View File

@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
"name": "ocoge",
"version": "0.1.3",
"license": "ISC",
"dependencies": {
@ -3819,12 +3820,14 @@
"@tensorflow-models/knn-classifier": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@tensorflow-models/knn-classifier/-/knn-classifier-1.2.2.tgz",
"integrity": "sha512-QRnkCf7ErOxSRtvJ6yCwhlLREPcBJGaXRanF46f0iY6ii3Sybjb6Ux0qnNPTrHZChD0izPa3Z4GQEgSAykiHkQ=="
"integrity": "sha512-QRnkCf7ErOxSRtvJ6yCwhlLREPcBJGaXRanF46f0iY6ii3Sybjb6Ux0qnNPTrHZChD0izPa3Z4GQEgSAykiHkQ==",
"requires": {}
},
"@tensorflow-models/mobilenet": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@tensorflow-models/mobilenet/-/mobilenet-2.1.0.tgz",
"integrity": "sha512-JjqT9ijHDFA2FEpUGWg7H2lQ0GrMuE2VmiCRBYmUew6b4JKht8LXDjG5HxZh95YH6c/25sZWTpGeHbquloH+hw=="
"integrity": "sha512-JjqT9ijHDFA2FEpUGWg7H2lQ0GrMuE2VmiCRBYmUew6b4JKht8LXDjG5HxZh95YH6c/25sZWTpGeHbquloH+hw==",
"requires": {}
},
"@tensorflow/tfjs": {
"version": "3.11.0",
@ -3869,7 +3872,8 @@
"@tensorflow/tfjs-converter": {
"version": "3.11.0",
"resolved": "https://registry.npmjs.org/@tensorflow/tfjs-converter/-/tfjs-converter-3.11.0.tgz",
"integrity": "sha512-rTRIKvBoqL0qdPYpm8UXauZycOiaBHZB2E2v3OoXoHnjvle/Xn/09uZJdrixgGhR+Kahs3Vz27BEEFz6RI5j2w=="
"integrity": "sha512-rTRIKvBoqL0qdPYpm8UXauZycOiaBHZB2E2v3OoXoHnjvle/Xn/09uZJdrixgGhR+Kahs3Vz27BEEFz6RI5j2w==",
"requires": {}
},
"@tensorflow/tfjs-core": {
"version": "3.11.0",
@ -3897,7 +3901,8 @@
"@tensorflow/tfjs-layers": {
"version": "3.11.0",
"resolved": "https://registry.npmjs.org/@tensorflow/tfjs-layers/-/tfjs-layers-3.11.0.tgz",
"integrity": "sha512-BtLgLucJZHv5te1K3yjT3iZdHXgMJArrLuOb/oRPOtTp4R2ad5N0V2m5RtuZJ3sI5/ah0h72xtmTWNyTv3/5dw=="
"integrity": "sha512-BtLgLucJZHv5te1K3yjT3iZdHXgMJArrLuOb/oRPOtTp4R2ad5N0V2m5RtuZJ3sI5/ah0h72xtmTWNyTv3/5dw==",
"requires": {}
},
"@tensorflow/tfjs-node": {
"version": "3.11.0",
@ -6142,7 +6147,8 @@
"@tensorflow/tfjs-converter": {
"version": "2.8.6",
"resolved": "https://registry.npmjs.org/@tensorflow/tfjs-converter/-/tfjs-converter-2.8.6.tgz",
"integrity": "sha512-Uv4YC66qjVC9UwBxz0IeLZ8KS2CReh63WlGRtHcSwDEYiwsa7cvp9H6lFSSPT7kiJmrK6JtHeJGIVcTuNnSt9w=="
"integrity": "sha512-Uv4YC66qjVC9UwBxz0IeLZ8KS2CReh63WlGRtHcSwDEYiwsa7cvp9H6lFSSPT7kiJmrK6JtHeJGIVcTuNnSt9w==",
"requires": {}
},
"@tensorflow/tfjs-core": {
"version": "2.8.6",
@ -6168,7 +6174,8 @@
"@tensorflow/tfjs-layers": {
"version": "2.8.6",
"resolved": "https://registry.npmjs.org/@tensorflow/tfjs-layers/-/tfjs-layers-2.8.6.tgz",
"integrity": "sha512-fdZ0i/R2dIKmy8OB5tBAsm5IbAHfJpI6AlbjxpgoU3aWj1HCdDo+pMji928MkDJhP01ISgFTgw/7PseGNaUflw=="
"integrity": "sha512-fdZ0i/R2dIKmy8OB5tBAsm5IbAHfJpI6AlbjxpgoU3aWj1HCdDo+pMji928MkDJhP01ISgFTgw/7PseGNaUflw==",
"requires": {}
},
"@types/webgl2": {
"version": "0.0.5",

View File

@ -323,7 +323,7 @@ Blockly.JavaScript['ugj_gpio_open'] = function (block) {
Blockly.JavaScript.provideFunction_(
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
);
var code = `console.log('pi='+pi.gpio_open());\n`; //
var code = `await pi.gpio_open();\n`; //
return code;
};
Blockly.Python['ugj_gpio_open'] = function (block) {
@ -352,7 +352,7 @@ Blockly.Blocks['ugj_gpio_close'] = {
}
};
Blockly.JavaScript['ugj_gpio_close'] = function (block) {
var code = 'pi.gpio_close();\n';
var code = 'await pi.gpio_close();\n';
return code;
};
Blockly.Python['ugj_gpio_close'] = function (block) {
@ -387,12 +387,12 @@ Blockly.Blocks['ugj_gpio_set_output'] = {
};
Blockly.JavaScript['ugj_gpio_set_output'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.gpio_set_output(${value_gpio});\n`;
var code = `await pi.gpio_set_output(${value_gpio});\n`;
return code;
};
Blockly.Python['ugj_gpio_set_output'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var code = `pi.gpio_set_output(${value_gpio})\n`;
var code = `await pi.gpio_set_output(${value_gpio})\n`;
return code;
};
@ -442,13 +442,13 @@ Blockly.Blocks['ugj_gpio_set_input'] = {
Blockly.JavaScript['ugj_gpio_set_input'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_lflag = block.getFieldValue('lflag');
var code = `pi.gpio_set_input(${value_gpio}, ${dropdown_lflag});\n`;
var code = `await pi.gpio_set_input(${value_gpio}, ${dropdown_lflag});\n`;
return code;
};
Blockly.Python['ugj_gpio_set_input'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var dropdown_lflag = block.getFieldValue('lflag');
var code = `pi.gpio_set_input(gpioHand, ${value_gpio}, ${dropdown_lflag})\n`;
var code = `await pi.gpio_set_input(gpioHand, ${value_gpio}, ${dropdown_lflag})\n`;
return code;
};
@ -478,12 +478,12 @@ Blockly.Blocks['ugj_gpio_read'] = {
};
Blockly.JavaScript['ugj_gpio_read'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.gpio_read(${value_gpio})`;
var code = `await pi.gpio_read(${value_gpio})`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_gpio_read'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var code = `pi.gpio_read(gpioHand, ${value_gpio})`;
var code = `await pi.gpio_read(gpioHand, ${value_gpio})`;
return [code, Blockly.Python.ORDER_NONE];
};
@ -529,13 +529,13 @@ Blockly.Blocks['ugj_gpio_write'] = {
Blockly.JavaScript['ugj_gpio_write'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_level = block.getFieldValue('level');
var code = `pi.gpio_write(${value_gpio}, ${dropdown_level});\n`;
var code = `await pi.gpio_write(${value_gpio}, ${dropdown_level});\n`;
return code;
};
Blockly.Python['ugj_gpio_write'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var dropdown_level = block.getFieldValue('level');
var code = `pi.gpio_write(gpioHand, ${value_gpio}, ${dropdown_level})\n`;
var code = `await pi.gpio_write(gpioHand, ${value_gpio}, ${dropdown_level})\n`;
return code;
};
@ -572,13 +572,13 @@ Blockly.Blocks['ugj_servo'] = {
Blockly.JavaScript['ugj_servo'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var value_pulsewidth = Blockly.JavaScript.valueToCode(block, 'pulsewidth', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.servo(${value_gpio}, ${value_pulsewidth});\n`;
var code = `await pi.servo(${value_gpio}, ${value_pulsewidth});\n`;
return code;
};
Blockly.Python['ugj_servo'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var value_pulsewidth = Blockly.Python.valueToCode(block, 'pulsewidth', Blockly.Python.ORDER_ATOMIC);
var code = `pi.servo(gpioHand, ${value_gpio}, ${value_pulsewidth})\n`;
var code = `await pi.servo(gpioHand, ${value_gpio}, ${value_pulsewidth})\n`;
return code;
};
@ -621,14 +621,14 @@ Blockly.JavaScript['ugj_pwm'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var value_pwm_frequency = Blockly.JavaScript.valueToCode(block, 'pwm_frequency', Blockly.JavaScript.ORDER_ATOMIC);
var value_pwm_duty_cycle = Blockly.JavaScript.valueToCode(block, 'pwm_duty_cycle', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.pwm(${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`;
var code = `await pi.pwm(${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`;
return code;
};
Blockly.Python['ugj_pwm'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var value_pwm_frequency = Blockly.Python.valueToCode(block, 'pwm_frequency', Blockly.Python.ORDER_ATOMIC);
var value_pwm_duty_cycle = Blockly.Python.valueToCode(block, 'pwm_duty_cycle', Blockly.Python.ORDER_ATOMIC);
var code = `pi.pwm(gpioHand, ${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle})\n`;
var code = `await pi.pwm(gpioHand, ${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle})\n`;
return code;
};
/********************** */
@ -680,7 +680,7 @@ Blockly.JavaScript['ugj_serial_open'] = function (block) {
Blockly.JavaScript.provideFunction_(
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
);
var code = `pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
var code = `await pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
return code;
};
Blockly.Python['ugj_serial_open'] = function (block) {
@ -746,12 +746,12 @@ Blockly.Blocks['ugj_serial_write'] = {
};
Blockly.JavaScript['ugj_serial_write'] = function (block) {
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.serial_write(${value_data});\n`;
var code = `await pi.serial_write(${value_data});\n`;
return code;
};
Blockly.Python['ugj_serial_write'] = function (block) {
var value_data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_ATOMIC);
var code = `pi.serial_write(ser_hand, ${value_data}.encode())\n`;
var code = `await pi.serial_write(ser_hand, ${value_data}.encode())\n`;
return code;
};
@ -781,12 +781,12 @@ Blockly.Blocks['ugj_serial_read'] = {
};
Blockly.JavaScript['ugj_serial_read'] = function (block) {
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.serial_read(${value_count})`;
var code = `await pi.serial_read(${value_count})`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_serial_read'] = function (block) {
var value_count = Blockly.Python.valueToCode(block, 'count', Blockly.Python.ORDER_ATOMIC);
var code = `pi.serial_read(ser_hand, ${value_count}).decode()`;
var code = `await pi.serial_read(ser_hand, ${value_count}).decode()`;
return [code, Blockly.Python.ORDER_ATOMIC];
};
@ -850,11 +850,11 @@ Blockly.Blocks['ugj_i2c_close'] = {
}
};
Blockly.JavaScript['ugj_i2c_close'] = function (block) {
var code = `pi.i2c_close();\n`;
var code = `await pi.i2c_close();\n`;
return code;
};
Blockly.Python['ugj_i2c_close'] = function (block) {
var code = `pi.i2c_close(i2c_hand)\n`;
var code = `await pi.i2c_close(i2c_hand)\n`;
return code;
};
@ -891,13 +891,13 @@ Blockly.Blocks['ugj_i2c_write_byte_data'] = {
Blockly.JavaScript['ugj_i2c_write_byte_data'] = function (block) {
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_write_byte_data(${value_reg}, ${value_byte_val});\n`;
var code = `await pi.i2c_write_byte_data(${value_reg}, ${value_byte_val});\n`;
return code;
};
Blockly.Python['ugj_i2c_write_byte_data'] = function (block) {
var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC);
var value_byte_val = Blockly.Python.valueToCode(block, 'byte_val', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_write_byte_data(i2c_hand, ${value_reg}, ${value_byte_val})\n`;
var code = `await pi.i2c_write_byte_data(i2c_hand, ${value_reg}, ${value_byte_val})\n`;
return code;
};
@ -927,12 +927,12 @@ Blockly.Blocks['ugj_i2c_read_byte_data'] = {
};
Blockly.JavaScript['ugj_i2c_read_byte_data'] = function (block) {
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_read_byte_data(${value_reg})\n`;
var code = `await pi.i2c_read_byte_data(${value_reg})\n`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_i2c_read_byte_data'] = function (block) {
var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_read_byte_data(i2c_hand, ${value_reg})\n`;
var code = `await pi.i2c_read_byte_data(i2c_hand, ${value_reg})\n`;
return [code, Blockly.Python.ORDER_ATOMIC];
};
@ -966,7 +966,7 @@ Blockly.Blocks['ugj_i2c_write_i2c_block_data'] = {
Blockly.JavaScript['ugj_i2c_write_i2c_block_data'] = function (block) {
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_write_i2c_block_data (${value_reg}, ${value_data});`;
var code = `await pi.i2c_write_i2c_block_data (${value_reg}, ${value_data});`;
return code;
};
Blockly.Python['ugj_i2c_write_i2c_block_data'] = function (block) {
@ -1003,12 +1003,12 @@ Blockly.Blocks['ugj_i2c_read_device'] = {
};
Blockly.JavaScript['ugj_i2c_read_device'] = function (block) {
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_read_device(${value_count})`;
var code = `await pi.i2c_read_device(${value_count})`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_i2c_read_device'] = function (block) {
var value_count = Blockly.Python.valueToCode(block, 'count', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_read_device(i2c_hand, ${value_count}).decode()`;
var code = `await pi.i2c_read_device(i2c_hand, ${value_count}).decode()`;
return [code, Blockly.Python.ORDER_ATOMIC];
};
/********************************************** */
@ -1038,12 +1038,12 @@ Blockly.Blocks['ugj_i2c_write_device'] = {
};
Blockly.JavaScript['ugj_i2c_write_device'] = function (block) {
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_write_device(${value_data})\n`;
var code = `await pi.i2c_write_device(${value_data})\n`;
return code;
};
Blockly.Python['ugj_i2c_write_device'] = function (block) {
var value_data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_write_device(i2c_hand, ${value_data}.encode())\n`;
var code = `await pi.i2c_write_device(i2c_hand, ${value_data}.encode())\n`;
return code;
};
@ -1101,12 +1101,12 @@ Blockly.JavaScript['ugj_bme280'] = function (block) {
` i2cBusNo: ${elutil.i2c_bus},`,
` i2cAddress: ${value_address}`,
`};`,
`bme280.init(options);`,
`let thp = bme280.readSensorData();`,
`await bme280.init(options);`,
`let thp = await bme280.readSensorData();`,
`${variable_temp} = Math.round(thp.temperature_C * 10) / 10;`,
`${variable_hum} = Math.round(thp.humidity * 10) / 10;`,
`${variable_pres} = Math.round(thp.pressure_hPa);`,
`bme280.cancel();`,
`await bme280.cancel();`,
``
].join('\n');
return code;
@ -1161,7 +1161,7 @@ Blockly.JavaScript['ugj_gesture_init'] = function (block) {
Blockly.JavaScript.provideFunction_(
'require_paj7620', [`const paj7620 = require('@ocogeclub/paj7620');`]
);
var code = `paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr});
var code = `await paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr});
`;
return code;
};
@ -1218,7 +1218,7 @@ Blockly.Blocks['ugj_gesture_stop'] = {
}
};
Blockly.JavaScript['ugj_gesture_stop'] = function (block) {
var code = 'paj7620.stop();\n';
var code = 'await paj7620.stop();\n';
return code;
};
Blockly.Python['ugj_gesture_stop'] = function (block) {
@ -1266,7 +1266,7 @@ Blockly.JavaScript['ugj_grideye_init'] = function (block) {
Blockly.JavaScript.provideFunction_(
'require_amg8833', [`const _amg8833 = require('@ocogeclub/amg8833');`]
);
var code = `_amg8833.init(${elutil.i2c_bus}, ${dropdown_addr});\n`;
var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr});\n`;
return code;
};
Blockly.Python['ugj_grideye_init'] = function (block) {
@ -1292,7 +1292,7 @@ Blockly.Blocks['ugj_grideye_thermistor'] = {
}
};
Blockly.JavaScript['ugj_grideye_thermistor'] = function (block) {
var code = `_amg8833.read_thermistor()`;
var code = `await _amg8833.read_thermistor()`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_grideye_thermistor'] = function (block) {
@ -1320,7 +1320,7 @@ Blockly.Blocks['ugj_grideye_read'] = {
}
};
Blockly.JavaScript['ugj_grideye_read'] = function (block) {
var code = '_amg8833.read_temp_array()';
var code = 'await _amg8833.read_temp_array()';
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_grideye_read'] = function (block) {
@ -1348,7 +1348,7 @@ Blockly.Blocks['ugj_grideye_stop'] = {
}
};
Blockly.JavaScript['ugj_grideye_stop'] = function (block) {
var code = '_amg8833.stop();\n';
var code = 'await _amg8833.stop();\n';
return code;
};
Blockly.Python['ugj_grideye_stop'] = function (block) {