update phyphox blocks

This commit is contained in:
Mario Pesch 2021-05-16 20:03:21 +02:00
parent 47984fa66c
commit 44d48997d4
7 changed files with 340 additions and 66 deletions

View File

@ -1,7 +1,5 @@
import * as Blockly from "blockly"; import * as Blockly from "blockly";
import { getColour } from "../helpers/colour"; import { getColour } from "../helpers/colour";
import { selectedBoard } from "../helpers/board";
import * as Types from "../helpers/types";
Blockly.Blocks["sensebox_phyphox_init"] = { Blockly.Blocks["sensebox_phyphox_init"] = {
init: function () { init: function () {
@ -40,6 +38,113 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = {
new Blockly.FieldTextInput("Experiment Beschreibung"), new Blockly.FieldTextInput("Experiment Beschreibung"),
"description" "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.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.senseBox_led_tooltip); this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
@ -49,10 +154,9 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = {
Blockly.Blocks["sensebox_phyphox_experiment_send"] = { Blockly.Blocks["sensebox_phyphox_experiment_send"] = {
init: function () { init: function () {
this.setColour(getColour().phyphox); this.setColour(getColour().phyphox);
this.appendDummyInput().appendField( this.appendStatementInput("sendValues").appendField(
Blockly.Msg.sensebox_phyphox_writeValues Blockly.Msg.sensebox_phyphox_writeValues
); );
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.senseBox_led_tooltip); this.setTooltip(Blockly.Msg.senseBox_led_tooltip);

View File

@ -100,6 +100,9 @@ Blockly["Arduino"].init = function (workspace) {
// creates a list of code to be setup before the setup block // creates a list of code to be setup before the setup block
Blockly["Arduino"].setupCode_ = Object.create(null); 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 // creates a list of code to be setup before the setup block
Blockly["Arduino"].loraSetupCode_ = Object.create(null); Blockly["Arduino"].loraSetupCode_ = Object.create(null);
@ -196,6 +199,7 @@ Blockly["Arduino"].finish = function (code) {
let codeFunctions = ""; let codeFunctions = "";
let functionsCode = ""; let functionsCode = "";
let definitionsCode = ""; let definitionsCode = "";
let phyphoxSetupCode = "";
let loopCodeOnce = ""; let loopCodeOnce = "";
let setupCode = ""; let setupCode = "";
let preSetupCode = ""; let preSetupCode = "";
@ -234,8 +238,18 @@ Blockly["Arduino"].finish = function (code) {
loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || ""; loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || "";
} }
for (const key in Blockly["Arduino"].phyphoxSetupCode_) {
phyphoxSetupCode += Blockly["Arduino"].phyphoxSetupCode_[key] + "\n" || "";
}
setupCode = 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"; let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n";

View File

@ -5,35 +5,132 @@ Blockly.Arduino.sensebox_phyphox_init = function () {
Blockly.Arduino.libraries_["phyphox_library"] = `#include <phyphoxBle.h>`; Blockly.Arduino.libraries_["phyphox_library"] = `#include <phyphoxBle.h>`;
Blockly.Arduino.libraries_["library_senseBoxMCU"] = Blockly.Arduino.libraries_["library_senseBoxMCU"] =
'#include "SenseBoxMCU.h"'; '#include "SenseBoxMCU.h"';
Blockly.Arduino.setupCode_["phyphox_start"] = `PhyphoxBLE::start("${name}");`; Blockly.Arduino.phyphoxSetupCode_[
"phyphox_start"
] = `PhyphoxBLE::start("${name}");`;
var code = ``; var code = ``;
return code; return code;
}; };
Blockly.Arduino.sensebox_phyphox_experiment = function () { Blockly.Arduino.sensebox_phyphox_experiment = function () {
var experimentname = this.getFieldValue("exeperimentname"); var experimentname = this.getFieldValue("exeperimentname").replace(
var title = this.getFieldValue("title"); /\s+/g,
""
);
var title = this.getFieldValue("title").replace(/[^a-zA-Z0-9]/g, "");
var category = this.getFieldValue("category"); var category = this.getFieldValue("category");
var description = this.getFieldValue("description"); var description = this.getFieldValue("description");
Blockly.Arduino.setupCode_[ var branch = Blockly.Arduino.statementToCode(this, "view");
Blockly.Arduino.phyphoxSetupCode_[
`PhyphoxBleExperiment_${experimentname}` `PhyphoxBleExperiment_${experimentname}`
] = `PhyphoxBleExperiment ${experimentname};`; ] = `PhyphoxBleExperiment ${experimentname};`;
Blockly.Arduino.setupCode_[ Blockly.Arduino.phyphoxSetupCode_[
`setTitle_${title}` `setTitle_${title}`
] = `${experimentname}.setTitle("${title}")`; ] = `${experimentname}.setTitle("${title}");`;
Blockly.Arduino.setupCode_[ Blockly.Arduino.phyphoxSetupCode_[
`setCategory_${category}` `setCategory_${category}`
] = `${experimentname}.setCategory("${category}")`; ] = `${experimentname}.setCategory("${category}");`;
Blockly.Arduino.setupCode_[ Blockly.Arduino.phyphoxSetupCode_[
`setDescription_${description}` `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 = ``; var code = ``;
return code; return code;
}; };
Blockly.Arduino.sensebox_phyphox_experiment_send = function () { Blockly.Arduino["sensebox_phyphox_timestamp"] = function () {
var data = ""; var code = 0;
Blockly.Arduino.loopCodeOnce_["phyphox_poll"] = `PhyphoxBLE::poll()`; return [code, Blockly.Arduino.ORDER_ATOMIC];
var code = `PhyphoxBLE::write()`; };
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; return code;
}; };

View File

@ -9,4 +9,17 @@ export const BLE = {
sensebox_phyphox_experimentCategory: "Kategorie", sensebox_phyphox_experimentCategory: "Kategorie",
sensebox_phyphox_experimentDescription: "Beschreibung", sensebox_phyphox_experimentDescription: "Beschreibung",
sensebox_phyphox_writeValues: "Sende Werte", 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",
}; };

View File

@ -1,47 +1,49 @@
import { AUDIO } from './en/audio'; import { AUDIO } from "./en/audio";
import { FAQ } from './en/faq'; import { BLE } from "./en/sensebox-ble";
import { IO } from './en/io'; import { FAQ } from "./en/faq";
import { LOGIC } from './en/logic'; import { IO } from "./en/io";
import { LOOPS } from './en/loops'; import { LOGIC } from "./en/logic";
import { MATH } from './en/math'; import { LOOPS } from "./en/loops";
import { MQTT } from './en/mqtt'; import { MATH } from "./en/math";
import { DISPLAY } from './en/sensebox-display'; import { MQTT } from "./en/mqtt";
import { LED } from './en/sensebox-led'; import { DISPLAY } from "./en/sensebox-display";
import { LORA } from './en/sensebox-lora'; import { LED } from "./en/sensebox-led";
import { OSEM } from './en/sensebox-osem'; import { LORA } from "./en/sensebox-lora";
import { SD } from './en/sensebox-sd'; import { OSEM } from "./en/sensebox-osem";
import { SENSORS } from './en/sensebox-sensors'; import { SD } from "./en/sensebox-sd";
import { TELEGRAM } from './en/sensebox-telegram'; import { SENSORS } from "./en/sensebox-sensors";
import { WEB } from './en/sensebox-web'; import { TELEGRAM } from "./en/sensebox-telegram";
import { TEXT } from './en/text'; import { WEB } from "./en/sensebox-web";
import { TIME } from './en/time'; import { TEXT } from "./en/text";
import { TOURS } from './en/tours'; import { TIME } from "./en/time";
import { TRANSLATIONS } from './en/translations'; import { TOURS } from "./en/tours";
import { UI } from './en/ui'; import { TRANSLATIONS } from "./en/translations";
import { VARIABLES } from './en/variables'; import { UI } from "./en/ui";
import { WEBSERVER } from './en/webserver'; import { VARIABLES } from "./en/variables";
import { WEBSERVER } from "./en/webserver";
export const En = { export const En = {
...AUDIO, ...AUDIO,
...FAQ, ...BLE,
...IO, ...FAQ,
...LOGIC, ...IO,
...LOOPS, ...LOGIC,
...MATH, ...LOOPS,
...MQTT, ...MATH,
...DISPLAY, ...MQTT,
...LED, ...DISPLAY,
...LORA, ...LED,
...OSEM, ...LORA,
...SD, ...OSEM,
...SENSORS, ...SD,
...TELEGRAM, ...SENSORS,
...WEB, ...TELEGRAM,
...TEXT, ...WEB,
...TIME, ...TEXT,
...TOURS, ...TIME,
...TRANSLATIONS, ...TOURS,
...UI, ...TRANSLATIONS,
...VARIABLES, ...UI,
...WEBSERVER ...VARIABLES,
} ...WEBSERVER,
};

View 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",
};

View File

@ -349,8 +349,27 @@ class Toolbox extends React.Component {
</Category> </Category>
<Category id="phyphox" name="Phyphox" colour={getColour().phyphox}> <Category id="phyphox" name="Phyphox" colour={getColour().phyphox}>
<Block type="sensebox_phyphox_init"></Block> <Block type="sensebox_phyphox_init"></Block>
<Block type="sensebox_phyphox_experiment"></Block> <Block type="sensebox_phyphox_experiment">
<Block type="sensebox_phyphox_experiment_send"></Block> <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>
<Category <Category
id="webserver" id="webserver"