From 89941e27f1fe072ff282ea32d254613c23368709 Mon Sep 17 00:00:00 2001 From: sverben <59171289+sverben@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:32:46 +0100 Subject: [PATCH 1/3] Feat: add blocks for serial write --- blocks/leaphy_common.js | 16 ++++++++++++++++ generators/arduino/leaphy_common.js | 12 ++++++++++++ msg/js/en.js | 2 ++ msg/js/nl.js | 2 ++ msg/json/en.json | 2 ++ msg/json/nl.json | 2 ++ msg/messages.js | 6 ++++++ 7 files changed, 42 insertions(+) diff --git a/blocks/leaphy_common.js b/blocks/leaphy_common.js index 358627b..bf6c3cc 100644 --- a/blocks/leaphy_common.js +++ b/blocks/leaphy_common.js @@ -92,6 +92,22 @@ function getBlocks(board) { tooltip: "", helpUrl: "", }, + { + type: "leaphy_serial_available", + message0: "%%{BKY_LEAPHY_SERIAL_AVAILABLE}", + style: "leaphy_blocks", + output: "Number", + tooltip: "", + helpUrl: "", + }, + { + type: "leaphy_serial_read_line", + message0: "%%{BKY_LEAPHY_SERIAL_READ_LINE}", + style: "leaphy_blocks", + output: "String", + tooltip: "", + helpUrl: "", + }, { type: "leaphy_rgb_color", message0: "%1", diff --git a/generators/arduino/leaphy_common.js b/generators/arduino/leaphy_common.js index d249846..204e1a2 100644 --- a/generators/arduino/leaphy_common.js +++ b/generators/arduino/leaphy_common.js @@ -25,6 +25,18 @@ function getCodeGenerators(Arduino) { return null; }; + Arduino.forBlock["leaphy_serial_available"] = function (block) { + Arduino.addSetup("serial", "Serial.begin(115200);", false); + var code = "Serial.available()"; + return [code, Arduino.ORDER_ATOMIC]; + } + + Arduino.forBlock["leaphy_serial_read_line"] = function (block) { + Arduino.addSetup("serial", "Serial.begin(115200);", false); + var code = "Serial.readStringUntil('\\n')"; + return [code, Arduino.ORDER_ATOMIC]; + } + Arduino.forBlock["leaphy_serial_print_line"] = function (block) { Arduino.addSetup("serial", "Serial.begin(115200);", false); var value = Arduino.valueToCode(this, "VALUE", Arduino.ORDER_ATOMIC) || "0"; diff --git a/msg/js/en.js b/msg/js/en.js index 7609d78..9468043 100644 --- a/msg/js/en.js +++ b/msg/js/en.js @@ -152,6 +152,8 @@ Blockly.Msg["LEAPHY_RGB_RAW_COLOR_GREEN"] = "RawColor Green"; Blockly.Msg["LEAPHY_RGB_RAW_COLOR_RED"] = "RawColor Red"; Blockly.Msg["LEAPHY_RGB_READ_SENSOR"] = "Read RGB sensor"; Blockly.Msg["LEAPHY_SERIAL_PRINT"] = "Show on screen"; +Blockly.Msg["LEAPHY_SERIAL_AVAILABLE"] = "Available on screen"; +Blockly.Msg["LEAPHY_SERIAL_READ_LINE"] = "Read from screen"; Blockly.Msg["LEAPHY_SITUATION_CATEGORY"] = "Thinkflow"; Blockly.Msg["LEAPHY_SONAR_READ_ECHO"] = "Echo"; Blockly.Msg["LEAPHY_SONAR_READ_TRIG"] = "Sonar Trig"; diff --git a/msg/js/nl.js b/msg/js/nl.js index ff24621..f3c0197 100644 --- a/msg/js/nl.js +++ b/msg/js/nl.js @@ -150,6 +150,8 @@ Blockly.Msg["LEAPHY_RGB_RAW_COLOR_GREEN"] = "G-bron"; Blockly.Msg["LEAPHY_RGB_RAW_COLOR_RED"] = "R-bron"; Blockly.Msg["LEAPHY_RGB_READ_SENSOR"] = "Lees RGB Sensor"; Blockly.Msg["LEAPHY_SERIAL_PRINT"] = "Toon op scherm"; +Blockly.Msg["LEAPHY_SERIAL_AVAILABLE"] = "Beschikbaar op scherm"; +Blockly.Msg["LEAPHY_SERIAL_READ_LINE"] = "Lees van scherm"; Blockly.Msg["LEAPHY_SITUATION_CATEGORY"] = "Denk stappen"; Blockly.Msg["LEAPHY_SONAR_READ_ECHO"] = "Echo"; // untranslated Blockly.Msg["LEAPHY_SONAR_READ_TRIG"] = "Sonar Trig"; // untranslated diff --git a/msg/json/en.json b/msg/json/en.json index 5b40406..e9de017 100644 --- a/msg/json/en.json +++ b/msg/json/en.json @@ -77,6 +77,8 @@ "LEAPHY_BUZZ_HERTZ": "Hertz", "LEAPHY_BUZZ_MS": "ms", "LEAPHY_SERIAL_PRINT": "Show on screen", + "LEAPHY_SERIAL_AVAILABLE": "Available on screen", + "LEAPHY_SERIAL_READ_LINE": "Read from screen", "LEAPHY_DISPLAY_CLEAR": "Clear display", "LEAPHY_DISPLAY_PRINT": "Display - Set Ln.", "LEAPHY_DISPLAY_DISPLAY": "Show on display", diff --git a/msg/json/nl.json b/msg/json/nl.json index cb607da..4fdc0ea 100644 --- a/msg/json/nl.json +++ b/msg/json/nl.json @@ -69,6 +69,8 @@ "LEAPHY_VARIABLES_CATEGORY": "Variabelen", "LEAPHY_FUNCTIONS_CATEGORY": "Eigen blokken", "LEAPHY_SERIAL_PRINT": "Toon op scherm", + "LEAPHY_SERIAL_AVAILABLE": "Beschikbaar op scherm", + "LEAPHY_SERIAL_READ_LINE": "Lees van scherm", "LEAPHY_DISPLAY_CLEAR": "Maak display leeg", "LEAPHY_DISPLAY_PRINT": "Stel display in - Rg.", "LEAPHY_DISPLAY_DISPLAY": "Toon op display", diff --git a/msg/messages.js b/msg/messages.js index f548a45..d2110bb 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -209,6 +209,12 @@ Blockly.Msg.LEAPHY_BUZZ_MS = 'ms'; /// Print print Blockly.Msg.LEAPHY_SERIAL_PRINT = 'Show on screen'; /** @type {string} */ +/// Serial available +Blockly.Msg.LEAPHY_SERIAL_AVAILABLE = "Available on screen"; +/** @type {string} */ +/// Serial read +Blockly.Msg.LEAPHY_SERIAL_READ_LINE = "Read from screen"; +/** @type {string} */ /// Clear display Blockly.Msg.LEAPHY_DISPLAY_CLEAR = 'Clear display'; /** @type {string} */ From 06994cc6dabcffdcd497291bcec0fd39d555160c Mon Sep 17 00:00:00 2001 From: Ronald Moesbergen Date: Sun, 28 Jan 2024 13:51:40 +0100 Subject: [PATCH 2/3] chore: prettier --- generators/arduino/leaphy_common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/arduino/leaphy_common.js b/generators/arduino/leaphy_common.js index 204e1a2..ae962fd 100644 --- a/generators/arduino/leaphy_common.js +++ b/generators/arduino/leaphy_common.js @@ -29,13 +29,13 @@ function getCodeGenerators(Arduino) { Arduino.addSetup("serial", "Serial.begin(115200);", false); var code = "Serial.available()"; return [code, Arduino.ORDER_ATOMIC]; - } + }; Arduino.forBlock["leaphy_serial_read_line"] = function (block) { Arduino.addSetup("serial", "Serial.begin(115200);", false); var code = "Serial.readStringUntil('\\n')"; return [code, Arduino.ORDER_ATOMIC]; - } + }; Arduino.forBlock["leaphy_serial_print_line"] = function (block) { Arduino.addSetup("serial", "Serial.begin(115200);", false); From 2b620839b6b64ca97832778025b2e2acd165ad76 Mon Sep 17 00:00:00 2001 From: sverben <59171289+sverben@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:11:28 +0100 Subject: [PATCH 3/3] Chore: bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bdbb457..f8cac88 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "msg", "theme" ], - "version": "1.7.1", + "version": "1.8.0", "description": "Leaphy custom Blockly blocks and arduino code generator", "name": "@leaphy-robotics/leaphy-blocks" }