Skip to content

Commit

Permalink
Prefix some constant with SUMOBIT
Browse files Browse the repository at this point in the history
  • Loading branch information
noqman committed Dec 6, 2024
1 parent 6470d70 commit 7b3cd62
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 104 deletions.
4 changes: 2 additions & 2 deletions battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace sumobit {
export function readBatteryValue(): number {
let highByte: number;
let lowByte: number;
highByte = sumobit.i2cRead(REG_ADD_VIN_HIGH);
lowByte = sumobit.i2cRead(REG_ADD_VIN_LOW);
highByte = sumobit.i2cRead(SUMOBIT_REG_ADD_VIN_HIGH);
lowByte = sumobit.i2cRead(SUMOBIT_REG_ADD_VIN_LOW);
return ((highByte << 8) | lowByte) / 100;
}
}
78 changes: 39 additions & 39 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
const SUMOBIT_I2C_ADDRESS = 0x09;

// I2C register addresses
const REG_ADD_REVISION = 0;
const REG_ADD_SRV1_POS = 1;
const REG_ADD_SRV1_SPEED = 2;
const REG_ADD_SRV2_POS = 3;
const REG_ADD_SRV2_SPEED = 4;
const REG_SERVO_R1 = 5;
const REG_SERVO_R2 = 6;
const REG_SERVO_R3 = 7;
const REG_SERVO_R4 = 8;
const REG_ADD_PWM1 = 9;
const REG_ADD_DIR1 = 10;
const REG_ADD_ACCEL1 = 11;
const REG_ADD_PWM2 = 12;
const REG_ADD_DIR2 = 13;
const REG_ADD_ACCEL2 = 14;
const REG_MOTOR_R1 = 15;
const REG_MOTOR_R2 = 16;
const REG_MOTOR_R3 = 17;
const REG_MOTOR_R4 = 18;
const REG_ADD_R0 = 19;
const REG_ADD_G0 = 20;
const REG_ADD_B0 = 21;
const REG_ADD_R1 = 22;
const REG_ADD_G1 = 23;
const REG_ADD_B1 = 24;
const REG_ADD_AN1_HIGH = 25;
const REG_ADD_AN1_LOW = 26;
const REG_ADD_AN2_HIGH = 27;
const REG_ADD_AN2_LOW = 28;
const REG_CURRENT_R1 = 29;
const REG_CURRENT_R2 = 30;
const REG_ADD_VIN_HIGH = 31;
const REG_ADD_VIN_LOW = 32;
const REG_VIN_R1 = 33;
const REG_VIN_R2 = 34;
const REG_ADD_DIP = 35;
const REG_ADD_RESET = 36;
const SUMOBIT_REG_ADD_REVISION = 0;
const SUMOBIT_REG_ADD_SRV1_POS = 1;
const SUMOBIT_REG_ADD_SRV1_SPEED = 2;
const SUMOBIT_REG_ADD_SRV2_POS = 3;
const SUMOBIT_REG_ADD_SRV2_SPEED = 4;
const SUMOBIT_REG_SERVO_R1 = 5;
const SUMOBIT_REG_SERVO_R2 = 6;
const SUMOBIT_REG_SERVO_R3 = 7;
const SUMOBIT_REG_SERVO_R4 = 8;
const SUMOBIT_REG_ADD_PWM1 = 9;
const SUMOBIT_REG_ADD_DIR1 = 10;
const SUMOBIT_REG_ADD_ACCEL1 = 11;
const SUMOBIT_REG_ADD_PWM2 = 12;
const SUMOBIT_REG_ADD_DIR2 = 13;
const SUMOBIT_REG_ADD_ACCEL2 = 14;
const SUMOBIT_REG_MOTOR_R1 = 15;
const SUMOBIT_REG_MOTOR_R2 = 16;
const SUMOBIT_REG_MOTOR_R3 = 17;
const SUMOBIT_REG_MOTOR_R4 = 18;
const SUMOBIT_REG_ADD_R0 = 19;
const SUMOBIT_REG_ADD_G0 = 20;
const SUMOBIT_REG_ADD_B0 = 21;
const SUMOBIT_REG_ADD_R1 = 22;
const SUMOBIT_REG_ADD_G1 = 23;
const SUMOBIT_REG_ADD_B1 = 24;
const SUMOBIT_REG_ADD_AN1_HIGH = 25;
const SUMOBIT_REG_ADD_AN1_LOW = 26;
const SUMOBIT_REG_ADD_AN2_HIGH = 27;
const SUMOBIT_REG_ADD_AN2_LOW = 28;
const SUMOBIT_REG_CURRENT_R1 = 29;
const SUMOBIT_REG_CURRENT_R2 = 30;
const SUMOBIT_REG_ADD_VIN_HIGH = 31;
const SUMOBIT_REG_ADD_VIN_LOW = 32;
const SUMOBIT_REG_VIN_R1 = 33;
const SUMOBIT_REG_VIN_R2 = 34;
const SUMOBIT_REG_ADD_DIP = 35;
const SUMOBIT_REG_ADD_RESET = 36;

