update phyphox blocks
This commit is contained in:
parent
47984fa66c
commit
44d48997d4
@ -1,7 +1,5 @@
|
||||
import * as Blockly from "blockly";
|
||||
import { getColour } from "../helpers/colour";
|
||||
import { selectedBoard } from "../helpers/board";
|
||||
import * as Types from "../helpers/types";
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_init"] = {
|
||||
init: function () {
|
||||
@ -40,6 +38,113 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = {
|
||||
new Blockly.FieldTextInput("Experiment Beschreibung"),
|
||||
"description"
|
||||
);
|
||||
this.appendStatementInput("view").appendField(
|
||||
Blockly.Msg.sensebox_phyphox_createView
|
||||
);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_view"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendStatementInput("view").appendField(
|
||||
Blockly.Msg.sensebox_phyphox_createView
|
||||
);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_graph"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_createGraph)
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_graphLabel)
|
||||
.appendField(new Blockly.FieldTextInput("Label"), "label");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_unitx)
|
||||
.appendField(new Blockly.FieldTextInput("Unit X"), "unitx");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_unity)
|
||||
.appendField(new Blockly.FieldTextInput("Unit Y"), "unity");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_labelx)
|
||||
.appendField(new Blockly.FieldTextInput("Label X"), "labelx");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_labely)
|
||||
.appendField(new Blockly.FieldTextInput("Label Y"), "labely");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_graphStyle)
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown([
|
||||
["dots", "dots"],
|
||||
["line", "line"],
|
||||
]),
|
||||
"style"
|
||||
);
|
||||
this.appendValueInput("channel0").appendField(
|
||||
Blockly.Msg.sensebox_phyphox_channel0
|
||||
);
|
||||
this.appendValueInput("channel1").appendField(
|
||||
Blockly.Msg.sensebox_phyphox_channel1
|
||||
);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_timestamp"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.sensebox_phyphox_timestamp);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_channel"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_channel)
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown([
|
||||
["1", "1"],
|
||||
["2", "2"],
|
||||
["3", "3"],
|
||||
["4", "4"],
|
||||
["5", "5"],
|
||||
]),
|
||||
"channel"
|
||||
);
|
||||
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Blocks["sensebox_phyphox_sendchannel"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendValueInput("value")
|
||||
.appendField(Blockly.Msg.sensebox_phyphox_sendchannel)
|
||||
.appendField(
|
||||
new Blockly.FieldDropdown([
|
||||
["1", "1"],
|
||||
["2", "2"],
|
||||
["3", "3"],
|
||||
["4", "4"],
|
||||
["5", "5"],
|
||||
]),
|
||||
"channel"
|
||||
);
|
||||
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
@ -49,10 +154,9 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = {
|
||||
Blockly.Blocks["sensebox_phyphox_experiment_send"] = {
|
||||
init: function () {
|
||||
this.setColour(getColour().phyphox);
|
||||
this.appendDummyInput().appendField(
|
||||
this.appendStatementInput("sendValues").appendField(
|
||||
Blockly.Msg.sensebox_phyphox_writeValues
|
||||
);
|
||||
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
|
||||
|
@ -100,6 +100,9 @@ Blockly["Arduino"].init = function (workspace) {
|
||||
// creates a list of code to be setup before the setup block
|
||||
Blockly["Arduino"].setupCode_ = Object.create(null);
|
||||
|
||||
// creates a list of code to be setup before the setup block
|
||||
Blockly["Arduino"].phyphoxSetupCode_ = Object.create(null);
|
||||
|
||||
// creates a list of code to be setup before the setup block
|
||||
Blockly["Arduino"].loraSetupCode_ = Object.create(null);
|
||||
|
||||
@ -196,6 +199,7 @@ Blockly["Arduino"].finish = function (code) {
|
||||
let codeFunctions = "";
|
||||
let functionsCode = "";
|
||||
let definitionsCode = "";
|
||||
let phyphoxSetupCode = "";
|
||||
let loopCodeOnce = "";
|
||||
let setupCode = "";
|
||||
let preSetupCode = "";
|
||||
@ -234,8 +238,18 @@ Blockly["Arduino"].finish = function (code) {
|
||||
loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || "";
|
||||
}
|
||||
|
||||
for (const key in Blockly["Arduino"].phyphoxSetupCode_) {
|
||||
phyphoxSetupCode += Blockly["Arduino"].phyphoxSetupCode_[key] + "\n" || "";
|
||||
}
|
||||
|
||||
setupCode =
|
||||
"\nvoid setup() { \n" + preSetupCode + "\n" + loraSetupCode + "\n}\n";
|
||||
"\nvoid setup() { \n" +
|
||||
preSetupCode +
|
||||
"\n" +
|
||||
phyphoxSetupCode +
|
||||
"\n" +
|
||||
loraSetupCode +
|
||||
"\n}\n";
|
||||
|
||||
let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n";
|
||||
|
||||
|
@ -5,35 +5,132 @@ Blockly.Arduino.sensebox_phyphox_init = function () {
|
||||
Blockly.Arduino.libraries_["phyphox_library"] = `#include <phyphoxBle.h>`;
|
||||
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
|
||||
'#include "SenseBoxMCU.h"';
|
||||
Blockly.Arduino.setupCode_["phyphox_start"] = `PhyphoxBLE::start("${name}");`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
"phyphox_start"
|
||||
] = `PhyphoxBLE::start("${name}");`;
|
||||
var code = ``;
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_experiment = function () {
|
||||
var experimentname = this.getFieldValue("exeperimentname");
|
||||
var title = this.getFieldValue("title");
|
||||
var experimentname = this.getFieldValue("exeperimentname").replace(
|
||||
/\s+/g,
|
||||
""
|
||||
);
|
||||
var title = this.getFieldValue("title").replace(/[^a-zA-Z0-9]/g, "");
|
||||
var category = this.getFieldValue("category");
|
||||
var description = this.getFieldValue("description");
|
||||
Blockly.Arduino.setupCode_[
|
||||
var branch = Blockly.Arduino.statementToCode(this, "view");
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`PhyphoxBleExperiment_${experimentname}`
|
||||
] = `PhyphoxBleExperiment ${experimentname};`;
|
||||
Blockly.Arduino.setupCode_[
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`setTitle_${title}`
|
||||
] = `${experimentname}.setTitle("${title}")`;
|
||||
Blockly.Arduino.setupCode_[
|
||||
] = `${experimentname}.setTitle("${title}");`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`setCategory_${category}`
|
||||
] = `${experimentname}.setCategory("${category}")`;
|
||||
Blockly.Arduino.setupCode_[
|
||||
] = `${experimentname}.setCategory("${category}");`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`setDescription_${description}`
|
||||
] = `${experimentname}.setDescription("${description}")`;
|
||||
] = `${experimentname}.setDescription("${description}");`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`addView_${experimentname}`
|
||||
] = `PhyphoxBleExperiment::View firstView;\nfirstView.setLabel("Messwerte"); //Create a "view"`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[`addGraph`] = `${branch}`;
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`addView_firstview`
|
||||
] = `${experimentname}.addView(firstView);`; //Attach view to experiment
|
||||
Blockly.Arduino.phyphoxSetupCode_[
|
||||
`addExperiment_${experimentname}`
|
||||
] = `PhyphoxBLE::addExperiment(${experimentname});`; //Attach experiment to server
|
||||
|
||||
var code = ``;
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_experiment_send = function () {
|
||||
var data = "";
|
||||
Blockly.Arduino.loopCodeOnce_["phyphox_poll"] = `PhyphoxBLE::poll()`;
|
||||
var code = `PhyphoxBLE::write()`;
|
||||
Blockly.Arduino["sensebox_phyphox_timestamp"] = function () {
|
||||
var code = 0;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino["sensebox_phyphox_channel"] = function () {
|
||||
var channel = parseFloat(this.getFieldValue("channel"));
|
||||
var code = channel;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_view = function () {
|
||||
//var code = `${branch}`;
|
||||
//return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_sendchannel = function (block) {
|
||||
var channel = this.getFieldValue("channel");
|
||||
var value =
|
||||
Blockly.Arduino.valueToCode(this, "value", Blockly.Arduino.ORDER_ATOMIC) ||
|
||||
"1";
|
||||
|
||||
var code = `float channel${channel} = ${value};\n`;
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_phyphox_graph = function () {
|
||||
var label = this.getFieldValue("label").replace(/[^a-zA-Z0-9]/g, "");
|
||||
var unitx = this.getFieldValue("unitx");
|
||||
var unity = this.getFieldValue("unity");
|
||||
var labelx = this.getFieldValue("labelx");
|
||||
var labely = this.getFieldValue("labely");
|
||||
var style = this.getFieldValue("style");
|
||||
var channelX =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"channel0",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || 0;
|
||||
var channelY =
|
||||
Blockly.Arduino.valueToCode(
|
||||
this,
|
||||
"channel1",
|
||||
Blockly.Arduino.ORDER_ATOMIC
|
||||
) || 1;
|
||||
|
||||
var code = `PhyphoxBleExperiment::Graph ${label};\n`; //Create graph which will plot random numbers over time
|
||||
code += `${label}.setLabel("${label}");\n`;
|
||||
code += `${label}.setUnitX("${unitx}");\n`;
|
||||
code += `${label}.setUnitY("${unity}");\n`;
|
||||
code += `${label}.setLabelX("${labelx}");\n`;
|
||||
code += `${label}.setLabelY("${labely}");\n`;
|
||||
code += `${label}.setStyle("${style}");\n`;
|
||||
code += `${label}.setChannel(${channelX}, ${channelY});\n`;
|
||||
code += `firstView.addElement(${label});\n`;
|
||||
return code;
|
||||
};
|
||||
|
||||
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++) {
|
||||
if (blocks[i].type === "sensebox_phyphox_sendchannel") {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count === 5) {
|
||||
}
|
||||
var string = "";
|
||||
|
||||
for (var j = 1; j <= count; j++) {
|
||||
console.log("append");
|
||||
if (string === "") {
|
||||
string += `channel${j}`;
|
||||
} else if (string !== "") {
|
||||
string += `, channel${j}`;
|
||||
}
|
||||
}
|
||||
Blockly.Arduino.loopCodeOnce_["phyphox_poll"] = `PhyphoxBLE::poll();`;
|
||||
var code = `${branch}\nPhyphoxBLE::write(${string});`;
|
||||
return code;
|
||||
};
|
||||
|
@ -9,4 +9,17 @@ export const BLE = {
|
||||
sensebox_phyphox_experimentCategory: "Kategorie",
|
||||
sensebox_phyphox_experimentDescription: "Beschreibung",
|
||||
sensebox_phyphox_writeValues: "Sende Werte",
|
||||
sensebox_phyphox_createView: "Mit Graphen:",
|
||||
sensebox_phyphox_createGraph: "Erstelle Graph",
|
||||
sensebox_phyphox_graphLabel: "",
|
||||
sensebox_phyphox_unitx: "Einheit x-Achse",
|
||||
sensebox_phyphox_unity: "Einheit y-Achse",
|
||||
sensebox_phyphox_labelx: "Beschriftung x-Achse",
|
||||
sensebox_phyphox_labely: "Beschriftung y-Achse",
|
||||
sensebox_phyphox_channel0: "Wert x-Achse",
|
||||
sensebox_phyphox_channel1: "Wert y-Achse",
|
||||
sensebox_phyphox_timestamp: "Zeitstempel",
|
||||
sensebox_phyphox_channel: "Kanal",
|
||||
sensebox_phyphox_sendchannel: "sende an Kanal:",
|
||||
sensebox_phyphox_graphStyle: "Stil",
|
||||
};
|
||||
|
@ -1,28 +1,30 @@
|
||||
import { AUDIO } from './en/audio';
|
||||
import { FAQ } from './en/faq';
|
||||
import { IO } from './en/io';
|
||||
import { LOGIC } from './en/logic';
|
||||
import { LOOPS } from './en/loops';
|
||||
import { MATH } from './en/math';
|
||||
import { MQTT } from './en/mqtt';
|
||||
import { DISPLAY } from './en/sensebox-display';
|
||||
import { LED } from './en/sensebox-led';
|
||||
import { LORA } from './en/sensebox-lora';
|
||||
import { OSEM } from './en/sensebox-osem';
|
||||
import { SD } from './en/sensebox-sd';
|
||||
import { SENSORS } from './en/sensebox-sensors';
|
||||
import { TELEGRAM } from './en/sensebox-telegram';
|
||||
import { WEB } from './en/sensebox-web';
|
||||
import { TEXT } from './en/text';
|
||||
import { TIME } from './en/time';
|
||||
import { TOURS } from './en/tours';
|
||||
import { TRANSLATIONS } from './en/translations';
|
||||
import { UI } from './en/ui';
|
||||
import { VARIABLES } from './en/variables';
|
||||
import { WEBSERVER } from './en/webserver';
|
||||
import { AUDIO } from "./en/audio";
|
||||
import { BLE } from "./en/sensebox-ble";
|
||||
import { FAQ } from "./en/faq";
|
||||
import { IO } from "./en/io";
|
||||
import { LOGIC } from "./en/logic";
|
||||
import { LOOPS } from "./en/loops";
|
||||
import { MATH } from "./en/math";
|
||||
import { MQTT } from "./en/mqtt";
|
||||
import { DISPLAY } from "./en/sensebox-display";
|
||||
import { LED } from "./en/sensebox-led";
|
||||
import { LORA } from "./en/sensebox-lora";
|
||||
import { OSEM } from "./en/sensebox-osem";
|
||||
import { SD } from "./en/sensebox-sd";
|
||||
import { SENSORS } from "./en/sensebox-sensors";
|
||||
import { TELEGRAM } from "./en/sensebox-telegram";
|
||||
import { WEB } from "./en/sensebox-web";
|
||||
import { TEXT } from "./en/text";
|
||||
import { TIME } from "./en/time";
|
||||
import { TOURS } from "./en/tours";
|
||||
import { TRANSLATIONS } from "./en/translations";
|
||||
import { UI } from "./en/ui";
|
||||
import { VARIABLES } from "./en/variables";
|
||||
import { WEBSERVER } from "./en/webserver";
|
||||
|
||||
export const En = {
|
||||
...AUDIO,
|
||||
...BLE,
|
||||
...FAQ,
|
||||
...IO,
|
||||
...LOGIC,
|
||||
@ -43,5 +45,5 @@ export const En = {
|
||||
...TRANSLATIONS,
|
||||
...UI,
|
||||
...VARIABLES,
|
||||
...WEBSERVER
|
||||
}
|
||||
...WEBSERVER,
|
||||
};
|
||||
|
25
src/components/Blockly/msg/en/sensebox-ble.js
Normal file
25
src/components/Blockly/msg/en/sensebox-ble.js
Normal file
@ -0,0 +1,25 @@
|
||||
export const BLE = {
|
||||
/**
|
||||
* Phyphox Init
|
||||
*/
|
||||
sensebox_phyphox_init: "Phyphox Experiment",
|
||||
sensebox_phyphox_createExperiment: "Erstelle Experiment",
|
||||
sensebox_phyphox_experimentName: "Name des Experiments",
|
||||
sensebox_phyphox_experimentTitle: "Titel",
|
||||
sensebox_phyphox_experimentCategory: "Kategorie",
|
||||
sensebox_phyphox_experimentDescription: "Beschreibung",
|
||||
sensebox_phyphox_writeValues: "Sende Werte",
|
||||
sensebox_phyphox_createView: "Mit Graphen:",
|
||||
sensebox_phyphox_createGraph: "Erstelle Graph",
|
||||
sensebox_phyphox_graphLabel: "",
|
||||
sensebox_phyphox_unitx: "Einheit x-Achse",
|
||||
sensebox_phyphox_unity: "Einheit y-Achse",
|
||||
sensebox_phyphox_labelx: "Beschriftung x-Achse",
|
||||
sensebox_phyphox_labely: "Beschriftung y-Achse",
|
||||
sensebox_phyphox_channel0: "Wert x-Achse",
|
||||
sensebox_phyphox_channel1: "Wert y-Achse",
|
||||
sensebox_phyphox_timestamp: "Zeitstempel",
|
||||
sensebox_phyphox_channel: "Kanal",
|
||||
sensebox_phyphox_sendchannel: "sende an Kanal:",
|
||||
sensebox_phyphox_graphStyle: "Stil",
|
||||
};
|
@ -349,8 +349,27 @@ class Toolbox extends React.Component {
|
||||
</Category>
|
||||
<Category id="phyphox" name="Phyphox" colour={getColour().phyphox}>
|
||||
<Block type="sensebox_phyphox_init"></Block>
|
||||
<Block type="sensebox_phyphox_experiment"></Block>
|
||||
<Block type="sensebox_phyphox_experiment_send"></Block>
|
||||
<Block type="sensebox_phyphox_experiment">
|
||||
<Value name="view">
|
||||
<Block type="sensebox_phyphox_graph">
|
||||
<Value name="channel0">
|
||||
<Block type="sensebox_phyphox_timestamp"></Block>
|
||||
</Value>
|
||||
<Value name="channel1">
|
||||
<Block type="sensebox_phyphox_channel"></Block>
|
||||
</Value>
|
||||
</Block>
|
||||
</Value>
|
||||
</Block>
|
||||
<Block type="sensebox_phyphox_experiment_send">
|
||||
<Value name="sendValues">
|
||||
<Block type="sensebox_phyphox_sendchannel"></Block>
|
||||
</Value>
|
||||
</Block>
|
||||
<Block type="sensebox_phyphox_graph"></Block>
|
||||
<Block type="sensebox_phyphox_timestamp"></Block>
|
||||
<Block type="sensebox_phyphox_channel"></Block>
|
||||
<Block type="sensebox_phyphox_sendchannel"></Block>
|
||||
</Category>
|
||||
<Category
|
||||
id="webserver"
|
||||
|
Loading…
x
Reference in New Issue
Block a user