ocoge/blocks/sensors/paj7620.js

123 lines
3.8 KiB
JavaScript
Raw Permalink 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);
}
};
javascript.javascriptGenerator.forBlock['ugj_gesture_init'] = function (block, generator) {
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
'require_paj7620', [`const _paj7620 = require('@ocoge/paj7620');`]
);
var code = `await _paj7620.init(_rg, ${apptool.i2c_bus}, ${value_i2c_addr});
`;
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);
}
};
javascript.javascriptGenerator.forBlock['ugj_gesture_read'] = function (block, generator) {
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);
}
};
javascript.javascriptGenerator.forBlock['ugj_gesture_stop'] = function (block, generator) {
var code = 'await _paj7620.stop();\n';
return code;
};
flyout_contents = flyout_contents.concat([
{
"kind": "label",
"text": "ジェスチャーセンサー PAJ7620",
"web-line": "4.0",
"web-line-width": "200"
},
{
"kind": "block",
"type": "ugj_gesture_init",
"inputs": {
"i2c_addr": {
"shadow": {
"type": "ugj_hextodec",
"inputs": {
"hex": {
"shadow": {
"type": "text",
"fields": {
"TEXT": "73"
}
}
}
}
}
}
}
},
{
"kind": "block",
"type": "ugj_gesture_read"
},
{
"kind": "block",
"type": "ugj_gesture_stop"
}
]);