From 76af24626cbf714f7e6f4aa45f755ea176a0e455 Mon Sep 17 00:00:00 2001 From: Ronald Moesbergen Date: Tue, 7 Nov 2023 20:15:34 +0100 Subject: [PATCH] feat: add leaphy_compass_degrees block --- blocks/leaphy_common.js | 8 ++++++++ generators/arduino/leaphy_common.js | 12 ++++++++++++ msg/js/en.js | 1 + msg/js/nl.js | 1 + msg/json/en.json | 1 + msg/json/nl.json | 1 + package.json | 2 +- 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/blocks/leaphy_common.js b/blocks/leaphy_common.js index 34b0e19..6225698 100644 --- a/blocks/leaphy_common.js +++ b/blocks/leaphy_common.js @@ -393,6 +393,14 @@ function getBlocks(board) { tooltip: "", helpUrl: "", }, + { + type: "leaphy_compass_degrees", + message0: "%%{BKY_LEAPHY_COMPASS}", + style: "leaphy_blocks", + output: "Number", + tooltip: "", + helpUrl: "", + }, ]; return blocks; } diff --git a/generators/arduino/leaphy_common.js b/generators/arduino/leaphy_common.js index 24a72eb..50604e6 100644 --- a/generators/arduino/leaphy_common.js +++ b/generators/arduino/leaphy_common.js @@ -44,6 +44,18 @@ function getCodeGenerators(Arduino) { ");\n"; return code; }; + + Arduino.forBlock["leaphy_compass_degrees"] = function (block) { + Arduino.addInclude("leaphy_compass", "#include "); + Arduino.addDeclaration("leaphy_compass", "QMC5883LCompass compass;"); + Arduino.addDeclaration( + "leaphy_compass_read", + "int getCompassDegrees() {\n compass.read();\n int azimuth = compass.getAzimuth();\n return compass.getBearing(azimuth) * 24;\n}\n", + ); + Arduino.addSetup("leaphy_compass", "compass.init();"); + var code = "getCompassDegrees()"; + return [code, Arduino.ORDER_ATOMIC]; + }; } export default getCodeGenerators; diff --git a/msg/js/en.js b/msg/js/en.js index a30c6a0..3647388 100644 --- a/msg/js/en.js +++ b/msg/js/en.js @@ -95,6 +95,7 @@ Blockly.Msg["LEAPHY_BUZZ_BUZZ"] = "Buzz"; Blockly.Msg["LEAPHY_BUZZ_HERTZ"] = "Hertz"; Blockly.Msg["LEAPHY_BUZZ_MS"] = "ms"; Blockly.Msg["LEAPHY_CLICK_CATEGORY"] = "Leaphy Click"; +Blockly.Msg["LEAPHY_COMPASS"] = "Read compass"; Blockly.Msg["LEAPHY_DIGITAL_READ"] = "Read digipin"; Blockly.Msg["LEAPHY_DISPLAY_CLEAR"] = "Clear display"; Blockly.Msg["LEAPHY_DISPLAY_DISPLAY"] = "Show on display"; diff --git a/msg/js/nl.js b/msg/js/nl.js index 9159948..0c8eea8 100644 --- a/msg/js/nl.js +++ b/msg/js/nl.js @@ -93,6 +93,7 @@ Blockly.Msg["LEAPHY_BUZZ_BUZZ"] = "Buzz"; // untranslated Blockly.Msg["LEAPHY_BUZZ_HERTZ"] = "Hertz"; // untranslated Blockly.Msg["LEAPHY_BUZZ_MS"] = "ms"; // untranslated Blockly.Msg["LEAPHY_CLICK_CATEGORY"] = "Leaphy Click"; // untranslated +Blockly.Msg["LEAPHY_COMPASS"] = "Lees kompas"; Blockly.Msg["LEAPHY_DIGITAL_READ"] = "Lees digipin"; Blockly.Msg["LEAPHY_DISPLAY_CLEAR"] = "Maak display leeg"; Blockly.Msg["LEAPHY_DISPLAY_DISPLAY"] = "Toon op display"; diff --git a/msg/json/en.json b/msg/json/en.json index 6065690..518f529 100644 --- a/msg/json/en.json +++ b/msg/json/en.json @@ -8,6 +8,7 @@ "LEAPHY_START": "Leaphy", "LEAPHY_ORIGINAL_CATEGORY": "Leaphy Original", "LEAPHY_CLICK_CATEGORY": "Leaphy Click", + "LEAPHY_COMPASS": "Read compass", "LEAPHY_FLITZ_CATEGORY": "Leaphy Flitz", "LEAPHY_UNO_CATEGORY": "Arduino Uno", "LEAPHY_EXTRA_CATEGORY": "Leaphy Extra", diff --git a/msg/json/nl.json b/msg/json/nl.json index 80834b9..5f0e1bf 100644 --- a/msg/json/nl.json +++ b/msg/json/nl.json @@ -19,6 +19,7 @@ "아라" ] }, + "LEAPHY_COMPASS": "Lees kompas", "LEAPHY_MOTOR_FORWARD": "Vooruit", "LEAPHY_MOTOR_BACKWARD": "Achteruit", "LEAPHY_MOTOR_LEFT": "Links", diff --git a/package.json b/package.json index c8b4952..8703887 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "msg", "theme" ], - "version": "1.5.0", + "version": "1.5.1", "description": "Leaphy custom Blockly blocks and arduino code generator", "name": "@leaphy-robotics/leaphy-blocks" }