add first phyphox blocks

This commit is contained in:
Mario Pesch 2021-05-06 15:21:54 +02:00
parent bc5cbb6b33
commit 47984fa66c
10 changed files with 1033 additions and 864 deletions

View File

@ -1,24 +1,25 @@
import './loops'; import "./loops";
import './sensebox'; import "./sensebox";
import './logic'; import "./logic";
import './sensebox-sensors'; import "./sensebox-sensors";
import './sensebox-telegram'; import "./sensebox-telegram";
import './sensebox-osem'; import "./sensebox-osem";
import './sensebox-web'; import "./sensebox-web";
import './sensebox-display'; import "./sensebox-display";
import './sensebox-lora'; import "./sensebox-lora";
import './sensebox-led'; import "./sensebox-led";
import './sensebox-sd'; import "./sensebox-ble";
import './mqtt'; import "./sensebox-sd";
import './text'; import "./mqtt";
import './io'; import "./text";
import './audio'; import "./io";
import './math'; import "./audio";
import './map'; import "./math";
import './procedures'; import "./map";
import './time'; import "./procedures";
import './variables'; import "./time";
import './lists'; import "./variables";
import './webserver'; import "./lists";
import "./webserver";
import '../helpers/types' import "../helpers/types";

View File

@ -0,0 +1,60 @@
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 () {
this.setColour(getColour().phyphox);
this.appendDummyInput()
.appendField(Blockly.Msg.sensebox_phyphox_init)
.appendField(new Blockly.FieldTextInput("Geräte Name"), "devicename");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
},
};
Blockly.Blocks["sensebox_phyphox_experiment"] = {
init: function () {
this.setColour(getColour().phyphox);
this.appendDummyInput()
.appendField(Blockly.Msg.sensebox_phyphox_createExperiment)
.appendField(
new Blockly.FieldTextInput("Experiment Name"),
"exeperimentname"
);
this.appendDummyInput()
.appendField(Blockly.Msg.sensebox_phyphox_experimentTitle)
.appendField(new Blockly.FieldTextInput("Experiment Title"), "title");
this.appendDummyInput()
.appendField(Blockly.Msg.sensebox_phyphox_experimentCategory)
.appendField(
new Blockly.FieldTextInput("senseBox Experiments"),
"category"
);
this.appendDummyInput()
.appendField(Blockly.Msg.sensebox_phyphox_experimentDescription)
.appendField(
new Blockly.FieldTextInput("Experiment Beschreibung"),
"description"
);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
},
};
Blockly.Blocks["sensebox_phyphox_experiment_send"] = {
init: function () {
this.setColour(getColour().phyphox);
this.appendDummyInput().appendField(
Blockly.Msg.sensebox_phyphox_writeValues
);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.senseBox_led_tooltip);
},
};

View File