/**
* Blocks for SUMO:BIT.
Expand All @@ -54,8 +54,8 @@ namespace sumobit {


// Stop all motor initially
sumobit.i2cWrite(REG_ADD_PWM1, 0);
sumobit.i2cWrite(REG_ADD_PWM2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, 0);

// Disable the servos initially
sumobit.i2cWrite(SumobitServoChannel.Servo1, 0);
Expand Down
2 changes: 1 addition & 1 deletion mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let oldCompareResult: boolean[] = [];
//% blockId=sumobit_mode_read_value
//% block="mode"
export function readModeValue(): number {
return sumobit.i2cRead(REG_ADD_DIP);
return sumobit.i2cRead(SUMOBIT_REG_ADD_DIP);
}

/**
Expand Down
64 changes: 32 additions & 32 deletions motor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ namespace sumobit {
export function stopMotor(motor: SumobitMotorChannel): void {
switch (motor) {
case SumobitMotorChannel.RightMotor:
sumobit.i2cWrite(REG_ADD_PWM1, 0);
sumobit.i2cWrite(REG_ADD_DIR1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 0);
break;

case SumobitMotorChannel.LeftMotor:
sumobit.i2cWrite(REG_ADD_PWM2, 0);
sumobit.i2cWrite(REG_ADD_DIR2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 0);
break;

case SumobitMotorChannel.Both:
sumobit.i2cWrite(REG_ADD_PWM1, 0);
sumobit.i2cWrite(REG_ADD_DIR1, 0);
sumobit.i2cWrite(REG_ADD_PWM2, 0);
sumobit.i2cWrite(REG_ADD_DIR2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 0);
break;
}
}
Expand Down Expand Up @@ -92,46 +92,46 @@ namespace sumobit {
switch (motor) {
case SumobitMotorChannel.RightMotor:
if (direction == SumobitMotorDirection.Forward) {
sumobit.i2cWrite(REG_ADD_PWM1, speed);
sumobit.i2cWrite(REG_ADD_DIR1, 0);
sumobit.i2cWrite(REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL1, acceleration);
}
else {
sumobit.i2cWrite(REG_ADD_PWM1, speed);
sumobit.i2cWrite(REG_ADD_DIR1, 1);
sumobit.i2cWrite(REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 1);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL1, acceleration);
}
break;

case SumobitMotorChannel.LeftMotor:
if (direction == SumobitMotorDirection.Forward) {
sumobit.i2cWrite(REG_ADD_PWM2, speed);
sumobit.i2cWrite(REG_ADD_DIR2, 0);
sumobit.i2cWrite(REG_ADD_ACCEL2, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL2, acceleration);
}
else {
sumobit.i2cWrite(REG_ADD_PWM2, speed);
sumobit.i2cWrite(REG_ADD_DIR2, 1);
sumobit.i2cWrite(REG_ADD_ACCEL2, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 1);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL2, acceleration);
}
break;

case SumobitMotorChannel.Both:
if (direction == SumobitMotorDirection.Forward) {
sumobit.i2cWrite(REG_ADD_PWM1, speed);
sumobit.i2cWrite(REG_ADD_DIR1, 0);
sumobit.i2cWrite(REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(REG_ADD_PWM2, speed);
sumobit.i2cWrite(REG_ADD_DIR2, 0);
sumobit.i2cWrite(REG_ADD_ACCEL2, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL2, acceleration);
}
else {
sumobit.i2cWrite(REG_ADD_PWM1, speed);
sumobit.i2cWrite(REG_ADD_DIR1, 1);
sumobit.i2cWrite(REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(REG_ADD_PWM2, speed);
sumobit.i2cWrite(REG_ADD_DIR2, 1);
sumobit.i2cWrite(REG_ADD_ACCEL2, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM1, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR1, 1);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL1, acceleration);
sumobit.i2cWrite(SUMOBIT_REG_ADD_PWM2, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_DIR2, 1);
sumobit.i2cWrite(SUMOBIT_REG_ADD_ACCEL2, acceleration);
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions motorcurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ let oldCompareResult: boolean[] = [];
export function readRightMotorCurrentValue(): number {
let highByte: number;
let lowByte: number;
highByte = sumobit.i2cRead(REG_ADD_AN1_HIGH);
lowByte = sumobit.i2cRead(REG_ADD_AN1_LOW);
highByte = sumobit.i2cRead(SUMOBIT_REG_ADD_AN1_HIGH);
lowByte = sumobit.i2cRead(SUMOBIT_REG_ADD_AN1_LOW);
return ((highByte << 8) | lowByte) / 100;
}

Expand All @@ -68,8 +68,8 @@ let oldCompareResult: boolean[] = [];
export function readLeftMotorCurrentValue(): number {
let highByte: number;
let lowByte: number;
highByte = sumobit.i2cRead(REG_ADD_AN2_HIGH);
lowByte = sumobit.i2cRead(REG_ADD_AN2_LOW);
highByte = sumobit.i2cRead(SUMOBIT_REG_ADD_AN2_HIGH);
lowByte = sumobit.i2cRead(SUMOBIT_REG_ADD_AN2_LOW);
return ((highByte << 8) | lowByte) / 100;
}

Expand Down
36 changes: 18 additions & 18 deletions rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ namespace sumobit {
//% block="clear all RGB pixels"
export function clearAllRgbPixels(): void {

sumobit.i2cWrite(REG_ADD_R0, 0);
sumobit.i2cWrite(REG_ADD_G0, 0);
sumobit.i2cWrite(REG_ADD_B0, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R0, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G0, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B0, 0);

sumobit.i2cWrite(REG_ADD_R1, 0);
sumobit.i2cWrite(REG_ADD_G1, 0);
sumobit.i2cWrite(REG_ADD_B1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G1, 0);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B1, 0);

}

Expand Down Expand Up @@ -89,13 +89,13 @@ namespace sumobit {
let green = (color >> 8) & 0xFF; // Shift right by 8 bits and mask with 0xFF
let blue = color & 0xFF;

sumobit.i2cWrite(REG_ADD_R0, red);
sumobit.i2cWrite(REG_ADD_G0, green);
sumobit.i2cWrite(REG_ADD_B0, blue);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R0, red);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G0, green);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B0, blue);

sumobit.i2cWrite(REG_ADD_R1, red);
sumobit.i2cWrite(REG_ADD_G1, green);
sumobit.i2cWrite(REG_ADD_B1, blue);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R1, red);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G1, green);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B1, blue);

}

Expand Down Expand Up @@ -126,15 +126,15 @@ namespace sumobit {

switch (pixel) {
case 0:
sumobit.i2cWrite(REG_ADD_R0, red);
sumobit.i2cWrite(REG_ADD_G0, green);
sumobit.i2cWrite(REG_ADD_B0, blue);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R0, red);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G0, green);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B0, blue);
break;

case 1:
sumobit.i2cWrite(REG_ADD_R1, red);
sumobit.i2cWrite(REG_ADD_G1, green);
sumobit.i2cWrite(REG_ADD_B1, blue);
sumobit.i2cWrite(SUMOBIT_REG_ADD_R1, red);
sumobit.i2cWrite(SUMOBIT_REG_ADD_G1, green);
sumobit.i2cWrite(SUMOBIT_REG_ADD_B1, blue);
break;

}
Expand Down
16 changes: 8 additions & 8 deletions servo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ namespace sumobit{

switch (servo) {
case SumobitServoChannel.Servo1:
sumobit.i2cWrite(REG_ADD_SRV1_POS, position);
sumobit.i2cWrite(REG_ADD_SRV1_SPEED, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV1_POS, position);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV1_SPEED, speed);
break;

case SumobitServoChannel.Servo2:
sumobit.i2cWrite(REG_ADD_SRV2_POS, position);
sumobit.i2cWrite(REG_ADD_SRV2_SPEED, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV2_POS, position);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV2_SPEED, speed);
break;

case SumobitServoChannel.All:
sumobit.i2cWrite(REG_ADD_SRV1_POS, position);
sumobit.i2cWrite(REG_ADD_SRV2_POS, position);
sumobit.i2cWrite(REG_ADD_SRV1_SPEED, speed);
sumobit.i2cWrite(REG_ADD_SRV2_SPEED, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV1_POS, position);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV2_POS, position);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV1_SPEED, speed);
sumobit.i2cWrite(SUMOBIT_REG_ADD_SRV2_SPEED, speed);
break;
}
}
Expand Down

0 comments on commit 7b3cd62

Please sign in to comment.