mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-21 15:19:48 +00:00
[update] lgpioモジュールの一部関数の戻り値の返し方を変更
This commit is contained in:
parent
a16f58b2a9
commit
5caa639a26
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,5 @@ build/
|
||||
push.sh
|
||||
n
|
||||
*.bak
|
||||
*.old
|
||||
*.old
|
||||
lg/
|
@ -104,7 +104,7 @@ class BME280 {
|
||||
|
||||
// Grab temperature, humidity, and pressure in a single read
|
||||
//
|
||||
let [count, buffer] = this.pi.i2c_read_i2c_block_data(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)
|
||||
//
|
||||
@ -156,7 +156,7 @@ class BME280 {
|
||||
}
|
||||
|
||||
loadCalibration(callback) {
|
||||
let [count, buffer] = this.pi.i2c_read_i2c_block_data(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.pi.i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H1);
|
||||
|
@ -257,18 +257,11 @@ Value SerialRead(const CallbackInfo &info)
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int count = info[1].As<Number>().Int32Value();
|
||||
|
||||
// char rxBuf[count + 1];
|
||||
// int32_t resultCount = lgSerialRead(handle, rxBuf, count);
|
||||
// Buffer<char> resultBuf = Buffer<char>::Copy(env, rxBuf, count);
|
||||
auto rxBuf = Buffer<char>::New(env, count);
|
||||
int rxCount = lgSerialRead(handle, rxBuf.Data(), count);
|
||||
char rxBuf[count];
|
||||
int rxCount = lgSerialRead(handle, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
Array returnArr = Array::New(env);
|
||||
int i = 0;
|
||||
returnArr[i] = Number::New(env, rxCount);
|
||||
returnArr[++i] = rxBuf;
|
||||
|
||||
return returnArr;
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// シリアルデバイスにバイト列を送る(data: buffer)
|
||||
@ -452,15 +445,11 @@ Value i2cReadI2cBlockData(const CallbackInfo &info)
|
||||
int i2cReg = info[1].As<Number>().Int32Value();
|
||||
int count = info[2].As<Number>().Int32Value();
|
||||
|
||||
auto rxBuf = Buffer<char>::New(env, count);
|
||||
int rxCount = lgI2cReadI2CBlockData(handle, i2cReg, rxBuf.Data(), count);
|
||||
char rxBuf[count];
|
||||
int rxCount = lgI2cReadI2CBlockData(handle, i2cReg, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
Array returnArr = Array::New(env);
|
||||
int i = 0;
|
||||
returnArr[i] = Number::New(env, rxCount);
|
||||
returnArr[++i] = rxBuf;
|
||||
|
||||
return returnArr;
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから単一の16ビットワードを読み取る
|
||||
@ -505,15 +494,11 @@ Value I2cReadDevice(const CallbackInfo &info)
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int count = info[1].As<Number>().Int32Value();
|
||||
|
||||
auto rxBuf = Buffer<char>::New(env, count);
|
||||
int rxCount = lgI2cReadDevice(handle, rxBuf.Data(), count);
|
||||
char rxBuf[count];
|
||||
int rxCount = lgI2cReadDevice(handle, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
auto returnArr = Array::New(env);
|
||||
int i = 0;
|
||||
returnArr[i] = Number::New(env, rxCount);
|
||||
returnArr[++i] = rxBuf;
|
||||
|
||||
return returnArr;
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// i2c デバイスにバイト列を送る(data: buffer)
|
||||
|
@ -767,30 +767,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 functionName = Blockly.JavaScript.provideFunction_(
|
||||
'ugj_serial_read',
|
||||
[
|
||||
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = ser_hand => {',
|
||||
`[count, data] = pi.serial_read(ser_hand, ${value_count});`,
|
||||
`return data.toString('utf8', 0, count);`,
|
||||
'}'
|
||||
]
|
||||
);
|
||||
var code = `${functionName}(ser_hand)`;
|
||||
var code = `pi.serial_read(ser_hand, ${value_count}).toString('utf8')`;
|
||||
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 functionName = Blockly.Python.provideFunction_(
|
||||
'ugj_serial_read',
|
||||
[
|
||||
'def ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(ser_hand) :',
|
||||
` (count, data) = pi.serial_read(ser_hand, ${value_count})`,
|
||||
` return data[0:count].decode()`,
|
||||
''
|
||||
]
|
||||
);
|
||||
var code = `${functionName}(ser_hand)`;
|
||||
var code = `pi.serial_read(ser_hand, ${value_count}).decode()`;
|
||||
return [code, Blockly.Python.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
@ -966,30 +948,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 functionName = Blockly.JavaScript.provideFunction_(
|
||||
'ugj_i2c_read_device',
|
||||
[
|
||||
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = i2c_hand => {',
|
||||
`[count, data] = pi.i2c_read_device(i2c_hand, ${value_count});`,
|
||||
`return data.toString('utf8', 0, count);`,
|
||||
'}'
|
||||
]
|
||||
);
|
||||
var code = `${functionName}(i2c_hand)`;
|
||||
var code = `pi.i2c_read_device(i2c_hand, ${value_count}).toString('utf8')`;
|
||||
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 functionName = Blockly.Python.provideFunction_(
|
||||
'ugj_i2c_read_device',
|
||||
[
|
||||
'def ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(i2c_hand) :',
|
||||
` (count, data) = pi.i2c_read_device(i2c_hand, ${value_count})`,
|
||||
` return data[0:count].decode()`,
|
||||
''
|
||||
]
|
||||
);
|
||||
var code = `${functionName}(i2c_hand)`;
|
||||
var code = `pi.i2c_read_device(i2c_hand, ${value_count}).decode()`;
|
||||
return [code, Blockly.Python.ORDER_ATOMIC];
|
||||
};
|
||||
/********************************************** */
|
||||
|
Loading…
Reference in New Issue
Block a user