Skip to content

Commit

Permalink
fix: uno
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Dec 7, 2024
1 parent b2e1e63 commit 36543ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/blocks/leaphy_original.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ const motorLeftRightDropdown = [
["%{BKY_LEAPHY_MOTOR_LEFT_DROPDOWN}", "9"],
["%{BKY_LEAPHY_MOTOR_RIGHT_DROPDOWN}", "10"],
];

export enum MotorDirection {
FORWARD = "1",
BACKWARD = "2",
LEFT = "3",
RIGHT = "4",
}

const motorForwardBackwardDropdown = [
["%{BKY_LEAPHY_MOTOR_FORWARD}", "2"],
["%{BKY_LEAPHY_MOTOR_BACKWARD}", "1"],
["%{BKY_LEAPHY_MOTOR_LEFT}", "4"],
["%{BKY_LEAPHY_MOTOR_RIGHT}", "3"],
["%{BKY_LEAPHY_MOTOR_FORWARD}", MotorDirection.FORWARD],
["%{BKY_LEAPHY_MOTOR_BACKWARD}", MotorDirection.BACKWARD],
["%{BKY_LEAPHY_MOTOR_LEFT}", MotorDirection.LEFT],
["%{BKY_LEAPHY_MOTOR_RIGHT}", MotorDirection.RIGHT],
];

const blocks: BlockDefinition = [
Expand Down
18 changes: 15 additions & 3 deletions src/generators/arduino/leaphy_original.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Arduino } from "../arduino";
import { MotorDirection } from "../../blocks/leaphy_original";

function getCodeGenerators(arduino: Arduino) {
arduino.forBlock["leaphy_original_set_led"] = function (block) {
Expand Down Expand Up @@ -71,23 +72,34 @@ function getCodeGenerators(arduino: Arduino) {
};

arduino.forBlock["leaphy_original_move_motors"] = function (block) {
const dropdown_Type = block.getFieldValue("MOTOR_DIRECTION");
let direction = block.getFieldValue(
"MOTOR_DIRECTION",
) as MotorDirection;
const speed =
arduino.valueToCode(block, "MOTOR_SPEED", arduino.ORDER_ATOMIC) ||
"100";
arduino.addInclude(
"include_leaphy_original",
'#include "Leaphyoriginal1.h"',
);

// Set different motor pins for nano robots
if (arduino.robotType.includes("nano"))
if (arduino.robotType.includes("nano")) {
const directionMap: Record<MotorDirection, number> = {
[MotorDirection.FORWARD]: 2,
[MotorDirection.BACKWARD]: 1,
[MotorDirection.LEFT]: 4,
[MotorDirection.RIGHT]: 3,
};
direction = directionMap[direction];
arduino.addSetup(
"set_motor_pins",
"setMotorPins(3, 2, 11, 4);",
true,
);
}

return `moveMotors(${dropdown_Type}, ${speed});\n`;
return `moveMotors(${direction}, ${speed});\n`;
};

arduino.forBlock["digital_read"] = function (block) {
Expand Down

0 comments on commit 36543ed

Please sign in to comment.