Skip to content

Commit 2249a46

Browse files
authored
Merge pull request #327 from sensebox/development
Development
2 parents efbdc19 + 1e906d8 commit 2249a46

File tree

15 files changed

+599
-287
lines changed

15 files changed

+599
-287
lines changed

src/components/Blockly/BlocklyWindow.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ class BlocklyWindow extends Component {
3838
zoomToFit.init();
3939
// Initialize plugin.
4040
const backpack = new Backpack(workspace);
41+
4142
backpack.init();
4243
}
4344

4445
componentDidUpdate(props) {
4546
const workspace = Blockly.getMainWorkspace();
4647
var xml = this.props.initialXml;
4748
if (props.selectedBoard !== this.props.selectedBoard) {
48-
xml = localStorage.getItem("autoSaveXML");
49+
xml = localStorage.getItem("autoSaveXML");
4950
// change board
50-
if(!xml) xml = initialXml;
51+
if (!xml) xml = initialXml;
5152
var xmlDom = Blockly.Xml.textToDom(xml);
5253
Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace);
53-
5454
}
55-
55+
5656
// if svg is true, then the update process is done in the BlocklySvg component
5757
if (props.initialXml !== xml && !this.props.svg) {
5858
// guarantees that the current xml-code (this.props.initialXml) is rendered
@@ -62,14 +62,15 @@ class BlocklyWindow extends Component {
6262
}
6363
if (props.language !== this.props.language) {
6464
// change language
65-
xml = localStorage.getItem("autoSaveXML");
65+
xml = localStorage.getItem("autoSaveXML");
6666
if (!xml) xml = initialXml;
67-
xmlDom = Blockly.Xml.textToDom(xml);
67+
xmlDom = Blockly.Xml.textToDom(xml);
6868
Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace);
6969
// var toolbox = workspace.getToolbox();
7070
// workspace.updateToolbox(toolbox.toolboxDef_);
7171
}
7272
Blockly.svgResize(workspace);
73+
7374
}
7475

7576
render() {

src/components/Blockly/blocks/io.js

+43-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import Blockly from "blockly/core";
1414
import { selectedBoard } from "../helpers/board";
1515
import * as Types from "../helpers/types";
16+
import { getColour } from "../helpers/colour";
1617

1718
Blockly.Blocks["io_digitalwrite"] = {
1819
/**
@@ -21,7 +22,7 @@ Blockly.Blocks["io_digitalwrite"] = {
2122
*/
2223
init: function () {
2324
this.setHelpUrl("http://arduino.cc/en/Reference/DigitalWrite");
24-
this.setColour(250);
25+
this.setColour(getColour().io);
2526
this.appendValueInput("STATE")
2627
.appendField(Blockly.Msg.ARD_DIGITALWRITE)
2728
.appendField(
@@ -55,7 +56,7 @@ Blockly.Blocks["io_digitalread"] = {
5556
*/
5657
init: function () {
5758
this.setHelpUrl("http://arduino.cc/en/Reference/DigitalRead");
58-
this.setColour(250);
59+
this.setColour(getColour().io);
5960
this.appendDummyInput()
6061
.appendField(Blockly.Msg.ARD_DIGITALREAD)
6162
.appendField(
@@ -89,7 +90,7 @@ Blockly.Blocks["io_builtin_led"] = {
8990
*/
9091
init: function () {
9192
this.setHelpUrl("http://arduino.cc/en/Reference/DigitalWrite");
92-
this.setColour(250);
93+
this.setColour(getColour().io);
9394
this.appendValueInput("STATE")
9495
.appendField(Blockly.Msg.ARD_BUILTIN_LED)
9596
.appendField(
@@ -127,7 +128,7 @@ Blockly.Blocks["io_analogwrite"] = {
127128
*/
128129
init: function () {
129130
this.setHelpUrl("http://arduino.cc/en/Reference/AnalogWrite");
130-
this.setColour(250);
131+
this.setColour(getColour().io);
131132
this.appendValueInput("NUM")
132133
.appendField(Blockly.Msg.ARD_ANALOGWRITE)
133134
.appendField(new Blockly.FieldDropdown(selectedBoard().pwmPins), "PIN")
@@ -158,7 +159,7 @@ Blockly.Blocks["io_analogread"] = {
158159
*/
159160
init: function () {
160161
this.setHelpUrl("http://arduino.cc/en/Reference/AnalogRead");
161-
this.setColour(250);
162+
this.setColour(getColour().io);
162163
this.appendDummyInput()
163164
.appendField(Blockly.Msg.ARD_ANALOGREAD)
164165
.appendField(
@@ -188,7 +189,7 @@ Blockly.Blocks["io_highlow"] = {
188189
*/
189190
init: function () {
190191
this.setHelpUrl("http://arduino.cc/en/Reference/Constants");
191-
this.setColour(250);
192+
this.setColour(getColour().io);
192193
this.appendDummyInput().appendField(
193194
new Blockly.FieldDropdown([
194195
[Blockly.Msg.ARD_HIGH, "HIGH"],
@@ -228,7 +229,7 @@ Blockly.Blocks["io_pulsein"] = {
228229
],
229230
output: Types.NUMBER.typeName,
230231
inputsInline: true,
231-
colour: 250,
232+
colour: getColour().io,
232233
tooltip: Blockly.Msg.ARD_PULSE_TIP,
233234
helpUrl: "https://www.arduino.cc/en/Reference/PulseIn",
234235
});
@@ -268,7 +269,7 @@ Blockly.Blocks["io_pulsetimeout"] = {
268269
],
269270
output: Types.NUMBER.typeName,
270271
inputsInline: true,
271-
colour: 250,
272+
colour: getColour().io,
272273
tooltip: Blockly.Msg.ARD_PULSETIMEOUT_TIP,
273274
helpUrl: "https://www.arduino.cc/en/Reference/PulseIn",
274275
});
@@ -278,3 +279,37 @@ Blockly.Blocks["io_pulsetimeout"] = {
278279
return Types.NUMBER.typeName;
279280
},
280281
};
282+
283+
Blockly.Blocks["io_analogreadmillivolt"] = {
284+
/**
285+
* Block for reading an analogue input.
286+
* @this Blockly.Block
287+
*/
288+
init: function () {
289+
this.setHelpUrl(
290+
"https://docs.espressif.com/projects/arduino-esp32/en/latest/api/adc.html"
291+
);
292+
this.setColour(getColour().io);
293+
this.appendDummyInput()
294+
.appendField(Blockly.Msg.ARD_ANALOGREADMILIVOLT)
295+
.appendField("Port:")
296+
.appendField(
297+
new Blockly.FieldDropdown(selectedBoard().digitalPorts),
298+
"Port"
299+
);
300+
301+
this.setOutput(true, Types.NUMBER.typeName);
302+
this.setTooltip(Blockly.Msg.ARD_ANALOGREADMILIVOLT_TIP);
303+
},
304+
/** @return {!string} The type of return value for the block, an integer. */
305+
getBlockType: function () {
306+
return Types.NUMBER.typeName;
307+
},
308+
/**
309+
* Updates the content of the the pin related fields.
310+
* @this Blockly.Block
311+
*/
312+
updateFields: function () {
313+
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, "PIN", "analogPins");
314+
},
315+
};

0 commit comments

Comments
 (0)