@@ -148,53 +148,7 @@ Blockly["Arduino"].init = function (workspace) {
|
||||
// Blockly.Names.DEVELOPER_VARIABLE_TYPE));
|
||||
// }
|
||||
|
||||
const doubleVariables = workspace.getVariablesOfType("Number");
|
||||
let i = 0;
|
||||
let variableCode = "";
|
||||
for (i = 0; i < doubleVariables.length; i += 1) {
|
||||
variableCode +=
|
||||
"double " +
|
||||
Blockly["Arduino"].nameDB_.getName(
|
||||
doubleVariables[i].getId(),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
) +
|
||||
" = 0; \n\n";
|
||||
}
|
||||
|
||||
const stringVariables = workspace.getVariablesOfType("String");
|
||||
for (i = 0; i < stringVariables.length; i += 1) {
|
||||
variableCode +=
|
||||
"String " +
|
||||
Blockly["Arduino"].nameDB_.getName(
|
||||
stringVariables[i].getId(),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
) +
|
||||
' = ""; \n\n';
|
||||
}
|
||||
|
||||
const booleanVariables = workspace.getVariablesOfType("Boolean");
|
||||
for (i = 0; i < booleanVariables.length; i += 1) {
|
||||
variableCode +=
|
||||
"boolean " +
|
||||
Blockly["Arduino"].nameDB_.getDistinctName(
|
||||
booleanVariables[i].getId(),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
) +
|
||||
" = false; \n\n";
|
||||
}
|
||||
|
||||
const colourVariables = workspace.getVariablesOfType("Colour");
|
||||
for (i = 0; i < colourVariables.length; i += 1) {
|
||||
variableCode +=
|
||||
"RGB " +
|
||||
Blockly["Arduino"].nameDB_.getName(
|
||||
colourVariables[i].getId(),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
) +
|
||||
" = {0, 0, 0}; \n\n";
|
||||
}
|
||||
|
||||
Blockly["Arduino"].variablesInitCode_ = variableCode;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,7 +101,6 @@ Blockly.Arduino.sensebox_phyphox_graph = function () {
|
||||
Blockly.Arduino.sensebox_phyphox_experiment_send = function () {
|
||||
var branch = Blockly.Arduino.statementToCode(this, "sendValues");
|
||||
var blocks = this.getDescendants();
|
||||
console.log(blocks);
|
||||
var count = 0;
|
||||
if (blocks !== undefined) {
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
@@ -115,7 +114,6 @@ Blockly.Arduino.sensebox_phyphox_experiment_send = function () {
|
||||
var string = "";
|
||||
|
||||
for (var j = 1; j <= count; j++) {
|
||||
console.log("append");
|
||||
if (string === "") {
|
||||
string += `channel${j}`;
|
||||
} else if (string !== "") {
|
||||
|
||||
@@ -203,6 +203,5 @@ Blockly.Arduino.sensebox_sd_save_for_osem = function (block) {
|
||||
Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] =
|
||||
"const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";';
|
||||
code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n";
|
||||
console.log(code);
|
||||
return code;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import Blockly from "blockly";
|
||||
//import store from "../../../store";
|
||||
|
||||
// preperations for the esp board
|
||||
// var selectedBoard = store.getState().board.board;
|
||||
// store.subscribe(() => {
|
||||
// selectedBoard = store.getState().board.board;
|
||||
// });
|
||||
|
||||
|
||||
/* Wifi connection and openSenseMap Blocks*/
|
||||
Blockly.Arduino.sensebox_wifi = function (block) {
|
||||
@@ -110,3 +118,5 @@ Blockly.Arduino.sensebox_ethernetIp = function () {
|
||||
var code = "Ethernet.localIP()";
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,17 @@ import Blockly from "blockly";
|
||||
|
||||
const setVariableFunction = function (defaultValue) {
|
||||
return function (block) {
|
||||
const variableName = Blockly["Arduino"].nameDB_.getName(
|
||||
block.getFieldValue("VAR"),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
);
|
||||
var id = block.getFieldValue("VAR");
|
||||
|
||||
const variableName = Blockly.Variables.getVariable(
|
||||
Blockly.getMainWorkspace(),
|
||||
id
|
||||
).name;
|
||||
|
||||
// const variableName = Blockly["Arduino"].nameDB_.getName(
|
||||
// id,
|
||||
// Blockly.Variables.NAME_TYPE
|
||||
// );
|
||||
const variableValue = Blockly["Arduino"].valueToCode(
|
||||
block,
|
||||
"VALUE",
|
||||
@@ -17,31 +24,10 @@ const setVariableFunction = function (defaultValue) {
|
||||
.getAllVariables();
|
||||
const myVar = allVars.filter((v) => v.name === variableName)[0];
|
||||
var code = "";
|
||||
|
||||
switch (myVar.type) {
|
||||
default:
|
||||
Blockly.Arduino.variables_[variableName + myVar.type] =
|
||||
myVar.type + " " + myVar.name + ";\n";
|
||||
code = variableName + " = " + (variableValue || defaultValue) + ";\n";
|
||||
break;
|
||||
case "Array":
|
||||
var arrayType;
|
||||
var number;
|
||||
|
||||
if (this.getChildren().length > 0) {
|
||||
if (this.getChildren()[0].type === "lists_create_empty") {
|
||||
arrayType = this.getChildren()[0].getFieldValue("type");
|
||||
number = Blockly.Arduino.valueToCode(
|
||||
this.getChildren()[0],
|
||||
"NUMBER",
|
||||
Blockly["Arduino"].ORDER_ATOMIC
|
||||
);
|
||||
Blockly.Arduino.variables_[
|
||||
myVar + myVar.type
|
||||
] = `${arrayType} ${myVar.name} [${number}];\n`;
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (myVar !== undefined) {
|
||||
Blockly.Arduino.variables_[variableName + myVar.type] =
|
||||
myVar.type + " " + myVar.name + ";\n";
|
||||
code = variableName + " = " + (variableValue || defaultValue) + ";\n";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user