mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-24 16:39:49 +00:00
90 lines
3.1 KiB
JavaScript
90 lines
3.1 KiB
JavaScript
/********** */
|
|
/** PAJ7620 */
|
|
/********** */
|
|
Blockly.Msg["UGJ_GESTURE_INIT_TITLE"] = "ジェスチャーセンサー(アドレス: %1 )を初期化";
|
|
Blockly.Msg["UGJ_GESTURE_INIT_TOOLTIP"] = "PAJ7620 ジェスチャーセンサーを使用する準備をします。";
|
|
Blockly.Msg["UGJ_GESTURE_READ_TITLE"] = "ジェスチャーの値";
|
|
Blockly.Msg["UGJ_GESTURE_READ_TOOLTIP"] = "センサーから現在のジェスチャーの値(0〜9)を読み込みます";
|
|
Blockly.Msg["UGJ_GESTURE_STOP_TITLE"] = "ジェスチャーセンサーから切断";
|
|
Blockly.Msg["UGJ_GESTURE_STOP_TOOLTIP"] = "センサーとの接続を停止します。";
|
|
|
|
var ugjGestureInitDefinition = {
|
|
"type": "ugj_gesture_init",
|
|
"message0": "%{BKY_UGJ_GESTURE_INIT_TITLE}",
|
|
"args0": [
|
|
{
|
|
"type": "input_value",
|
|
"name": "i2c_addr",
|
|
"check": "Number"
|
|
}
|
|
],
|
|
"inputsInline": true,
|
|
"previousStatement": null,
|
|
"nextStatement": null,
|
|
"tooltip": "%{BKY_UGJ_GESTURE_INIT_TOOLTIP}",
|
|
"helpUrl": "",
|
|
"style": "sensor_blocks"
|
|
};
|
|
Blockly.Blocks['ugj_gesture_init'] = {
|
|
init: function () {
|
|
this.jsonInit(ugjGestureInitDefinition);
|
|
}
|
|
};
|
|
Blockly.JavaScript['ugj_gesture_init'] = function (block) {
|
|
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
|
|
Blockly.JavaScript.provideFunction_(
|
|
'require_gpio', [`const _pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
|
);
|
|
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
|
|
Blockly.JavaScript.provideFunction_(
|
|
'require_paj7620', [`const _paj7620 = require('${modpath}');`]
|
|
);
|
|
var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr}, window.addEventListener);
|
|
`;
|
|
return code;
|
|
};
|
|
|
|
/****************** */
|
|
/** Gesture Read ** */
|
|
/****************** */
|
|
var ugjGestureReadDefinition = {
|
|
"type": "ugj_gesture_read",
|
|
"message0": "%{BKY_UGJ_GESTURE_READ_TITLE}",
|
|
"inputsInline": true,
|
|
"output": "Number",
|
|
"tooltip": "%{BKY_UGJ_GESTURE_READ_TOOLTIP}",
|
|
"helpUrl": "https://ocoge.club/sensors/paj7620.html",
|
|
"style": "sensor_blocks"
|
|
};
|
|
Blockly.Blocks['ugj_gesture_read'] = {
|
|
init: function () {
|
|
this.jsonInit(ugjGestureReadDefinition);
|
|
}
|
|
};
|
|
Blockly.JavaScript['ugj_gesture_read'] = function (block) {
|
|
var code = 'await _paj7620.return_gesture()';
|
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
|
};
|
|
/****************** */
|
|
/** Gesture Stop ** */
|
|
/****************** */
|
|
var ugjGestureStopDefinition = {
|
|
"type": "ugj_gesture_stop",
|
|
"message0": "%{BKY_UGJ_GESTURE_STOP_TITLE}",
|
|
"inputsInline": true,
|
|
"previousStatement": null,
|
|
"nextStatement": null,
|
|
"tooltip": "%{BKY_UGJ_GESTURE_STOP_TOOLTIP}",
|
|
"helpUrl": "",
|
|
"style": "sensor_blocks"
|
|
};
|
|
Blockly.Blocks['ugj_gesture_stop'] = {
|
|
init: function () {
|
|
this.jsonInit(ugjGestureStopDefinition);
|
|
}
|
|
};
|
|
Blockly.JavaScript['ugj_gesture_stop'] = function (block) {
|
|
var code = 'await _paj7620.stop();\n';
|
|
return code;
|
|
};
|