@ -1,6 +1,6 @@
/** /**
* @license * @license
* *
* Copyright 2019 Google LLC * Copyright 2019 Google LLC
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -24,13 +24,13 @@
// More on generating code: // More on generating code:
// https://developers.google.com/blockly/guides/create-custom-blocks/generating-code // https://developers.google.com/blockly/guides/create-custom-blocks/generating-code
import * as Blockly from 'blockly/core'; import * as Blockly from "blockly/core";
/** /**
* Arduino code generator. * Arduino code generator.
* @type !Blockly.Generator * @type !Blockly.Generator
*/ */
Blockly['Arduino'] = new Blockly.Generator('Arduino'); Blockly["Arduino"] = new Blockly.Generator("Arduino");
/** /**
* List of illegal variable names. * List of illegal variable names.
@ -39,156 +39,150 @@ Blockly['Arduino'] = new Blockly.Generator('Arduino');
* accidentally clobbering a built-in object or function. * accidentally clobbering a built-in object or function.
* @private * @private
*/ */
Blockly['Arduino'].addReservedWords( Blockly["Arduino"].addReservedWords(
// http://arduino.cc/en/Reference/HomePage // http://arduino.cc/en/Reference/HomePage
'setup,loop,if,else,for,switch,case,while,' + "setup,loop,if,else,for,switch,case,while," +
'do,break,continue,return,goto,define,include,' + "do,break,continue,return,goto,define,include," +
'HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,' + "HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false," +
'interger, constants,floating,point,void,boolean,char,' + "interger, constants,floating,point,void,boolean,char," +
'unsigned,byte,int,word,long,float,double,string,String,array,' + "unsigned,byte,int,word,long,float,double,string,String,array," +
'static, volatile,const,sizeof,pinMode,digitalWrite,digitalRead,' + "static, volatile,const,sizeof,pinMode,digitalWrite,digitalRead," +
'analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,' + "analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn," +
'pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain,' + "pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain," +
'map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead,' + "map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead," +
'bitWrite,bitSet,bitClear,ultraSonicDistance,parseDouble,setNeoPixelColor,' + "bitWrite,bitSet,bitClear,ultraSonicDistance,parseDouble,setNeoPixelColor," +
'bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts', "bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts",
'short', "short",
'isBtnPressed' "isBtnPressed"
); );
/** /**
* Order of operation ENUMs. * Order of operation ENUMs.
* *
*/ */
Blockly['Arduino'].ORDER_ATOMIC = 0; // 0 "" ... Blockly["Arduino"].ORDER_ATOMIC = 0; // 0 "" ...
Blockly['Arduino'].ORDER_UNARY_POSTFIX = 1; // expr++ expr-- () [] . Blockly["Arduino"].ORDER_UNARY_POSTFIX = 1; // expr++ expr-- () [] .
Blockly['Arduino'].ORDER_UNARY_PREFIX = 2; // -expr !expr ~expr ++expr --expr Blockly["Arduino"].ORDER_UNARY_PREFIX = 2; // -expr !expr ~expr ++expr --expr
Blockly['Arduino'].ORDER_MULTIPLICATIVE = 3; // * / % ~/ Blockly["Arduino"].ORDER_MULTIPLICATIVE = 3; // * / % ~/
Blockly['Arduino'].ORDER_ADDITIVE = 4; // + - Blockly["Arduino"].ORDER_ADDITIVE = 4; // + -
Blockly['Arduino'].ORDER_LOGICAL_NOT = 4.4; // ! Blockly["Arduino"].ORDER_LOGICAL_NOT = 4.4; // !
Blockly['Arduino'].ORDER_SHIFT = 5; // << >> Blockly["Arduino"].ORDER_SHIFT = 5; // << >>
Blockly['Arduino'].ORDER_MODULUS = 5.3; // % Blockly["Arduino"].ORDER_MODULUS = 5.3; // %
Blockly['Arduino'].ORDER_RELATIONAL = 6; // is is! >= > <= < Blockly["Arduino"].ORDER_RELATIONAL = 6; // is is! >= > <= <
Blockly['Arduino'].ORDER_EQUALITY = 7; // === !== === !== Blockly["Arduino"].ORDER_EQUALITY = 7; // === !== === !==
Blockly['Arduino'].ORDER_BITWISE_AND = 8; // & Blockly["Arduino"].ORDER_BITWISE_AND = 8; // &
Blockly['Arduino'].ORDER_BITWISE_XOR = 9; // ^ Blockly["Arduino"].ORDER_BITWISE_XOR = 9; // ^
Blockly['Arduino'].ORDER_BITWISE_OR = 10; // | Blockly["Arduino"].ORDER_BITWISE_OR = 10; // |
Blockly['Arduino'].ORDER_LOGICAL_AND = 11; // && Blockly["Arduino"].ORDER_LOGICAL_AND = 11; // &&
Blockly['Arduino'].ORDER_LOGICAL_OR = 12; // || Blockly["Arduino"].ORDER_LOGICAL_OR = 12; // ||
Blockly['Arduino'].ORDER_CONDITIONAL = 13; // expr ? expr : expr Blockly["Arduino"].ORDER_CONDITIONAL = 13; // expr ? expr : expr
Blockly['Arduino'].ORDER_ASSIGNMENT = 14; // = *= /= ~/= %= += -= <<= >>= &= ^= |= Blockly["Arduino"].ORDER_ASSIGNMENT = 14; // = *= /= ~/= %= += -= <<= >>= &= ^= |=
Blockly['Arduino'].ORDER_COMMA = 18; // , Blockly["Arduino"].ORDER_COMMA = 18; // ,
Blockly['Arduino'].ORDER_NONE = 99; // (...) Blockly["Arduino"].ORDER_NONE = 99; // (...)
/** /**
* *
* @param {} workspace * @param {} workspace
* *
* Blockly Types * Blockly Types
*/ */
/** /**
* Initialise the database of variable names. * Initialise the database of variable names.
* @param {!Blockly.Workspace} workspace Workspace to generate code from. * @param {!Blockly.Workspace} workspace Workspace to generate code from.
*/ */
Blockly['Arduino'].init = function (workspace) { Blockly["Arduino"].init = function (workspace) {
// Create a dictionary of definitions to be printed before the code. // Create a dictionary of definitions to be printed before the code.
Blockly['Arduino'].libraries_ = Object.create(null); Blockly["Arduino"].libraries_ = Object.create(null);
Blockly['Arduino'].definitions_ = Object.create(null); Blockly["Arduino"].definitions_ = 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'].setupCode_ = Object.create(null); Blockly["Arduino"].setupCode_ = 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);
// creates a list of code for the loop to be runned once // creates a list of code for the loop to be runned once
Blockly['Arduino'].loopCodeOnce_ = Object.create(null) Blockly["Arduino"].loopCodeOnce_ = Object.create(null);
// creates a list of code for the loop to be runned once // creates a list of code for the loop to be runned once
Blockly['Arduino'].codeFunctions_ = Object.create(null) Blockly["Arduino"].codeFunctions_ = Object.create(null);
// creates a list of code variables // creates a list of code variables
Blockly['Arduino'].variables_ = Object.create(null) Blockly["Arduino"].variables_ = Object.create(null);
// Create a dictionary mapping desired function names in definitions_ // Create a dictionary mapping desired function names in definitions_
// to actual function names (to avoid collisions with user functions). // to actual function names (to avoid collisions with user functions).
Blockly['Arduino'].functionNames_ = Object.create(null); Blockly["Arduino"].functionNames_ = Object.create(null);
Blockly['Arduino'].variablesInitCode_ = ''; Blockly["Arduino"].variablesInitCode_ = "";
if (!Blockly['Arduino'].variableDB_) { if (!Blockly["Arduino"].variableDB_) {
Blockly['Arduino'].variableDB_ = new Blockly.Names( Blockly["Arduino"].variableDB_ = new Blockly.Names(
Blockly['Arduino'].RESERVED_WORDS_ Blockly["Arduino"].RESERVED_WORDS_
); );
} else { } else {
Blockly['Arduino'].variableDB_.reset(); Blockly["Arduino"].variableDB_.reset();
} }
Blockly['Arduino'].variableDB_.setVariableMap(workspace.getVariableMap()); Blockly["Arduino"].variableDB_.setVariableMap(workspace.getVariableMap());
// We don't have developer variables for now // We don't have developer variables for now
// // Add developer variables (not created or named by the user). // // Add developer variables (not created or named by the user).
// var devVarList = Blockly.Variables.allDeveloperVariables(workspace); // var devVarList = Blockly.Variables.allDeveloperVariables(workspace);
// for (var i = 0; i < devVarList.length; i++) { // for (var i = 0; i < devVarList.length; i++) {
// defvars.push(Blockly['Arduino'].variableDB_.getName(devVarList[i], // defvars.push(Blockly['Arduino'].variableDB_.getName(devVarList[i],
// Blockly.Names.DEVELOPER_VARIABLE_TYPE)); // Blockly.Names.DEVELOPER_VARIABLE_TYPE));
// } // }
const doubleVariables = workspace.getVariablesOfType('Number'); const doubleVariables = workspace.getVariablesOfType("Number");
let i = 0; let i = 0;
let variableCode = ''; let variableCode = "";
for (i = 0; i < doubleVariables.length; i += 1) { for (i = 0; i < doubleVariables.length; i += 1) {
variableCode += variableCode +=
'double ' + "double " +
Blockly['Arduino'].variableDB_.getName( Blockly["Arduino"].variableDB_.getName(
doubleVariables[i].getId(), doubleVariables[i].getId(),
Blockly.Variables.NAME_TYPE Blockly.Variables.NAME_TYPE
) + ) +
' = 0; \n\n'; " = 0; \n\n";
} }
const stringVariables = workspace.getVariablesOfType('String'); const stringVariables = workspace.getVariablesOfType("String");
for (i = 0; i < stringVariables.length; i += 1) { for (i = 0; i < stringVariables.length; i += 1) {
variableCode += variableCode +=
'String ' + "String " +
Blockly['Arduino'].variableDB_.getName( Blockly["Arduino"].variableDB_.getName(
stringVariables[i].getId(), stringVariables[i].getId(),
Blockly.Variables.NAME_TYPE Blockly.Variables.NAME_TYPE
) + ) +
' = ""; \n\n'; ' = ""; \n\n';
} }
const booleanVariables = workspace.getVariablesOfType('Boolean'); const booleanVariables = workspace.getVariablesOfType("Boolean");
for (i = 0; i < booleanVariables.length; i += 1) { for (i = 0; i < booleanVariables.length; i += 1) {
variableCode += variableCode +=
'boolean ' + "boolean " +
Blockly['Arduino'].variableDB_.getDistinctName( Blockly["Arduino"].variableDB_.getDistinctName(
booleanVariables[i].getId(), booleanVariables[i].getId(),
Blockly.Variables.NAME_TYPE Blockly.Variables.NAME_TYPE
) + ) +
' = false; \n\n'; " = false; \n\n";
} }
const colourVariables = workspace.getVariablesOfType('Colour'); const colourVariables = workspace.getVariablesOfType("Colour");
for (i = 0; i < colourVariables.length; i += 1) { for (i = 0; i < colourVariables.length; i += 1) {
variableCode += variableCode +=
'RGB ' + "RGB " +
Blockly['Arduino'].variableDB_.getName( Blockly["Arduino"].variableDB_.getName(
colourVariables[i].getId(), colourVariables[i].getId(),
Blockly.Variables.NAME_TYPE Blockly.Variables.NAME_TYPE
) + ) +
' = {0, 0, 0}; \n\n'; " = {0, 0, 0}; \n\n";
} }
Blockly['Arduino'].variablesInitCode_ = variableCode; Blockly["Arduino"].variablesInitCode_ = variableCode;
}; };
/** /**
@ -196,88 +190,84 @@ Blockly['Arduino'].init = function (workspace) {
* @param {string} code Generated code. * @param {string} code Generated code.
* @return {string} Completed code. * @return {string} Completed code.
*/ */
Blockly['Arduino'].finish = function (code) { Blockly["Arduino"].finish = function (code) {
let libraryCode = ''; let libraryCode = "";
let variablesCode = ''; let variablesCode = "";
let codeFunctions = ''; let codeFunctions = "";
let functionsCode = ''; let functionsCode = "";
let definitionsCode = ''; let definitionsCode = "";
let loopCodeOnce = ''; let loopCodeOnce = "";
let setupCode = ''; let setupCode = "";
let preSetupCode = ''; let preSetupCode = "";
let loraSetupCode = ''; let loraSetupCode = "";
let devVariables = '\n'; let devVariables = "\n";
for (const key in Blockly['Arduino'].libraries_) { for (const key in Blockly["Arduino"].libraries_) {
libraryCode += Blockly['Arduino'].libraries_[key] + '\n'; libraryCode += Blockly["Arduino"].libraries_[key] + "\n";
} }
for (const key in Blockly['Arduino'].variables_) { for (const key in Blockly["Arduino"].variables_) {
variablesCode += Blockly['Arduino'].variables_[key] + '\n'; variablesCode += Blockly["Arduino"].variables_[key] + "\n";
} }
for (const key in Blockly['Arduino'].definitions_) { for (const key in Blockly["Arduino"].definitions_) {
definitionsCode += Blockly['Arduino'].definitions_[key] + '\n'; definitionsCode += Blockly["Arduino"].definitions_[key] + "\n";
} }
for (const key in Blockly['Arduino'].loopCodeOnce_) { for (const key in Blockly["Arduino"].loopCodeOnce_) {
loopCodeOnce += Blockly['Arduino'].loopCodeOnce_[key] + '\n'; loopCodeOnce += Blockly["Arduino"].loopCodeOnce_[key] + "\n";
} }
for (const key in Blockly['Arduino'].codeFunctions_) { for (const key in Blockly["Arduino"].codeFunctions_) {
codeFunctions += Blockly['Arduino'].codeFunctions_[key] + '\n'; codeFunctions += Blockly["Arduino"].codeFunctions_[key] + "\n";
} }
for (const key in Blockly['Arduino'].functionNames_) { for (const key in Blockly["Arduino"].functionNames_) {
functionsCode += Blockly['Arduino'].functionNames_[key] + '\n'; functionsCode += Blockly["Arduino"].functionNames_[key] + "\n";
} }
for (const key in Blockly["Arduino"].setupCode_) {
preSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || "";
}
for (const key in Blockly["Arduino"].loraSetupCode_) {
loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || "";
}
for (const key in Blockly['Arduino'].setupCode_) { setupCode =
preSetupCode += Blockly['Arduino'].setupCode_[key] || ''; "\nvoid setup() { \n" + preSetupCode + "\n" + loraSetupCode + "\n}\n";
}
for (const key in Blockly['Arduino'].loraSetupCode_) { let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n";
loraSetupCode += Blockly['Arduino'].loraSetupCode_[key] || '';
}
// Convert the definitions dictionary into a list.
code =
devVariables +
"\n" +
libraryCode +
"\n" +
variablesCode +
"\n" +
definitionsCode +
"\n" +
codeFunctions +
"\n" +
Blockly["Arduino"].variablesInitCode_ +
"\n" +
functionsCode +
"\n" +
setupCode +
"\n" +
loopCode;
setupCode = '\nvoid setup() { \n' + preSetupCode + '\n' + loraSetupCode + '\n}\n'; // Clean up temporary data.
delete Blockly["Arduino"].definitions_;
delete Blockly["Arduino"].functionNames_;
delete Blockly["Arduino"].loopCodeOnce_;
delete Blockly["Arduino"].variablesInitCode_;
delete Blockly["Arduino"].libraries_;
Blockly["Arduino"].variableDB_.reset();
let loopCode = '\nvoid loop() { \n' + loopCodeOnce + code + '\n}\n'; return code;
// Convert the definitions dictionary into a list.
code =
devVariables +
'\n' +
libraryCode +
'\n' +
variablesCode +
'\n' +
definitionsCode +
'\n' +
codeFunctions +
'\n' +
Blockly['Arduino'].variablesInitCode_ +
'\n' +
functionsCode +
'\n' +
setupCode +
'\n' +
loopCode
;
// Clean up temporary data.
delete Blockly['Arduino'].definitions_;
delete Blockly['Arduino'].functionNames_;
delete Blockly['Arduino'].loopCodeOnce_;
delete Blockly['Arduino'].variablesInitCode_;
delete Blockly['Arduino'].libraries_;
Blockly['Arduino'].variableDB_.reset();
return code;
}; };
/** /**
@ -286,8 +276,8 @@ Blockly['Arduino'].finish = function (code) {
* @param {string} line Line of generated code. * @param {string} line Line of generated code.
* @return {string} Legal line of code. * @return {string} Legal line of code.
*/ */
Blockly['Arduino'].scrubNakedValue = function (line) { Blockly["Arduino"].scrubNakedValue = function (line) {
return line + ';\n'; return line + ";\n";
}; };
/** /**
@ -297,14 +287,14 @@ Blockly['Arduino'].scrubNakedValue = function (line) {
* @return {string} Arduino string. * @return {string} Arduino string.
* @private * @private
*/ */
Blockly['Arduino'].quote_ = function (string) { Blockly["Arduino"].quote_ = function (string) {
// Can't use goog.string.quote since Google's style guide recommends // Can't use goog.string.quote since Google's style guide recommends
// JS string literals use single quotes. // JS string literals use single quotes.
string = string string = string
.replace(/\\/g, '\\\\') .replace(/\\/g, "\\\\")
.replace(/\n/g, '\\\n') .replace(/\n/g, "\\\n")
.replace(/'/g, "\\'"); .replace(/'/g, "\\'");
return '"' + string + '"'; return '"' + string + '"';
}; };
/** /**
@ -317,43 +307,42 @@ Blockly['Arduino'].quote_ = function (string) {
* @return {string} Arduino code with comments and subsequent blocks added. * @return {string} Arduino code with comments and subsequent blocks added.
* @private * @private
*/ */
Blockly['Arduino'].scrub_ = function (block, code) { Blockly["Arduino"].scrub_ = function (block, code) {
let commentCode = ''; let commentCode = "";
// Only collect comments for blocks that aren't inline. // Only collect comments for blocks that aren't inline.
if (!block.outputConnection || !block.outputConnection.targetConnection) { if (!block.outputConnection || !block.outputConnection.targetConnection) {
// Collect comment for this block. // Collect comment for this block.
let comment = block.getCommentText(); let comment = block.getCommentText();
//@ts-ignore //@ts-ignore
comment = comment ? Blockly.utils.string.wrap( comment = comment
comment, ? Blockly.utils.string.wrap(comment, Blockly["Arduino"].COMMENT_WRAP - 3)
Blockly['Arduino'].COMMENT_WRAP - 3 : null;
) : null; if (comment) {
if (comment) { if (block.getProcedureDef) {
if (block.getProcedureDef) { // Use a comment block for function comments.
// Use a comment block for function comments. commentCode +=
commentCode += "/**\n" +
'/**\n' + Blockly["Arduino"].prefixLines(comment + "\n", " * ") +
Blockly['Arduino'].prefixLines(comment + '\n', ' * ') + " */\n";
' */\n'; } else {
} else { commentCode += Blockly["Arduino"].prefixLines(comment + "\n", "// ");
commentCode += Blockly['Arduino'].prefixLines(comment + '\n', '// '); }
}
}
// Collect comments for all value arguments.
// Don't collect comments for nested statements.
for (let i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type === Blockly.INPUT_VALUE) {
const childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) {
const comment = Blockly['Arduino'].allNestedComments(childBlock);
if (comment) {
commentCode += Blockly['Arduino'].prefixLines(comment, '// ');
}
}
}
}
} }
const nextBlock = block.nextConnection && block.nextConnection.targetBlock(); // Collect comments for all value arguments.
const nextCode = Blockly['Arduino'].blockToCode(nextBlock); // Don't collect comments for nested statements.
return commentCode + code + nextCode; for (let i = 0; i < block.inputList.length; i++) {
}; if (block.inputList[i].type === Blockly.INPUT_VALUE) {
const childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) {
const comment = Blockly["Arduino"].allNestedComments(childBlock);
if (comment) {
commentCode += Blockly["Arduino"].prefixLines(comment, "// ");
}
}
}
}
}
const nextBlock = block.nextConnection && block.nextConnection.targetBlock();
const nextCode = Blockly["Arduino"].blockToCode(nextBlock);
return commentCode + code + nextCode;
};

