[update] lib/の中身を整理・i2c bus の選択機能のテスト実装・gpio_inputブロックにミスがあったのを修正

pull/5/head
ocogeclub 2021-10-11 23:40:18 +09:00
parent 3f2d06bb51
commit 3a3b83a822
25 changed files with 187 additions and 32586 deletions

View File

@ -53,6 +53,5 @@
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
}

View File

@ -336,7 +336,7 @@
<field name="level">1</field>
</block>
<block type="ugj_gpio_set_input">
<field name="lflag">pi.SET_PULL_DOWN</field>
<field name="lflag">pi.PULL_DOWN</field>
<value name="gpio">
<shadow type="math_number">
<field name="NUM">6</field>
@ -440,6 +440,18 @@
</shadow>
</value>
</block>
<block type="ugj_i2c_write_i2c_block_data">
<value name="reg">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="data">
<shadow type="text">
<field name="TEXT">abc</field>
</shadow>
</value>
</block>
<block type="ugj_i2c_read_device">
<value name="count">
<shadow type="math_number">

View File

@ -87,6 +87,9 @@ Blockly.Msg["GPIO_CLOSE_TOOLTIP"] = "GPIOとの接続を終了します。";
Blockly.Msg["GPIO_CLOSE_TITLE"] = "GPIO の後片付けをする";
Blockly.Msg["GPIO_SET_INPUT_TITLE"] = "GPIO %1 を入力モードにして %2";
Blockly.Msg["GPIO_SET_INPUT_TOOLTIP"] = "GPIO端子を入力モードにして、プルアップ・プルダウン・無しを設定します。";
Blockly.Msg["GPIO_SET_INPUT_PULLUP"] = "プルアップ";
Blockly.Msg["GPIO_SET_INPUT_PULLDOWN"] = "プルダウン";
Blockly.Msg["GPIO_SET_INPUT_PULLNONE"] = "プル無し";
Blockly.Msg["GPIO_SET_OUTPUT_TITLE"] = "GPIO %1 を出力モードにする";
Blockly.Msg["GPIO_SET_OUTPUT_TOOLTIP"] = "GPIO端子のモードを出力に設定します。";
Blockly.Msg["GPIO_READ_TITLE"] = "GPIO %1 の値";
@ -117,6 +120,8 @@ Blockly.Msg["I2C_WRITE_BYTE_DATA_TITLE"] = "レジスタ %1 に %2 を書き込
Blockly.Msg["I2C_WRITE_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタに1バイトを書き込みます。";
Blockly.Msg["I2C_READ_BYTE_DATA_TITLE"] = "レジスタ %1 の値";
Blockly.Msg["I2C_READ_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタから1バイトを読み込みます。";
Blockly.Msg["I2C_WRITE_I2C_BLOCK_DATA_TITLE"] = "レジスタ %1 に %2 を書き込む";
Blockly.Msg["I2C_WRITE_I2C_BLOCK_DATA_TOOLTIP"] = "デバイスの指定されたレジスタに最大32バイトのテキストデータを書き込みます。";
Blockly.Msg["I2C_READ_DEVICE_TITLE"] = "i2cデバイスから %1 バイト受け取る";
Blockly.Msg["I2C_READ_DEVICE_TOOLTIP"] = "デバイスから指定したバイト数のデータを受け取ります。データが指定の長さより短いこともあります。";
Blockly.Msg["I2C_WRITE_DEVICE_TITLE"] = "i2c デバイスに %1 を送信";

View File

@ -12,8 +12,9 @@ const ugj_const = {
executable_path: './bin/',
localStorage_fname: 'ocoge.json',
error_ja_all: 'エラーが発生しました。\n『おこげ倶楽部』までお問い合わせください。',
PIG: 'pigpio',
LG: 'lgpio'
pig: 'pigpio',
lg: 'lgpio', // lgpioがテストフェーズを終えてハードウェアPWMを実装したら切り替えを実装予定
i2c_defbus: '6' // 文字列リテラルで指定
}
/** クラス elUtil ****************************************************************** */
@ -28,7 +29,8 @@ class elUtil {
this.wsChanged = false;
this.mascotFilePath = this.path.join(ugj_const.mascot_path, ugj_const.mascot_defname);
this.children = [];
this.gpio_backend = ugj_const.PIG;
this.gpio_backend = ugj_const.pig;
this.i2c_bus = ugj_const.i2c_defbus;
}
// 0で数値の桁合わせ : NUM=値 LEN=桁数
zeroPadding(NUM, LEN) {
@ -226,6 +228,11 @@ class elUtil {
return this.mascotFilePath;
}
// i2cバス番号変更
setI2cbusNo(n) {
this.i2c_bus = n;
}
// ファイル名にアプリケーションのドキュメントルートまでのパスをつけて返す
getDocPath(filename) {

File diff suppressed because one or more lines are too long

View File

@ -1,53 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import cv2
import time
# 引数
args = sys.argv
isWIN = 0
if len(args) >= 2:
if args[1] == "-w":
isWIN = 1
# カメラの準備
faceCascade = cv2.CascadeClassifier('scripts/haarcascade_frontalface_alt.xml')
capture = cv2.VideoCapture(0) # カメラセット
# 画像サイズの指定
ret = capture.set(3, 320)
ret = capture.set(4, 180)
try:
while True:
ret, image = capture.read() # 画像取得
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face = faceCascade.detectMultiScale(
gray_image, scaleFactor=1.3, minNeighbors=2, minSize=(30, 30))
if len(face) > 0: # 一番大きい顔を選ぶ
bigw = 0
for (x, y, w, h) in face:
if w > bigw:
bigx = x
bigw = w
if isWIN:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
pos = (bigx+(bigw/2)) - 160 # 顔の位置
print pos
sys.stdout.flush()
if isWIN: # カメラ画像表示
cv2.imshow("Camera Test", image)
# キーが押されたら保存・終了
if cv2.waitKey(10) == 32: # 32:[Space]
pass
except KeyboardInterrupt:
capture.release()
cv2.destroyAllWindows()
print "正常終了"

File diff suppressed because it is too large Load Diff

View File

@ -1,123 +0,0 @@
const CLASSES = {0:'zero', 1:'one', 2:'two', 3:'three', 4:'four',5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine'}
//-----------------------
// start button event
//-----------------------
$("#start-button").click(function(){
loadModel() ;
startWebcam();
});
//-----------------------
// load model
//-----------------------
let model;
async function loadModel() {
console.log("model loading..");
$("#console").html(`<li>model loading...</li>`);
model=await tf.loadModel(`http://localhost:8080/sign_language_vgg16/model.json`);
console.log("model loaded.");
$("#console").html(`<li>VGG16 pre trained model loaded.</li>`);
};
//-----------------------
// start webcam
//-----------------------
var video;
function startWebcam() {
console.log("video streaming start.");
$("#console").html(`<li>video streaming start.</li>`);
video = $('#main-stream-video').get(0);
vendorUrl = window.URL || window.webkitURL;
navigator.getMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
navigator.getMedia({
video: true,
audio: false
}, function(stream) {
localStream = stream;
video.srcObject = stream;
video.play();
}, function(error) {
alert("Something wrong with webcam!");
});
}
//-----------------------
// predict button event
//-----------------------
$("#predict-button").click(function(){
setInterval(predict, 1000/10);
});
//-----------------------
// TensorFlow.js method
// predict tensor
//-----------------------
async function predict(){
let tensor = captureWebcam();
let prediction = await model.predict(tensor).data();
let results = Array.from(prediction)
.map(function(p,i){
return {
probability: p,
className: CLASSES[i]
};
}).sort(function(a,b){
return b.probability-a.probability;
}).slice(0,5);
$("#console").empty();
results.forEach(function(p){
$("#console").append(`<li>${p.className} : ${p.probability.toFixed(6)}</li>`);
console.log(p.className,p.probability.toFixed(6))
});
};
//------------------------------
// capture streaming video
// to a canvas object
//------------------------------
function captureWebcam() {
var canvas = document.createElement("canvas");
var context = canvas.getContext('2d');
canvas.width = video.width;
canvas.height = video.height;
context.drawImage(video, 0, 0, video.width, video.height);
tensor_image = preprocessImage(canvas);
return tensor_image;
}
//-----------------------
// TensorFlow.js method
// image to tensor
//-----------------------
function preprocessImage(image){
let tensor = tf.fromPixels(image).resizeNearestNeighbor([100,100]).toFloat();
let offset = tf.scalar(255);
return tensor.div(offset).expandDims();
}
//-----------------------
// clear button event
//-----------------------
$("#clear-button").click(function clear() {
location.reload();
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
'use strict';
this.pig = null;
this.pi = null;
this.i2cBusNo = null;
@ -41,16 +42,24 @@ this.REGISTER_TEMP_DATA = 0xFA;
this.REGISTER_HUMIDITY_DATA = 0xFD;
exports.init = (options) => {
this.pi = require('@ocogeclub/lgpio');
this.pig = require('@ocogeclub/pigpio')
// console.log('pig= ' + this.pig)
this.pi = 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.pi._i2c_open(this.i2cBusNo, this.i2cAddress);
this.i2cHand = 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.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CHIPID, 0);
r = 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.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_CHIPID);
let chipId = 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() &&
chipId !== this.CHIP_ID2_BMP280() &&
@ -64,11 +73,13 @@ exports.init = (options) => {
}
// Humidity 16x oversampling
//
let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
let r = 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.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
r = 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}`;
return 0;
@ -81,7 +92,8 @@ exports.init = (options) => {
//
exports.reset = () => {
const POWER_ON_RESET_CMD = 0xB6;
let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
let r = 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;
}
@ -92,8 +104,11 @@ exports.reset = () => {
//
exports.cancel = () => {
if (this.i2cHand >= 0) {
this.pi._i2c_close(this.i2cHand);
this.i2cHand = 0;
this.pig._i2c_close(this.pi, this.i2cHand);
// this.pi._i2c_close(this.i2cHand);
this.i2cHand = null;
this.pig._pigpio_stop(this.pi);
this.pi = null;
}
}
@ -104,7 +119,8 @@ exports.readSensorData = () => {
// Grab temperature, humidity, and pressure in a single read
//
let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
let buffer = 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)
//
@ -156,16 +172,24 @@ exports.readSensorData = () => {
}
exports.loadCalibration = (callback) => {
let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_DIG_T1, 24);
let buffer = 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.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);
let h4 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H4);
let h5 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5);
let h5_1 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5 + 1);
let h6 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H6);
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 = 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);
// let h4 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H4);
// let h5 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5);
// let h5_1 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5 + 1);
// let h6 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H6);
this.cal = {
dig_T1: this.uint16(buffer[1], buffer[0]),

View File

@ -5,6 +5,6 @@
"private": true,
"license": "MIT",
"dependencies": {
"@ocogeclub/lgpio": "file:../lgpio"
"@ocogeclub/pigpio": "file:../pigpio"
}
}

View File

@ -78,6 +78,9 @@ module.exports.i2c_write_byte_data = (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_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_read_device = count => {
if (i2c_hand >= 0) return module.exports._i2c_read_device(pi, i2c_hand, count).toString('utf8');
}

View File

@ -25,7 +25,8 @@ Value _pigpioStart(const CallbackInfo &info)
}
std::string addrStr = info[0].As<String>().Utf8Value();
std::string portStr = info[1].As<String>().Utf8Value();
return Number::New(env, pigpio_start(&addrStr[0], &portStr[0]));
return Number::New(env, pigpio_start(addrStr.c_str(), portStr.c_str()));
// return Number::New(env, pigpio_start(&addrStr[0], &portStr[0]));
}
// pigpio 後始末
@ -389,7 +390,7 @@ Value _i2cClose(const CallbackInfo &info)
return env.Null();
}
int pi = info[0].As<Number>().Int32Value();
unsigned int handle = info[0].As<Number>().Uint32Value();
unsigned int handle = info[1].As<Number>().Uint32Value();
return Number::New(env,
i2c_close(pi, handle));
@ -455,9 +456,9 @@ Value _i2cWriteByteData(const CallbackInfo &info)
return env.Null();
}
int pi = info[0].As<Number>().Int32Value();
unsigned int handle = info[0].As<Number>().Uint32Value();
unsigned int i2c_reg = info[1].As<Number>().Uint32Value();
unsigned int bVal = info[2].As<Number>().Uint32Value();
unsigned int handle = info[1].As<Number>().Uint32Value();
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
unsigned int bVal = info[3].As<Number>().Uint32Value();
return Number::New(env,
i2c_write_byte_data(pi, handle, i2c_reg, bVal));
@ -486,6 +487,32 @@ Value _i2cReadByteData(const CallbackInfo &info)
i2c_read_byte_data(pi, handle, i2c_reg));
}
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに最大バイトのデータを書き込む。
Value _i2cWriteI2cBlockData(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 4)
{
TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsBuffer())
{
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
return env.Null();
}
int pi = info[0].As<Number>().Int32Value();
unsigned int handle = info[1].As<Number>().Uint32Value();
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
auto buf = info[3].As<Buffer<char>>();
unsigned int count = buf.Length();
return Number::New(env,
i2c_write_i2c_block_data(pi, handle, i2c_reg, buf.Data(), count));
}
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタからcountバイトを読み込む。countは132。
Value _i2cReadI2cBlockData(const CallbackInfo &info)
{
@ -612,6 +639,7 @@ Init(Env env, Object exports)
exports.Set(String::New(env, "_i2c_read_byte"), Function::New(env, _i2cReadByte));
exports.Set(String::New(env, "_i2c_write_byte_data"), Function::New(env, _i2cWriteByteData));
exports.Set(String::New(env, "_i2c_read_byte_data"), Function::New(env, _i2cReadByteData));
exports.Set(String::New(env, "_i2c_write_i2c_block_data"), Function::New(env, _i2cWriteI2cBlockData));
exports.Set(String::New(env, "_i2c_read_i2c_block_data"), Function::New(env, _i2cReadI2cBlockData));
exports.Set(String::New(env, "_i2c_read_word_data"), Function::New(env, _i2cReadWordData));
exports.Set(String::New(env, "_i2c_write_device"), Function::New(env, _i2cWriteDevice));

27
main.js
View File

@ -124,7 +124,32 @@ app.whenReady().then(() => {
accelerator: "CommandOrControl+Q"
}
]
}
},
{
label: "Settings",
submenu: [
{
label: "i2c bus",
submenu: [
{
label: "1",
click: (item, focusedWindow) => {
if (focusedWindow)
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("1")');
}
},
{
label: "6",
click: (item, focusedWindow) => {
if (focusedWindow)
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("6")');
}
},
]
}
]
},
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

View File

@ -30,4 +30,4 @@
"axios": "^0.21.1",
"nodemailer": "^6.6.0"
}
}
}

View File

@ -399,16 +399,16 @@ var ugjGpioSetInputDefinition = {
"name": "lflag",
"options": [
[
"プルアップ",
"pi.SET_PULL_UP"
"%{BKY_GPIO_SET_INPUT_PULLUP}",
"pi.PULL_UP"
],
[
"プルダウン",
"pi.SET_PULL_DOWN"
"%{BKY_GPIO_SET_INPUT_PULLDOWN}",
"pi.PULL_DOWN"
],
[
"プル無し",
"pi.SET_PULL_NONE"
"%{BKY_GPIO_SET_INPUT_PULLNONE}",
"pi.PULL_NONE"
]
]
}
@ -664,7 +664,7 @@ Blockly.JavaScript['ugj_serial_open'] = function (block) {
// var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_baud = block.getFieldValue('baud');
Blockly.JavaScript.provideFunction_(
'require_oclg', [`const pi = require('@ocogeclub/lgpio');`]
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
);
var code = `pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
return code;
@ -804,9 +804,9 @@ Blockly.Blocks['ugj_i2c_open'] = {
Blockly.JavaScript['ugj_i2c_open'] = function (block) {
var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
'require_oclg', [`const pi = require('@ocogeclub/lgpio');`]
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
);
var code = `pi.i2c_open(3, ${value_i2c_address});\n`;
var code = `pi.i2c_open(${elutil.i2c_bus}, ${value_i2c_address});\n`;
return code;
};
Blockly.Python['ugj_i2c_open'] = function (block) {
@ -922,6 +922,47 @@ Blockly.Python['ugj_i2c_read_byte_data'] = function (block) {
return [code, Blockly.Python.ORDER_ATOMIC];
};
var ugjI2cWriteI2cBlockDataDefinition = {
"type": "ugj_i2c_write_i2c_block_data",
"message0": "%{BKY_I2C_WRITE_I2C_BLOCK_DATA_TITLE}",
"args0": [
{
"type": "input_value",
"name": "reg",
"check": "Number"
},
{
"type": "input_value",
"name": "data",
"check": "String"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_I2C_WRITE_I2C_BLOCK_DATA_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_i2c_write_i2c_block_data'] = {
init: function () {
this.jsonInit(ugjI2cWriteI2cBlockDataDefinition);
}
};
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});`;
return code;
};
Blockly.Python['ugj_i2c_write_i2c_block_data'] = function (block) {
var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC);
var value_name = Blockly.Python.valueToCode(block, 'NAME', Blockly.Python.ORDER_ATOMIC);
// TODO: Assemble Python into code variable.
var code = '...\n';
return code;
};
/************************************************************************** */
/** Returns count bytes read from the raw device associated with handle. ** */
/************************************************************************** */
@ -1043,7 +1084,7 @@ Blockly.JavaScript['ugj_bme280'] = function (block) {
);
var code = [
`const options = {`,
` i2cBusNo: 3,`,
` i2cBusNo: ${elutil.i2c_bus},`,
` i2cAddress: ${value_address}`,
`};`,
`bme280.init(options);`,

View File

@ -64,13 +64,7 @@
"@ocogeclub/bme280@file:local_modules/@ocogeclub/bme280":
version "0.0.1"
dependencies:
"@ocogeclub/lgpio" "file:../../.cache/yarn/v6/npm-@ocogeclub-bme280-0.0.1-a3a7781d-d04c-4890-9c31-c037b0309492-1633696738699/node_modules/@ocogeclub/lgpio"
"@ocogeclub/lgpio@file:local_modules/@ocogeclub/lgpio":
version "0.0.1"
dependencies:
bindings "^1.5.0"
node-addon-api "^1.7.1"
"@ocogeclub/pigpio" "file:../../.cache/yarn/v6/npm-@ocogeclub-bme280-0.0.1-afe790ae-69ff-47f6-96b0-8796b0a559a8-1633832163228/node_modules/@ocogeclub/pigpio"
"@ocogeclub/pigpio@file:local_modules/@ocogeclub/pigpio":
version "0.0.1"