Changed default motor to A instead of all. Added TODOs and DEBUG code comments. Changed output-commands to use proper enums

This commit is contained in:
Kevin Andersen 2019-01-21 08:01:10 +01:00
parent 0557fc8e09
commit 7cee07db83

View file

@ -55,23 +55,13 @@ const BoostDevice = {
CURRENT: 0x15, CURRENT: 0x15,
}; };
/**
* Enum for connection/port ids assigned to internal Boost output devices.
* @readonly
* @enum {number}
*/
// TODO: Check for these more accurately at startup?
const BoostConnectID = {
LED: 6,
PIEZO: 5
};
/** /**
* Enum for ids for various output commands on the Boost. * Enum for ids for various output commands on the Boost.
* @readonly * @readonly
* @enum {number} * @enum {number}
*/ */
const BoostCommand = { const BoostCommand = {
// TODO: Figure out if this enum is necessary or if we're always just sending 0x81
OUTPUT: 0x81, OUTPUT: 0x81,
}; };
@ -563,7 +553,7 @@ class Boost {
]; ];
const cmd = this.generateOutputCommand( const cmd = this.generateOutputCommand(
50, this._ports.indexOf(BoostDevice.LED),
0x51, 0x51,
BoostMode.LED, BoostMode.LED,
rgb rgb
@ -594,9 +584,9 @@ class Boost {
*/ */
stopLED () { stopLED () {
const cmd = this.generateOutputCommand( const cmd = this.generateOutputCommand(
BoostConnectID.LED, this._ports.indexOf(BoostDevice.LED),
0x32, 0x51,
BoostMode.LED, BoostUnit.LED,
[0, 0, 0] [0, 0, 0]
); );
@ -749,9 +739,8 @@ class Boost {
command.unshift(command.length+1) // Prepend payload with length byte command.unshift(command.length+1) // Prepend payload with length byte
// Add checksum //DEBUG
console.log(buf2hex(command)) console.log(buf2hex(command))
//console.log(command)
return command; return command;
} }
@ -761,8 +750,6 @@ class Boost {
* @private * @private
*/ */
_onConnect () { _onConnect () {
//this.setLEDMode();
//this.setLED(0x00FF00);
this._ble.startNotifications( this._ble.startNotifications(
BLEService, BLEService,
BLECharacteristic, BLECharacteristic,
@ -839,9 +826,11 @@ class Boost {
break; break;
case BoostMessageTypes.PORT_INPUT_FORMAT: case BoostMessageTypes.PORT_INPUT_FORMAT:
case BoostMessageTypes.ERROR: case BoostMessageTypes.ERROR:
//DEBUG
console.log(buf2hex(data)) console.log(buf2hex(data))
break; break;
default: default:
//DEBUG
console.log(buf2hex(data)) console.log(buf2hex(data))
} }
} }
@ -1010,7 +999,7 @@ class Scratch3BoostBlocks {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_ID',
defaultValue: BoostMotorLabel.DEFAULT defaultValue: BoostMotorLabel.A
}, },
DURATION: { DURATION: {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
@ -1030,7 +1019,7 @@ class Scratch3BoostBlocks {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_ID',
defaultValue: BoostMotorLabel.DEFAULT defaultValue: BoostMotorLabel.A
} }
} }
}, },
@ -1046,7 +1035,7 @@ class Scratch3BoostBlocks {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_ID',
defaultValue: BoostMotorLabel.DEFAULT defaultValue: BoostMotorLabel.A
} }
} }
}, },
@ -1062,7 +1051,7 @@ class Scratch3BoostBlocks {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_ID',
defaultValue: BoostMotorLabel.DEFAULT defaultValue: BoostMotorLabel.A
}, },
POWER: { POWER: {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
@ -1082,7 +1071,7 @@ class Scratch3BoostBlocks {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_ID',
defaultValue: BoostMotorLabel.DEFAULT defaultValue: BoostMotorLabel.A
}, },
MOTOR_DIRECTION: { MOTOR_DIRECTION: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
@ -1213,14 +1202,14 @@ class Scratch3BoostBlocks {
opcode: 'getMotorPosition', opcode: 'getMotorPosition',
text: formatMessage({ text: formatMessage({
id: 'boost.getMotorPosition', id: 'boost.getMotorPosition',
default: 'motor position [MOTOR_ID]', default: 'motor position [MOTOR_REPORTER_ID]',
description: 'the position returned by the motor' description: 'the position returned by the motor'
}), }),
blockType: BlockType.REPORTER, blockType: BlockType.REPORTER,
arguments: { arguments: {
MOTOR_ID: { MOTOR_REPORTER_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'MOTOR_ID', menu: 'MOTOR_REPORTER_ID',
defaultValue: BoostMotorLabel.A defaultValue: BoostMotorLabel.A
} }
} }
@ -1228,14 +1217,6 @@ class Scratch3BoostBlocks {
], ],
menus: { menus: {
MOTOR_ID: [ MOTOR_ID: [
{
text: formatMessage({
id: 'boost.motorId.default',
default: 'motor',
description: 'label for motor element in motor menu for LEGO Boost extension'
}),
value: BoostMotorLabel.DEFAULT
},
{ {
text: formatMessage({ text: formatMessage({
id: 'boost.motorId.a', id: 'boost.motorId.a',
@ -1277,6 +1258,40 @@ class Scratch3BoostBlocks {
value: BoostMotorLabel.ALL value: BoostMotorLabel.ALL
} }
], ],
MOTOR_REPORTER_ID: [
{
text: formatMessage({
id: 'boost.motorReporterId.a',
default: 'A',
description: 'label for motor A element in motor menu for LEGO Boost extension'
}),
value: BoostMotorLabel.A
},
{
text: formatMessage({
id: 'boost.motorReporterId.b',
default: 'B',
description: 'label for motor B element in motor menu for LEGO Boost extension'
}),
value: BoostMotorLabel.B
},
{
text: formatMessage({
id: 'boost.motorReporterId.c',
default: 'C',
description: 'label for motor C element in motor menu for LEGO Boost extension'
}),
value: BoostMotorLabel.C
},
{
text: formatMessage({
id: 'boost.motorReporterId.d',
default: 'D',
description: 'label for motor D element in motor menu for LEGO Boost extension'
}),
value: BoostMotorLabel.D
}
],
MOTOR_DIRECTION: [ MOTOR_DIRECTION: [
{ {
text: formatMessage({ text: formatMessage({
@ -1644,7 +1659,7 @@ class Scratch3BoostBlocks {
* @return {number} * @return {number}
*/ */
getMotorPosition (args) { getMotorPosition (args) {
switch(args.MOTOR_ID) { switch(args.MOTOR_REPORTER_ID) {
// TODO: Handle negative rotation. // TODO: Handle negative rotation.
case BoostMotorLabel.A: case BoostMotorLabel.A:
return MathUtil.wrapClamp(this._peripheral._motors[BoostPort.A].position, 0, 360); return MathUtil.wrapClamp(this._peripheral._motors[BoostPort.A].position, 0, 360);