From c6b9602095d39567fb45a20ac8f188b1abe7f901 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Thu, 10 Oct 2024 15:41:29 +0200 Subject: [PATCH 01/39] provide board information to connect app --- src/components/Workspace/Compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Workspace/Compile.js b/src/components/Workspace/Compile.js index ea15a00e..ba7eb718 100644 --- a/src/components/Workspace/Compile.js +++ b/src/components/Workspace/Compile.js @@ -136,7 +136,7 @@ class Compile extends Component { this.state.name ); this.setState({ - link: `blocklyconnect-app://sketch/${filename}/${this.state.id}`, + link: `blocklyconnect-app://sketch/${filename}/${this.state.id}/${this.props.selectedBoard}`, }); this.setState({ appDialog: true }); } else { From 21ab2f7c376a9c60650825d0d6e06bf08f11ca0c Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Mon, 28 Oct 2024 14:07:15 +0100 Subject: [PATCH 02/39] exclude OTA on MCU-S2 --- src/components/Blockly/generator/generator.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index 599f022a..cb3cfc67 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -31,10 +31,16 @@ import store from "../../../store"; var ota = store.getState().general.platform ? store.getState().general.platform : null; +var board = store.getState().board.board + ? store.getState().board.board + : null; store.subscribe(() => { ota = store.getState().general.platform ? store.getState().general.platform : null; + board = store.getState().board.board + ? store.getState().board.board + : null; }); /** @@ -218,7 +224,7 @@ Blockly["Arduino"].finish = function (code) { let loopCode = "\nvoid loop() { \n" + loopCodeOnce + code + "\n}\n"; // only add OTA code if tablet mode is enabled - if (ota === true) { + if (ota === true && board !== "esp32") { code = devVariables + "\n" + From 56662d2418070d249bd42afe21fe9c09499df04e Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Wed, 13 Nov 2024 12:56:53 +0100 Subject: [PATCH 03/39] change to testing compiler --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 044e0614..5fcd76bb 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -REACT_APP_COMPILER_URL=https://compiler.sensebox.de +REACT_APP_COMPILER_URL=https://compile.sensebox.de REACT_APP_BOARD=sensebox-mcu REACT_APP_BLOCKLY_API=https://api.blockly.sensebox.de From 10da3e1c34eb4a66fda104ae8298146181b9e745 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Thu, 14 Nov 2024 14:58:05 +0100 Subject: [PATCH 04/39] change I2C address of VL53L8CX first --- src/components/Blockly/generator/generator.js | 8 +++-- .../Blockly/generator/sensebox-sensors.js | 34 ++++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index ea8fc50b..43621de4 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -194,15 +194,17 @@ Blockly["Arduino"].finish = function (code) { } for (const key in Blockly["Arduino"].setupCode_) { - preSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || ""; + if(key=="Wire.begin") { // Wire needs to be initialized first + preSetupCode = (Blockly["Arduino"].setupCode_[key] + "\n" || "") + preSetupCode; + } else { + preSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || ""; + } } for (const key in Blockly["Arduino"].loraSetupCode_) { loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || ""; } - setupCode = - "\nvoid setup() { \n" + preSetupCode + "\n" + loraSetupCode + "\n}\n"; for (const key in Blockly["Arduino"].phyphoxSetupCode_) { phyphoxSetupCode += Blockly["Arduino"].phyphoxSetupCode_[key] + "\n" || ""; } diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 9844bbda..af18c0df 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -57,11 +57,12 @@ void write_reg(byte address, uint8_t reg, uint8_t val) Wire.write(val); Wire.endTransmission(); }`; - + if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { + Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; + } Blockly.Arduino.codeFunctions_["Lightsensor_begin"] = ` void Lightsensor_begin() { - Wire.begin(); unsigned int u = 0; u = read_reg(0x29, 0x80 | 0x0A); //id register if ((u & 0xF0) == 0xA0) // TSL45315 @@ -262,7 +263,9 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { delay(100); }`; //Setup Code - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();"; + if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { + Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; + } Blockly.Arduino.setupCode_["iaqSensor.begin"] = "iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);"; Blockly.Arduino.setupCode_["checkIaqSensorStatus"] = @@ -365,11 +368,18 @@ Blockly.Arduino.sensebox_tof_imager = function () { Blockly.Arduino.libraries_[`library_vl53l8cx`] = `#include `; Blockly.Arduino.variables_["define:_vl53l8cx"] = ` -VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); -`; + VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); + `; + + if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { + Blockly.Arduino.setupCode_["Wire.begin"] = `Wire.begin(); + Wire.setClock(1000000); // VL53L8CX (ToF) has max I2C freq of 1MHz + sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor\n`; + } else { + Blockly.Arduino.setupCode_["Wire.begin"] += `Wire.setClock(1000000); //Sensor has max I2C freq of 1MHz + sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor\n`; + } Blockly.Arduino.setupCode_["setup_vl53l8cx"] = ` - Wire.begin(); - Wire.setClock(1000000); //Sensor has max I2C freq of 1MHz sensor_vl53l8cx.begin(); sensor_vl53l8cx.init(); sensor_vl53l8cx.set_ranging_frequency_hz(30); @@ -597,7 +607,10 @@ Blockly.Arduino.sensebox_scd30 = function () { Blockly.Arduino.libraries_["scd30_library"] = "#include // http://librarymanager/All#SparkFun_SCD30_Arduino_Library"; Blockly.Arduino.definitions_["SCD30"] = "SCD30 airSensor;"; - Blockly.Arduino.setupCode_["init_scd30"] = ` Wire.begin(); + if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { + Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; + } + Blockly.Arduino.setupCode_["init_scd30"] = ` if (airSensor.begin() == false) { while (1) @@ -633,7 +646,10 @@ Blockly.Arduino.sensebox_gps = function () { "#include // http://librarymanager/All#SparkFun_u-blox_GNSS_Arduino_Library"; Blockly.Arduino.libraries_["library_wire"] = "#include "; Blockly.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;"; - Blockly.Arduino.setupCode_["init_gps"] = ` Wire.begin(); + if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { + Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; + } + Blockly.Arduino.setupCode_["init_gps"] = ` if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port { From 0f0467c50d56f33003acb1907da5aa36be69c129 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Wed, 20 Nov 2024 09:32:37 +0100 Subject: [PATCH 05/39] if and test --- src/components/Blockly/msg/de/translations.js | 2 +- src/components/Blockly/toolbox/Toolbox.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/Blockly/msg/de/translations.js b/src/components/Blockly/msg/de/translations.js index 2e569d58..0ec10d01 100644 --- a/src/components/Blockly/msg/de/translations.js +++ b/src/components/Blockly/msg/de/translations.js @@ -204,7 +204,7 @@ export const TRANSLATIONS = { VARIABLES_SET_TOOLTIP: "Setzt den Wert einer Variable.", MATH_CHANGE_TITLE_ITEM: "Element", PROCEDURES_DEFRETURN_TITLE: "zu", - CONTROLS_IF_IF_TITLE_IF: "if", + CONTROLS_IF_IF_TITLE_IF: "wenn", CONTROLS_WHILEUNTIL_INPUT_DO: "mache", CONTROLS_IF_MSG_THEN: "mache", CONTROLS_IF_ELSE_TITLE_ELSE: "sonst", diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 1e619c43..f0f8afc0 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -31,6 +31,13 @@ class Toolbox extends React.Component { console.log(this.props.selectedBoard); this.setState({ board: this.props.selectedBoard }); } + + //test + if (props.language !== this.props.language) { + console.log("change language"); + console.log(this.props.language); + this.setState({ board: this.props.language }); + } this.props.workspace.updateToolbox(this.props.toolbox.current); } @@ -72,6 +79,7 @@ class Toolbox extends React.Component { } const mapStateToProps = (state) => ({ + language: state.general.language, selectedBoard: state.board.board, }); From 6f27ccc1b5693348d0e59c13aa42f8da6a7ec359 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Wed, 20 Nov 2024 12:45:36 +0100 Subject: [PATCH 06/39] fix language --- src/components/Blockly/msg/de/ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 28edd324..e105ef6a 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -338,7 +338,7 @@ export const UI = { suggestion_pre_text: "Versuch es mal mit: ", display_not_declared: - "Stelle sicher, dasss du das Display im Setup initialisiert hast.", + "Stelle sicher, dass du das Display im Setup initialisiert hast.", /** * Code Editor * */ From 6435318474cef971dcbbc345c8eaef3fefcdcab5 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Wed, 20 Nov 2024 12:50:33 +0100 Subject: [PATCH 07/39] only necessary change to fix toolbox language error --- src/components/Blockly/toolbox/Toolbox.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index f0f8afc0..4da7b2d4 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -31,13 +31,6 @@ class Toolbox extends React.Component { console.log(this.props.selectedBoard); this.setState({ board: this.props.selectedBoard }); } - - //test - if (props.language !== this.props.language) { - console.log("change language"); - console.log(this.props.language); - this.setState({ board: this.props.language }); - } this.props.workspace.updateToolbox(this.props.toolbox.current); } From d9367149d2bb30567437573ec58c41e7c22400a9 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Wed, 20 Nov 2024 13:14:39 +0100 Subject: [PATCH 08/39] added automatic change from decimal comma to dot and visualize numer parsing --- src/components/Blockly/generator/math.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/Blockly/generator/math.js b/src/components/Blockly/generator/math.js index 768acca6..dc8f26de 100644 --- a/src/components/Blockly/generator/math.js +++ b/src/components/Blockly/generator/math.js @@ -20,7 +20,14 @@ import * as Blockly from "blockly/core"; */ Blockly.Arduino["math_number"] = function (block) { // Numeric value. - var code = parseFloat(block.getFieldValue("NUM")); + var unparsedCode = block.getFieldValue("NUM"); + // understand decimal comma for german users + if (unparsedCode.includes(",")) { + // maybe add notification for educational purpose here + unparsedCode = unparsedCode.replace(",", "."); + } + var code = parseFloat(unparsedCode); + block.setFieldValue(code, "NUM"); if (code === Infinity) { code = "INFINITY"; } else if (code === -Infinity) { From 2e60d5e541210da04d48de870f9eecbd746fbd68 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:14:21 +0000 Subject: [PATCH 09/39] Bump cross-spawn from 7.0.3 to 7.0.6 Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6. - [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md) - [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v7.0.3...v7.0.6) --- updated-dependencies: - dependency-name: cross-spawn dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8beffbfa..1014f656 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6994,9 +6994,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", From 226f0f4059618d7a5ba573b9852736efaa38cd05 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Fri, 22 Nov 2024 13:16:56 +0100 Subject: [PATCH 10/39] preSetupCode --- src/components/Blockly/generator/generator.js | 19 +++++++++---- .../Blockly/generator/sensebox-sensors.js | 28 ++++++------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index 43621de4..917e3919 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -106,6 +106,9 @@ Blockly["Arduino"].init = function (workspace) { Blockly["Arduino"].definitions_ = Object.create(null); + // creates a list of code to be setup before the setup block + Blockly["Arduino"].preSetupCode_ = Object.create(null); + // creates a list of code to be setup before the setup block Blockly["Arduino"].setupCode_ = Object.create(null); @@ -165,6 +168,7 @@ Blockly["Arduino"].finish = function (code) { let loopCodeOnce = ""; let setupCode = ""; let preSetupCode = ""; + let mainSetupCode = ""; let loraSetupCode = ""; let devVariables = "\n"; @@ -193,14 +197,17 @@ Blockly["Arduino"].finish = function (code) { functionsCode += Blockly["Arduino"].functionNames_[key] + "\n"; } - for (const key in Blockly["Arduino"].setupCode_) { - if(key=="Wire.begin") { // Wire needs to be initialized first - preSetupCode = (Blockly["Arduino"].setupCode_[key] + "\n" || "") + preSetupCode; - } else { - preSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || ""; + if(Blockly["Arduino"].preSetupCode_["Wire.begin"]) { + preSetupCode += Blockly["Arduino"].preSetupCode_["Wire.begin"] + "\n"; + if(Blockly["Arduino"].preSetupCode_["vl53l8cx_clock_address"]) { + preSetupCode += Blockly["Arduino"].preSetupCode_["vl53l8cx_clock_address"] + "\n"; } } + for (const key in Blockly["Arduino"].setupCode_) { + mainSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || ""; + } + for (const key in Blockly["Arduino"].loraSetupCode_) { loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || ""; } @@ -213,6 +220,8 @@ Blockly["Arduino"].finish = function (code) { "\nvoid setup() { \n" + preSetupCode + "\n" + + mainSetupCode + + "\n" + phyphoxSetupCode + "\n" + loraSetupCode + diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index af18c0df..268cf232 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -57,9 +57,7 @@ void write_reg(byte address, uint8_t reg, uint8_t val) Wire.write(val); Wire.endTransmission(); }`; - if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; - } + Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; Blockly.Arduino.codeFunctions_["Lightsensor_begin"] = ` void Lightsensor_begin() { @@ -263,9 +261,7 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { delay(100); }`; //Setup Code - if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; - } + Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; Blockly.Arduino.setupCode_["iaqSensor.begin"] = "iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);"; Blockly.Arduino.setupCode_["checkIaqSensorStatus"] = @@ -371,14 +367,10 @@ Blockly.Arduino.sensebox_tof_imager = function () { VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); `; - if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { - Blockly.Arduino.setupCode_["Wire.begin"] = `Wire.begin(); - Wire.setClock(1000000); // VL53L8CX (ToF) has max I2C freq of 1MHz - sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor\n`; - } else { - Blockly.Arduino.setupCode_["Wire.begin"] += `Wire.setClock(1000000); //Sensor has max I2C freq of 1MHz - sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor\n`; - } + Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; + Blockly.Arduino.preSetupCode_["vl53l8cx_clock_address"] = `Wire.setClock(1000000); // VL53L8CX (ToF) has max I2C freq of 1MHz + sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor`; + Blockly.Arduino.setupCode_["setup_vl53l8cx"] = ` sensor_vl53l8cx.begin(); sensor_vl53l8cx.init(); @@ -607,9 +599,7 @@ Blockly.Arduino.sensebox_scd30 = function () { Blockly.Arduino.libraries_["scd30_library"] = "#include // http://librarymanager/All#SparkFun_SCD30_Arduino_Library"; Blockly.Arduino.definitions_["SCD30"] = "SCD30 airSensor;"; - if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; - } + Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; Blockly.Arduino.setupCode_["init_scd30"] = ` if (airSensor.begin() == false) { @@ -646,9 +636,7 @@ Blockly.Arduino.sensebox_gps = function () { "#include // http://librarymanager/All#SparkFun_u-blox_GNSS_Arduino_Library"; Blockly.Arduino.libraries_["library_wire"] = "#include "; Blockly.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;"; - if (Blockly.Arduino.setupCode_["Wire.begin"] == undefined) { - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();\n"; - } + Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; Blockly.Arduino.setupCode_["init_gps"] = ` if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port From 1f260a87b532df0bb1961d736a2f2464af4b1b1b Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Mon, 25 Nov 2024 14:24:59 +0100 Subject: [PATCH 11/39] dont give negative distances --- src/components/Blockly/generator/sensebox-sensors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 268cf232..44f91a29 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -401,7 +401,7 @@ Blockly.Arduino.sensebox_tof_imager = function () { } } } - oldVl53l8cxMin = (min==10000.0) ? 0.0 : min; + oldVl53l8cxMin = (min==10000.0 || min < 0.0) ? 0.0 : min; } return oldVl53l8cxMin; }`; From 28a328b75e45c99629315be8bfbd17072a9a9420 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Mon, 25 Nov 2024 12:37:04 +0000 Subject: [PATCH 12/39] feat: initial blockly update --- package-lock.json | 360 +++++---- package.json | 18 +- src/App.js | 5 +- src/actions/workspaceActions.js | 2 +- src/components/Blockly/BlocklyComponent.jsx | 16 +- src/components/Blockly/BlocklySvg.js | 2 +- src/components/Blockly/BlocklyWindow.js | 6 +- src/components/Blockly/blocks/audio.js | 8 +- src/components/Blockly/blocks/io.js | 26 +- src/components/Blockly/blocks/lists.js | 4 +- src/components/Blockly/blocks/logic.js | 18 +- src/components/Blockly/blocks/loops.js | 4 +- src/components/Blockly/blocks/mqtt.js | 8 +- src/components/Blockly/blocks/procedures.js | 28 +- .../Blockly/blocks/sensebox-esp-now.js | 4 +- src/components/Blockly/blocks/sensebox-led.js | 8 +- .../Blockly/blocks/sensebox-lora.js | 36 +- .../Blockly/blocks/sensebox-motors.js | 12 +- .../Blockly/blocks/sensebox-osem.js | 18 +- src/components/Blockly/blocks/sensebox-sd.js | 18 +- .../Blockly/blocks/sensebox-sensors.js | 40 +- .../Blockly/blocks/sensebox-telegram.js | 6 +- src/components/Blockly/blocks/sensebox-web.js | 20 +- src/components/Blockly/blocks/text.js | 2 +- src/components/Blockly/blocks/time.js | 8 +- src/components/Blockly/blocks/variables.js | 2 +- src/components/Blockly/blocks/watchdog.js | 2 +- src/components/Blockly/blocks/webserver.js | 24 +- src/components/Blockly/generator/audio.js | 12 +- src/components/Blockly/generator/generator.js | 164 ++-- src/components/Blockly/generator/io.js | 96 ++- src/components/Blockly/generator/lists.js | 25 +- src/components/Blockly/generator/logic.js | 95 ++- src/components/Blockly/generator/loops.js | 57 +- src/components/Blockly/generator/map.js | 39 +- src/components/Blockly/generator/math.js | 203 +++-- src/components/Blockly/generator/mqtt.js | 59 +- .../Blockly/generator/procedures.js | 71 +- .../Blockly/generator/sensebox-ble.js | 142 ++-- .../Blockly/generator/sensebox-display.js | 425 ++++++----- .../Blockly/generator/sensebox-esp-now.js | 51 +- .../Blockly/generator/sensebox-esp-wifi.js | 67 +- .../Blockly/generator/sensebox-led.js | 223 ++++-- .../Blockly/generator/sensebox-lora.js | 300 +++++--- .../Blockly/generator/sensebox-motors.js | 139 ++-- .../Blockly/generator/sensebox-ntp.js | 23 +- .../Blockly/generator/sensebox-osem.js | 329 ++++---- .../Blockly/generator/sensebox-rtc.js | 135 ++-- .../Blockly/generator/sensebox-sd.js | 182 +++-- .../Blockly/generator/sensebox-sensors.js | 722 +++++++++--------- .../Blockly/generator/sensebox-telegram.js | 55 +- .../Blockly/generator/sensebox-web.js | 140 ++-- src/components/Blockly/generator/sensebox.js | 33 +- src/components/Blockly/generator/serial.js | 16 +- src/components/Blockly/generator/text.js | 42 +- src/components/Blockly/generator/time.js | 56 +- src/components/Blockly/generator/variables.js | 31 +- src/components/Blockly/generator/watchdog.js | 9 +- src/components/Blockly/generator/webserver.js | 163 ++-- src/components/CodeEditor/CodeEditor.js | 2 +- src/components/CodeEditor/Sidebar.js | 2 +- src/components/ErrorBoundary.js | 40 + 62 files changed, 2831 insertions(+), 2022 deletions(-) create mode 100644 src/components/ErrorBoundary.js diff --git a/package-lock.json b/package-lock.json index 8beffbfa..8646414d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,13 +9,15 @@ "version": "1.0.0", "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", - "@blockly/block-plus-minus": "^4.0.4", - "@blockly/field-grid-dropdown": "^2.0.4", - "@blockly/field-slider": "4.0.4", - "@blockly/plugin-scroll-options": "^3.0.5", - "@blockly/plugin-typed-variable-modal": "^5.0.6", - "@blockly/workspace-backpack": "^3.0.4", - "@blockly/zoom-to-fit": "^3.0.4", + "@blockly/block-plus-minus": "^8.0.9", + "@blockly/field-grid-dropdown": "^5.0.9", + "@blockly/field-multilineinput": "^5.0.10", + "@blockly/field-slider": "7.0.9", + "@blockly/plugin-scroll-options": "^6.0.9", + "@blockly/plugin-typed-variable-modal": "^8.0.9", + "@blockly/workspace-backpack": "^6.0.9", + "@blockly/workspace-minimap": "^0.2.9", + "@blockly/zoom-to-fit": "^6.0.9", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "@fortawesome/fontawesome-svg-core": "^6.2.1", @@ -28,8 +30,8 @@ "@testing-library/jest-dom": "^5.16.1", "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^7.2.1", + "blockly": "^11.1.1", "axios": "^0.28.0", - "blockly": "^9.2.0", "file-saver": "^2.0.5", "markdown-it": "^12.3.2", "mnemonic-id": "^3.2.7", @@ -2200,94 +2202,123 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==" }, "node_modules/@blockly/block-plus-minus": { - "version": "4.0.17", - "resolved": "https://registry.npmjs.org/@blockly/block-plus-minus/-/block-plus-minus-4.0.17.tgz", - "integrity": "sha512-wLGdNkCp8VdyErF/3g0xmzPI+C/GD28N4eDGd6y4NL+XWboRlIyAzNGTCcO0oUNqg6kiz/ABwGACRpeXk0VTug==", + "version": "8.0.9", + "resolved": "https://registry.npmjs.org/@blockly/block-plus-minus/-/block-plus-minus-8.0.9.tgz", + "integrity": "sha512-eUKxVmP1a1gERCydB5aObveO28XAwTzBxGH6majOsn/SRzwQnlXhpVH7nF4yLc67StBPQk89SXYxMG2FqVF34g==", + "license": "Apache-2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" } }, "node_modules/@blockly/field-grid-dropdown": { - "version": "2.0.18", - "resolved": "https://registry.npmjs.org/@blockly/field-grid-dropdown/-/field-grid-dropdown-2.0.18.tgz", - "integrity": "sha512-XdrnpFznJNlz9fUVt3X5R+93ua1vB5nKHSSfeFb4Cmn1eXo8v5FFFJSDIRYXJOREdo8WPEEieYuYeew8r3fcCw==", + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@blockly/field-grid-dropdown/-/field-grid-dropdown-5.0.9.tgz", + "integrity": "sha512-ziVKA1PL4J/n2FeY+CvY8dSzc/sOESBe8xNB/kPCDEe3UOvwhFtpnOvOmIWLixn4VO4B5Wp0aCY/C49SRILP4Q==", + "license": "Apache 2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.3.1" + "blockly": "^11.0.0" + } + }, + "node_modules/@blockly/field-multilineinput": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/@blockly/field-multilineinput/-/field-multilineinput-5.0.10.tgz", + "integrity": "sha512-rjdbR2GCy/YN4gRbTbCfXeYZEgcOA0IGDhE2A+wCv/+7dFf2c98Mgs315jEZkI3B67zBYFyadooiNlFpnAGKnQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + }, + "peerDependencies": { + "blockly": "^11.0.0" } }, "node_modules/@blockly/field-slider": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@blockly/field-slider/-/field-slider-4.0.4.tgz", - "integrity": "sha512-T3lMHzG1uaTLkv9WfDLO6Mo4uYLCQVP3mJzS/yICPvEAWzYXps+Ig5MJBLe3Mfh4qBkQyFO3jG2EgYK+jytJ9w==", + "version": "7.0.9", + "resolved": "https://registry.npmjs.org/@blockly/field-slider/-/field-slider-7.0.9.tgz", + "integrity": "sha512-E+JAvPYAPWm49AUom6Fd5RJJeDdEtd0jW6LVYx8aqHBH3XfYbWseTFOWLs5KLcP7h4s3b91+yf2ppgPo+MBULQ==", + "license": "Apache-2.0", "engines": { "node": ">=8.0.0" }, "peerDependencies": { - "blockly": "^9.2.0" + "blockly": "^11.0.0" } }, "node_modules/@blockly/plugin-modal": { - "version": "4.0.18", - "resolved": "https://registry.npmjs.org/@blockly/plugin-modal/-/plugin-modal-4.0.18.tgz", - "integrity": "sha512-TWBwKe14FLt81u4vvdKEzqpt0P+LQFfSEcV8Mv4eGflI2qsxm6UE+hDDYMlca8ibpBZoJX0+JQGNnh04jDpJbA==", + "version": "7.0.9", + "resolved": "https://registry.npmjs.org/@blockly/plugin-modal/-/plugin-modal-7.0.9.tgz", + "integrity": "sha512-8ObcYwlqYtsUtmG/glMjcpJ4sXK+NuL5RIvB7qoAUKJj446Efy4ZEUzI93Yp+f+Koo/SDDXxMKwJz0rqFNDF1g==", + "license": "Apache 2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" } }, "node_modules/@blockly/plugin-scroll-options": { - "version": "3.0.19", - "resolved": "https://registry.npmjs.org/@blockly/plugin-scroll-options/-/plugin-scroll-options-3.0.19.tgz", - "integrity": "sha512-7TLIEOsYbmqXZ4D3KM3Ba589i4kHg0e6LpeT5WgNqg01w/fWtpPGMuvobQfpYI6ECuVJFA2R4/pWrEYpPWAGhQ==", + "version": "6.0.9", + "resolved": "https://registry.npmjs.org/@blockly/plugin-scroll-options/-/plugin-scroll-options-6.0.9.tgz", + "integrity": "sha512-kSK3EZG4P1y0YdEkdVihf85lLWT0m9L3hmqcu7fR1epckC8YDzMvaBgFHQKbYFM9MCmEN3oHZ9pl0BxtzCAZpg==", + "license": "Apache-2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" } }, "node_modules/@blockly/plugin-typed-variable-modal": { - "version": "5.0.19", - "resolved": "https://registry.npmjs.org/@blockly/plugin-typed-variable-modal/-/plugin-typed-variable-modal-5.0.19.tgz", - "integrity": "sha512-U21/xxAmh7I40iyQHqev8adEpQdW0eA3xOQCYqWXAzfnY77Q0vuw5WDnxXcvOqv2VNJ6FZlUyAhlR5OPSElmSg==", + "version": "8.0.9", + "resolved": "https://registry.npmjs.org/@blockly/plugin-typed-variable-modal/-/plugin-typed-variable-modal-8.0.9.tgz", + "integrity": "sha512-RiSf1FByZhtZSEd9yW0DkXVNceF8u9iwkK8EmGh6nlUH1RE1DZ7T7ChjeJgVHNRGSeqQ25ytoGxkmMEJHKMumg==", + "license": "Apache-2.0", "dependencies": { - "@blockly/plugin-modal": "^4.0.18" + "@blockly/plugin-modal": "^7.0.9" }, "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" } }, "node_modules/@blockly/workspace-backpack": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/@blockly/workspace-backpack/-/workspace-backpack-3.1.5.tgz", - "integrity": "sha512-nZRcNeyLcrtEH+BV+Ipkj284bgMZ3hKd6Sav9TlqbyHjnfcL8vwrIzEn6RXmcLwI90N1N9VjV6J/5tVSRj21Fw==", + "version": "6.0.9", + "resolved": "https://registry.npmjs.org/@blockly/workspace-backpack/-/workspace-backpack-6.0.9.tgz", + "integrity": "sha512-ZWy01XH0Vgo/DGE5SorhFT0iuY1WbPQH1nn6hycQU30QJohpYiulD79AMBsGcNCp9Gbg60Atf02Wk7Y3FjXKww==", + "license": "Apache-2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" + } + }, + "node_modules/@blockly/workspace-minimap": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/@blockly/workspace-minimap/-/workspace-minimap-0.2.9.tgz", + "integrity": "sha512-4cp4mVZDpSOk+gdzj3dd8oCHY1k/DbWS7zGl9E/2oPJ8+7xsIop3C5+nCEUvGGFupm30zkmqEPwqux2L4htXKg==", + "license": "Apache-2.0", + "peerDependencies": { + "blockly": "^11.0.0" } }, "node_modules/@blockly/zoom-to-fit": { - "version": "3.0.17", - "resolved": "https://registry.npmjs.org/@blockly/zoom-to-fit/-/zoom-to-fit-3.0.17.tgz", - "integrity": "sha512-HR0hwyG/tYw1KWrppMygYc/jViJ/yKjMkM7Jvzj504xeBUeXk/Y59DcLIOQMKkd3fZIXDGPNHwjEEOSWtyux9A==", + "version": "6.0.9", + "resolved": "https://registry.npmjs.org/@blockly/zoom-to-fit/-/zoom-to-fit-6.0.9.tgz", + "integrity": "sha512-2cfg0dwf8hQo6Nk58sqOVq7xsxMbo9fYv0Oay8DZg375hKXhN20Uf70oxcAjsaLPnacaBXwFDmHD245nhcqYEg==", + "license": "Apache-2.0", "engines": { "node": ">=8.17.0" }, "peerDependencies": { - "blockly": "^9.0.0" + "blockly": "^11.0.0" } }, "node_modules/@csstools/normalize.css": { @@ -4609,14 +4640,6 @@ "@testing-library/dom": ">=5" } }, - "node_modules/@tootallnate/once": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", - "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", - "engines": { - "node": ">= 10" - } - }, "node_modules/@trysound/sax": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz", @@ -5480,15 +5503,6 @@ "node": ">=0.4.0" } }, - "node_modules/acorn-globals": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-7.0.1.tgz", - "integrity": "sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==", - "dependencies": { - "acorn": "^8.1.0", - "acorn-walk": "^8.0.2" - } - }, "node_modules/acorn-import-attributes": { "version": "1.9.5", "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", @@ -5506,14 +5520,6 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/acorn-walk": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.0.tgz", - "integrity": "sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/address": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/address/-/address-1.2.2.tgz", @@ -6245,11 +6251,15 @@ } }, "node_modules/blockly": { - "version": "9.3.3", - "resolved": "https://registry.npmjs.org/blockly/-/blockly-9.3.3.tgz", - "integrity": "sha512-L7LlrGXICEN+UaZsYq3Iz2/SF8uF2ks90ozwVXTkpueCpuo/Xt9eu4Skci6b1JUL7alMPPgt+AxIuq+2/p99Cg==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/blockly/-/blockly-11.1.1.tgz", + "integrity": "sha512-PmInYM9zH1HcYMffqnfmeu2O3g0intsowy08S0KDu3q8/95TfGo1tcDYpeWNQDkPOEzN1yy3oocsRO4NPDHtKA==", + "license": "Apache-2.0", "dependencies": { - "jsdom": "21.1.1" + "jsdom": "23.0.0" + }, + "engines": { + "node": ">=18" } }, "node_modules/bluebird": { @@ -7424,6 +7434,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-3.0.0.tgz", "integrity": "sha512-N4u2ABATi3Qplzf0hWbVCdjenim8F3ojEXpBDF5hBpjzW182MjNGLqfmQ0SkSPeQ+V86ZXgeH8aXj6kayd4jgg==", + "license": "MIT", "dependencies": { "rrweb-cssom": "^0.6.0" }, @@ -7442,16 +7453,16 @@ "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==" }, "node_modules/data-urls": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-4.0.0.tgz", - "integrity": "sha512-/mMTei/JXPqvFqQtfyTowxmJVwr2PVAeCcDxyFf6LhoOu/09TX2OX3kb2wzi4DMXcfj4OItwDOnhl5oziPnT6g==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "license": "MIT", "dependencies": { - "abab": "^2.0.6", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.0" + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/debug": { @@ -7778,17 +7789,6 @@ } ] }, - "node_modules/domexception": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/domexception/-/domexception-4.0.0.tgz", - "integrity": "sha512-A2is4PLG+eeSfoTMA95/s4pvAoSo2mKtiM5jlHkAVewmiO8ISFTFKZjH7UAM1Atli/OT/7JHOrJRJiMKUZKYBw==", - "dependencies": { - "webidl-conversions": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/domhandler": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.3.1.tgz", @@ -9244,9 +9244,10 @@ } }, "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -9861,14 +9862,15 @@ } }, "node_modules/html-encoding-sniffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", - "integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "license": "MIT", "dependencies": { - "whatwg-encoding": "^2.0.0" + "whatwg-encoding": "^3.1.1" }, "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/html-entities": { @@ -10000,16 +10002,28 @@ } }, "node_modules/http-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", - "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "license": "MIT", "dependencies": { - "@tootallnate/once": "2", - "agent-base": "6", - "debug": "4" + "agent-base": "^7.1.0", + "debug": "^4.3.4" }, "engines": { - "node": ">= 6" + "node": ">= 14" + } + }, + "node_modules/http-proxy-agent/node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" } }, "node_modules/http-proxy-middleware": { @@ -12940,42 +12954,38 @@ } }, "node_modules/jsdom": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.1.1.tgz", - "integrity": "sha512-Jjgdmw48RKcdAIQyUD1UdBh2ecH7VqwaXPN3ehoZN6MqgVbMn+lRm1aAT1AsdJRAJpwfa4IpwgzySn61h2qu3w==", + "version": "23.0.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.0.0.tgz", + "integrity": "sha512-cbL/UCtohJguhFC7c2/hgW6BeZCNvP7URQGnx9tSJRYKCdnfbfWOrtuLTMfiB2VxKsx5wPHVsh/J0aBy9lIIhQ==", + "license": "MIT", "dependencies": { - "abab": "^2.0.6", - "acorn": "^8.8.2", - "acorn-globals": "^7.0.0", "cssstyle": "^3.0.0", - "data-urls": "^4.0.0", + "data-urls": "^5.0.0", "decimal.js": "^10.4.3", - "domexception": "^4.0.0", - "escodegen": "^2.0.0", "form-data": "^4.0.0", - "html-encoding-sniffer": "^3.0.0", - "http-proxy-agent": "^5.0.0", - "https-proxy-agent": "^5.0.1", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", "is-potential-custom-element-name": "^1.0.1", - "nwsapi": "^2.2.2", + "nwsapi": "^2.2.7", "parse5": "^7.1.2", "rrweb-cssom": "^0.6.0", "saxes": "^6.0.0", "symbol-tree": "^3.2.4", - "tough-cookie": "^4.1.2", - "w3c-xmlserializer": "^4.0.0", + "tough-cookie": "^4.1.3", + "w3c-xmlserializer": "^5.0.0", "webidl-conversions": "^7.0.0", - "whatwg-encoding": "^2.0.0", - "whatwg-mimetype": "^3.0.0", - "whatwg-url": "^12.0.1", - "ws": "^8.13.0", - "xml-name-validator": "^4.0.0" + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.14.2", + "xml-name-validator": "^5.0.0" }, "engines": { - "node": ">=14" + "node": ">=18" }, "peerDependencies": { - "canvas": "^2.5.0" + "canvas": "^3.0.0" }, "peerDependenciesMeta": { "canvas": { @@ -12983,6 +12993,31 @@ } } }, + "node_modules/jsdom/node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/jsdom/node_modules/https-proxy-agent": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "license": "MIT", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -14928,11 +14963,12 @@ } }, "node_modules/parse5": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", - "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.1.tgz", + "integrity": "sha512-BuBYQYlv1ckiPdQi/ohiivi9Sagc9JG+Ozs0r7b/0iK3sKmrb0b9FdWdBbOdx6hBCM/F9Ir82ofnBhtZOjCRPQ==", + "license": "MIT", "dependencies": { - "entities": "^4.4.0" + "entities": "^4.5.0" }, "funding": { "url": "https://github.com/inikulin/parse5?sponsor=1" @@ -14942,6 +14978,7 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "license": "BSD-2-Clause", "engines": { "node": ">=0.12" }, @@ -17564,7 +17601,8 @@ "node_modules/rrweb-cssom": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", - "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==" + "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==", + "license": "MIT" }, "node_modules/run-parallel": { "version": "1.2.0", @@ -17704,6 +17742,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "license": "ISC", "dependencies": { "xmlchars": "^2.2.0" }, @@ -19103,14 +19142,15 @@ } }, "node_modules/tr46": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", - "integrity": "sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "license": "MIT", "dependencies": { - "punycode": "^2.3.0" + "punycode": "^2.3.1" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/trim-lines": { @@ -19756,14 +19796,15 @@ } }, "node_modules/w3c-xmlserializer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", - "integrity": "sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "license": "MIT", "dependencies": { - "xml-name-validator": "^4.0.0" + "xml-name-validator": "^5.0.0" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/walker": { @@ -19808,6 +19849,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", "engines": { "node": ">=12" } @@ -20122,14 +20164,15 @@ } }, "node_modules/whatwg-encoding": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz", - "integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "license": "MIT", "dependencies": { "iconv-lite": "0.6.3" }, "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/whatwg-fetch": { @@ -20138,23 +20181,25 @@ "integrity": "sha512-d67JP4dHSbm2TrpFj8AbO8DnL1JXL5J9u0Kq2xW6d0TFDbCA3Muhdt8orXC22utleTVj7Prqt82baN6RBvnEgw==" }, "node_modules/whatwg-mimetype": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz", - "integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "license": "MIT", "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/whatwg-url": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-12.0.1.tgz", - "integrity": "sha512-Ed/LrqB8EPlGxjS+TrsXcpUond1mhccS3pchLhzSgPCnTimUCKj3IZE75pAs5m6heB2U2TMerKFUXheyHY+VDQ==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "license": "MIT", "dependencies": { - "tr46": "^4.1.1", + "tr46": "^5.0.0", "webidl-conversions": "^7.0.0" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/which": { @@ -20600,11 +20645,12 @@ } }, "node_modules/xml-name-validator": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz", - "integrity": "sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "license": "Apache-2.0", "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/xmlchars": { diff --git a/package.json b/package.json index c8b52104..435550e6 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,15 @@ "private": true, "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", - "@blockly/block-plus-minus": "^4.0.4", - "@blockly/field-grid-dropdown": "^2.0.4", - "@blockly/field-slider": "4.0.4", - "@blockly/plugin-scroll-options": "^3.0.5", - "@blockly/plugin-typed-variable-modal": "^5.0.6", - "@blockly/workspace-backpack": "^3.0.4", - "@blockly/zoom-to-fit": "^3.0.4", + "@blockly/block-plus-minus": "^8.0.9", + "@blockly/field-grid-dropdown": "^5.0.9", + "@blockly/field-multilineinput": "^5.0.10", + "@blockly/field-slider": "7.0.9", + "@blockly/plugin-scroll-options": "^6.0.9", + "@blockly/plugin-typed-variable-modal": "^8.0.9", + "@blockly/workspace-backpack": "^6.0.9", + "@blockly/workspace-minimap": "^0.2.9", + "@blockly/zoom-to-fit": "^6.0.9", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "@fortawesome/fontawesome-svg-core": "^6.2.1", @@ -24,7 +26,7 @@ "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^7.2.1", "axios": "^0.28.0", - "blockly": "^9.2.0", + "blockly": "^11.1.1", "file-saver": "^2.0.5", "markdown-it": "^12.3.2", "mnemonic-id": "^3.2.7", diff --git a/src/App.js b/src/App.js index 352b656b..75180956 100644 --- a/src/App.js +++ b/src/App.js @@ -6,6 +6,7 @@ import { createBrowserHistory } from "history"; import { Provider } from "react-redux"; import store from "./store"; import { loadUser } from "./actions/authActions"; +import ErrorBoundary from "./components/ErrorBoundary"; import "./App.css"; @@ -44,7 +45,9 @@ class App extends Component { - + + + diff --git a/src/actions/workspaceActions.js b/src/actions/workspaceActions.js index 1bad3529..fdd27589 100644 --- a/src/actions/workspaceActions.js +++ b/src/actions/workspaceActions.js @@ -22,7 +22,7 @@ export const workspaceChange = () => (dispatch) => { export const onChangeCode = () => (dispatch, getState) => { const workspace = Blockly.getMainWorkspace(); var code = getState().workspace.code; - code.arduino = Blockly.Arduino.workspaceToCode(workspace); + code.arduino = Blockly.Generator.Arduino.workspaceToCode(workspace); var xmlDom = Blockly.Xml.workspaceToDom(workspace); var board = getState().board.board; xmlDom.setAttribute("board", board); diff --git a/src/components/Blockly/BlocklyComponent.jsx b/src/components/Blockly/BlocklyComponent.jsx index 1b0325b5..ad78dd30 100644 --- a/src/components/Blockly/BlocklyComponent.jsx +++ b/src/components/Blockly/BlocklyComponent.jsx @@ -23,7 +23,7 @@ import React from "react"; -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import "blockly/blocks"; import Toolbox from "./toolbox/Toolbox"; @@ -34,6 +34,8 @@ import { ScrollMetricsManager, } from "@blockly/plugin-scroll-options"; +import { PositionedMinimap } from "@blockly/workspace-minimap"; + class BlocklyComponent extends React.Component { constructor(props) { super(props); @@ -44,7 +46,7 @@ class BlocklyComponent extends React.Component { componentDidMount() { const { initialXml, children, ...rest } = this.props; - this.primaryWorkspace = Blockly.inject(this.blocklyDiv.current, { + const workspace = Blockly.inject(this.blocklyDiv.current, { toolbox: this.toolbox.current, plugins: { // These are both required. @@ -55,12 +57,18 @@ class BlocklyComponent extends React.Component { }); // Initialize plugin. + // Initialize plugin. + // const minimap = new PositionedMinimap(workspace); + // minimap.init(); + + this.primaryWorkspace = workspace; + this.setState({ workspace: this.primaryWorkspace }); const plugin = new ScrollOptions(this.workspace); plugin.init({ enableWheelScroll: true, enableEdgeScroll: false }); if (initialXml) { Blockly.Xml.domToWorkspace( - Blockly.Xml.textToDom(initialXml), + Blockly.utils.xml.textToDom(initialXml), this.primaryWorkspace, ); } @@ -72,7 +80,7 @@ class BlocklyComponent extends React.Component { setXml(xml) { Blockly.Xml.domToWorkspace( - Blockly.Xml.textToDom(xml), + Blockly.utils.xml.textToDom(xml), this.primaryWorkspace, ); } diff --git a/src/components/Blockly/BlocklySvg.js b/src/components/Blockly/BlocklySvg.js index c482733b..95efccb2 100644 --- a/src/components/Blockly/BlocklySvg.js +++ b/src/components/Blockly/BlocklySvg.js @@ -24,7 +24,7 @@ class BlocklySvg extends Component { const workspace = Blockly.getMainWorkspace(); workspace.clear(); Blockly.Xml.domToWorkspace( - Blockly.Xml.textToDom(this.props.initialXml), + Blockly.utils.xml.textToDom(this.props.initialXml), workspace, ); var canvas = workspace.svgBlockCanvas_.cloneNode(true); diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index b5f5ba85..85cae14d 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -49,7 +49,7 @@ class BlocklyWindow extends Component { xml = localStorage.getItem("autoSaveXML"); // change board if (!xml) xml = initialXml; - var xmlDom = Blockly.Xml.textToDom(xml); + var xmlDom = Blockly.utils.xml.textToDom(xml); Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); } @@ -58,13 +58,13 @@ class BlocklyWindow extends Component { // guarantees that the current xml-code (this.props.initialXml) is rendered workspace.clear(); if (!xml) xml = initialXml; - Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace); + Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(xml), workspace); } if (props.language !== this.props.language) { // change language xml = localStorage.getItem("autoSaveXML"); if (!xml) xml = initialXml; - xmlDom = Blockly.Xml.textToDom(xml); + xmlDom = Blockly.utils.xml.textToDom(xml); Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); // var toolbox = workspace.getToolbox(); // workspace.updateToolbox(toolbox.toolboxDef_); diff --git a/src/components/Blockly/blocks/audio.js b/src/components/Blockly/blocks/audio.js index 11d90db1..ec5af10e 100644 --- a/src/components/Blockly/blocks/audio.js +++ b/src/components/Blockly/blocks/audio.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { selectedBoard } from "../helpers/board"; import * as Types from "../helpers/types"; import { getColour } from "../helpers/colour"; @@ -35,10 +35,10 @@ Blockly.Blocks["io_tone"] = { ) { return; // Block deleted or irrelevant event } - var freq = Blockly.Arduino.valueToCode( + var freq = Blockly.Generator.Arduino.valueToCode( this, "FREQUENCY", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); if (freq < 31 || freq > 65535) { this.setWarningText(Blockly.Msg.ARD_TONE_WARNING, "io_tone"); @@ -64,6 +64,6 @@ Blockly.Blocks["io_notone"] = { }, /** @return {!string} The type of input value for the block, an integer. */ getBlockType: function () { - return Blockly.Types.NUMBER; + return Types.NUMBER; }, }; diff --git a/src/components/Blockly/blocks/io.js b/src/components/Blockly/blocks/io.js index 360c8bdb..cb8bf830 100644 --- a/src/components/Blockly/blocks/io.js +++ b/src/components/Blockly/blocks/io.js @@ -10,7 +10,7 @@ * * TODO: maybe change this to a "PIN" BlocklyType */ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { selectedBoard } from "../helpers/board"; import * as Types from "../helpers/types"; import { getColour } from "../helpers/colour"; @@ -41,7 +41,7 @@ Blockly.Blocks["io_digitalwrite"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown( + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( this, "PIN", "digitalPins", @@ -75,7 +75,7 @@ Blockly.Blocks["io_digitalread"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown( + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( this, "PIN", "digitalPins", @@ -109,7 +109,7 @@ Blockly.Blocks["io_builtin_led"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown( + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( this, "BUILT_IN_LED", "builtinLed", @@ -144,7 +144,11 @@ Blockly.Blocks["io_analogwrite"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, "PIN", "pwmPins"); + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( + this, + "PIN", + "pwmPins", + ); }, /** @return {!string} The type of input value for the block, an integer. */ getBlockType: function () { @@ -178,7 +182,11 @@ Blockly.Blocks["io_analogread"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, "PIN", "analogPins"); + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( + this, + "PIN", + "analogPins", + ); }, }; @@ -310,6 +318,10 @@ Blockly.Blocks["io_analogreadmillivolt"] = { * @this Blockly.Block */ updateFields: function () { - Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, "PIN", "analogPins"); + Blockly.Generator.Arduino.Boards.refreshBlockFieldDropdown( + this, + "PIN", + "analogPins", + ); }, }; diff --git a/src/components/Blockly/blocks/lists.js b/src/components/Blockly/blocks/lists.js index b58eb9a7..5d9d32f7 100644 --- a/src/components/Blockly/blocks/lists.js +++ b/src/components/Blockly/blocks/lists.js @@ -1,4 +1,4 @@ -import Blockly, { FieldDropdown } from "blockly/core"; +import * as Blockly from "blockly/core"; import * as Types from "../helpers/types"; import { getColour } from "../helpers/colour"; @@ -14,7 +14,7 @@ Blockly.Blocks["lists_create_empty"] = { this.appendValueInput("NUMBER"); this.appendDummyInput() .appendField("Items of Type") - .appendField(new FieldDropdown(Types.VARIABLE_TYPES), "type"); + .appendField(new Blockly.FieldDropdown(Types.VARIABLE_TYPES), "type"); this.setOutput(true, Types.ARRAY.typeName); this.setTooltip(Blockly.Msg.ARD_TIME_MILLIS_TIP); }, diff --git a/src/components/Blockly/blocks/logic.js b/src/components/Blockly/blocks/logic.js index 4fe1d65d..7e365060 100644 --- a/src/components/Blockly/blocks/logic.js +++ b/src/components/Blockly/blocks/logic.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; import { getCompatibleTypes } from "../helpers/types"; @@ -20,7 +20,7 @@ Blockly.Blocks["controls_if"] = { this.setPreviousStatement(true); this.setNextStatement(true); this.setMutator( - new Blockly.Mutator(["controls_if_elseif", "controls_if_else"]), + new Blockly.icons.MutatorIcon(["controls_if_elseif", "controls_if_else"]), ); this.setTooltip(Blockly.Msg.CONTROLS_IF_TOOLTIP_1); this.elseifCount_ = 0; @@ -110,10 +110,14 @@ Blockly.Blocks["controls_if"] = { this.updateShape_(); // Reconnect any child blocks. for (var i = 1; i <= this.elseifCount_; i++) { - Blockly.Mutator.reconnect(valueConnections[i], this, "IF" + i); - Blockly.Mutator.reconnect(statementConnections[i], this, "DO" + i); + Blockly.icons.MutatorIcon.reconnect(valueConnections[i], this, "IF" + i); + Blockly.icons.MutatorIcon.reconnect( + statementConnections[i], + this, + "DO" + i, + ); } - Blockly.Mutator.reconnect(elseStatementConnection, this, "ELSE"); + Blockly.icons.MutatorIcon.reconnect(elseStatementConnection, this, "ELSE"); }, /** * Store pointers to any connected child blocks. @@ -491,7 +495,9 @@ Blockly.Blocks["switch_case"] = { Blockly.Msg.cases_condition, ); this.appendStatementInput("CASE0").appendField(Blockly.Msg.cases_do); - this.setMutator(new Blockly.Mutator(["case_incaseof", "case_default"])); + this.setMutator( + new Blockly.icons.MutatorIcon(["case_incaseof", "case_default"]), + ); this.caseCount_ = 0; this.defaultCount_ = 0; }, diff --git a/src/components/Blockly/blocks/loops.js b/src/components/Blockly/blocks/loops.js index 2f5c0e46..e2231b90 100644 --- a/src/components/Blockly/blocks/loops.js +++ b/src/components/Blockly/blocks/loops.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; import { getCompatibleTypes } from "../helpers/types"; import * as Types from "../helpers/types"; @@ -131,7 +131,7 @@ Blockly.Blocks["controls_forEach"] = { customContextMenu: Blockly.Blocks["controls_for"].customContextMenu, /** @returns {!string} The type of the variable used in this block */ getVarType: function (varName) { - return Blockly.Types.NUMBER; + return Types.NUMBER; }, }; diff --git a/src/components/Blockly/blocks/mqtt.js b/src/components/Blockly/blocks/mqtt.js index 847d9b8c..d7f31e8b 100644 --- a/src/components/Blockly/blocks/mqtt.js +++ b/src/components/Blockly/blocks/mqtt.js @@ -21,19 +21,19 @@ Blockly.Blocks["sensebox_mqtt_setup"] = { "service", ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_mqtt_server) .appendField(new Blockly.FieldTextInput("Server"), "server"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_mqtt_port) .appendField(new Blockly.FieldTextInput("Port"), "port"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_mqtt_username) .appendField(new Blockly.FieldTextInput("Username"), "username"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_mqtt_password, "passwordmsg") .appendField(new Blockly.FieldTextInput("Password"), "password"); this.setPreviousStatement(true, null); diff --git a/src/components/Blockly/blocks/procedures.js b/src/components/Blockly/blocks/procedures.js index 639f3e18..57cd6287 100644 --- a/src/components/Blockly/blocks/procedures.js +++ b/src/components/Blockly/blocks/procedures.js @@ -49,7 +49,7 @@ Blockly.Blocks["procedures_defnoreturn"] = { .appendField(Blockly.Msg.PROCEDURES_DEFNORETURN) .appendField(nameField, "NAME") .appendField("", "PARAMS"); - this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"])); + this.setMutator(new Blockly.icons.MutatorIcon(["procedures_mutatorarg"])); if ( (this.workspace.options.comments || (this.workspace.options.parentWorkspace && @@ -270,7 +270,11 @@ Blockly.Blocks["procedures_defnoreturn"] = { if (hasStatements) { this.setStatements_(true); // Restore the stack, if one was saved. - Blockly.Mutator.reconnect(this.statementConnection_, this, "STACK"); + Blockly.icons.MutatorIcon.reconnect( + this.statementConnection_, + this, + "STACK", + ); this.statementConnection_ = null; } else { // Save the stack, then disconnect it. @@ -471,9 +475,9 @@ Blockly.Blocks["procedures_defreturn"] = { .appendField(returnTypeField, "RETURN TYPE"); this.appendValueInput("RETURN") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg["PROCEDURES_DEFRETURN_RETURN"]); - this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"])); + this.setMutator(new Blockly.icons.MutatorIcon(["procedures_mutatorarg"])); if ( (this.workspace.options.comments || (this.workspace.options.parentWorkspace && @@ -704,7 +708,7 @@ Blockly.Blocks["procedures_mutatorarg"] = { return null; } - const outerWs = Blockly.mainWorkspace; + const outerWs = Blockly.getMainWorkspace(); let model = outerWs.getVariable(varName, varType); // CHANGING VARIABLE NAME TO REFLECT TYPE if (model && model.name !== varName) { @@ -738,7 +742,7 @@ Blockly.Blocks["procedures_mutatorarg"] = { deleteIntermediateVars_: function (varName, varType) { varName = varName || this.getFieldValue("NAME"); varType = varType || this.getFieldValue("TYPE"); - const outerWs = Blockly.mainWorkspace; + const outerWs = Blockly.getMainWorkspace(); if (!outerWs) { return; } @@ -904,7 +908,9 @@ Blockly.Blocks["procedures_callnoreturn"] = { if (quarkId in this.quarkConnections_) { const connection = this.quarkConnections_[quarkId]; try { - if (!Blockly.Mutator.reconnect(connection, this, "ARG" + i)) { + if ( + !Blockly.icons.MutatorIcon.reconnect(connection, this, "ARG" + i) + ) { // Block no longer exists or has been attached elsewhere. delete this.quarkConnections_[quarkId]; } @@ -954,7 +960,7 @@ Blockly.Blocks["procedures_callnoreturn"] = { // Add new input. field = new Blockly.FieldLabel(labelString); const input = this.appendValueInput("ARG" + i) - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(field, "ARGNAME" + i) .setCheck( Types.getCompatibleTypes([this.argumentVarModels_[i].type]), @@ -1020,7 +1026,7 @@ Blockly.Blocks["procedures_callnoreturn"] = { for (let i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) { if (childNode.nodeName.toLowerCase() === "arg") { - var variables = Blockly.mainWorkspace.getAllVariables(); + var variables = Blockly.getMainWorkspace().getAllVariables(); var varName = childNode.getAttribute("name"); for (let y = 0; variables.length; y++) { @@ -1116,8 +1122,8 @@ Blockly.Blocks["procedures_callnoreturn"] = { const block = document.createElement("block"); block.setAttribute("type", this.defType_); const xy = this.getRelativeToSurfaceXY(); - const x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); - const y = xy.y + Blockly.SNAP_RADIUS * 2; + const x = xy.x + Blockly.config.snapRadius * (this.RTL ? -1 : 1); + const y = xy.y + Blockly.config.snapRadius * 2; block.setAttribute("x", x); block.setAttribute("y", y); const mutation = this.mutationToDom(); diff --git a/src/components/Blockly/blocks/sensebox-esp-now.js b/src/components/Blockly/blocks/sensebox-esp-now.js index 4a1b34ea..01df8567 100644 --- a/src/components/Blockly/blocks/sensebox-esp-now.js +++ b/src/components/Blockly/blocks/sensebox-esp-now.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; @@ -20,7 +20,7 @@ Blockly.Blocks["sensebox_esp_now_sender"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_esp_now_sender); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_esp_now_send_mac) .appendField( new Blockly.FieldTextInput("00:00:00:00:00:00"), diff --git a/src/components/Blockly/blocks/sensebox-led.js b/src/components/Blockly/blocks/sensebox-led.js index 7be4a6a2..8663e776 100644 --- a/src/components/Blockly/blocks/sensebox-led.js +++ b/src/components/Blockly/blocks/sensebox-led.js @@ -3,6 +3,12 @@ import { getColour } from "../helpers/colour"; import { selectedBoard } from "../helpers/board"; import * as Types from "../helpers/types"; import { FieldSlider } from "@blockly/field-slider"; +import { + registerFieldMultilineInput, + FieldMultilineInput, +} from "@blockly/field-multilineinput"; + +registerFieldMultilineInput(); Blockly.Blocks["sensebox_led"] = { init: function () { @@ -341,7 +347,7 @@ Blockly.Blocks["sensebox_ws2812_matrix_custom_bitmap"] = { this.appendDummyInput("BITMAP") .appendField(Blockly.Msg.senseBox_ws2812_rgb_matrix_custom_bitmap) .appendField( - new Blockly.FieldMultilineInput( + new FieldMultilineInput( Blockly.Msg.senseBox_ws2812_rgb_matrix_custom_bitmap_example, ), "FIELDNAME", diff --git a/src/components/Blockly/blocks/sensebox-lora.js b/src/components/Blockly/blocks/sensebox-lora.js index 556f400f..6e14be9e 100644 --- a/src/components/Blockly/blocks/sensebox-lora.js +++ b/src/components/Blockly/blocks/sensebox-lora.js @@ -12,25 +12,25 @@ Blockly.Blocks["sensebox_lora_initialize_otaa"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField("Initialize LoRa (OTAA)"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_device_id) .appendField("{") .appendField(new Blockly.FieldTextInput("DEVICE ID"), "DEVICEID") .appendField("}"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_app_id) .appendField("{") .appendField(new Blockly.FieldTextInput("APP ID"), "APPID") .appendField("}"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_app_key) .appendField("{") .appendField(new Blockly.FieldTextInput("APP KEY"), "APPKEY") .appendField("}"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_interval) .appendField(new Blockly.FieldTextInput("5"), "INTERVAL"); this.setPreviousStatement(true, null); @@ -45,23 +45,23 @@ Blockly.Blocks["sensebox_lora_initialize_abp"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField("Initialize LoRa (ABP)"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_nwskey_id) .appendField("{") .appendField(new Blockly.FieldTextInput("NWSKEY"), "NWSKEY") .appendField("}"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_appskey_id) .appendField("{") .appendField(new Blockly.FieldTextInput("APPSKEY"), "APPSKEY") .appendField("}"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_devaddr_id) .appendField(new Blockly.FieldTextInput("DEVADDR"), "DEVADDR"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_interval) .appendField(new Blockly.FieldTextInput("5"), "INTERVAL"); // this.appendStatementInput('DO') @@ -94,7 +94,7 @@ Blockly.Blocks["sensebox_send_lora_sensor_value"] = { Blockly.Msg.senseBox_measurement, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("Bytes") .appendField(new Blockly.FieldTextInput("2"), "MESSAGE_BYTES"); this.setPreviousStatement(true, null); @@ -131,7 +131,7 @@ Blockly.Blocks["sensebox_lora_ttn_mapper"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField("TTN Mapper"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField("Fix Type Limit") .appendField( new Blockly.FieldDropdown( @@ -184,7 +184,7 @@ Blockly.Blocks["sensebox_lora_cayenne_temperature"] = { Blockly.Msg.senseBox_LoRa_cayenne_temperature, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -201,7 +201,7 @@ Blockly.Blocks["sensebox_lora_cayenne_humidity"] = { Blockly.Msg.senseBox_LoRa_cayenne_humidity, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -218,7 +218,7 @@ Blockly.Blocks["sensebox_lora_cayenne_pressure"] = { Blockly.Msg.senseBox_LoRa_cayenne_pressure, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -235,7 +235,7 @@ Blockly.Blocks["sensebox_lora_cayenne_luminosity"] = { Blockly.Msg.senseBox_LoRa_cayenne_luminosity, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -252,7 +252,7 @@ Blockly.Blocks["sensebox_lora_cayenne_sensor"] = { Blockly.Msg.senseBox_LoRa_cayenne_analog, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -269,7 +269,7 @@ Blockly.Blocks["sensebox_lora_cayenne_accelerometer"] = { this.appendValueInput("Y").appendField(Blockly.Msg.senseBox_LoRa_cayenne_y); this.appendValueInput("Z").appendField(Blockly.Msg.senseBox_LoRa_cayenne_z); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -292,7 +292,7 @@ Blockly.Blocks["sensebox_lora_cayenne_gps"] = { Blockly.Msg.senseBox_LoRa_cayenne_alt, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); @@ -310,7 +310,7 @@ Blockly.Blocks["sensebox_lora_cayenne_concentration"] = { Blockly.Msg.senseBox_LoRa_cayenne_concentration, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_LoRa_cayenne_channel) .appendField(new Blockly.FieldTextInput("1"), "CHANNEL"); this.setPreviousStatement(true, null); diff --git a/src/components/Blockly/blocks/sensebox-motors.js b/src/components/Blockly/blocks/sensebox-motors.js index 7be8ff55..50ac246a 100644 --- a/src/components/Blockly/blocks/sensebox-motors.js +++ b/src/components/Blockly/blocks/sensebox-motors.js @@ -18,7 +18,7 @@ Blockly.Blocks["sensebox_motors_beginServoMotor"] = { new Blockly.FieldDropdown(selectedBoard().digitalPins), "pin", ) - .setAlign(Blockly.ALIGN_RIGHT); + .setAlign(Blockly.inputs.Align.RIGHT); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(getColour().motors); @@ -38,10 +38,10 @@ Blockly.Blocks["sensebox_motors_moveServoMotor"] = { new Blockly.FieldDropdown(selectedBoard().digitalPins), "pin", ) - .setAlign(Blockly.ALIGN_RIGHT); + .setAlign(Blockly.inputs.Align.RIGHT); this.appendValueInput("degrees", "Number") .appendField(Blockly.Msg.sensebox_motors_moveServoMotor_degrees) - .setAlign(Blockly.ALIGN_RIGHT); + .setAlign(Blockly.inputs.Align.RIGHT); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(getColour().motors); @@ -80,7 +80,7 @@ Blockly.Blocks["sensebox_motors_I2CMotorBoard_moveDCMotor"] = { .appendField(Blockly.Msg.sensebox_motors_I2CMotorBoard_moveDCMotor_motor); this.appendValueInput("speed", "Number") .appendField(Blockly.Msg.sensebox_motors_I2CMotorBoard_moveDCMotor_speed) - .setAlign(Blockly.ALIGN_RIGHT); + .setAlign(Blockly.inputs.Align.RIGHT); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(getColour().motors); @@ -129,7 +129,7 @@ Blockly.Blocks["sensebox_motors_beginStepperMotor"] = { Blockly.Msg.sensebox_motors_beginStepperMotor_pins, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField( new Blockly.FieldDropdown(selectedBoard().digitalPins), "in1", @@ -167,7 +167,7 @@ Blockly.Blocks["sensebox_motors_moveStepperMotor"] = { Blockly.Msg.sensebox_motors_moveStepperMotor, ); this.appendValueInput("steps", "Number") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.sensebox_motors_moveStepperMotor_step); this.setPreviousStatement(true, null); this.setNextStatement(true, null); diff --git a/src/components/Blockly/blocks/sensebox-osem.js b/src/components/Blockly/blocks/sensebox-osem.js index 8d08dbe3..0ddb70e7 100644 --- a/src/components/Blockly/blocks/sensebox-osem.js +++ b/src/components/Blockly/blocks/sensebox-osem.js @@ -25,7 +25,7 @@ Blockly.Blocks["sensebox_osem_connection"] = { .appendField(Blockly.Msg.senseBox_osem_restart) .appendField(new Blockly.FieldCheckbox("TRUE"), "RESTART"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_osem_exposure) .appendField( new Blockly.FieldDropdown([ @@ -36,7 +36,7 @@ Blockly.Blocks["sensebox_osem_connection"] = { ); if (!boxes) { this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("senseBox ID") .appendField(new Blockly.FieldTextInput("senseBox ID"), "BoxID"); } else { @@ -45,12 +45,12 @@ Blockly.Blocks["sensebox_osem_connection"] = { dropdown.push([boxes[i].name, boxes[i]._id]); } this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("senseBox ID") .appendField(new Blockly.FieldDropdown(dropdown), "BoxID"); } this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_osem_access_token) .appendField(new Blockly.FieldTextInput("access_token"), "access_token"); this.appendStatementInput("DO") @@ -139,7 +139,7 @@ Blockly.Blocks["sensebox_send_to_osem"] = { ); } else { this.appendValueInput("Value") - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("Phänomen") .appendField(new Blockly.FieldTextInput("sensorID"), "SensorID"); } @@ -209,7 +209,7 @@ Blockly.Blocks["sensebox_esp32s2_osem_connection"] = { .appendField("SSL") .appendField(new Blockly.FieldCheckbox(ssl), "SSL"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_osem_exposure) .appendField( new Blockly.FieldDropdown([ @@ -220,7 +220,7 @@ Blockly.Blocks["sensebox_esp32s2_osem_connection"] = { ); if (!boxes) { this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("senseBox ID") .appendField(new Blockly.FieldTextInput("senseBox ID"), "BoxID"); } else { @@ -229,12 +229,12 @@ Blockly.Blocks["sensebox_esp32s2_osem_connection"] = { dropdown.push([boxes[i].name, boxes[i]._id]); } this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("senseBox ID") .appendField(new Blockly.FieldDropdown(dropdown), "BoxID"); } this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_osem_access_token) .appendField(new Blockly.FieldTextInput("access_token"), "access_token"); this.appendStatementInput("DO") diff --git a/src/components/Blockly/blocks/sensebox-sd.js b/src/components/Blockly/blocks/sensebox-sd.js index a0d39f89..78ab74b4 100644 --- a/src/components/Blockly/blocks/sensebox-sd.js +++ b/src/components/Blockly/blocks/sensebox-sd.js @@ -14,7 +14,7 @@ Blockly.Blocks["sensebox_sd_open_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_open_file) - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField( new Blockly.FieldTextInput("Data", checkFileName), "Filename", @@ -40,7 +40,7 @@ Blockly.Blocks["sensebox_sd_create_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_create_file) - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_output_filename) .appendField( new Blockly.FieldTextInput("Data", checkFileName), @@ -66,7 +66,7 @@ Blockly.Blocks["sensebox_sd_write_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_write_file) - .setAlign(Blockly.ALIGN_LEFT); + .setAlign(Blockly.inputs.Align.LEFT); this.appendValueInput("DATA").setCheck(null); this.appendDummyInput("CheckboxText") .appendField(Blockly.Msg.senseBox_output_linebreak) @@ -109,10 +109,10 @@ Blockly.Blocks["sensebox_sd_osem"] = { this.setHelpUrl(Blockly.Msg.sensebox_sd_helpurl); this.setColour(getColour().sensebox); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.sensebox_sd_osem); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_osem_exposure) .appendField( new Blockly.FieldDropdown([ @@ -165,7 +165,7 @@ Blockly.Blocks["sensebox_sd_save_for_osem"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.sensebox_sd_save_for_osem); this.appendValueInput("Value") - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.sensebox_sd_save_for_osem_id) .appendField(new Blockly.FieldTextInput("sensorID"), "SensorID"); this.setPreviousStatement(true, null); @@ -181,7 +181,7 @@ Blockly.Blocks["sensebox_esp32s2_sd_open_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_open_file) - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField( new Blockly.FieldTextInput("Data", checkFileName), "Filename", @@ -207,7 +207,7 @@ Blockly.Blocks["sensebox_esp32s2_sd_create_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_create_file) - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_output_filename) .appendField( new Blockly.FieldTextInput("Data", checkFileName), @@ -233,7 +233,7 @@ Blockly.Blocks["sensebox_esp32s2_sd_write_file"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_write_file) - .setAlign(Blockly.ALIGN_LEFT); + .setAlign(Blockly.inputs.Align.LEFT); this.appendValueInput("DATA").setCheck(null); this.appendDummyInput("CheckboxText") .appendField(Blockly.Msg.senseBox_output_linebreak) diff --git a/src/components/Blockly/blocks/sensebox-sensors.js b/src/components/Blockly/blocks/sensebox-sensors.js index 64344a8e..ba614fc2 100644 --- a/src/components/Blockly/blocks/sensebox-sensors.js +++ b/src/components/Blockly/blocks/sensebox-sensors.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; import { selectedBoard } from "../helpers/board"; @@ -14,7 +14,7 @@ Blockly.Blocks["sensebox_sensor_temp_hum"] = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.senseBox_temp_hum); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ @@ -40,7 +40,7 @@ Blockly.Blocks["sensebox_sensor_uv_light"] = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.senseBox_uv_light); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ @@ -67,7 +67,7 @@ Blockly.Blocks["sensebox_sensor_bmx055_accelerometer"] = { Blockly.Msg.senseBox_bmx055_accelerometer, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_bmx055_accelerometer_direction) .appendField( new Blockly.FieldDropdown([ @@ -79,7 +79,7 @@ Blockly.Blocks["sensebox_sensor_bmx055_accelerometer"] = { "VALUE", ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_bmx055_accelerometer_range) .appendField( new Blockly.FieldDropdown([ @@ -107,7 +107,7 @@ Blockly.Blocks["sensebox_sensor_sds011"] = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.senseBox_sds011); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ @@ -152,7 +152,7 @@ Blockly.Blocks["sensebox_sensor_pressure"] = { }); this.appendDummyInput().appendField(Blockly.Msg.senseBox_pressure_sensor); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(dropdown, "NAME"); this.setColour(getColour().sensebox); @@ -170,7 +170,7 @@ Blockly.Blocks["sensebox_sensor_pressure"] = { if (isAltitude) { if (this.getInput("extraField") == null) { this.appendDummyInput("extraField") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_pressure_referencePressure) .appendField(new Blockly.FieldTextInput("1013"), "referencePressure") .appendField(Blockly.Msg.senseBox_pressure_referencePressure_dim); @@ -199,7 +199,7 @@ Blockly.Blocks["sensebox_sensor_bme680_bsec"] = { ]; this.appendDummyInput().appendField(Blockly.Msg.senseBox_bme680); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); this.setOutput(true, Types.DECIMAL.typeName); @@ -231,7 +231,7 @@ Blockly.Blocks["sensebox_sensor_ultrasonic_ranger"] = { .appendField(Blockly.Msg.senseBox_ultrasonic) .appendField(dropdown, "port"); this.appendDummyInput("TrigEcho") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_ultrasonic_trigger) .appendField( new Blockly.FieldDropdown(selectedBoard().digitalPins), @@ -324,7 +324,7 @@ Blockly.Blocks["sensebox_tof_imager"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.sensebox_tof_imager); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(dropdown, "dropdown"); this.setOutput(true, Types.NUMBER.typeName); @@ -340,7 +340,7 @@ Blockly.Blocks["sensebox_tof_imager"] = { this.setOutput(true, "Bitmap"); if (this.getInput("extraField") == null) { this.appendDummyInput("extraField") - // .setAlign(Blockly.ALIGN_RIGHT) // This doesnt work for manual data input + // .setAlign(Blockly.inputs.Align.RIGHT) // This doesnt work for manual data input .appendField(Blockly.Msg.sensebox_tof_imager_max_distance) .appendField(new FieldSlider(200, 1, 400), "maxDistance") .appendField(Blockly.Msg.sensebox_tof_imager_max_distance_unit); @@ -410,7 +410,7 @@ Blockly.Blocks["sensebox_button"] = { if (isLongPress) { if (this.getInput("extraField") == null) { this.appendDummyInput("extraField") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_button_longPress_time) .appendField(new Blockly.FieldTextInput("1000"), "time") .appendField("ms"); @@ -435,7 +435,7 @@ Blockly.Blocks["sensebox_scd30"] = { ]; this.appendDummyInput().appendField(Blockly.Msg.senseBox_scd30); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); this.setOutput(true, Types.NUMBER.typeName); @@ -472,7 +472,7 @@ Blockly.Blocks["sensebox_gps"] = { ]; this.appendDummyInput().appendField("GPS Modul"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(new Blockly.FieldDropdown(dropdownOptions), "dropdown"); this.setOutput(true, Types.NUMBER.typeName); @@ -624,7 +624,7 @@ Blockly.Blocks["sensebox_sensor_dps310"] = { }); this.appendDummyInput().appendField(Blockly.Msg.senseBox_sensor_dps310); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField(dropdown, "NAME"); this.setColour(getColour().sensebox); @@ -642,7 +642,7 @@ Blockly.Blocks["sensebox_sensor_dps310"] = { if (isAltitude) { if (this.getInput("extraField") == null) { this.appendDummyInput("extraField") - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_pressure_referencePressure) .appendField(new Blockly.FieldTextInput("1013"), "referencePressure") .appendField(Blockly.Msg.senseBox_pressure_referencePressure_dim); @@ -662,7 +662,7 @@ Blockly.Blocks["sensebox_sensor_sps30"] = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.senseBox_sps30); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ @@ -691,7 +691,7 @@ Blockly.Blocks["sensebox_esp32s2_light"] = { init: function () { this.appendDummyInput().appendField("ESP32-S2 Phododiode"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ @@ -716,7 +716,7 @@ Blockly.Blocks["sensebox_esp32s2_mpu6050"] = { init: function () { this.appendDummyInput().appendField("ESP32-S2 MPU6050"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) + .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg.senseBox_value) .appendField( new Blockly.FieldDropdown([ diff --git a/src/components/Blockly/blocks/sensebox-telegram.js b/src/components/Blockly/blocks/sensebox-telegram.js index e005ec6e..b56862ef 100644 --- a/src/components/Blockly/blocks/sensebox-telegram.js +++ b/src/components/Blockly/blocks/sensebox-telegram.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; Blockly.Blocks["sensebox_telegram"] = { @@ -6,7 +6,7 @@ Blockly.Blocks["sensebox_telegram"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_telegram_init); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("telegram") .appendField(new Blockly.FieldTextInput("token"), "telegram_token"); this.setPreviousStatement(true, null); @@ -33,7 +33,7 @@ Blockly.Blocks["sensebox_telegram_do_on_message"] = { Blockly.Msg.senseBox_telegram_do_on_message, ); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_telegram_message) .appendField(new Blockly.FieldTextInput("/message"), "telegram_message"); this.appendStatementInput("telegram_do_on_message").setCheck(null); diff --git a/src/components/Blockly/blocks/sensebox-web.js b/src/components/Blockly/blocks/sensebox-web.js index c320bd25..86c004b0 100644 --- a/src/components/Blockly/blocks/sensebox-web.js +++ b/src/components/Blockly/blocks/sensebox-web.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; @@ -9,11 +9,11 @@ Blockly.Blocks["sensebox_wifi"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_connect); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_ssid) .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_output_password) .appendField(new Blockly.FieldTextInput("Password"), "Password"); this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl); @@ -47,7 +47,7 @@ Blockly.Blocks["sensebox_startap"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_startap); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_ssid) .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl); @@ -163,15 +163,15 @@ Blockly.Blocks["sensebox_esp32s2_wifi_enterprise"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.sensebox_wifi_enterprise); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_ssid) .appendField(new Blockly.FieldTextInput("eduroam"), "SSID"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_user) .appendField(new Blockly.FieldTextInput("User"), "User"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_password) .appendField(new Blockly.FieldTextInput("Password"), "Password"); this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl); @@ -205,7 +205,7 @@ Blockly.Blocks["sensebox_esp32s2_startap"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_startap); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_ssid) .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl); @@ -221,11 +221,11 @@ Blockly.Blocks["sensebox_esp32s2_wifi"] = { this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_wifi_connect); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_wifi_ssid) .appendField(new Blockly.FieldTextInput("SSID"), "SSID"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.senseBox_output_password) .appendField(new Blockly.FieldTextInput("Password"), "Password"); this.setHelpUrl(Blockly.Msg.senseBox_wifi_helpurl); diff --git a/src/components/Blockly/blocks/text.js b/src/components/Blockly/blocks/text.js index 0faa432b..53a2d14b 100644 --- a/src/components/Blockly/blocks/text.js +++ b/src/components/Blockly/blocks/text.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; diff --git a/src/components/Blockly/blocks/time.js b/src/components/Blockly/blocks/time.js index 497c353b..9dbce38b 100644 --- a/src/components/Blockly/blocks/time.js +++ b/src/components/Blockly/blocks/time.js @@ -8,7 +8,7 @@ * The arduino built in functions syntax can be found in * http://arduino.cc/en/Reference/HomePage */ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; @@ -64,7 +64,7 @@ Blockly.Blocks["time_millis"] = { }, /** @return {string} The type of return value for the block, an integer. */ getBlockType: function () { - return Blockly.Types.LARGE_NUMBER; + return Types.LARGE_NUMBER; }, }; @@ -112,7 +112,7 @@ Blockly.Blocks["infinite_loop"] = { // this.setColour(getColour().time); // this.appendDummyInput().appendField(Blockly.Msg.senseBox_interval_timer); // this.appendDummyInput() -// .setAlign(Blockly.ALIGN_LEFT) +// .setAlign(Blockly.inputs.Align.LEFT) // .appendField(new Blockly.FieldTextInput("10000"), "interval") // .appendField(Blockly.Msg.senseBox_interval); // this.appendStatementInput("DO").setCheck(null); @@ -132,7 +132,7 @@ Blockly.Blocks["sensebox_interval_timer"] = { .appendField(new Blockly.FieldTextInput("Interval"), "name"); this.appendDummyInput() .appendField(Blockly.Msg.senseBox_interval_time) - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(new Blockly.FieldTextInput("10000"), "interval") .appendField(Blockly.Msg.senseBox_interval); this.appendStatementInput("DO").setCheck(null); diff --git a/src/components/Blockly/blocks/variables.js b/src/components/Blockly/blocks/variables.js index ff9009c0..9553dcc6 100644 --- a/src/components/Blockly/blocks/variables.js +++ b/src/components/Blockly/blocks/variables.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; import { getCompatibleTypes } from "../helpers/types"; diff --git a/src/components/Blockly/blocks/watchdog.js b/src/components/Blockly/blocks/watchdog.js index 09ce26d1..11e31611 100644 --- a/src/components/Blockly/blocks/watchdog.js +++ b/src/components/Blockly/blocks/watchdog.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; Blockly.Blocks["watchdog_enable"] = { diff --git a/src/components/Blockly/blocks/webserver.js b/src/components/Blockly/blocks/webserver.js index 4eefd50f..d49a3704 100644 --- a/src/components/Blockly/blocks/webserver.js +++ b/src/components/Blockly/blocks/webserver.js @@ -1,4 +1,4 @@ -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; import { getCompatibleTypes } from "../helpers/types"; import * as Types from "../helpers/types"; @@ -14,7 +14,7 @@ Blockly.Blocks["sensebox_initialize_http_server"] = { this.setColour(getColour().webserver); this.appendDummyInput().appendField(Blockly.Msg.senseBox_init_http_server); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField("Port") .appendField(new Blockly.FieldNumber(80), "Port"); this.setPreviousStatement(true, null); @@ -56,7 +56,7 @@ Blockly.Blocks["sensebox_http_method"] = { this.setHelpUrl("https://sensebox.de/books"); }, getBlockType: function () { - return Blockly.Types.TEXT; + return Types.TEXT; }, }; @@ -106,11 +106,11 @@ Blockly.Blocks["sensebox_generate_html_doc"] = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.senseBox_html_document); this.appendValueInput("HEADER") - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .setCheck(getCompatibleTypes("String")) .appendField(Blockly.Msg.senseBox_html_header); this.appendValueInput("BODY") - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .setCheck(getCompatibleTypes("String")) .appendField(Blockly.Msg.senseBox_html_body); this.setInputsInline(false); @@ -163,7 +163,7 @@ Blockly.Blocks["sensebox_general_html_tag"] = { this.setHelpUrl("https://sensebox.de/books"); this.setPreviousStatement(false); this.setNextStatement(false); - this.setMutator(new Blockly.Mutator(["additional_child"])); + this.setMutator(new Blockly.icons.MutatorIcon(["additional_child"])); this.additionalChildCount_ = 0; }, /** @@ -234,7 +234,11 @@ Blockly.Blocks["sensebox_general_html_tag"] = { this.updateShape_(); // Reconnect any child blocks. for (var i = 1; i <= this.additionalChildCount_; i++) { - Blockly.Mutator.reconnect(statementConnections[i], this, "DO" + i); + Blockly.icons.MutatorIcon.reconnect( + statementConnections[i], + this, + "DO" + i, + ); } }, /** @@ -274,7 +278,7 @@ Blockly.Blocks["sensebox_general_html_tag"] = { } // Rebuild block. for (i = 1; i <= this.additionalChildCount_; i++) { - this.appendValueInput("DO" + i, Blockly.Arduino.ORDER_NONE); + this.appendValueInput("DO" + i, Blockly.Generator.Arduino.ORDER_NONE); } }, }; @@ -308,9 +312,9 @@ Blockly.Blocks["sensebox_web_readHTML"] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.senseBox_sd_web_readHTML) - .setAlign(Blockly.ALIGN_LEFT); + .setAlign(Blockly.inputs.Align.LEFT); this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) + .setAlign(Blockly.inputs.Align.LEFT) .appendField(Blockly.Msg.sensebox_web_readHTML_filename) .appendField(new Blockly.FieldTextInput("index.txt"), "FILENAME"); this.setOutput(true, Types.TEXT.typeName); diff --git a/src/components/Blockly/generator/audio.js b/src/components/Blockly/generator/audio.js index f5e93a9c..3d2868a2 100644 --- a/src/components/Blockly/generator/audio.js +++ b/src/components/Blockly/generator/audio.js @@ -8,22 +8,22 @@ import * as Blockly from "blockly/core"; * @return {array} Completed code with order of operation. */ -Blockly.Arduino["io_tone"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_tone"] = function (block, generator) { var pin = block.getFieldValue("TONEPIN"); - var freq = Blockly.Arduino.valueToCode( + var freq = Blockly.Generator.Arduino.valueToCode( block, "FREQUENCY", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly.Arduino.setupCode_["io_tone" + pin] = + Blockly.Generator.Arduino.setupCode_["io_tone" + pin] = "pinMode(" + pin + ", OUTPUT);\n"; var code = "tone(" + pin + "," + freq + ");\n"; return code; }; -Blockly.Arduino["io_notone"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_notone"] = function (block, generator) { var pin = block.getFieldValue("TONEPIN"); - Blockly.Arduino.setupCode_["io_tone" + pin] = + Blockly.Generator.Arduino.setupCode_["io_tone" + pin] = "pinMode(" + pin + ", OUTPUT);\n"; var code = "noTone(" + pin + ");\n"; return code; diff --git a/src/components/Blockly/generator/generator.js b/src/components/Blockly/generator/generator.js index ea8fc50b..6d1ecec0 100644 --- a/src/components/Blockly/generator/generator.js +++ b/src/components/Blockly/generator/generator.js @@ -41,7 +41,7 @@ store.subscribe(() => { * Arduino code generator. * @type !Blockly.Generator */ -Blockly["Arduino"] = new Blockly.Generator("Arduino"); +Blockly.Generator.Arduino = new Blockly.Generator("Arduino"); /** * List of illegal variable names. @@ -50,7 +50,7 @@ Blockly["Arduino"] = new Blockly.Generator("Arduino"); * accidentally clobbering a built-in object or function. * @private */ -Blockly["Arduino"].addReservedWords( +Blockly.Generator.Arduino.addReservedWords( // http://arduino.cc/en/Reference/HomePage "setup,loop,if,else,for,switch,case,while," + "do,break,continue,return,goto,define,include," + @@ -69,25 +69,25 @@ Blockly["Arduino"].addReservedWords( * 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.Generator.Arduino.ORDER_ATOMIC = 0; // 0 "" ... +Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX = 1; // expr++ expr-- () [] . +Blockly.Generator.Arduino.ORDER_UNARY_PREFIX = 2; // -expr !expr ~expr ++expr --expr +Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE = 3; // * / % ~/ +Blockly.Generator.Arduino.ORDER_ADDITIVE = 4; // + - +Blockly.Generator.Arduino.ORDER_LOGICAL_NOT = 4.4; // ! +Blockly.Generator.Arduino.ORDER_SHIFT = 5; // << >> +Blockly.Generator.Arduino.ORDER_MODULUS = 5.3; // % +Blockly.Generator.Arduino.ORDER_RELATIONAL = 6; // is is! >= > <= < +Blockly.Generator.Arduino.ORDER_EQUALITY = 7; // === !== === !== +Blockly.Generator.Arduino.ORDER_BITWISE_AND = 8; // & +Blockly.Generator.Arduino.ORDER_BITWISE_XOR = 9; // ^ +Blockly.Generator.Arduino.ORDER_BITWISE_OR = 10; // | +Blockly.Generator.Arduino.ORDER_LOGICAL_AND = 11; // && +Blockly.Generator.Arduino.ORDER_LOGICAL_OR = 12; // || +Blockly.Generator.Arduino.ORDER_CONDITIONAL = 13; // expr ? expr : expr +Blockly.Generator.Arduino.ORDER_ASSIGNMENT = 14; // = *= /= ~/= %= += -= <<= >>= &= ^= |= +Blockly.Generator.Arduino.ORDER_COMMA = 18; // , +Blockly.Generator.Arduino.ORDER_NONE = 99; // (...) /** * @@ -100,45 +100,45 @@ Blockly["Arduino"].ORDER_NONE = 99; // (...) * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. */ -Blockly["Arduino"].init = function (workspace) { +Blockly.Generator.Arduino.init = function (workspace) { // Create a dictionary of definitions to be printed before the code. - Blockly["Arduino"].libraries_ = Object.create(null); + Blockly.Generator.Arduino.libraries_ = Object.create(null); - Blockly["Arduino"].definitions_ = Object.create(null); + Blockly.Generator.Arduino.definitions_ = Object.create(null); // creates a list of code to be setup before the setup block - Blockly["Arduino"].setupCode_ = Object.create(null); + Blockly.Generator.Arduino.setupCode_ = {}; // creates a list of code to be setup before the setup block - Blockly["Arduino"].phyphoxSetupCode_ = Object.create(null); + Blockly.Generator.Arduino.phyphoxSetupCode_ = Object.create(null); // creates a list of code to be setup before the setup block - Blockly["Arduino"].loraSetupCode_ = Object.create(null); + Blockly.Generator.Arduino.loraSetupCode_ = Object.create(null); // creates a list of code for the loop to be runned once - Blockly["Arduino"].loopCodeOnce_ = Object.create(null); + Blockly.Generator.Arduino.loopCodeOnce_ = Object.create(null); // creates a list of code for the loop to be runned once - Blockly["Arduino"].codeFunctions_ = Object.create(null); + Blockly.Generator.Arduino.codeFunctions_ = Object.create(null); // creates a list of code variables - Blockly["Arduino"].variables_ = Object.create(null); + Blockly.Generator.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); + Blockly.Generator.Arduino.functionNames_ = Object.create(null); - Blockly["Arduino"].variablesInitCode_ = ""; + Blockly.Generator.Arduino.variablesInitCode_ = ""; - if (!Blockly["Arduino"].nameDB_) { - Blockly["Arduino"].nameDB_ = new Blockly.Names( - Blockly["Arduino"].RESERVED_WORDS_, + if (!Blockly.Generator.Arduino.nameDB_) { + Blockly.Generator.Arduino.nameDB_ = new Blockly.Names( + Blockly.Generator.Arduino.RESERVED_WORDS_, ); } else { - Blockly["Arduino"].nameDB_.reset(); + Blockly.Generator.Arduino.nameDB_.reset(); } - Blockly["Arduino"].nameDB_.setVariableMap(workspace.getVariableMap()); + Blockly.Generator.Arduino.nameDB_.setVariableMap(workspace.getVariableMap()); // We don't have developer variables for now // // Add developer variables (not created or named by the user). @@ -154,7 +154,7 @@ Blockly["Arduino"].init = function (workspace) { * @param {string} code Generated code. * @return {string} Completed code. */ -Blockly["Arduino"].finish = function (code) { +Blockly.Generator.Arduino.finish = function (code) { let commentCode = ""; let libraryCode = ""; let variablesCode = ""; @@ -169,42 +169,43 @@ Blockly["Arduino"].finish = function (code) { let devVariables = "\n"; commentCode = "// Code generated by senseBox Blockly on " + new Date(); - for (const key in Blockly["Arduino"].libraries_) { - libraryCode += Blockly["Arduino"].libraries_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.libraries_) { + libraryCode += Blockly.Generator.Arduino.libraries_[key] + "\n"; } - for (const key in Blockly["Arduino"].variables_) { - variablesCode += Blockly["Arduino"].variables_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.variables_) { + variablesCode += Blockly.Generator.Arduino.variables_[key] + "\n"; } - for (const key in Blockly["Arduino"].definitions_) { - definitionsCode += Blockly["Arduino"].definitions_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.definitions_) { + definitionsCode += Blockly.Generator.Arduino.definitions_[key] + "\n"; } - for (const key in Blockly["Arduino"].loopCodeOnce_) { - loopCodeOnce += Blockly["Arduino"].loopCodeOnce_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.loopCodeOnce_) { + loopCodeOnce += Blockly.Generator.Arduino.loopCodeOnce_[key] + "\n"; } - for (const key in Blockly["Arduino"].codeFunctions_) { - codeFunctions += Blockly["Arduino"].codeFunctions_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.codeFunctions_) { + codeFunctions += Blockly.Generator.Arduino.codeFunctions_[key] + "\n"; } - for (const key in Blockly["Arduino"].functionNames_) { - functionsCode += Blockly["Arduino"].functionNames_[key] + "\n"; + for (const key in Blockly.Generator.Arduino.functionNames_) { + functionsCode += Blockly.Generator.Arduino.functionNames_[key] + "\n"; } - for (const key in Blockly["Arduino"].setupCode_) { - preSetupCode += Blockly["Arduino"].setupCode_[key] + "\n" || ""; + for (const key in Blockly.Generator.Arduino.setupCode_) { + preSetupCode += Blockly.Generator.Arduino.setupCode_[key] + "\n" || ""; } - for (const key in Blockly["Arduino"].loraSetupCode_) { - loraSetupCode += Blockly["Arduino"].loraSetupCode_[key] + "\n" || ""; + for (const key in Blockly.Generator.Arduino.loraSetupCode_) { + loraSetupCode += Blockly.Generator.Arduino.loraSetupCode_[key] + "\n" || ""; } setupCode = "\nvoid setup() { \n" + preSetupCode + "\n" + loraSetupCode + "\n}\n"; - for (const key in Blockly["Arduino"].phyphoxSetupCode_) { - phyphoxSetupCode += Blockly["Arduino"].phyphoxSetupCode_[key] + "\n" || ""; + for (const key in Blockly.Generator.Arduino.phyphoxSetupCode_) { + phyphoxSetupCode += + Blockly.Generator.Arduino.phyphoxSetupCode_[key] + "\n" || ""; } setupCode = @@ -234,7 +235,7 @@ Blockly["Arduino"].finish = function (code) { "\n" + codeFunctions + "\n" + - Blockly["Arduino"].variablesInitCode_ + + Blockly.Generator.Arduino.variablesInitCode_ + "\n" + functionsCode + "\n" + @@ -256,7 +257,7 @@ Blockly["Arduino"].finish = function (code) { "\n" + codeFunctions + "\n" + - Blockly["Arduino"].variablesInitCode_ + + Blockly.Generator.Arduino.variablesInitCode_ + "\n" + functionsCode + "\n" + @@ -266,14 +267,14 @@ Blockly["Arduino"].finish = function (code) { } // 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"].nameDB_.reset(); - - return Blockly["Arduino"].formatCode(code); + delete Blockly.Generator.Arduino.definitions_; + delete Blockly.Generator.Arduino.functionNames_; + delete Blockly.Generator.Arduino.loopCodeOnce_; + delete Blockly.Generator.Arduino.variablesInitCode_; + delete Blockly.Generator.Arduino.libraries_; + Blockly.Generator.Arduino.nameDB_.reset(); + + return Blockly.Generator.Arduino.formatCode(code); }; /** @@ -282,7 +283,7 @@ Blockly["Arduino"].finish = function (code) { * @param {string} line Line of generated code. * @return {string} Legal line of code. */ -Blockly["Arduino"].scrubNakedValue = function (line) { +Blockly.Generator.Arduino.scrubNakedValue = function (line) { return line + ";\n"; }; @@ -292,7 +293,7 @@ Blockly["Arduino"].scrubNakedValue = function (line) { * @param {string} code The Arduino code to format. * @return {string} Formatted Arduino code. */ -Blockly["Arduino"].formatCode = function (code) { +Blockly.Generator.Arduino.formatCode = function (code) { let formattedCode = ""; let indentLevel = 0; const indentSize = 2; // Number of spaces per indentation level @@ -341,7 +342,7 @@ Blockly["Arduino"].formatCode = function (code) { * @return {string} Arduino string. * @private */ -Blockly["Arduino"].quote_ = function (string) { +Blockly.Generator.Arduino.quote_ = function (string) { // Can't use goog.string.quote since Google's style guide recommends // JS string literals use single quotes. string = string @@ -361,7 +362,8 @@ Blockly["Arduino"].quote_ = function (string) { * @return {string} Arduino code with comments and subsequent blocks added. * @private */ -Blockly["Arduino"].scrub_ = function (block, code) { + +Blockly.Generator.Arduino.scrub_ = function (block, code) { let commentCode = ""; // Only collect comments for blocks that aren't inline. if (!block.outputConnection || !block.outputConnection.targetConnection) { @@ -369,17 +371,23 @@ Blockly["Arduino"].scrub_ = function (block, code) { let comment = block.getCommentText(); //@ts-ignore comment = comment - ? Blockly.utils.string.wrap(comment, Blockly["Arduino"].COMMENT_WRAP - 3) + ? Blockly.utils.string.wrap( + comment, + Blockly.Generator.Arduino.COMMENT_WRAP - 3, + ) : null; if (comment) { if (block.getProcedureDef) { // Use a comment block for function comments. commentCode += "/**\n" + - Blockly["Arduino"].prefixLines(comment + "\n", " * ") + + Blockly.Generator.Arduino.prefixLines(comment + "\n", " * ") + " */\n"; } else { - commentCode += Blockly["Arduino"].prefixLines(comment + "\n", "// "); + commentCode += Blockly.Generator.Arduino.prefixLines( + comment + "\n", + "// ", + ); } } // Collect comments for all value arguments. @@ -388,15 +396,19 @@ Blockly["Arduino"].scrub_ = function (block, code) { if (block.inputList[i].type === Blockly.INPUT_VALUE) { const childBlock = block.inputList[i].connection.targetBlock(); if (childBlock) { - const comment = Blockly["Arduino"].allNestedComments(childBlock); + const comment = + Blockly.Generator.Arduino.allNestedComments(childBlock); if (comment) { - commentCode += Blockly["Arduino"].prefixLines(comment, "// "); + commentCode += Blockly.Generator.Arduino.prefixLines( + comment, + "// ", + ); } } } } } const nextBlock = block.nextConnection && block.nextConnection.targetBlock(); - const nextCode = Blockly["Arduino"].blockToCode(nextBlock); + const nextCode = Blockly.Generator.Arduino.blockToCode(nextBlock); return commentCode + code + nextCode; }; diff --git a/src/components/Blockly/generator/io.js b/src/components/Blockly/generator/io.js index e2b41a25..f3ebb921 100644 --- a/src/components/Blockly/generator/io.js +++ b/src/components/Blockly/generator/io.js @@ -7,15 +7,19 @@ import * as Blockly from "blockly/core"; * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["io_digitalwrite"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_digitalwrite"] = function ( + block, + generator, +) { var pin = block.getFieldValue("PIN"); var stateOutput = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "STATE", - Blockly["Arduino"].ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "LOW"; - Blockly["Arduino"].setupCode_["pinMode"] = "pinMode(" + pin + ", OUTPUT);"; + Blockly.Generator.Arduino.setupCode_["pinMode"] = + "pinMode(" + pin + ", OUTPUT);"; var code = "digitalWrite(" + pin + ", " + stateOutput + ");\n"; return code; }; @@ -27,12 +31,15 @@ Blockly.Arduino["io_digitalwrite"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["io_digitalread"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_digitalread"] = function ( + block, + generator, +) { var pin = block.getFieldValue("PIN"); - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pinMode(" + pin + ", INPUT);"; var code = "digitalRead(" + pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -42,12 +49,18 @@ Blockly.Arduino["io_digitalread"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["io_builtin_led"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_builtin_led"] = function ( + block, + generator, +) { var pin = block.getFieldValue("BUILT_IN_LED"); var stateOutput = - Blockly.Arduino.valueToCode(block, "STATE", Blockly.Arduino.ORDER_ATOMIC) || - "LOW"; - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.valueToCode( + block, + "STATE", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "LOW"; + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pindMode(" + pin + "OUTPUT);"; var code = "digitalWrite(" + pin + ", " + stateOutput + ");\n"; return code; @@ -60,12 +73,18 @@ Blockly.Arduino["io_builtin_led"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["io_analogwrite"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_analogwrite"] = function ( + block, + generator, +) { var pin = block.getFieldValue("PIN"); var stateOutput = - Blockly.Arduino.valueToCode(block, "NUM", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pinMode(" + pin + ", OUTPUT);"; // Warn if the input value is out of range if (stateOutput < 0 || stateOutput > 255) { @@ -87,12 +106,15 @@ Blockly.Arduino["io_analogwrite"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["io_analogread"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_analogread"] = function ( + block, + generator, +) { var pin = block.getFieldValue("PIN"); - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pinMode(" + pin + ", INPUT);"; var code = "analogRead(" + pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -101,43 +123,49 @@ Blockly.Arduino["io_analogread"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["io_highlow"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_highlow"] = function (block, generator) { var code = block.getFieldValue("STATE"); - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["io_pulsein"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_pulsein"] = function (block, generator) { var pin = block.getFieldValue("PULSEPIN"); - var type = Blockly.Arduino.valueToCode( + var type = Blockly.Generator.Arduino.valueToCode( block, "PULSETYPE", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pinMode(" + pin + ", INPUT);"; var code = "pulseIn(" + pin + ", " + type + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["io_pulsetimeout"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_pulsetimeout"] = function ( + block, + generator, +) { var pin = block.getFieldValue("PULSEPIN"); - var type = Blockly.Arduino.valueToCode( + var type = Blockly.Generator.Arduino.valueToCode( block, "PULSETYPE", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var timeout = Blockly.Arduino.valueToCode( + var timeout = Blockly.Generator.Arduino.valueToCode( block, "TIMEOUT", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly["Arduino"].setupCode_["pinMode" + pin] = + Blockly.Generator.Arduino.setupCode_["pinMode" + pin] = "pinMode(" + pin + ", INPUT);"; var code = "pulseIn(" + pin + ", " + type + ", " + timeout + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["io_analogreadmillivolt"] = function (block) { +Blockly.Generator.Arduino.forBlock["io_analogreadmillivolt"] = function ( + block, + generator, +) { var dropdown_port = this.getFieldValue("Port"); var pin = 1; switch (dropdown_port) { @@ -161,5 +189,5 @@ Blockly.Arduino["io_analogreadmillivolt"] = function (block) { } var code = "analogReadMilliVolts(" + pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/generator/lists.js b/src/components/Blockly/generator/lists.js index 1311cfab..6b67ff4d 100644 --- a/src/components/Blockly/generator/lists.js +++ b/src/components/Blockly/generator/lists.js @@ -1,21 +1,30 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino["lists_create_empty"] = function () { +Blockly.Generator.Arduino.forBlock["lists_create_empty"] = function ( + block, + generator, +) { var code = ""; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["array_getIndex"] = function () { +Blockly.Generator.Arduino.forBlock["array_getIndex"] = function ( + block, + generator, +) { var code = ""; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["lists_length"] = function () { - var array = Blockly.Arduino.valueToCode( +Blockly.Generator.Arduino.forBlock["lists_length"] = function ( + block, + generator, +) { + var array = Blockly.Generator.Arduino.valueToCode( this, "ARRAY", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); var code = `${array}.length`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/generator/logic.js b/src/components/Blockly/generator/logic.js index 4b4ecb67..9997b164 100644 --- a/src/components/Blockly/generator/logic.js +++ b/src/components/Blockly/generator/logic.js @@ -1,12 +1,18 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino["logic_boolean"] = function (Block) { +Blockly.Generator.Arduino.forBlock["logic_boolean"] = function ( + block, + generator, +) { // Boolean values true and false. const code = Block.getFieldValue("BOOL") === "TRUE" ? "true" : "false"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["logic_compare"] = function (Block) { +Blockly.Generator.Arduino.forBlock["logic_compare"] = function ( + block, + generator, +) { // Comparison operator. const OPERATORS = { EQ: "==", @@ -19,23 +25,28 @@ Blockly.Arduino["logic_compare"] = function (Block) { const operator = OPERATORS[Block.getFieldValue("OP")]; const order = operator === "==" || operator === "!=" - ? Blockly.Arduino.ORDER_EQUALITY - : Blockly.Arduino.ORDER_RELATIONAL; - const argument0 = Blockly.Arduino.valueToCode(Block, "A", order) || "0"; - const argument1 = Blockly.Arduino.valueToCode(Block, "B", order) || "0"; + ? Blockly.Generator.Arduino.ORDER_EQUALITY + : Blockly.Generator.Arduino.ORDER_RELATIONAL; + const argument0 = + Blockly.Generator.Arduino.valueToCode(Block, "A", order) || "0"; + const argument1 = + Blockly.Generator.Arduino.valueToCode(Block, "B", order) || "0"; const code = "( " + argument0 + " " + operator + " " + argument1 + ")"; return [code, order]; }; -Blockly.Arduino["logic_operation"] = function (Block) { +Blockly.Generator.Arduino.forBlock["logic_operation"] = function ( + block, + generator, +) { // Operations 'and', 'or'. const operator = Block.getFieldValue("OP") === "AND" ? "&&" : "||"; const order = operator === "&&" - ? Blockly.Arduino.ORDER_LOGICAL_AND - : Blockly.Arduino.ORDER_LOGICAL_OR; - let argument0 = Blockly.Arduino.valueToCode(Block, "A", order); - let argument1 = Blockly.Arduino.valueToCode(Block, "B", order); + ? Blockly.Generator.Arduino.ORDER_LOGICAL_AND + : Blockly.Generator.Arduino.ORDER_LOGICAL_OR; + let argument0 = Blockly.Generator.Arduino.valueToCode(Block, "A", order); + let argument1 = Blockly.Generator.Arduino.valueToCode(Block, "B", order); if (!argument0 && !argument1) { // If there are no arguments, then the return value is false. argument0 = "false"; @@ -54,7 +65,10 @@ Blockly.Arduino["logic_operation"] = function (Block) { return [code, order]; }; -Blockly.Arduino["controls_if"] = function (Block) { +Blockly.Generator.Arduino.forBlock["controls_if"] = function ( + block, + generator, +) { // If/elseif/else condition. let n = 0; let code = "", @@ -62,12 +76,12 @@ Blockly.Arduino["controls_if"] = function (Block) { conditionCode; do { conditionCode = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "IF" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ) || "false"; - branchCode = Blockly.Arduino.statementToCode(Block, "DO" + n); + branchCode = Blockly.Generator.Arduino.statementToCode(Block, "DO" + n); code += (n > 0 ? " else " : "") + "if (" + @@ -80,13 +94,16 @@ Blockly.Arduino["controls_if"] = function (Block) { } while (Block.getInput("IF" + n)); if (Block.getInput("ELSE")) { - branchCode = Blockly.Arduino.statementToCode(Block, "ELSE"); + branchCode = Blockly.Generator.Arduino.statementToCode(Block, "ELSE"); code += " else {\n" + branchCode + "}\n"; } return code + "\n"; }; -Blockly.Arduino["controls_ifelse"] = function (Block) { +Blockly.Generator.Arduino.forBlock["controls_ifelse"] = function ( + block, + generator, +) { // If/elseif/else condition. let n = 0; let code = "", @@ -94,12 +111,12 @@ Blockly.Arduino["controls_ifelse"] = function (Block) { conditionCode; do { conditionCode = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "IF" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ) || "false"; - branchCode = Blockly.Arduino.statementToCode(Block, "DO" + n); + branchCode = Blockly.Generator.Arduino.statementToCode(Block, "DO" + n); code += (n > 0 ? " else " : "") + "if (" + @@ -112,45 +129,55 @@ Blockly.Arduino["controls_ifelse"] = function (Block) { } while (Block.getInput("IF" + n)); if (Block.getInput("ELSE")) { - branchCode = Blockly.Arduino.statementToCode(Block, "ELSE"); + branchCode = Blockly.Generator.Arduino.statementToCode(Block, "ELSE"); code += " else {\n" + branchCode + "}\n"; } return code + "\n"; }; -Blockly.Arduino["logic_negate"] = function (Block) { +Blockly.Generator.Arduino.forBlock["logic_negate"] = function ( + block, + generator, +) { // Negation. - const order = Blockly.Arduino.ORDER_UNARY_PREFIX; - const argument0 = Blockly.Arduino.valueToCode(Block, "BOOL", order) || "true"; + const order = Blockly.Generator.Arduino.ORDER_UNARY_PREFIX; + const argument0 = + Blockly.Generator.Arduino.valueToCode(Block, "BOOL", order) || "true"; const code = "!" + argument0; return [code, order]; }; -Blockly.Arduino["switch_case"] = function (block) { +Blockly.Generator.Arduino.forBlock["switch_case"] = function ( + block, + generator, +) { var n = 0; var argument = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "CONDITION", - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ) || ""; - var branch = Blockly.Arduino.statementToCode(block, "CASECONDITON0" + n); + var branch = Blockly.Generator.Arduino.statementToCode( + block, + "CASECONDITON0" + n, + ); var cases = ""; var default_code = ""; - var DO = Blockly.Arduino.statementToCode(block, "CASE" + n); + var DO = Blockly.Generator.Arduino.statementToCode(block, "CASE" + n); for (n = 0; n <= block.caseCount_; n++) { - DO = Blockly.Arduino.statementToCode(block, "CASE" + n); + DO = Blockly.Generator.Arduino.statementToCode(block, "CASE" + n); branch = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "CASECONDITION" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ) || "0"; cases += "case " + branch + ":\n"; cases += DO + "\nbreak;\n"; } if (block.defaultCount_) { - branch = Blockly.Arduino.statementToCode(block, "ONDEFAULT"); + branch = Blockly.Generator.Arduino.statementToCode(block, "ONDEFAULT"); default_code = "default: \n" + branch + "\n break;\n"; } var code = "switch (" + argument + ") {\n" + cases + default_code + "}"; diff --git a/src/components/Blockly/generator/loops.js b/src/components/Blockly/generator/loops.js index a7b7b0fe..d5ffb04c 100644 --- a/src/components/Blockly/generator/loops.js +++ b/src/components/Blockly/generator/loops.js @@ -1,17 +1,20 @@ import * as Blockly from "blockly/core"; -Blockly["Arduino"]["controls_repeat_ext"] = function (Block) { +Blockly.Generator.Arduino.forBlock["controls_repeat_ext"] = function ( + block, + generator, +) { // Repeat n times. const repeats = - Blockly["Arduino"].valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "TIMES", - Blockly["Arduino"].ORDER_ASSIGNMENT, + Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; - let branch = Blockly["Arduino"].statementToCode(Block, "DO"); - branch = Blockly["Arduino"].addLoopTrap(branch, Block.id); + let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); let code = ""; const loopVar = "i"; code += @@ -30,40 +33,46 @@ Blockly["Arduino"]["controls_repeat_ext"] = function (Block) { return code; }; -Blockly["Arduino"]["controls_for"] = function (Block) { - const loopIndexVariable = Blockly.mainWorkspace.getVariableById( +Blockly.Generator.Arduino.forBlock["controls_for"] = function ( + block, + generator, +) { + const loopIndexVariable = Blockly.getMainWorkspace().getVariableById( Block.getFieldValue("VAR"), ).name; const allVars = Blockly.getMainWorkspace().getVariableMap().getAllVariables(); const myVar = allVars.filter((v) => v.name === loopIndexVariable)[0]; var initVariable = ""; - if (Blockly.Arduino.variables_[loopIndexVariable + myVar.type] == undefined) { + if ( + Blockly.Generator.Arduino.variables_[loopIndexVariable + myVar.type] == + undefined + ) { initVariable = "int "; // alternatively set to 'myVar.type' but that could lead to issues if users choose a char or a boolean } - const branch = Blockly["Arduino"].statementToCode(Block, "DO"); + const branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); const startNumber = - Blockly["Arduino"].valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "FROM", - Blockly["Arduino"].ORDER_ASSIGNMENT, + Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; const toNumber = - Blockly["Arduino"].valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "TO", - Blockly["Arduino"].ORDER_ASSIGNMENT, + Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; let byNumber = Math.abs( parseInt( - Blockly["Arduino"].valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "BY", - Blockly["Arduino"].ORDER_ASSIGNMENT, + Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ), ), ); @@ -94,24 +103,30 @@ Blockly["Arduino"]["controls_for"] = function (Block) { ); }; -Blockly["Arduino"]["controls_whileUntil"] = function (Block) { +Blockly.Generator.Arduino.forBlock["controls_whileUntil"] = function ( + block, + generator, +) { // Do while/until loop. const until = Block.getFieldValue("MODE") === "UNTIL"; let argument0 = - Blockly["Arduino"].valueToCode( + Blockly.Generator.Arduino.valueToCode( Block, "BOOL", - Blockly["Arduino"].ORDER_LOGICAL_AND, + Blockly.Generator.Arduino.ORDER_LOGICAL_AND, ) || "false"; - let branch = Blockly["Arduino"].statementToCode(Block, "DO"); - branch = Blockly["Arduino"].addLoopTrap(branch, Block.id); + let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); if (until) { argument0 = "!" + argument0; } return "\twhile (" + argument0 + ") {\n" + branch + "\t}\n"; }; -Blockly["Arduino"]["controls_flow_statements"] = function (Block) { +Blockly.Generator.Arduino.forBlock["controls_flow_statements"] = function ( + block, + generator, +) { // Flow statements: continue, break. switch (Block.getFieldValue("FLOW")) { case "BREAK": diff --git a/src/components/Blockly/generator/map.js b/src/components/Blockly/generator/map.js index e9803dc3..93be69a6 100644 --- a/src/components/Blockly/generator/map.js +++ b/src/components/Blockly/generator/map.js @@ -6,22 +6,37 @@ 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["base_map"] = function (block) { +Blockly.Generator.Arduino.forBlock["base_map"] = function (block, generator) { var valueNum = - Blockly.Arduino.valueToCode(block, "NUM", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; var fromMin = - Blockly.Arduino.valueToCode(block, "FMIN", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "FMIN", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var fromMax = - Blockly.Arduino.valueToCode(block, "FMAX", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "FMAX", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var valueDmin = - Blockly.Arduino.valueToCode(block, "DMIN", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "DMIN", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var valueDmax = - Blockly.Arduino.valueToCode(block, "DMAX", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "DMAX", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var code = "map(" + @@ -35,5 +50,5 @@ Blockly.Arduino["base_map"] = function (block) { "," + valueDmax + ")"; - return [code, Blockly.Arduino.ORDER_NONE]; + return [code, Blockly.Generator.Arduino.ORDER_NONE]; }; diff --git a/src/components/Blockly/generator/math.js b/src/components/Blockly/generator/math.js index 768acca6..8a72e250 100644 --- a/src/components/Blockly/generator/math.js +++ b/src/components/Blockly/generator/math.js @@ -18,7 +18,10 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_number"] = function ( + block, + generator, +) { // Numeric value. var code = parseFloat(block.getFieldValue("NUM")); if (code === Infinity) { @@ -26,7 +29,7 @@ Blockly.Arduino["math_number"] = function (block) { } else if (code === -Infinity) { code = "-INFINITY"; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -36,24 +39,29 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function ( + block, + generator, +) { 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. + ADD: [" + ", Blockly.Generator.Arduino.ORDER_ADDITIVE], + MINUS: [" - ", Blockly.Generator.Arduino.ORDER_ADDITIVE], + MULTIPLY: [" * ", Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE], + DIVIDE: [" / ", Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE], + POWER: [null, Blockly.Generator.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 argument0 = + Blockly.Generator.Arduino.valueToCode(block, "A", order) || "0"; + var argument1 = + Blockly.Generator.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]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } code = argument0 + operator + argument1; return [code, order]; @@ -65,43 +73,49 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_single"] = function ( + block, + generator, +) { 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( + Blockly.Generator.Arduino.valueToCode( block, "NUM", - Blockly.Arduino.ORDER_UNARY_PREFIX, + Blockly.Generator.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]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_PREFIX]; } if (operator === "ABS" || operator.substring(0, 5) === "ROUND") { arg = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "NUM", - Blockly.Arduino.ORDER_UNARY_POSTFIX, + Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, ) || "0"; } else if (operator === "SIN" || operator === "COS" || operator === "TAN") { arg = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "NUM", - Blockly.Arduino.ORDER_MULTIPLICATIVE, + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, ) || "0"; } else { arg = - Blockly.Arduino.valueToCode(block, "NUM", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; } // First, handle cases which generate values that don't need parentheses. switch (operator) { @@ -142,7 +156,7 @@ Blockly.Arduino["math_single"] = function (block) { break; } if (code) { - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } // Second, handle cases which generate values that may need parentheses. switch (operator) { @@ -161,7 +175,7 @@ Blockly.Arduino["math_single"] = function (block) { default: throw new Error("Unknown math operator: " + operator); } - return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; + return [code, Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE]; }; /** @@ -173,14 +187,20 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_constant"] = function ( + block, + generator, +) { 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], + PI: ["M_PI", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], + E: ["M_E", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], + GOLDEN_RATIO: [ + "(1 + sqrt(5)) / 2", + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, + ], + SQRT2: ["M_SQRT2", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], + SQRT1_2: ["M_SQRT1_2", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], + INFINITY: ["INFINITY", Blockly.Generator.Arduino.ORDER_ATOMIC], }; return CONSTANTS[block.getFieldValue("CONSTANT")]; }; @@ -192,18 +212,21 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_number_property"] = function ( + block, + generator, +) { var number_to_check = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "NUMBER_TO_CHECK", - Blockly.Arduino.ORDER_MULTIPLICATIVE, + Blockly.Generator.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) {", + "boolean " + Blockly.Generator.Arduino.DEF_FUNC_NAME + "(int n) {", " // https://en.wikipedia.org/wiki/Primality_test#Naive_methods", " if (n == 2 || n == 3) {", " return true;", @@ -223,10 +246,13 @@ Blockly.Arduino["math_number_property"] = function (block) { " return true;", "}", ]; - var funcName = Blockly.Arduino.addFunction("mathIsPrime", func.join("\n")); - Blockly.Arduino.addInclude("math", "#include "); + var funcName = Blockly.Generator.Arduino.addFunction( + "mathIsPrime", + func.join("\n"), + ); + Blockly.Generator.Arduino.addInclude("math", "#include "); code = funcName + "(" + number_to_check + ")"; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } switch (dropdown_property) { case "EVEN": @@ -236,7 +262,7 @@ Blockly.Arduino["math_number_property"] = function (block) { code = number_to_check + " % 2 == 1"; break; case "WHOLE": - Blockly.Arduino.addInclude("math", "#include "); + Blockly.Generator.Arduino.addInclude("math", "#include "); code = "(floor(" + number_to_check + ") == " + number_to_check + ")"; break; case "POSITIVE": @@ -247,17 +273,17 @@ Blockly.Arduino["math_number_property"] = function (block) { break; case "DIVISIBLE_BY": var divisor = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DIVISOR", - Blockly.Arduino.ORDER_MULTIPLICATIVE, + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, ) || "0"; code = number_to_check + " % " + divisor + " == 0"; break; default: break; } - return [code, Blockly.Arduino.ORDER_EQUALITY]; + return [code, Blockly.Generator.Arduino.ORDER_EQUALITY]; }; /** @@ -268,19 +294,22 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_change"] = function ( + block, + generator, +) { var argument0 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DELTA", - Blockly.Arduino.ORDER_ADDITIVE, + Blockly.Generator.Arduino.ORDER_ADDITIVE, ) || "0"; var id = block.getFieldValue("VAR"); const varName = Blockly.Variables.getVariable( Blockly.getMainWorkspace(), id, ).name; - // var varName = Blockly.Arduino.nameDB_.getName( + // var varName = Blockly.Generator.Arduino.nameDB_.getName( // block.getFieldValue("VAR"), // Blockly.Variables.NAME_TYPE // ); @@ -288,10 +317,12 @@ Blockly.Arduino["math_change"] = function (block) { }; /** Rounding functions have a single operand. */ -Blockly.Arduino["math_round"] = Blockly.Arduino["math_single"]; +Blockly.Generator.Arduino["math_round"] = + Blockly.Generator.Arduino["math_single"]; /** Trigonometry functions have a single operand. */ -Blockly.Arduino["math_trig"] = Blockly.Arduino["math_single"]; +Blockly.Generator.Arduino["math_trig"] = + Blockly.Generator.Arduino["math_single"]; /** * Generator for the math function to a list. @@ -300,7 +331,8 @@ 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.Generator.Arduino["math_on_list"] = + Blockly.Generator.Arduino.noGeneratorCodeInline; /** * Generator for the math modulo function (calculates remainder of X/Y). @@ -308,21 +340,24 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_modulo"] = function ( + block, + generator, +) { var argument0 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DIVIDEND", - Blockly.Arduino.ORDER_MULTIPLICATIVE, + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, ) || "0"; var argument1 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DIVISOR", - Blockly.Arduino.ORDER_MULTIPLICATIVE, + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, ) || "0"; var code = argument0 + " % " + argument1; - return [code, Blockly.Arduino.ORDER_MULTIPLICATIVE]; + return [code, Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE]; }; /** @@ -331,17 +366,29 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_constrain"] = function ( + block, + generator, +) { // Constrain a number between two limits. var argument0 = - Blockly.Arduino.valueToCode(block, "VALUE", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "VALUE", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; var argument1 = - Blockly.Arduino.valueToCode(block, "LOW", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "LOW", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; var argument2 = - Blockly.Arduino.valueToCode(block, "HIGH", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "HIGH", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; var code = "(" + argument0 + @@ -358,7 +405,7 @@ Blockly.Arduino["math_constrain"] = function (block) { " : " + argument0 + "))"; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; }; /** @@ -368,14 +415,25 @@ 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) { +Blockly.Generator.Arduino.forBlock["math_random_int"] = function ( + block, + generator, +) { var argument0 = - Blockly.Arduino.valueToCode(block, "FROM", Blockly.Arduino.ORDER_NONE) || - "0"; + Blockly.Generator.Arduino.valueToCode( + block, + "FROM", + Blockly.Generator.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"] = + Blockly.Generator.Arduino.valueToCode( + block, + "TO", + Blockly.Generator.Arduino.ORDER_NONE, + ) || "0"; + Blockly.Generator.Arduino.setupCode_["init_rand"] = + "randomSeed(analogRead(0));"; + Blockly.Generator.Arduino.functionNames_["math_random_int"] = `int mathRandomInt (int min, int max) {\n if (min > max) { int temp = min; @@ -386,7 +444,7 @@ Blockly.Arduino["math_random_int"] = function (block) { } `; var code = `mathRandomInt(${argument0},${argument1})`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -395,6 +453,9 @@ 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.Generator.Arduino.forBlock["math_random_float"] = function ( + block, + generator, +) { + return ["(rand() / RAND_MAX)", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; }; diff --git a/src/components/Blockly/generator/mqtt.js b/src/components/Blockly/generator/mqtt.js index aadf3420..3502b5ee 100644 --- a/src/components/Blockly/generator/mqtt.js +++ b/src/components/Blockly/generator/mqtt.js @@ -5,42 +5,48 @@ import * as Blockly from "blockly/core"; let service; -Blockly.Arduino.sensebox_mqtt_setup = function () { +Blockly.Generator.Arduino.forBlock["sensebox_mqtt_setup"] = function () { var server = this.getFieldValue("server"); var port = this.getFieldValue("port"); var username = this.getFieldValue("username"); var pass = this.getFieldValue("password"); service = this.getFieldValue("service"); - Blockly.Arduino.libraries_["library_adafruitmqtt"] = + Blockly.Generator.Arduino.libraries_["library_adafruitmqtt"] = '#include //http://librarymanager/All#Adafruit_MQTT_Library"'; - Blockly.Arduino.libraries_["library_adafruitmqttclient"] = + Blockly.Generator.Arduino.libraries_["library_adafruitmqttclient"] = "#include "; - Blockly.Arduino.definitions_["mqtt_server"] = + Blockly.Generator.Arduino.definitions_["mqtt_server"] = '#define SERVER "' + server + '"'; - Blockly.Arduino.definitions_["mqtt_port"] = + Blockly.Generator.Arduino.definitions_["mqtt_port"] = "#define SERVERPORT " + port + ""; - Blockly.Arduino.definitions_["mqtt_username"] = + Blockly.Generator.Arduino.definitions_["mqtt_username"] = '#define USERNAME "' + username + '"'; - Blockly.Arduino.definitions_["mqtt_pass"] = + Blockly.Generator.Arduino.definitions_["mqtt_pass"] = '#define PASS "' + pass + '"'; - Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;"; - Blockly.Arduino.definitions_["mqtt_client"] = + Blockly.Generator.Arduino.definitions_["WiFiClient"] = "WiFiClient client;"; + Blockly.Generator.Arduino.definitions_["mqtt_client"] = "Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PASS);"; var code = ""; return code; }; -Blockly.Arduino.sensebox_mqtt_publish = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_mqtt_publish"] = function ( + block, + generator, +) { var feedname = this.getFieldValue("publishfeed"); var res = feedname.split("/"); var feed_client = res[res.length - 1]; var value = - Blockly.Arduino.valueToCode(this, "value", Blockly.Arduino.ORDER_ATOMIC) || - '"No Block connected"'; + Blockly.Generator.Arduino.valueToCode( + this, + "value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"No Block connected"'; switch (service) { case "adafruitio": - Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] = + Blockly.Generator.Arduino.definitions_["mqtt_" + feed_client + ""] = "Adafruit_MQTT_Publish " + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + @@ -48,7 +54,7 @@ Blockly.Arduino.sensebox_mqtt_publish = function (block) { '");'; break; case "dioty": - Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] = + Blockly.Generator.Arduino.definitions_["mqtt_" + feed_client + ""] = "Adafruit_MQTT_Publish " + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, "/"USERNAME"/' + @@ -56,7 +62,7 @@ Blockly.Arduino.sensebox_mqtt_publish = function (block) { '");'; break; case "custom": - Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] = + Blockly.Generator.Arduino.definitions_["mqtt_" + feed_client + ""] = "Adafruit_MQTT_Publish " + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, "' + @@ -67,8 +73,8 @@ Blockly.Arduino.sensebox_mqtt_publish = function (block) { break; } - //Blockly.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");' - Blockly.Arduino.codeFunctions_["mqtt_connect_function"] = + //Blockly.Generator.Arduino.definitions_['mqtt_' + feed_client + ''] = 'Adafruit_MQTT_Publish ' + feed_client + ' = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/' + feedname + '");' + Blockly.Generator.Arduino.codeFunctions_["mqtt_connect_function"] = `// Function to connect and reconnect as necessary to the MQTT server. // Should be called in the loop function and it will take care if connecting. void MQTT_connect() { @@ -82,33 +88,38 @@ void MQTT_connect() { delay(5000); // wait 5 seconds } }`; - Blockly.Arduino.loopCodeOnce_["mqtt_connect"] = "MQTT_connect();"; + Blockly.Generator.Arduino.loopCodeOnce_["mqtt_connect"] = "MQTT_connect();"; var code = "" + feed_client + ".publish(" + value + ");"; return code; }; -Blockly.Arduino.sensebox_mqtt_subscribe = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_mqtt_subscribe"] = function ( + block, + generator, +) { var feedname = this.getFieldValue("subscribefeed"); var x = 5, feed_client; feed_client = feedname.substr(feedname.length - x, x); - Blockly.Arduino.definitions_["mqtt_" + feed_client + ""] = + Blockly.Generator.Arduino.definitions_["mqtt_" + feed_client + ""] = "Adafruit_MQTT_Subscribe " + feed_client + "= Adafruit_MQTT_Subscribe(&mqtt," + feedname + ");"; - Blockly.Arduino.codeFunctions_["mqtt_" + feed_client + "callbackFunction"] = + Blockly.Generator.Arduino.codeFunctions_[ + "mqtt_" + feed_client + "callbackFunction" + ] = `void ` + feed_client + `Callback (double x){ Serial.println(x); }`; - Blockly.Arduino.setupCode_["mqtt_" + feed_client + "_callback"] = + Blockly.Generator.Arduino.setupCode_["mqtt_" + feed_client + "_callback"] = "" + feed_client + ".setCallback(" + feed_client + "Callback);"; - Blockly.Arduino.setupCode_["mqtt_" + feed_client + "_subscribe"] = + Blockly.Generator.Arduino.setupCode_["mqtt_" + feed_client + "_subscribe"] = "mqtt.subscribe(&" + feed_client + ");"; - Blockly.Arduino.loopCodeOnce_["mqtt_processPackages"] = + Blockly.Generator.Arduino.loopCodeOnce_["mqtt_processPackages"] = "mqtt.processPackets(10);"; var code = ""; return code; diff --git a/src/components/Blockly/generator/procedures.js b/src/components/Blockly/generator/procedures.js index bf2f5720..d71ffca7 100644 --- a/src/components/Blockly/generator/procedures.js +++ b/src/components/Blockly/generator/procedures.js @@ -7,17 +7,20 @@ import * as Blockly from "blockly/core"; * @return {string} Completed code. */ -Blockly.Arduino["arduino_functions"] = function (block) { +Blockly.Generator.Arduino.forBlock["arduino_functions"] = function ( + block, + generator, +) { var board = window.sessionStorage.getItem("board"); if (board === "mcu" || board === "mini") { - Blockly.Arduino.libraries_["library_senseBoxIO"] = + Blockly.Generator.Arduino.libraries_["library_senseBoxIO"] = "#include "; } // Edited version of Blockly.Generator.prototype.statementToCode function statementToCodeNoTab(block, name) { var targetBlock = block.getInputTargetBlock(name); - var code = Blockly.Arduino.blockToCode(targetBlock); + var code = Blockly.Generator.Arduino.blockToCode(targetBlock); if (typeof code != "string") { throw new Error( 'Expecting code from statement block "' + targetBlock.type + '".', @@ -26,31 +29,41 @@ Blockly.Arduino["arduino_functions"] = function (block) { return code; } - var setupBranch = Blockly.Arduino.statementToCode(block, "SETUP_FUNC"); - // //var setupCode = Blockly.Arduino.scrub_(block, setupBranch); No comment block + var setupBranch = Blockly.Generator.Arduino.statementToCode( + block, + "SETUP_FUNC", + ); + // //var setupCode = Blockly.Generator.Arduino.scrub_(block, setupBranch); No comment block if (setupBranch) { - Blockly.Arduino.setupCode_["mainsetup"] = setupBranch; + Blockly.Generator.Arduino.setupCode_["mainsetup"] = setupBranch; } var loopBranch = statementToCodeNoTab(block, "LOOP_FUNC"); - //var loopcode = Blockly.Arduino.scrub_(block, loopBranch); No comment block + //var loopcode = Blockly.Generator.Arduino.scrub_(block, loopBranch); No comment block return loopBranch; }; -Blockly.Arduino["procedures_defreturn"] = function (block) { +Blockly.Generator.Arduino.forBlock["procedures_defreturn"] = function ( + block, + generator, +) { // Define a procedure with a return value. - const funcName = Blockly.Arduino.nameDB_.getName( + const funcName = Blockly.Generator.Arduino.nameDB_.getName( block.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE, ); - const branch = Blockly.Arduino.statementToCode(block, "STACK"); + const branch = Blockly.Generator.Arduino.statementToCode(block, "STACK"); const returnType = block.getFieldValue("RETURN TYPE") || "void"; let returnValue = - Blockly.Arduino.valueToCode(block, "RETURN", Blockly.Arduino.ORDER_NONE) || - ""; + Blockly.Generator.Arduino.valueToCode( + block, + "RETURN", + Blockly.Generator.Arduino.ORDER_NONE, + ) || ""; if (returnValue) { - returnValue = Blockly.Arduino.INDENT + "return " + returnValue + ";\n"; + returnValue = + Blockly.Generator.Arduino.INDENT + "return " + returnValue + ";\n"; } const args = []; for (let i = 0; i < block.argumentVarModels_.length; i++) { @@ -69,9 +82,9 @@ Blockly.Arduino["procedures_defreturn"] = function (block) { branch + returnValue + "}"; - code = Blockly.Arduino.scrub_(block, code); + code = Blockly.Generator.Arduino.scrub_(block, code); // Add % so as not to collide with helper functions in definitions list. - Blockly.Arduino.functionNames_["%" + funcName] = code; + Blockly.Generator.Arduino.functionNames_["%" + funcName] = code; return null; }; @@ -92,41 +105,47 @@ function translateType(type) { } } -Blockly.Arduino["procedures_defnoreturn"] = - Blockly.Arduino["procedures_defreturn"]; +Blockly.Generator.Arduino["procedures_defnoreturn"] = + Blockly.Generator.Arduino["procedures_defreturn"]; -Blockly.Arduino["procedures_callreturn"] = function (block) { +Blockly.Generator.Arduino.forBlock["procedures_callreturn"] = function ( + block, + generator, +) { // Call a procedure with a return value. - const funcName = Blockly.Arduino.nameDB_.getName( + const funcName = Blockly.Generator.Arduino.nameDB_.getName( block.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE, ); const args = []; for (let i = 0; i < block.arguments_.length; i++) { args[i] = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "ARG" + i, - Blockly.Arduino.ORDER_COMMA, + Blockly.Generator.Arduino.ORDER_COMMA, ) || "null"; } const code = funcName + "(" + args.join(", ") + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["procedures_callnoreturn"] = function (block) { +Blockly.Generator.Arduino.forBlock["procedures_callnoreturn"] = function ( + block, + generator, +) { // Call a procedure with no return value. - const funcName = Blockly.Arduino.nameDB_.getName( + const funcName = Blockly.Generator.Arduino.nameDB_.getName( block.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE, ); const args = []; for (let i = 0; i < block.arguments_.length; i++) { args[i] = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "ARG" + i, - Blockly.Arduino.ORDER_COMMA, + Blockly.Generator.Arduino.ORDER_COMMA, ) || "null"; } diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js index a4bfad7c..88a48403 100644 --- a/src/components/Blockly/generator/sensebox-ble.js +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -1,61 +1,79 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino.sensebox_phyphox_init = function () { +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_init"] = function () { var name = this.getFieldValue("devicename"); - Blockly.Arduino.libraries_["phyphox_library"] = `#include `; - Blockly.Arduino.phyphoxSetupCode_["phyphox_start"] = + Blockly.Generator.Arduino.libraries_["phyphox_library"] = + `#include `; + Blockly.Generator.Arduino.phyphoxSetupCode_["phyphox_start"] = `PhyphoxBLE::start("${name}");`; var code = ``; return code; }; -Blockly.Arduino.sensebox_phyphox_experiment = function () { - 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"); - Blockly.Arduino.phyphoxSetupCode_[`PhyphoxBleExperiment_${experimentname}`] = - `PhyphoxBleExperiment ${experimentname};`; - Blockly.Arduino.phyphoxSetupCode_[`setTitle_${title}`] = - `${experimentname}.setTitle("${title}");`; - Blockly.Arduino.phyphoxSetupCode_[`setCategory_senseBoxExperiments}`] = - `${experimentname}.setCategory("senseBox Experimente");`; - Blockly.Arduino.phyphoxSetupCode_[`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 +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_experiment"] = + function () { + var experimentname = "experiment"; + var title = this.getFieldValue("title").replace(/[^a-zA-Z0-9]/g, ""); + var description = this.getFieldValue("description"); + var branch = Blockly.Generator.Arduino.statementToCode(this, "view"); + Blockly.Generator.Arduino.phyphoxSetupCode_[ + `PhyphoxBleExperiment_${experimentname}` + ] = `PhyphoxBleExperiment ${experimentname};`; + Blockly.Generator.Arduino.phyphoxSetupCode_[`setTitle_${title}`] = + `${experimentname}.setTitle("${title}");`; + Blockly.Generator.Arduino.phyphoxSetupCode_[ + `setCategory_senseBoxExperiments}` + ] = `${experimentname}.setCategory("senseBox Experimente");`; + Blockly.Generator.Arduino.phyphoxSetupCode_[ + `setDescription_${description}` + ] = `${experimentname}.setDescription("${description}");`; + Blockly.Generator.Arduino.phyphoxSetupCode_[`addView_${experimentname}`] = + `PhyphoxBleExperiment::View firstView;\nfirstView.setLabel("Messwerte"); //Create a "view"`; + Blockly.Generator.Arduino.phyphoxSetupCode_[`addGraph`] = `${branch}`; + Blockly.Generator.Arduino.phyphoxSetupCode_[`addView_firstview`] = + `${experimentname}.addView(firstView);`; //Attach view to experiment + Blockly.Generator.Arduino.phyphoxSetupCode_[ + `addExperiment_${experimentname}` + ] = `PhyphoxBLE::addExperiment(${experimentname});`; //Attach experiment to server - var code = ``; - return code; -}; + var code = ``; + return code; + }; -Blockly.Arduino["sensebox_phyphox_timestamp"] = function () { +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_timestamp"] = function ( + block, + generator, +) { var code = 0; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["sensebox_phyphox_channel"] = function () { +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_channel"] = function ( + block, + generator, +) { var channel = parseFloat(this.getFieldValue("channel")); var code = channel; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_phyphox_sendchannel = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_sendchannel"] = function ( + block, + generator, +) { var channel = this.getFieldValue("channel"); var value = - Blockly.Arduino.valueToCode(this, "value", Blockly.Arduino.ORDER_ATOMIC) || - "1"; + Blockly.Generator.Arduino.valueToCode( + this, + "value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "1"; var code = `float channel${channel} = ${value};\n`; return code; }; -Blockly.Arduino.sensebox_phyphox_graph = function () { +Blockly.Generator.Arduino.forBlock["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"); @@ -63,16 +81,16 @@ Blockly.Arduino.sensebox_phyphox_graph = function () { var labely = this.getFieldValue("labely"); var style = this.getFieldValue("style"); var channelX = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "channel0", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || 0; var channelY = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "channel1", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || 1; var code = `PhyphoxBleExperiment::Graph ${label};\n`; //Create graph which will plot random numbers over time @@ -89,32 +107,34 @@ Blockly.Arduino.sensebox_phyphox_graph = function () { return code; }; -Blockly.Arduino.sensebox_phyphox_experiment_send = function () { - var branch = Blockly.Arduino.statementToCode(this, "sendValues"); - var blocks = this.getDescendants(); - var count = 0; - if (blocks !== undefined) { - for (var i = 0; i < blocks.length; i++) { - if (blocks[i].type === "sensebox_phyphox_sendchannel") { - count++; +Blockly.Generator.Arduino.forBlock["sensebox_phyphox_experiment_send"] = + function () { + var branch = Blockly.Generator.Arduino.statementToCode(this, "sendValues"); + var blocks = this.getDescendants(); + 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 = ""; + if (count === 5) { + } + var string = ""; - for (var j = 1; j <= count; j++) { - if (string === "") { - string += `channel${j}`; - } else if (string !== "") { - string += `, channel${j}`; + for (var j = 1; j <= count; j++) { + 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; -}; + Blockly.Generator.Arduino.loopCodeOnce_["phyphox_poll"] = + `PhyphoxBLE::poll();`; + var code = `${branch}\nPhyphoxBLE::write(${string});`; + return code; + }; /** * senseBox BLE @@ -122,7 +142,7 @@ Blockly.Arduino.sensebox_phyphox_experiment_send = function () { * */ -Blockly.Arduino.sensebox_ble_init = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ble_init"] = function () { var code = ""; return code; }; diff --git a/src/components/Blockly/generator/sensebox-display.js b/src/components/Blockly/generator/sensebox-display.js index b8f0bbca..c1984d58 100644 --- a/src/components/Blockly/generator/sensebox-display.js +++ b/src/components/Blockly/generator/sensebox-display.js @@ -1,77 +1,86 @@ import * as Blockly from "blockly/core"; /*Display Blocks*/ -Blockly.Arduino.sensebox_display_beginDisplay = function () { - Blockly.Arduino.libraries_["library_spi"] = "#include "; - Blockly.Arduino.libraries_["library_wire"] = "#include "; - Blockly.Arduino.libraries_["library_AdafruitGFX"] = - "#include // http://librarymanager/All#Adafruit_GFX_Library"; - Blockly.Arduino.libraries_["library_AdafruitSSD1306"] = - "#include // http://librarymanager/All#Adafruit_SSD1306"; - Blockly.Arduino.definitions_["define_display_size"] = - `#define SCREEN_WIDTH 128\n#define SCREEN_HEIGHT 64`; - Blockly.Arduino.definitions_["define_display"] = - "#define OLED_RESET -1\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);"; +Blockly.Generator.Arduino.forBlock["sensebox_display_beginDisplay"] = + function () { + Blockly.Generator.Arduino.libraries_["library_spi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_wire"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_AdafruitGFX"] = + "#include // http://librarymanager/All#Adafruit_GFX_Library"; + Blockly.Generator.Arduino.libraries_["library_AdafruitSSD1306"] = + "#include // http://librarymanager/All#Adafruit_SSD1306"; + Blockly.Generator.Arduino.definitions_["define_display_size"] = + `#define SCREEN_WIDTH 128\n#define SCREEN_HEIGHT 64`; + Blockly.Generator.Arduino.definitions_["define_display"] = + "#define OLED_RESET -1\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);"; - Blockly.Arduino.setupCode_["sensebox_display_begin"] = - "display.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();"; - var code = ""; - return code; -}; + Blockly.Generator.Arduino.setupCode_["sensebox_display_begin"] = + "display.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();"; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_display_clearDisplay = function () { - var code = "display.clearDisplay();\n"; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_display_clearDisplay"] = + function () { + var code = "display.clearDisplay();\n"; + return code; + }; -Blockly.Arduino.sensebox_display_printDisplay = function () { - var x = this.getFieldValue("X"); - var y = this.getFieldValue("Y"); - var printDisplay = - Blockly.Arduino.valueToCode( - this, - "printDisplay", - Blockly.Arduino.ORDER_ATOMIC, - ) || '"Keine Eingabe"'; - var size = this.getFieldValue("SIZE"); - var color = this.getFieldValue("COLOR"); - var code = "display.setCursor(" + x + "," + y + ");\n"; - code += "display.setTextSize(" + size + ");\n"; - code += "display.setTextColor(" + color + ");\n"; - code += "display.println(" + printDisplay + ");\n"; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_display_printDisplay"] = + function () { + var x = this.getFieldValue("X"); + var y = this.getFieldValue("Y"); + var printDisplay = + Blockly.Generator.Arduino.valueToCode( + this, + "printDisplay", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; + var size = this.getFieldValue("SIZE"); + var color = this.getFieldValue("COLOR"); + var code = "display.setCursor(" + x + "," + y + ");\n"; + code += "display.setTextSize(" + size + ");\n"; + code += "display.setTextColor(" + color + ");\n"; + code += "display.println(" + printDisplay + ");\n"; + return code; + }; -Blockly.Arduino.sensebox_display_fastPrint = function () { +Blockly.Generator.Arduino.forBlock["sensebox_display_fastPrint"] = function () { var title1 = - Blockly.Arduino.valueToCode(this, "Title1", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var value1 = Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( + this, + "Title1", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var value1 = Blockly.Generator.Arduino.valueToCode( this, "Value1", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); var dimension1 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "Dimension1", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var title2 = - Blockly.Arduino.valueToCode(this, "Title2", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var value2 = Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( + this, + "Title2", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var value2 = Blockly.Generator.Arduino.valueToCode( this, "Value2", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); var dimension2 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "Dimension2", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; - Blockly.Arduino.codeFunctions_["sensebox_fastPrint"] = ` + Blockly.Generator.Arduino.codeFunctions_["sensebox_fastPrint"] = ` void printOnDisplay(String title1, String measurement1, String unit1, String title2, String measurement2, String unit2) { display.setCursor(0, 0); @@ -99,136 +108,198 @@ Blockly.Arduino.sensebox_display_fastPrint = function () { return code; }; -Blockly.Arduino.sensebox_display_show = function (block) { - var show = Blockly.Arduino.statementToCode(block, "SHOW"); +Blockly.Generator.Arduino.forBlock["sensebox_display_show"] = function ( + block, + generator, +) { + var show = Blockly.Generator.Arduino.statementToCode(block, "SHOW"); var code = ""; code += show; code += "display.display();\n"; return code; }; -Blockly.Arduino.sensebox_display_plotDisplay = function () { - var YLabel = - Blockly.Arduino.valueToCode(this, "YLabel", Blockly.Arduino.ORDER_ATOMIC) || - "Y"; - var XLabel = - Blockly.Arduino.valueToCode(this, "XLabel", Blockly.Arduino.ORDER_ATOMIC) || - "X"; - var Title = - Blockly.Arduino.valueToCode(this, "Title", Blockly.Arduino.ORDER_ATOMIC) || - "Title"; - var XRange1 = - Blockly.Arduino.valueToCode( - this, - "XRange1", - Blockly.Arduino.ORDER_ATOMIC, - ) || "0"; - var XRange2 = - Blockly.Arduino.valueToCode( - this, - "XRange2", - Blockly.Arduino.ORDER_ATOMIC, - ) || "0"; - var YRange1 = - Blockly.Arduino.valueToCode( - this, - "YRange1", - Blockly.Arduino.ORDER_ATOMIC, - ) || "0"; - var YRange2 = - Blockly.Arduino.valueToCode( - this, - "YRange2", - Blockly.Arduino.ORDER_ATOMIC, - ) || "0"; - var XTick = - Blockly.Arduino.valueToCode(this, "XTick", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var YTick = - Blockly.Arduino.valueToCode(this, "YTick", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var TimeFrame = - Blockly.Arduino.valueToCode( - this, - "TimeFrame", - Blockly.Arduino.ORDER_ATOMIC, - ) || "0"; - var plotDisplay = - Blockly.Arduino.valueToCode( - this, - "plotDisplay", - Blockly.Arduino.ORDER_ATOMIC, - ) || '"Keine Eingabe"'; - Blockly.Arduino.libraries_["library_plot"] = "#include "; - Blockly.Arduino.definitions_["define_plot_class"] = - "Plot DataPlot(&display);\n"; - Blockly.Arduino.variables_["define_plot_class"] = - "const double TIMEFRAME = " + TimeFrame + ";\n"; - Blockly.Arduino.setupCode_["sensebox_plot_setup"] = - "DataPlot.setTitle(" + - Title + - ");\nDataPlot.setXLabel(" + - XLabel + - ");\nDataPlot.setYLabel(" + - YLabel + - ");\nDataPlot.setXRange(" + - XRange1 + - "," + - XRange2 + - ");\nDataPlot.setYRange(" + - YRange1 + - "," + - YRange2 + - ");\nDataPlot.setXTick(" + - XTick + - ");\nDataPlot.setYTick(" + - YTick + - ");\nDataPlot.setXPrecision(0);\nDataPlot.setYPrecision(0);\n"; - var code = "DataPlot.clear();"; - code += - "double starttime = millis();\ndouble t = 0;\nwhile (t <= TIMEFRAME) {\nt = (millis() - starttime) / 1000.0;\nfloat value = " + - plotDisplay + - ";\n"; - code += "DataPlot.addDataPoint(t,value);\n}\n"; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_display_plotDisplay"] = + function () { + var YLabel = + Blockly.Generator.Arduino.valueToCode( + this, + "YLabel", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "Y"; + var XLabel = + Blockly.Generator.Arduino.valueToCode( + this, + "XLabel", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "X"; + var Title = + Blockly.Generator.Arduino.valueToCode( + this, + "Title", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "Title"; + var XRange1 = + Blockly.Generator.Arduino.valueToCode( + this, + "XRange1", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var XRange2 = + Blockly.Generator.Arduino.valueToCode( + this, + "XRange2", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var YRange1 = + Blockly.Generator.Arduino.valueToCode( + this, + "YRange1", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var YRange2 = + Blockly.Generator.Arduino.valueToCode( + this, + "YRange2", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var XTick = + Blockly.Generator.Arduino.valueToCode( + this, + "XTick", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var YTick = + Blockly.Generator.Arduino.valueToCode( + this, + "YTick", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var TimeFrame = + Blockly.Generator.Arduino.valueToCode( + this, + "TimeFrame", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var plotDisplay = + Blockly.Generator.Arduino.valueToCode( + this, + "plotDisplay", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; + Blockly.Generator.Arduino.libraries_["library_plot"] = "#include "; + Blockly.Generator.Arduino.definitions_["define_plot_class"] = + "Plot DataPlot(&display);\n"; + Blockly.Generator.Arduino.variables_["define_plot_class"] = + "const double TIMEFRAME = " + TimeFrame + ";\n"; + Blockly.Generator.Arduino.setupCode_["sensebox_plot_setup"] = + "DataPlot.setTitle(" + + Title + + ");\nDataPlot.setXLabel(" + + XLabel + + ");\nDataPlot.setYLabel(" + + YLabel + + ");\nDataPlot.setXRange(" + + XRange1 + + "," + + XRange2 + + ");\nDataPlot.setYRange(" + + YRange1 + + "," + + YRange2 + + ");\nDataPlot.setXTick(" + + XTick + + ");\nDataPlot.setYTick(" + + YTick + + ");\nDataPlot.setXPrecision(0);\nDataPlot.setYPrecision(0);\n"; + var code = "DataPlot.clear();"; + code += + "double starttime = millis();\ndouble t = 0;\nwhile (t <= TIMEFRAME) {\nt = (millis() - starttime) / 1000.0;\nfloat value = " + + plotDisplay + + ";\n"; + code += "DataPlot.addDataPoint(t,value);\n}\n"; + return code; + }; -Blockly.Arduino.sensebox_display_fillCircle = function () { - let code = ""; - var x = - Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC) || "0"; - var y = - Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC) || "0"; - var radius = - Blockly.Arduino.valueToCode(this, "Radius", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var fill = this.getFieldValue("FILL"); - if (fill === "TRUE") { - code = "display.fillCircle(" + x + "," + y + "," + radius + ",1);\n"; - } else { - code = "display.drawCircle(" + x + "," + y + "," + radius + ",1);\n"; - } - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_display_fillCircle"] = + function () { + let code = ""; + var x = + Blockly.Generator.Arduino.valueToCode( + this, + "X", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var y = + Blockly.Generator.Arduino.valueToCode( + this, + "Y", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var radius = + Blockly.Generator.Arduino.valueToCode( + this, + "Radius", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var fill = this.getFieldValue("FILL"); + if (fill === "TRUE") { + code = "display.fillCircle(" + x + "," + y + "," + radius + ",1);\n"; + } else { + code = "display.drawCircle(" + x + "," + y + "," + radius + ",1);\n"; + } + return code; + }; -Blockly.Arduino.sensebox_display_drawRectangle = function () { - let code = ""; - var x = - Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC) || "0"; - var y = - Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC) || "0"; - var width = - Blockly.Arduino.valueToCode(this, "width", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var height = - Blockly.Arduino.valueToCode(this, "height", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - var fill = this.getFieldValue("FILL"); - if (fill === "TRUE") { - code = - "display.fillRect(" + x + "," + y + "," + width + "," + height + ",1);\n"; - } else { - code = - "display.drawRect(" + x + "," + y + "," + width + "," + height + ",1);\n"; - } - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_display_drawRectangle"] = + function () { + let code = ""; + var x = + Blockly.Generator.Arduino.valueToCode( + this, + "X", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var y = + Blockly.Generator.Arduino.valueToCode( + this, + "Y", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var width = + Blockly.Generator.Arduino.valueToCode( + this, + "width", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var height = + Blockly.Generator.Arduino.valueToCode( + this, + "height", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + var fill = this.getFieldValue("FILL"); + if (fill === "TRUE") { + code = + "display.fillRect(" + + x + + "," + + y + + "," + + width + + "," + + height + + ",1);\n"; + } else { + code = + "display.drawRect(" + + x + + "," + + y + + "," + + width + + "," + + height + + ",1);\n"; + } + return code; + }; diff --git a/src/components/Blockly/generator/sensebox-esp-now.js b/src/components/Blockly/generator/sensebox-esp-now.js index 285df43e..5cc16db5 100644 --- a/src/components/Blockly/generator/sensebox-esp-now.js +++ b/src/components/Blockly/generator/sensebox-esp-now.js @@ -1,9 +1,10 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; -Blockly.Arduino.sensebox_esp_now = function () { - Blockly.Arduino.libraries_["library_ESP_Now"] = "#include "; - Blockly.Arduino.libraries_["library_WiFi"] = "#include "; - Blockly.Arduino.setupCode_["esp_now_begin"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_esp_now"] = function () { + Blockly.Generator.Arduino.libraries_["library_ESP_Now"] = + "#include "; + Blockly.Generator.Arduino.libraries_["library_WiFi"] = "#include "; + Blockly.Generator.Arduino.setupCode_["esp_now_begin"] = ` WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK){ return; @@ -12,14 +13,15 @@ Blockly.Arduino.sensebox_esp_now = function () { return code; }; -Blockly.Arduino.sensebox_esp_now_sender = function () { +Blockly.Generator.Arduino.forBlock["sensebox_esp_now_sender"] = function () { var mac_address = this.getFieldValue("mac-address"); if (!mac_address.startsWith("{")) { mac_address = mac_address.replaceAll(":", ", 0x"); mac_address = "{ 0x" + mac_address + " }"; } - Blockly.Arduino.variables_["peer_info"] = `esp_now_peer_info_t peerInfo;`; - Blockly.Arduino.setupCode_["esp_now_sender"] = ` + Blockly.Generator.Arduino.variables_["peer_info"] = + `esp_now_peer_info_t peerInfo;`; + Blockly.Generator.Arduino.setupCode_["esp_now_sender"] = ` peerInfo.channel = 0; peerInfo.encrypt = false;`; var code = ` @@ -30,15 +32,19 @@ Blockly.Arduino.sensebox_esp_now_sender = function () { return code; }; -Blockly.Arduino.sensebox_get_mac = function () { - Blockly.Arduino.definitions_["define_macadress"] = "String mac_address;"; - Blockly.Arduino.setupCode_["sensebox_get_mac"] = +Blockly.Generator.Arduino.forBlock["sensebox_get_mac"] = function () { + Blockly.Generator.Arduino.definitions_["define_macadress"] = + "String mac_address;"; + Blockly.Generator.Arduino.setupCode_["sensebox_get_mac"] = " mac_address = WiFi.macAddress();"; var code = "mac_address"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_esp_now_receive = function (Block) { +Blockly.Generator.Arduino.forBlock["sensebox_esp_now_receive"] = function ( + block, + generator, +) { var idMessage = Block.getFieldValue("VAR"); const varMessage = Blockly.Variables.getVariable( Blockly.getMainWorkspace(), @@ -49,13 +55,13 @@ Blockly.Arduino.sensebox_esp_now_receive = function (Block) { Blockly.getMainWorkspace(), idAddress, ); - Blockly.Arduino.variables_[varMessage.name + varMessage.type] = + Blockly.Generator.Arduino.variables_[varMessage.name + varMessage.type] = varMessage.type + " " + varMessage.name + ";\n"; - Blockly.Arduino.variables_[varAddress.name + varAddress.type] = + Blockly.Generator.Arduino.variables_[varAddress.name + varAddress.type] = varAddress.type + " " + varAddress.name + ";\n"; - let branch = Blockly["Arduino"].statementToCode(Block, "DO"); - branch = Blockly["Arduino"].addLoopTrap(branch, Block.id); - Blockly.Arduino.codeFunctions_["on_data_receive"] = ` + let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); + Blockly.Generator.Arduino.codeFunctions_["on_data_receive"] = ` void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { ${varMessage.name} = (char*)incomingData; ${varAddress.name} = String(mac[0],HEX) + ":" + String(mac[1],HEX) + ":" + String(mac[2],HEX) + ":" + String(mac[3],HEX) + ":" + String(mac[4],HEX) + ":" + String(mac[5],HEX); @@ -67,10 +73,13 @@ Blockly.Arduino.sensebox_esp_now_receive = function (Block) { return code; }; -Blockly.Arduino.sensebox_esp_now_send = function () { +Blockly.Generator.Arduino.forBlock["sensebox_esp_now_send"] = function () { var value = - Blockly.Arduino.valueToCode(this, "value", Blockly.Arduino.ORDER_ATOMIC) || - `" "`; + Blockly.Generator.Arduino.valueToCode( + this, + "value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || `" "`; var mac_address = this.getFieldValue("mac-address"); if (!mac_address.startsWith("{")) { diff --git a/src/components/Blockly/generator/sensebox-esp-wifi.js b/src/components/Blockly/generator/sensebox-esp-wifi.js index 8d051381..944e6a57 100644 --- a/src/components/Blockly/generator/sensebox-esp-wifi.js +++ b/src/components/Blockly/generator/sensebox-esp-wifi.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; //import store from "../../../store"; // preperations for the esp board @@ -9,69 +9,80 @@ import Blockly from "blockly"; /* Wifi connection and openSenseMap Blocks*/ -Blockly.Arduino.sensebox_esp_wifi = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_esp_wifi"] = function ( + block, + generator, +) { var pw = this.getFieldValue("Password"); var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_WiFi_ESP"] = + Blockly.Generator.Arduino.libraries_["library_WiFi_ESP"] = "#include "; - Blockly.Arduino.variables_["ssid"] = `char* ssid = "${ssid}";`; - Blockly.Arduino.variables_["pass"] = `char* password = "${pw}";`; - Blockly.Arduino.variables_["wifi_Status"] = "int status = WL_IDLE_STATUS;"; + Blockly.Generator.Arduino.variables_["ssid"] = `char* ssid = "${ssid}";`; + Blockly.Generator.Arduino.variables_["pass"] = `char* password = "${pw}";`; + Blockly.Generator.Arduino.variables_["wifi_Status"] = + "int status = WL_IDLE_STATUS;"; if (pw === "") { - Blockly.Arduino.setupCode_["wifi_begin"] = "WiFi.begin(ssid, password);"; - } else Blockly.Arduino.setupCode_["wifi_begin"] = "WiFi.begin(ssid);"; - Blockly.Arduino.setupCode_["wifi_wait"] = + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = + "WiFi.begin(ssid, password);"; + } else + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = "WiFi.begin(ssid);"; + Blockly.Generator.Arduino.setupCode_["wifi_wait"] = "while (WiFi.status() != WL_CONNECTED) {delay(1000);}"; var code = ""; return code; }; -Blockly.Arduino.sensebox_wifi_status = function () { +Blockly.Generator.Arduino.forBlock["sensebox_wifi_status"] = function () { var code = "WiFi.status()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_wifi_rssi = function () { +Blockly.Generator.Arduino.forBlock["sensebox_wifi_rssi"] = function () { var code = "WiFi.RSSI()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_get_ip = function () { - Blockly.Arduino.definitions_["define_ipadress"] = "IPAddress ip;"; - Blockly.Arduino.setupCode_["sensebox_get_ip"] = " ip = WiFi.localIP();"; +Blockly.Generator.Arduino.forBlock["sensebox_get_ip"] = function () { + Blockly.Generator.Arduino.definitions_["define_ipadress"] = "IPAddress ip;"; + Blockly.Generator.Arduino.setupCode_["sensebox_get_ip"] = + " ip = WiFi.localIP();"; var code = "ip"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_startap = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_startap"] = function ( + block, + generator, +) { var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_WiFi"] = "#include "; - Blockly.Arduino.setupCode_["wifi_startAP"] = `WiFi.beginAP(${ssid});`; + Blockly.Generator.Arduino.libraries_["library_WiFi"] = "#include "; + Blockly.Generator.Arduino.setupCode_["wifi_startAP"] = + `WiFi.beginAP(${ssid});`; var code = ""; return code; }; -Blockly.Arduino.sensebox_ethernet = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ethernet"] = function () { var ip = this.getFieldValue("ip"); var gateway = this.getFieldValue("gateway"); var subnetmask = this.getFieldValue("subnetmask"); var dns = this.getFieldValue("dns"); var mac = this.getFieldValue("mac"); var dhcp = this.getFieldValue("dhcp"); - Blockly.Arduino.libraries_["library_ethernet"] = + Blockly.Generator.Arduino.libraries_["library_ethernet"] = "#include // http://librarymanager/All#Ethernet"; - Blockly.Arduino.definitions_["ethernet_config"] = ` + Blockly.Generator.Arduino.definitions_["ethernet_config"] = ` byte mac[] = { ${mac}};`; if (dhcp === "Manual") { - Blockly.Arduino.definitions_["ethernet_manual_config"] = ` + Blockly.Generator.Arduino.definitions_["ethernet_manual_config"] = ` //Configure static IP setup (only needed if DHCP is disabled) IPAddress myIp(${ip.replaceAll(".", ", ")}); IPAddress myDns(${dns.replaceAll(".", ",")}); IPAddress myGateway(${gateway.replaceAll(".", ",")}); IPAddress mySubnet(${subnetmask.replaceAll(".", ",")}); `; - Blockly.Arduino.setupCode_["ethernet_setup"] = ` + Blockly.Generator.Arduino.setupCode_["ethernet_setup"] = ` Ethernet.init(23);// start the Ethernet connection: if (Ethernet.begin(mac) == 0) { // no point in carrying on, so do nothing forevermore: @@ -82,7 +93,7 @@ if (Ethernet.begin(mac) == 0) { delay(1000); `; } else { - Blockly.Arduino.setupCode_["ethernet_setup"] = ` + Blockly.Generator.Arduino.setupCode_["ethernet_setup"] = ` Ethernet.init(23); // start the Ethernet connection: Ethernet.begin(mac); // give the Ethernet shield a second to initialize: delay(1000); @@ -93,7 +104,7 @@ delay(1000); return code; }; -Blockly.Arduino.sensebox_ethernetIp = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ethernetIp"] = function () { var code = "Ethernet.localIP()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/generator/sensebox-led.js b/src/components/Blockly/generator/sensebox-led.js index c6e1db94..a36e589a 100644 --- a/src/components/Blockly/generator/sensebox-led.js +++ b/src/components/Blockly/generator/sensebox-led.js @@ -1,27 +1,31 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino.sensebox_led = function () { +Blockly.Generator.Arduino.forBlock["sensebox_led"] = function () { var dropdown_pin = this.getFieldValue("PIN"); var dropdown_stat = this.getFieldValue("STAT"); - Blockly.Arduino.setupCode_["setup_led_" + dropdown_pin] = + Blockly.Generator.Arduino.setupCode_["setup_led_" + dropdown_pin] = "pinMode(" + dropdown_pin + ", OUTPUT);"; var code = "digitalWrite(" + dropdown_pin + "," + dropdown_stat + ");\n"; return code; }; -Blockly.Arduino.sensebox_rgb_led = function () { +Blockly.Generator.Arduino.forBlock["sensebox_rgb_led"] = function () { var dropdown_pin = this.getFieldValue("PIN"); var color = - Blockly.Arduino.valueToCode(this, "COLOR", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - Blockly.Arduino.libraries_["library_neopixel"] = "#include " - Blockly.Arduino.definitions_["define_rgb_led" + dropdown_pin] = - "Adafruit_NeoPixel rgb_led_" + - dropdown_pin + - " = Adafruit_NeoPixel(1," + - dropdown_pin + - ",NEO_RGB + NEO_KHZ800);\n"; - Blockly.Arduino.setupCode_["setup_rgb_led" + dropdown_pin] = + Blockly.Generator.Arduino.valueToCode( + this, + "COLOR", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + Blockly.Generator.Arduino.libraries_["library_neopixel"] = + "#include "; + Blockly.Generator.Arduino.definitions_["define_rgb_led" + dropdown_pin] = + "Adafruit_NeoPixel rgb_led_" + + dropdown_pin + + " = Adafruit_NeoPixel(1," + + dropdown_pin + + ",NEO_RGB + NEO_KHZ800);\n"; + Blockly.Generator.Arduino.setupCode_["setup_rgb_led" + dropdown_pin] = "rgb_led_" + dropdown_pin + ".begin();"; var code = "rgb_led_" + @@ -35,39 +39,48 @@ Blockly.Arduino.sensebox_rgb_led = function () { return code; }; -Blockly.Arduino.sensebox_ws2818_led_init = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ws2818_led_init"] = function () { let dropdown_pin = 1; dropdown_pin = this.getFieldValue("Port"); var numPixel = - Blockly.Arduino.valueToCode(this, "NUMBER", Blockly.Arduino.ORDER_ATOMIC) || - "1"; + Blockly.Generator.Arduino.valueToCode( + this, + "NUMBER", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "1"; var brightness = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "BRIGHTNESS", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "50"; - Blockly.Arduino.libraries_["library_neopixel"] = "#include " - Blockly.Arduino.definitions_["define_rgb_led" + dropdown_pin] = `Adafruit_NeoPixel rgb_led_${dropdown_pin}= Adafruit_NeoPixel(${numPixel}, ${dropdown_pin},NEO_GRB + NEO_KHZ800);\n`; - Blockly.Arduino.setupCode_["setup_rgb_led" + dropdown_pin] = + Blockly.Generator.Arduino.libraries_["library_neopixel"] = + "#include "; + Blockly.Generator.Arduino.definitions_["define_rgb_led" + dropdown_pin] = + `Adafruit_NeoPixel rgb_led_${dropdown_pin}= Adafruit_NeoPixel(${numPixel}, ${dropdown_pin},NEO_GRB + NEO_KHZ800);\n`; + Blockly.Generator.Arduino.setupCode_["setup_rgb_led" + dropdown_pin] = "rgb_led_" + dropdown_pin + ".begin();\n"; - Blockly.Arduino.setupCode_["setup_rgb_led_brightness" + dropdown_pin] = - `rgb_led_${dropdown_pin}.setBrightness(${brightness});\n`; + Blockly.Generator.Arduino.setupCode_[ + "setup_rgb_led_brightness" + dropdown_pin + ] = `rgb_led_${dropdown_pin}.setBrightness(${brightness});\n`; return ""; }; -Blockly.Arduino.sensebox_ws2818_led = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ws2818_led"] = function () { let dropdown_pin = 1; dropdown_pin = this.getFieldValue("Port"); var position = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "POSITION", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var color = - Blockly.Arduino.valueToCode(this, "COLOR", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + this, + "COLOR", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var code = `rgb_led_${dropdown_pin}.setPixelColor(${position},rgb_led_${dropdown_pin}.Color(${color}));\nrgb_led_${dropdown_pin}.show();\n`; return code; }; @@ -83,37 +96,49 @@ function hexToRgb(hex) { : null; } -Blockly.Arduino["colour_picker"] = function (block) { +Blockly.Generator.Arduino.forBlock["colour_picker"] = function ( + block, + generator, +) { const rgb = hexToRgb(block.getFieldValue("COLOUR")); - return [rgb.r + ", " + rgb.g + ", " + rgb.b, Blockly.Arduino.ORDER_ATOMIC]; + return [ + rgb.r + ", " + rgb.g + ", " + rgb.b, + Blockly.Generator.Arduino.ORDER_ATOMIC, + ]; }; -Blockly.Arduino["colour_random"] = function (block) { +Blockly.Generator.Arduino.forBlock["colour_random"] = function ( + block, + generator, +) { return [ "random(0, 255), random(0, 255), random(0, 255)", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ]; }; -Blockly.Arduino["colour_rgb"] = function (block) { - const red = Blockly.Arduino.valueToCode( +Blockly.Generator.Arduino.forBlock["colour_rgb"] = function (block, generator) { + const red = Blockly.Generator.Arduino.valueToCode( block, "RED", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - const green = Blockly.Arduino.valueToCode( + const green = Blockly.Generator.Arduino.valueToCode( block, "GREEN", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - const blue = Blockly.Arduino.valueToCode( + const blue = Blockly.Generator.Arduino.valueToCode( block, "BLUE", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - return [red + ", " + green + ", " + blue, Blockly.Arduino.ORDER_ATOMIC]; + return [ + red + ", " + green + ", " + blue, + Blockly.Generator.Arduino.ORDER_ATOMIC, + ]; }; /** @@ -122,33 +147,43 @@ Blockly.Arduino["colour_rgb"] = function (block) { * */ -Blockly.Arduino["sensebox_ws2812_matrix_init"] = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_ws2812_matrix_init"] = function ( + block, + generator, +) { var dropdown_pin = this.getFieldValue("Port"); var brightness = this.getFieldValue("BRIGHTNESS"); - Blockly.Arduino.libraries_["libraries_neopixel"] = + Blockly.Generator.Arduino.libraries_["libraries_neopixel"] = `#include `; - Blockly.Arduino.libraries_["libraries_rgb_matrix"] = + Blockly.Generator.Arduino.libraries_["libraries_rgb_matrix"] = "#include "; - Blockly.Arduino.libraries_["library_AdafruitGFX"] = + Blockly.Generator.Arduino.libraries_["library_AdafruitGFX"] = "#include // http://librarymanager/All#Adafruit_GFX_Library"; - Blockly.Arduino.definitions_["definition_rgb_matrix_widht"] = + Blockly.Generator.Arduino.definitions_["definition_rgb_matrix_widht"] = "#define WIDTH 12"; - Blockly.Arduino.definitions_["definition_rgb_matrix_height"] = + Blockly.Generator.Arduino.definitions_["definition_rgb_matrix_height"] = "#define HEIGHT 8"; - Blockly.Arduino.definitions_["definition_rgb_matrix" + dropdown_pin] = + Blockly.Generator.Arduino.definitions_[ + "definition_rgb_matrix" + dropdown_pin + ] = `Adafruit_NeoMatrix matrix_${dropdown_pin} = Adafruit_NeoMatrix(WIDTH, HEIGHT, ${dropdown_pin}, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);`; - Blockly.Arduino.setupCode_["setup_matrix_brightness" + dropdown_pin] = - `matrix_${dropdown_pin}.setBrightness(${brightness});\n`; - Blockly.Arduino.setupCode_["setup_matrix_text_wrap" + dropdown_pin] = - "matrix_" + dropdown_pin + ".setTextWrap(false);\n"; - Blockly.Arduino.setupCode_["matrix" + dropdown_pin] = + Blockly.Generator.Arduino.setupCode_[ + "setup_matrix_brightness" + dropdown_pin + ] = `matrix_${dropdown_pin}.setBrightness(${brightness});\n`; + Blockly.Generator.Arduino.setupCode_[ + "setup_matrix_text_wrap" + dropdown_pin + ] = "matrix_" + dropdown_pin + ".setTextWrap(false);\n"; + Blockly.Generator.Arduino.setupCode_["matrix" + dropdown_pin] = "matrix_" + dropdown_pin + ".begin();\n"; - // Blockly.Arduino.setupCode_['setup_matrix_color' + dropdown_pin] = `matrix_${dropdown_pin}.setColor(matrix.Color(255, 0, 0));\n`; + // Blockly.Generator.Arduino.setupCode_['setup_matrix_color' + dropdown_pin] = `matrix_${dropdown_pin}.setColor(matrix.Color(255, 0, 0));\n`; return ""; }; -Blockly.Arduino["sensebox_ws2812_matrix_clear"] = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_ws2812_matrix_clear"] = function ( + block, + generator, +) { var dropdown_pin = this.getFieldValue("Port"); var code = ""; code += `matrix_${dropdown_pin}.fillScreen(0);\n`; @@ -156,17 +191,23 @@ Blockly.Arduino["sensebox_ws2812_matrix_clear"] = function (block) { return code; }; -Blockly.Arduino["sensebox_ws2812_matrix_text"] = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_ws2812_matrix_text"] = function ( + block, + generator, +) { var code = ""; var dropdown_pin = this.getFieldValue("Port"); var value = - Blockly.Arduino.valueToCode(this, "input", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; + Blockly.Generator.Arduino.valueToCode( + this, + "input", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; var autoscroll = this.getFieldValue("AUTOSCROLL"); - var color = Blockly.Arduino.valueToCode( + var color = Blockly.Generator.Arduino.valueToCode( this, "COLOR", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); code += `matrix_${dropdown_pin}.setTextColor(matrix_${dropdown_pin}.Color(${color}));\n`; if (autoscroll === "TRUE") { @@ -188,14 +229,24 @@ Blockly.Arduino["sensebox_ws2812_matrix_text"] = function (block) { return code; }; -Blockly.Arduino["sensebox_ws2812_matrix_drawPixel"] = function (block) { +Blockly.Generator.Arduino["sensebox_ws2812_matrix_drawPixel"] = function ( + block, +) { var dropdown_pin = this.getFieldValue("Port"); - var x = Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC); - var y = Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC); - var color = Blockly.Arduino.valueToCode( + var x = Blockly.Generator.Arduino.valueToCode( + this, + "X", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var y = Blockly.Generator.Arduino.valueToCode( + this, + "Y", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var color = Blockly.Generator.Arduino.valueToCode( this, "COLOR", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); var show = this.getFieldValue("SHOW"); var code = `matrix_${dropdown_pin}.drawPixel(${x},${y},matrix_${dropdown_pin}.Color(${color}));\n`; @@ -205,17 +256,25 @@ Blockly.Arduino["sensebox_ws2812_matrix_drawPixel"] = function (block) { return code; }; -Blockly.Arduino["sensebox_ws2812_matrix_showBitmap"] = function (block) { +Blockly.Generator.Arduino["sensebox_ws2812_matrix_showBitmap"] = function ( + block, +) { var dropdown_pin = this.getFieldValue("Port"); var value = - Blockly.Arduino.valueToCode(this, "input", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; + Blockly.Generator.Arduino.valueToCode( + this, + "input", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; var code = `matrix_${dropdown_pin}.drawRGBBitmap(0,0, ${value}, WIDTH, HEIGHT);\n`; code += `matrix_${dropdown_pin}.show();\n`; return code; }; -Blockly.Arduino["sensebox_ws2812_matrix_bitmap"] = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_ws2812_matrix_bitmap"] = function ( + block, + generator, +) { var dropdown_bitmap = this.getFieldValue("BITMAP"); var bitmap = ""; switch (dropdown_bitmap) { @@ -292,25 +351,31 @@ Blockly.Arduino["sensebox_ws2812_matrix_bitmap"] = function (block) { 0x2589, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2589, 0x2589, 0x2589, 0x2589, 0x0000, 0x0000, 0x0000, 0x0000,`; break; } - Blockly.Arduino.definitions_[`define_bitmap_${dropdown_bitmap}`] = + Blockly.Generator.Arduino.definitions_[`define_bitmap_${dropdown_bitmap}`] = `const uint16_t bitmap_${dropdown_bitmap}[] = {${bitmap}};`; var code = "bitmap_" + dropdown_bitmap; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["sensebox_ws2812_matrix_custom_bitmap"] = function (block) { +Blockly.Generator.Arduino["sensebox_ws2812_matrix_custom_bitmap"] = function ( + block, +) { var dropdown_pin = this.getFieldValue("Port"); - Blockly.Arduino.definitions_[`define_custom_bitmap_${dropdown_pin}`] = - `const uint16_t custom_bitmap[] = {};`; + Blockly.Generator.Arduino.definitions_[ + `define_custom_bitmap_${dropdown_pin}` + ] = `const uint16_t custom_bitmap[] = {};`; var value = - Blockly.Arduino.valueToCode(this, "input", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; + Blockly.Generator.Arduino.valueToCode( + this, + "input", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; var code = `matrix_${dropdown_pin}.drawBitmap(0,0,${value},WIDTH,HEIGHT,matrix_${dropdown_pin}.Color(255,255,255));\n`; code += `matrix_${dropdown_pin}.show();\n`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino["sensebox_ws2812_matrix_draw_custom_bitmap_example"] = +Blockly.Generator.Arduino["sensebox_ws2812_matrix_draw_custom_bitmap_example"] = function (block) { var bitmap = ""; for (let i = 1; i <= 8; i += 1) { @@ -328,9 +393,9 @@ Blockly.Arduino["sensebox_ws2812_matrix_draw_custom_bitmap_example"] = } bitmap += "\n"; } - Blockly.Arduino.definitions_[`define_custom_draw_bitmap}`] = + Blockly.Generator.Arduino.definitions_[`define_custom_draw_bitmap}`] = `const uint16_t bitmap_custom[] = {${bitmap}};`; var code = `bitmap_custom`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/generator/sensebox-lora.js b/src/components/Blockly/generator/sensebox-lora.js index 2e41dac4..c8f2c56f 100644 --- a/src/components/Blockly/generator/sensebox-lora.js +++ b/src/components/Blockly/generator/sensebox-lora.js @@ -1,15 +1,18 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino.sensebox_lora_initialize_otaa = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_lora_initialize_otaa"] = function ( + block, + generator, +) { var deivceID = this.getFieldValue("DEVICEID"); var appID = this.getFieldValue("APPID"); var appKey = this.getFieldValue("APPKEY"); var interval = this.getFieldValue("INTERVAL"); - Blockly.Arduino.libraries_["library_spi"] = "#include "; - Blockly.Arduino.libraries_["library_lmic"] = + Blockly.Generator.Arduino.libraries_["library_spi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_lmic"] = "#include // http://librarymanager/All#IBM_LMIC_framework"; - Blockly.Arduino.libraries_["library_hal"] = "#include "; - Blockly.Arduino.definitions_["define_LoRaVariablesOTAA"] = ` + Blockly.Generator.Arduino.libraries_["library_hal"] = "#include "; + Blockly.Generator.Arduino.definitions_["define_LoRaVariablesOTAA"] = ` static const u1_t PROGMEM APPEUI[8]= {${appID}}; void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI , 8);} @@ -37,7 +40,7 @@ Blockly.Arduino.sensebox_lora_initialize_otaa = function (block) { .dio = {PIN_XB1_INT, PIN_XB1_INT, LMIC_UNUSED_PIN}, };`; - Blockly.Arduino.codeFunctions_["functions_initLora"] = ` + Blockly.Generator.Arduino.codeFunctions_["functions_initLora"] = ` void initLora() { delay(2000); // LMIC init @@ -49,7 +52,7 @@ Blockly.Arduino.sensebox_lora_initialize_otaa = function (block) { do_send(&sendjob); }`; - Blockly.Arduino.codeFunctions_["functions_onEvent"] = ` + Blockly.Generator.Arduino.codeFunctions_["functions_onEvent"] = ` void onEvent (ev_t ev) { Serial.print(os_getTime()); Serial.print(": "); @@ -119,18 +122,24 @@ Blockly.Arduino.sensebox_lora_initialize_otaa = function (block) { break; } }`; - Blockly.Arduino.loraSetupCode_["initLora"] = "initLora();\n"; - Blockly.Arduino.setupCode_["serial.begin"] = + Blockly.Generator.Arduino.loraSetupCode_["initLora"] = "initLora();\n"; + Blockly.Generator.Arduino.setupCode_["serial.begin"] = "Serial.begin(9600);\ndelay(1000);\n"; var code = ""; return code; }; -Blockly.Arduino.sensebox_lora_message_send = function (block) { - Blockly.Arduino.libraries_["library_lora_message"] = +Blockly.Generator.Arduino.forBlock["sensebox_lora_message_send"] = function ( + block, + generator, +) { + Blockly.Generator.Arduino.libraries_["library_lora_message"] = "#include "; - var lora_sensor_values = Blockly.Arduino.statementToCode(block, "DO"); - Blockly.Arduino.functionNames_["functions_do_send"] = ` + var lora_sensor_values = Blockly.Generator.Arduino.statementToCode( + block, + "DO", + ); + Blockly.Generator.Arduino.functionNames_["functions_do_send"] = ` void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { @@ -145,42 +154,53 @@ Blockly.Arduino.sensebox_lora_message_send = function (block) { } // Next TX is scheduled after TX_COMPLETE event. }`; - Blockly.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; + Blockly.Generator.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; return ""; }; /** * Block send Data to TTN */ -Blockly.Arduino.sensebox_send_lora_sensor_value = function (block) { - const reading = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; - var messageBytes = this.getFieldValue("MESSAGE_BYTES"); - var code = ""; - switch (Number(messageBytes)) { - case 1: - code = `message.addUint8(${reading});\n`; - break; - case 2: - code = `message.addUint16(${reading});\n`; - break; - case 3: - code = `message.addUint8(${reading}); +Blockly.Generator.Arduino.forBlock["sensebox_send_lora_sensor_value"] = + function (block, generator) { + const reading = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; + var messageBytes = this.getFieldValue("MESSAGE_BYTES"); + var code = ""; + switch (Number(messageBytes)) { + case 1: + code = `message.addUint8(${reading});\n`; + break; + case 2: + code = `message.addUint16(${reading});\n`; + break; + case 3: + code = `message.addUint8(${reading}); message.addUint16(${reading} >> 8);\n`; - break; - default: - code = `message.addUint16(${reading});\n`; - } - return code; -}; + break; + default: + code = `message.addUint16(${reading});\n`; + } + return code; + }; -Blockly.Arduino.sensebox_lora_cayenne_send = function (block) { - Blockly.Arduino.libraries_["library_cayene"] = +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_send"] = function ( + block, + generator, +) { + Blockly.Generator.Arduino.libraries_["library_cayene"] = "#include // http://librarymanager/All#CayenneLPP"; - Blockly.Arduino.variables_["variable_cayenne"] = "CayenneLPP lpp(51);"; - var lora_sensor_values = Blockly.Arduino.statementToCode(block, "DO"); - Blockly.Arduino.functionNames_["functions_do_send"] = ` + Blockly.Generator.Arduino.variables_["variable_cayenne"] = + "CayenneLPP lpp(51);"; + var lora_sensor_values = Blockly.Generator.Arduino.statementToCode( + block, + "DO", + ); + Blockly.Generator.Arduino.functionNames_["functions_do_send"] = ` void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { @@ -195,38 +215,41 @@ Blockly.Arduino.sensebox_lora_cayenne_send = function (block) { } // Next TX is scheduled after TX_COMPLETE event. }`; - Blockly.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; + Blockly.Generator.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; return ""; }; -Blockly.Arduino.sensebox_lora_ttn_mapper = function (block) { - var latitude = Blockly.Arduino.valueToCode( +Blockly.Generator.Arduino.forBlock["sensebox_lora_ttn_mapper"] = function ( + block, + generator, +) { + var latitude = Blockly.Generator.Arduino.valueToCode( this, "Latitude", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var longitude = Blockly.Arduino.valueToCode( + var longitude = Blockly.Generator.Arduino.valueToCode( this, "Longitude", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var altitude = Blockly.Arduino.valueToCode( + var altitude = Blockly.Generator.Arduino.valueToCode( this, "Altitude", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var pDOP = Blockly.Arduino.valueToCode( + var pDOP = Blockly.Generator.Arduino.valueToCode( this, "pDOP", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var fixType = Blockly.Arduino.valueToCode( + var fixType = Blockly.Generator.Arduino.valueToCode( this, "Fix Type", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); var fixTypeLimit = this.getFieldValue("dropdown"); - Blockly.Arduino.functionNames_["functions_do_send"] = ` + Blockly.Generator.Arduino.functionNames_["functions_do_send"] = ` void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { @@ -269,19 +292,22 @@ Blockly.Arduino.sensebox_lora_ttn_mapper = function (block) { } // Next TX is scheduled after TX_COMPLETE event. }`; - Blockly.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; + Blockly.Generator.Arduino.loopCodeOnce_["os_runloop"] = "os_runloop_once();"; return ""; }; -Blockly.Arduino.sensebox_lora_initialize_abp = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_lora_initialize_abp"] = function ( + block, + generator, +) { var nwskey = this.getFieldValue("NWSKEY"); var appskey = this.getFieldValue("APPSKEY"); var devaddr = this.getFieldValue("DEVADDR"); var interval = this.getFieldValue("INTERVAL"); - Blockly.Arduino.libraries_["library_spi"] = "#include "; - Blockly.Arduino.libraries_["library_lmic"] = "#include "; - Blockly.Arduino.libraries_["library_hal"] = "#include "; - Blockly.Arduino.definitions_["define_LoRaVariablesABP"] = ` + Blockly.Generator.Arduino.libraries_["library_spi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_lmic"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_hal"] = "#include "; + Blockly.Generator.Arduino.definitions_["define_LoRaVariablesABP"] = ` // LoRaWAN NwkSKey, network session key // This is the default Semtech key, which is used by the early prototype TTN // network. @@ -316,7 +342,7 @@ Blockly.Arduino.sensebox_lora_initialize_abp = function (block) { .dio = {PIN_XB1_INT, PIN_XB1_INT, LMIC_UNUSED_PIN}, };`; - Blockly.Arduino.codeFunctions_["functions_initLora"] = ` + Blockly.Generator.Arduino.codeFunctions_["functions_initLora"] = ` void initLora() { delay(2000); // LMIC init @@ -384,7 +410,7 @@ Blockly.Arduino.sensebox_lora_initialize_abp = function (block) { do_send(&sendjob); }`; - Blockly.Arduino.codeFunctions_["functions_onEvent"] = ` + Blockly.Generator.Arduino.codeFunctions_["functions_onEvent"] = ` void onEvent (ev_t ev) { Serial.print(os_getTime()); Serial.print(": "); @@ -449,85 +475,141 @@ Blockly.Arduino.sensebox_lora_initialize_abp = function (block) { break; } }`; - Blockly.Arduino.loraSetupCode_["initLora"] = "initLora();\n"; - Blockly.Arduino.setupCode_["serial.begin"] = + Blockly.Generator.Arduino.loraSetupCode_["initLora"] = "initLora();\n"; + Blockly.Generator.Arduino.setupCode_["serial.begin"] = "Serial.begin(9600);\ndelay(1000);\n"; return ""; }; -Blockly.Arduino.sensebox_lora_cayenne_temperature = function (block) { - var temperature = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; - var channel = this.getFieldValue("CHANNEL"); - var code = `lpp.addTemperature(${channel}, ${temperature});\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_temperature"] = + function (block, generator) { + var temperature = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; + var channel = this.getFieldValue("CHANNEL"); + var code = `lpp.addTemperature(${channel}, ${temperature});\n`; + return code; + }; -Blockly.Arduino.sensebox_lora_cayenne_humidity = function (block) { - var humidity = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; - var channel = this.getFieldValue("CHANNEL"); - var code = `lpp.addRelativeHumidity(${channel}, ${humidity});\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_humidity"] = + function (block, generator) { + var humidity = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; + var channel = this.getFieldValue("CHANNEL"); + var code = `lpp.addRelativeHumidity(${channel}, ${humidity});\n`; + return code; + }; -Blockly.Arduino.sensebox_lora_cayenne_pressure = function (block) { - var pressure = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; - var channel = this.getFieldValue("CHANNEL"); - var code = `lpp.addBarometricPressure(${channel}, ${pressure});\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_pressure"] = + function (block, generator) { + var pressure = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; + var channel = this.getFieldValue("CHANNEL"); + var code = `lpp.addBarometricPressure(${channel}, ${pressure});\n`; + return code; + }; -Blockly.Arduino.sensebox_lora_cayenne_luminosity = function (block) { - var luminosity = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; - var channel = this.getFieldValue("CHANNEL"); - var code = `lpp.addLuminosity(${channel}, ${luminosity});\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_luminosity"] = + function (block, generator) { + var luminosity = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; + var channel = this.getFieldValue("CHANNEL"); + var code = `lpp.addLuminosity(${channel}, ${luminosity});\n`; + return code; + }; -Blockly.Arduino.sensebox_lora_cayenne_sensor = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_sensor"] = function ( + block, + generator, +) { var sensorValue = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var channel = this.getFieldValue("CHANNEL"); var code = `lpp.addAnalogInput(${channel}, ${sensorValue});\n`; return code; }; -Blockly.Arduino.sensebox_lora_cayenne_accelerometer = function (block) { +Blockly.Generator.Arduino.sensebox_lora_cayenne_accelerometer = function ( + block, +) { var x = - Blockly.Arduino.valueToCode(this, "X", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "X", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var y = - Blockly.Arduino.valueToCode(this, "Y", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "Y", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var z = - Blockly.Arduino.valueToCode(this, "Z", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "Z", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var channel = this.getFieldValue("CHANNEL"); var code = `lpp.addAccelerometer(${channel}, ${x}, ${y}, ${z});\n`; return code; }; -Blockly.Arduino.sensebox_lora_cayenne_gps = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_lora_cayenne_gps"] = function ( + block, + generator, +) { var lat = - Blockly.Arduino.valueToCode(this, "LAT", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "LAT", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var lng = - Blockly.Arduino.valueToCode(this, "LNG", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "LNG", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var alt = - Blockly.Arduino.valueToCode(this, "ALT", Blockly.Arduino.ORDER_ATOMIC) || 0; + Blockly.Generator.Arduino.valueToCode( + this, + "ALT", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var channel = this.getFieldValue("CHANNEL"); var code = `lpp.addGPS(${channel}, ${lat}, ${lng}, ${alt});\n`; return code; }; -Blockly.Arduino.sensebox_lora_cayenne_concentration = function (block) { +Blockly.Generator.Arduino.sensebox_lora_cayenne_concentration = function ( + block, +) { var value = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - 0; + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || 0; var channel = this.getFieldValue("CHANNEL"); var code = `lpp.addConcentration(${channel}, ${value});\n`; return code; diff --git a/src/components/Blockly/generator/sensebox-motors.js b/src/components/Blockly/generator/sensebox-motors.js index 775e51b4..da5bcdcd 100644 --- a/src/components/Blockly/generator/sensebox-motors.js +++ b/src/components/Blockly/generator/sensebox-motors.js @@ -4,81 +4,96 @@ import * as Blockly from "blockly/core"; * Servo Motor * */ -Blockly.Arduino.sensebox_motors_beginServoMotor = function () { - var pin = this.getFieldValue("pin"); - Blockly.Arduino.libraries_["include_servo_motor"] = "#include "; - Blockly.Arduino.definitions_[`define_servo_motor_${pin}`] = - `Servo servo_motor_${pin}; // servo Motor`; - Blockly.Arduino.setupCode_[`setup_servo_motor_${pin}`] = - `servo_motor_${pin}.attach(${pin}); // attach servo motor to pin ${pin}`; - var code = ""; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_motors_beginServoMotor"] = + function () { + var pin = this.getFieldValue("pin"); + Blockly.Generator.Arduino.libraries_["include_servo_motor"] = + "#include "; + Blockly.Generator.Arduino.definitions_[`define_servo_motor_${pin}`] = + `Servo servo_motor_${pin}; // servo Motor`; + Blockly.Generator.Arduino.setupCode_[`setup_servo_motor_${pin}`] = + `servo_motor_${pin}.attach(${pin}); // attach servo motor to pin ${pin}`; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_motors_moveServoMotor = function () { - var pin = this.getFieldValue("pin"); - var degrees = - Blockly.Arduino.valueToCode( - this, - "degrees", - Blockly.Arduino.ORDER_ATOMIC, - ) || "90"; - var code = `servo_motor_${pin}.write(${degrees}); // move servo motor to ${degrees} degrees\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_motors_moveServoMotor"] = + function () { + var pin = this.getFieldValue("pin"); + var degrees = + Blockly.Generator.Arduino.valueToCode( + this, + "degrees", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "90"; + var code = `servo_motor_${pin}.write(${degrees}); // move servo motor to ${degrees} degrees\n`; + return code; + }; /** * I2C Motor Board * */ -Blockly.Arduino.sensebox_motors_I2CMotorBoard_begin = function () { - Blockly.Arduino.libraries_["include_i2c_motor_board"] = - "#include "; - Blockly.Arduino.definitions_["define_i2c_motor_board"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_motors_I2CMotorBoard_begin"] = + function () { + Blockly.Generator.Arduino.libraries_["include_i2c_motor_board"] = + "#include "; + Blockly.Generator.Arduino.definitions_["define_i2c_motor_board"] = ` #define I2C_MOTOR_BOARD_ADDRESS 0x0f // default I2C address of I2C Motor Board`; - Blockly.Arduino.setupCode_["setup_i2c_motor_board"] = ` + Blockly.Generator.Arduino.setupCode_["setup_i2c_motor_board"] = ` Motor.begin(I2C_MOTOR_BOARD_ADDRESS); // Initialize I2C Motor Board`; - var code = ""; - return code; -}; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_motors_I2CMotorBoard_moveDCMotor = function () { - var motor = this.getFieldValue("motor"); - var speed = - Blockly.Arduino.valueToCode(this, "speed", Blockly.Arduino.ORDER_ATOMIC) || - "50"; - var code = `Motor.speed(MOTOR${motor}, ${speed}); // set speed of motor\n`; - return code; -}; +Blockly.Generator.Arduino.sensebox_motors_I2CMotorBoard_moveDCMotor = + function () { + var motor = this.getFieldValue("motor"); + var speed = + Blockly.Generator.Arduino.valueToCode( + this, + "speed", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "50"; + var code = `Motor.speed(MOTOR${motor}, ${speed}); // set speed of motor\n`; + return code; + }; -Blockly.Arduino.sensebox_motors_I2CMotorBoard_stopDCMotor = function () { - var motor = this.getFieldValue("motor"); - var code = `Motor.stop(MOTOR${motor}); // stop motor\n`; - return code; -}; +Blockly.Generator.Arduino.sensebox_motors_I2CMotorBoard_stopDCMotor = + function () { + var motor = this.getFieldValue("motor"); + var code = `Motor.stop(MOTOR${motor}); // stop motor\n`; + return code; + }; /** * Stepper Motor */ -Blockly.Arduino.sensebox_motors_beginStepperMotor = function () { - var in1 = this.getFieldValue("in1"); - var in2 = this.getFieldValue("in2"); - var in3 = this.getFieldValue("in3"); - var in4 = this.getFieldValue("in4"); - var rpm = this.getFieldValue("rpm"); - Blockly.Arduino.libraries_["include_stepper_motor"] = "#include "; - Blockly.Arduino.definitions_["define_stepper_motor"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_motors_beginStepperMotor"] = + function () { + var in1 = this.getFieldValue("in1"); + var in2 = this.getFieldValue("in2"); + var in3 = this.getFieldValue("in3"); + var in4 = this.getFieldValue("in4"); + var rpm = this.getFieldValue("rpm"); + Blockly.Generator.Arduino.libraries_["include_stepper_motor"] = + "#include "; + Blockly.Generator.Arduino.definitions_["define_stepper_motor"] = ` Stepper stepper_motor(2048, ${in1}, ${in2}, ${in3}, ${in4}); // stepper Motor with 2048 steps per rotation`; - Blockly.Arduino.setupCode_["setup_stepper_motor"] = - `stepper_motor.setSpeed(${rpm}); // speed in rotations per minute`; - var code = ""; - return code; -}; + Blockly.Generator.Arduino.setupCode_["setup_stepper_motor"] = + `stepper_motor.setSpeed(${rpm}); // speed in rotations per minute`; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_motors_moveStepperMotor = function () { - var steps = - Blockly.Arduino.valueToCode(this, "steps", Blockly.Arduino.ORDER_ATOMIC) || - "2048"; - var code = `stepper_motor.step(${steps}); // 2048 steps correspond to one rotation\n`; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_motors_moveStepperMotor"] = + function () { + var steps = + Blockly.Generator.Arduino.valueToCode( + this, + "steps", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "2048"; + var code = `stepper_motor.step(${steps}); // 2048 steps correspond to one rotation\n`; + return code; + }; diff --git a/src/components/Blockly/generator/sensebox-ntp.js b/src/components/Blockly/generator/sensebox-ntp.js index 75c527aa..15e41d10 100644 --- a/src/components/Blockly/generator/sensebox-ntp.js +++ b/src/components/Blockly/generator/sensebox-ntp.js @@ -1,18 +1,21 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; -Blockly.Arduino.sensebox_ntp_init = function () { - Blockly.Arduino.libraries_["WiFiUdp"] = `#include `; - Blockly.Arduino.libraries_["NTPClient"] = `#include `; - Blockly.Arduino.definitions_["WiFiUDP"] = `WiFiUDP ntpUDP;`; - Blockly.Arduino.definitions_["NTPClient"] = `NTPClient timeClient(ntpUDP);`; - Blockly.Arduino.setupCode_["timeclient.begin"] = `timeClient.begin();`; - Blockly.Arduino.setupCode_["timeclient.update"] = `timeClient.update();`; +Blockly.Generator.Arduino.forBlock["sensebox_ntp_init"] = function () { + Blockly.Generator.Arduino.libraries_["WiFiUdp"] = `#include `; + Blockly.Generator.Arduino.libraries_["NTPClient"] = `#include `; + Blockly.Generator.Arduino.definitions_["WiFiUDP"] = `WiFiUDP ntpUDP;`; + Blockly.Generator.Arduino.definitions_["NTPClient"] = + `NTPClient timeClient(ntpUDP);`; + Blockly.Generator.Arduino.setupCode_["timeclient.begin"] = + `timeClient.begin();`; + Blockly.Generator.Arduino.setupCode_["timeclient.update"] = + `timeClient.update();`; var code = ``; return code; }; -Blockly.Arduino.sensebox_ntp_get = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ntp_get"] = function () { var format = this.getFieldValue("dropdown"); var code = `timeClient.${format}()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/generator/sensebox-osem.js b/src/components/Blockly/generator/sensebox-osem.js index f59e8ff8..0696eb79 100644 --- a/src/components/Blockly/generator/sensebox-osem.js +++ b/src/components/Blockly/generator/sensebox-osem.js @@ -1,22 +1,31 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; /** * Block send Data to the openSenseMap */ -Blockly.Arduino.sensebox_send_to_osem = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_send_to_osem"] = function ( + block, + generator, +) { var code = ""; var sensor_id = this.getFieldValue("SensorID"); var id = sensor_id.slice(-3).toUpperCase(); var sensor_value = - Blockly.Arduino.valueToCode(this, "Value", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; - Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] = + Blockly.Generator.Arduino.valueToCode( + this, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; + Blockly.Generator.Arduino.definitions_["SENSOR_ID" + id + ""] = "const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";'; code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n"; return code; }; -Blockly.Arduino.sensebox_osem_connection = function (Block) { +Blockly.Generator.Arduino.forBlock["sensebox_osem_connection"] = function ( + block, + generator, +) { var workspace = Blockly.getMainWorkspace(); var wifi = false; var ethernet = false; @@ -28,7 +37,7 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { wifi = false; } var box_id = this.getFieldValue("BoxID"); - var branch = Blockly.Arduino.statementToCode(Block, "DO"); + var branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); var access_token = this.getFieldValue("access_token"); var blocks = this.getDescendants(); var type = this.getFieldValue("type"); @@ -44,80 +53,88 @@ Blockly.Arduino.sensebox_osem_connection = function (Block) { } } var num_sensors = count; - Blockly.Arduino.definitions_["num_sensors"] = + Blockly.Generator.Arduino.definitions_["num_sensors"] = "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; - Blockly.Arduino.definitions_["SenseBoxID"] = + Blockly.Generator.Arduino.definitions_["SenseBoxID"] = 'const char SENSEBOX_ID [] PROGMEM = "' + box_id + '";'; - Blockly.Arduino.definitions_["host"] = + Blockly.Generator.Arduino.definitions_["host"] = 'const char server [] PROGMEM ="ingress.opensensemap.org";'; if (wifi === true) { if (ssl === "TRUE") { - Blockly.Arduino.libraries_["library_bearSSL"] = + Blockly.Generator.Arduino.libraries_["library_bearSSL"] = "#include "; - Blockly.Arduino.libraries_["library_arduinoECC08"] = + Blockly.Generator.Arduino.libraries_["library_arduinoECC08"] = "#include "; - Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient wifiClient;"; - Blockly.Arduino.definitions_["BearSSLClient"] = + Blockly.Generator.Arduino.definitions_["WiFiClient"] = + "WiFiClient wifiClient;"; + Blockly.Generator.Arduino.definitions_["BearSSLClient"] = "BearSSLClient client(wifiClient);"; - Blockly.Arduino.functionNames_["getTime"] = `unsigned long getTime() { + Blockly.Generator.Arduino.functionNames_["getTime"] = + `unsigned long getTime() { return WiFi.getTime(); }`; - Blockly.Arduino.setupCode_["initBearSSL"] = + Blockly.Generator.Arduino.setupCode_["initBearSSL"] = "ArduinoBearSSL.onGetTime(getTime);"; port = 443; } else if (ssl === "FALSE") { - Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;"; + Blockly.Generator.Arduino.definitions_["WiFiClient"] = + "WiFiClient client;"; port = 80; } } else if (ethernet === true) { if (ssl === "TRUE") { - Blockly.Arduino.libraries_["library_bearSSL"] = + Blockly.Generator.Arduino.libraries_["library_bearSSL"] = "#include "; - Blockly.Arduino.libraries_["library_arduinoECC08"] = + Blockly.Generator.Arduino.libraries_["library_arduinoECC08"] = "#include "; - Blockly.Arduino.libraries_["library_ethernetUdp"] = + Blockly.Generator.Arduino.libraries_["library_ethernetUdp"] = "#include "; - Blockly.Arduino.libraries_["library_NTPClient"] = + Blockly.Generator.Arduino.libraries_["library_NTPClient"] = "#include "; - Blockly.Arduino.definitions_["EthernetClient"] = + Blockly.Generator.Arduino.definitions_["EthernetClient"] = "EthernetClient eclient;"; - Blockly.Arduino.definitions_["BearSSLClient"] = + Blockly.Generator.Arduino.definitions_["BearSSLClient"] = "BearSSLClient client(eclient);"; - Blockly.Arduino.definitions_["EthernetUDP"] = "EthernetUDP Udp;"; - Blockly.Arduino.definitions_["NTPClient"] = "NTPClient timeClient(Udp);"; - Blockly.Arduino.functionNames_["getTime"] = ` + Blockly.Generator.Arduino.definitions_["EthernetUDP"] = + "EthernetUDP Udp;"; + Blockly.Generator.Arduino.definitions_["NTPClient"] = + "NTPClient timeClient(Udp);"; + Blockly.Generator.Arduino.functionNames_["getTime"] = ` unsigned long getTime() { timeClient.update(); return timeClient.getEpochTime(); }`; - Blockly.Arduino.setupCode_["timeClient_begin"] = "timeClient.begin();"; - Blockly.Arduino.setupCode_["initBearSSL"] = + Blockly.Generator.Arduino.setupCode_["timeClient_begin"] = + "timeClient.begin();"; + Blockly.Generator.Arduino.setupCode_["initBearSSL"] = "ArduinoBearSSL.onGetTime(getTime);"; port = 443; } else if (ssl === "FALSE") { - Blockly.Arduino.definitions_["EthernetClient"] = "EthernetClient client;"; + Blockly.Generator.Arduino.definitions_["EthernetClient"] = + "EthernetClient client;"; port = 80; } } - Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement { + Blockly.Generator.Arduino.definitions_["measurement"] = + `typedef struct measurement { const char *sensorId; float value; } measurement;`; - Blockly.Arduino.definitions_["buffer"] = "char buffer[750];"; - Blockly.Arduino.definitions_["num_measurement"] = + Blockly.Generator.Arduino.definitions_["buffer"] = "char buffer[750];"; + Blockly.Generator.Arduino.definitions_["num_measurement"] = `measurement measurements[NUM_SENSORS]; uint8_t num_measurements = 0;`; - Blockly.Arduino.definitions_["lengthMultiplikator"] = + Blockly.Generator.Arduino.definitions_["lengthMultiplikator"] = "const int lengthMultiplikator = 35;"; - Blockly.Arduino.functionNames_["addMeasurement"] = ` + Blockly.Generator.Arduino.functionNames_["addMeasurement"] = ` void addMeasurement(const char *sensorId, float value) { measurements[num_measurements].sensorId = sensorId; measurements[num_measurements].value = value; num_measurements++; }`; if (type === "Stationary") { - Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToClient"] = ` void writeMeasurementsToClient() { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -129,7 +146,7 @@ unsigned long getTime() { // reset num_measurements num_measurements = 0; }`; - Blockly.Arduino.functionNames_["submitValues"] = + Blockly.Generator.Arduino.functionNames_["submitValues"] = ` void submitValues() { ${ @@ -197,29 +214,29 @@ ${ code += branch; code += "submitValues();\n"; } else if (type === "Mobile") { - var lat = Blockly.Arduino.valueToCode( + var lat = Blockly.Generator.Arduino.valueToCode( Block, "lat", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var lng = Blockly.Arduino.valueToCode( + var lng = Blockly.Generator.Arduino.valueToCode( Block, "lng", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var timestamp = Blockly.Arduino.valueToCode( + var timestamp = Blockly.Generator.Arduino.valueToCode( Block, "timeStamp", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var altitude = Blockly.Arduino.valueToCode( + var altitude = Blockly.Generator.Arduino.valueToCode( Block, "altitude", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly.Arduino.definitions_["lengthMultiplikator"] = + Blockly.Generator.Arduino.definitions_["lengthMultiplikator"] = "const int lengthMultiplikator = 77;"; - Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToClient"] = ` void writeMeasurementsToClient(float lat, float lng, float altitude, char* timeStamp) { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -231,9 +248,9 @@ ${ // reset num_measurements num_measurements = 0; }`; - Blockly.Arduino.variables_["latitude"] = "float latitude;"; - Blockly.Arduino.variables_["longitude"] = "float longitude;"; - Blockly.Arduino.functionNames_["submitValues"] = + Blockly.Generator.Arduino.variables_["latitude"] = "float latitude;"; + Blockly.Generator.Arduino.variables_["longitude"] = "float longitude;"; + Blockly.Generator.Arduino.functionNames_["submitValues"] = ` void submitValues(float lat, float lng, float altitude, char* timeStamp) { if (client.connected()) { @@ -308,49 +325,52 @@ ${ return code; }; -Blockly.Arduino.sensebox_esp32s2_osem_connection = function (Block) { - var workspace = Blockly.getMainWorkspace(); - var wifi = false; - var ethernet = false; - if (workspace.getBlocksByType("sensebox_wifi").length > 0) { - wifi = true; - ethernet = false; - } else if (workspace.getBlocksByType("sensebox_ethernet").length > 0) { - ethernet = true; - wifi = false; - } - var box_id = this.getFieldValue("BoxID"); - var branch = Blockly.Arduino.statementToCode(Block, "DO"); - var access_token = this.getFieldValue("access_token"); - var blocks = this.getDescendants(); - var type = this.getFieldValue("type"); - var ssl = this.getFieldValue("SSL"); - var restart = this.getFieldValue("RESTART"); - var port; - var count = 0; - if (blocks !== undefined) { - for (var i = 0; i < blocks.length; i++) { - if (blocks[i].type === "sensebox_send_to_osem") { - count++; +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_osem_connection"] = + function (block, generator) { + var workspace = Blockly.getMainWorkspace(); + var wifi = false; + var ethernet = false; + if (workspace.getBlocksByType("sensebox_wifi").length > 0) { + wifi = true; + ethernet = false; + } else if (workspace.getBlocksByType("sensebox_ethernet").length > 0) { + ethernet = true; + wifi = false; + } + var box_id = this.getFieldValue("BoxID"); + var branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + var access_token = this.getFieldValue("access_token"); + var blocks = this.getDescendants(); + var type = this.getFieldValue("type"); + var ssl = this.getFieldValue("SSL"); + var restart = this.getFieldValue("RESTART"); + var port; + var count = 0; + if (blocks !== undefined) { + for (var i = 0; i < blocks.length; i++) { + if (blocks[i].type === "sensebox_send_to_osem") { + count++; + } } } - } - var num_sensors = count; - Blockly.Arduino.definitions_["num_sensors"] = - "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; - Blockly.Arduino.definitions_["SenseBoxID"] = - 'const char* SENSEBOX_ID = "' + box_id + '";'; - Blockly.Arduino.definitions_["host"] = - 'const char* server ="ingress.opensensemap.org";'; - Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement { + var num_sensors = count; + Blockly.Generator.Arduino.definitions_["num_sensors"] = + "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; + Blockly.Generator.Arduino.definitions_["SenseBoxID"] = + 'const char* SENSEBOX_ID = "' + box_id + '";'; + Blockly.Generator.Arduino.definitions_["host"] = + 'const char* server ="ingress.opensensemap.org";'; + Blockly.Generator.Arduino.definitions_["measurement"] = + `typedef struct measurement { const char *sensorId; float value; } measurement;`; - if (ssl === "TRUE") { - Blockly.Arduino.libraries_["library_wifiClientSecure"] = - "#include "; - Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClientSecure client;"; - Blockly.Arduino.definitions_["root_ca"] = `const char* root_ca = + if (ssl === "TRUE") { + Blockly.Generator.Arduino.libraries_["library_wifiClientSecure"] = + "#include "; + Blockly.Generator.Arduino.definitions_["WiFiClient"] = + "WiFiClientSecure client;"; + Blockly.Generator.Arduino.definitions_["root_ca"] = `const char* root_ca = "-----BEGIN CERTIFICATE-----\\n" "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\\n" "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\\n" @@ -382,28 +402,29 @@ Blockly.Arduino.sensebox_esp32s2_osem_connection = function (Block) { "mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\\n" "emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\\n" "-----END CERTIFICATE-----\\n";`; - Blockly.Arduino.setupCode_["wifiClientSecure_setRootCa"] = - "client.setCACert(root_ca);"; - port = 443; - } else if (ssl === "FALSE") { - Blockly.Arduino.definitions_["WiFiClient"] = "WiFiClient client;"; - port = 80; - } - Blockly.Arduino.definitions_["buffer"] = "char buffer[750];"; - Blockly.Arduino.definitions_["num_measurement"] = - `measurement measurements[NUM_SENSORS]; + Blockly.Generator.Arduino.setupCode_["wifiClientSecure_setRootCa"] = + "client.setCACert(root_ca);"; + port = 443; + } else if (ssl === "FALSE") { + Blockly.Generator.Arduino.definitions_["WiFiClient"] = + "WiFiClient client;"; + port = 80; + } + Blockly.Generator.Arduino.definitions_["buffer"] = "char buffer[750];"; + Blockly.Generator.Arduino.definitions_["num_measurement"] = + `measurement measurements[NUM_SENSORS]; uint8_t num_measurements = 0;`; - Blockly.Arduino.definitions_["lengthMultiplikator"] = - "const int lengthMultiplikator = 35;"; - Blockly.Arduino.functionNames_["addMeasurement"] = ` + Blockly.Generator.Arduino.definitions_["lengthMultiplikator"] = + "const int lengthMultiplikator = 35;"; + Blockly.Generator.Arduino.functionNames_["addMeasurement"] = ` void addMeasurement(const char *sensorId, float value) { measurements[num_measurements].sensorId = sensorId; measurements[num_measurements].value = value; num_measurements++; }`; - if (type === "Stationary") { - Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` + if (type === "Stationary") { + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToClient"] = ` void writeMeasurementsToClient() { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -415,8 +436,8 @@ Blockly.Arduino.sensebox_esp32s2_osem_connection = function (Block) { // reset num_measurements num_measurements = 0; }`; - Blockly.Arduino.functionNames_["submitValues"] = - ` + Blockly.Generator.Arduino.functionNames_["submitValues"] = + ` void submitValues() { ${ wifi === true @@ -432,8 +453,8 @@ ${ strcpy_P(_server, server); for (uint8_t timeout = 2; timeout != 0; timeout--) { connected = client.connect(_server, ` + - port + - `); + port + + `); if (connected == true) { // construct the HTTP POST request: sprintf_P(buffer,PSTR("POST /boxes/%s/data HTTP/1.1\\nAuthorization: ${access_token}\\nHost: %s\\nContent-Type:text/csv\\nConnection: close\\nContent-Length: %i\\n\\n"), @@ -464,33 +485,33 @@ ${ }`; - var code = ""; - code += branch; - code += "submitValues();\n"; - } else if (type === "Mobile") { - var lat = Blockly.Arduino.valueToCode( - Block, - "lat", - Blockly.Arduino.ORDER_ATOMIC, - ); - var lng = Blockly.Arduino.valueToCode( - Block, - "lng", - Blockly.Arduino.ORDER_ATOMIC, - ); - var timestamp = Blockly.Arduino.valueToCode( - Block, - "timeStamp", - Blockly.Arduino.ORDER_ATOMIC, - ); - var altitude = Blockly.Arduino.valueToCode( - Block, - "altitude", - Blockly.Arduino.ORDER_ATOMIC, - ); - Blockly.Arduino.definitions_["lengthMultiplikator"] = - "const int lengthMultiplikator = 77;"; - Blockly.Arduino.functionNames_["writeMeasurementsToClient"] = ` + var code = ""; + code += branch; + code += "submitValues();\n"; + } else if (type === "Mobile") { + var lat = Blockly.Generator.Arduino.valueToCode( + Block, + "lat", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var lng = Blockly.Generator.Arduino.valueToCode( + Block, + "lng", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var timestamp = Blockly.Generator.Arduino.valueToCode( + Block, + "timeStamp", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var altitude = Blockly.Generator.Arduino.valueToCode( + Block, + "altitude", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + Blockly.Generator.Arduino.definitions_["lengthMultiplikator"] = + "const int lengthMultiplikator = 77;"; + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToClient"] = ` void writeMeasurementsToClient(float lat, float lng, float altitude, char* timeStamp) { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -502,10 +523,10 @@ ${ // reset num_measurements num_measurements = 0; }`; - Blockly.Arduino.variables_["latitude"] = "float latitude;"; - Blockly.Arduino.variables_["longitude"] = "float longitude;"; - Blockly.Arduino.functionNames_["submitValues"] = - ` + Blockly.Generator.Arduino.variables_["latitude"] = "float latitude;"; + Blockly.Generator.Arduino.variables_["longitude"] = "float longitude;"; + Blockly.Generator.Arduino.functionNames_["submitValues"] = + ` void submitValues(float lat, float lng, float altitude, char* timeStamp) { if (client.connected()) { client.stop(); @@ -516,8 +537,8 @@ ${ strcpy_P(_server, server); for (uint8_t timeout = 2; timeout != 0; timeout--) { connected = client.connect(_server, ` + - port + - `); + port + + `); if (connected == true) { // construct the HTTP POST request: sprintf_P(buffer, @@ -561,18 +582,18 @@ ${ } }`; - code = ""; - code += branch; - code += - "submitValues((" + - lat + - "/float(10000000)),(" + - lng + - "/float(10000000)),(" + - altitude + - "/float(100))," + - timestamp + - ");\n"; - } - return code; -}; + code = ""; + code += branch; + code += + "submitValues((" + + lat + + "/float(10000000)),(" + + lng + + "/float(10000000)),(" + + altitude + + "/float(100))," + + timestamp + + ");\n"; + } + return code; + }; diff --git a/src/components/Blockly/generator/sensebox-rtc.js b/src/components/Blockly/generator/sensebox-rtc.js index 399e46b7..17599e77 100644 --- a/src/components/Blockly/generator/sensebox-rtc.js +++ b/src/components/Blockly/generator/sensebox-rtc.js @@ -1,79 +1,94 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; -Blockly.Arduino.sensebox_rtc_init = function () { - Blockly.Arduino.libraries_["RV8523"] = `#include `; - Blockly.Arduino.definitions_["RTC"] = `RV8523 rtc;`; - Blockly.Arduino.setupCode_["rtc.begin"] = `rtc.begin();`; +Blockly.Generator.Arduino.forBlock["sensebox_rtc_init"] = function () { + Blockly.Generator.Arduino.libraries_["RV8523"] = `#include `; + Blockly.Generator.Arduino.definitions_["RTC"] = `RV8523 rtc;`; + Blockly.Generator.Arduino.setupCode_["rtc.begin"] = `rtc.begin();`; var code = ``; return code; }; -Blockly.Arduino.sensebox_rtc_set = function () { +Blockly.Generator.Arduino.forBlock["sensebox_rtc_set"] = function () { var second = - Blockly.Arduino.valueToCode(this, "second", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + this, + "second", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var minutes = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "minutes", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var hour = - Blockly.Arduino.valueToCode(this, "hour", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + this, + "hour", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var day = - Blockly.Arduino.valueToCode(this, "day", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + this, + "day", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var month = - Blockly.Arduino.valueToCode(this, "month", Blockly.Arduino.ORDER_ATOMIC) || - "0"; + Blockly.Generator.Arduino.valueToCode( + this, + "month", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; var year = - Blockly.Arduino.valueToCode(this, "year", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - Blockly.Arduino.libraries_["RV8523"] = `#include `; - Blockly.Arduino.setupCode_["rtc.start"] = `rtc.start();`; - Blockly.Arduino.setupCode_["rtc.batterySwitchOver"] = + Blockly.Generator.Arduino.valueToCode( + this, + "year", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + Blockly.Generator.Arduino.libraries_["RV8523"] = `#include `; + Blockly.Generator.Arduino.setupCode_["rtc.start"] = `rtc.start();`; + Blockly.Generator.Arduino.setupCode_["rtc.batterySwitchOver"] = `rtc.batterySwitchOver(1);`; - Blockly.Arduino.setupCode_["rtc.set"] = + Blockly.Generator.Arduino.setupCode_["rtc.set"] = `rtc.set(${second}, ${minutes}, ${hour}, ${day}, ${month}, ${year});`; var code = ``; return code; }; -Blockly.Arduino.sensebox_rtc_ntp = function () { - Blockly.Arduino.libraries_["RV8523"] = `#include `; - Blockly.Arduino.setupCode_["rtc.start"] = `rtc.start();`; - Blockly.Arduino.setupCode_["rtc.batterySwitchOver"] = +Blockly.Generator.Arduino.forBlock["sensebox_rtc_ntp"] = function () { + Blockly.Generator.Arduino.libraries_["RV8523"] = `#include `; + Blockly.Generator.Arduino.setupCode_["rtc.start"] = `rtc.start();`; + Blockly.Generator.Arduino.setupCode_["rtc.batterySwitchOver"] = `rtc.batterySwitchOver(1);`; - Blockly.Arduino.setupCode_["rtc.set"] = + Blockly.Generator.Arduino.setupCode_["rtc.set"] = `rtc.set(SECOND, MINUTE, HOUR, DAY, MONTH, YEAR);`; var code = ``; return code; }; -Blockly.Arduino.sensebox_rtc_get = function () { +Blockly.Generator.Arduino.forBlock["sensebox_rtc_get"] = function () { var dropdown = this.getFieldValue("dropdown"); - Blockly.Arduino.libraries_["RV8523"] = `#include `; - Blockly.Arduino.setupCode_["rtc.start"] = `rtc.start();`; - Blockly.Arduino.setupCode_["rtc.batterySwitchOver"] = + Blockly.Generator.Arduino.libraries_["RV8523"] = `#include `; + Blockly.Generator.Arduino.setupCode_["rtc.start"] = `rtc.start();`; + Blockly.Generator.Arduino.setupCode_["rtc.batterySwitchOver"] = `rtc.batterySwitchOver(1);`; - Blockly.Arduino.loopCodeOnce_["rtc_variables"] = + Blockly.Generator.Arduino.loopCodeOnce_["rtc_variables"] = `uint8_t sec, min, hour, day, month;\nuint16_t year;`; - Blockly.Arduino.loopCodeOnce_["rtc_get"] = + Blockly.Generator.Arduino.loopCodeOnce_["rtc_get"] = `rtc.get(&sec, &min, &hour, &day, &month, &year);`; var code = `${dropdown}`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_rtc_get_timestamp = function () { - Blockly.Arduino.libraries_["RV8523"] = `#include `; - Blockly.Arduino.setupCode_["rtc.start"] = `rtc.start();`; - Blockly.Arduino.setupCode_["rtc.batterySwitchOver"] = +Blockly.Generator.Arduino.forBlock["sensebox_rtc_get_timestamp"] = function () { + Blockly.Generator.Arduino.libraries_["RV8523"] = `#include `; + Blockly.Generator.Arduino.setupCode_["rtc.start"] = `rtc.start();`; + Blockly.Generator.Arduino.setupCode_["rtc.batterySwitchOver"] = `rtc.batterySwitchOver(1);`; - Blockly.Arduino.variables_["rtc_timestamp"] = `char timestamp[20];`; - Blockly.Arduino.codeFunctions_["getTimeStamp"] = ` + Blockly.Generator.Arduino.variables_["rtc_timestamp"] = `char timestamp[20];`; + Blockly.Generator.Arduino.codeFunctions_["getTimeStamp"] = ` char* getTimeStamp() { uint8_t sec, min, hour, day, month; uint16_t year; @@ -83,34 +98,40 @@ uint8_t sec, min, hour, day, month; } `; var code = `getTimeStamp()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_internal_rtc_init = function () { - Blockly.Arduino.libraries_["RTClib"] = `#include `; - Blockly.Arduino.definitions_["RTC"] = `RTCZero rtc;`; - Blockly.Arduino.setupCode_["rtc.begin"] = `rtc.begin();`; +Blockly.Generator.Arduino.forBlock["sensebox_internal_rtc_init"] = function () { + Blockly.Generator.Arduino.libraries_["RTClib"] = `#include `; + Blockly.Generator.Arduino.definitions_["RTC"] = `RTCZero rtc;`; + Blockly.Generator.Arduino.setupCode_["rtc.begin"] = `rtc.begin();`; return ""; }; -Blockly.Arduino.sensebox_internal_rtc_set = function () { +Blockly.Generator.Arduino.forBlock["sensebox_internal_rtc_set"] = function () { var branch = - Blockly.Arduino.valueToCode(this, "time", Blockly.Arduino.ORDER_ATOMIC) || - "0"; - Blockly.Arduino.setupCode_["rtc.setEpoch"] = `rtc.setEpoch(${branch});`; + Blockly.Generator.Arduino.valueToCode( + this, + "time", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || "0"; + Blockly.Generator.Arduino.setupCode_["rtc.setEpoch"] = + `rtc.setEpoch(${branch});`; var code = ``; return code; }; -Blockly.Arduino.sensebox_internal_rtc_get = function () { +Blockly.Generator.Arduino.forBlock["sensebox_internal_rtc_get"] = function () { var dropdown = this.getFieldValue("dropdown"); var code = `rtc.get${dropdown}()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_internal_rtc_get_timestamp = function () { - Blockly.Arduino.variables_["rtc_timestamp"] = `char timestamp[20];`; - Blockly.Arduino.codeFunctions_["getTimeStamp"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_internal_rtc_get_timestamp"] = + function () { + Blockly.Generator.Arduino.variables_["rtc_timestamp"] = + `char timestamp[20];`; + Blockly.Generator.Arduino.codeFunctions_["getTimeStamp"] = ` char* getTimeStamp() { uint8_t sec, min, hour, day, month; uint16_t year; @@ -124,6 +145,6 @@ year = rtc.getYear(); return timestamp; } `; - var code = `getTimeStamp()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; + var code = `getTimeStamp()`; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; diff --git a/src/components/Blockly/generator/sensebox-sd.js b/src/components/Blockly/generator/sensebox-sd.js index 858241c4..44b5a176 100644 --- a/src/components/Blockly/generator/sensebox-sd.js +++ b/src/components/Blockly/generator/sensebox-sd.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; /* SD-Card Blocks using the Standard SD Library*/ /** @@ -8,38 +8,51 @@ import Blockly from "blockly"; * @return {array} Completed code with order of operation. */ -Blockly.Arduino.sensebox_sd_create_file = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_sd_create_file"] = function ( + block, + generator, +) { var filename = this.getFieldValue("Filename"); var extension = this.getFieldValue("extension"); var newFileName = filename.concat(".", extension); - Blockly.Arduino.libraries_["library_spi"] = "#include "; - Blockly.Arduino.libraries_["library_sd"] = "#include "; - Blockly.Arduino.definitions_["define_" + filename] = `File ${filename};`; - Blockly.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);\n"; - Blockly.Arduino.setupCode_["sensebox_sd" + filename] = + Blockly.Generator.Arduino.libraries_["library_spi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_sd"] = "#include "; + Blockly.Generator.Arduino.definitions_["define_" + filename] = + `File ${filename};`; + Blockly.Generator.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);\n"; + Blockly.Generator.Arduino.setupCode_["sensebox_sd" + filename] = `${filename} = SD.open("${newFileName}", FILE_WRITE);\n${filename}.close();\n`; var code = ""; return code; }; -Blockly.Arduino.sensebox_sd_open_file = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_sd_open_file"] = function ( + block, + generator, +) { var filename = this.getFieldValue("Filename"); var extension = this.getFieldValue("extension"); var newFileName = filename.concat(".", extension); - var branch = Blockly.Arduino.statementToCode(block, "SD"); + var branch = Blockly.Generator.Arduino.statementToCode(block, "SD"); var code = `${filename} = SD.open("${newFileName}", FILE_WRITE);\n`; code += branch; code += `${filename}.close();\n`; return code; }; -Blockly.Arduino.sensebox_sd_write_file = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_sd_write_file"] = function ( + block, + generator, +) { if (this.parentBlock_ != null) { var filename = this.getSurroundParent().getFieldValue("Filename"); } var branch = - Blockly.Arduino.valueToCode(this, "DATA", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; + Blockly.Generator.Arduino.valueToCode( + this, + "DATA", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; var linebreak = this.getFieldValue("linebreak"); if (linebreak === "TRUE") { linebreak = "ln"; @@ -55,14 +68,14 @@ Blockly.Arduino.sensebox_sd_write_file = function (block) { return code; }; -Blockly.Arduino.sensebox_sd_osem = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sd_osem"] = function () { if (this.parentBlock_ != null) { var filename = this.getSurroundParent().getFieldValue("Filename"); } var type = this.getFieldValue("type"); var blocks = this.getDescendants(); - var branch = Blockly.Arduino.statementToCode(this, "DO"); + var branch = Blockly.Generator.Arduino.statementToCode(this, "DO"); var count = 0; if (blocks !== undefined) { for (var i = 0; i < blocks.length; i++) { @@ -72,31 +85,32 @@ Blockly.Arduino.sensebox_sd_osem = function () { } } var num_sensors = count; - var timestamp = Blockly.Arduino.valueToCode( + var timestamp = Blockly.Generator.Arduino.valueToCode( this, "timeStamp", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly.Arduino.definitions_["num_sensors"] = + Blockly.Generator.Arduino.definitions_["num_sensors"] = "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; - Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement { + Blockly.Generator.Arduino.definitions_["measurement"] = + `typedef struct measurement { const char *sensorId; float value; } measurement;`; - Blockly.Arduino.definitions_["buffer"] = "char buffer[750];"; - Blockly.Arduino.definitions_["num_measurement"] = + Blockly.Generator.Arduino.definitions_["buffer"] = "char buffer[750];"; + Blockly.Generator.Arduino.definitions_["num_measurement"] = `measurement measurements[NUM_SENSORS]; uint8_t num_measurements = 0;`; if (type === "Stationary") { - Blockly.Arduino.functionNames_["addMeasurement"] = ` + Blockly.Generator.Arduino.functionNames_["addMeasurement"] = ` void addMeasurement(const char *sensorId, float value) { measurements[num_measurements].sensorId = sensorId; measurements[num_measurements].value = value; num_measurements++; } `; - Blockly.Arduino.functionNames_["writeMeasurementsToSdCard"] = ` + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToSdCard"] = ` void writeMeasurementsToSdCard(char* timeStamp) { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -108,7 +122,7 @@ sprintf_P(buffer, PSTR("%s,%9.2f,%s"), measurements[i].sensorId, measurements[i] num_measurements = 0; } `; - Blockly.Arduino.functionNames_["saveValues"] = ` + Blockly.Generator.Arduino.functionNames_["saveValues"] = ` void saveValues() { @@ -124,41 +138,43 @@ void saveValues() { /** * add mobile functions here */ - Blockly.Arduino.libraries_["dtostrf.h"] = "#include "; - var lat = Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.libraries_["dtostrf.h"] = + "#include "; + var lat = Blockly.Generator.Arduino.valueToCode( this, "lat", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - var lng = Blockly.Arduino.valueToCode( + var lng = Blockly.Generator.Arduino.valueToCode( this, "lng", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - // var altitude = Blockly.Arduino.valueToCode( + // var altitude = Blockly.Generator.Arduino.valueToCode( // this, // "altitude", - // Blockly.Arduino.ORDER_ATOMIC + // Blockly.Generator.Arduino.ORDER_ATOMIC // ); - Blockly.Arduino.definitions_["num_sensors"] = + Blockly.Generator.Arduino.definitions_["num_sensors"] = "static const uint8_t NUM_SENSORS = " + num_sensors + ";"; - Blockly.Arduino.definitions_["measurement"] = `typedef struct measurement { + Blockly.Generator.Arduino.definitions_["measurement"] = + `typedef struct measurement { const char *sensorId; float value; } measurement;`; - Blockly.Arduino.definitions_["buffer"] = "char buffer[750];"; - Blockly.Arduino.definitions_["num_measurement"] = + Blockly.Generator.Arduino.definitions_["buffer"] = "char buffer[750];"; + Blockly.Generator.Arduino.definitions_["num_measurement"] = `measurement measurements[NUM_SENSORS]; uint8_t num_measurements = 0;`; - Blockly.Arduino.functionNames_["addMeasurement"] = ` + Blockly.Generator.Arduino.functionNames_["addMeasurement"] = ` void addMeasurement(const char *sensorId, float value) { measurements[num_measurements].sensorId = sensorId; measurements[num_measurements].value = value; num_measurements++; } `; - Blockly.Arduino.functionNames_["writeMeasurementsToSdCard"] = ` + Blockly.Generator.Arduino.functionNames_["writeMeasurementsToSdCard"] = ` void writeMeasurementsToSdCard(char* timeStamp, int32_t latitudes, int32_t longitudes) { // iterate throug the measurements array for (uint8_t i = 0; i < num_measurements; i++) { @@ -176,7 +192,7 @@ void writeMeasurementsToSdCard(char* timeStamp, int32_t latitudes, int32_t longi num_measurements = 0; } `; - Blockly.Arduino.functionNames_["saveValues"] = ` + Blockly.Generator.Arduino.functionNames_["saveValues"] = ` void saveValues() { // send measurements writeMeasurementsToSdCard(${timestamp}, ${lat}, ${lng}); @@ -190,14 +206,20 @@ void writeMeasurementsToSdCard(char* timeStamp, int32_t latitudes, int32_t longi return code; }; -Blockly.Arduino.sensebox_sd_save_for_osem = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_sd_save_for_osem"] = function ( + block, + generator, +) { var code = ""; var sensor_id = this.getFieldValue("SensorID"); var id = sensor_id.slice(-3).toUpperCase(); var sensor_value = - Blockly.Arduino.valueToCode(block, "Value", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; - Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] = + Blockly.Generator.Arduino.valueToCode( + block, + "Value", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; + Blockly.Generator.Arduino.definitions_["SENSOR_ID" + id + ""] = "const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";'; code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n"; return code; @@ -207,52 +229,62 @@ Blockly.Arduino.sensebox_sd_save_for_osem = function (block) { * senseBox-esp32-s2 sd Blocks */ -Blockly.Arduino.sensebox_esp32s2_sd_create_file = function (block) { - var filename = this.getFieldValue("Filename"); - var extension = this.getFieldValue("extension"); - var newFileName = filename.concat(".", extension); +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_sd_create_file"] = + function (block, generator) { + var filename = this.getFieldValue("Filename"); + var extension = this.getFieldValue("extension"); + var newFileName = filename.concat(".", extension); - Blockly.Arduino.libraries_["library_sd"] = `#include `; - Blockly.Arduino.libraries_["library_spi"] = `#include `; - Blockly.Arduino.libraries_["library_fs"] = `#include "FS.h"`; + Blockly.Generator.Arduino.libraries_["library_sd"] = `#include `; + Blockly.Generator.Arduino.libraries_["library_spi"] = `#include `; + Blockly.Generator.Arduino.libraries_["library_fs"] = `#include "FS.h"`; - Blockly.Arduino.definitions_["define_" + filename] = `File ${filename};`; - Blockly.Arduino.definitions_["define_sdspi"] = `SPIClass sdspi = SPIClass();`; - Blockly.Arduino.setupCode_["sensebox_esp32s2_sd"] = - "//Init SD\n pinMode(SD_ENABLE,OUTPUT);\n digitalWrite(SD_ENABLE,LOW);\nsdspi.begin(VSPI_SCLK,VSPI_MISO,VSPI_MOSI,VSPI_SS);\n SD.begin(VSPI_SS,sdspi);"; - Blockly.Arduino.setupCode_["sensebox_esp32s2_sd" + filename] = - ` ${filename} = SD.open("/${newFileName}", FILE_WRITE);\n ${filename}.close();\n `; - var code = ""; - return code; -}; + Blockly.Generator.Arduino.definitions_["define_" + filename] = + `File ${filename};`; + Blockly.Generator.Arduino.definitions_["define_sdspi"] = + `SPIClass sdspi = SPIClass();`; + Blockly.Generator.Arduino.setupCode_["sensebox_esp32s2_sd"] = + "//Init SD\n pinMode(SD_ENABLE,OUTPUT);\n digitalWrite(SD_ENABLE,LOW);\nsdspi.begin(VSPI_SCLK,VSPI_MISO,VSPI_MOSI,VSPI_SS);\n SD.begin(VSPI_SS,sdspi);"; + Blockly.Generator.Arduino.setupCode_["sensebox_esp32s2_sd" + filename] = + ` ${filename} = SD.open("/${newFileName}", FILE_WRITE);\n ${filename}.close();\n `; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_esp32s2_sd_open_file = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_sd_open_file"] = function ( + block, + generator, +) { var filename = this.getFieldValue("Filename"); var extension = this.getFieldValue("extension"); var newFileName = filename.concat(".", extension); - var branch = Blockly.Arduino.statementToCode(block, "SD"); + var branch = Blockly.Generator.Arduino.statementToCode(block, "SD"); var code = ` ${filename} = SD.open("/${newFileName}", FILE_APPEND);\n`; code += branch; code += ` ${filename}.close();\n`; return code; }; -Blockly.Arduino.sensebox_esp32s2_sd_write_file = function (block) { - if (this.parentBlock_ != null) { - var filename = this.getSurroundParent().getFieldValue("Filename"); - } +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_sd_write_file"] = + function (block, generator) { + if (this.parentBlock_ != null) { + var filename = this.getSurroundParent().getFieldValue("Filename"); + } - var branch = - Blockly.Arduino.valueToCode(this, "DATA", Blockly.Arduino.ORDER_ATOMIC) || - '"Keine Eingabe"'; + var branch = + Blockly.Generator.Arduino.valueToCode( + this, + "DATA", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ) || '"Keine Eingabe"'; - var linebreak = this.getFieldValue("linebreak"); - if (linebreak === "TRUE") { - linebreak = "ln"; - } else { - linebreak = ""; - } + var linebreak = this.getFieldValue("linebreak"); + if (linebreak === "TRUE") { + linebreak = "ln"; + } else { + linebreak = ""; + } - var code = `${filename}.print${linebreak}(${branch});\n`; - return code; -}; + var code = `${filename}.print${linebreak}(${branch});\n`; + return code; + }; diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 9844bbda..0bfa247a 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -6,16 +6,17 @@ import { selectedBoard } from "../helpers/board"; * */ -Blockly.Arduino.sensebox_sensor_temp_hum = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_temp_hum"] = function () { var dropdown_name = this.getFieldValue("NAME"); - Blockly.Arduino.libraries_["library_adafruithdc1000"] = + Blockly.Generator.Arduino.libraries_["library_adafruithdc1000"] = "#include // http://librarymanager/All#Adafruit_HDC1000_Library"; - Blockly.Arduino.definitions_["define_hdc"] = + Blockly.Generator.Arduino.definitions_["define_hdc"] = "Adafruit_HDC1000 hdc = Adafruit_HDC1000();"; - Blockly.Arduino.setupCode_["sensebox_sensor_temp_hum"] = "hdc.begin();"; + Blockly.Generator.Arduino.setupCode_["sensebox_sensor_temp_hum"] = + "hdc.begin();"; var code = `hdc.read${dropdown_name}()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -23,19 +24,22 @@ Blockly.Arduino.sensebox_sensor_temp_hum = function () { * */ -Blockly.Arduino.sensebox_sensor_uv_light = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_uv_light"] = function () { var dropdown_name = this.getFieldValue("NAME"); let code = ""; if (dropdown_name === "UvIntensity") { - Blockly.Arduino.libraries_["library_veml6070"] = "#include "; - Blockly.Arduino.definitions_["define_veml"] = "VEML6070 veml;"; - Blockly.Arduino.setupCode_["sensebox_sensor_uv_light"] = "veml.begin();"; + Blockly.Generator.Arduino.libraries_["library_veml6070"] = + "#include "; + Blockly.Generator.Arduino.definitions_["define_veml"] = "VEML6070 veml;"; + Blockly.Generator.Arduino.setupCode_["sensebox_sensor_uv_light"] = + "veml.begin();"; code = "veml.getUV()"; } if (dropdown_name === "Illuminance") { - Blockly.Arduino.libraries_["library_ltr329"] = `#include `; - Blockly.Arduino.libraries_["library_wire"] = "#include "; - Blockly.Arduino.codeFunctions_["read_reg"] = ` + Blockly.Generator.Arduino.libraries_["library_ltr329"] = + `#include `; + Blockly.Generator.Arduino.libraries_["library_wire"] = "#include "; + Blockly.Generator.Arduino.codeFunctions_["read_reg"] = ` int read_reg(byte address, uint8_t reg) { int i = 0; @@ -49,7 +53,7 @@ int read_reg(byte address, uint8_t reg) return i; } `; - Blockly.Arduino.codeFunctions_["write_reg"] = ` + Blockly.Generator.Arduino.codeFunctions_["write_reg"] = ` void write_reg(byte address, uint8_t reg, uint8_t val) { Wire.beginTransmission(address); @@ -58,7 +62,7 @@ void write_reg(byte address, uint8_t reg, uint8_t val) Wire.endTransmission(); }`; - Blockly.Arduino.codeFunctions_["Lightsensor_begin"] = ` + Blockly.Generator.Arduino.codeFunctions_["Lightsensor_begin"] = ` void Lightsensor_begin() { Wire.begin(); @@ -83,7 +87,7 @@ void Lightsensor_begin() } `; - Blockly.Arduino.codeFunctions_["Lightsensor_getIlluminance"] = ` + Blockly.Generator.Arduino.codeFunctions_["Lightsensor_getIlluminance"] = ` uint32_t Lightsensor_getIlluminance() { unsigned int lux = 0; @@ -111,7 +115,7 @@ void Lightsensor_begin() return lux; } `; - Blockly.Arduino.definitions_["define_lightsensor"] = ` + Blockly.Generator.Arduino.definitions_["define_lightsensor"] = ` bool lightsensortype = 0; //0 for tsl - 1 for ltr //settings for LTR sensor LTR329 LTR; @@ -119,12 +123,12 @@ unsigned char gain = 1; unsigned char integrationTime = 0; unsigned char measurementRate = 3; `; - Blockly.Arduino.setupCode_["sensebox_sensor_illuminance"] = + Blockly.Generator.Arduino.setupCode_["sensebox_sensor_illuminance"] = "Lightsensor_begin();"; code = "Lightsensor_getIlluminance()"; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -132,30 +136,32 @@ unsigned char measurementRate = 3; * */ -Blockly.Arduino.sensebox_sensor_bmx055_accelerometer = function () { - var dropdown_value = this.getFieldValue("VALUE"); - var range = this.getFieldValue("RANGE"); - Blockly.Arduino.libraries_["library_bmx055"] = `#include `; - Blockly.Arduino.definitions_["define_bmx"] = "BMX055 bmx;"; - Blockly.Arduino.setupCode_["sensebox_sensor_bmx055"] = - "bmx.beginAcc(" + range + ");"; - var code = "bmx.getAcceleration" + dropdown_value + "()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; +Blockly.Generator.Arduino.forBlock["sensebox_sensor_bmx055_accelerometer"] = + function () { + var dropdown_value = this.getFieldValue("VALUE"); + var range = this.getFieldValue("RANGE"); + Blockly.Generator.Arduino.libraries_["library_bmx055"] = + `#include `; + Blockly.Generator.Arduino.definitions_["define_bmx"] = "BMX055 bmx;"; + Blockly.Generator.Arduino.setupCode_["sensebox_sensor_bmx055"] = + "bmx.beginAcc(" + range + ");"; + var code = "bmx.getAcceleration" + dropdown_value + "()"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; /** * SDS011 Fine Particlar Matter * */ -Blockly.Arduino.sensebox_sensor_sds011 = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_sds011"] = function () { var dropdown_name = this.getFieldValue("NAME"); var serial_name = this.getFieldValue("SERIAL"); - Blockly.Arduino.libraries_["SdsDustSensor"] = + Blockly.Generator.Arduino.libraries_["SdsDustSensor"] = `#include // http://librarymanager/All#Nova_Fitness_Sds_dust_sensors_library`; - Blockly.Arduino.definitions_["define_sds011"] = + Blockly.Generator.Arduino.definitions_["define_sds011"] = "SdsDustSensor sds(" + serial_name + ");"; - Blockly.Arduino.functionNames_["sds011_getPmData()"] = ` + Blockly.Generator.Arduino.functionNames_["sds011_getPmData()"] = ` float getPmData(int type) { PmResult pm = sds.queryPm(); if (pm.isOk()) { @@ -168,14 +174,14 @@ float getPmData(int type) { } } `; - Blockly.Arduino.setupCode_["sds011_begin"] = "sds.begin();"; - Blockly.Arduino.setupCode_["sds011_setQueryReportingMode"] = + Blockly.Generator.Arduino.setupCode_["sds011_begin"] = "sds.begin();"; + Blockly.Generator.Arduino.setupCode_["sds011_setQueryReportingMode"] = "sds.setQueryReportingMode();"; - // Blockly.Arduino.loopCodeOnce_[ + // Blockly.Generator.Arduino.loopCodeOnce_[ // "sds011_getData" // ] = `PmResult pm = sds.queryPm();`; var code = `getPmData(${dropdown_name})`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -183,15 +189,17 @@ float getPmData(int type) { * */ -Blockly.Arduino.sensebox_sensor_pressure = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_pressure"] = function () { var dropdown_name = this.getFieldValue("NAME"); var code = ""; var referencePressure = this.getFieldValue("referencePressure"); - Blockly.Arduino.libraries_["adafruit_bmp280"] = + Blockly.Generator.Arduino.libraries_["adafruit_bmp280"] = `#include // http://librarymanager/All#Adafruit_BMP280_Library`; - Blockly.Arduino.definitions_["define_pressure"] = "Adafruit_BMP280 bmp;"; - Blockly.Arduino.setupCode_["sensebox_bmp_sensor"] = "bmp.begin(0x76);"; - Blockly.Arduino.setupCode_["bmp_setSampling"] = ` + Blockly.Generator.Arduino.definitions_["define_pressure"] = + "Adafruit_BMP280 bmp;"; + Blockly.Generator.Arduino.setupCode_["sensebox_bmp_sensor"] = + "bmp.begin(0x76);"; + Blockly.Generator.Arduino.setupCode_["bmp_setSampling"] = ` bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, Adafruit_BMP280::SAMPLING_X2, Adafruit_BMP280::SAMPLING_X16, @@ -211,7 +219,7 @@ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, default: code = ""; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -219,22 +227,26 @@ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, * */ -Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { - var dropdown_name = this.getFieldValue("dropdown"); - let code = ""; - Blockly.Arduino.libraries_["library_bsec"] = - "#include // http://librarymanager/All#BSEC_Software_Library"; - Blockly.Arduino.definitions_["bsec_iaqSensor"] = "Bsec iaqSensor;"; - Blockly.Arduino.variables_["bmeTemperatur"] = "float bmeTemperatur;"; - Blockly.Arduino.variables_["bmeHumidity"] = "float bmeHumidity;"; - Blockly.Arduino.variables_["bmePressure"] = "double bmePressure;"; - Blockly.Arduino.variables_["bmeIAQ"] = "float bmeIAQ;"; - Blockly.Arduino.variables_["bmeIAQAccuracy"] = "float bmeIAQAccuracy;"; - Blockly.Arduino.variables_["bmeCO2"] = "int bmeCO2;"; - Blockly.Arduino.variables_["bmeBreathVocEquivalent"] = - "float bmeBreathVocEquivalent;"; - - Blockly.Arduino.functionNames_["checkIaqSensorStatus"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_sensor_bme680_bsec"] = + function () { + var dropdown_name = this.getFieldValue("dropdown"); + let code = ""; + Blockly.Generator.Arduino.libraries_["library_bsec"] = + "#include // http://librarymanager/All#BSEC_Software_Library"; + Blockly.Generator.Arduino.definitions_["bsec_iaqSensor"] = + "Bsec iaqSensor;"; + Blockly.Generator.Arduino.variables_["bmeTemperatur"] = + "float bmeTemperatur;"; + Blockly.Generator.Arduino.variables_["bmeHumidity"] = "float bmeHumidity;"; + Blockly.Generator.Arduino.variables_["bmePressure"] = "double bmePressure;"; + Blockly.Generator.Arduino.variables_["bmeIAQ"] = "float bmeIAQ;"; + Blockly.Generator.Arduino.variables_["bmeIAQAccuracy"] = + "float bmeIAQAccuracy;"; + Blockly.Generator.Arduino.variables_["bmeCO2"] = "int bmeCO2;"; + Blockly.Generator.Arduino.variables_["bmeBreathVocEquivalent"] = + "float bmeBreathVocEquivalent;"; + + Blockly.Generator.Arduino.functionNames_["checkIaqSensorStatus"] = ` void checkIaqSensorStatus(void) { if (iaqSensor.bsecStatus != BSEC_OK) { @@ -252,7 +264,7 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { } } `; - Blockly.Arduino.functionNames_["errLeds"] = ` + Blockly.Generator.Arduino.functionNames_["errLeds"] = ` void errLeds(void) { pinMode(LED_BUILTIN, OUTPUT); @@ -261,13 +273,13 @@ Blockly.Arduino.sensebox_sensor_bme680_bsec = function () { digitalWrite(LED_BUILTIN, LOW); delay(100); }`; - //Setup Code - Blockly.Arduino.setupCode_["Wire.begin"] = "Wire.begin();"; - Blockly.Arduino.setupCode_["iaqSensor.begin"] = - "iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);"; - Blockly.Arduino.setupCode_["checkIaqSensorStatus"] = - "checkIaqSensorStatus();"; - Blockly.Arduino.setupCode_["bsec_sensorlist"] = ` + //Setup Code + Blockly.Generator.Arduino.setupCode_["Wire.begin"] = "Wire.begin();"; + Blockly.Generator.Arduino.setupCode_["iaqSensor.begin"] = + "iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire);"; + Blockly.Generator.Arduino.setupCode_["checkIaqSensorStatus"] = + "checkIaqSensorStatus();"; + Blockly.Generator.Arduino.setupCode_["bsec_sensorlist"] = ` bsec_virtual_sensor_t sensorList[13] = { BSEC_OUTPUT_IAQ, BSEC_OUTPUT_STATIC_IAQ, @@ -285,10 +297,10 @@ bsec_virtual_sensor_t sensorList[13] = { }; `; - Blockly.Arduino.setupCode_["iaqSensorUpdateSubscription"] = - "iaqSensor.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);\ncheckIaqSensorStatus();"; - //Loop Code - Blockly.Arduino.loopCodeOnce_["iaqloop"] = ` + Blockly.Generator.Arduino.setupCode_["iaqSensorUpdateSubscription"] = + "iaqSensor.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);\ncheckIaqSensorStatus();"; + //Loop Code + Blockly.Generator.Arduino.loopCodeOnce_["iaqloop"] = ` if (iaqSensor.run()) { bmeTemperatur = iaqSensor.temperature; bmeHumidity = iaqSensor.humidity; @@ -301,73 +313,74 @@ bsec_virtual_sensor_t sensorList[13] = { checkIaqSensorStatus(); } `; - switch (dropdown_name) { - case "temperature": - code = "bmeTemperatur"; - break; - case "humidity": - code = "bmeHumidity"; - break; - case "pressure": - code = "bmePressure"; - break; - case "IAQ": - code = "bmeIAQ"; - break; - case "IAQAccuracy": - code = "bmeIAQAccuracy"; - break; - case "CO2": - code = "bmeCO2"; - break; - case "breathVocEquivalent": - code = "bmeBreathVocEquivalent"; - break; - default: - break; - } - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; + switch (dropdown_name) { + case "temperature": + code = "bmeTemperatur"; + break; + case "humidity": + code = "bmeHumidity"; + break; + case "pressure": + code = "bmePressure"; + break; + case "IAQ": + code = "bmeIAQ"; + break; + case "IAQAccuracy": + code = "bmeIAQAccuracy"; + break; + case "CO2": + code = "bmeCO2"; + break; + case "breathVocEquivalent": + code = "bmeBreathVocEquivalent"; + break; + default: + break; + } + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; /** * Ultrasonic Distance Sensor * */ -Blockly.Arduino.sensebox_sensor_ultrasonic_ranger = function () { - var dropdown_pin_RX = this.getFieldValue("ultrasonic_trigger"); - var dropdown_pin_TX = this.getFieldValue("ultrasonic_echo"); - var port = this.getFieldValue("port"); - var maxDistance = this.getFieldValue("maxDistance"); - Blockly.Arduino.libraries_["library_newPing"] = - `#include // http://librarymanager/All#NewPing`; - Blockly.Arduino.variables_["define_newPingVariables" + port] = ` +Blockly.Generator.Arduino.forBlock["sensebox_sensor_ultrasonic_ranger"] = + function () { + var dropdown_pin_RX = this.getFieldValue("ultrasonic_trigger"); + var dropdown_pin_TX = this.getFieldValue("ultrasonic_echo"); + var port = this.getFieldValue("port"); + var maxDistance = this.getFieldValue("maxDistance"); + Blockly.Generator.Arduino.libraries_["library_newPing"] = + `#include // http://librarymanager/All#NewPing`; + Blockly.Generator.Arduino.variables_["define_newPingVariables" + port] = ` #define TRIGGER_PIN_${port} ${dropdown_pin_RX} #define ECHO_PIN_${port} ${dropdown_pin_TX} #define MAX_DISTANCE_${port} ${maxDistance} `; - Blockly.Arduino.definitions_["define_newPing" + port] = - `NewPing sonar${port}(TRIGGER_PIN_${port}, ECHO_PIN_${port}, MAX_DISTANCE_${port});`; - var code; - code = `sonar${port}.ping_cm()`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; + Blockly.Generator.Arduino.definitions_["define_newPing" + port] = + `NewPing sonar${port}(TRIGGER_PIN_${port}, ECHO_PIN_${port}, MAX_DISTANCE_${port});`; + var code; + code = `sonar${port}.ping_cm()`; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; /** * * ToF Imager */ -Blockly.Arduino.sensebox_tof_imager = function () { +Blockly.Generator.Arduino.forBlock["sensebox_tof_imager"] = function () { var dropdown_name = this.getFieldValue("dropdown"); var maxDistance = this.getFieldValue("maxDistance"); - Blockly.Arduino.libraries_["library_wire"] = "#include "; - Blockly.Arduino.libraries_[`library_vl53l8cx`] = + Blockly.Generator.Arduino.libraries_["library_wire"] = "#include "; + Blockly.Generator.Arduino.libraries_[`library_vl53l8cx`] = `#include `; - Blockly.Arduino.variables_["define:_vl53l8cx"] = ` + Blockly.Generator.Arduino.variables_["define:_vl53l8cx"] = ` VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); `; - Blockly.Arduino.setupCode_["setup_vl53l8cx"] = ` + Blockly.Generator.Arduino.setupCode_["setup_vl53l8cx"] = ` Wire.begin(); Wire.setClock(1000000); //Sensor has max I2C freq of 1MHz sensor_vl53l8cx.begin(); @@ -379,7 +392,7 @@ VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); var code = ""; switch (dropdown_name) { case "DistanzCM": - Blockly.Arduino.codeFunctions_["define_tof_range"] = ` + Blockly.Generator.Arduino.codeFunctions_["define_tof_range"] = ` float oldVl53l8cxMin = -1.0; float getVl53l8cxMin() { VL53L8CX_ResultsData Results; @@ -406,7 +419,7 @@ VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); code += "getVl53l8cxMin()"; break; case "DistanzBM": - Blockly.Arduino.codeFunctions_["define_tof_bitmap"] = ` + Blockly.Generator.Arduino.codeFunctions_["define_tof_bitmap"] = ` uint16_t oldVl53l8cxBitmap[96] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -511,7 +524,7 @@ VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); default: break; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -519,9 +532,9 @@ VL53L8CX sensor_vl53l8cx(&Wire, -1, -1); * */ -Blockly.Arduino.sensebox_sensor_sound = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_sound"] = function () { var dropdown_pin = this.getFieldValue("PIN"); - Blockly.Arduino.codeFunctions_["define_sound"] = ` + Blockly.Generator.Arduino.codeFunctions_["define_sound"] = ` float getSoundValue(int pin) { unsigned long start = millis(); // Start des Messintervalls unsigned int peakToPeak = 0; // Abstand von maximalem zu minimalem Amplitudenausschlag @@ -551,7 +564,7 @@ float getSoundValue(int pin) { return volts; }`; var code = "getSoundValue(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -559,17 +572,17 @@ float getSoundValue(int pin) { * */ -Blockly.Arduino.sensebox_button = function () { +Blockly.Generator.Arduino.forBlock["sensebox_button"] = function () { var dropdown_pin = this.getFieldValue("PIN"); var dropown_function = this.getFieldValue("FUNCTION"); - Blockly.Arduino.libraries_["library_jcButtons"] = + Blockly.Generator.Arduino.libraries_["library_jcButtons"] = `#include // http://librarymanager/All#JC_Button`; - Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] = + Blockly.Generator.Arduino.definitions_["define_button" + dropdown_pin + ""] = "Button button_" + dropdown_pin + "(" + dropdown_pin + ");"; - Blockly.Arduino.setupCode_["setup_button" + dropdown_pin + ""] = + Blockly.Generator.Arduino.setupCode_["setup_button" + dropdown_pin + ""] = "button_" + dropdown_pin + ".begin();"; - Blockly.Arduino.loopCodeOnce_["loop_button" + dropdown_pin + ""] = + Blockly.Generator.Arduino.loopCodeOnce_["loop_button" + dropdown_pin + ""] = "button_" + dropdown_pin + ".read();"; var code = ""; if (dropown_function === "isPressed") { @@ -581,10 +594,11 @@ Blockly.Arduino.sensebox_button = function () { code = "button_" + dropdown_pin + ".pressedFor(" + time + ")"; } else if (dropown_function === "toggleButton") { code = "button_" + dropdown_pin + ".toggleState()"; - Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] = - "ToggleButton button_" + dropdown_pin + "(" + dropdown_pin + ");"; + Blockly.Generator.Arduino.definitions_[ + "define_button" + dropdown_pin + "" + ] = "ToggleButton button_" + dropdown_pin + "(" + dropdown_pin + ");"; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -592,18 +606,18 @@ Blockly.Arduino.sensebox_button = function () { * */ -Blockly.Arduino.sensebox_scd30 = function () { +Blockly.Generator.Arduino.forBlock["sensebox_scd30"] = function () { var dropdown = this.getFieldValue("dropdown"); - Blockly.Arduino.libraries_["scd30_library"] = + Blockly.Generator.Arduino.libraries_["scd30_library"] = "#include // http://librarymanager/All#SparkFun_SCD30_Arduino_Library"; - Blockly.Arduino.definitions_["SCD30"] = "SCD30 airSensor;"; - Blockly.Arduino.setupCode_["init_scd30"] = ` Wire.begin(); + Blockly.Generator.Arduino.definitions_["SCD30"] = "SCD30 airSensor;"; + Blockly.Generator.Arduino.setupCode_["init_scd30"] = ` Wire.begin(); if (airSensor.begin() == false) { while (1) ; }`; - Blockly.Arduino.setupCode_["scd30_staleData"] = + Blockly.Generator.Arduino.setupCode_["scd30_staleData"] = "airSensor.useStaleData(true);"; var code = ""; switch (dropdown) { @@ -619,7 +633,7 @@ if (airSensor.begin() == false) default: code = ""; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -627,13 +641,13 @@ if (airSensor.begin() == false) * */ -Blockly.Arduino.sensebox_gps = function () { +Blockly.Generator.Arduino.forBlock["sensebox_gps"] = function () { var dropdown = this.getFieldValue("dropdown"); - Blockly.Arduino.libraries_["gps_library"] = + Blockly.Generator.Arduino.libraries_["gps_library"] = "#include // http://librarymanager/All#SparkFun_u-blox_GNSS_Arduino_Library"; - Blockly.Arduino.libraries_["library_wire"] = "#include "; - Blockly.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;"; - Blockly.Arduino.setupCode_["init_gps"] = ` Wire.begin(); + Blockly.Generator.Arduino.libraries_["library_wire"] = "#include "; + Blockly.Generator.Arduino.definitions_["GPS"] = "SFE_UBLOX_GNSS myGNSS;"; + Blockly.Generator.Arduino.setupCode_["init_gps"] = ` Wire.begin(); if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port { @@ -661,10 +675,10 @@ Blockly.Arduino.sensebox_gps = function () { code = "myGNSS.getFixType()"; break; case "timestamp": - Blockly.Arduino.variables_["timestampVars"] = ` + Blockly.Generator.Arduino.variables_["timestampVars"] = ` char tsBuffer[21]; `; - Blockly.Arduino.codeFunctions_["getTimeStamp()"] = ` + Blockly.Generator.Arduino.codeFunctions_["getTimeStamp()"] = ` char* getTimeStamp() { if (myGNSS.getTimeValid() == true) @@ -683,19 +697,79 @@ return tsBuffer; default: code = ""; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** * Block for Truebner STM50 */ -Blockly.Arduino.sensebox_sensor_truebner_smt50 = function () { - var dropdown_port = this.getFieldValue("Port"); - var dropdown_value = this.getFieldValue("value"); - var dropdown_pin = 1; - var code = ""; - if (dropdown_value === "temp") { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_truebner_smt50"] = + function () { + var dropdown_port = this.getFieldValue("Port"); + var dropdown_value = this.getFieldValue("value"); + var dropdown_pin = 1; + var code = ""; + if (dropdown_value === "temp") { + switch (dropdown_port) { + case "IO3_2": + dropdown_pin = 3; + break; + case "IO3_4": + dropdown_pin = 3; + break; + case "IO5_4": + dropdown_pin = 5; + break; + case "IO5_6": + dropdown_pin = 5; + break; + case "IO7_6": + dropdown_pin = 7; + break; + default: // "IO1_2" + dropdown_pin = 1; + } + Blockly.Generator.Arduino.codeFunctions_["sensebox_smt50_temp"] = + "float getSMT50Temperature(int analogPin){\n int sensorValue = analogRead(analogPin);\n float voltage = sensorValue * (3.3 / 1024.0);\n return (voltage - 0.5) * 100;\n}"; + code = "getSMT50Temperature(" + dropdown_pin + ")"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + } else if (dropdown_value === "soil") { + switch (dropdown_port) { + case "IO3_2": + dropdown_pin = 2; + break; + case "IO3_4": + dropdown_pin = 4; + break; + case "IO5_4": + dropdown_pin = 4; + break; + case "IO5_6": + dropdown_pin = 6; + break; + case "IO7_6": + dropdown_pin = 6; + break; + default: // "IO1_2" + dropdown_pin = 2; + } + Blockly.Generator.Arduino.codeFunctions_["sensebox_smt50_soil"] = + "float getSMT50Moisture(int analogPin){\n int sensorValue = analogRead(analogPin);\n float voltage = sensorValue * (3.3 / 1024.0);\n return (voltage * 50) / 3;\n}"; + code = "getSMT50Moisture(" + dropdown_pin + ")"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + } + }; + +/** + * DS18B20 Watertemperature + * + */ + +Blockly.Generator.Arduino.forBlock["sensebox_sensor_watertemperature"] = + function () { + var dropdown_port = this.getFieldValue("Port"); + var dropdown_pin = 1; switch (dropdown_port) { case "IO3_2": dropdown_pin = 3; @@ -715,79 +789,22 @@ Blockly.Arduino.sensebox_sensor_truebner_smt50 = function () { default: // "IO1_2" dropdown_pin = 1; } - Blockly.Arduino.codeFunctions_["sensebox_smt50_temp"] = - "float getSMT50Temperature(int analogPin){\n int sensorValue = analogRead(analogPin);\n float voltage = sensorValue * (3.3 / 1024.0);\n return (voltage - 0.5) * 100;\n}"; - code = "getSMT50Temperature(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; - } else if (dropdown_value === "soil") { - switch (dropdown_port) { - case "IO3_2": - dropdown_pin = 2; - break; - case "IO3_4": - dropdown_pin = 4; - break; - case "IO5_4": - dropdown_pin = 4; - break; - case "IO5_6": - dropdown_pin = 6; - break; - case "IO7_6": - dropdown_pin = 6; - break; - default: // "IO1_2" - dropdown_pin = 2; - } - Blockly.Arduino.codeFunctions_["sensebox_smt50_soil"] = - "float getSMT50Moisture(int analogPin){\n int sensorValue = analogRead(analogPin);\n float voltage = sensorValue * (3.3 / 1024.0);\n return (voltage * 50) / 3;\n}"; - code = "getSMT50Moisture(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; - } -}; - -/** - * DS18B20 Watertemperature - * - */ - -Blockly.Arduino.sensebox_sensor_watertemperature = function () { - var dropdown_port = this.getFieldValue("Port"); - var dropdown_pin = 1; - switch (dropdown_port) { - case "IO3_2": - dropdown_pin = 3; - break; - case "IO3_4": - dropdown_pin = 3; - break; - case "IO5_4": - dropdown_pin = 5; - break; - case "IO5_6": - dropdown_pin = 5; - break; - case "IO7_6": - dropdown_pin = 7; - break; - default: // "IO1_2" - dropdown_pin = 1; - } - var dropdown_index = this.getFieldValue("Index"); - Blockly.Arduino.libraries_["library_oneWire"] = - "#include // http://librarymanager/All#OneWire"; - Blockly.Arduino.libraries_["library_oneDallasTemperature"] = - "#include // http://librarymanager/All#DallasTemperature"; - Blockly.Arduino.definitions_["define_OneWire"] = - "#define ONE_WIRE_BUS " + - dropdown_pin + - "\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&oneWire);"; - Blockly.Arduino.setupCode_["sensebox_oneWireSetup"] = "sensors.begin();"; - Blockly.Arduino.codeFunctions_["sensebox_requestTemp"] = - "float getWaterTemp(int index){\nsensors.requestTemperatures();\nreturn sensors.getTempCByIndex(index);\n}"; - var code = "getWaterTemp(" + dropdown_index + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; + var dropdown_index = this.getFieldValue("Index"); + Blockly.Generator.Arduino.libraries_["library_oneWire"] = + "#include // http://librarymanager/All#OneWire"; + Blockly.Generator.Arduino.libraries_["library_oneDallasTemperature"] = + "#include // http://librarymanager/All#DallasTemperature"; + Blockly.Generator.Arduino.definitions_["define_OneWire"] = + "#define ONE_WIRE_BUS " + + dropdown_pin + + "\nOneWire oneWire(ONE_WIRE_BUS);\nDallasTemperature sensors(&oneWire);"; + Blockly.Generator.Arduino.setupCode_["sensebox_oneWireSetup"] = + "sensors.begin();"; + Blockly.Generator.Arduino.codeFunctions_["sensebox_requestTemp"] = + "float getWaterTemp(int index){\nsensors.requestTemperatures();\nreturn sensors.getTempCByIndex(index);\n}"; + var code = "getWaterTemp(" + dropdown_index + ")"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; /** * Windspeed @@ -795,9 +812,9 @@ Blockly.Arduino.sensebox_sensor_watertemperature = function () { -Blockly.Arduino.sensebox_windspeed = function () { +Blockly.Generator.Arduino.forBlock["sensebox_windspeed"] = function() { var dropdown_pin = this.getFieldValue('PIN'); - Blockly.Arduino.codeFunctions_['windspeed'] = ` + Blockly.Generator.Arduino.codeFunctions_['windspeed'] = ` float getWindspeed(){ float voltageWind = analogRead(`+ dropdown_pin + `) * (3.3 / 1024.0); float windspeed = 0.0; @@ -814,7 +831,7 @@ float getWindspeed(){ return windspeed; }` var code = 'getWindspeed()'; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; */ @@ -827,32 +844,33 @@ float getWindspeed(){ * */ -Blockly.Arduino.sensebox_soundsensor_dfrobot = function () { - var dropdown_port = this.getFieldValue("Port"); - var dropdown_pin = 1; - switch (dropdown_port) { - case "IO3_2": - dropdown_pin = 3; - break; - case "IO3_4": - dropdown_pin = 3; - break; - case "IO5_4": - dropdown_pin = 5; - break; - case "IO5_6": - dropdown_pin = 5; - break; - case "IO7_6": - dropdown_pin = 7; - break; - default: // "IO1_2" - dropdown_pin = 1; - } +Blockly.Generator.Arduino.forBlock["sensebox_soundsensor_dfrobot"] = + function () { + var dropdown_port = this.getFieldValue("Port"); + var dropdown_pin = 1; + switch (dropdown_port) { + case "IO3_2": + dropdown_pin = 3; + break; + case "IO3_4": + dropdown_pin = 3; + break; + case "IO5_4": + dropdown_pin = 5; + break; + case "IO5_6": + dropdown_pin = 5; + break; + case "IO7_6": + dropdown_pin = 7; + break; + default: // "IO1_2" + dropdown_pin = 1; + } - var board = selectedBoard().title; - if (board === "MCU" || board === "Mini") { - Blockly.Arduino.codeFunctions_["soundsensor"] = ` + var board = selectedBoard().title; + if (board === "MCU" || board === "Mini") { + Blockly.Generator.Arduino.codeFunctions_["soundsensor"] = ` int getSoundValue(int sensorPin) { float v = analogRead(sensorPin) / 1000.0; float decibel; @@ -861,10 +879,10 @@ Blockly.Arduino.sensebox_soundsensor_dfrobot = function () { else decibel = v * 50.0; return int(decibel); }`; - } else { - Blockly.Arduino.setupCode_["soundsensorbegin"] = - `analogReadResolution(13);`; - Blockly.Arduino.codeFunctions_["soundsensor"] = ` + } else { + Blockly.Generator.Arduino.setupCode_["soundsensorbegin"] = + `analogReadResolution(13);`; + Blockly.Generator.Arduino.codeFunctions_["soundsensor"] = ` int getSoundValue(int sensorPin) { float v = analogReadMilliVolts(sensorPin) / 1000.0; float decibel; @@ -873,33 +891,33 @@ Blockly.Arduino.sensebox_soundsensor_dfrobot = function () { else decibel = v * 50.0; return int(decibel); }`; - } + } - var code = "getSoundValue(" + dropdown_pin + ")"; + var code = "getSoundValue(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; /** * Infineon DPS310 Pressure Sensor * */ -Blockly.Arduino.sensebox_sensor_dps310 = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_dps310"] = function () { var dropdown_name = this.getFieldValue("NAME"); var code = ""; var referencePressure = this.getFieldValue("referencePressure"); - Blockly.Arduino.libraries_["adafruit_dps310"] = + Blockly.Generator.Arduino.libraries_["adafruit_dps310"] = `#include // http://librarymanager/All#Adafruit_DPS310`; - Blockly.Arduino.definitions_["define_dps"] = "Adafruit_DPS310 dps;"; - Blockly.Arduino.setupCode_["dps_begin"] = "dps.begin_I2C(0x76);"; - Blockly.Arduino.setupCode_["dps_configuration"] = ` + Blockly.Generator.Arduino.definitions_["define_dps"] = "Adafruit_DPS310 dps;"; + Blockly.Generator.Arduino.setupCode_["dps_begin"] = "dps.begin_I2C(0x76);"; + Blockly.Generator.Arduino.setupCode_["dps_configuration"] = ` dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES); dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES); `; - Blockly.Arduino.loopCodeOnce_["dps_events"] = + Blockly.Generator.Arduino.loopCodeOnce_["dps_events"] = "sensors_event_t temp_event, pressure_event;"; - Blockly.Arduino.loopCodeOnce_["dps_getEvents"] = + Blockly.Generator.Arduino.loopCodeOnce_["dps_getEvents"] = "dps.getEvents(&temp_event, &pressure_event);"; switch (dropdown_name) { case "Temperature": @@ -914,7 +932,7 @@ Blockly.Arduino.sensebox_sensor_dps310 = function () { default: code = ""; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -922,21 +940,21 @@ Blockly.Arduino.sensebox_sensor_dps310 = function () { * */ -Blockly.Arduino.sensebox_sensor_sps30 = function () { +Blockly.Generator.Arduino.forBlock["sensebox_sensor_sps30"] = function () { var dropdown_name = this.getFieldValue("value"); - Blockly.Arduino.libraries_["sps30"] = + Blockly.Generator.Arduino.libraries_["sps30"] = `#include // http://librarymanager/All#`; - Blockly.Arduino.variables_["sps30_measurement"] = + Blockly.Generator.Arduino.variables_["sps30_measurement"] = "struct sps30_measurement m;"; - Blockly.Arduino.variables_["sps30_auto_clean_days"] = + Blockly.Generator.Arduino.variables_["sps30_auto_clean_days"] = "uint32_t auto_clean_days = 4;"; - Blockly.Arduino.variables_["sps30_interval_intervalsps"] = + Blockly.Generator.Arduino.variables_["sps30_interval_intervalsps"] = "const long intervalsps = 1000;"; - Blockly.Arduino.variables_["sps30_time_startsps"] = + Blockly.Generator.Arduino.variables_["sps30_time_startsps"] = "unsigned long time_startsps = 0;"; - Blockly.Arduino.variables_["sps30_time_actualsps"] = + Blockly.Generator.Arduino.variables_["sps30_time_actualsps"] = "unsigned long time_actualsps = 0;"; - Blockly.Arduino.codeFunctions_["sps30_getData"] = ` + Blockly.Generator.Arduino.codeFunctions_["sps30_getData"] = ` void getSPS30Data(){ uint16_t data_ready; @@ -954,19 +972,19 @@ do { } `; - Blockly.Arduino.setupCode_["sps30_begin"] = "sensirion_i2c_init();"; - Blockly.Arduino.setupCode_["sps30_setFanCleaningInterval"] = + Blockly.Generator.Arduino.setupCode_["sps30_begin"] = "sensirion_i2c_init();"; + Blockly.Generator.Arduino.setupCode_["sps30_setFanCleaningInterval"] = "sps30_set_fan_auto_cleaning_interval_days(auto_clean_days);"; - Blockly.Arduino.setupCode_["sps30_startMeasurement"] = + Blockly.Generator.Arduino.setupCode_["sps30_startMeasurement"] = "sps30_start_measurement();"; - Blockly.Arduino.loopCodeOnce_["getSPS30Data();"] = ` + Blockly.Generator.Arduino.loopCodeOnce_["getSPS30Data();"] = ` time_startsps = millis(); if (time_startsps > time_actualsps + intervalsps) { time_actualsps = millis(); getSPS30Data(); }`; var code = `m.mc_${dropdown_name}`; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -974,9 +992,9 @@ if (time_startsps > time_actualsps + intervalsps) { * */ -Blockly.Arduino.sensebox_esp32s2_light = function () { +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_light"] = function () { var code = "analogRead(PD_SENSE)"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -984,23 +1002,24 @@ Blockly.Arduino.sensebox_esp32s2_light = function () { * **/ -Blockly.Arduino.sensebox_esp32s2_mpu6050 = function () { +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_mpu6050"] = function () { var code = ""; var dropdown = this.getFieldValue("value"); - Blockly.Arduino.libraries_["esp32s2_mpu6050"] = + Blockly.Generator.Arduino.libraries_["esp32s2_mpu6050"] = `#include `; - Blockly.Arduino.libraries_["Adafruit_Sensor"] = + Blockly.Generator.Arduino.libraries_["Adafruit_Sensor"] = `#include `; - Blockly.Arduino.libraries_["library_wire"] = `#include `; - Blockly.Arduino.definitions_["define_Adafruit_mpu6050"] = + Blockly.Generator.Arduino.libraries_["library_wire"] = `#include `; + Blockly.Generator.Arduino.definitions_["define_Adafruit_mpu6050"] = "Adafruit_MPU6050 mpu;"; - Blockly.Arduino.definitions_["define_sensor_events"] = + Blockly.Generator.Arduino.definitions_["define_sensor_events"] = "sensors_event_t a, g, temp;"; - Blockly.Arduino.setupCode_["Wire1.begin()"] = "Wire1.begin();"; - Blockly.Arduino.setupCode_["mpu.begin()"] = "mpu.begin(0x68, &Wire1);"; - Blockly.Arduino.setupCode_["mpu.setAccelerometerRange()"] = + Blockly.Generator.Arduino.setupCode_["Wire1.begin()"] = "Wire1.begin();"; + Blockly.Generator.Arduino.setupCode_["mpu.begin()"] = + "mpu.begin(0x68, &Wire1);"; + Blockly.Generator.Arduino.setupCode_["mpu.setAccelerometerRange()"] = "mpu.setAccelerometerRange(MPU6050_RANGE_8_G);"; - Blockly.Arduino.loopCodeOnce_["mpu.getEvent"] = + Blockly.Generator.Arduino.loopCodeOnce_["mpu.getEvent"] = "mpu.getEvent(&a, &g, &temp);"; switch (dropdown) { case "accelerationX": @@ -1027,70 +1046,71 @@ Blockly.Arduino.sensebox_esp32s2_mpu6050 = function () { default: code = ""; } - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** * Block for Truebner STM50 on MCUS2 */ -Blockly.Arduino.sensebox_sensor_truebner_smt50_esp32 = function () { - var dropdown_port = this.getFieldValue("Port"); - var dropdown_value = this.getFieldValue("value"); - var dropdown_pin = 1; - var code = ""; - Blockly.Arduino.setupCode_["analogReadResolution"] = - "analogReadResolution(13);"; - - if (dropdown_value === "temp") { - switch (dropdown_port) { - case "IO3_2": - dropdown_pin = 3; - break; - case "IO3_4": - dropdown_pin = 3; - break; - case "IO5_4": - dropdown_pin = 5; - break; - case "IO5_6": - dropdown_pin = 5; - break; - case "IO7_6": - dropdown_pin = 7; - break; - default: // "IO1_2" - dropdown_pin = 1; - } - Blockly.Arduino.codeFunctions_["sensebox_smt50_temp_esp32"] = - "float getSMT50Temperature(int analogPin){\n float voltage = analogReadMilliVolts(analogPin)/1000.0;\n return (voltage - 0.5) * 100;\n }"; - code = "getSMT50Temperature(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; - } else if (dropdown_value === "soil") { - switch (dropdown_port) { - case "IO3_2": - dropdown_pin = 2; - break; - case "IO3_4": - dropdown_pin = 4; - break; - case "IO5_4": - dropdown_pin = 4; - break; - case "IO5_6": - dropdown_pin = 6; - break; - case "IO7_6": - dropdown_pin = 6; - break; - default: // "IO1_2" - dropdown_pin = 2; - } +Blockly.Generator.Arduino.forBlock["sensebox_sensor_truebner_smt50_esp32"] = + function () { + var dropdown_port = this.getFieldValue("Port"); + var dropdown_value = this.getFieldValue("value"); + var dropdown_pin = 1; + var code = ""; + Blockly.Generator.Arduino.setupCode_["analogReadResolution"] = + "analogReadResolution(13);"; + + if (dropdown_value === "temp") { + switch (dropdown_port) { + case "IO3_2": + dropdown_pin = 3; + break; + case "IO3_4": + dropdown_pin = 3; + break; + case "IO5_4": + dropdown_pin = 5; + break; + case "IO5_6": + dropdown_pin = 5; + break; + case "IO7_6": + dropdown_pin = 7; + break; + default: // "IO1_2" + dropdown_pin = 1; + } + Blockly.Generator.Arduino.codeFunctions_["sensebox_smt50_temp_esp32"] = + "float getSMT50Temperature(int analogPin){\n float voltage = analogReadMilliVolts(analogPin)/1000.0;\n return (voltage - 0.5) * 100;\n }"; + code = "getSMT50Temperature(" + dropdown_pin + ")"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + } else if (dropdown_value === "soil") { + switch (dropdown_port) { + case "IO3_2": + dropdown_pin = 2; + break; + case "IO3_4": + dropdown_pin = 4; + break; + case "IO5_4": + dropdown_pin = 4; + break; + case "IO5_6": + dropdown_pin = 6; + break; + case "IO7_6": + dropdown_pin = 6; + break; + default: // "IO1_2" + dropdown_pin = 2; + } - Blockly.Arduino.codeFunctions_["sensebox_smt50_soil_esp32"] = - "float getSMT50Moisture(int analogPin){\n float voltage = analogReadMilliVolts(analogPin)/1000.0;\n if (voltage >= 3) voltage = 3.0;\n return (voltage * 50.0) / 3.0;\n}"; + Blockly.Generator.Arduino.codeFunctions_["sensebox_smt50_soil_esp32"] = + "float getSMT50Moisture(int analogPin){\n float voltage = analogReadMilliVolts(analogPin)/1000.0;\n if (voltage >= 3) voltage = 3.0;\n return (voltage * 50.0) / 3.0;\n}"; - code = "getSMT50Moisture(" + dropdown_pin + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; - } -}; + code = "getSMT50Moisture(" + dropdown_pin + ")"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + } + }; diff --git a/src/components/Blockly/generator/sensebox-telegram.js b/src/components/Blockly/generator/sensebox-telegram.js index b04d8967..d5db805c 100644 --- a/src/components/Blockly/generator/sensebox-telegram.js +++ b/src/components/Blockly/generator/sensebox-telegram.js @@ -3,12 +3,16 @@ import * as Blockly from "blockly/core"; /** * Telegram Bot by re:edu */ -Blockly.Arduino.sensebox_telegram = function (Block) { +Blockly.Generator.Arduino.forBlock["sensebox_telegram"] = function ( + block, + generator, +) { let token = Block.getFieldValue("telegram_token"); - Blockly["Arduino"].libraries_["library_telegram"] = + Blockly.Generator.Arduino.libraries_["library_telegram"] = `#include `; - Blockly["Arduino"].functionNames_["WiFiSSLClient"] = "WiFiSSLClient client;"; - Blockly["Arduino"].functionNames_["telegram_objects"] = + Blockly.Generator.Arduino.functionNames_["WiFiSSLClient"] = + "WiFiSSLClient client;"; + Blockly.Generator.Arduino.functionNames_["telegram_objects"] = `#define BOTtoken "${token}" // your Bot Token (Get from Botfather) UniversalTelegramBot bot(BOTtoken, client);`; @@ -17,18 +21,21 @@ Blockly.Arduino.sensebox_telegram = function (Block) { return code; }; -Blockly.Arduino.sensebox_telegram_do = function (block) { - var messageProcessing = Blockly.Arduino.statementToCode( +Blockly.Generator.Arduino.forBlock["sensebox_telegram_do"] = function ( + block, + generator, +) { + var messageProcessing = Blockly.Generator.Arduino.statementToCode( block, "telegram_do", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); - Blockly.Arduino.definitions_["telegram_variables"] = + Blockly.Generator.Arduino.definitions_["telegram_variables"] = `int Bot_mtbs = 1000; //mean time between scan messages long Bot_lasttime; //last time messages' scan has been done`; - Blockly.Arduino.loopCodeOnce_["sensebox_telegram_loop"] = + Blockly.Generator.Arduino.loopCodeOnce_["sensebox_telegram_loop"] = `if (millis() > Bot_lasttime + Bot_mtbs) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1); while(numNewMessages) { @@ -46,26 +53,30 @@ Blockly.Arduino.sensebox_telegram_do = function (block) { return code; }; -Blockly.Arduino.sensebox_telegram_do_on_message = function (block) { - var message = this.getFieldValue("telegram_message"); - var stuffToDo = Blockly.Arduino.statementToCode( - block, - "telegram_do_on_message", - Blockly.Arduino.ORDER_ATOMIC, - ); - var code = ` +Blockly.Generator.Arduino.forBlock["sensebox_telegram_do_on_message"] = + function (block, generator) { + var message = this.getFieldValue("telegram_message"); + var stuffToDo = Blockly.Generator.Arduino.statementToCode( + block, + "telegram_do_on_message", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var code = ` if (text == "${message}") { ${stuffToDo} }`; - return code; -}; + return code; + }; -Blockly.Arduino.sensebox_telegram_send = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_telegram_send"] = function ( + block, + generator, +) { var textToSend = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "telegram_text_to_send", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || '"Keine Eingabe"'; var code = `bot.sendMessage(chat_id, String(${textToSend}), "");\n`; return code; diff --git a/src/components/Blockly/generator/sensebox-web.js b/src/components/Blockly/generator/sensebox-web.js index 90525c53..12177b85 100644 --- a/src/components/Blockly/generator/sensebox-web.js +++ b/src/components/Blockly/generator/sensebox-web.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; //import store from "../../../store"; // preperations for the esp board @@ -8,15 +8,19 @@ import Blockly from "blockly"; // }); /* Wifi connection and openSenseMap Blocks*/ -Blockly.Arduino.sensebox_wifi = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_wifi"] = function ( + block, + generator, +) { var pw = this.getFieldValue("Password"); var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_WiFi"] = "#include "; - Blockly.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; - Blockly.Arduino.variables_["pass"] = `char pass[] = "${pw}";`; - Blockly.Arduino.variables_["wifi_Status"] = "int status = WL_IDLE_STATUS;"; + Blockly.Generator.Arduino.libraries_["library_WiFi"] = "#include "; + Blockly.Generator.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; + Blockly.Generator.Arduino.variables_["pass"] = `char pass[] = "${pw}";`; + Blockly.Generator.Arduino.variables_["wifi_Status"] = + "int status = WL_IDLE_STATUS;"; if (pw === "") { - Blockly.Arduino.setupCode_["wifi_begin"] = ` + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = ` if (WiFi.status() == WL_NO_SHIELD) { while (true); } @@ -26,7 +30,7 @@ Blockly.Arduino.sensebox_wifi = function (block) { } `; } else - Blockly.Arduino.setupCode_["wifi_begin"] = ` + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = ` if (WiFi.status() == WL_NO_SHIELD) { while (true); } @@ -39,52 +43,57 @@ while (status != WL_CONNECTED) { return code; }; -Blockly.Arduino.sensebox_wifi_status = function () { +Blockly.Generator.Arduino.forBlock["sensebox_wifi_status"] = function () { var code = "WiFi.status()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_wifi_rssi = function () { +Blockly.Generator.Arduino.forBlock["sensebox_wifi_rssi"] = function () { var code = "WiFi.RSSI()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_get_ip = function () { - Blockly.Arduino.definitions_["define_ipadress"] = "IPAddress ip;"; - Blockly.Arduino.setupCode_["sensebox_get_ip"] = " ip = WiFi.localIP();"; +Blockly.Generator.Arduino.forBlock["sensebox_get_ip"] = function () { + Blockly.Generator.Arduino.definitions_["define_ipadress"] = "IPAddress ip;"; + Blockly.Generator.Arduino.setupCode_["sensebox_get_ip"] = + " ip = WiFi.localIP();"; var code = "ip"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_startap = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_startap"] = function ( + block, + generator, +) { var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_WiFi"] = "#include "; - Blockly.Arduino.setupCode_["wifi_startAP"] = `WiFi.beginAP("${ssid}");`; + Blockly.Generator.Arduino.libraries_["library_WiFi"] = "#include "; + Blockly.Generator.Arduino.setupCode_["wifi_startAP"] = + `WiFi.beginAP("${ssid}");`; var code = ""; return code; }; -Blockly.Arduino.sensebox_ethernet = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ethernet"] = function () { var ip = this.getFieldValue("ip"); var gateway = this.getFieldValue("gateway"); var subnetmask = this.getFieldValue("subnetmask"); var dns = this.getFieldValue("dns"); var mac = this.getFieldValue("mac"); var dhcp = this.getFieldValue("dhcp"); - Blockly.Arduino.libraries_["library_ethernet"] = + Blockly.Generator.Arduino.libraries_["library_ethernet"] = "#include // http://librarymanager/All#Ethernet"; - Blockly.Arduino.definitions_["ethernet_config"] = ` + Blockly.Generator.Arduino.definitions_["ethernet_config"] = ` byte mac[] = { ${mac}};`; if (dhcp === "Manual") { - Blockly.Arduino.definitions_["ethernet_manual_config"] = ` + Blockly.Generator.Arduino.definitions_["ethernet_manual_config"] = ` //Configure static IP setup (only needed if DHCP is disabled) IPAddress myIp(${ip.replaceAll(".", ", ")}); IPAddress myDns(${dns.replaceAll(".", ",")}); IPAddress myGateway(${gateway.replaceAll(".", ",")}); IPAddress mySubnet(${subnetmask.replaceAll(".", ",")}); `; - Blockly.Arduino.setupCode_["ethernet_setup"] = ` + Blockly.Generator.Arduino.setupCode_["ethernet_setup"] = ` Ethernet.init(23); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { @@ -96,7 +105,7 @@ if (Ethernet.begin(mac) == 0) { delay(1000); `; } else { - Blockly.Arduino.setupCode_["ethernet_setup"] = ` + Blockly.Generator.Arduino.setupCode_["ethernet_setup"] = ` Ethernet.init(23); // start the Ethernet connection: Ethernet.begin(mac); @@ -109,9 +118,9 @@ delay(1000); return code; }; -Blockly.Arduino.sensebox_ethernetIp = function () { +Blockly.Generator.Arduino.forBlock["sensebox_ethernetIp"] = function () { var code = "Ethernet.localIP()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -120,30 +129,33 @@ Blockly.Arduino.sensebox_ethernetIp = function () { * */ -Blockly.Arduino.sensebox_esp32s2_wifi_enterprise = function () { - /* WiFi connection for eduroam networks*/ - var pw = this.getFieldValue("Password"); - var user = this.getFieldValue("User"); - var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_WiFi"] = "#include "; - Blockly.Arduino.libraries_["library_wpa2"] = `#include "esp_wpa2.h"`; - Blockly.Arduino.definitions_["define_identity"] = - `#define EAP_IDENTITY "${user}"`; - Blockly.Arduino.definitions_["define_username"] = - `#define EAP_USERNAME "${user}"`; - Blockly.Arduino.definitions_["define_password"] = - `#define EAP_PASSWORD "${pw}"`; - Blockly.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; - Blockly.Arduino.variables_["pass"] = `char pass[] = "";`; - Blockly.Arduino.variables_["wifi_Status"] = "int status = WL_IDLE_STATUS;"; - Blockly.Arduino.codeFunctions_["initWifi"] = ` +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_wifi_enterprise"] = + function () { + /* WiFi connection for eduroam networks*/ + var pw = this.getFieldValue("Password"); + var user = this.getFieldValue("User"); + var ssid = this.getFieldValue("SSID"); + Blockly.Generator.Arduino.libraries_["library_WiFi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_wpa2"] = + `#include "esp_wpa2.h"`; + Blockly.Generator.Arduino.definitions_["define_identity"] = + `#define EAP_IDENTITY "${user}"`; + Blockly.Generator.Arduino.definitions_["define_username"] = + `#define EAP_USERNAME "${user}"`; + Blockly.Generator.Arduino.definitions_["define_password"] = + `#define EAP_PASSWORD "${pw}"`; + Blockly.Generator.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; + Blockly.Generator.Arduino.variables_["pass"] = `char pass[] = "";`; + Blockly.Generator.Arduino.variables_["wifi_Status"] = + "int status = WL_IDLE_STATUS;"; + Blockly.Generator.Arduino.codeFunctions_["initWifi"] = ` void initWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_IDENTITY, EAP_USERNAME, EAP_PASSWORD); } `; - if (pw === "") { - Blockly.Arduino.setupCode_["wifi_begin"] = ` + if (pw === "") { + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = ` if (WiFi.status() == WL_NO_SHIELD) { while (true); } @@ -152,18 +164,18 @@ Blockly.Arduino.sensebox_esp32s2_wifi_enterprise = function () { delay(5000); } `; - } else Blockly.Arduino.setupCode_["wifi_begin"] = `initWiFi();`; - var code = ""; - return code; -}; + } else Blockly.Generator.Arduino.setupCode_["wifi_begin"] = `initWiFi();`; + var code = ""; + return code; + }; -Blockly.Arduino.sensebox_esp32s2_wifi = function () { +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_wifi"] = function () { var pw = this.getFieldValue("Password"); var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_ESPWiFi"] = "#include "; - Blockly.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; - Blockly.Arduino.variables_["pass"] = `char pass[] = "${pw}";`; - Blockly.Arduino.setupCode_["wifi_begin"] = ` + Blockly.Generator.Arduino.libraries_["library_ESPWiFi"] = "#include "; + Blockly.Generator.Arduino.variables_["ssid"] = `char ssid[] = "${ssid}";`; + Blockly.Generator.Arduino.variables_["pass"] = `char pass[] = "${pw}";`; + Blockly.Generator.Arduino.setupCode_["wifi_begin"] = ` WiFi.begin(ssid, pass); if(WiFi.status() == WL_NO_SHIELD){ while(true); @@ -177,19 +189,23 @@ Blockly.Arduino.sensebox_esp32s2_wifi = function () { return code; }; -Blockly.Arduino.sensebox_esp32s2_startap = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_startap"] = function ( + block, + generator, +) { var ssid = this.getFieldValue("SSID"); - Blockly.Arduino.libraries_["library_ESPWiFi"] = "#include "; - Blockly.Arduino.libraries_["library_ESPWiFiClient"] = + Blockly.Generator.Arduino.libraries_["library_ESPWiFi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_ESPWiFiClient"] = "#include "; - Blockly.Arduino.libraries_["WiFiAP"] = "#include "; - Blockly.Arduino.variables_["ssid"] = `const char ssid[] = "${ssid}";`; - Blockly.Arduino.setupCode_["wifi_startAP"] = `WiFi.softAP(ssid);\n`; + Blockly.Generator.Arduino.libraries_["WiFiAP"] = "#include "; + Blockly.Generator.Arduino.variables_["ssid"] = + `const char ssid[] = "${ssid}";`; + Blockly.Generator.Arduino.setupCode_["wifi_startAP"] = `WiFi.softAP(ssid);\n`; var code = ""; return code; }; -// Blockly.Arduino.definitions_["certificate"] = ` +// Blockly.Generator.Arduino.definitions_["certificate"] = ` // const char* root_ca = \ // "-----BEGIN CERTIFICATE-----\n" \ // "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\n" \ diff --git a/src/components/Blockly/generator/sensebox.js b/src/components/Blockly/generator/sensebox.js index 6eb9849e..1cffb17f 100644 --- a/src/components/Blockly/generator/sensebox.js +++ b/src/components/Blockly/generator/sensebox.js @@ -3,35 +3,36 @@ import * as Blockly from "blockly/core"; /* * Multiplexer */ -Blockly.Arduino.sensebox_multiplexer_init = function () { - // Blockly.Arduino.libraries_['library_spi'] = '#include '; +Blockly.Generator.Arduino.forBlock["sensebox_multiplexer_init"] = function () { + // Blockly.Generator.Arduino.libraries_['library_spi'] = '#include '; var nrChannels = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( this, "nrChannels", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) | 0; var array = []; for (var i = 0; i < nrChannels; i++) { array.push(i); } - Blockly.Arduino.libraries_["library_wire"] = "#include "; - Blockly.Arduino.definitions_["define_multiplexer"] = + Blockly.Generator.Arduino.libraries_["library_wire"] = "#include "; + Blockly.Generator.Arduino.definitions_["define_multiplexer"] = `byte multiplexAddress = 0x77; byte channels[] = {${array}};`; - // Blockly.Arduino.setupCode_['sensebox_display_begin'] = 'senseBoxIO.powerI2C(true);\ndelay(2000);\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();'; + // Blockly.Generator.Arduino.setupCode_['sensebox_display_begin'] = 'senseBoxIO.powerI2C(true);\ndelay(2000);\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3D);\ndisplay.display();\ndelay(100);\ndisplay.clearDisplay();'; var code = ""; return code; }; -Blockly.Arduino.sensebox_multiplexer_changeChannel = function () { - var channel = Blockly.Arduino.valueToCode( - this, - "Channel", - Blockly.Arduino.ORDER_ATOMIC, - ); - var code = `Wire.beginTransmission(0x77); +Blockly.Generator.Arduino.forBlock["sensebox_multiplexer_changeChannel"] = + function () { + var channel = Blockly.Generator.Arduino.valueToCode( + this, + "Channel", + Blockly.Generator.Arduino.ORDER_ATOMIC, + ); + var code = `Wire.beginTransmission(0x77); Wire.write(1 << channels[${channel - 1}]); Wire.endTransmission();`; - return code; -}; + return code; + }; diff --git a/src/components/Blockly/generator/serial.js b/src/components/Blockly/generator/serial.js index 12e03ced..73ff9d62 100644 --- a/src/components/Blockly/generator/serial.js +++ b/src/components/Blockly/generator/serial.js @@ -1,12 +1,15 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino["print_serial_monitor"] = function (block) { +Blockly.Generator.Arduino.forBlock["print_serial_monitor"] = function ( + block, + generator, +) { var serialId = block.getFieldValue("SERIAL_ID"); var content = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "CONTENT", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var checkbox_name = block.getFieldValue("NEW_LINE") === "TRUE"; var code = ""; @@ -24,10 +27,13 @@ Blockly.Arduino["print_serial_monitor"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code. */ -Blockly.Arduino["init_serial_monitor"] = function (block) { +Blockly.Generator.Arduino.forBlock["init_serial_monitor"] = function ( + block, + generator, +) { var serialId = block.getFieldValue("SERIAL_ID"); var serialSpeed = block.getFieldValue("SPEED"); - Blockly.Arduino.setupCode_["init_serial"] = + Blockly.Generator.Arduino.setupCode_["init_serial"] = `${serialId}.begin(${serialSpeed});`; var code = ""; return code; diff --git a/src/components/Blockly/generator/text.js b/src/components/Blockly/generator/text.js index d4a59ad3..6a66a935 100644 --- a/src/components/Blockly/generator/text.js +++ b/src/components/Blockly/generator/text.js @@ -6,9 +6,9 @@ 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["text"] = function (block) { - var code = Blockly.Arduino.quote_(block.getFieldValue("TEXT")); - return [code, Blockly.Arduino.ORDER_ATOMIC]; +Blockly.Generator.Arduino.forBlock["text"] = function (block, generator) { + var code = Blockly.Generator.Arduino.quote_(block.getFieldValue("TEXT")); + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -20,27 +20,27 @@ Blockly.Arduino["text"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["text_join"] = function (block) { +Blockly.Generator.Arduino.forBlock["text_join"] = function (block, generator) { var code; if (block.itemCount_ === 0) { - return ['""', Blockly.Arduino.ORDER_ATOMIC]; + return ['""', Blockly.Generator.Arduino.ORDER_ATOMIC]; } else if (block.itemCount_ === 1) { var argument0 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "ADD0", - Blockly.Arduino.ORDER_UNARY_POSTFIX, + Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, ) || '""'; code = "String(" + argument0 + ")"; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } else { var argument; code = []; for (var n = 0; n < block.itemCount_; n++) { - argument = Blockly.Arduino.valueToCode( + argument = Blockly.Generator.Arduino.valueToCode( block, "ADD" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ); if (argument === "") { code[n] = '""'; @@ -49,7 +49,7 @@ Blockly.Arduino["text_join"] = function (block) { } } code = code.join(" + "); - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } }; @@ -60,17 +60,20 @@ Blockly.Arduino["text_join"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["text_append"] = function (block) { +Blockly.Generator.Arduino.forBlock["text_append"] = function ( + block, + generator, +) { // Append to a variable in place. var id = block.getFieldValue("VAR"); const variable = Blockly.Variables.getVariable( Blockly.getMainWorkspace(), id, ); - var argument0 = Blockly.Arduino.valueToCode( + var argument0 = Blockly.Generator.Arduino.valueToCode( block, "TEXT", - Blockly.Arduino.ORDER_UNARY_POSTFIX, + Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, ); if (argument0 === "") { argument0 = '""'; @@ -87,13 +90,16 @@ Blockly.Arduino["text_append"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["text_length"] = function (block) { +Blockly.Generator.Arduino.forBlock["text_length"] = function ( + block, + generator, +) { var argument0 = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "VALUE", - Blockly.Arduino.ORDER_UNARY_POSTFIX, + Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, ) || '""'; var code = "String(" + argument0 + ").length()"; - return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; }; diff --git a/src/components/Blockly/generator/time.js b/src/components/Blockly/generator/time.js index fb89c6d3..af2869d8 100644 --- a/src/components/Blockly/generator/time.js +++ b/src/components/Blockly/generator/time.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; /** * @license Licensed under the Apache License, Version 2.0 (the "License"): @@ -16,12 +16,12 @@ import Blockly from "blockly"; * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["time_delay"] = function (block) { +Blockly.Generator.Arduino.forBlock["time_delay"] = function (block, generator) { var delayTime = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DELAY_TIME_MILI", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var code = "delay(" + delayTime + ");\n"; return code; @@ -33,12 +33,15 @@ Blockly.Arduino["time_delay"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["time_delaymicros"] = function (block) { +Blockly.Generator.Arduino.forBlock["time_delaymicros"] = function ( + block, + generator, +) { var delayTimeMs = - Blockly.Arduino.valueToCode( + Blockly.Generator.Arduino.valueToCode( block, "DELAY_TIME_MICRO", - Blockly.Arduino.ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ) || "0"; var code = "delayMicroseconds(" + delayTimeMs + ");\n"; return code; @@ -50,9 +53,12 @@ Blockly.Arduino["time_delaymicros"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["time_millis"] = function (block) { +Blockly.Generator.Arduino.forBlock["time_millis"] = function ( + block, + generator, +) { var code = "millis()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -61,9 +67,12 @@ Blockly.Arduino["time_millis"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Arduino["time_micros"] = function (block) { +Blockly.Generator.Arduino.forBlock["time_micros"] = function ( + block, + generator, +) { var code = "micros()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; /** @@ -72,17 +81,21 @@ Blockly.Arduino["time_micros"] = function (block) { * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Arduino["infinite_loop"] = function (block) { +Blockly.Generator.Arduino.forBlock["infinite_loop"] = function ( + block, + generator, +) { return "while(true);\n"; }; -// Blockly.Arduino.sensebox_interval_timer = function (block) { +// Blockly.Generator.Arduino.forBlock["sensebox_interval_timer"] = function(block, generator) { + // var interval = this.getFieldValue("interval"); -// Blockly.Arduino.variables_["define_interval_variables"] = +// Blockly.Generator.Arduino.variables_["define_interval_variables"] = // "const long interval = " + // interval + // ";\nlong time_start = 0;\nlong time_actual = 0;"; -// var branch = Blockly.Arduino.statementToCode(block, "DO"); +// var branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); // var code = "time_start = millis();\n"; // code += // "if (time_start > time_actual + interval) {\n time_actual = millis();\n"; @@ -91,16 +104,21 @@ Blockly.Arduino["infinite_loop"] = function (block) { // return code; // }; -Blockly.Arduino.sensebox_interval_timer = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_interval_timer"] = function ( + block, + generator, +) { var intervalTime = this.getFieldValue("interval"); var intervalName = this.getFieldValue("name"); - Blockly.Arduino.variables_[`define_interval_variables${intervalName}`] = ` + Blockly.Generator.Arduino.variables_[ + `define_interval_variables${intervalName}` + ] = ` const long interval${intervalName} = ${intervalTime}; long time_start${intervalName} = 0; long time_actual${intervalName} = 0;`; - Blockly.Arduino.loopCodeOnce_[`interval_loop${intervalName}`] = + Blockly.Generator.Arduino.loopCodeOnce_[`interval_loop${intervalName}`] = `time_start${intervalName} = millis();\n`; - var branch = Blockly.Arduino.statementToCode(block, "DO"); + var branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); var code = ` if (time_start${intervalName} > time_actual${intervalName} + interval${intervalName}) {\n time_actual${intervalName} = millis();\n`; code += branch; diff --git a/src/components/Blockly/generator/variables.js b/src/components/Blockly/generator/variables.js index a8dfaf27..3dcc3235 100644 --- a/src/components/Blockly/generator/variables.js +++ b/src/components/Blockly/generator/variables.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; const setVariableFunction = function (defaultValue) { return function (block) { @@ -9,14 +9,14 @@ const setVariableFunction = function (defaultValue) { id, ).name; - // const variableName = Blockly["Arduino"].nameDB_.getName( + // const variableName = Blockly.Generator.Arduino.nameDB_.getName( // id, // Blockly.Variables.NAME_TYPE // ); - const variableValue = Blockly["Arduino"].valueToCode( + const variableValue = Blockly.Generator.Arduino.valueToCode( block, "VALUE", - Blockly["Arduino"].ORDER_ATOMIC, + Blockly.Generator.Arduino.ORDER_ATOMIC, ); const allVars = Blockly.getMainWorkspace() @@ -25,9 +25,16 @@ const setVariableFunction = function (defaultValue) { const myVar = allVars.filter((v) => v.name === variableName)[0]; var code = ""; if (myVar !== undefined) { - Blockly.Arduino.variables_[variableName + myVar.type] = - myVar.type + " " + myVar.name.replace(/_/g, '__').replace(/[^a-zA-Z0-9_]/g, '_') + ";\n"; - code = myVar.name.replace(/_/g, '__').replace(/[^a-zA-Z0-9_]/g, '_') + " = " + (variableValue || defaultValue) + ";\n"; + Blockly.Generator.Arduino.variables_[variableName + myVar.type] = + myVar.type + + " " + + myVar.name.replace(/_/g, "__").replace(/[^a-zA-Z0-9_]/g, "_") + + ";\n"; + code = + myVar.name.replace(/_/g, "__").replace(/[^a-zA-Z0-9_]/g, "_") + + " = " + + (variableValue || defaultValue) + + ";\n"; } return code; }; @@ -43,13 +50,13 @@ const getVariableFunction = function (block) { const allVars = Blockly.getMainWorkspace().getVariableMap().getAllVariables(); const myVar = allVars.filter((v) => v.name === variableName)[0]; - // const variableName = Blockly["Arduino"].nameDB_.getName( + // const variableName = Blockly.Generator.Arduino.nameDB_.getName( // block.getFieldValue("VAR"), // Blockly.Variables.NAME_TYPE // ); - var code = myVar.name.replace(/_/g, '__').replace(/[^a-zA-Z0-9_]/g, '_'); - return [code, Blockly["Arduino"].ORDER_ATOMIC]; + var code = myVar.name.replace(/_/g, "__").replace(/[^a-zA-Z0-9_]/g, "_"); + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly["Arduino"]["variables_set_dynamic"] = setVariableFunction(); -Blockly["Arduino"]["variables_get_dynamic"] = getVariableFunction; +Blockly.Generator.Arduino["variables_set_dynamic"] = setVariableFunction(); +Blockly.Generator.Arduino["variables_get_dynamic"] = getVariableFunction; diff --git a/src/components/Blockly/generator/watchdog.js b/src/components/Blockly/generator/watchdog.js index eac3e659..65f68364 100644 --- a/src/components/Blockly/generator/watchdog.js +++ b/src/components/Blockly/generator/watchdog.js @@ -1,16 +1,17 @@ import * as Blockly from "blockly/core"; -Blockly.Arduino.watchdog_enable = function () { +Blockly.Generator.Arduino.forBlock["watchdog_enable"] = function () { var time = this.getFieldValue("TIME"); - Blockly.Arduino.libraries_["Adafruit_sleepydog"] = + Blockly.Generator.Arduino.libraries_["Adafruit_sleepydog"] = "#include // http://librarymanager/All#Adafruit_SleepyDog_Library"; - Blockly.Arduino.setupCode_["watchdog_enable"] = `Watchdog.enable(${time});`; + Blockly.Generator.Arduino.setupCode_["watchdog_enable"] = + `Watchdog.enable(${time});`; var code = ""; return code; }; -Blockly.Arduino.watchdog_reset = function () { +Blockly.Generator.Arduino.forBlock["watchdog_reset"] = function () { var code = "Watchdog.reset();"; return code; }; diff --git a/src/components/Blockly/generator/webserver.js b/src/components/Blockly/generator/webserver.js index 51d280ba..70bf669e 100644 --- a/src/components/Blockly/generator/webserver.js +++ b/src/components/Blockly/generator/webserver.js @@ -1,94 +1,133 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; /** * Webserver Blocks by Lucas Steinmann * */ -Blockly.Arduino.sensebox_initialize_http_server = function (block) { - var box_id = this.getFieldValue("Port"); - Blockly.Arduino.libraries_["library_http"] = "#include "; +Blockly.Generator.Arduino.forBlock["sensebox_initialize_http_server"] = + function (block, generator) { + var box_id = this.getFieldValue("Port"); + Blockly.Generator.Arduino.libraries_["library_http"] = + "#include "; - Blockly.Arduino.codeFunctions_["define_wifi_server"] = - "WiFiServer server(" + box_id + ");"; - Blockly.Arduino.setupCode_["sensebox_wifi_server_beging"] = "server.begin();"; - return ""; -}; + Blockly.Generator.Arduino.codeFunctions_["define_wifi_server"] = + "WiFiServer server(" + box_id + ");"; + Blockly.Generator.Arduino.setupCode_["sensebox_wifi_server_beging"] = + "server.begin();"; + return ""; + }; -Blockly.Arduino.sensebox_http_on_client_connect = function (block) { - var onConnect = Blockly.Arduino.statementToCode(block, "ON_CONNECT"); - var code = ""; - code += "WiFiClient client = server.available();\n"; - code += "if (client && client.available()) {\n"; - code += " String request_string = listenClient(client);\n"; - code += " Request request;\n"; - code += " if (parseRequestSafe(request_string, request)) {\n"; - code += onConnect; - code += " }\n"; - code += " delay(1);\n"; - code += " client.stop();\n"; - code += " delay(1);\n"; - code += "}\n"; - return code; -}; +Blockly.Generator.Arduino.forBlock["sensebox_http_on_client_connect"] = + function (block, generator) { + var onConnect = Blockly.Generator.Arduino.statementToCode( + block, + "ON_CONNECT", + ); + var code = ""; + code += "WiFiClient client = server.available();\n"; + code += "if (client && client.available()) {\n"; + code += " String request_string = listenClient(client);\n"; + code += " Request request;\n"; + code += " if (parseRequestSafe(request_string, request)) {\n"; + code += onConnect; + code += " }\n"; + code += " delay(1);\n"; + code += " client.stop();\n"; + code += " delay(1);\n"; + code += "}\n"; + return code; + }; -Blockly.Arduino.sensebox_http_method = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_http_method"] = function ( + block, + generator, +) { var code = "request.method"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_http_uri = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_http_uri"] = function ( + block, + generator, +) { var code = "request.uri"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_http_protocol_version = function (block) { - var code = "request.protocol_version"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; -}; +Blockly.Generator.Arduino.forBlock["sensebox_http_protocol_version"] = + function (block, generator) { + var code = "request.protocol_version"; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; + }; -Blockly.Arduino.sensebox_http_user_agent = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_http_user_agent"] = function ( + block, + generator, +) { var code = "request.user_agent"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_generate_html_doc = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_generate_html_doc"] = function ( + block, + generator, +) { var header = - Blockly.Arduino.valueToCode(block, "HEADER", Blockly.Arduino.ORDER_NONE) || - '""'; + Blockly.Generator.Arduino.valueToCode( + block, + "HEADER", + Blockly.Generator.Arduino.ORDER_NONE, + ) || '""'; var body = - Blockly.Arduino.valueToCode(block, "BODY", Blockly.Arduino.ORDER_NONE) || - '""'; + Blockly.Generator.Arduino.valueToCode( + block, + "BODY", + Blockly.Generator.Arduino.ORDER_NONE, + ) || '""'; var code = "buildHTML(" + header + ", " + body + ")"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_generate_http_succesful_response = function (block) { +Blockly.Generator.Arduino.sensebox_generate_http_succesful_response = function ( + block, +) { var content = - Blockly.Arduino.valueToCode(block, "CONTENT", Blockly.Arduino.ORDER_NONE) || - '""'; + Blockly.Generator.Arduino.valueToCode( + block, + "CONTENT", + Blockly.Generator.Arduino.ORDER_NONE, + ) || '""'; var code = "client.println(buildSuccessfulResponse(request, " + content + "));\n"; return code; }; -Blockly.Arduino.sensebox_generate_http_not_found_response = function (block) { +Blockly.Generator.Arduino.sensebox_generate_http_not_found_response = function ( + block, +) { var code = "client.println(buildNotFoundResponse(request));\n"; return code; }; -Blockly.Arduino.sensebox_ip_address = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_ip_address"] = function ( + block, + generator, +) { var code = "b->getIpAddress()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_general_html_tag = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_general_html_tag"] = function ( + block, + generator, +) { var tag = this.getFieldValue("TAG"); var code = 'buildTag("' + tag + '",'; var n = 0; - var branch = Blockly.Arduino.valueToCode( + var branch = Blockly.Generator.Arduino.valueToCode( block, "DO" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ); if (branch.length > 0) { code += "\n " + branch; @@ -96,22 +135,26 @@ Blockly.Arduino.sensebox_general_html_tag = function (block) { code += '""'; } for (n = 1; n <= block.additionalChildCount_; n++) { - branch = Blockly.Arduino.valueToCode( + branch = Blockly.Generator.Arduino.valueToCode( block, "DO" + n, - Blockly.Arduino.ORDER_NONE, + Blockly.Generator.Arduino.ORDER_NONE, ); code += " +" + branch; } - return [code + ")", Blockly.Arduino.ORDER_ATOMIC]; + return [code + ")", Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Arduino.sensebox_web_readHTML = function (block) { +Blockly.Generator.Arduino.forBlock["sensebox_web_readHTML"] = function ( + block, + generator, +) { var filename = this.getFieldValue("FILENAME"); - Blockly.Arduino.libraries_["library_spi"] = "#include "; - Blockly.Arduino.libraries_["library_sd"] = "#include "; - Blockly.Arduino.codeFunctions_["define_sd" + filename] = "File webFile;"; - Blockly.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);"; + Blockly.Generator.Arduino.libraries_["library_spi"] = "#include "; + Blockly.Generator.Arduino.libraries_["library_sd"] = "#include "; + Blockly.Generator.Arduino.codeFunctions_["define_sd" + filename] = + "File webFile;"; + Blockly.Generator.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);"; var func = [ "String generateHTML(){", ' webFile = SD.open("' + filename + '", FILE_READ);', @@ -123,10 +166,10 @@ Blockly.Arduino.sensebox_web_readHTML = function (block) { " return finalString;", "}", ]; - var functionName = Blockly.Arduino.addFunction( + var functionName = Blockly.Generator.Arduino.addFunction( "generateHTML", func.join("\n"), ); var code = functionName + "()"; - return [code, Blockly.Arduino.ORDER_ATOMIC]; + return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index 7fff003d..cc743e6f 100644 --- a/src/components/CodeEditor/CodeEditor.js +++ b/src/components/CodeEditor/CodeEditor.js @@ -3,7 +3,7 @@ import { useState, useRef } from "react"; import { default as MonacoEditor } from "@monaco-editor/react"; import { withRouter } from "react-router-dom"; import { Button, Grid } from "@mui/material"; -import Blockly from "blockly/core"; +import * as Blockly from "blockly/core"; import Divider from "@mui/material/Divider"; import { saveAs } from "file-saver"; import Drawer from "@mui/material/Drawer"; diff --git a/src/components/CodeEditor/Sidebar.js b/src/components/CodeEditor/Sidebar.js index 4820e4c2..02e8ee01 100644 --- a/src/components/CodeEditor/Sidebar.js +++ b/src/components/CodeEditor/Sidebar.js @@ -1,5 +1,5 @@ import React from "react"; -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { useSelector } from "react-redux"; import Accordion from "@mui/material/Accordion"; import AccordionSummary from "@mui/material/AccordionSummary"; diff --git a/src/components/ErrorBoundary.js b/src/components/ErrorBoundary.js new file mode 100644 index 00000000..16a61924 --- /dev/null +++ b/src/components/ErrorBoundary.js @@ -0,0 +1,40 @@ +import React from "react"; + +export default class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(error) { + // Update state so the next render will show the fallback UI. + return { hasError: true }; + } + + componentDidCatch(error, errorInfo) { + // You can also log the error to an error reporting service + console.log(error, errorInfo); + } + + handleReset = () => { + // Clear local storage + localStorage.clear(); + + // Reset the error state + this.setState({ hasError: false }); + }; + + render() { + if (this.state.hasError) { + // Render fallback UI with a reset button + return ( +
+

Something went wrong.

+ +
+ ); + } + + return this.props.children; + } +} From 9c9e2b44905a1f5143912f8dba99c88aee34716d Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Mon, 25 Nov 2024 14:16:18 +0100 Subject: [PATCH 13/39] fix: Block with capital b --- src/components/Blockly/generator/logic.js | 36 +++++++++---------- src/components/Blockly/generator/loops.js | 26 +++++++------- .../Blockly/generator/sensebox-esp-now.js | 8 ++--- .../Blockly/generator/sensebox-osem.js | 22 ++++++------ .../Blockly/generator/sensebox-telegram.js | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/components/Blockly/generator/logic.js b/src/components/Blockly/generator/logic.js index 9997b164..7ff86bc8 100644 --- a/src/components/Blockly/generator/logic.js +++ b/src/components/Blockly/generator/logic.js @@ -5,7 +5,7 @@ Blockly.Generator.Arduino.forBlock["logic_boolean"] = function ( generator, ) { // Boolean values true and false. - const code = Block.getFieldValue("BOOL") === "TRUE" ? "true" : "false"; + const code = block.getFieldValue("BOOL") === "TRUE" ? "true" : "false"; return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; @@ -22,15 +22,15 @@ Blockly.Generator.Arduino.forBlock["logic_compare"] = function ( GT: ">", GTE: ">=", }; - const operator = OPERATORS[Block.getFieldValue("OP")]; + const operator = OPERATORS[block.getFieldValue("OP")]; const order = operator === "==" || operator === "!=" ? Blockly.Generator.Arduino.ORDER_EQUALITY : Blockly.Generator.Arduino.ORDER_RELATIONAL; const argument0 = - Blockly.Generator.Arduino.valueToCode(Block, "A", order) || "0"; + Blockly.Generator.Arduino.valueToCode(block, "A", order) || "0"; const argument1 = - Blockly.Generator.Arduino.valueToCode(Block, "B", order) || "0"; + Blockly.Generator.Arduino.valueToCode(block, "B", order) || "0"; const code = "( " + argument0 + " " + operator + " " + argument1 + ")"; return [code, order]; }; @@ -40,13 +40,13 @@ Blockly.Generator.Arduino.forBlock["logic_operation"] = function ( generator, ) { // Operations 'and', 'or'. - const operator = Block.getFieldValue("OP") === "AND" ? "&&" : "||"; + const operator = block.getFieldValue("OP") === "AND" ? "&&" : "||"; const order = operator === "&&" ? Blockly.Generator.Arduino.ORDER_LOGICAL_AND : Blockly.Generator.Arduino.ORDER_LOGICAL_OR; - let argument0 = Blockly.Generator.Arduino.valueToCode(Block, "A", order); - let argument1 = Blockly.Generator.Arduino.valueToCode(Block, "B", order); + let argument0 = Blockly.Generator.Arduino.valueToCode(block, "A", order); + let argument1 = Blockly.Generator.Arduino.valueToCode(block, "B", order); if (!argument0 && !argument1) { // If there are no arguments, then the return value is false. argument0 = "false"; @@ -77,11 +77,11 @@ Blockly.Generator.Arduino.forBlock["controls_if"] = function ( do { conditionCode = Blockly.Generator.Arduino.valueToCode( - Block, + block, "IF" + n, Blockly.Generator.Arduino.ORDER_NONE, ) || "false"; - branchCode = Blockly.Generator.Arduino.statementToCode(Block, "DO" + n); + branchCode = Blockly.Generator.Arduino.statementToCode(block, "DO" + n); code += (n > 0 ? " else " : "") + "if (" + @@ -91,10 +91,10 @@ Blockly.Generator.Arduino.forBlock["controls_if"] = function ( "}\n"; ++n; - } while (Block.getInput("IF" + n)); + } while (block.getInput("IF" + n)); - if (Block.getInput("ELSE")) { - branchCode = Blockly.Generator.Arduino.statementToCode(Block, "ELSE"); + if (block.getInput("ELSE")) { + branchCode = Blockly.Generator.Arduino.statementToCode(block, "ELSE"); code += " else {\n" + branchCode + "}\n"; } return code + "\n"; @@ -112,11 +112,11 @@ Blockly.Generator.Arduino.forBlock["controls_ifelse"] = function ( do { conditionCode = Blockly.Generator.Arduino.valueToCode( - Block, + block, "IF" + n, Blockly.Generator.Arduino.ORDER_NONE, ) || "false"; - branchCode = Blockly.Generator.Arduino.statementToCode(Block, "DO" + n); + branchCode = Blockly.Generator.Arduino.statementToCode(block, "DO" + n); code += (n > 0 ? " else " : "") + "if (" + @@ -126,10 +126,10 @@ Blockly.Generator.Arduino.forBlock["controls_ifelse"] = function ( "}\n"; ++n; - } while (Block.getInput("IF" + n)); + } while (block.getInput("IF" + n)); - if (Block.getInput("ELSE")) { - branchCode = Blockly.Generator.Arduino.statementToCode(Block, "ELSE"); + if (block.getInput("ELSE")) { + branchCode = Blockly.Generator.Arduino.statementToCode(block, "ELSE"); code += " else {\n" + branchCode + "}\n"; } return code + "\n"; @@ -142,7 +142,7 @@ Blockly.Generator.Arduino.forBlock["logic_negate"] = function ( // Negation. const order = Blockly.Generator.Arduino.ORDER_UNARY_PREFIX; const argument0 = - Blockly.Generator.Arduino.valueToCode(Block, "BOOL", order) || "true"; + Blockly.Generator.Arduino.valueToCode(block, "BOOL", order) || "true"; const code = "!" + argument0; return [code, order]; }; diff --git a/src/components/Blockly/generator/loops.js b/src/components/Blockly/generator/loops.js index d5ffb04c..bea9b674 100644 --- a/src/components/Blockly/generator/loops.js +++ b/src/components/Blockly/generator/loops.js @@ -8,13 +8,13 @@ Blockly.Generator.Arduino.forBlock["controls_repeat_ext"] = function ( const repeats = Blockly.Generator.Arduino.valueToCode( - Block, + block, "TIMES", Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; - let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); - branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); + let branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, block.id); let code = ""; const loopVar = "i"; code += @@ -38,7 +38,7 @@ Blockly.Generator.Arduino.forBlock["controls_for"] = function ( generator, ) { const loopIndexVariable = Blockly.getMainWorkspace().getVariableById( - Block.getFieldValue("VAR"), + block.getFieldValue("VAR"), ).name; const allVars = Blockly.getMainWorkspace().getVariableMap().getAllVariables(); @@ -51,18 +51,18 @@ Blockly.Generator.Arduino.forBlock["controls_for"] = function ( initVariable = "int "; // alternatively set to 'myVar.type' but that could lead to issues if users choose a char or a boolean } - const branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + const branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); const startNumber = Blockly.Generator.Arduino.valueToCode( - Block, + block, "FROM", Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; const toNumber = Blockly.Generator.Arduino.valueToCode( - Block, + block, "TO", Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ) || "0"; @@ -70,7 +70,7 @@ Blockly.Generator.Arduino.forBlock["controls_for"] = function ( let byNumber = Math.abs( parseInt( Blockly.Generator.Arduino.valueToCode( - Block, + block, "BY", Blockly.Generator.Arduino.ORDER_ASSIGNMENT, ), @@ -108,15 +108,15 @@ Blockly.Generator.Arduino.forBlock["controls_whileUntil"] = function ( generator, ) { // Do while/until loop. - const until = Block.getFieldValue("MODE") === "UNTIL"; + const until = block.getFieldValue("MODE") === "UNTIL"; let argument0 = Blockly.Generator.Arduino.valueToCode( - Block, + block, "BOOL", Blockly.Generator.Arduino.ORDER_LOGICAL_AND, ) || "false"; - let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); - branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); + let branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, block.id); if (until) { argument0 = "!" + argument0; } @@ -128,7 +128,7 @@ Blockly.Generator.Arduino.forBlock["controls_flow_statements"] = function ( generator, ) { // Flow statements: continue, break. - switch (Block.getFieldValue("FLOW")) { + switch (block.getFieldValue("FLOW")) { case "BREAK": return "break;\n"; case "CONTINUE": diff --git a/src/components/Blockly/generator/sensebox-esp-now.js b/src/components/Blockly/generator/sensebox-esp-now.js index 5cc16db5..cad45657 100644 --- a/src/components/Blockly/generator/sensebox-esp-now.js +++ b/src/components/Blockly/generator/sensebox-esp-now.js @@ -45,12 +45,12 @@ Blockly.Generator.Arduino.forBlock["sensebox_esp_now_receive"] = function ( block, generator, ) { - var idMessage = Block.getFieldValue("VAR"); + var idMessage = block.getFieldValue("VAR"); const varMessage = Blockly.Variables.getVariable( Blockly.getMainWorkspace(), idMessage, ); - var idAddress = Block.getFieldValue("MAC"); + var idAddress = block.getFieldValue("MAC"); const varAddress = Blockly.Variables.getVariable( Blockly.getMainWorkspace(), idAddress, @@ -59,8 +59,8 @@ Blockly.Generator.Arduino.forBlock["sensebox_esp_now_receive"] = function ( varMessage.type + " " + varMessage.name + ";\n"; Blockly.Generator.Arduino.variables_[varAddress.name + varAddress.type] = varAddress.type + " " + varAddress.name + ";\n"; - let branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); - branch = Blockly.Generator.Arduino.addLoopTrap(branch, Block.id); + let branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); + branch = Blockly.Generator.Arduino.addLoopTrap(branch, block.id); Blockly.Generator.Arduino.codeFunctions_["on_data_receive"] = ` void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { ${varMessage.name} = (char*)incomingData; diff --git a/src/components/Blockly/generator/sensebox-osem.js b/src/components/Blockly/generator/sensebox-osem.js index 0696eb79..13e98edc 100644 --- a/src/components/Blockly/generator/sensebox-osem.js +++ b/src/components/Blockly/generator/sensebox-osem.js @@ -1,7 +1,7 @@ import * as Blockly from "blockly"; /** - * Block send Data to the openSenseMap + * block send Data to the openSenseMap */ Blockly.Generator.Arduino.forBlock["sensebox_send_to_osem"] = function ( block, @@ -37,7 +37,7 @@ Blockly.Generator.Arduino.forBlock["sensebox_osem_connection"] = function ( wifi = false; } var box_id = this.getFieldValue("BoxID"); - var branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + var branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); var access_token = this.getFieldValue("access_token"); var blocks = this.getDescendants(); var type = this.getFieldValue("type"); @@ -215,22 +215,22 @@ ${ code += "submitValues();\n"; } else if (type === "Mobile") { var lat = Blockly.Generator.Arduino.valueToCode( - Block, + block, "lat", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var lng = Blockly.Generator.Arduino.valueToCode( - Block, + block, "lng", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var timestamp = Blockly.Generator.Arduino.valueToCode( - Block, + block, "timeStamp", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var altitude = Blockly.Generator.Arduino.valueToCode( - Block, + block, "altitude", Blockly.Generator.Arduino.ORDER_ATOMIC, ); @@ -338,7 +338,7 @@ Blockly.Generator.Arduino.forBlock["sensebox_esp32s2_osem_connection"] = wifi = false; } var box_id = this.getFieldValue("BoxID"); - var branch = Blockly.Generator.Arduino.statementToCode(Block, "DO"); + var branch = Blockly.Generator.Arduino.statementToCode(block, "DO"); var access_token = this.getFieldValue("access_token"); var blocks = this.getDescendants(); var type = this.getFieldValue("type"); @@ -490,22 +490,22 @@ ${ code += "submitValues();\n"; } else if (type === "Mobile") { var lat = Blockly.Generator.Arduino.valueToCode( - Block, + block, "lat", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var lng = Blockly.Generator.Arduino.valueToCode( - Block, + block, "lng", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var timestamp = Blockly.Generator.Arduino.valueToCode( - Block, + block, "timeStamp", Blockly.Generator.Arduino.ORDER_ATOMIC, ); var altitude = Blockly.Generator.Arduino.valueToCode( - Block, + block, "altitude", Blockly.Generator.Arduino.ORDER_ATOMIC, ); diff --git a/src/components/Blockly/generator/sensebox-telegram.js b/src/components/Blockly/generator/sensebox-telegram.js index d5db805c..72d8fcdb 100644 --- a/src/components/Blockly/generator/sensebox-telegram.js +++ b/src/components/Blockly/generator/sensebox-telegram.js @@ -7,7 +7,7 @@ Blockly.Generator.Arduino.forBlock["sensebox_telegram"] = function ( block, generator, ) { - let token = Block.getFieldValue("telegram_token"); + let token = block.getFieldValue("telegram_token"); Blockly.Generator.Arduino.libraries_["library_telegram"] = `#include `; Blockly.Generator.Arduino.functionNames_["WiFiSSLClient"] = From b1282bafc2694bb326aaddcbc682a7fe41e6d567 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Mon, 25 Nov 2024 13:29:25 +0000 Subject: [PATCH 14/39] fix: color field block --- package-lock.json | 13 +++++++++++++ package.json | 1 + src/components/Blockly/blocks/sensebox-led.js | 2 ++ 3 files changed, 16 insertions(+) diff --git a/package-lock.json b/package-lock.json index 8646414d..8626c95e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@blockly/block-plus-minus": "^8.0.9", + "@blockly/field-colour": "^5.0.9", "@blockly/field-grid-dropdown": "^5.0.9", "@blockly/field-multilineinput": "^5.0.10", "@blockly/field-slider": "7.0.9", @@ -2213,6 +2214,18 @@ "blockly": "^11.0.0" } }, + "node_modules/@blockly/field-colour": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/@blockly/field-colour/-/field-colour-5.0.9.tgz", + "integrity": "sha512-ebj4oGwrqkcGKTYjLDHLQYilZ1qfmiPIfi3QVv/ROfSut4VPEf4JEnTmc/AJJrKQgzygdbz02QLZ2DBlVkoWNg==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + }, + "peerDependencies": { + "blockly": "^11.0.0" + } + }, "node_modules/@blockly/field-grid-dropdown": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/@blockly/field-grid-dropdown/-/field-grid-dropdown-5.0.9.tgz", diff --git a/package.json b/package.json index 435550e6..328a02ab 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@blockly/block-plus-minus": "^8.0.9", + "@blockly/field-colour": "^5.0.9", "@blockly/field-grid-dropdown": "^5.0.9", "@blockly/field-multilineinput": "^5.0.10", "@blockly/field-slider": "7.0.9", diff --git a/src/components/Blockly/blocks/sensebox-led.js b/src/components/Blockly/blocks/sensebox-led.js index 8663e776..d47a8405 100644 --- a/src/components/Blockly/blocks/sensebox-led.js +++ b/src/components/Blockly/blocks/sensebox-led.js @@ -7,8 +7,10 @@ import { registerFieldMultilineInput, FieldMultilineInput, } from "@blockly/field-multilineinput"; +import { registerFieldColour } from "@blockly/field-colour"; registerFieldMultilineInput(); +registerFieldColour(); Blockly.Blocks["sensebox_led"] = { init: function () { From ecb590b435758028e00919485b5010acdaad0c85 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Mon, 25 Nov 2024 13:47:40 +0000 Subject: [PATCH 15/39] fix: blockly import --- package-lock.json | 2 +- src/components/Blockly/generator/sensebox-sensors.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8626c95e..d2f848b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,8 +31,8 @@ "@testing-library/jest-dom": "^5.16.1", "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^7.2.1", - "blockly": "^11.1.1", "axios": "^0.28.0", + "blockly": "^11.1.1", "file-saver": "^2.0.5", "markdown-it": "^12.3.2", "mnemonic-id": "^3.2.7", diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 0bfa247a..b2646f61 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -1,4 +1,4 @@ -import Blockly from "blockly"; +import * as Blockly from "blockly"; import { selectedBoard } from "../helpers/board"; /** From 6790b1463f86f13a89bc2f842432627fe772b75c Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Mon, 25 Nov 2024 15:16:07 +0100 Subject: [PATCH 16/39] fix: minify svg --- src/components/copy_esp32.svg | 5095 ++++++++++++++++++++++++++++++++- 1 file changed, 5092 insertions(+), 3 deletions(-) diff --git a/src/components/copy_esp32.svg b/src/components/copy_esp32.svg index 6e9fa454..a52963a2 100644 --- a/src/components/copy_esp32.svg +++ b/src/components/copy_esp32.svg @@ -1,4 +1,5093 @@ - - - \ No newline at end of file + From b66cbdd93017fe98a8e7ca2f3b9f2ce88ae06508 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Mon, 25 Nov 2024 15:37:59 +0100 Subject: [PATCH 17/39] only use 1MHz I2C vor vl53l8cx not for other sensors --- src/components/Blockly/generator/sensebox-sensors.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 44f91a29..ca6b41ae 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -368,15 +368,16 @@ Blockly.Arduino.sensebox_tof_imager = function () { `; Blockly.Arduino.preSetupCode_["Wire.begin"] = "Wire.begin();"; - Blockly.Arduino.preSetupCode_["vl53l8cx_clock_address"] = `Wire.setClock(1000000); // VL53L8CX (ToF) has max I2C freq of 1MHz - sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor`; + Blockly.Arduino.preSetupCode_["vl53l8cx_clock_address"] = `sensor_vl53l8cx.set_i2c_address(0x51); // need to change address, because default address is shared with other sensor`; Blockly.Arduino.setupCode_["setup_vl53l8cx"] = ` + Wire.setClock(1000000); // vl53l8cx can operate at 1MHz sensor_vl53l8cx.begin(); sensor_vl53l8cx.init(); sensor_vl53l8cx.set_ranging_frequency_hz(30); sensor_vl53l8cx.set_resolution(VL53L8CX_RESOLUTION_8X8); sensor_vl53l8cx.start_ranging(); + Wire.setClock(100000); // lower the I2C clock to 0.1MHz again for compatibility with other sensors `; var code = ""; switch (dropdown_name) { @@ -388,10 +389,12 @@ Blockly.Arduino.sensebox_tof_imager = function () { uint8_t NewDataReady = 0; uint8_t status; + Wire.setClock(1000000); // vl53l8cx can operate at 1MHz status = sensor_vl53l8cx.check_data_ready(&NewDataReady); if ((!status) && (NewDataReady != 0)) { sensor_vl53l8cx.get_ranging_data(&Results); + Wire.setClock(100000); // lower the I2C clock to 0.1MHz again for compatibility with other sensors float min = 10000.0; for(int i = 0; i < VL53L8CX_RESOLUTION_8X8*VL53L8CX_NB_TARGET_PER_ZONE; i++) { if((&Results)->target_status[i]!=255){ From 0f80c3a5e5c4c283cd03a9e48496779a90f664f3 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Mon, 25 Nov 2024 16:38:36 +0100 Subject: [PATCH 18/39] only use target status 5, 6 or 9 --- .../Blockly/generator/sensebox-sensors.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index ca6b41ae..62195c76 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -395,16 +395,23 @@ Blockly.Arduino.sensebox_tof_imager = function () { if ((!status) && (NewDataReady != 0)) { sensor_vl53l8cx.get_ranging_data(&Results); Wire.setClock(100000); // lower the I2C clock to 0.1MHz again for compatibility with other sensors - float min = 10000.0; + float minStatus5 = 10000.0; + float minStatus69 = 10000.0; for(int i = 0; i < VL53L8CX_RESOLUTION_8X8*VL53L8CX_NB_TARGET_PER_ZONE; i++) { - if((&Results)->target_status[i]!=255){ - float distance = ((&Results)->distance_mm[i])/10; - if(min > distance) { - min = distance; - } + float distance = ((&Results)->distance_mm[i])/10; + if((&Results)->target_status[i] == 5 && minStatus5 > distance) { + minStatus5 = distance; + } else if(((&Results)->target_status[i] == 6 || (&Results)->target_status[i] == 9) && minStatus69 > distance) { + minStatus69 = distance; } } - oldVl53l8cxMin = (min==10000.0 || min < 0.0) ? 0.0 : min; + if (minStatus5 < 10000.0 && minStatus5 >=0) { + oldVl53l8cxMin = minStatus5; + } else if (minStatus69 < 10000.0 && minStatus69 >=0) { + oldVl53l8cxMin = minStatus69; + } else { + oldVl53l8cxMin = 0.0; + } } return oldVl53l8cxMin; }`; From 2edba7625bbcba7141db78988389d85170b33e69 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Mon, 25 Nov 2024 16:45:33 +0100 Subject: [PATCH 19/39] updated target_status and I2C clock for bitmap generation too --- src/components/Blockly/generator/sensebox-sensors.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 62195c76..1b0adcc6 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -399,9 +399,10 @@ Blockly.Arduino.sensebox_tof_imager = function () { float minStatus69 = 10000.0; for(int i = 0; i < VL53L8CX_RESOLUTION_8X8*VL53L8CX_NB_TARGET_PER_ZONE; i++) { float distance = ((&Results)->distance_mm[i])/10; - if((&Results)->target_status[i] == 5 && minStatus5 > distance) { + float target_status = (&Results)->target_status[i]; + if(target_status == 5 && minStatus5 > distance) { minStatus5 = distance; - } else if(((&Results)->target_status[i] == 6 || (&Results)->target_status[i] == 9) && minStatus69 > distance) { + } else if((target_status == 6 || target_status == 9) && minStatus69 > distance) { minStatus69 = distance; } } @@ -433,10 +434,12 @@ Blockly.Arduino.sensebox_tof_imager = function () { uint8_t NewDataReady = 0; uint8_t status; + Wire.setClock(1000000); // vl53l8cx can operate at 1MHz status = sensor_vl53l8cx.check_data_ready(&NewDataReady); if ((!status) && (NewDataReady != 0)) { sensor_vl53l8cx.get_ranging_data(&Result); + Wire.setClock(100000); // lower the I2C clock to 0.1MHz again for compatibility with other sensors int8_t i, j, k; uint8_t zones_per_line; uint8_t number_of_zones = VL53L8CX_RESOLUTION_8X8; @@ -447,7 +450,8 @@ Blockly.Arduino.sensebox_tof_imager = function () { { for (k = (zones_per_line - 1); k >= 0; k--) { - if((long)(&Result)->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k))] ==255){ + float target_status = (&Result)->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k))]; + if(target_status != 5 && target_status != 6 && target_status != 9) { oldVl53l8cxBitmap[j + k + 2 + ((j+1)/2)] = (((0 >> 3) & 0x1F)<<11 | (((0 >> 2) & 0x3F) << 5) | ((0 >> 3) & 0x1F)); } else { long distance = (long)(&Result)->distance_mm[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k))]; From 06113608440701d4b8798b744485a6385bea0ee9 Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Tue, 26 Nov 2024 13:17:36 +0100 Subject: [PATCH 20/39] fix mutators --- src/components/Blockly/blocks/logic.js | 7 +++++-- src/components/Blockly/blocks/procedures.js | 8 ++++++-- src/components/Blockly/blocks/webserver.js | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/Blockly/blocks/logic.js b/src/components/Blockly/blocks/logic.js index 7e365060..32b949c1 100644 --- a/src/components/Blockly/blocks/logic.js +++ b/src/components/Blockly/blocks/logic.js @@ -20,7 +20,10 @@ Blockly.Blocks["controls_if"] = { this.setPreviousStatement(true); this.setNextStatement(true); this.setMutator( - new Blockly.icons.MutatorIcon(["controls_if_elseif", "controls_if_else"]), + new Blockly.icons.MutatorIcon( + ["controls_if_elseif", "controls_if_else"], + this, + ), ); this.setTooltip(Blockly.Msg.CONTROLS_IF_TOOLTIP_1); this.elseifCount_ = 0; @@ -496,7 +499,7 @@ Blockly.Blocks["switch_case"] = { ); this.appendStatementInput("CASE0").appendField(Blockly.Msg.cases_do); this.setMutator( - new Blockly.icons.MutatorIcon(["case_incaseof", "case_default"]), + new Blockly.icons.MutatorIcon(["case_incaseof", "case_default"], this), ); this.caseCount_ = 0; this.defaultCount_ = 0; diff --git a/src/components/Blockly/blocks/procedures.js b/src/components/Blockly/blocks/procedures.js index 57cd6287..0f3d6918 100644 --- a/src/components/Blockly/blocks/procedures.js +++ b/src/components/Blockly/blocks/procedures.js @@ -49,7 +49,9 @@ Blockly.Blocks["procedures_defnoreturn"] = { .appendField(Blockly.Msg.PROCEDURES_DEFNORETURN) .appendField(nameField, "NAME") .appendField("", "PARAMS"); - this.setMutator(new Blockly.icons.MutatorIcon(["procedures_mutatorarg"])); + this.setMutator( + new Blockly.icons.MutatorIcon(["procedures_mutatorarg"], this), + ); if ( (this.workspace.options.comments || (this.workspace.options.parentWorkspace && @@ -477,7 +479,9 @@ Blockly.Blocks["procedures_defreturn"] = { this.appendValueInput("RETURN") .setAlign(Blockly.inputs.Align.RIGHT) .appendField(Blockly.Msg["PROCEDURES_DEFRETURN_RETURN"]); - this.setMutator(new Blockly.icons.MutatorIcon(["procedures_mutatorarg"])); + this.setMutator( + new Blockly.icons.MutatorIcon(["procedures_mutatorarg"], this), + ); if ( (this.workspace.options.comments || (this.workspace.options.parentWorkspace && diff --git a/src/components/Blockly/blocks/webserver.js b/src/components/Blockly/blocks/webserver.js index d49a3704..a0cfe35d 100644 --- a/src/components/Blockly/blocks/webserver.js +++ b/src/components/Blockly/blocks/webserver.js @@ -163,7 +163,7 @@ Blockly.Blocks["sensebox_general_html_tag"] = { this.setHelpUrl("https://sensebox.de/books"); this.setPreviousStatement(false); this.setNextStatement(false); - this.setMutator(new Blockly.icons.MutatorIcon(["additional_child"])); + this.setMutator(new Blockly.icons.MutatorIcon(["additional_child"], this)); this.additionalChildCount_ = 0; }, /** From 046dad065e7d840965b7f2c455c34196cddc2e1c Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Tue, 26 Nov 2024 13:13:45 +0000 Subject: [PATCH 21/39] fix: compare block.outputConnection --- src/components/Blockly/blocks/logic.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Blockly/blocks/logic.js b/src/components/Blockly/blocks/logic.js index 32b949c1..ff6e79e0 100644 --- a/src/components/Blockly/blocks/logic.js +++ b/src/components/Blockly/blocks/logic.js @@ -470,18 +470,18 @@ Blockly.Blocks["logic_compare"] = { } if (blockA !== null && blockB === null) { this.getInput("A").setCheck( - getCompatibleTypes(blockA.outputConnection.check_[0]), + getCompatibleTypes(blockA.outputConnection.check[0]), ); this.getInput("B").setCheck( - getCompatibleTypes(blockA.outputConnection.check_[0]), + getCompatibleTypes(blockA.outputConnection.check[0]), ); } if (blockB !== null && blockA === null) { this.getInput("B").setCheck( - getCompatibleTypes(blockB.outputConnection.check_[0]), + getCompatibleTypes(blockB.outputConnection.check[0]), ); this.getInput("A").setCheck( - getCompatibleTypes(blockB.outputConnection.check_[0]), + getCompatibleTypes(blockB.outputConnection.check[0]), ); } }, From 1f8df0bf20403801d3ba9674aac47bb33cddd9d5 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Tue, 26 Nov 2024 13:44:08 +0000 Subject: [PATCH 22/39] fix: procedures_defnoreturn generator --- .../Blockly/generator/procedures.js | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/Blockly/generator/procedures.js b/src/components/Blockly/generator/procedures.js index d71ffca7..d16aa920 100644 --- a/src/components/Blockly/generator/procedures.js +++ b/src/components/Blockly/generator/procedures.js @@ -105,8 +105,39 @@ function translateType(type) { } } -Blockly.Generator.Arduino["procedures_defnoreturn"] = - Blockly.Generator.Arduino["procedures_defreturn"]; +Blockly.Generator.Arduino.forBlock["procedures_defnoreturn"] = function ( + block, + generator, +) { + // Define a procedure with a return value. + const funcName = Blockly.Generator.Arduino.nameDB_.getName( + block.getFieldValue("NAME"), + Blockly.Procedures.NAME_TYPE, + ); + const branch = Blockly.Generator.Arduino.statementToCode(block, "STACK"); + const returnType = "void"; + + const args = []; + for (let i = 0; i < block.argumentVarModels_.length; i++) { + args[i] = + translateType(block.argumentVarModels_[i].type) + + " " + + block.argumentVarModels_[i].name; + } + let code = + translateType(returnType) + + " " + + funcName + + "(" + + args.join(", ") + + ") {\n" + + branch + + "}"; + code = Blockly.Generator.Arduino.scrub_(block, code); + // Add % so as not to collide with helper functions in definitions list. + Blockly.Generator.Arduino.functionNames_["%" + funcName] = code; + return null; +}; Blockly.Generator.Arduino.forBlock["procedures_callreturn"] = function ( block, From 0a920f857f523f497ec3f6331be3c5ae4b24e539 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Tue, 26 Nov 2024 14:12:10 +0000 Subject: [PATCH 23/39] fix: reconnect connections --- src/components/Blockly/blocks/logic.js | 16 +++++++++------- src/components/Blockly/blocks/procedures.js | 12 +++++------- src/components/Blockly/blocks/webserver.js | 8 +++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/components/Blockly/blocks/logic.js b/src/components/Blockly/blocks/logic.js index ff6e79e0..e9274cb6 100644 --- a/src/components/Blockly/blocks/logic.js +++ b/src/components/Blockly/blocks/logic.js @@ -113,14 +113,16 @@ Blockly.Blocks["controls_if"] = { this.updateShape_(); // Reconnect any child blocks. for (var i = 1; i <= this.elseifCount_; i++) { - Blockly.icons.MutatorIcon.reconnect(valueConnections[i], this, "IF" + i); - Blockly.icons.MutatorIcon.reconnect( - statementConnections[i], - this, - "DO" + i, - ); + if (valueConnections[i]) { + valueConnections[i].reconnect(this, "IF" + i); + } + if (statementConnections[i]) { + statementConnections[i].reconnect(this, "DO" + i); + } + } + if (elseStatementConnection) { + elseStatementConnection.reconnect(this, "ELSE"); } - Blockly.icons.MutatorIcon.reconnect(elseStatementConnection, this, "ELSE"); }, /** * Store pointers to any connected child blocks. diff --git a/src/components/Blockly/blocks/procedures.js b/src/components/Blockly/blocks/procedures.js index 0f3d6918..fa595b75 100644 --- a/src/components/Blockly/blocks/procedures.js +++ b/src/components/Blockly/blocks/procedures.js @@ -272,11 +272,9 @@ Blockly.Blocks["procedures_defnoreturn"] = { if (hasStatements) { this.setStatements_(true); // Restore the stack, if one was saved. - Blockly.icons.MutatorIcon.reconnect( - this.statementConnection_, - this, - "STACK", - ); + if (this.statementConnection_) { + this.statementConnection_.reconnect(this, "STACK"); + } this.statementConnection_ = null; } else { // Save the stack, then disconnect it. @@ -912,8 +910,8 @@ Blockly.Blocks["procedures_callnoreturn"] = { if (quarkId in this.quarkConnections_) { const connection = this.quarkConnections_[quarkId]; try { - if ( - !Blockly.icons.MutatorIcon.reconnect(connection, this, "ARG" + i) + if (connection && + !connection.reconnect(this, "ARG" + i) ) { // Block no longer exists or has been attached elsewhere. delete this.quarkConnections_[quarkId]; diff --git a/src/components/Blockly/blocks/webserver.js b/src/components/Blockly/blocks/webserver.js index a0cfe35d..8fd4ea7c 100644 --- a/src/components/Blockly/blocks/webserver.js +++ b/src/components/Blockly/blocks/webserver.js @@ -234,11 +234,9 @@ Blockly.Blocks["sensebox_general_html_tag"] = { this.updateShape_(); // Reconnect any child blocks. for (var i = 1; i <= this.additionalChildCount_; i++) { - Blockly.icons.MutatorIcon.reconnect( - statementConnections[i], - this, - "DO" + i, - ); + if (statementConnections[i]) { + statementConnections[i].reconnect(this, "DO" + i); + } } }, /** From 2605ba3fb98d31a7b2871b537800c1438050778b Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Tue, 26 Nov 2024 14:39:30 +0000 Subject: [PATCH 24/39] fix: switch_case CASECONDITION --- src/components/Blockly/generator/logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Blockly/generator/logic.js b/src/components/Blockly/generator/logic.js index 7ff86bc8..20c23f8e 100644 --- a/src/components/Blockly/generator/logic.js +++ b/src/components/Blockly/generator/logic.js @@ -160,7 +160,7 @@ Blockly.Generator.Arduino.forBlock["switch_case"] = function ( ) || ""; var branch = Blockly.Generator.Arduino.statementToCode( block, - "CASECONDITON0" + n, + "CASECONDITION" + n, ); var cases = ""; var default_code = ""; From 893966e10371d688e1d693d3aea21bf37f474140 Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Tue, 26 Nov 2024 14:51:25 +0000 Subject: [PATCH 25/39] fix: forBlock in variables --- src/components/Blockly/generator/variables.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Blockly/generator/variables.js b/src/components/Blockly/generator/variables.js index 3dcc3235..73fbe9a2 100644 --- a/src/components/Blockly/generator/variables.js +++ b/src/components/Blockly/generator/variables.js @@ -58,5 +58,5 @@ const getVariableFunction = function (block) { return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; -Blockly.Generator.Arduino["variables_set_dynamic"] = setVariableFunction(); -Blockly.Generator.Arduino["variables_get_dynamic"] = getVariableFunction; +Blockly.Generator.Arduino.forBlock["variables_set_dynamic"] = setVariableFunction(); +Blockly.Generator.Arduino.forBlock["variables_get_dynamic"] = getVariableFunction; From d609ffbdd03335d23997141bcf8db7604d522bdd Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Tue, 26 Nov 2024 16:46:32 +0100 Subject: [PATCH 26/39] fix case block --- src/components/Blockly/blocks/logic.js | 6 ++- src/components/Blockly/generator/logic.js | 47 ++++++++++++----------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/components/Blockly/blocks/logic.js b/src/components/Blockly/blocks/logic.js index e9274cb6..dadc0a3a 100644 --- a/src/components/Blockly/blocks/logic.js +++ b/src/components/Blockly/blocks/logic.js @@ -522,8 +522,10 @@ Blockly.Blocks["switch_case"] = { }, domToMutation: function (xmlElement) { - this.caseCount_ = parseInt(xmlElement.getAttribute("case"), 10); + this.caseCount_ = parseInt(xmlElement.getAttribute("case"), 10) || 0; this.defaultCount_ = parseInt(xmlElement.getAttribute("default"), 10); + this.removeInput("CASECONDITION0"); + this.removeInput("CASE0"); for (var x = 0; x <= this.caseCount_; x++) { this.appendValueInput("CASECONDITION" + x).appendField( Blockly.Msg.cases_condition, @@ -546,7 +548,7 @@ Blockly.Blocks["switch_case"] = { connection = caseBlock.nextConnection; } if (this.defaultCount_) { - var defaultBlock = Blockly.Block.obtain(workspace, "case_default"); + var defaultBlock = workspace.newBlock("case_default"); defaultBlock.initSvg(); connection.connect(defaultBlock.previousConnection); } diff --git a/src/components/Blockly/generator/logic.js b/src/components/Blockly/generator/logic.js index 20c23f8e..e680c5bc 100644 --- a/src/components/Blockly/generator/logic.js +++ b/src/components/Blockly/generator/logic.js @@ -147,39 +147,42 @@ Blockly.Generator.Arduino.forBlock["logic_negate"] = function ( return [code, order]; }; -Blockly.Generator.Arduino.forBlock["switch_case"] = function ( - block, - generator, -) { - var n = 0; +Blockly.Generator.Arduino.forBlock["switch_case"] = function (block) { + // Retrieve the switch condition var argument = Blockly.Generator.Arduino.valueToCode( - this, + block, "CONDITION", Blockly.Generator.Arduino.ORDER_NONE, - ) || ""; - var branch = Blockly.Generator.Arduino.statementToCode( - block, - "CASECONDITION" + n, - ); + ) || "0"; + + // Initialize variables for cases and the default case var cases = ""; - var default_code = ""; - var DO = Blockly.Generator.Arduino.statementToCode(block, "CASE" + n); - for (n = 0; n <= block.caseCount_; n++) { - DO = Blockly.Generator.Arduino.statementToCode(block, "CASE" + n); - branch = + var defaultCode = ""; + + // Iterate through all cases (ensure the loop covers all cases) + for (var n = 0; n <= block.caseCount_; n++) { + // Generate the case condition and corresponding code + var branch = Blockly.Generator.Arduino.valueToCode( block, "CASECONDITION" + n, Blockly.Generator.Arduino.ORDER_NONE, ) || "0"; - cases += "case " + branch + ":\n"; - cases += DO + "\nbreak;\n"; + var code = Blockly.Generator.Arduino.statementToCode(block, "CASE" + n); + cases += " case " + branch + ":\n" + code + " break;\n"; } + + // Add the default case, if present if (block.defaultCount_) { - branch = Blockly.Generator.Arduino.statementToCode(block, "ONDEFAULT"); - default_code = "default: \n" + branch + "\n break;\n"; + var defaultBranch = Blockly.Generator.Arduino.statementToCode( + block, + "ONDEFAULT", + ); + defaultCode = " default:\n" + defaultBranch + " break;\n"; } - var code = "switch (" + argument + ") {\n" + cases + default_code + "}"; - return code + "\n"; + + // Combine everything into a single switch statement + var code = "switch (" + argument + ") {\n" + cases + defaultCode + "}\n"; + return code; }; From 0084ac3f222e3efc2ff6c2ff3c2f4aa36093236e Mon Sep 17 00:00:00 2001 From: Mario Pesch Date: Tue, 26 Nov 2024 16:52:28 +0100 Subject: [PATCH 27/39] fix load xml file and reset workspace --- src/components/Tutorial/Builder/BlocklyExample.js | 2 +- src/components/Workspace/OpenProject.js | 7 +++++-- src/components/Workspace/ResetWorkspace.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Tutorial/Builder/BlocklyExample.js b/src/components/Tutorial/Builder/BlocklyExample.js index d3fe6f8d..23d79227 100644 --- a/src/components/Tutorial/Builder/BlocklyExample.js +++ b/src/components/Tutorial/Builder/BlocklyExample.js @@ -87,7 +87,7 @@ class BlocklyExample extends Component { var xml = this.props.value; // check if value is valid xml; try { - Blockly.Xml.textToDom(xml); + Blockly.utils.xml.textToDom(xml); this.props.deleteError(this.props.index, "xml"); } catch (err) { xml = initialXml; diff --git a/src/components/Workspace/OpenProject.js b/src/components/Workspace/OpenProject.js index 2e09d7eb..467b23c6 100644 --- a/src/components/Workspace/OpenProject.js +++ b/src/components/Workspace/OpenProject.js @@ -67,7 +67,10 @@ class OpenProject extends Component { this.props.clearStats(); Blockly.Xml.domToWorkspace(xmlFile, workspace); if (workspace.getAllBlocks().length < 1) { - Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xmlBefore), workspace); + Blockly.Xml.domToWorkspace( + Blockly.utils.xml.textToDom(xmlBefore), + workspace, + ); this.setState({ open: true, title: Blockly.Msg.no_blocks_found_title, @@ -104,7 +107,7 @@ class OpenProject extends Component { reader.onloadend = () => { var xmlDom = null; try { - xmlDom = Blockly.Xml.textToDom(reader.result); + xmlDom = Blockly.utils.xml.textToDom(reader.result); var boardAttribute = xmlDom.getAttribute("board"); if (!boardAttribute) { this.setState({ showOldXMLFileWarning: true }); diff --git a/src/components/Workspace/ResetWorkspace.js b/src/components/Workspace/ResetWorkspace.js index ac50a6ac..30ffdb4b 100644 --- a/src/components/Workspace/ResetWorkspace.js +++ b/src/components/Workspace/ResetWorkspace.js @@ -61,7 +61,7 @@ class ResetWorkspace extends Component { const workspace = Blockly.getMainWorkspace(); Blockly.Events.disable(); // https://groups.google.com/forum/#!topic/blockly/m7e3g0TC75Y // if events are disabled, then the workspace will be cleared AND the blocks are not in the trashcan - const xmlDom = Blockly.Xml.textToDom(initialXml); + const xmlDom = Blockly.utils.xml.textToDom(initialXml); Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); Blockly.Events.enable(); workspace.options.maxBlocks = Infinity; From 6cba720b0827c33973ac7e4c9d42d881d87a9a7a Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Tue, 17 Dec 2024 13:56:40 +0100 Subject: [PATCH 28/39] single negativ block, better Tooltip links, deacrease variable, fix tooltip language update, fix prime detection and readHTML --- src/components/Blockly/blocks/math.js | 35 ++- src/components/Blockly/generator/math.js | 236 ++++++++++++------ src/components/Blockly/generator/webserver.js | 26 +- src/components/Blockly/msg/de/math.js | 6 +- src/components/Blockly/msg/de/ui.js | 4 +- src/components/Blockly/msg/en/math.js | 6 +- src/components/Blockly/msg/en/ui.js | 5 +- src/components/Blockly/toolbox/ToolboxEsp.js | 1 + src/components/Blockly/toolbox/ToolboxMcu.js | 1 + src/components/TooltipViewer.js | 47 ++-- 10 files changed, 245 insertions(+), 122 deletions(-) diff --git a/src/components/Blockly/blocks/math.js b/src/components/Blockly/blocks/math.js index 88cf43bd..5c1b6a33 100644 --- a/src/components/Blockly/blocks/math.js +++ b/src/components/Blockly/blocks/math.js @@ -81,6 +81,29 @@ Blockly.Blocks["math_arithmetic"] = { //TODO: a getBlockType based on the two input types following C++ rules }; +Blockly.Blocks["math_negative"] = { + /** + * Block for single minus sign + * @this Blockly.Block + */ + init: function () { + this.jsonInit({ + message0: "- %1", + args0: [ + { + type: "input_value", + name: "NUM", + check: Types.getCompatibleTypes("float"), + }, + ], + output: Types.DECIMAL.typeName, + colour: getColour().math, + helpUrl: Blockly.Msg.MATH_SINGLE_HELPURL, + tooltip: Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG, + }); + }, +}; + Blockly.Blocks["math_single"] = { /** * Block for advanced math operators with single operand. @@ -96,7 +119,6 @@ Blockly.Blocks["math_single"] = { options: [ [Blockly.Msg.MATH_SINGLE_OP_ROOT, "ROOT"], [Blockly.Msg.MATH_SINGLE_OP_ABSOLUTE, "ABS"], - ["-", "NEG"], ["ln", "LN"], ["log10", "LOG10"], ["e^", "EXP"], @@ -120,7 +142,6 @@ Blockly.Blocks["math_single"] = { var TOOLTIPS = { ROOT: Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT, ABS: Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS, - NEG: Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG, LN: Blockly.Msg.MATH_SINGLE_TOOLTIP_LN, LOG10: Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10, EXP: Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP, @@ -281,13 +302,21 @@ Blockly.Blocks["math_number_property"] = { Blockly.Blocks["math_change"] = { /** - * Block for adding to a variable in place. + * Block for adding or subtracting to a variable in place. * @this Blockly.Block */ init: function () { this.jsonInit({ message0: Blockly.Msg.MATH_CHANGE_TITLE, args0: [ + { + type: "field_dropdown", + name: "DIRECTION", + options: [ + [Blockly.Msg.MATH_CHANGE_UP, "+="], + [Blockly.Msg.MATH_CHANGE_DOWN, "-="], + ], + }, { type: "field_variable", name: "VAR", diff --git a/src/components/Blockly/generator/math.js b/src/components/Blockly/generator/math.js index 7d7b4f59..cc46d88c 100644 --- a/src/components/Blockly/generator/math.js +++ b/src/components/Blockly/generator/math.js @@ -18,17 +18,10 @@ 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.Generator.Arduino.forBlock["math_number"] = function ( - block, - generator, -) { - // Numeric value. +Blockly.Generator.Arduino.forBlock["math_number"] = function (block) { var unparsedCode = block.getFieldValue("NUM"); - // understand decimal comma for german users - if (unparsedCode.includes(",")) { - // maybe add notification for educational purpose here - unparsedCode = unparsedCode.replace(",", "."); - } + // understand decimal comma for german users (maybe add notification for educational purpose here) + unparsedCode = unparsedCode.replace(",", "."); var code = parseFloat(unparsedCode); block.setFieldValue(code, "NUM"); if (code === Infinity) { @@ -46,16 +39,13 @@ Blockly.Generator.Arduino.forBlock["math_number"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function (block) { var OPERATORS = { ADD: [" + ", Blockly.Generator.Arduino.ORDER_ADDITIVE], MINUS: [" - ", Blockly.Generator.Arduino.ORDER_ADDITIVE], MULTIPLY: [" * ", Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE], DIVIDE: [" / ", Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE], - POWER: [null, Blockly.Generator.Arduino.ORDER_NONE], // Handle power separately. + POWER: [" ^ ", Blockly.Generator.Arduino.ORDER_NONE], // Handle power separately. }; var tuple = OPERATORS[block.getFieldValue("OP")]; var operator = tuple[0]; @@ -66,24 +56,19 @@ Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function ( Blockly.Generator.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 + ")"; + if (operator === " ^ ") { + code = `Math.pow(${argument0}, ${argument1})`; return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } code = argument0 + operator + argument1; return [code, order]; -}; - -/** +}; /** * Generator for math operators that contain a single operand (X). * Arduino code: loop { operator(X) } * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_single"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { var operator = block.getFieldValue("OP"); var code; var arg; @@ -185,6 +170,123 @@ Blockly.Generator.Arduino.forBlock["math_single"] = function ( return [code, Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE]; }; +/** + * Generator math negative operant -(X). + * Arduino code: loop { -(X) } + * @param {!Blockly.Block} block Block to generate the code from. + * @return {array} Completed code with order of operation. + */ +Blockly.Generator.Arduino.forBlock["math_negative"] = function (block) { + var code; + var arg; + // Negation is a special case given its different operator precedents. + arg = + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_UNARY_PREFIX, + ) || "0"; + if (arg[0] === "-") { + // --3 is not legal in C++ in this context. + arg = " " + arg; + } + code = "-" + arg; + return [code, Blockly.Generator.Arduino.ORDER_UNARY_PREFIX]; +}; + +/** + * Generator for math operators that contain a single operand (X). + * Arduino code: loop { operator(X) } + * @param {!Blockly.Block} block Block to generate the code from. + * @return {array} Completed code with order of operation. + */ +Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { + var operator = block.getFieldValue("OP"); + var code; + var arg; + if (operator === "ABS" || operator.substring(0, 5) === "ROUND") { + arg = + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, + ) || "0"; + } else if (operator === "SIN" || operator === "COS" || operator === "TAN") { + arg = + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, + ) || "0"; + } else { + arg = + Blockly.Generator.Arduino.valueToCode( + block, + "NUM", + Blockly.Generator.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.Generator.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.Generator.Arduino.ORDER_MULTIPLICATIVE]; +}; + /** * Generator for math constants (PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), * INFINITY). @@ -194,10 +296,7 @@ Blockly.Generator.Arduino.forBlock["math_single"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Generator.Arduino.forBlock["math_constant"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_constant"] = function (block) { var CONSTANTS = { PI: ["M_PI", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], E: ["M_E", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX], @@ -219,10 +318,7 @@ Blockly.Generator.Arduino.forBlock["math_constant"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_number_property"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_number_property"] = function (block) { var number_to_check = Blockly.Generator.Arduino.valueToCode( block, @@ -232,33 +328,26 @@ Blockly.Generator.Arduino.forBlock["math_number_property"] = function ( var dropdown_property = block.getFieldValue("PROPERTY"); var code; if (dropdown_property === "PRIME") { - var func = [ - "boolean " + Blockly.Generator.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.Generator.Arduino.addFunction( - "mathIsPrime", - func.join("\n"), - ); - Blockly.Generator.Arduino.addInclude("math", "#include "); - code = funcName + "(" + number_to_check + ")"; + Blockly.Generator.Arduino.codeFunctions_["isPrime"] = + `boolean isPrime(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 or 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; + }`; + Blockly.Generator.Arduino.libraries_["math"] = "#include "; + code = `isPrime(${number_to_check})`; return [code, Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; } switch (dropdown_property) { @@ -269,7 +358,7 @@ Blockly.Generator.Arduino.forBlock["math_number_property"] = function ( code = number_to_check + " % 2 == 1"; break; case "WHOLE": - Blockly.Generator.Arduino.addInclude("math", "#include "); + Blockly.Generator.Arduino.libraries_["math"] = "#include "; code = "(floor(" + number_to_check + ") == " + number_to_check + ")"; break; case "POSITIVE": @@ -294,17 +383,14 @@ Blockly.Generator.Arduino.forBlock["math_number_property"] = function ( }; /** - * Generator to add (Y) to a variable (X). + * Generator to add/subtract (Y) to a variable (X). * If variable X has not been declared before this block it will be declared as * a (not initialised) global int, however globals are 0 initialised in C/C++. * Arduino code: loop { X += Y; } * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_change"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_change"] = function (block) { var argument0 = Blockly.Generator.Arduino.valueToCode( block, @@ -347,10 +433,7 @@ Blockly.Generator.Arduino["math_on_list"] = * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_modulo"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_modulo"] = function (block) { var argument0 = Blockly.Generator.Arduino.valueToCode( block, @@ -373,10 +456,7 @@ Blockly.Generator.Arduino.forBlock["math_modulo"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_constrain"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_constrain"] = function (block) { // Constrain a number between two limits. var argument0 = Blockly.Generator.Arduino.valueToCode( @@ -422,10 +502,7 @@ Blockly.Generator.Arduino.forBlock["math_constrain"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_random_int"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_random_int"] = function (block) { var argument0 = Blockly.Generator.Arduino.valueToCode( block, @@ -460,9 +537,6 @@ Blockly.Generator.Arduino.forBlock["math_random_int"] = function ( * @param {!Blockly.Block} block Block to generate the code from. * @return {string} Completed code. */ -Blockly.Generator.Arduino.forBlock["math_random_float"] = function ( - block, - generator, -) { +Blockly.Generator.Arduino.forBlock["math_random_float"] = function () { return ["(rand() / RAND_MAX)", Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX]; }; diff --git a/src/components/Blockly/generator/webserver.js b/src/components/Blockly/generator/webserver.js index 70bf669e..50b6dda1 100644 --- a/src/components/Blockly/generator/webserver.js +++ b/src/components/Blockly/generator/webserver.js @@ -155,21 +155,15 @@ Blockly.Generator.Arduino.forBlock["sensebox_web_readHTML"] = function ( Blockly.Generator.Arduino.codeFunctions_["define_sd" + filename] = "File webFile;"; Blockly.Generator.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);"; - var func = [ - "String generateHTML(){", - ' webFile = SD.open("' + filename + '", FILE_READ);', - ' String finalString ="";', - " while (webFile.available())", - " {", - " finalString+=(char)webFile.read();", - " }", - " return finalString;", - "}", - ]; - var functionName = Blockly.Generator.Arduino.addFunction( - "generateHTML", - func.join("\n"), - ); - var code = functionName + "()"; + Blockly.Generator.Arduino.codeFunctions_["generateHTML"] = + `String readHTML(String filename){ + webFile = SD.open(filename, FILE_READ); + String finalString = ""; + while (webFile.available()) { + finalString += (char)webFile.read(); + } + return finalString; + }`; + var code = `readHTML("${filename}")`; return [code, Blockly.Generator.Arduino.ORDER_ATOMIC]; }; diff --git a/src/components/Blockly/msg/de/math.js b/src/components/Blockly/msg/de/math.js index 8be2a648..d9a128d6 100644 --- a/src/components/Blockly/msg/de/math.js +++ b/src/components/Blockly/msg/de/math.js @@ -8,8 +8,10 @@ export const MATH = { MATH_ARITHMETIC_TOOLTIP_POWER: "Ist der erste Wert potenziert mit dem zweiten Wert.", MATH_CHANGE_HELPURL: "https://de.wikipedia.org/wiki/Inkrement_und_Dekrement", - MATH_CHANGE_TITLE: "erhöhe %1 um %2", - MATH_CHANGE_TOOLTIP: 'Addiert einen Wert zur Variable "%1" hinzu.', + MATH_CHANGE_TITLE: "%1 %2 um %3", + MATH_CHANGE_UP: "erhöhe", + MATH_CHANGE_DOWN: "verringere", + MATH_CHANGE_TOOLTIP: 'Addiert/Subtraiert einen Wert zur/von Variable "%2".', MATH_CONSTANT_HELPURL: "https://de.wikipedia.org/wiki/Mathematische_Konstante", MATH_CONSTANT_TOOLTIP: diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 3b13dd9d..2ea0feeb 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -322,7 +322,7 @@ export const UI = { */ tooltip_viewer: "Hilfe", - tooltip_moreInformation: "Mehr Informationen findest du ", + tooltip_moreInformation: "Mehr Informationen", tooltip_hint: "Wähle einen Block aus um dir die Hilfe anzeigen zu lassen", /** @@ -341,7 +341,7 @@ export const UI = { "Stelle sicher, dasss du das Display im Setup initialisiert hast.", variable_redeclared: "Stelle sicher, dass du keine Sonderzeichen in deinen Variablennamen verwendest. Dazu gehören z.B. Leerzeichen, Sternchen oder Anführungszeichen.", - + /** * Code Editor * */ diff --git a/src/components/Blockly/msg/en/math.js b/src/components/Blockly/msg/en/math.js index 551de72c..05852f88 100644 --- a/src/components/Blockly/msg/en/math.js +++ b/src/components/Blockly/msg/en/math.js @@ -9,8 +9,10 @@ export const MATH = { "Return the first number raised to the power of the second number.", MATH_CHANGE_HELPURL: "https://en.wikipedia.org/wiki/Programming_idiom#Incrementing_a_counter", - MATH_CHANGE_TITLE: "change %1 by %2", - MATH_CHANGE_TOOLTIP: "Add a number to variable '%1'.", + MATH_CHANGE_TITLE: "%1 %2 by %3", + MATH_CHANGE_UP: "increase", + MATH_CHANGE_DOWN: "decrease", + MATH_CHANGE_TOOLTIP: "Adds/Subtracts a number to/from the variable '%2'.", MATH_CONSTANT_HELPURL: "https://en.wikipedia.org/wiki/Mathematical_constant", MATH_CONSTANT_TOOLTIP: "Return one of the common constants: π (3.141…), e (2.718…), φ (1.618…), sqrt(2) (1.414…), sqrt(½) (0.707…), or ∞ (infinity).", diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 837e8426..7f34f70c 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -316,7 +316,7 @@ export const UI = { */ tooltip_viewer: "Help", - tooltip_moreInformation: "More informations can be found ", + tooltip_moreInformation: "More information", tooltip_hint: "Select a Block to show the hint", /** @@ -344,7 +344,8 @@ export const UI = { suggestion_pre_text: "Maybe you should try:", display_not_declared: "Initialise the display in the setup() function", - variable_redeclared: "Make sure that you do not use any special characters in your variable names. This includes spaces, asterisks or quotation marks.", + variable_redeclared: + "Make sure that you do not use any special characters in your variable names. This includes spaces, asterisks or quotation marks.", /** * Device Selection * */ diff --git a/src/components/Blockly/toolbox/ToolboxEsp.js b/src/components/Blockly/toolbox/ToolboxEsp.js index 2e9b9858..61355496 100644 --- a/src/components/Blockly/toolbox/ToolboxEsp.js +++ b/src/components/Blockly/toolbox/ToolboxEsp.js @@ -546,6 +546,7 @@ export const ToolboxEsp = () => { > + diff --git a/src/components/Blockly/toolbox/ToolboxMcu.js b/src/components/Blockly/toolbox/ToolboxMcu.js index 5e5342ff..9475e0f6 100644 --- a/src/components/Blockly/toolbox/ToolboxMcu.js +++ b/src/components/Blockly/toolbox/ToolboxMcu.js @@ -538,6 +538,7 @@ export const ToolboxMcu = () => { > + diff --git a/src/components/TooltipViewer.js b/src/components/TooltipViewer.js index 43fc80c7..1bbb14f4 100644 --- a/src/components/TooltipViewer.js +++ b/src/components/TooltipViewer.js @@ -60,20 +60,38 @@ class TooltipViewer extends Component { {this.props.tooltip} - {store.getState().workspace.code.data ? ( - - ) : ( - {`${Blockly.Msg.tooltip_moreInformation} [${Blockly.Msg.labels_here}](${this.props.helpurl})`} - )} +
+ {store.getState().workspace.code.data && ( + + )} + {this.props.helpurl && ( + + )} +
{store.getState().workspace.code.data ? ( @@ -115,6 +133,7 @@ TooltipViewer.propTypes = { const mapStateToProps = (state) => ({ tooltip: state.workspace.code.tooltip, helpurl: state.workspace.code.helpurl, + language: state.general.language, }); export default connect(mapStateToProps, null)(withWidth()(TooltipViewer)); From b43b686b408a636fc104427c83e0e1d2fe7e5e21 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Mon, 30 Dec 2024 22:46:38 +0100 Subject: [PATCH 29/39] fix language (update), tooltips and compiling math bugs --- src/components/Blockly/blocks/math.js | 68 +------ src/components/Blockly/generator/math.js | 185 ++++++------------ src/components/Blockly/generator/webserver.js | 2 +- src/components/Blockly/msg/de/math.js | 30 +-- src/components/Blockly/msg/en/math.js | 30 +-- src/components/Blockly/msg/en/ui.js | 2 +- src/components/CodeViewer.js | 1 - src/components/TooltipViewer.js | 4 +- 8 files changed, 112 insertions(+), 210 deletions(-) diff --git a/src/components/Blockly/blocks/math.js b/src/components/Blockly/blocks/math.js index 5c1b6a33..42d2e1a2 100644 --- a/src/components/Blockly/blocks/math.js +++ b/src/components/Blockly/blocks/math.js @@ -15,16 +15,7 @@ Blockly.Blocks["math_number"] = { "NUM", ); this.setOutput(true, Types.NUMBER.typeName); - // Assign 'this' to a variable for use in the tooltip closure below. - var thisBlock = this; - // Number block is trivial. Use tooltip of parent block if it exists. - this.setTooltip(function () { - var parent = thisBlock.getParent(); - return ( - (parent && parent.getInputsInline() && parent.tooltip) || - Blockly.Msg.MATH_NUMBER_TOOLTIP - ); - }); + this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP); //update in generator }, }; @@ -64,19 +55,7 @@ Blockly.Blocks["math_arithmetic"] = { colour: getColour().math, helpUrl: Blockly.Msg.MATH_ARITHMETIC_HELPURL, }); - // Assign 'this' to a variable for use in the tooltip closure below. - var thisBlock = this; - this.setTooltip(function () { - var mode = thisBlock.getFieldValue("OP"); - var TOOLTIPS = { - ADD: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD, - MINUS: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS, - MULTIPLY: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY, - DIVIDE: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE, - POWER: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER, - }; - return TOOLTIPS[mode]; - }); + this.setTooltip(Blockly.Msg.MATH_ARITHMETIC_TOOLTIP); //update in generator }, //TODO: a getBlockType based on the two input types following C++ rules }; @@ -134,20 +113,7 @@ Blockly.Blocks["math_single"] = { output: Types.DECIMAL.typeName, colour: getColour().math, helpUrl: Blockly.Msg.MATH_SINGLE_HELPURL, - }); - // Assign 'this' to a variable for use in the tooltip closure below. - var thisBlock = this; - this.setTooltip(function () { - var mode = thisBlock.getFieldValue("OP"); - var TOOLTIPS = { - ROOT: Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT, - ABS: Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS, - LN: Blockly.Msg.MATH_SINGLE_TOOLTIP_LN, - LOG10: Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10, - EXP: Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP, - POW10: Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10, - }; - return TOOLTIPS[mode]; + tooltip: Blockly.Msg.MATH_SINGLE_TOOLTIP, // update in generator }); }, }; @@ -182,20 +148,7 @@ Blockly.Blocks["math_trig"] = { output: Types.DECIMAL.typeName, colour: getColour().math, helpUrl: Blockly.Msg.MATH_TRIG_HELPURL, - }); - // Assign 'this' to a variable for use in the tooltip closure below. - var thisBlock = this; - this.setTooltip(function () { - var mode = thisBlock.getFieldValue("OP"); - var TOOLTIPS = { - SIN: Blockly.Msg.MATH_TRIG_TOOLTIP_SIN, - COS: Blockly.Msg.MATH_TRIG_TOOLTIP_COS, - TAN: Blockly.Msg.MATH_TRIG_TOOLTIP_TAN, - ASIN: Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN, - ACOS: Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS, - ATAN: Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN, - }; - return TOOLTIPS[mode]; + tooltip: Blockly.Msg.MATH_TRIG_TOOLTIP, // update in generator }); }, }; @@ -259,6 +212,7 @@ Blockly.Blocks["math_number_property"] = { this.setOutput(true, Types.BOOLEAN.typeName); this.setTooltip(Blockly.Msg.MATH_IS_TOOLTIP); }, + /** * Create XML to represent whether the 'divisorInput' should be present. * @return {Element} XML storage element. @@ -313,8 +267,8 @@ Blockly.Blocks["math_change"] = { type: "field_dropdown", name: "DIRECTION", options: [ - [Blockly.Msg.MATH_CHANGE_UP, "+="], - [Blockly.Msg.MATH_CHANGE_DOWN, "-="], + [Blockly.Msg.MATH_CHANGE_INCREASE, "+="], + [Blockly.Msg.MATH_CHANGE_DECREASE, "-="], ], }, { @@ -337,12 +291,7 @@ Blockly.Blocks["math_change"] = { }); // Assign 'this' to a variable for use in the tooltip closure below. var thisBlock = this; - this.setTooltip(function () { - return Blockly.Msg.MATH_CHANGE_TOOLTIP.replace( - "%1", - thisBlock.getFieldValue("VAR"), - ); - }); + this.setTooltip(Blockly.Msg.MATH_CHANGE_TOOLTIP); // update in generator }, }; @@ -407,6 +356,7 @@ Blockly.Blocks["math_on_list"] = { .setCheck(Types.getCompatibleTypes("array")) .appendField(dropdown, "OP"); this.setTooltip(function () { + //TODO: move to generator and add a generic tooltip here when implementing in toolbox var mode = thisBlock.getFieldValue("OP"); var TOOLTIPS = { SUM: Blockly.Msg.MATH_ONLIST_TOOLTIP_SUM, diff --git a/src/components/Blockly/generator/math.js b/src/components/Blockly/generator/math.js index cc46d88c..c0f51b89 100644 --- a/src/components/Blockly/generator/math.js +++ b/src/components/Blockly/generator/math.js @@ -19,8 +19,15 @@ import * as Blockly from "blockly/core"; * @return {array} Completed code with order of operation. */ Blockly.Generator.Arduino.forBlock["math_number"] = function (block) { + // update tooltip in generator + // Number block is trivial. Use tooltip of parent block if it exists + var parent = block.getParent(); + block.setTooltip( + (parent && parent.getInputsInline() && parent.tooltip) || + Blockly.Msg.MATH_NUMBER_TOOLTIP, + ); var unparsedCode = block.getFieldValue("NUM"); - // understand decimal comma for german users (maybe add notification for educational purpose here) + // understand decimal comma for german users unparsedCode = unparsedCode.replace(",", "."); var code = parseFloat(unparsedCode); block.setFieldValue(code, "NUM"); @@ -47,6 +54,17 @@ Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function (block) { DIVIDE: [" / ", Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE], POWER: [" ^ ", Blockly.Generator.Arduino.ORDER_NONE], // Handle power separately. }; + // update tooltip in generator + // Assign 'this' to a variable for use in the tooltip closure below. + var mode = block.getFieldValue("OP"); + var TOOLTIPS = { + ADD: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD, + MINUS: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS, + MULTIPLY: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY, + DIVIDE: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE, + POWER: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER, + }; + block.setTooltip(TOOLTIPS[mode]); var tuple = OPERATORS[block.getFieldValue("OP")]; var operator = tuple[0]; var order = tuple[1]; @@ -62,121 +80,16 @@ Blockly.Generator.Arduino.forBlock["math_arithmetic"] = function (block) { } code = argument0 + operator + argument1; return [code, order]; -}; /** - * Generator for math operators that contain a single operand (X). - * Arduino code: loop { operator(X) } - * @param {!Blockly.Block} block Block to generate the code from. - * @return {array} Completed code with order of operation. - */ -Blockly.Generator.Arduino.forBlock["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.Generator.Arduino.valueToCode( - block, - "NUM", - Blockly.Generator.Arduino.ORDER_UNARY_PREFIX, - ) || "0"; - if (arg[0] === "-") { - // --3 is not legal in C++ in this context. - arg = " " + arg; - } - code = "-" + arg; - return [code, Blockly.Generator.Arduino.ORDER_UNARY_PREFIX]; - } - if (operator === "ABS" || operator.substring(0, 5) === "ROUND") { - arg = - Blockly.Generator.Arduino.valueToCode( - block, - "NUM", - Blockly.Generator.Arduino.ORDER_UNARY_POSTFIX, - ) || "0"; - } else if (operator === "SIN" || operator === "COS" || operator === "TAN") { - arg = - Blockly.Generator.Arduino.valueToCode( - block, - "NUM", - Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE, - ) || "0"; - } else { - arg = - Blockly.Generator.Arduino.valueToCode( - block, - "NUM", - Blockly.Generator.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.Generator.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.Generator.Arduino.ORDER_MULTIPLICATIVE]; }; /** - * Generator math negative operant -(X). + * Generator for math operator -(X). * Arduino code: loop { -(X) } * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino.forBlock["math_negative"] = function (block) { +Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { + var operator = block.getFieldValue("OP"); var code; var arg; // Negation is a special case given its different operator precedents. @@ -202,6 +115,25 @@ Blockly.Generator.Arduino.forBlock["math_negative"] = function (block) { */ Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { var operator = block.getFieldValue("OP"); + //update tooltip in generator + var TOOLTIPS = { + ROOT: Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT, + ABS: Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS, + LN: Blockly.Msg.MATH_SINGLE_TOOLTIP_LN, + LOG10: Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10, + EXP: Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP, + POW10: Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10, + SIN: Blockly.Msg.MATH_TRIG_TOOLTIP_SIN, + COS: Blockly.Msg.MATH_TRIG_TOOLTIP_COS, + TAN: Blockly.Msg.MATH_TRIG_TOOLTIP_TAN, + ASIN: Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN, + ACOS: Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS, + ATAN: Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN, + ROUND: Blockly.Msg.MATH_ROUND_TOOLTIP, + ROUNDUP: Blockly.Msg.MATH_ROUND_TOOLTIP, + ROUNDDOWN: Blockly.Msg.MATH_ROUND_TOOLTIP, + }; + block.setTooltip(TOOLTIPS[operator]); var code; var arg; if (operator === "ABS" || operator.substring(0, 5) === "ROUND") { @@ -253,13 +185,13 @@ Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { code = "floor(" + arg + ")"; break; case "SIN": - code = "sin(" + arg + " / 180 * Math.PI)"; + code = "sin(" + arg + " / 180 * M_PI)"; break; case "COS": - code = "cos(" + arg + " / 180 * Math.PI)"; + code = "cos(" + arg + " / 180 * M_PI)"; break; case "TAN": - code = "tan(" + arg + " / 180 * Math.PI)"; + code = "tan(" + arg + " / 180 * M_PI)"; break; default: break; @@ -287,6 +219,18 @@ Blockly.Generator.Arduino.forBlock["math_single"] = function (block) { return [code, Blockly.Generator.Arduino.ORDER_MULTIPLICATIVE]; }; +/** Negative sign is a single operand. */ +Blockly.Generator.Arduino.forBlock["math_negative"] = + Blockly.Generator.Arduino.forBlock["math_single"]; + +/** Rounding functions have a single operand. */ +Blockly.Generator.Arduino.forBlock["math_round"] = + Blockly.Generator.Arduino.forBlock["math_single"]; + +/** Trigonometry functions have a single operand. */ +Blockly.Generator.Arduino.forBlock["math_trig"] = + Blockly.Generator.Arduino.forBlock["math_single"]; + /** * Generator for math constants (PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), * INFINITY). @@ -402,21 +346,18 @@ Blockly.Generator.Arduino.forBlock["math_change"] = function (block) { Blockly.getMainWorkspace(), id, ).name; + var dropdown_direction = block.getFieldValue("DIRECTION"); + // update tooltip in generator + this.setTooltip( + Blockly.Msg.MATH_CHANGE_TOOLTIP_WITH_VARIABLE.replace("%1", varName), + ); // var varName = Blockly.Generator.Arduino.nameDB_.getName( // block.getFieldValue("VAR"), // Blockly.Variables.NAME_TYPE // ); - return varName + " += " + argument0 + ";\n"; + return `${varName} ${dropdown_direction} ${argument0};\n`; }; -/** Rounding functions have a single operand. */ -Blockly.Generator.Arduino["math_round"] = - Blockly.Generator.Arduino["math_single"]; - -/** Trigonometry functions have a single operand. */ -Blockly.Generator.Arduino["math_trig"] = - Blockly.Generator.Arduino["math_single"]; - /** * Generator for the math function to a list. * Arduino code: ??? @@ -424,7 +365,7 @@ Blockly.Generator.Arduino["math_trig"] = * @param {!Blockly.Block} block Block to generate the code from. * @return {array} Completed code with order of operation. */ -Blockly.Generator.Arduino["math_on_list"] = +Blockly.Generator.Arduino.forBlock["math_on_list"] = Blockly.Generator.Arduino.noGeneratorCodeInline; /** diff --git a/src/components/Blockly/generator/webserver.js b/src/components/Blockly/generator/webserver.js index 50b6dda1..4362fb66 100644 --- a/src/components/Blockly/generator/webserver.js +++ b/src/components/Blockly/generator/webserver.js @@ -155,7 +155,7 @@ Blockly.Generator.Arduino.forBlock["sensebox_web_readHTML"] = function ( Blockly.Generator.Arduino.codeFunctions_["define_sd" + filename] = "File webFile;"; Blockly.Generator.Arduino.setupCode_["sensebox_sd"] = "SD.begin(28);"; - Blockly.Generator.Arduino.codeFunctions_["generateHTML"] = + Blockly.Generator.Arduino.codeFunctions_["readHTML"] = `String readHTML(String filename){ webFile = SD.open(filename, FILE_READ); String finalString = ""; diff --git a/src/components/Blockly/msg/de/math.js b/src/components/Blockly/msg/de/math.js index d9a128d6..a9f724a6 100644 --- a/src/components/Blockly/msg/de/math.js +++ b/src/components/Blockly/msg/de/math.js @@ -1,6 +1,7 @@ export const MATH = { MATH_ADDITION_SYMBOL: "+", // untranslated MATH_ARITHMETIC_HELPURL: "https://de.wikipedia.org/wiki/Grundrechenart", + MATH_ARITHMETIC_TOOLTIP: "Operationen auf zwei Zahlen.", MATH_ARITHMETIC_TOOLTIP_ADD: "Ist die Summe zweier Werte.", MATH_ARITHMETIC_TOOLTIP_DIVIDE: "Ist der Quotient zweier Werte.", MATH_ARITHMETIC_TOOLTIP_MINUS: "Ist die Differenz zweier Werte.", @@ -9,9 +10,11 @@ export const MATH = { "Ist der erste Wert potenziert mit dem zweiten Wert.", MATH_CHANGE_HELPURL: "https://de.wikipedia.org/wiki/Inkrement_und_Dekrement", MATH_CHANGE_TITLE: "%1 %2 um %3", - MATH_CHANGE_UP: "erhöhe", - MATH_CHANGE_DOWN: "verringere", - MATH_CHANGE_TOOLTIP: 'Addiert/Subtraiert einen Wert zur/von Variable "%2".', + MATH_CHANGE_INCREASE: "erhöhe", + MATH_CHANGE_DECREASE: "verringere", + MATH_CHANGE_TOOLTIP: "Addiert/Subtraiert einen Wert zur/von einer Variable.", + MATH_CHANGE_TOOLTIP_WITH_VARIABLE: + 'Addiert/Subtraiert einen Wert zur/von Variable "%1".', MATH_CONSTANT_HELPURL: "https://de.wikipedia.org/wiki/Mathematische_Konstante", MATH_CONSTANT_TOOLTIP: @@ -36,17 +39,18 @@ export const MATH = { MATH_MODULO_TOOLTIP: "Der Rest nach einer Division.", MATH_MULTIPLICATION_SYMBOL: "×", MATH_NUMBER_HELPURL: "https://de.wikipedia.org/wiki/Zahl", - MATH_NUMBER_TOOLTIP: "Eine Zahl.", + MATH_NUMBER_TOOLTIP: + "Eine Zahl. Es kann sowohl eine ganze Zahl (0, -1, 4, ...) oder eine Kommerzahl (0.5, 3.14, ...) sein.", MATH_ONLIST_HELPURL: "http://www.sysplus.ch/einstieg.php?links:menu&seite:4125&grad:Crash&prog:Excel", - MATH_ONLIST_OPERATOR_AVERAGE: "Mittelwert einer Liste", - MATH_ONLIST_OPERATOR_MAX: "Maximalwert einer Liste", - MATH_ONLIST_OPERATOR_MEDIAN: "Median einer Liste", - MATH_ONLIST_OPERATOR_MIN: "Minimalwert einer Liste", - MATH_ONLIST_OPERATOR_MODE: "am häufigsten in Liste", - MATH_ONLIST_OPERATOR_RANDOM: "Zufallswert einer Liste", - MATH_ONLIST_OPERATOR_STD_DEV: "Standardabweichung einer Liste", - MATH_ONLIST_OPERATOR_SUM: "Summe einer Liste", + MATH_ONLIST_OPERATOR_AVERAGE: "Mittelwert einer Liste.", + MATH_ONLIST_OPERATOR_MAX: "Maximalwert einer Liste.", + MATH_ONLIST_OPERATOR_MEDIAN: "Median einer Liste.", + MATH_ONLIST_OPERATOR_MIN: "Minimalwert einer Liste.", + MATH_ONLIST_OPERATOR_MODE: "am häufigsten in Liste.", + MATH_ONLIST_OPERATOR_RANDOM: "Zufallswert einer Liste.", + MATH_ONLIST_OPERATOR_STD_DEV: "Standardabweichung einer Liste.", + MATH_ONLIST_OPERATOR_SUM: "Summe einer Liste.", MATH_ONLIST_TOOLTIP_AVERAGE: "Ist der Durchschnittswert aller Werte in einer Liste.", MATH_ONLIST_TOOLTIP_MAX: "Ist der größte Wert in einer Liste.", @@ -74,6 +78,7 @@ export const MATH = { MATH_ROUND_OPERATOR_ROUNDUP: "aufrunden", MATH_ROUND_TOOLTIP: "Eine Zahl auf- oder abrunden.", MATH_SINGLE_HELPURL: "https://de.wikipedia.org/wiki/Quadratwurzel", + MATH_SINGLE_TOOLTIP: "Operationen auf einer einzelnen Zahl.", MATH_SINGLE_OP_ABSOLUTE: "Absolutwert", MATH_SINGLE_OP_ROOT: "Quadratwurzel", MATH_SINGLE_TOOLTIP_ABS: "Ist der Absolutwert eines Wertes.", @@ -89,6 +94,7 @@ export const MATH = { MATH_TRIG_ATAN: "atan", MATH_TRIG_COS: "cos", MATH_TRIG_HELPURL: "https://de.wikipedia.org/wiki/Trigonometrie", + MATH_TRIG_TOOLTIP: "Trigonometrische Opreationen.", MATH_TRIG_SIN: "sin", MATH_TRIG_TAN: "tan", MATH_TRIG_TOOLTIP_ACOS: "Ist der Arkuskosinus des Eingabewertes.", diff --git a/src/components/Blockly/msg/en/math.js b/src/components/Blockly/msg/en/math.js index 05852f88..5f4bbcf8 100644 --- a/src/components/Blockly/msg/en/math.js +++ b/src/components/Blockly/msg/en/math.js @@ -1,6 +1,7 @@ export const MATH = { MATH_ADDITION_SYMBOL: "+", MATH_ARITHMETIC_HELPURL: "https://en.wikipedia.org/wiki/Arithmetic", + MATH_ARITHMETIC_TOOLTIP: "Arithmetic operations on two numbers.", MATH_ARITHMETIC_TOOLTIP_ADD: "Return the sum of the two numbers.", MATH_ARITHMETIC_TOOLTIP_DIVIDE: "Return the quotient of the two numbers.", MATH_ARITHMETIC_TOOLTIP_MINUS: "Return the difference of the two numbers.", @@ -10,9 +11,11 @@ export const MATH = { MATH_CHANGE_HELPURL: "https://en.wikipedia.org/wiki/Programming_idiom#Incrementing_a_counter", MATH_CHANGE_TITLE: "%1 %2 by %3", - MATH_CHANGE_UP: "increase", - MATH_CHANGE_DOWN: "decrease", - MATH_CHANGE_TOOLTIP: "Adds/Subtracts a number to/from the variable '%2'.", + MATH_CHANGE_INCREASE: "increase", + MATH_CHANGE_DECREASE: "decrease", + MATH_CHANGE_TOOLTIP: "Adds/Subtracts a number to/from a variable.", + MATH_CHANGE_TOOLTIP_WITH_VARIABLE: + "Adds/Subtracts a number to/from the variable '%1'.", MATH_CONSTANT_HELPURL: "https://en.wikipedia.org/wiki/Mathematical_constant", MATH_CONSTANT_TOOLTIP: "Return one of the common constants: π (3.141…), e (2.718…), φ (1.618…), sqrt(2) (1.414…), sqrt(½) (0.707…), or ∞ (infinity).", @@ -36,16 +39,17 @@ export const MATH = { MATH_MODULO_TOOLTIP: "Return the remainder from dividing the two numbers.", MATH_MULTIPLICATION_SYMBOL: "×", MATH_NUMBER_HELPURL: "https://en.wikipedia.org/wiki/Number", - MATH_NUMBER_TOOLTIP: "A number.", + MATH_NUMBER_TOOLTIP: + "A number. It can be a whole number (0, -1, 4, ...) or a decimal number (0.5, 3.14, ...).", MATH_ONLIST_HELPURL: "", - MATH_ONLIST_OPERATOR_AVERAGE: "average of list", - MATH_ONLIST_OPERATOR_MAX: "max of list", - MATH_ONLIST_OPERATOR_MEDIAN: "median of list", - MATH_ONLIST_OPERATOR_MIN: "min of list", - MATH_ONLIST_OPERATOR_MODE: "modes of list", - MATH_ONLIST_OPERATOR_RANDOM: "random item of list", - MATH_ONLIST_OPERATOR_STD_DEV: "standard deviation of list", - MATH_ONLIST_OPERATOR_SUM: "sum of list", + MATH_ONLIST_OPERATOR_AVERAGE: "average of list.", + MATH_ONLIST_OPERATOR_MAX: "max of list.", + MATH_ONLIST_OPERATOR_MEDIAN: "median of list.", + MATH_ONLIST_OPERATOR_MIN: "min of list.", + MATH_ONLIST_OPERATOR_MODE: "modes of list.", + MATH_ONLIST_OPERATOR_RANDOM: "random item of list.", + MATH_ONLIST_OPERATOR_STD_DEV: "standard deviation of list.", + MATH_ONLIST_OPERATOR_SUM: "sum of list.", MATH_ONLIST_TOOLTIP_AVERAGE: "Return the average (arithmetic mean) of the numeric values in the list.", MATH_ONLIST_TOOLTIP_MAX: "Return the largest number in the list.", @@ -73,6 +77,7 @@ export const MATH = { MATH_ROUND_OPERATOR_ROUNDUP: "round up", MATH_ROUND_TOOLTIP: "Round a number up or down.", MATH_SINGLE_HELPURL: "https://en.wikipedia.org/wiki/Square_root", + MATH_SINGLE_TOOLTIP: "Single operations on a number.", MATH_SINGLE_OP_ABSOLUTE: "absolute", MATH_SINGLE_OP_ROOT: "square root", MATH_SINGLE_TOOLTIP_ABS: "Return the absolute value of a number.", @@ -88,6 +93,7 @@ export const MATH = { MATH_TRIG_ATAN: "atan", MATH_TRIG_COS: "cos", MATH_TRIG_HELPURL: "https://en.wikipedia.org/wiki/Trigonometric_functions", + MATH_TRIG_TOOLTIP: "Trigonometric operations.", MATH_TRIG_SIN: "sin", MATH_TRIG_TAN: "tan", MATH_TRIG_TOOLTIP_ACOS: "Return the arccosine of a number.", diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 7f34f70c..4c3d4595 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -13,7 +13,7 @@ export const UI = { toolbox_functions: "Functions", toolbox_variables: "Variables", toolbox_serial: "Serial", - toolbox_advanced: "Erweitert", + toolbox_advanced: "Advanced", toolbox_motors: "Motors", toolbox_label_externalRTC: "External RTC", toolbox_label_internalRTC: "Internal RTC", diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 8f892728..eaf2d16e 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -193,7 +193,6 @@ class CodeViewer extends Component { CodeViewer.propTypes = { arduino: PropTypes.string.isRequired, xml: PropTypes.string.isRequired, - tooltip: PropTypes.string.isRequired, }; const mapStateToProps = (state) => ({ diff --git a/src/components/TooltipViewer.js b/src/components/TooltipViewer.js index 1bbb14f4..82df8ab9 100644 --- a/src/components/TooltipViewer.js +++ b/src/components/TooltipViewer.js @@ -126,8 +126,8 @@ class TooltipViewer extends Component { } TooltipViewer.propTypes = { - tooltip: PropTypes.string.isRequired, - helpurl: PropTypes.string.isRequired, + tooltip: PropTypes.string, + helpurl: PropTypes.string, }; const mapStateToProps = (state) => ({ From ae1116bd6c2f7aab20410e9ffba00f9119b16ca6 Mon Sep 17 00:00:00 2001 From: BjoernLuig Date: Mon, 6 Jan 2025 12:21:22 +0100 Subject: [PATCH 30/39] add note on workaraung with settooltip --- src/components/Blockly/blocks/math.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/Blockly/blocks/math.js b/src/components/Blockly/blocks/math.js index 42d2e1a2..124db6f8 100644 --- a/src/components/Blockly/blocks/math.js +++ b/src/components/Blockly/blocks/math.js @@ -2,6 +2,18 @@ import * as Blockly from "blockly/core"; import { getColour } from "../helpers/colour"; import * as Types from "../helpers/types"; +/* + * NOTE/TODO: + * Updating the tooltips in multiple of the following blocks should be done using the setTooltip() + * function with an update function as parameter as discripted in these docs + * https://developers.google.com/blockly/reference/js/blockly.field_class.settooltip_1_method?hl=de + * + * This does not work as described in this issue + * https://github.com/sensebox/React-Ardublockly/issues/381 + * + * Therefore the update is done for know in the generator functions as a workaround. + */ + Blockly.Blocks["math_number"] = { /** * Block for numeric value. From 73cbf25a249c6544b045a6fc9a921c24710bcada Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Fri, 10 Jan 2025 15:18:44 +0100 Subject: [PATCH 31/39] update hint box links --- .../Blockly/blocks/sensebox-display.js | 2 +- src/components/Blockly/blocks/sensebox-led.js | 23 ++++- .../Blockly/blocks/sensebox-osem.js | 2 +- .../Blockly/blocks/sensebox-sensors.js | 3 + .../Blockly/msg/de/sensebox-display.js | 1 + src/components/Blockly/msg/de/sensebox-led.js | 3 + .../Blockly/msg/de/sensebox-osem.js | 2 +- .../Blockly/msg/de/sensebox-sensors.js | 25 +++-- src/components/TooltipViewer.js | 91 +++++++------------ 9 files changed, 81 insertions(+), 71 deletions(-) diff --git a/src/components/Blockly/blocks/sensebox-display.js b/src/components/Blockly/blocks/sensebox-display.js index dc4b42de..b4916b4f 100644 --- a/src/components/Blockly/blocks/sensebox-display.js +++ b/src/components/Blockly/blocks/sensebox-display.js @@ -219,7 +219,7 @@ Blockly.Blocks["sensebox_display_show"] = { this.appendDummyInput().appendField(Blockly.Msg.sensebox_display_show); this.appendStatementInput("SHOW"); this.setTooltip(Blockly.Msg.sensebox_display_show_tip); - this.setHelpUrl(""); + this.setHelpUrl(Blockly.Msg.senseBox_display_helpurl); this.setPreviousStatement(true, null); this.setNextStatement(true, null); }, diff --git a/src/components/Blockly/blocks/sensebox-led.js b/src/components/Blockly/blocks/sensebox-led.js index 7be4a6a2..4968f3cb 100644 --- a/src/components/Blockly/blocks/sensebox-led.js +++ b/src/components/Blockly/blocks/sensebox-led.js @@ -97,6 +97,12 @@ Blockly.Blocks["sensebox_ws2818_led"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2818_rgb_led_tooltip); + if (selectedBoard().title === "MCU-S2") { + this.setHelpUrl(Blockly.Msg.senseBox_ws2818_rgb_led_helpurl); + } + else { + this.setHelpUrl(Blockly.Msg.senseBox_ws2818_rgb_led_helpurl_2); + } }, }; @@ -216,6 +222,7 @@ Blockly.Blocks["sensebox_ws2812_matrix_init"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_init_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); }, }; @@ -246,6 +253,9 @@ Blockly.Blocks["sensebox_ws2812_matrix_text"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_print_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + + }, }; @@ -274,6 +284,8 @@ Blockly.Blocks["sensebox_ws2812_matrix_drawPixel"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_draw_pixel_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + }, }; @@ -290,6 +302,8 @@ Blockly.Blocks["sensebox_ws2812_matrix_clear"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_clear_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + }, }; @@ -309,6 +323,8 @@ Blockly.Blocks["sensebox_ws2812_matrix_showBitmap"] = { this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_show_bitmap_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + }, }; @@ -332,6 +348,8 @@ Blockly.Blocks["sensebox_ws2812_matrix_bitmap"] = { ); this.setOutput(true, "Bitmap"); this.setTooltip(Blockly.Msg.senseBox_ws2812_rgb_matrix_bitmap_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + }, }; @@ -350,6 +368,8 @@ Blockly.Blocks["sensebox_ws2812_matrix_custom_bitmap"] = { this.setTooltip( Blockly.Msg.senseBox_ws2812_rgb_matrix_custom_bitmap_tooltip, ); + this.setHelpUrl(Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl); + }, }; @@ -867,6 +887,7 @@ Blockly.defineBlocksWithJsonArray([ output: "Bitmap", colour: getColour().sensebox, tooltip: Blockly.Msg.senseBox_ws2812_rgb_matrix_draw_bitmap_tooltip, - helpUrl: "", + helpUrl: Blockly.Msg.senseBox_ws2812_rgb_matrix_helpurl, + }, ]); diff --git a/src/components/Blockly/blocks/sensebox-osem.js b/src/components/Blockly/blocks/sensebox-osem.js index 8d08dbe3..1af023ab 100644 --- a/src/components/Blockly/blocks/sensebox-osem.js +++ b/src/components/Blockly/blocks/sensebox-osem.js @@ -127,7 +127,7 @@ Blockly.Blocks["sensebox_osem_connection"] = { Blockly.Blocks["sensebox_send_to_osem"] = { init: function () { this.setTooltip(Blockly.Msg.senseBox_send_to_osem_tip); - this.setHelpUrl(""); + this.setHelpUrl(Blockly.Msg.senseBox_osem_connection_helpurl); this.setColour(getColour().sensebox); this.appendDummyInput().appendField(Blockly.Msg.senseBox_send_to_osem); if (boxes) { diff --git a/src/components/Blockly/blocks/sensebox-sensors.js b/src/components/Blockly/blocks/sensebox-sensors.js index 64344a8e..8dba7655 100644 --- a/src/components/Blockly/blocks/sensebox-sensors.js +++ b/src/components/Blockly/blocks/sensebox-sensors.js @@ -329,6 +329,7 @@ Blockly.Blocks["sensebox_tof_imager"] = { .appendField(dropdown, "dropdown"); this.setOutput(true, Types.NUMBER.typeName); this.setTooltip(Blockly.Msg.sensebox_tof_imager_tooltip); + this.setHelpUrl(Blockly.Msg.sensebox_tof_imager_helpurl); this.getField("dropdown").setValidator( function (val) { this.updateShape_(val === "DistanzBM"); @@ -478,6 +479,7 @@ Blockly.Blocks["sensebox_gps"] = { this.setOutput(true, Types.NUMBER.typeName); this.setColour(getColour().sensebox); this.setTooltip(Blockly.Msg.senseBox_gps_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_gps_helpurl); }, }; @@ -702,6 +704,7 @@ Blockly.Blocks["sensebox_esp32s2_light"] = { this.setOutput(true, Types.DECIMAL.typeName); this.setColour(getColour().sensebox); this.setTooltip(Blockly.Msg.senseBox_esp32_photodiode_tooltip); + this.setHelpUrl(Blockly.Msg.senseBox_esp32_photodiode_helpurl); this.data = { name: "Photodiode" }; }, }; diff --git a/src/components/Blockly/msg/de/sensebox-display.js b/src/components/Blockly/msg/de/sensebox-display.js index b475aeb1..b7c756b4 100644 --- a/src/components/Blockly/msg/de/sensebox-display.js +++ b/src/components/Blockly/msg/de/sensebox-display.js @@ -8,6 +8,7 @@ export const DISPLAY = { **Anschluss:** I2C `, + senseBox_display_clearDisplay_tooltip: "Löscht die Anzeige auf dem Display. Sollte immer zu Begin oder am Ende der Endlosschleife aufgerufen werden.", senseBox_display_clearDisplay: "Display löschen", diff --git a/src/components/Blockly/msg/de/sensebox-led.js b/src/components/Blockly/msg/de/sensebox-led.js index 4c3a44f5..9b2091fe 100644 --- a/src/components/Blockly/msg/de/sensebox-led.js +++ b/src/components/Blockly/msg/de/sensebox-led.js @@ -10,6 +10,8 @@ export const LED = { senseBox_ws2818_rgb_led_init_tooltip: `Schließe die RGB-LED an einen der **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`, + senseBox_ws2818_rgb_led_helpurl: 'https://docs.sensebox.de/docs/hardware/accessoires/rgb-led-esp32', + senseBox_ws2818_rgb_led_helpurl_2: 'https://docs.sensebox.de/docs/hardware/accessoires/rgb-led', /** * Color @@ -75,4 +77,5 @@ export const LED = { `0x29B3, 0x74DA, 0x74DA, 0x74DA, 0x0000, 0x0000, 0x0000, 0xB5B6, 0x0000, 0x0000, 0x29B3, 0x29B3, 0x29B3, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels}`, senseBox_ws2812_rgb_matrix_draw_bitmap: `Male eine eigene Bitmap`, senseBox_ws2812_rgb_matrix_draw_bitmap_tooltip: `Wähle anzuzeigende Farben für die einzelnen Pixel aus.`, + senseBox_ws2812_rgb_matrix_helpurl: 'https://docs.sensebox.de/docs/hardware/accessoires/led-matrix', }; diff --git a/src/components/Blockly/msg/de/sensebox-osem.js b/src/components/Blockly/msg/de/sensebox-osem.js index 79f62a65..827861b9 100644 --- a/src/components/Blockly/msg/de/sensebox-osem.js +++ b/src/components/Blockly/msg/de/sensebox-osem.js @@ -4,7 +4,7 @@ export const OSEM = { */ senseBox_osem_connection_tip: "Verwende diesen Block, um deine senseBox mit der openSenseMap zu verbinden. Registriere deine senseBox auf der openSenseMap und trage die IDs und den API-Schlüssel ein. Verwende anschließend den Block ***Sende Messwert an die openSenseMap*** und die Sensor-ID, um die Messwerte zu übertragen.", - senseBox_osem_connection_helpurl: "https://www.opensensemap.org/", + senseBox_osem_connection_helpurl: "https://docs.sensebox.de/docs/editors/blockly/blocks/web/opensensemap", senseBox_send_to_osem_tip: "Sende mit diesem Block Messwerte an die openSenseMap. Verwende pro Messwert einen Block und trage die zugewiesene Sensor ID ein", senseBox_send_to_osem: "Sende Messwert an die openSenseMap", diff --git a/src/components/Blockly/msg/de/sensebox-sensors.js b/src/components/Blockly/msg/de/sensebox-sensors.js index de40b62f..50cd52c2 100644 --- a/src/components/Blockly/msg/de/sensebox-sensors.js +++ b/src/components/Blockly/msg/de/sensebox-sensors.js @@ -24,14 +24,14 @@ export const SENSORS = { senseBox_sensor_dps310: "Luftdruck-/Temperatursensor (DPS310)", senseBox_sensor_dps310_tooltip: "Schließe den Sensor an einen der **I2C-Anschlüsse** an. Der Sensor gibt dir den Messwert für den Luftdruck in hPa. Um die korrekte Höhe über NN zu berechnen benötigt der Sensor einen aktuellen Referenzwert.", - senseBox_sensor_dps310_helpurl: "", + senseBox_sensor_dps310_helpurl: "https://docs.sensebox.de/docs/hardware/sensors/luftdruck-temperatur", /** * Mikro */ senseBox_sound: "Mikrofon", - senseBox_sound_tip: - "Schließe den Sensor über das Breadbord an einen der **analog/digital** Ports an. Gibt den Messwert des Mikrofons in Volt zurück", + senseBox_sound_tooltip: + "Schließe den Sensor über das Breadbord an einen der **Analog/Digital** Ports an. Gibt den Messwert des Mikrofons in Volt zurück", senseBox_sound_helpurl: "https://docs.sensebox.de/hardware/sensoren-mikro/", /** @@ -116,7 +116,7 @@ Wenn die maximale Distanz überschritten wird, wird ein Wert von **O** ausgegebe **Beachte:** Das GPS Modul benöigt beim ersten Verwenden relativ lange (ca. 5-10 Minuten) bis es deinen Standort gefunden hat! `, - senseBox_gps_helpurl: "https://docs.sensebox.de/hardware/sensoren-gps/", + senseBox_gps_helpurl: "https://docs.sensebox.de/docs/hardware/accessoires/gps/", /** * Windspeed @@ -129,7 +129,7 @@ Wenn die maximale Distanz überschritten wird, wird ein Wert von **O** ausgegebe */ senseBox_soundsensor_dfrobot: "Soundsensor (DF Robot)", senseBox_soundsensor_dfrobot_tooltip: - "Schließe den Sensor an einen der **digital/analog Ports** an. Der Sensor gibt dir den Messwert in dB mit einer Nachkommastelle", + "Schließe den Sensor an einen der **Digital/Analog Ports** an. Der Sensor gibt dir den Messwert in dB mit einer Nachkommastelle", senseBox_soundsensor_dfrobot_helpurl: "https://docs.sensebox.de/hardware/sensoren-lautstaerke/", /* @@ -185,7 +185,7 @@ Die Messwerte für Temperatur, Luftfeuchtigkeit und Luftdruck können direkt ver senseBox_sds011_serial1: "Serial1", senseBox_sds011_serial2: "Serial2", senseBox_sds011_helpurl: - "https://docs.sensebox.de/hardware/sensoren-feinstaub/", + "https://docs.sensebox.de/docs/hardware/sensors/feinstaub-sds011/", /** * Button @@ -215,7 +215,7 @@ Die Messwerte für Temperatur, Luftfeuchtigkeit und Luftdruck können direkt ver senseBox_sps30_tooltip: "Dieser Block gibt dir den Messwert des Sensirion SPS30 Feinstaubsensor. Schließe den Feinstaubsensor an einen der **I2C** Anschlüssen an. Im Dropdown Menü zwischen PM1.0, PM2.5, PM4.0 und PM10 auswählen. Der Messwert wird dir als **Kommazahl** in µg/m3", senseBox_sps30_helpurl: - "https://docs.sensebox.de/hardware/sensoren-feinstaub/", + "https://docs.sensebox.de/docs/hardware/sensors/feinstaub-sps30/", /** * Photodiode MCUS2(ESP32) @@ -224,8 +224,16 @@ Die Messwerte für Temperatur, Luftfeuchtigkeit und Luftdruck können direkt ver senseBox_esp32_photodiode: "Lichtintensität", senseBox_esp32_photodiode_tooltip: "Die Photodiode misst Lichtintensität. Der ausgegebene Wert ist eine **Ganzzahl** zwischen 0 und 4095. Je höher der Wert, desto heller ist die Umgebung.", - + senseBox_esp32_photodiode_helpurl:"https://docs.sensebox.de/docs/hardware/sensors/photodiode", + /** + * MPU6050 */ + senseBox_mpu6050_tooltip: "Der MPU6050 ist ein Beschleunigungs- und Gyroskopsensor. Schließe den Sensor an einen der I2C Anschlüsse an. Der Sensor gibt dir die Beschleunigung in m/s² und die Winkelgeschwindigkeit in °/s zurück.", + senseBox_mpu6050_helpurl:"https://docs.sensebox.de/docs/hardware/sensors/mpu6050/", + + + + /** * ToF Imager * */ @@ -236,4 +244,5 @@ Die Messwerte für Temperatur, Luftfeuchtigkeit und Luftdruck können direkt ver sensebox_distance_bitmap: "8x8 Distanzen als Bitmap (für LED-Matrix)", sensebox_tof_imager_max_distance: "Maximal messbare Distanz ", sensebox_tof_imager_max_distance_unit: "cm", + sensebox_tof_imager_helpurl: "https://docs.sensebox.de/docs/hardware/sensors/tof", }; diff --git a/src/components/TooltipViewer.js b/src/components/TooltipViewer.js index 43fc80c7..1cbdfb2c 100644 --- a/src/components/TooltipViewer.js +++ b/src/components/TooltipViewer.js @@ -42,66 +42,39 @@ class TooltipViewer extends Component { render() { return ( - - - {Blockly.Msg.tooltip_viewer} - - - - - {this.props.tooltip} - - {store.getState().workspace.code.data ? ( - - ) : ( - {`${Blockly.Msg.tooltip_moreInformation} [${Blockly.Msg.labels_here}](${this.props.helpurl})`} - )} - - - {store.getState().workspace.code.data ? ( - { - this.toggleDialog(); - }} - maxWidth={"md"} - fullWidth={true} - > - - - - - - - - ) : null} + + + Sensor Informationen + + + {this.props.tooltip} + + {this.props.helpurl && ( + + )} + ); } From f558e20fd2b854d4479f6e328fe3859733fce3ba Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Fri, 10 Jan 2025 16:06:10 +0100 Subject: [PATCH 32/39] fixed hitn button and styled a bit --- src/components/Blockly/msg/de/ui.js | 1 + src/components/CodeViewer.js | 2 +- src/components/TooltipViewer.js | 34 +++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 1181491f..3178d70d 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -323,6 +323,7 @@ export const UI = { tooltip_viewer: "Hilfe", tooltip_moreInformation: "Mehr Informationen findest du ", + tooltip_moreInformation_02: "Informationem zum Block", tooltip_hint: "Wähle einen Block aus um dir die Hilfe anzeigen zu lassen", /** diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 8f892728..f2ec06b5 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -108,7 +108,7 @@ class CodeViewer extends Component { var curlyBrackets = "{ }"; var unequal = "<>"; return ( - + { @@ -44,18 +45,43 @@ class TooltipViewer extends Component { - - Sensor Informationen - + + + {Blockly.Msg.tooltip_moreInformation_02} + + + {this.props.tooltip} From 9dbc49204dc20207c5d8cb9586bb7c05a336b38d Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Fri, 10 Jan 2025 16:10:28 +0100 Subject: [PATCH 33/39] fix error raised by #368 --- src/components/Blockly/generator/sensebox-sensors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Blockly/generator/sensebox-sensors.js b/src/components/Blockly/generator/sensebox-sensors.js index 1b81967f..0e70a29d 100644 --- a/src/components/Blockly/generator/sensebox-sensors.js +++ b/src/components/Blockly/generator/sensebox-sensors.js @@ -889,8 +889,8 @@ Blockly.Generator.Arduino.forBlock["sensebox_soundsensor_dfrobot"] = var board = selectedBoard().title; if (board === "MCU" || board === "Mini") { Blockly.Generator.Arduino.codeFunctions_["soundsensor"] = ` - int getSoundValue(int sensorPin) { - float v = analogRead(sensorPin) / 1000.0; + int getSoundValue(int sensorPin) { + float v = analogRead(sensorPin) * (3.3 / 1024.0); float decibel; if (v <= 0.6) decibel = 0.0; if (v >= 2.6) decibel = 130.0; From 927f0f1ec6e5d0ecee8cea2416dbc893c0a945cf Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Fri, 10 Jan 2025 16:43:12 +0100 Subject: [PATCH 34/39] make compiler interchangable, closes #357 --- .env | 1 - src/App.js | 3 + src/components/Blockly/msg/de/ui.js | 1 + src/components/Blockly/msg/en/ui.js | 1 + src/components/CodeEditor/CodeEditor.js | 4 +- src/components/Settings/CompilerSelector.js | 67 ++++++++++++--------- src/reducers/generalReducer.js | 2 +- 7 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.env b/.env index 044e0614..45fa416d 100644 --- a/.env +++ b/.env @@ -1,4 +1,3 @@ -REACT_APP_COMPILER_URL=https://compiler.sensebox.de REACT_APP_BOARD=sensebox-mcu REACT_APP_BLOCKLY_API=https://api.blockly.sensebox.de diff --git a/src/App.js b/src/App.js index 75180956..b47cc24b 100644 --- a/src/App.js +++ b/src/App.js @@ -17,6 +17,7 @@ import { } from "@mui/material/styles"; import Content from "./components/Content"; +import { setCompiler } from "./actions/generalActions"; const theme = createTheme({ palette: { @@ -36,6 +37,8 @@ const theme = createTheme({ class App extends Component { componentDidMount() { store.dispatch(loadUser()); + // set initial compiler + store.dispatch(setCompiler("https://compiler.sensebox.de")); } render() { diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 2ea0feeb..055432d4 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -222,6 +222,7 @@ export const UI = { "Geben die URL des Compilers ein, den du verwenden möchten. Die Standard-URL ist: https://compiler.sensebox.de", settings_compiler_helperText: "Die URL muss mit https:// oder http:// beginnen", + settings_compiler_readOnly: "Compiler URL ändern", /** * 404 diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 4c3d4595..8453de31 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -215,6 +215,7 @@ export const UI = { settings_compiler_text: "Enter the URL of the compiler you want to use. The default compiler is: https://compiler.sensebox.de", settings_compiler_helperText: "Die URL must start https:// or http://", + settings_compiler_readOnly: "Change compiler URL", /** * 404 diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index cc743e6f..3d658b50 100644 --- a/src/components/CodeEditor/CodeEditor.js +++ b/src/components/CodeEditor/CodeEditor.js @@ -36,7 +36,7 @@ const CodeEditor = (props) => { : "sensebox-esp32s2", sketch: editorRef.current.getValue(), }; - fetch(`${process.env.REACT_APP_COMPILER_URL}/compile`, { + fetch(`${this.props.selectedCompiler}/compile`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), @@ -53,7 +53,7 @@ const CodeEditor = (props) => { //setId(result); const filename = "sketch"; window.open( - `${process.env.REACT_APP_COMPILER_URL}/download?id=${result}&board=${ + `${this.props.selectedCompiler}/download?id=${result}&board=${ store.getState().board.board === "mcu" ? "sensebox-mcu" : "sensebox-esp32s2" diff --git a/src/components/Settings/CompilerSelector.js b/src/components/Settings/CompilerSelector.js index fc0f1fe9..1a600105 100644 --- a/src/components/Settings/CompilerSelector.js +++ b/src/components/Settings/CompilerSelector.js @@ -24,8 +24,10 @@ class CompilerSelector extends Component { // Ensure that Blockly.setLocale is adopted in the component. // Otherwise, the text will not be displayed until the next update of the component. this.forceUpdate(); + } + changeStatus = () => { this.setState({ readOnly: !this.state.readOnly }); }; @@ -33,36 +35,41 @@ class CompilerSelector extends Component { render() { return (
- - {Blockly.Msg.settings_compiler} - - - {Blockly.Msg.settings_compiler_text} - - - this.props.setCompiler(e.target.value)} - value={this.props.selectedCompiler} - InputProps={{ - readOnly: !this.state.readOnly, - }} - /> - } - checked={this.state.readOnly} - onChange={this.changeStatus} - label="Change URL" - /> - + + {Blockly.Msg.settings_compiler} + + + {Blockly.Msg.settings_compiler_text} + + + } + checked={this.state.readOnly} + onChange={this.changeStatus} + label={Blockly.Msg.settings_compiler_readOnly} + /> + this.props.setCompiler(e.target.value)} + value={this.props.selectedCompiler} + InputProps={{ + readOnly: !this.state.readOnly, + }} + style={{ + backgroundColor: !this.state.readOnly ? "#f0f0f0" : "white", + color: this.state.readOnly ? "gray" : "black", + borderRadius: "5px", + }} + /> +
); } diff --git a/src/reducers/generalReducer.js b/src/reducers/generalReducer.js index 6418322d..5e5fdfe2 100644 --- a/src/reducers/generalReducer.js +++ b/src/reducers/generalReducer.js @@ -23,7 +23,7 @@ const initialPlatform = () => { }; const initialCompiler = () => { - return process.env.REACT_APP_COMPILER_URL; + return "https://compiler.sensebox.de"; }; const initialSounds = () => { From 9a1243d201f613ac7fd72e3539f64bc8b29ad105 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Fri, 10 Jan 2025 16:47:19 +0100 Subject: [PATCH 35/39] initial compiler as env variable --- .env | 1 + src/App.js | 2 +- src/reducers/generalReducer.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 45fa416d..9f2396d5 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ +INITIAL_COMPILER_URL=https://compiler.sensebox.de REACT_APP_BOARD=sensebox-mcu REACT_APP_BLOCKLY_API=https://api.blockly.sensebox.de diff --git a/src/App.js b/src/App.js index b47cc24b..4e506864 100644 --- a/src/App.js +++ b/src/App.js @@ -38,7 +38,7 @@ class App extends Component { componentDidMount() { store.dispatch(loadUser()); // set initial compiler - store.dispatch(setCompiler("https://compiler.sensebox.de")); + store.dispatch(setCompiler(process.env.INITIAL_COMPILER_URL)); } render() { diff --git a/src/reducers/generalReducer.js b/src/reducers/generalReducer.js index 5e5fdfe2..cddc38ae 100644 --- a/src/reducers/generalReducer.js +++ b/src/reducers/generalReducer.js @@ -23,7 +23,7 @@ const initialPlatform = () => { }; const initialCompiler = () => { - return "https://compiler.sensebox.de"; + return process.env.INITIAL_COMPILER_URL; }; const initialSounds = () => { From 028d3e2e204c4f618e8a515073efa9e5c3f9aab4 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Tue, 21 Jan 2025 11:57:08 +0100 Subject: [PATCH 36/39] translation fixes --- src/components/Blockly/msg/de/ui.js | 2 +- src/components/Blockly/msg/en/ui.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 82ee37e4..81a8bc16 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -322,7 +322,7 @@ export const UI = { */ tooltip_viewer: "Hilfe", - tooltip_moreInformation_02: "Informationem zum Block", + tooltip_moreInformation_02: "Informationen zum Block", tooltip_moreInformation: "Mehr Informationen", tooltip_hint: "Wähle einen Block aus um dir die Hilfe anzeigen zu lassen", diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 4c3d4595..336ddddc 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -317,6 +317,7 @@ export const UI = { tooltip_viewer: "Help", tooltip_moreInformation: "More information", + tooltip_moreInformation_02: "Information about the Block", tooltip_hint: "Select a Block to show the hint", /** From 926205d944eacfd6c8c507a9ed06d489971c6ad2 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Tue, 21 Jan 2025 12:50:10 +0100 Subject: [PATCH 37/39] adjust border radius and background --- src/components/TooltipViewer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/TooltipViewer.js b/src/components/TooltipViewer.js index bf1fdfa5..28a81e07 100644 --- a/src/components/TooltipViewer.js +++ b/src/components/TooltipViewer.js @@ -49,8 +49,7 @@ class TooltipViewer extends Component { overflowY: "scroll", marginTop: "1vh", padding: "1rem", - backgroundColor: "#f9f9f9", - borderRadius: "10px", + borderRadius: "4px", border: "1px solid #ddd", boxShadow: "0px 4px 6px rgba(0, 0, 0, 0.1)", }} From 92973bf39c76590407ab1d5c7965e06c480248a5 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Tue, 21 Jan 2025 12:51:17 +0100 Subject: [PATCH 38/39] slightly adjust padding --- src/components/TooltipViewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TooltipViewer.js b/src/components/TooltipViewer.js index 28a81e07..92fd7258 100644 --- a/src/components/TooltipViewer.js +++ b/src/components/TooltipViewer.js @@ -48,7 +48,7 @@ class TooltipViewer extends Component { height: "25vh", overflowY: "scroll", marginTop: "1vh", - padding: "1rem", + padding: "1.1rem", borderRadius: "4px", border: "1px solid #ddd", boxShadow: "0px 4px 6px rgba(0, 0, 0, 0.1)", From 3962f8cb2bf2a869b4b550b1577cbd9df1357404 Mon Sep 17 00:00:00 2001 From: Eric Thieme-Garmann Date: Tue, 21 Jan 2025 13:03:28 +0100 Subject: [PATCH 39/39] rename env variable --- .env | 2 +- src/App.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 9f2396d5..abf2849a 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -INITIAL_COMPILER_URL=https://compiler.sensebox.de +REACT_APP_INITIAL_COMPILER_URL=https://compiler.sensebox.de REACT_APP_BOARD=sensebox-mcu REACT_APP_BLOCKLY_API=https://api.blockly.sensebox.de diff --git a/src/App.js b/src/App.js index 4e506864..298c99d6 100644 --- a/src/App.js +++ b/src/App.js @@ -38,7 +38,8 @@ class App extends Component { componentDidMount() { store.dispatch(loadUser()); // set initial compiler - store.dispatch(setCompiler(process.env.INITIAL_COMPILER_URL)); + console.log("compiler", process.env.REACT_APP_INITIAL_COMPILER_URL) + store.dispatch(setCompiler(process.env.REACT_APP_INITIAL_COMPILER_URL)); } render() {