update code generation to replace mcu library
This commit is contained in:
@@ -18,6 +18,7 @@ import "./audio";
|
||||
import "./math";
|
||||
import "./map";
|
||||
import "./procedures";
|
||||
import "./serial";
|
||||
import "./time";
|
||||
import "./variables";
|
||||
import "./lists";
|
||||
|
||||
@@ -2,6 +2,7 @@ import Blockly from "blockly";
|
||||
import { getColour } from "../helpers/colour";
|
||||
import * as Types from "../helpers/types";
|
||||
import { selectedBoard } from "../helpers/board";
|
||||
import { FieldGridDropdown } from "@blockly/field-grid-dropdown";
|
||||
|
||||
/**
|
||||
* HDC1080 Temperature and Humidity Sensor
|
||||
@@ -245,9 +246,7 @@ Blockly.Blocks["sensebox_sensor_ultrasonic_ranger"] = {
|
||||
[Blockly.Msg.senseBox_ultrasonic_port_B, "B"],
|
||||
[Blockly.Msg.senseBox_ultrasonic_port_C, "C"],
|
||||
];
|
||||
var dropdown = new Blockly.FieldDropdown(dropdownOptions, function (
|
||||
option
|
||||
) {
|
||||
var dropdown = new FieldGridDropdown(dropdownOptions, function (option) {
|
||||
var input = option === "A" || option === "B" || option === "C";
|
||||
this.sourceBlock_.updateShape_(input);
|
||||
});
|
||||
@@ -268,6 +267,10 @@ Blockly.Blocks["sensebox_sensor_ultrasonic_ranger"] = {
|
||||
new Blockly.FieldDropdown(selectedBoard().digitalPins),
|
||||
"ultrasonic_echo"
|
||||
);
|
||||
this.appendDummyInput("maxDistance")
|
||||
.appendField(Blockly.Msg.senseBox_ultrasonic_maxDistance)
|
||||
.appendField(new Blockly.FieldTextInput("250"), "maxDistance")
|
||||
.appendField("cm");
|
||||
this.setOutput(true, Types.NUMBER.typeName);
|
||||
this.setTooltip(Blockly.Msg.senseBox_ultrasonic_tooltip);
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_ultrasonic_helpurl);
|
||||
@@ -355,6 +358,7 @@ Blockly.Blocks["sensebox_button"] = {
|
||||
[Blockly.Msg.senseBox_button_isPressed, "isPressed"],
|
||||
[Blockly.Msg.senseBox_button_wasPressed, "wasPressed"],
|
||||
[Blockly.Msg.senseBox_button_switch, "Switch"],
|
||||
[Blockly.Msg.senseBox_button_longPress, "longPress"],
|
||||
]),
|
||||
"FUNCTION"
|
||||
)
|
||||
@@ -367,6 +371,51 @@ Blockly.Blocks["sensebox_button"] = {
|
||||
this.setColour(getColour().sensebox);
|
||||
this.setTooltip(Blockly.Msg.senseBox_button_tooltip);
|
||||
},
|
||||
/**
|
||||
* Parse XML to restore the number of pins available.
|
||||
* @param {!Element} xmlElement XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
domToMutation: function (xmlElement) {
|
||||
xmlElement.getAttribute("port");
|
||||
},
|
||||
/**
|
||||
* Create XML to represent number of pins selection.
|
||||
* @return {!Element} XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement("mutation");
|
||||
var input = this.getFieldValue("FUNCTION");
|
||||
this.updateShape_(input);
|
||||
container.setAttribute("FUNCTION", input);
|
||||
return container;
|
||||
},
|
||||
/**
|
||||
* Modify this block to have the correct number of pins available.
|
||||
* @param {boolean}
|
||||
* @private
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
updateShape_: function () {
|
||||
var extraFieldExist = this.getFieldValue("time");
|
||||
var input = this.getFieldValue("FUNCTION");
|
||||
if (input === "longPress" && extraFieldExist === null) {
|
||||
this.appendDummyInput("extraField")
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.appendField(Blockly.Msg.senseBox_pressure_referencePressure)
|
||||
.appendField(new Blockly.FieldTextInput("1000"), "time")
|
||||
.appendField("ms");
|
||||
}
|
||||
|
||||
if (
|
||||
(input === "isPressed" || input === "wasPressed" || input === "Switch") &&
|
||||
extraFieldExist !== null
|
||||
) {
|
||||
this.removeInput("extraField");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,60 +1,87 @@
|
||||
import Blockly from 'blockly';
|
||||
import { getColour } from '../helpers/colour'
|
||||
import Blockly from "blockly";
|
||||
import { getColour } from "../helpers/colour";
|
||||
import * as Types from "../helpers/types";
|
||||
|
||||
Blockly.Blocks['sensebox_wifi'] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_tooltip);
|
||||
this.setHelpUrl('');
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.senseBox_wifi_connect);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_wifi_ssid)
|
||||
.appendField(new Blockly.FieldTextInput("SSID"), "SSID");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_output_password)
|
||||
.appendField(new Blockly.FieldTextInput("Password"), "Password");
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
},
|
||||
onchange: function (e) {
|
||||
var legal = false;
|
||||
// Is the block nested in a loop?
|
||||
var block = this;
|
||||
do {
|
||||
if (this.LOOP_TYPES.indexOf(block.type) !== -1) {
|
||||
legal = true;
|
||||
break;
|
||||
}
|
||||
block = block.getSurroundParent();
|
||||
} while (block);
|
||||
if (legal) {
|
||||
this.setWarningText(null);
|
||||
|
||||
} else {
|
||||
this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING);
|
||||
|
||||
}
|
||||
},
|
||||
LOOP_TYPES: ['arduino_functions'],
|
||||
Blockly.Blocks["sensebox_wifi"] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_tooltip);
|
||||
this.setHelpUrl("");
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_connect);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_wifi_ssid)
|
||||
.appendField(new Blockly.FieldTextInput("SSID"), "SSID");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_output_password)
|
||||
.appendField(new Blockly.FieldTextInput("Password"), "Password");
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
},
|
||||
onchange: function (e) {
|
||||
var legal = false;
|
||||
// Is the block nested in a loop?
|
||||
var block = this;
|
||||
do {
|
||||
if (this.LOOP_TYPES.indexOf(block.type) !== -1) {
|
||||
legal = true;
|
||||
break;
|
||||
}
|
||||
block = block.getSurroundParent();
|
||||
} while (block);
|
||||
if (legal) {
|
||||
this.setWarningText(null);
|
||||
} else {
|
||||
this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING);
|
||||
}
|
||||
},
|
||||
LOOP_TYPES: ["arduino_functions"],
|
||||
};
|
||||
|
||||
Blockly.Blocks['sensebox_startap'] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_startap_tooltip);
|
||||
this.setHelpUrl('');
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.senseBox_wifi_startap);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_wifi_ssid)
|
||||
.appendField(new Blockly.FieldTextInput("SSID"), "SSID");
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
Blockly.Blocks["sensebox_wifi_status"] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_status_tooltip);
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_status);
|
||||
this.setOutput(true, Types.BOOLEAN.typeName);
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_status_helpurl);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_wifi_ip"] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_ip_tooltip);
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_ip);
|
||||
this.setOutput(true, Types.TEXT.typeName);
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_ip_helpurl);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_wifi_rssi"] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_rssi_tooltip);
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_rssi);
|
||||
this.setOutput(true, Types.NUMBER.typeName);
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_rssi_helpurl);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_startap"] = {
|
||||
init: function () {
|
||||
this.setTooltip(Blockly.Msg.senseBox_wifi_startap_tooltip);
|
||||
this.setHelpUrl("");
|
||||
this.setColour(getColour().sensebox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_startap);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_LEFT)
|
||||
.appendField(Blockly.Msg.senseBox_wifi_ssid)
|
||||
.appendField(new Blockly.FieldTextInput("SSID"), "SSID");
|
||||
this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import * as Blockly from "blockly/core";
|
||||
import { getColour } from "../helpers/colour";
|
||||
import { selectedBoard } from "../helpers/board";
|
||||
|
||||
Blockly.Blocks["init_serial_monitor"] = {
|
||||
init: function () {
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(getColour().serial);
|
||||
this.setHelpUrl("http://arduino.cc/en/Serial/Begin");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.ARD_SERIAL_SETUP)
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown(selectedBoard().serial),
|
||||
"SERIAL_ID"
|
||||
)
|
||||
.appendField(Blockly.Msg.ARD_SERIAL_SPEED)
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown(selectedBoard().serialSpeed),
|
||||
"SPEED"
|
||||
)
|
||||
.appendField(Blockly.Msg.ARD_SERIAL_BPS);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.ARD_SERIAL_SETUP_TIP);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["print_serial_monitor"] = {
|
||||
init: function () {
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(getColour().serial);
|
||||
this.setHelpUrl("http://www.arduino.cc/en/Serial/Print");
|
||||
this.appendDummyInput()
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown(selectedBoard().serial),
|
||||
"SERIAL_ID"
|
||||
)
|
||||
.appendField(Blockly.Msg.ARD_SERIAL_PRINT);
|
||||
this.appendValueInput("CONTENT");
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldCheckbox("TRUE"), "NEW_LINE")
|
||||
.appendField(Blockly.Msg.ARD_SERIAL_PRINT_NEWLINE);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.ARD_SERIAL_PRINT_TIP);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user