From 25c3e2c49bcce000705ad15ade98d43403513a08 Mon Sep 17 00:00:00 2001 From: noqman <140384051+noqman@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:27:11 +0800 Subject: [PATCH] Ensure JavaScript matches block definitions for all functions --- edge.ts | 4 ++-- motor.ts | 6 +++--- opponent.ts | 52 ++++++++++++++++------------------------------------ robot.ts | 8 ++++---- servo.ts | 4 ++-- 5 files changed, 27 insertions(+), 47 deletions(-) diff --git a/edge.ts b/edge.ts index e434dbf..82b7195 100644 --- a/edge.ts +++ b/edge.ts @@ -75,7 +75,7 @@ namespace sumobit { //% blockGap=8 //% blockId=sumobit_edge_return_value //% block="%edge edge sensor" - //% edge.defl=0 + //% edge.defl=SumobitEdgeSelection.Right export function fetchEdgeValue(edge: SumobitEdgeSelection): number { switch (edge) { case SumobitEdgeSelection.Right: @@ -169,7 +169,7 @@ namespace sumobit { //% blockGap=8 //% blockId=sumobit_edge_compare_calibrated_value //% block="%edge sensor detect edge" - //% edge.defl=0 + //% edge.defl=SumobitEdgeSelection.Right export function compareEdgeCalibrated(edge: SumobitEdgeSelection): boolean { let result = false; switch (edge) { diff --git a/motor.ts b/motor.ts index 0ce5ef3..52173ab 100644 --- a/motor.ts +++ b/motor.ts @@ -41,7 +41,7 @@ namespace sumobit { //% blockGap=8 //% blockId=sumobit_motor_stop //% block="stop %motor motor" - //% motor.defl=1000 + //% motor.defl=SumobitMotorChannel.Both export function stopMotor(motor: SumobitMotorChannel): void { switch (motor) { case SumobitMotorChannel.RightMotor: @@ -78,8 +78,8 @@ namespace sumobit { //% accel.fieldOptions.label="Acceleration Factor" //% block="run %motor motor %direction at %speed speed || with %acceleration acceleration factor" //% inlineInputMode=inline - //% motor.defl=0 - //% direction.defl=1000 + //% motor.defl=SumobitMotorChannel.Both + //% direction.defl=SumobitMotorDirection.Forward //% speed.min=0 speed.max=255 //% speed.defl=120 //% acceleration.min=1 acceleration.max=9 diff --git a/opponent.ts b/opponent.ts index 58c4546..979a58a 100644 --- a/opponent.ts +++ b/opponent.ts @@ -43,10 +43,6 @@ enum SumobitSensorSelection2 { //% block="right" Right = 4, - //% block="all" - //% blockHidden=true - All = 5, - //% block="none" None = 6 } @@ -64,7 +60,7 @@ namespace sumobit { //% blockGap=8 //% blockId=sumobit_maker_object_read_digital //% block="%sensor opponent sensor" - //% sensor.defl=4 + //% sensor.defl=SumobitSensorSelection1.Right //% position.fieldEditor="gridpicker" position.fieldOptions.columns=5 export function oppSensorValue(sensor: SumobitSensorSelection1): number { @@ -93,62 +89,46 @@ namespace sumobit { /** * Returns true if the opponent sensor is low (Obstacle detected). - * @param sensor The opponent sensor to read (Left, Front Left, Center, Front Right, Right). eg: SumobitSensorSelection2.Right + * @param position The opponent sensor to read (Left, Front Left, Center, Front Right, Right). eg: SumobitSensorSelection2.Right */ //% group="Opponent Sensors" //% weight=88 //% blockGap=8 //% blockId=sumobit_maker_object_detect_opponent //% block="%position sensor detect opponent" - //% position.defl = 4 + //% position.defl=SumobitSensorSelection2.Right export function oppSensorDetection(position: SumobitSensorSelection2): boolean { - - + let result = false; let L = oppSensorValue(0); let FL = oppSensorValue(1); let FC = oppSensorValue(2); let FR = oppSensorValue(3); let R = oppSensorValue(4); + switch (position) { - case SumobitSensorSelection2.None: - if (L == 1 && FL == 1 && FC == 1 && FR == 1 && R == 1) - return true; - else return false; - case SumobitSensorSelection2.Left: - if (L == 0) - return true; - else return false; + return L == 0; case SumobitSensorSelection2.FrontLeft: - if (FL == 0) - return true; - else return false; + return FL == 0; case SumobitSensorSelection2.Center: - if (FC == 0) - return true; - else return false; + return FC == 0; case SumobitSensorSelection2.FrontRight: - if (FR == 0) - return true; - else return false; + return FR == 0; case SumobitSensorSelection2.Right: - if (R == 0) - return true; - else return false; - - case SumobitSensorSelection2.All: - if (L == 0 && FL == 0 && FC == 0 && FR == 0 && R == 0) - return true; - else return false; - } + return R == 0; + + case SumobitSensorSelection2.None: + return L == 1 && FL == 1 && FC == 1 && FR == 1 && R == 1; - return false; + default: + return false; + } } /** diff --git a/robot.ts b/robot.ts index d65a0e0..b1c5b6d 100644 --- a/robot.ts +++ b/robot.ts @@ -65,7 +65,7 @@ let searchMillis = control.millis(); //% blockGap=8 //% blockId="sumobit_robot_countdown" //% block="start countdown %second" - //% second.defl=5 + //% second.defl=SumobitCountdown.Five //% second.fieldOptions.decompileLiterals=true //% subcategory="Robot Kit" export function countdown(second: SumobitCountdown): void { @@ -89,7 +89,7 @@ let searchMillis = control.millis(); //% blockId="sumobit_robot_backoff" //% block="backoff %direction speed:%speed || acceleration:%acceleration" //% expandableArgumentMode="toggle" - //% direction.defl=1 + //% direction.defl=SumobitDirection.Right //% speed.min=0 speed.max=255 //% speed.defl=120 //% acceleration.min=1 acceleration.max=9 @@ -167,7 +167,7 @@ let searchMillis = control.millis(); /** * Robot search routine - * @param mode The search mode. eg: SumobitSearch.0 + * @param mode The search mode. eg: SumobitSearch.Normal * @param speed Motor speed while searching for opponent. eg: 120 * @param acceleration Motor acceleration factor (1-9). eg: 9 */ @@ -176,7 +176,7 @@ let searchMillis = control.millis(); //% blockGap=8 //% blockId="sumobit_robot_search" //% block="search %mode speed:%speed || acceleration:%acceleration" - //% mode.defl=0 + //% mode.defl= SumobitSearch.Normal //% speed.min=0 speed.max=255 //% speed.defl=120 //% acceleration.min=1 acceleration.max=9 diff --git a/servo.ts b/servo.ts index fce6bcb..a8a7316 100644 --- a/servo.ts +++ b/servo.ts @@ -33,7 +33,7 @@ namespace sumobit{ //% blockGap=8 //% blockId=sumobit_servo_disable //% block="disable %servo" - //% servo.defl=1 + //% servo.defl=SumobitServoChannel.Servo1 export function disableServo(servo: SumobitServoChannel): void { switch (servo) { @@ -63,7 +63,7 @@ namespace sumobit{ //% blockGap=8 //% blockId=sumobit_servo_set_position //% block="set %servo position to %position \\° || at speed:%speed" - //% servo.defl=1 + //% servo.defl= SumobitServoChannel.Servo1 //% position.min=0 position.max=180 //% position.defl=90 //% speed.min=0 speed.max=180