Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add blocks for serial read #41

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions blocks/leaphy_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions generators/arduino/leaphy_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions msg/js/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions msg/js/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions msg/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions msg/json/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions msg/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading