Skip to content

Commit

Permalink
Ensure JavaScript matches block definitions for all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
noqman committed Dec 4, 2024
1 parent f854293 commit 25c3e2c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 47 deletions.
4 changes: 2 additions & 2 deletions edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions motor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
52 changes: 16 additions & 36 deletions opponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ enum SumobitSensorSelection2 {
//% block="right"
Right = 4,

//% block="all"
//% blockHidden=true
All = 5,

//% block="none"
None = 6
}
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions servo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 25c3e2c

Please sign in to comment.