View File

@ -1,24 +1,23 @@
import './generator'; import "./generator";
import './loops'; import "./loops";
import './sensebox-sensors'; import "./sensebox-sensors";
import './sensebox-telegram'; import "./sensebox-telegram";
import './sensebox-osem'; import "./sensebox-osem";
import './sensebox-web'; import "./sensebox-web";
import './sensebox-display'; import "./sensebox-display";
import './sensebox-lora'; import "./sensebox-lora";
import './sensebox-led'; import "./sensebox-led";
import './sensebox-sd'; import "./sensebox-ble";
import './mqtt'; import "./sensebox-sd";
import './logic'; import "./mqtt";
import './text'; import "./logic";
import './math'; import "./text";
import './map'; import "./math";
import './io'; import "./map";
import './audio'; import "./io";
import './procedures'; import "./audio";
import './time'; import "./procedures";
import './variables'; import "./time";
import './lists'; import "./variables";
import './webserver'; import "./lists";
import "./webserver";

View File

@ -0,0 +1,39 @@
import * as Blockly from "blockly/core";
Blockly.Arduino.sensebox_phyphox_init = function () {
var name = this.getFieldValue("devicename");
Blockly.Arduino.libraries_["phyphox_library"] = `#include <phyphoxBle.h>`;
Blockly.Arduino.libraries_["library_senseBoxMCU"] =
'#include "SenseBoxMCU.h"';
Blockly.Arduino.setupCode_["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 category = this.getFieldValue("category");
var description = this.getFieldValue("description");
Blockly.Arduino.setupCode_[
`PhyphoxBleExperiment_${experimentname}`
] = `PhyphoxBleExperiment ${experimentname};`;
Blockly.Arduino.setupCode_[
`setTitle_${title}`
] = `${experimentname}.setTitle("${title}")`;
Blockly.Arduino.setupCode_[
`setCategory_${category}`
] = `${experimentname}.setCategory("${category}")`;
Blockly.Arduino.setupCode_[
`setDescription_${description}`
] = `${experimentname}.setDescription("${description}")`;
var code = ``;
return code;
};
Blockly.Arduino.sensebox_phyphox_experiment_send = function () {
var data = "";
Blockly.Arduino.loopCodeOnce_["phyphox_poll"] = `PhyphoxBLE::poll()`;
var code = `PhyphoxBLE::write()`;
return code;
};

View File

@ -1,22 +1,20 @@
const colours = { const colours = {
sensebox: 120, sensebox: 120,
logic: 210, logic: 210,
loops: 10, loops: 10,
math: 230, math: 230,
io: 60, io: 60,
procedures: 290, procedures: 290,
time: 140, time: 140,
text: 160, text: 160,
variables: 330, variables: 330,
audio: 250, audio: 250,
arrays: 33, arrays: 33,
mqtt: 90, mqtt: 90,
webserver: 40 webserver: 40,
} phyphox: 25,
export const getColour = () => {
return colours;
}; };
export const getColour = () => {
return colours;
};

View File

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

View File

@ -1,36 +1,40 @@
export const LED = { export const LED = {
/** /**
* WS2818 RGB LED * WS2818 RGB LED
*/ */
senseBox_ws2818_rgb_led: "Setze RGB-LED an", senseBox_ws2818_rgb_led: "Setze RGB-LED an",
senseBox_ws2818_rgb_led_init: "RGB LED (WS2818) initialisieren", senseBox_ws2818_rgb_led_init: "RGB LED (WS2818) initialisieren",
senseBox_ws2818_rgb_led_position: "Position", senseBox_ws2818_rgb_led_position: "Position",
senseBox_ws2818_rgb_led_brightness: "Helligkeit", senseBox_ws2818_rgb_led_brightness: "Helligkeit",
senseBox_ws2818_rgb_led_tooltip: "Verändere mit diesem Block die Farbe deiner RGB-LED. Verbinde einen Block für die Farbe. Wenn mehrere RGB-LEDs miteinander verkettet werden kannst du über die Position bestimmen welche LED angesteuert wird. ", senseBox_ws2818_rgb_led_tooltip:
senseBox_ws2818_rgb_led_init_tooltip: "Schließe die RGB-LED an einen der drei **digital/analog Ports** an. Wenn mehrere RGB-LEDs miteinander verkettet werden kannst du über die Position bestimmen welche LED angesteuert wird. ", "Verändere mit diesem Block die Farbe deiner RGB-LED. Verbinde einen Block für die Farbe. Wenn mehrere RGB-LEDs miteinander verkettet werden kannst du über die Position bestimmen welche LED angesteuert wird. ",
senseBox_ws2818_rgb_led_color: "Farbe", senseBox_ws2818_rgb_led_init_tooltip:
senseBox_ws2818_rgb_led_number: "Anzahl", "Schließe die RGB-LED an einen der drei **digital/analog Ports** an. Wenn mehrere RGB-LEDs miteinander verkettet werden kannst du über die Position bestimmen welche LED angesteuert wird. ",
senseBox_ws2818_rgb_led_color: "Farbe",
senseBox_ws2818_rgb_led_number: "Anzahl",
/** /**
* Color * Color
*/ */
COLOUR_BLEND_COLOUR1: "Farbe 1", COLOUR_BLEND_COLOUR1: "Farbe 1",
COLOUR_BLEND_COLOUR2: "mit Farbe 2", COLOUR_BLEND_COLOUR2: "mit Farbe 2",
COLOUR_BLEND_HELPURL: "http://meyerweb.com/eric/tools/color-blend/", COLOUR_BLEND_HELPURL: "http://meyerweb.com/eric/tools/color-blend/",
COLOUR_BLEND_RATIO: "im Verhältnis", COLOUR_BLEND_RATIO: "im Verhältnis",
COLOUR_BLEND_TITLE: "mische", COLOUR_BLEND_TITLE: "mische",
COLOUR_BLEND_TOOLTIP: "Vermische 2 Farben mit konfigurierbaren Farbverhältnis (0.0 - 1.0).", COLOUR_BLEND_TOOLTIP:
COLOUR_PICKER_HELPURL: "https://de.wikipedia.org/wiki/Farbe", "Vermische 2 Farben mit konfigurierbaren Farbverhältnis (0.0 - 1.0).",
COLOUR_PICKER_TOOLTIP: "Wähle eine Farbe aus der Palette. Die Farbe wird automatisch in RGB-Werte konvertiert.", COLOUR_PICKER_HELPURL: "https://de.wikipedia.org/wiki/Farbe",
COLOUR_RANDOM_HELPURL: "http://randomcolour.com", // untranslated COLOUR_PICKER_TOOLTIP:
COLOUR_RANDOM_TITLE: "zufällige Farbe", "Wähle eine Farbe aus der Palette. Die Farbe wird automatisch in RGB-Werte konvertiert.",
COLOUR_RANDOM_TOOLTIP: "Erstelle eine Farbe nach dem Zufallsprinzip.", COLOUR_RANDOM_HELPURL: "http://randomcolour.com", // untranslated
COLOUR_RGB_BLUE: "blau", COLOUR_RANDOM_TITLE: "zufällige Farbe",
COLOUR_RGB_GREEN: "grün", COLOUR_RANDOM_TOOLTIP: "Erstelle eine Farbe nach dem Zufallsprinzip.",
COLOUR_RGB_HELPURL: "https://de.wikipedia.org/wiki/RGB-Farbraum", COLOUR_RGB_BLUE: "blau",
COLOUR_RGB_RED: "rot", COLOUR_RGB_GREEN: "grün",
COLOUR_RGB_TITLE: "Farbe mit", COLOUR_RGB_HELPURL: "https://de.wikipedia.org/wiki/RGB-Farbraum",
COLOUR_RGB_TOOLTIP: "Erstelle eine Farbe mit selbst definierten Rot-, Grün- und Blauwerten. Alle Werte müssen zwischen 0 und 255 liegen. 0 ist hierbei die geringte Intensität der Farbe 255 die höchste.", COLOUR_RGB_RED: "rot",
COLOUR_RGB_TITLE: "Farbe mit",
} COLOUR_RGB_TOOLTIP:
"Erstelle eine Farbe mit selbst definierten Rot-, Grün- und Blauwerten. Alle Werte müssen zwischen 0 und 255 liegen. 0 ist hierbei die geringte Intensität der Farbe 255 die höchste.",
};

File diff suppressed because it is too large Load Diff