add io blocks

This commit is contained in:
Mario
2020-07-23 16:04:00 +02:00
parent d1d7a447bc
commit eca3bf16a1
11 changed files with 817 additions and 41 deletions
+3 -1
View File
@@ -1,4 +1,6 @@
import './loops';
import './sensebox';
import './logic';
import './sensebox-sensors';
import './sensebox-sensors';
import './sensebox-telegram';
import './io';
+257
View File
@@ -0,0 +1,257 @@
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview Blocks for Arduino Digital and Analogue input and output
* functions. The Arduino function syntax can be found at
* http://arduino.cc/en/Reference/HomePage
*
* TODO: maybe change this to a "PIN" BlocklyType
*/
import { defineBlocksWithJsonArray } from 'blockly';
import Blockly from 'blockly/core';
import { selectedBoard } from '../helpers/board'
Blockly.Blocks['io_digitalwrite'] = {
/**
* Block for creating a 'set pin' to a state.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(250);
this.appendValueInput('STATE')
.appendField(Blockly.Msg.ARD_DIGITALWRITE)
.appendField(new Blockly.FieldDropdown(
selectedBoard().digitalPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
// .setCheck(Blockly.Types.BOOLEAN.checkList);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_DIGITALWRITE_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function () {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'digitalPins');
}
};
Blockly.Blocks['io_digitalread'] = {
/**
* Block for creating a 'read pin'.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalRead');
this.setColour(250);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_DIGITALREAD)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.digitalPins), 'PIN');
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_DIGITALREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.BOOLEAN;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function () {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'PIN', 'digitalPins');
}
};
Blockly.Blocks['io_builtin_led'] = {
/**
* Block for setting built-in LED to a state.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(250);
this.appendValueInput('STATE')
.appendField(Blockly.Msg.ARD_BUILTIN_LED)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.builtinLed), 'BUILT_IN_LED')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.BOOLEAN.checkList);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_BUILTIN_LED_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function () {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'BUILT_IN_LED', 'builtinLed');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.BOOLEAN;
},
};
Blockly.Blocks['io_analogwrite'] = {
/**
* Block for creating a 'set pin' to an analogue value.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogWrite');
this.setColour(250);
this.appendValueInput('NUM')
.appendField(Blockly.Msg.ARD_ANALOGWRITE)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.pwmPins), 'PIN')
.appendField(Blockly.Msg.ARD_WRITE_TO)
.setCheck(Blockly.Types.NUMBER.output);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.ARD_ANALOGWRITE_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function () {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'pwmPins');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.NUMBER;
},
};
Blockly.Blocks['io_analogread'] = {
/**
* Block for reading an analogue input.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogRead');
this.setColour(250);
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_ANALOGREAD)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.analogPins), 'PIN');
this.setOutput(true, Blockly.Types.NUMBER.output);
this.setTooltip(Blockly.Msg.ARD_ANALOGREAD_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.NUMBER;
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function () {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'analogPins');
}
};
Blockly.Blocks['io_highlow'] = {
/**
* Block for creating a pin state.
* @this Blockly.Block
*/
init: function () {
this.setHelpUrl('http://arduino.cc/en/Reference/Constants');
this.setColour(250);
this.appendDummyInput()
.appendField(
new Blockly.FieldDropdown([[Blockly.Msg.ARD_HIGH, 'HIGH'], [Blockly.Msg.ARD_LOW, 'LOW']]),
'STATE');
this.setOutput(true, Blockly.Types.BOOLEAN.output);
this.setTooltip(Blockly.Msg.ARD_HIGHLOW_TIP);
},
/** @return {!string} The type of return value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.BOOLEAN;
}
};
Blockly.Blocks['io_pulsein'] = {
/**
* Block for measuring the duration of a pulse in an input pin.
* @this Blockly.Block
*/
init: function () {
this.jsonInit({
"type": "math_foo",
"message0": Blockly.Msg.ARD_PULSE_READ,
"args0": [{
"type": "input_value",
"name": "PULSETYPE",
"check": Blockly.Types.BOOLEAN.check
}, {
"type": "field_dropdown",
"name": "PULSEPIN",
"options": Blockly.Arduino.Boards.selected.digitalPins
}
],
"output": Blockly.Types.NUMBER.output,
"inputsInline": true,
"colour": 250,
"tooltip": Blockly.Msg.ARD_PULSE_TIP,
"helpUrl": 'https://www.arduino.cc/en/Reference/PulseIn'
});
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.NUMBER;
}
};
Blockly.Blocks['io_pulsetimeout'] = {
/**
* Block for measuring (with a time-out) the duration of a pulse in an input
* pin.
* @this Blockly.Block
*/
init: function () {
this.jsonInit({
"type": "math_foo",
"message0": Blockly.Msg.ARD_PULSE_READ_TIMEOUT,
"args0": [{
"type": "input_value",
"name": "PULSETYPE",
"check": Blockly.Types.BOOLEAN.check
}, {
"type": "field_dropdown",
"name": "PULSEPIN",
"options": Blockly.Arduino.Boards.selected.digitalPins
}, {
"type": "input_value",
"name": "TIMEOUT",
"check": Blockly.Types.NUMBER.check
}
],
"output": Blockly.Types.NUMBER.output,
"inputsInline": true,
"colour": 250,
"tooltip": Blockly.Msg.ARD_PULSETIMEOUT_TIP,
"helpUrl": 'https://www.arduino.cc/en/Reference/PulseIn'
});
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function () {
return Blockly.Types.NUMBER;
}
};
@@ -0,0 +1,17 @@
import Blockly from 'blockly';
Blockly.Blocks["sensebox_telegram"] = {
init: function () {
this.setColour(120);
this.appendDummyInput()
.appendField(Blockly.Msg.senseBox_telegram_init);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_LEFT)
.appendField("telegram")
.appendField(new Blockly.FieldTextInput("token"), "telegram_token");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
+1 -13
View File
@@ -1,16 +1,4 @@
import Blockly from 'blockly';
Blockly.Blocks["sensebox_telegram"] = {
init: function () {
this.setColour(120);
this.appendDummyInput()
.appendField(Blockly.Msg.senseBox_telegram_init);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_LEFT)
.appendField("telegram")
.appendField(new Blockly.FieldTextInput("token"), "telegram_token");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};