diff --git a/blocks/leaphy_click.js b/blocks/leaphy_click.js index b6ff20e..391c217 100644 --- a/blocks/leaphy_click.js +++ b/blocks/leaphy_click.js @@ -56,25 +56,6 @@ const blocks = [ tooltip: "", helpUrl: "", }, - { - type: "leaphy_click_nano_set_motor", - message0: "%%{BKY_LEAPHY_MOTOR_TYPE} %1 %2 %%{BKY_LEAPHY_MOTOR_SPEED} %3", - args0: [ - { - type: "field_dropdown", - name: "MOTOR_TYPE", - options: motorDropdown, - }, - { type: "input_dummy" }, - { type: "input_value", name: "MOTOR_SPEED", check: "Number" }, - ], - inputsInline: true, - previousStatement: null, - nextStatement: null, - style: "leaphy_blocks", - tooltip: "", - helpUrl: "", - }, { type: "leaphy_click_rgb_digitalwrite", message0: diff --git a/blocks/leaphy_flitz.js b/blocks/leaphy_flitz.js index 8b39bf4..17f824c 100644 --- a/blocks/leaphy_flitz.js +++ b/blocks/leaphy_flitz.js @@ -71,23 +71,6 @@ const blocks = [ tooltip: "", helpUrl: "", }, - { - type: "leaphy_flitz_nano_led", - message0: - "%%{BKY_LEAPHY_FLITZ_LED} %1 %%{BKY_LEAPHY_FLITZ_LED_R} %2 %%{BKY_LEAPHY_FLITZ_LED_G} %3 %%{BKY_LEAPHY_FLITZ_LED_B} %4", - args0: [ - { type: "input_dummy" }, - { type: "input_value", name: "FLITZ_LED_R", check: "Number" }, - { type: "input_value", name: "FLITZ_LED_G", check: "Number" }, - { type: "input_value", name: "FLITZ_LED_B", check: "Number" }, - ], - inputsInline: true, - previousStatement: null, - nextStatement: null, - style: "leaphy_blocks", - tooltip: "", - helpUrl: "", - }, ]; export { blocks }; diff --git a/blocks/leaphy_original.js b/blocks/leaphy_original.js index eb9bc84..a80c55d 100644 --- a/blocks/leaphy_original.js +++ b/blocks/leaphy_original.js @@ -63,25 +63,6 @@ const blocks = [ tooltip: "", helpUrl: "", }, - { - type: "leaphy_nano_set_motor", - message0: "%%{BKY_LEAPHY_MOTOR_TYPE} %1 %2 %%{BKY_LEAPHY_MOTOR_SPEED} %3", - args0: [ - { - type: "field_dropdown", - name: "MOTOR_TYPE", - options: motorLeftRightDropdown, - }, - { type: "input_dummy" }, - { type: "input_value", name: "MOTOR_SPEED", check: "Number" }, - ], - inputsInline: true, - previousStatement: null, - nextStatement: null, - style: "leaphy_blocks", - tooltip: "", - helpUrl: "", - }, { type: "leaphy_original_get_distance", message0: "%%{BKY_LEAPHY_GET_DISTANCE}", @@ -109,25 +90,6 @@ const blocks = [ tooltip: "", helpUrl: "", }, - { - type: "leaphy_nano_move_motors", - message0: "%%{BKY_LEAPHY_MOTOR_DIRECTION} %1 %2 %3", - args0: [ - { - type: "field_dropdown", - name: "MOTOR_DIRECTION", - options: motorForwardBackwardDropdown, - }, - { type: "input_dummy" }, - { type: "input_value", name: "MOTOR_SPEED", check: "Number" }, - ], - inputsInline: true, - previousStatement: null, - nextStatement: null, - style: "leaphy_blocks", - tooltip: "", - helpUrl: "", - }, { type: "leaphy_original_buzz", message0: diff --git a/generators/arduino/all.js b/generators/arduino/all.js index 65d24df..aef9199 100644 --- a/generators/arduino/all.js +++ b/generators/arduino/all.js @@ -411,6 +411,14 @@ Arduino.noGeneratorCodeLine = function () { return ""; }; +// Override workspaceToCode with an additional robotType parameter that can be used by code generators +// to change bevaviour (like pins) for different robot types +Arduino._workspaceToCode = Arduino.workspaceToCode; +Arduino.workspaceToCode = function (workspace, robotType) { + Arduino.robotType = robotType; + return Arduino._workspaceToCode(workspace); +}; + import * as arduino from "./arduino"; import * as leaphy_click from "./leaphy_click"; import * as leaphy_common from "./leaphy_common"; diff --git a/generators/arduino/leaphy_flitz.js b/generators/arduino/leaphy_flitz.js index ba6765f..0d557a2 100644 --- a/generators/arduino/leaphy_flitz.js +++ b/generators/arduino/leaphy_flitz.js @@ -46,38 +46,34 @@ function getCodeGenerators(Arduino) { Arduino.valueToCode(this, "FLITZ_LED_G", Arduino.ORDER_ATOMIC) || "0"; var flitz_blue = Arduino.valueToCode(this, "FLITZ_LED_B", Arduino.ORDER_ATOMIC) || "0"; - var code = - "analogWrite(3, " + - flitz_red + - ");\nanalogWrite(5, " + - flitz_green + - ");\nanalogWrite(6, " + - flitz_blue + - ");\n"; - return code; - }; - Arduino.forBlock["leaphy_flitz_nano_led"] = function (block) { - var flitz_red = - Arduino.valueToCode(this, "FLITZ_LED_R", Arduino.ORDER_ATOMIC) || "0"; - var flitz_green = - Arduino.valueToCode(this, "FLITZ_LED_G", Arduino.ORDER_ATOMIC) || "0"; - var flitz_blue = - Arduino.valueToCode(this, "FLITZ_LED_B", Arduino.ORDER_ATOMIC) || "0"; - // Ground is connected to pin 8 on the nano, so it needs to be pulled LOW - Arduino.addSetup( - "setup_flitz_nano_rgb", - "pinMode(8, OUTPUT);\n digitalWrite(8, LOW);", - false, - ); - var code = - "analogWrite(11, " + - flitz_red + - ");\nanalogWrite(10, " + - flitz_green + - ");\nanalogWrite(9, " + - flitz_blue + - ");\n"; + var code; + if (Arduino.robotType.includes("nano")) { + // Ground is connected to pin 8 on the nano, so it needs to be pulled LOW + Arduino.addSetup( + "setup_flitz_nano_rgb", + "pinMode(8, OUTPUT);\n digitalWrite(8, LOW);", + false, + ); + code = + "analogWrite(11, " + + flitz_red + + ");\nanalogWrite(10, " + + flitz_green + + ");\nanalogWrite(9, " + + flitz_blue + + ");\n"; + } else { + code = + "analogWrite(3, " + + flitz_red + + ");\nanalogWrite(5, " + + flitz_green + + ");\nanalogWrite(6, " + + flitz_blue + + ");\n"; + } + return code; }; } diff --git a/generators/arduino/leaphy_original.js b/generators/arduino/leaphy_original.js index 2252c09..f667dbd 100644 --- a/generators/arduino/leaphy_original.js +++ b/generators/arduino/leaphy_original.js @@ -21,27 +21,16 @@ function getCodeGenerators(Arduino) { "include_leaphy_original", '#include "Leaphyoriginal1.h"', ); - var code = "setMotor(" + dropdown_Type + ", " + speed + ");\n"; - return code; - }; + // Set different motor pins for nano robots + if (Arduino.robotType.includes("nano")) + Arduino.addSetup("set_motor_pins", "setMotorPins(3, 2, 11, 4);", true); - Arduino.forBlock["leaphy_nano_set_motor"] = function (block) { - var dropdown_Type = block.getFieldValue("MOTOR_TYPE"); - var speed = - Arduino.valueToCode(this, "MOTOR_SPEED", Arduino.ORDER_ATOMIC) || "100"; - Arduino.addInclude( - "include_leaphy_original", - '#include "Leaphyoriginal1.h"', - ); - Arduino.addSetup("set_motor_pins", "setMotorPins(3, 2, 11, 4);", true); var code = "setMotor(" + dropdown_Type + ", " + speed + ");\n"; return code; }; Arduino.forBlock["leaphy_click_set_motor"] = Arduino.forBlock["leaphy_original_set_motor"]; - Arduino.forBlock["leaphy_click_nano_set_motor"] = - Arduino.forBlock["leaphy_nano_set_motor"]; Arduino.forBlock["leaphy_original_get_distance"] = function (block) { Arduino.addInclude( @@ -60,19 +49,10 @@ function getCodeGenerators(Arduino) { "include_leaphy_original", '#include "Leaphyoriginal1.h"', ); - var code = "moveMotors(" + dropdown_Type + ", " + speed + ");\n"; - return code; - }; + // Set different motor pins for nano robots + if (Arduino.robotType.includes("nano")) + Arduino.addSetup("set_motor_pins", "setMotorPins(3, 2, 11, 4);", true); - Arduino.forBlock["leaphy_nano_move_motors"] = function (block) { - var dropdown_Type = block.getFieldValue("MOTOR_DIRECTION"); - var speed = - Arduino.valueToCode(this, "MOTOR_SPEED", Arduino.ORDER_ATOMIC) || "100"; - Arduino.addInclude( - "include_leaphy_original", - '#include "Leaphyoriginal1.h"', - ); - Arduino.addSetup("set_motor_pins", "setMotorPins(3, 2, 11, 4);", true); var code = "moveMotors(" + dropdown_Type + ", " + speed + ");\n"; return code; }; diff --git a/package.json b/package.json index e9ecbe6..c8b4952 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "msg", "theme" ], - "version": "1.4.1", + "version": "1.5.0", "description": "Leaphy custom Blockly blocks and arduino code generator", "name": "@leaphy-robotics/leaphy-blocks" }