ocoge/blocks/sensors/paj7620/index.js

90 lines
3.1 KiB
JavaScript
Raw Normal View History

/********** */
/** 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('@ocoge.club/` + apptool.gpio_backend + `');`]
);
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
Blockly.JavaScript.provideFunction_(
'require_paj7620', [`const _paj7620 = require('${modpath}');`]
);
var code = `await _paj7620.init(${apptool.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;
};