From 47984fa66c4d4678624da745db28de25161e303f Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Thu, 6 May 2021 15:21:54 +0200 Subject: [PATCH 1/6] add first phyphox blocks --- src/components/Blockly/blocks/index.js | 47 +- src/components/Blockly/blocks/sensebox-ble.js | 60 + src/components/Blockly/generator/generator.js | 469 ++++---- src/components/Blockly/generator/index.js | 47 +- .../Blockly/generator/sensebox-ble.js | 39 + src/components/Blockly/helpers/colour.js | 36 +- src/components/Blockly/msg/de.js | 93 +- src/components/Blockly/msg/de/sensebox-ble.js | 12 + src/components/Blockly/msg/de/sensebox-led.js | 70 +- src/components/Blockly/toolbox/Toolbox.js | 1024 +++++++++-------- 10 files changed, 1033 insertions(+), 864 deletions(-) create mode 100644 src/components/Blockly/blocks/sensebox-ble.js create mode 100644 src/components/Blockly/generator/sensebox-ble.js create mode 100644 src/components/Blockly/msg/de/sensebox-ble.js diff --git a/src/components/Blockly/blocks/index.js b/src/components/Blockly/blocks/index.js index 964c2dc..c1ea173 100644 --- a/src/components/Blockly/blocks/index.js +++ b/src/components/Blockly/blocks/index.js @@ -1,24 +1,25 @@ -import './loops'; -import './sensebox'; -import './logic'; -import './sensebox-sensors'; -import './sensebox-telegram'; -import './sensebox-osem'; -import './sensebox-web'; -import './sensebox-display'; -import './sensebox-lora'; -import './sensebox-led'; -import './sensebox-sd'; -import './mqtt'; -import './text'; -import './io'; -import './audio'; -import './math'; -import './map'; -import './procedures'; -import './time'; -import './variables'; -import './lists'; -import './webserver'; +import "./loops"; +import "./sensebox"; +import "./logic"; +import "./sensebox-sensors"; +import "./sensebox-telegram"; +import "./sensebox-osem"; +import "./sensebox-web"; +import "./sensebox-display"; +import "./sensebox-lora"; +import "./sensebox-led"; +import "./sensebox-ble"; +import "./sensebox-sd"; +import "./mqtt"; +import "./text"; +import "./io"; +import "./audio"; +import "./math"; +import "./map"; +import "./procedures"; +import "./time"; +import "./variables"; +import "./lists"; +import "./webserver"; -import '../helpers/types' \ No newline at end of file +import "../helpers/types"; diff --git a/src/components/Blockly/blocks/sensebox-ble.js b/src/components/Blockly/blocks/sensebox-ble.js new file mode 100644 index 0000000..b4082b1 --- /dev/null +++ b/src/components/Blockly/blocks/sensebox-ble.js @@ -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); + }, +}; diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index 2bcb63d..a6b02ce 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -1,6 +1,6 @@ /** * @license - * + * * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,13 +24,13 @@ // More on 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. * @type !Blockly.Generator */ -Blockly['Arduino'] = new Blockly.Generator('Arduino'); +Blockly["Arduino"] = new Blockly.Generator("Arduino"); /** * List of illegal variable names. @@ -39,156 +39,150 @@ Blockly['Arduino'] = new Blockly.Generator('Arduino'); * accidentally clobbering a built-in object or function. * @private */ -Blockly['Arduino'].addReservedWords( - // http://arduino.cc/en/Reference/HomePage - 'setup,loop,if,else,for,switch,case,while,' + - 'do,break,continue,return,goto,define,include,' + - 'HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,' + - 'interger, constants,floating,point,void,boolean,char,' + - 'unsigned,byte,int,word,long,float,double,string,String,array,' + - 'static, volatile,const,sizeof,pinMode,digitalWrite,digitalRead,' + - 'analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,' + - 'pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain,' + - 'map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead,' + - 'bitWrite,bitSet,bitClear,ultraSonicDistance,parseDouble,setNeoPixelColor,' + - 'bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts', - 'short', - 'isBtnPressed' +Blockly["Arduino"].addReservedWords( + // http://arduino.cc/en/Reference/HomePage + "setup,loop,if,else,for,switch,case,while," + + "do,break,continue,return,goto,define,include," + + "HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false," + + "interger, constants,floating,point,void,boolean,char," + + "unsigned,byte,int,word,long,float,double,string,String,array," + + "static, volatile,const,sizeof,pinMode,digitalWrite,digitalRead," + + "analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn," + + "pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain," + + "map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead," + + "bitWrite,bitSet,bitClear,ultraSonicDistance,parseDouble,setNeoPixelColor," + + "bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts", + "short", + "isBtnPressed" ); /** * Order of operation ENUMs. * */ -Blockly['Arduino'].ORDER_ATOMIC = 0; // 0 "" ... -Blockly['Arduino'].ORDER_UNARY_POSTFIX = 1; // expr++ expr-- () [] . -Blockly['Arduino'].ORDER_UNARY_PREFIX = 2; // -expr !expr ~expr ++expr --expr -Blockly['Arduino'].ORDER_MULTIPLICATIVE = 3; // * / % ~/ -Blockly['Arduino'].ORDER_ADDITIVE = 4; // + - -Blockly['Arduino'].ORDER_LOGICAL_NOT = 4.4; // ! -Blockly['Arduino'].ORDER_SHIFT = 5; // << >> -Blockly['Arduino'].ORDER_MODULUS = 5.3; // % -Blockly['Arduino'].ORDER_RELATIONAL = 6; // is is! >= > <= < -Blockly['Arduino'].ORDER_EQUALITY = 7; // === !== === !== -Blockly['Arduino'].ORDER_BITWISE_AND = 8; // & -Blockly['Arduino'].ORDER_BITWISE_XOR = 9; // ^ -Blockly['Arduino'].ORDER_BITWISE_OR = 10; // | -Blockly['Arduino'].ORDER_LOGICAL_AND = 11; // && -Blockly['Arduino'].ORDER_LOGICAL_OR = 12; // || -Blockly['Arduino'].ORDER_CONDITIONAL = 13; // expr ? expr : expr -Blockly['Arduino'].ORDER_ASSIGNMENT = 14; // = *= /= ~/= %= += -= <<= >>= &= ^= |= -Blockly['Arduino'].ORDER_COMMA = 18; // , -Blockly['Arduino'].ORDER_NONE = 99; // (...) - - - +Blockly["Arduino"].ORDER_ATOMIC = 0; // 0 "" ... +Blockly["Arduino"].ORDER_UNARY_POSTFIX = 1; // expr++ expr-- () [] . +Blockly["Arduino"].ORDER_UNARY_PREFIX = 2; // -expr !expr ~expr ++expr --expr +Blockly["Arduino"].ORDER_MULTIPLICATIVE = 3; // * / % ~/ +Blockly["Arduino"].ORDER_ADDITIVE = 4; // + - +Blockly["Arduino"].ORDER_LOGICAL_NOT = 4.4; // ! +Blockly["Arduino"].ORDER_SHIFT = 5; // << >> +Blockly["Arduino"].ORDER_MODULUS = 5.3; // % +Blockly["Arduino"].ORDER_RELATIONAL = 6; // is is! >= > <= < +Blockly["Arduino"].ORDER_EQUALITY = 7; // === !== === !== +Blockly["Arduino"].ORDER_BITWISE_AND = 8; // & +Blockly["Arduino"].ORDER_BITWISE_XOR = 9; // ^ +Blockly["Arduino"].ORDER_BITWISE_OR = 10; // | +Blockly["Arduino"].ORDER_LOGICAL_AND = 11; // && +Blockly["Arduino"].ORDER_LOGICAL_OR = 12; // || +Blockly["Arduino"].ORDER_CONDITIONAL = 13; // expr ? expr : expr +Blockly["Arduino"].ORDER_ASSIGNMENT = 14; // = *= /= ~/= %= += -= <<= >>= &= ^= |= +Blockly["Arduino"].ORDER_COMMA = 18; // , +Blockly["Arduino"].ORDER_NONE = 99; // (...) /** - * - * @param {} workspace - * + * + * @param {} workspace + * * Blockly Types */ - - - /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. */ -Blockly['Arduino'].init = function (workspace) { - // Create a dictionary of definitions to be printed before the code. - Blockly['Arduino'].libraries_ = Object.create(null); +Blockly["Arduino"].init = function (workspace) { + // Create a dictionary of definitions to be printed before the code. + 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 - Blockly['Arduino'].setupCode_ = Object.create(null); + // 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'].loraSetupCode_ = Object.create(null); + // creates a list of code to be setup before the setup block + Blockly["Arduino"].loraSetupCode_ = Object.create(null); - // creates a list of code for the loop to be runned once - Blockly['Arduino'].loopCodeOnce_ = Object.create(null) + // creates a list of code for the loop to be runned once + Blockly["Arduino"].loopCodeOnce_ = Object.create(null); - // creates a list of code for the loop to be runned once - Blockly['Arduino'].codeFunctions_ = Object.create(null) + // creates a list of code for the loop to be runned once + Blockly["Arduino"].codeFunctions_ = Object.create(null); - // creates a list of code variables - Blockly['Arduino'].variables_ = Object.create(null) + // creates a list of code variables + Blockly["Arduino"].variables_ = Object.create(null); - // Create a dictionary mapping desired function names in definitions_ - // to actual function names (to avoid collisions with user functions). - Blockly['Arduino'].functionNames_ = Object.create(null); + // Create a dictionary mapping desired function names in definitions_ + // to actual function names (to avoid collisions with user functions). + Blockly["Arduino"].functionNames_ = Object.create(null); - Blockly['Arduino'].variablesInitCode_ = ''; + Blockly["Arduino"].variablesInitCode_ = ""; - if (!Blockly['Arduino'].variableDB_) { - Blockly['Arduino'].variableDB_ = new Blockly.Names( - Blockly['Arduino'].RESERVED_WORDS_ - ); - } else { - Blockly['Arduino'].variableDB_.reset(); - } + if (!Blockly["Arduino"].variableDB_) { + Blockly["Arduino"].variableDB_ = new Blockly.Names( + Blockly["Arduino"].RESERVED_WORDS_ + ); + } else { + Blockly["Arduino"].variableDB_.reset(); + } - Blockly['Arduino'].variableDB_.setVariableMap(workspace.getVariableMap()); + Blockly["Arduino"].variableDB_.setVariableMap(workspace.getVariableMap()); - // We don't have developer variables for now - // // Add developer variables (not created or named by the user). - // var devVarList = Blockly.Variables.allDeveloperVariables(workspace); - // for (var i = 0; i < devVarList.length; i++) { - // defvars.push(Blockly['Arduino'].variableDB_.getName(devVarList[i], - // Blockly.Names.DEVELOPER_VARIABLE_TYPE)); - // } + // We don't have developer variables for now + // // Add developer variables (not created or named by the user). + // var devVarList = Blockly.Variables.allDeveloperVariables(workspace); + // for (var i = 0; i < devVarList.length; i++) { + // defvars.push(Blockly['Arduino'].variableDB_.getName(devVarList[i], + // 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'].variableDB_.getName( - doubleVariables[i].getId(), - Blockly.Variables.NAME_TYPE - ) + - ' = 0; \n\n'; - } + const doubleVariables = workspace.getVariablesOfType("Number"); + let i = 0; + let variableCode = ""; + for (i = 0; i < doubleVariables.length; i += 1) { + variableCode += + "double " + + Blockly["Arduino"].variableDB_.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'].variableDB_.getName( - stringVariables[i].getId(), - Blockly.Variables.NAME_TYPE - ) + - ' = ""; \n\n'; - } + const stringVariables = workspace.getVariablesOfType("String"); + for (i = 0; i < stringVariables.length; i += 1) { + variableCode += + "String " + + Blockly["Arduino"].variableDB_.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'].variableDB_.getDistinctName( - booleanVariables[i].getId(), - Blockly.Variables.NAME_TYPE - ) + - ' = false; \n\n'; - } + const booleanVariables = workspace.getVariablesOfType("Boolean"); + for (i = 0; i < booleanVariables.length; i += 1) { + variableCode += + "boolean " + + Blockly["Arduino"].variableDB_.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'].variableDB_.getName( - colourVariables[i].getId(), - Blockly.Variables.NAME_TYPE - ) + - ' = {0, 0, 0}; \n\n'; - } + const colourVariables = workspace.getVariablesOfType("Colour"); + for (i = 0; i < colourVariables.length; i += 1) { + variableCode += + "RGB " + + Blockly["Arduino"].variableDB_.getName( + colourVariables[i].getId(), + Blockly.Variables.NAME_TYPE + ) + + " = {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. * @return {string} Completed code. */ -Blockly['Arduino'].finish = function (code) { - let libraryCode = ''; - let variablesCode = ''; - let codeFunctions = ''; - let functionsCode = ''; - let definitionsCode = ''; - let loopCodeOnce = ''; - let setupCode = ''; - let preSetupCode = ''; - let loraSetupCode = ''; - let devVariables = '\n'; +Blockly["Arduino"].finish = function (code) { + let libraryCode = ""; + let variablesCode = ""; + let codeFunctions = ""; + let functionsCode = ""; + let definitionsCode = ""; + let loopCodeOnce = ""; + let setupCode = ""; + let preSetupCode = ""; + let loraSetupCode = ""; + let devVariables = "\n"; - for (const key in Blockly['Arduino'].libraries_) { - libraryCode += Blockly['Arduino'].libraries_[key] + '\n'; - } + for (const key in Blockly["Arduino"].libraries_) { + libraryCode += Blockly["Arduino"].libraries_[key] + "\n"; + } - for (const key in Blockly['Arduino'].variables_) { - variablesCode += Blockly['Arduino'].variables_[key] + '\n'; - } + for (const key in Blockly["Arduino"].variables_) { + variablesCode += Blockly["Arduino"].variables_[key] + "\n"; + } - for (const key in Blockly['Arduino'].definitions_) { - definitionsCode += Blockly['Arduino'].definitions_[key] + '\n'; - } + for (const key in Blockly["Arduino"].definitions_) { + definitionsCode += Blockly["Arduino"].definitions_[key] + "\n"; + } - for (const key in Blockly['Arduino'].loopCodeOnce_) { - loopCodeOnce += Blockly['Arduino'].loopCodeOnce_[key] + '\n'; - } + for (const key in Blockly["Arduino"].loopCodeOnce_) { + loopCodeOnce += Blockly["Arduino"].loopCodeOnce_[key] + "\n"; + } - for (const key in Blockly['Arduino'].codeFunctions_) { - codeFunctions += Blockly['Arduino'].codeFunctions_[key] + '\n'; - } + for (const key in Blockly["Arduino"].codeFunctions_) { + codeFunctions += Blockly["Arduino"].codeFunctions_[key] + "\n"; + } - for (const key in Blockly['Arduino'].functionNames_) { - functionsCode += Blockly['Arduino'].functionNames_[key] + '\n'; - } + for (const key in Blockly["Arduino"].functionNames_) { + 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_) { - preSetupCode += Blockly['Arduino'].setupCode_[key] || ''; - } + setupCode = + "\nvoid setup() { \n" + preSetupCode + "\n" + loraSetupCode + "\n}\n"; - for (const key in Blockly['Arduino'].loraSetupCode_) { - loraSetupCode += Blockly['Arduino'].loraSetupCode_[key] || ''; - } + let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n"; + // 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'; - - - // 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; + return code; }; /** @@ -286,8 +276,8 @@ Blockly['Arduino'].finish = function (code) { * @param {string} line Line of generated code. * @return {string} Legal line of code. */ -Blockly['Arduino'].scrubNakedValue = function (line) { - return line + ';\n'; +Blockly["Arduino"].scrubNakedValue = function (line) { + return line + ";\n"; }; /** @@ -297,14 +287,14 @@ Blockly['Arduino'].scrubNakedValue = function (line) { * @return {string} Arduino string. * @private */ -Blockly['Arduino'].quote_ = function (string) { - // Can't use goog.string.quote since Google's style guide recommends - // JS string literals use single quotes. - string = string - .replace(/\\/g, '\\\\') - .replace(/\n/g, '\\\n') - .replace(/'/g, "\\'"); - return '"' + string + '"'; +Blockly["Arduino"].quote_ = function (string) { + // Can't use goog.string.quote since Google's style guide recommends + // JS string literals use single quotes. + string = string + .replace(/\\/g, "\\\\") + .replace(/\n/g, "\\\n") + .replace(/'/g, "\\'"); + return '"' + string + '"'; }; /** @@ -317,43 +307,42 @@ Blockly['Arduino'].quote_ = function (string) { * @return {string} Arduino code with comments and subsequent blocks added. * @private */ -Blockly['Arduino'].scrub_ = function (block, code) { - let commentCode = ''; - // Only collect comments for blocks that aren't inline. - if (!block.outputConnection || !block.outputConnection.targetConnection) { - // Collect comment for this block. - let comment = block.getCommentText(); - //@ts-ignore - comment = comment ? Blockly.utils.string.wrap( - comment, - Blockly['Arduino'].COMMENT_WRAP - 3 - ) : null; - if (comment) { - if (block.getProcedureDef) { - // Use a comment block for function comments. - commentCode += - '/**\n' + - Blockly['Arduino'].prefixLines(comment + '\n', ' * ') + - ' */\n'; - } else { - 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, '// '); - } - } - } - } +Blockly["Arduino"].scrub_ = function (block, code) { + let commentCode = ""; + // Only collect comments for blocks that aren't inline. + if (!block.outputConnection || !block.outputConnection.targetConnection) { + // Collect comment for this block. + let comment = block.getCommentText(); + //@ts-ignore + comment = comment + ? Blockly.utils.string.wrap(comment, Blockly["Arduino"].COMMENT_WRAP - 3) + : null; + if (comment) { + if (block.getProcedureDef) { + // Use a comment block for function comments. + commentCode += + "/**\n" + + Blockly["Arduino"].prefixLines(comment + "\n", " * ") + + " */\n"; + } else { + commentCode += Blockly["Arduino"].prefixLines(comment + "\n", "// "); + } } - const nextBlock = block.nextConnection && block.nextConnection.targetBlock(); - const nextCode = Blockly['Arduino'].blockToCode(nextBlock); - return commentCode + code + nextCode; -}; \ No newline at end of file + // 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(); + const nextCode = Blockly["Arduino"].blockToCode(nextBlock); + return commentCode + code + nextCode; +}; diff --git a/src/components/Blockly/generator/index.js b/src/components/Blockly/generator/index.js index 04f337f..7d1f088 100644 --- a/src/components/Blockly/generator/index.js +++ b/src/components/Blockly/generator/index.js @@ -1,24 +1,23 @@ -import './generator'; -import './loops'; -import './sensebox-sensors'; -import './sensebox-telegram'; -import './sensebox-osem'; -import './sensebox-web'; -import './sensebox-display'; -import './sensebox-lora'; -import './sensebox-led'; -import './sensebox-sd'; -import './mqtt'; -import './logic'; -import './text'; -import './math'; -import './map'; -import './io'; -import './audio'; -import './procedures'; -import './time'; -import './variables'; -import './lists'; -import './webserver'; - - +import "./generator"; +import "./loops"; +import "./sensebox-sensors"; +import "./sensebox-telegram"; +import "./sensebox-osem"; +import "./sensebox-web"; +import "./sensebox-display"; +import "./sensebox-lora"; +import "./sensebox-led"; +import "./sensebox-ble"; +import "./sensebox-sd"; +import "./mqtt"; +import "./logic"; +import "./text"; +import "./math"; +import "./map"; +import "./io"; +import "./audio"; +import "./procedures"; +import "./time"; +import "./variables"; +import "./lists"; +import "./webserver"; diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js new file mode 100644 index 0000000..cec99e3 --- /dev/null +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -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 `; + 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; +}; diff --git a/src/components/Blockly/helpers/colour.js b/src/components/Blockly/helpers/colour.js index 0b3c1fb..ac2b0ed 100644 --- a/src/components/Blockly/helpers/colour.js +++ b/src/components/Blockly/helpers/colour.js @@ -1,22 +1,20 @@ - const colours = { - sensebox: 120, - logic: 210, - loops: 10, - math: 230, - io: 60, - procedures: 290, - time: 140, - text: 160, - variables: 330, - audio: 250, - arrays: 33, - mqtt: 90, - webserver: 40 -} - - -export const getColour = () => { - return colours; + sensebox: 120, + logic: 210, + loops: 10, + math: 230, + io: 60, + procedures: 290, + time: 140, + text: 160, + variables: 330, + audio: 250, + arrays: 33, + mqtt: 90, + webserver: 40, + phyphox: 25, }; +export const getColour = () => { + return colours; +}; diff --git a/src/components/Blockly/msg/de.js b/src/components/Blockly/msg/de.js index aff10ad..82d80e8 100644 --- a/src/components/Blockly/msg/de.js +++ b/src/components/Blockly/msg/de.js @@ -1,48 +1,49 @@ - -import { AUDIO } from './de/audio'; -import { FAQ } from './de/faq'; -import { IO } from './de/io'; -import { LOGIC } from './de/logic'; -import { LOOPS } from './de/loops'; -import { MATH } from './de/math'; -import { MQTT } from './de/mqtt'; -import { DISPLAY } from './de/sensebox-display'; -import { LED } from './de/sensebox-led'; -import { LORA } from './de/sensebox-lora'; -import { OSEM } from './de/sensebox-osem'; -import { SD } from './de/sensebox-sd'; -import { SENSORS } from './de/sensebox-sensors'; -import { TELEGRAM } from './de/sensebox-telegram'; -import { WEB } from './de/sensebox-web'; -import { TEXT } from './de/text'; -import { TIME } from './de/time'; -import { TOURS } from './de/tours'; -import { TRANSLATIONS } from './de/translations'; -import { UI } from './de/ui'; -import { VARIABLES } from './de/variables'; -import { WEBSERVER } from './de/webserver'; +import { AUDIO } from "./de/audio"; +import { BLE } from "./de/sensebox-ble"; +import { FAQ } from "./de/faq"; +import { IO } from "./de/io"; +import { LOGIC } from "./de/logic"; +import { LOOPS } from "./de/loops"; +import { MATH } from "./de/math"; +import { MQTT } from "./de/mqtt"; +import { DISPLAY } from "./de/sensebox-display"; +import { LED } from "./de/sensebox-led"; +import { LORA } from "./de/sensebox-lora"; +import { OSEM } from "./de/sensebox-osem"; +import { SD } from "./de/sensebox-sd"; +import { SENSORS } from "./de/sensebox-sensors"; +import { TELEGRAM } from "./de/sensebox-telegram"; +import { WEB } from "./de/sensebox-web"; +import { TEXT } from "./de/text"; +import { TIME } from "./de/time"; +import { TOURS } from "./de/tours"; +import { TRANSLATIONS } from "./de/translations"; +import { UI } from "./de/ui"; +import { VARIABLES } from "./de/variables"; +import { WEBSERVER } from "./de/webserver"; export const De = { - ...AUDIO, - ...FAQ, - ...IO, - ...LOGIC, - ...LOOPS, - ...MATH, - ...MQTT, - ...DISPLAY, - ...LED, - ...LORA, - ...OSEM, - ...SD, - ...SENSORS, - ...TELEGRAM, - ...WEB, - ...TEXT, - ...TIME, - ...TOURS, - ...TRANSLATIONS, - ...UI, - ...VARIABLES, - ...WEBSERVER -} + ...AUDIO, + ...BLE, + ...FAQ, + ...IO, + ...LOGIC, + ...LOOPS, + ...MATH, + ...MQTT, + ...DISPLAY, + ...LED, + ...LORA, + ...OSEM, + ...SD, + ...SENSORS, + ...TELEGRAM, + ...WEB, + ...TEXT, + ...TIME, + ...TOURS, + ...TRANSLATIONS, + ...UI, + ...VARIABLES, + ...WEBSERVER, +}; diff --git a/src/components/Blockly/msg/de/sensebox-ble.js b/src/components/Blockly/msg/de/sensebox-ble.js new file mode 100644 index 0000000..6ebdeb2 --- /dev/null +++ b/src/components/Blockly/msg/de/sensebox-ble.js @@ -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", +}; diff --git a/src/components/Blockly/msg/de/sensebox-led.js b/src/components/Blockly/msg/de/sensebox-led.js index 22961be..fb56ee4 100644 --- a/src/components/Blockly/msg/de/sensebox-led.js +++ b/src/components/Blockly/msg/de/sensebox-led.js @@ -1,36 +1,40 @@ export const LED = { - /** - * WS2818 RGB LED - */ - senseBox_ws2818_rgb_led: "Setze RGB-LED an", - senseBox_ws2818_rgb_led_init: "RGB LED (WS2818) initialisieren", - senseBox_ws2818_rgb_led_position: "Position", - 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_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. ", - senseBox_ws2818_rgb_led_color: "Farbe", - senseBox_ws2818_rgb_led_number: "Anzahl", + /** + * WS2818 RGB LED + */ + senseBox_ws2818_rgb_led: "Setze RGB-LED an", + senseBox_ws2818_rgb_led_init: "RGB LED (WS2818) initialisieren", + senseBox_ws2818_rgb_led_position: "Position", + 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_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. ", + senseBox_ws2818_rgb_led_color: "Farbe", + senseBox_ws2818_rgb_led_number: "Anzahl", - /** - * Color - */ + /** + * Color + */ - COLOUR_BLEND_COLOUR1: "Farbe 1", - COLOUR_BLEND_COLOUR2: "mit Farbe 2", - COLOUR_BLEND_HELPURL: "http://meyerweb.com/eric/tools/color-blend/", - COLOUR_BLEND_RATIO: "im Verhältnis", - COLOUR_BLEND_TITLE: "mische", - COLOUR_BLEND_TOOLTIP: "Vermische 2 Farben mit konfigurierbaren Farbverhältnis (0.0 - 1.0).", - COLOUR_PICKER_HELPURL: "https://de.wikipedia.org/wiki/Farbe", - COLOUR_PICKER_TOOLTIP: "Wähle eine Farbe aus der Palette. Die Farbe wird automatisch in RGB-Werte konvertiert.", - COLOUR_RANDOM_HELPURL: "http://randomcolour.com", // untranslated - COLOUR_RANDOM_TITLE: "zufällige Farbe", - COLOUR_RANDOM_TOOLTIP: "Erstelle eine Farbe nach dem Zufallsprinzip.", - COLOUR_RGB_BLUE: "blau", - COLOUR_RGB_GREEN: "grün", - COLOUR_RGB_HELPURL: "https://de.wikipedia.org/wiki/RGB-Farbraum", - 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.", - -} \ No newline at end of file + COLOUR_BLEND_COLOUR1: "Farbe 1", + COLOUR_BLEND_COLOUR2: "mit Farbe 2", + COLOUR_BLEND_HELPURL: "http://meyerweb.com/eric/tools/color-blend/", + COLOUR_BLEND_RATIO: "im Verhältnis", + COLOUR_BLEND_TITLE: "mische", + COLOUR_BLEND_TOOLTIP: + "Vermische 2 Farben mit konfigurierbaren Farbverhältnis (0.0 - 1.0).", + COLOUR_PICKER_HELPURL: "https://de.wikipedia.org/wiki/Farbe", + COLOUR_PICKER_TOOLTIP: + "Wähle eine Farbe aus der Palette. Die Farbe wird automatisch in RGB-Werte konvertiert.", + COLOUR_RANDOM_HELPURL: "http://randomcolour.com", // untranslated + COLOUR_RANDOM_TITLE: "zufällige Farbe", + COLOUR_RANDOM_TOOLTIP: "Erstelle eine Farbe nach dem Zufallsprinzip.", + COLOUR_RGB_BLUE: "blau", + COLOUR_RGB_GREEN: "grün", + COLOUR_RGB_HELPURL: "https://de.wikipedia.org/wiki/RGB-Farbraum", + 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.", +}; diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 713bce3..4976ed2 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -1,495 +1,561 @@ -import React from 'react'; -import { Block, Value, Field, Shadow, Category } from '../'; -import { getColour } from '../helpers/colour' -import '@blockly/block-plus-minus'; -import { TypedVariableModal } from '@blockly/plugin-typed-variable-modal'; -import * as Blockly from 'blockly/core'; - - - +import React from "react"; +import { Block, Value, Field, Shadow, Category } from "../"; +import { getColour } from "../helpers/colour"; +import "@blockly/block-plus-minus"; +import { TypedVariableModal } from "@blockly/plugin-typed-variable-modal"; +import * as Blockly from "blockly/core"; class Toolbox extends React.Component { + componentDidUpdate() { + this.props.workspace.registerToolboxCategoryCallback( + "CREATE_TYPED_VARIABLE", + this.createFlyout + ); - componentDidUpdate() { - this.props.workspace.registerToolboxCategoryCallback('CREATE_TYPED_VARIABLE', this.createFlyout); + const typedVarModal = new TypedVariableModal( + this.props.workspace, + "callbackName", + [ + ["SHORT_NUMBER", "char"], + ["NUMBER", "int"], + ["DECIMAL", "float"], + ["TEXT", "String"], + ["ARRAY", "Array"], + ["CHARACTER", "char"], + ["BOOLEAN", "boolean"], + ["NULL", "void"], + ["UNDEF", "undefined"], + ] + ); + typedVarModal.init(); + } - const typedVarModal = new TypedVariableModal(this.props.workspace, 'callbackName', [['SHORT_NUMBER', 'char'], ['NUMBER', 'int'], ['DECIMAL', 'float'], ['TEXT', 'String'], ['ARRAY', 'Array'], ['CHARACTER', 'char'], ['BOOLEAN', 'boolean'], ['NULL', 'void'], ['UNDEF', 'undefined']]); - typedVarModal.init(); - } + createFlyout(workspace) { + let xmlList = []; - createFlyout(workspace) { + // Add your button and give it a callback name. + const button = document.createElement("button"); + button.setAttribute("text", "Create Typed Variable"); + button.setAttribute("callbackKey", "callbackName"); - let xmlList = []; + xmlList.push(button); - // Add your button and give it a callback name. - const button = document.createElement('button'); - button.setAttribute('text', 'Create Typed Variable'); - button.setAttribute('callbackKey', 'callbackName'); + // This gets all the variables that the user creates and adds them to the + // flyout. + const blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace); + xmlList = xmlList.concat(blockList); + return xmlList; + } - xmlList.push(button); - - // This gets all the variables that the user creates and adds them to the - // flyout. - const blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace); - xmlList = xmlList.concat(blockList); - return xmlList; - }; - - render() { - return ( - - - - - - - - - - - - - - - - {/* */} - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - 30 - - - - - - - 0 - - - - - 0 - - - - - - - - - 100 - - - - - 50 - - - - - 0 - - - - - - - - - - - - 1 - - - - - 0 - - - - - 0 - - - - - - - Title - - - - - Unit - - - - - Title - - - - - Unit - - - - - - - - - - - - - - - - - - - 0 - - - - - 15 - - - - - 0 - - - - - 50 - - - - - 5 - - - - - 0 - - - - - 15 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - latitude - - - - - longitude - - - - - altitude - - - - - pDOP - - - - - fixType - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {/* */} - - - - - - - - - - - - - - - 10 - - - - - - - - 1 - - - - - 10 - - - - - 1 - - - - - - - - - - - - - - - - - - - - - 1000 - - - - - - - 100 - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - - 1 - - - - - 100 - - - - - - - 1 - - - - - 100 - - - - - - - - - - - 220 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 100 - - - - - {/* this block is the initial block of the workspace; not necessary + render() { + return ( + + + + + + + + + + + + + + + + {/* */} + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + 30 + + + + + + + 0 + + + + + 0 + + + + + + + + + 100 + + + + + 50 + + + + + 0 + + + + + + + + + + + + 1 + + + + + 0 + + + + + 0 + + + + + + + Title + + + + + Unit + + + + + Title + + + + + Unit + + + + + + + + + + + + + + + + 0 + + + + + 15 + + + + + 0 + + + + + 50 + + + + + 5 + + + + + 0 + + + + + 15 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + latitude + + + + + longitude + + + + + altitude + + + + + pDOP + + + + + fixType + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {/* */} + + + + + + + + + + + + + + + 10 + + + + + + + + 1 + + + + + 10 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + 1000 + + + + + + + 100 + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 1 + + + + + 100 + + + + + + + 1 + + + + + 100 + + + + + + + + + + + 220 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + {/* this block is the initial block of the workspace; not necessary to display, because it can only be used once anyway */} - - ); - }; + + ); + } } export default Toolbox; From 44d48997d45f4584457266114b0c594d0a1fa678 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Sun, 16 May 2021 20:03:21 +0200 Subject: [PATCH 2/6] update phyphox blocks --- src/components/Blockly/blocks/sensebox-ble.js | 112 +++++++++++++++- src/components/Blockly/generator/generator.js | 16 ++- .../Blockly/generator/sensebox-ble.js | 125 ++++++++++++++++-- src/components/Blockly/msg/de/sensebox-ble.js | 13 ++ src/components/Blockly/msg/en.js | 92 ++++++------- src/components/Blockly/msg/en/sensebox-ble.js | 25 ++++ src/components/Blockly/toolbox/Toolbox.js | 23 +++- 7 files changed, 340 insertions(+), 66 deletions(-) create mode 100644 src/components/Blockly/msg/en/sensebox-ble.js diff --git a/src/components/Blockly/blocks/sensebox-ble.js b/src/components/Blockly/blocks/sensebox-ble.js index b4082b1..6cff14b 100644 --- a/src/components/Blockly/blocks/sensebox-ble.js +++ b/src/components/Blockly/blocks/sensebox-ble.js @@ -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); diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index a6b02ce..841f7dc 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -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"; diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js index cec99e3..1532ff7 100644 --- a/src/components/Blockly/generator/sensebox-ble.js +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -5,35 +5,132 @@ Blockly.Arduino.sensebox_phyphox_init = function () { Blockly.Arduino.libraries_["phyphox_library"] = `#include `; 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; }; diff --git a/src/components/Blockly/msg/de/sensebox-ble.js b/src/components/Blockly/msg/de/sensebox-ble.js index 6ebdeb2..32447a7 100644 --- a/src/components/Blockly/msg/de/sensebox-ble.js +++ b/src/components/Blockly/msg/de/sensebox-ble.js @@ -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", }; diff --git a/src/components/Blockly/msg/en.js b/src/components/Blockly/msg/en.js index 74d7b9c..41eddea 100644 --- a/src/components/Blockly/msg/en.js +++ b/src/components/Blockly/msg/en.js @@ -1,47 +1,49 @@ -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, - ...FAQ, - ...IO, - ...LOGIC, - ...LOOPS, - ...MATH, - ...MQTT, - ...DISPLAY, - ...LED, - ...LORA, - ...OSEM, - ...SD, - ...SENSORS, - ...TELEGRAM, - ...WEB, - ...TEXT, - ...TIME, - ...TOURS, - ...TRANSLATIONS, - ...UI, - ...VARIABLES, - ...WEBSERVER -} + ...AUDIO, + ...BLE, + ...FAQ, + ...IO, + ...LOGIC, + ...LOOPS, + ...MATH, + ...MQTT, + ...DISPLAY, + ...LED, + ...LORA, + ...OSEM, + ...SD, + ...SENSORS, + ...TELEGRAM, + ...WEB, + ...TEXT, + ...TIME, + ...TOURS, + ...TRANSLATIONS, + ...UI, + ...VARIABLES, + ...WEBSERVER, +}; diff --git a/src/components/Blockly/msg/en/sensebox-ble.js b/src/components/Blockly/msg/en/sensebox-ble.js new file mode 100644 index 0000000..32447a7 --- /dev/null +++ b/src/components/Blockly/msg/en/sensebox-ble.js @@ -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", +}; diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 4976ed2..3fa673a 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -349,8 +349,27 @@ class Toolbox extends React.Component { - - + + + + + + + + + + + + + + + + + + + + + Date: Mon, 17 May 2021 15:51:57 +0200 Subject: [PATCH 3/6] add tooltips and en translations --- src/components/Blockly/blocks/sensebox-ble.js | 38 ++++--------- .../Blockly/generator/sensebox-ble.js | 10 +--- src/components/Blockly/msg/de/sensebox-ble.js | 20 ++++++- src/components/Blockly/msg/en/sensebox-ble.js | 55 ++++++++++++------- 4 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/components/Blockly/blocks/sensebox-ble.js b/src/components/Blockly/blocks/sensebox-ble.js index 6cff14b..25ce3cf 100644 --- a/src/components/Blockly/blocks/sensebox-ble.js +++ b/src/components/Blockly/blocks/sensebox-ble.js @@ -10,7 +10,7 @@ Blockly.Blocks["sensebox_phyphox_init"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_init_tooltip); }, }; @@ -26,16 +26,12 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = { 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"), + new Blockly.FieldTextInput( + Blockly.Msg.sensebox_phyphox_experiment_description + ), "description" ); this.appendStatementInput("view").appendField( @@ -43,19 +39,7 @@ Blockly.Blocks["sensebox_phyphox_experiment"] = { ); 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); + this.setTooltip(Blockly.Msg.sensebox_phyphox_experiment_tooltip); }, }; @@ -82,8 +66,8 @@ Blockly.Blocks["sensebox_phyphox_graph"] = { .appendField(Blockly.Msg.sensebox_phyphox_graphStyle) .appendField( new Blockly.FieldDropdown([ - ["dots", "dots"], - ["line", "line"], + [Blockly.Msg.sensebox_phyphox_style_dots, "dots"], + [Blockly.Msg.sensebox_phyphox_style_line, "line"], ]), "style" ); @@ -95,7 +79,7 @@ Blockly.Blocks["sensebox_phyphox_graph"] = { ); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_graph_tooltip); }, }; @@ -125,7 +109,7 @@ Blockly.Blocks["sensebox_phyphox_channel"] = { ); this.setOutput(true); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_timestamp_tooltip); }, }; @@ -147,7 +131,7 @@ Blockly.Blocks["sensebox_phyphox_sendchannel"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_sendchannel_tooltip); }, }; @@ -159,6 +143,6 @@ Blockly.Blocks["sensebox_phyphox_experiment_send"] = { ); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_experiment_send_tooltip); }, }; diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js index 1532ff7..a267c74 100644 --- a/src/components/Blockly/generator/sensebox-ble.js +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -18,7 +18,6 @@ Blockly.Arduino.sensebox_phyphox_experiment = function () { "" ); var title = this.getFieldValue("title").replace(/[^a-zA-Z0-9]/g, ""); - var category = this.getFieldValue("category"); var description = this.getFieldValue("description"); var branch = Blockly.Arduino.statementToCode(this, "view"); Blockly.Arduino.phyphoxSetupCode_[ @@ -28,8 +27,8 @@ Blockly.Arduino.sensebox_phyphox_experiment = function () { `setTitle_${title}` ] = `${experimentname}.setTitle("${title}");`; Blockly.Arduino.phyphoxSetupCode_[ - `setCategory_${category}` - ] = `${experimentname}.setCategory("${category}");`; + `setCategory_senseBoxExperiments}` + ] = `${experimentname}.setCategory("senseBox Experimente");`; Blockly.Arduino.phyphoxSetupCode_[ `setDescription_${description}` ] = `${experimentname}.setDescription("${description}");`; @@ -59,11 +58,6 @@ Blockly.Arduino["sensebox_phyphox_channel"] = function () { 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 = diff --git a/src/components/Blockly/msg/de/sensebox-ble.js b/src/components/Blockly/msg/de/sensebox-ble.js index 32447a7..d1edc54 100644 --- a/src/components/Blockly/msg/de/sensebox-ble.js +++ b/src/components/Blockly/msg/de/sensebox-ble.js @@ -1,13 +1,14 @@ export const BLE = { /** - * Phyphox Init + * Phyphox Blöcke */ - sensebox_phyphox_init: "Phyphox Experiment", + sensebox_phyphox_init: "Initialisiere Phyphox Gerät mit Namen:", 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_experiment_description: "Kurze Beschreibung des Experiments", sensebox_phyphox_writeValues: "Sende Werte", sensebox_phyphox_createView: "Mit Graphen:", sensebox_phyphox_createGraph: "Erstelle Graph", @@ -18,8 +19,23 @@ export const BLE = { sensebox_phyphox_labely: "Beschriftung y-Achse", sensebox_phyphox_channel0: "Wert x-Achse", sensebox_phyphox_channel1: "Wert y-Achse", + sensebox_phyphox_style_dots: "Punkte", + sensebox_phyphox_style_line: "Linie", sensebox_phyphox_timestamp: "Zeitstempel", sensebox_phyphox_channel: "Kanal", sensebox_phyphox_sendchannel: "sende an Kanal:", sensebox_phyphox_graphStyle: "Stil", + + sensebox_phyphox_init_tooltip: + "Initialisere das Bluetooth Bee. Stecke diese auf dem Steckplatz **XBEE1**. Gib dem Phphox Messgerät einen eindeutigen Namen, damit du dieses in der App wiederfindest", + sensebox_phyphox_experiment_tooltip: + "Erstelle ein Experiment und vergib einen eindeutigen Namen und eine kurze Beschreibung. Füge bis zu 5 verschiedene Graphen in der Ansicht hinzu. ", + sensebox_phyphox_graph_tooltip: + "Erstellt einen neuen Graph für das Experiment. Gibt die Einheit und Beschriftung für die Achsen an und wähle den Stil der Visualisuerng der Messwerte. Füge an die Schnittstellen für die Werte der X- und Y-Achse den Kanal an auf dem die Messwerte später gesendet werden. Möchtest du einen Zeitstempel über die Phyphox App erstellen lassen verbinde den Block *Zeitstempel*", + sensebox_phyphox_timestamp_tooltip: + "Verwende diesen Block, um einen Zeitstempel über die Phyphox App erstellen zu lassen", + sensebox_phyphox_sendchannel_tooltip: + "Sendet einen Messwert an den ausgewählten Kanal", + sensebox_phyphox_experiment_send_tooltip: + "Sendet die Messwerte an die Phyphox App", }; diff --git a/src/components/Blockly/msg/en/sensebox-ble.js b/src/components/Blockly/msg/en/sensebox-ble.js index 32447a7..407a53f 100644 --- a/src/components/Blockly/msg/en/sensebox-ble.js +++ b/src/components/Blockly/msg/en/sensebox-ble.js @@ -2,24 +2,41 @@ 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_init: "Initialise Phyphox device with name:", + sensebox_phyphox_createExperiment: "Create experiment", + sensebox_phyphox_experimentName: "Name of experiment", + sensebox_phyphox_experimentTitle: "Title", + sensebox_phyphox_experimentCategory: "Category", + sensebox_phyphox_experimentDescription: "Description", + sensebox_phyphox_experiment_description: + "Short description of the experiment", + sensebox_phyphox_writeValues: "Send values", + sensebox_phyphox_createView: "With graphs:", + sensebox_phyphox_createGraph: "Create 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", + sensebox_phyphox_unitx: "Unit x-axis", + sensebox_phyphox_unity: "Unit y-axis", + sensebox_phyphox_labelx: "Label x-axis", + sensebox_phyphox_labely: "Label y-axis", + sensebox_phyphox_channel0: "x-axis value", + sensebox_phyphox_channel1: "y-axis value", + sensebox_phyphox_style_dots: "Dots", + sensebox_phyphox_style_line: "Line", + sensebox_phyphox_timestamp: "Timestamp", + sensebox_phyphox_channel: "Channel", + sensebox_phyphox_sendchannel: "send to channel:", + sensebox_phyphox_graphStyle: "style", + + sensebox_phyphox_init_tooltip: + "Initialise the Bluetooth Bee. Plug it into the **XBEE1** slot. Give the Phphox meter a unique name so you can find it in the app", + sensebox_phyphox_experiment_tooltip: + "Create an experiment and give it a unique name and a short description. Add up to 5 different graphs in the view. ", + sensebox_phyphox_graph_tooltip: + "Creates a new graph for the experiment. Specify the unit and label for the axes and choose the style of visualisation of the measured values. Add to the interfaces for the values of the X- and Y-axis the channel on which the measured values will be sent later. If you want to create a timestamp via the Phyphox app, connect the block *Timestamp*", + sensebox_phyphox_timestamp_tooltip: + "Use this block to have a timestamp created via the Phyphox app", + sensebox_phyphox_sendchannel_tooltip: + "Sends a reading to the selected channel", + sensebox_phyphox_experiment_send_tooltip: + "Sends the measured values to the Phyphox App", }; From da65e23d3f7ebc8d0bb8079ef17162e2c686a172 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Mon, 17 May 2021 17:03:42 +0200 Subject: [PATCH 4/6] remove experiment field a --- src/components/Blockly/blocks/sensebox-ble.js | 9 +++------ src/components/Blockly/generator/sensebox-ble.js | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/components/Blockly/blocks/sensebox-ble.js b/src/components/Blockly/blocks/sensebox-ble.js index 25ce3cf..bfd03b7 100644 --- a/src/components/Blockly/blocks/sensebox-ble.js +++ b/src/components/Blockly/blocks/sensebox-ble.js @@ -17,12 +17,9 @@ Blockly.Blocks["sensebox_phyphox_init"] = { 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_createExperiment + ); this.appendDummyInput() .appendField(Blockly.Msg.sensebox_phyphox_experimentTitle) .appendField(new Blockly.FieldTextInput("Experiment Title"), "title"); diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js index a267c74..959ca3b 100644 --- a/src/components/Blockly/generator/sensebox-ble.js +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -13,10 +13,7 @@ Blockly.Arduino.sensebox_phyphox_init = function () { }; Blockly.Arduino.sensebox_phyphox_experiment = function () { - var experimentname = this.getFieldValue("exeperimentname").replace( - /\s+/g, - "" - ); + var experimentname = "experiment"; var title = this.getFieldValue("title").replace(/[^a-zA-Z0-9]/g, ""); var description = this.getFieldValue("description"); var branch = Blockly.Arduino.statementToCode(this, "view"); From 59142b4c25bfc84e38ec32df818747fd8074d237 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Mon, 17 May 2021 17:03:53 +0200 Subject: [PATCH 5/6] update randomInt function --- src/components/Blockly/generator/math.js | 517 +++++++++++++---------- 1 file changed, 283 insertions(+), 234 deletions(-) diff --git a/src/components/Blockly/generator/math.js b/src/components/Blockly/generator/math.js index efb02e1..b6312d4 100644 --- a/src/components/Blockly/generator/math.js +++ b/src/components/Blockly/generator/math.js @@ -1,5 +1,4 @@ - -import * as Blockly from 'blockly/core'; +import * as Blockly from "blockly/core"; /** * @license Licensed under the Apache License, Version 2.0 (the "License"): @@ -19,15 +18,15 @@ import * as Blockly from 'blockly/core'; * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_number'] = function (block) { - // Numeric value. - var code = parseFloat(block.getFieldValue('NUM')); - if (code === Infinity) { - code = 'INFINITY'; - } else if (code === -Infinity) { - code = '-INFINITY'; - } - return [code, Blockly.Arduino.ORDER_ATOMIC]; +Blockly.Arduino["math_number"] = function (block) { + // Numeric value. + var code = parseFloat(block.getFieldValue("NUM")); + if (code === Infinity) { + code = "INFINITY"; + } else if (code === -Infinity) { + code = "-INFINITY"; + } + return [code, Blockly.Arduino.ORDER_ATOMIC]; }; /** @@ -37,27 +36,27 @@ Blockly.Arduino['math_number'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_arithmetic'] = function (block) { - var OPERATORS = { - ADD: [' + ', Blockly.Arduino.ORDER_ADDITIVE], - MINUS: [' - ', Blockly.Arduino.ORDER_ADDITIVE], - MULTIPLY: [' * ', Blockly.Arduino.ORDER_MULTIPLICATIVE], - DIVIDE: [' / ', Blockly.Arduino.ORDER_MULTIPLICATIVE], - POWER: [null, Blockly.Arduino.ORDER_NONE] // Handle power separately. - }; - var tuple = OPERATORS[block.getFieldValue('OP')]; - var operator = tuple[0]; - var order = tuple[1]; - var argument0 = Blockly.Arduino.valueToCode(block, 'A', order) || '0'; - var argument1 = Blockly.Arduino.valueToCode(block, 'B', order) || '0'; - var code; - // Power in C++ requires a special case since it has no operator. - if (!operator) { - code = 'Math.pow(' + argument0 + ', ' + argument1 + ')'; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; - } - code = argument0 + operator + argument1; - return [code, order]; +Blockly.Arduino["math_arithmetic"] = function (block) { + var OPERATORS = { + ADD: [" + ", Blockly.Arduino.ORDER_ADDITIVE], + MINUS: [" - ", Blockly.Arduino.ORDER_ADDITIVE], + MULTIPLY: [" * ", Blockly.Arduino.ORDER_MULTIPLICATIVE], + DIVIDE: [" / ", Blockly.Arduino.ORDER_MULTIPLICATIVE], + POWER: [null, Blockly.Arduino.ORDER_NONE], // Handle power separately. + }; + var tuple = OPERATORS[block.getFieldValue("OP")]; + var operator = tuple[0]; + var order = tuple[1]; + var argument0 = Blockly.Arduino.valueToCode(block, "A", order) || "0"; + var argument1 = Blockly.Arduino.valueToCode(block, "B", order) || "0"; + var code; + // Power in C++ requires a special case since it has no operator. + if (!operator) { + code = "Math.pow(" + argument0 + ", " + argument1 + ")"; + return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + } + code = argument0 + operator + argument1; + return [code, order]; }; /** @@ -66,90 +65,103 @@ Blockly.Arduino['math_arithmetic'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_single'] = function (block) { - var operator = block.getFieldValue('OP'); - var code; - var arg; - if (operator === 'NEG') { - // Negation is a special case given its different operator precedents. - arg = Blockly.Arduino.valueToCode(block, 'NUM', - Blockly.Arduino.ORDER_UNARY_PREFIX) || '0'; - if (arg[0] === '-') { - // --3 is not legal in C++ in this context. - arg = ' ' + arg; - } - code = '-' + arg; - return [code, Blockly.Arduino.ORDER_UNARY_PREFIX]; +Blockly.Arduino["math_single"] = function (block) { + var operator = block.getFieldValue("OP"); + var code; + var arg; + if (operator === "NEG") { + // Negation is a special case given its different operator precedents. + arg = + Blockly.Arduino.valueToCode( + block, + "NUM", + Blockly.Arduino.ORDER_UNARY_PREFIX + ) || "0"; + if (arg[0] === "-") { + // --3 is not legal in C++ in this context. + arg = " " + arg; } - if (operator === 'ABS' || operator.substring(0, 5) === 'ROUND') { - arg = Blockly.Arduino.valueToCode(block, 'NUM', - Blockly.Arduino.ORDER_UNARY_POSTFIX) || '0'; - } else if (operator === 'SIN' || operator === 'COS' || operator === 'TAN') { - arg = Blockly.Arduino.valueToCode(block, 'NUM', - Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0'; - } else { - arg = Blockly.Arduino.valueToCode(block, 'NUM', - Blockly.Arduino.ORDER_NONE) || '0'; - } - // First, handle cases which generate values that don't need parentheses. - switch (operator) { - case 'ABS': - code = 'abs(' + arg + ')'; - break; - case 'ROOT': - code = 'sqrt(' + arg + ')'; - break; - case 'LN': - code = 'log(' + arg + ')'; - break; - case 'EXP': - code = 'exp(' + arg + ')'; - break; - case 'POW10': - code = 'pow(10,' + arg + ')'; - break; - case 'ROUND': - code = 'round(' + arg + ')'; - break; - case 'ROUNDUP': - code = 'ceil(' + arg + ')'; - break; - case 'ROUNDDOWN': - code = 'floor(' + arg + ')'; - break; - case 'SIN': - code = 'sin(' + arg + ' / 180 * Math.PI)'; - break; - case 'COS': - code = 'cos(' + arg + ' / 180 * Math.PI)'; - break; - case 'TAN': - code = 'tan(' + arg + ' / 180 * Math.PI)'; - break; - default: - break; - } - if (code) { - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; - } - // Second, handle cases which generate values that may need parentheses. - switch (operator) { - case 'LOG10': - code = 'log(' + arg + ') / log(10)'; - break; - case 'ASIN': - code = 'asin(' + arg + ') / M_PI * 180'; - break; - case 'ACOS': - code = 'acos(' + arg + ') / M_PI * 180'; - break; - case 'ATAN': - code = 'atan(' + arg + ') / M_PI * 180'; - break; - default: - throw new Error('Unknown math operator: ' + operator); - } - return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; + code = "-" + arg; + return [code, Blockly.Arduino.ORDER_UNARY_PREFIX]; + } + if (operator === "ABS" || operator.substring(0, 5) === "ROUND") { + arg = + Blockly.Arduino.valueToCode( + block, + "NUM", + Blockly.Arduino.ORDER_UNARY_POSTFIX + ) || "0"; + } else if (operator === "SIN" || operator === "COS" || operator === "TAN") { + arg = + Blockly.Arduino.valueToCode( + block, + "NUM", + Blockly.Arduino.ORDER_MULTIPLICATIVE + ) || "0"; + } else { + arg = + Blockly.Arduino.valueToCode(block, "NUM", Blockly.Arduino.ORDER_NONE) || + "0"; + } + // First, handle cases which generate values that don't need parentheses. + switch (operator) { + case "ABS": + code = "abs(" + arg + ")"; + break; + case "ROOT": + code = "sqrt(" + arg + ")"; + break; + case "LN": + code = "log(" + arg + ")"; + break; + case "EXP": + code = "exp(" + arg + ")"; + break; + case "POW10": + code = "pow(10," + arg + ")"; + break; + case "ROUND": + code = "round(" + arg + ")"; + break; + case "ROUNDUP": + code = "ceil(" + arg + ")"; + break; + case "ROUNDDOWN": + code = "floor(" + arg + ")"; + break; + case "SIN": + code = "sin(" + arg + " / 180 * Math.PI)"; + break; + case "COS": + code = "cos(" + arg + " / 180 * Math.PI)"; + break; + case "TAN": + code = "tan(" + arg + " / 180 * Math.PI)"; + break; + default: + break; + } + if (code) { + return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + } + // Second, handle cases which generate values that may need parentheses. + switch (operator) { + case "LOG10": + code = "log(" + arg + ") / log(10)"; + break; + case "ASIN": + code = "asin(" + arg + ") / M_PI * 180"; + break; + case "ACOS": + code = "acos(" + arg + ") / M_PI * 180"; + break; + case "ATAN": + code = "atan(" + arg + ") / M_PI * 180"; + break; + default: + throw new Error("Unknown math operator: " + operator); + } + return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; }; /** @@ -161,16 +173,16 @@ Blockly.Arduino['math_single'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino['math_constant'] = function (block) { - var CONSTANTS = { - 'PI': ['M_PI', Blockly.Arduino.ORDER_UNARY_POSTFIX], - 'E': ['M_E', Blockly.Arduino.ORDER_UNARY_POSTFIX], - 'GOLDEN_RATIO': ['(1 + sqrt(5)) / 2', Blockly.Arduino.ORDER_MULTIPLICATIVE], - 'SQRT2': ['M_SQRT2', Blockly.Arduino.ORDER_UNARY_POSTFIX], - 'SQRT1_2': ['M_SQRT1_2', Blockly.Arduino.ORDER_UNARY_POSTFIX], - 'INFINITY': ['INFINITY', Blockly.Arduino.ORDER_ATOMIC] - }; - return CONSTANTS[block.getFieldValue('CONSTANT')]; +Blockly.Arduino["math_constant"] = function (block) { + var CONSTANTS = { + PI: ["M_PI", Blockly.Arduino.ORDER_UNARY_POSTFIX], + E: ["M_E", Blockly.Arduino.ORDER_UNARY_POSTFIX], + GOLDEN_RATIO: ["(1 + sqrt(5)) / 2", Blockly.Arduino.ORDER_MULTIPLICATIVE], + SQRT2: ["M_SQRT2", Blockly.Arduino.ORDER_UNARY_POSTFIX], + SQRT1_2: ["M_SQRT1_2", Blockly.Arduino.ORDER_UNARY_POSTFIX], + INFINITY: ["INFINITY", Blockly.Arduino.ORDER_ATOMIC], + }; + return CONSTANTS[block.getFieldValue("CONSTANT")]; }; /** @@ -180,63 +192,72 @@ Blockly.Arduino['math_constant'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_number_property'] = function (block) { - var number_to_check = Blockly.Arduino.valueToCode(block, 'NUMBER_TO_CHECK', - Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0'; - var dropdown_property = block.getFieldValue('PROPERTY'); - var code; - if (dropdown_property === 'PRIME') { - var func = [ - 'boolean ' + Blockly.Arduino.DEF_FUNC_NAME + '(int n) {', - ' // https://en.wikipedia.org/wiki/Primality_test#Naive_methods', - ' if (n == 2 || n == 3) {', - ' return true;', - ' }', - ' // False if n is NaN, negative, is 1.', - ' // And false if n is divisible by 2 or 3.', - ' if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || ' + - '(n % 3 == 0)) {', - ' return false;', - ' }', - ' // Check all the numbers of form 6k +/- 1, up to sqrt(n).', - ' for (int x = 6; x <= sqrt(n) + 1; x += 6) {', - ' if (n % (x - 1) == 0 || n % (x + 1) == 0) {', - ' return false;', - ' }', - ' }', - ' return true;', - '}']; - var funcName = Blockly.Arduino.addFunction('mathIsPrime', func.join('\n')); - Blockly.Arduino.addInclude('math', '#include '); - code = funcName + '(' + number_to_check + ')'; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; - } - switch (dropdown_property) { - case 'EVEN': - code = number_to_check + ' % 2 == 0'; - break; - case 'ODD': - code = number_to_check + ' % 2 == 1'; - break; - case 'WHOLE': - Blockly.Arduino.addInclude('math', '#include '); - code = '(floor(' + number_to_check + ') == ' + number_to_check + ')'; - break; - case 'POSITIVE': - code = number_to_check + ' > 0'; - break; - case 'NEGATIVE': - code = number_to_check + ' < 0'; - break; - case 'DIVISIBLE_BY': - var divisor = Blockly.Arduino.valueToCode(block, 'DIVISOR', - Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0'; - code = number_to_check + ' % ' + divisor + ' == 0'; - break; - default: - break; - } - return [code, Blockly.Arduino.ORDER_EQUALITY]; +Blockly.Arduino["math_number_property"] = function (block) { + var number_to_check = + Blockly.Arduino.valueToCode( + block, + "NUMBER_TO_CHECK", + Blockly.Arduino.ORDER_MULTIPLICATIVE + ) || "0"; + var dropdown_property = block.getFieldValue("PROPERTY"); + var code; + if (dropdown_property === "PRIME") { + var func = [ + "boolean " + Blockly.Arduino.DEF_FUNC_NAME + "(int n) {", + " // https://en.wikipedia.org/wiki/Primality_test#Naive_methods", + " if (n == 2 || n == 3) {", + " return true;", + " }", + " // False if n is NaN, negative, is 1.", + " // And false if n is divisible by 2 or 3.", + " if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || " + + "(n % 3 == 0)) {", + " return false;", + " }", + " // Check all the numbers of form 6k +/- 1, up to sqrt(n).", + " for (int x = 6; x <= sqrt(n) + 1; x += 6) {", + " if (n % (x - 1) == 0 || n % (x + 1) == 0) {", + " return false;", + " }", + " }", + " return true;", + "}", + ]; + var funcName = Blockly.Arduino.addFunction("mathIsPrime", func.join("\n")); + Blockly.Arduino.addInclude("math", "#include "); + code = funcName + "(" + number_to_check + ")"; + return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + } + switch (dropdown_property) { + case "EVEN": + code = number_to_check + " % 2 == 0"; + break; + case "ODD": + code = number_to_check + " % 2 == 1"; + break; + case "WHOLE": + Blockly.Arduino.addInclude("math", "#include "); + code = "(floor(" + number_to_check + ") == " + number_to_check + ")"; + break; + case "POSITIVE": + code = number_to_check + " > 0"; + break; + case "NEGATIVE": + code = number_to_check + " < 0"; + break; + case "DIVISIBLE_BY": + var divisor = + Blockly.Arduino.valueToCode( + block, + "DIVISOR", + Blockly.Arduino.ORDER_MULTIPLICATIVE + ) || "0"; + code = number_to_check + " % " + divisor + " == 0"; + break; + default: + break; + } + return [code, Blockly.Arduino.ORDER_EQUALITY]; }; /** @@ -247,19 +268,25 @@ Blockly.Arduino['math_number_property'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_change'] = function (block) { - var argument0 = Blockly.Arduino.valueToCode(block, 'DELTA', - Blockly.Arduino.ORDER_ADDITIVE) || '0'; - var varName = Blockly.Arduino.variableDB_.getName( - block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); - return varName + ' += ' + argument0 + ';\n'; +Blockly.Arduino["math_change"] = function (block) { + var argument0 = + Blockly.Arduino.valueToCode( + block, + "DELTA", + Blockly.Arduino.ORDER_ADDITIVE + ) || "0"; + var varName = Blockly.Arduino.variableDB_.getName( + block.getFieldValue("VAR"), + Blockly.Variables.NAME_TYPE + ); + return varName + " += " + argument0 + ";\n"; }; /** Rounding functions have a single operand. */ -Blockly.Arduino['math_round'] = Blockly.Arduino['math_single']; +Blockly.Arduino["math_round"] = Blockly.Arduino["math_single"]; /** Trigonometry functions have a single operand. */ -Blockly.Arduino['math_trig'] = Blockly.Arduino['math_single']; +Blockly.Arduino["math_trig"] = Blockly.Arduino["math_single"]; /** * Generator for the math function to a list. @@ -268,7 +295,7 @@ Blockly.Arduino['math_trig'] = Blockly.Arduino['math_single']; * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_on_list'] = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino["math_on_list"] = Blockly.Arduino.noGeneratorCodeInline; /** * Generator for the math modulo function (calculates remainder of X/Y). @@ -276,13 +303,21 @@ Blockly.Arduino['math_on_list'] = Blockly.Arduino.noGeneratorCodeInline; * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_modulo'] = function (block) { - var argument0 = Blockly.Arduino.valueToCode(block, 'DIVIDEND', - Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0'; - var argument1 = Blockly.Arduino.valueToCode(block, 'DIVISOR', - Blockly.Arduino.ORDER_MULTIPLICATIVE) || '0'; - var code = argument0 + ' % ' + argument1; - return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; +Blockly.Arduino["math_modulo"] = function (block) { + var argument0 = + Blockly.Arduino.valueToCode( + block, + "DIVIDEND", + Blockly.Arduino.ORDER_MULTIPLICATIVE + ) || "0"; + var argument1 = + Blockly.Arduino.valueToCode( + block, + "DIVISOR", + Blockly.Arduino.ORDER_MULTIPLICATIVE + ) || "0"; + var code = argument0 + " % " + argument1; + return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; }; /** @@ -291,18 +326,34 @@ Blockly.Arduino['math_modulo'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_constrain'] = function (block) { - // Constrain a number between two limits. - var argument0 = Blockly.Arduino.valueToCode(block, 'VALUE', - Blockly.Arduino.ORDER_NONE) || '0'; - var argument1 = Blockly.Arduino.valueToCode(block, 'LOW', - Blockly.Arduino.ORDER_NONE) || '0'; - var argument2 = Blockly.Arduino.valueToCode(block, 'HIGH', - Blockly.Arduino.ORDER_NONE) || '0'; - var code = '(' + argument0 + ' < ' + argument1 + ' ? ' + argument1 + - ' : ( ' + argument0 + ' > ' + argument2 + ' ? ' + argument2 + ' : ' + - argument0 + '))'; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; +Blockly.Arduino["math_constrain"] = function (block) { + // Constrain a number between two limits. + var argument0 = + Blockly.Arduino.valueToCode(block, "VALUE", Blockly.Arduino.ORDER_NONE) || + "0"; + var argument1 = + Blockly.Arduino.valueToCode(block, "LOW", Blockly.Arduino.ORDER_NONE) || + "0"; + var argument2 = + Blockly.Arduino.valueToCode(block, "HIGH", Blockly.Arduino.ORDER_NONE) || + "0"; + var code = + "(" + + argument0 + + " < " + + argument1 + + " ? " + + argument1 + + " : ( " + + argument0 + + " > " + + argument2 + + " ? " + + argument2 + + " : " + + argument0 + + "))"; + return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; }; /** @@ -312,28 +363,26 @@ Blockly.Arduino['math_constrain'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino['math_random_int'] = function (block) { - var argument0 = Blockly.Arduino.valueToCode(block, 'FROM', - Blockly.Arduino.ORDER_NONE) || '0'; - var argument1 = Blockly.Arduino.valueToCode(block, 'TO', - Blockly.Arduino.ORDER_NONE) || '0'; - var functionName = Blockly.Arduino.variableDB_.getDistinctName( - 'math_random_int', Blockly.Generator.NAME_TYPE); - Blockly.Arduino.setups_['init_rand'] = 'randomSeed(analogRead(0));'; - Blockly.Arduino.math_random_int.random_function = functionName; - var func = [ - 'int ' + Blockly.Arduino.DEF_FUNC_NAME + '(int min, int max) {', - ' if (min > max) {', - ' // Swap min and max to ensure min is smaller.', - ' int temp = min;', - ' min = max;', - ' max = temp;', - ' }', - ' return min + (rand() % (max - min + 1));', - '}']; - var funcName = Blockly.Arduino.addFunction('mathRandomInt', func.join('\n')); - var code = funcName + '(' + argument0 + ', ' + argument1 + ')'; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; +Blockly.Arduino["math_random_int"] = function (block) { + var argument0 = + Blockly.Arduino.valueToCode(block, "FROM", Blockly.Arduino.ORDER_NONE) || + "0"; + var argument1 = + Blockly.Arduino.valueToCode(block, "TO", Blockly.Arduino.ORDER_NONE) || "0"; + Blockly.Arduino.setupCode_["init_rand"] = "randomSeed(analogRead(0));"; + Blockly.Arduino.functionNames_[ + "math_random_int" + ] = `int mathRandomInt (int min, int max) {\n + if (min > max) { + int temp = min; + min = max; + max = temp; + } + return min + (rand() % (max - min + 1)); + } + `; + var code = `mathRandomInt(${argument0},${argument1});`; + return [code, Blockly.Arduino.ORDER_ATOMIC]; }; /** @@ -342,6 +391,6 @@ Blockly.Arduino['math_random_int'] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino['math_random_float'] = function (block) { - return ['(rand() / RAND_MAX)', Blockly.Arduino.ORDER_UNARY_POSTFIX]; +Blockly.Arduino["math_random_float"] = function (block) { + return ["(rand() / RAND_MAX)", Blockly.Arduino.ORDER_UNARY_POSTFIX]; }; From 283da13455389631f2c2246b5986959680cf803b Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Tue, 18 May 2021 13:46:35 +0200 Subject: [PATCH 6/6] update tooltip --- src/components/Blockly/blocks/sensebox-ble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Blockly/blocks/sensebox-ble.js b/src/components/Blockly/blocks/sensebox-ble.js index bfd03b7..1ee29db 100644 --- a/src/components/Blockly/blocks/sensebox-ble.js +++ b/src/components/Blockly/blocks/sensebox-ble.js @@ -85,7 +85,7 @@ Blockly.Blocks["sensebox_phyphox_timestamp"] = { this.setColour(getColour().phyphox); this.appendDummyInput().appendField(Blockly.Msg.sensebox_phyphox_timestamp); this.setOutput(true); - this.setTooltip(Blockly.Msg.senseBox_led_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_timestamp_tooltip); }, }; @@ -106,7 +106,7 @@ Blockly.Blocks["sensebox_phyphox_channel"] = { ); this.setOutput(true); - this.setTooltip(Blockly.Msg.sensebox_phyphox_timestamp_tooltip); + this.setTooltip(Blockly.Msg.sensebox_phyphox_channel_tooltip); }, };