mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
- Consolidated BLE enums for brevity
- Added IOs from documentation to BoostIO enumotor follows the speed set by Scratch and not the highest possible speed. - Cleaned up line breaks in codebrake rather than float when stopping. - Cleaned up documentationensors - Deleted unused MOTOR_OUTPUT from BoostMode-enumbased on BoostMode-enum - Set default-value for "set motor power to"-block to be all motors after feedback from @ericrosenbaum - Implemented check in getMotorPosition() to see if motor is actually there before reporting position
This commit is contained in:
parent
40c022ca8e
commit
7fc705b741
1 changed files with 85 additions and 70 deletions
|
@ -22,16 +22,14 @@ const log = require('../../util/log');
|
||||||
const iconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAABYlAAAWJQFJUiTwAAAF8klEQVR4Ae2cbWxTVRjH/7ctbVc2tyEMNpWBk0VIkLcEjSAQgglTE5HEaKqJi1E/mbCP/dJA0kQbvzgTQ0Ki2T7V6AeYGoEPLJmGKPiyzZDwEpYJCHSbQIcbdLvres1zOa13Xbvdu2eTDp9fst329Lnn5XfPPfece7tphmFAmDkuccdDBDIRgUxEIBMRyEQEMhGBTEQgExHIRAQyEYFMRCATEchEBDIRgUxEIBMRyEQEMhGBTEQgExHIxMPNIByNVQBoBUDb7kgo2KTS9wBoUmFNkVCwW6U3A1gP4JJKHwxHY/S+WcW2RkLBVhV7AMAOAIMAGlWstbyOSCh4QMU2Uoy1PBVL+a7IqZu1vOZIKNg20/azBarGvKxebw9HY22RULADwBFLTBcATQnZl4lVEimN4ssteXQrQfstebQpmW1q30xshyqvxRLbofYnYW9ZYgeV8C5LLOWlzbTxM3ouHI7GPgSwWx3Z0syBSBku6IYnlTbM+uQenJQaMnKHDaqAFnDrcCFbl3G1defEjas0a4N/Vz10OybyvapfrSX1sjpo+WIz0ME7QL3djgtHPTAcjb2mepw/b2ZaGh5NL5RnofR8R99dIC5fHusK5JsrCUpm7TSx21XvbcwTNwnbAsPR2GcA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B5PWjY+ZT5RnMwkxGBFh5ZVmle9Z3MrGbjwfqccrC1vajrV7QCaVCfS6qrJj96nQlFK5CujPRT7MgYyEQEMhGBTGwJpAW4kJ9pBbo0zbx70X7y7AOv8HxP3LyB4YTpb2cZBt2iqL3QEwf9zDbX+waLca439QMeC7a+YBmOxugLiM/OTt2yaOoMoO+H6LOcNwf6xusrthsh/7mIh1yFmYhAJiKQiQhkIgKZiEAmIpCJCGQiApmIQCYikIkIZCICmYhAJiKQiQhkIgKZiEAmIpCJCGQiAjkA+AeOwQKMcWZqHgAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boost BLE service UUID.
|
* Boost BLE UUIDs.
|
||||||
* @type {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
const BLEService = '00001623-1212-efde-1623-785feabcd123';
|
|
||||||
|
|
||||||
/**
|
const BoostBLE = {
|
||||||
* Boost BLE characteristic UUID.
|
service: '00001623-1212-efde-1623-785feabcd123',
|
||||||
* @type {string}
|
characteristic: '00001624-1212-efde-1623-785feabcd123'
|
||||||
*/
|
}
|
||||||
const BLECharacteristic = '00001624-1212-efde-1623-785feabcd123';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A time interval to wait (in milliseconds) while a block that sends a BLE message is running.
|
* A time interval to wait (in milliseconds) while a block that sends a BLE message is running.
|
||||||
|
@ -51,13 +49,23 @@ const BLESendRateMax = 20;
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
const BoostIO = {
|
const BoostIO = {
|
||||||
MOTORINT: 0x27,
|
MOTOR_WEDO: 0x01,
|
||||||
MOTOREXT: 0x26,
|
MOTOR_SYSTEM: 0x02,
|
||||||
LED: 0x17,
|
BUTTON: 0x05,
|
||||||
TILT: 0x28,
|
LIGHT: 0x08,
|
||||||
COLOR: 0x25,
|
LIGHT1:0x09,
|
||||||
|
LIGHT2:0x0A,
|
||||||
VOLTAGE: 0x14,
|
VOLTAGE: 0x14,
|
||||||
CURRENT: 0x15,
|
CURRENT: 0x15,
|
||||||
|
PIEZO: 0x16,
|
||||||
|
LED: 0x17,
|
||||||
|
TILT_EXTERNAL: 0x22,
|
||||||
|
MOTION_SENSOR: 0x23,
|
||||||
|
COLOR: 0x25,
|
||||||
|
MOTOREXT: 0x26,
|
||||||
|
MOTORINT: 0x27,
|
||||||
|
TILT: 0x28,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,6 +94,11 @@ const BoostPort = {
|
||||||
D: 2
|
D: 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for indexed colors read by the Boost Vision Sensor
|
||||||
|
* @readonly
|
||||||
|
* @enum {number}
|
||||||
|
*/
|
||||||
const BoostColor = {
|
const BoostColor = {
|
||||||
NONE: 255,
|
NONE: 255,
|
||||||
RED: 9,
|
RED: 9,
|
||||||
|
@ -101,7 +114,6 @@ const BoostColor = {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostMessage = {
|
const BoostMessage = {
|
||||||
HUB_PROPERTIES: 0x01,
|
HUB_PROPERTIES: 0x01,
|
||||||
HUB_ACTIONS: 0x02,
|
HUB_ACTIONS: 0x02,
|
||||||
|
@ -125,7 +137,6 @@ const BoostMessage = {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostOutputSubCommand = {
|
const BoostOutputSubCommand = {
|
||||||
START_POWER_PAIR: 0x02,
|
START_POWER_PAIR: 0x02,
|
||||||
SET_ACC_TIME: 0x05,
|
SET_ACC_TIME: 0x05,
|
||||||
|
@ -148,7 +159,6 @@ const BoostOutputSubCommand = {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostOutputExecution = {
|
const BoostOutputExecution = {
|
||||||
// Startup information
|
// Startup information
|
||||||
BUFFER_IF_NECESSARY: 0x00,
|
BUFFER_IF_NECESSARY: 0x00,
|
||||||
|
@ -156,8 +166,6 @@ const BoostOutputExecution = {
|
||||||
// Completion information
|
// Completion information
|
||||||
NO_ACTION: 0x00,
|
NO_ACTION: 0x00,
|
||||||
COMMAND_FEEDBACK: 0x01,
|
COMMAND_FEEDBACK: 0x01,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +175,6 @@ const BoostOutputExecution = {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostMotorEndState = {
|
const BoostMotorEndState = {
|
||||||
FLOAT: 0,
|
FLOAT: 0,
|
||||||
HOLD: 126,
|
HOLD: 126,
|
||||||
|
@ -175,11 +182,10 @@ const BoostMotorEndState = {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for Boost Motor Acceleration/Deceleration profiles
|
* Enum for Boost Motor acceleration/deceleration profiles
|
||||||
* @readyonly
|
* @readyonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostMotorProfile = {
|
const BoostMotorProfile = {
|
||||||
DO_NOT_USE: 0x00,
|
DO_NOT_USE: 0x00,
|
||||||
ACCELERATION: 0x01,
|
ACCELERATION: 0x01,
|
||||||
|
@ -192,7 +198,6 @@ const BoostMotorProfile = {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostIOEvent = {
|
const BoostIOEvent = {
|
||||||
ATTACHED: 0x01,
|
ATTACHED: 0x01,
|
||||||
DETACHED: 0x00,
|
DETACHED: 0x00,
|
||||||
|
@ -200,7 +205,7 @@ const BoostIOEvent = {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for modes for input sensors on the Boost.
|
* Enum for selected sensor modes.
|
||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
const BoostMode = {
|
const BoostMode = {
|
||||||
|
@ -208,7 +213,6 @@ const BoostMode = {
|
||||||
LED: 1, // Set LED to accept RGB values
|
LED: 1, // Set LED to accept RGB values
|
||||||
COLOR: 0, // Read indexed colors from Vision Sensor
|
COLOR: 0, // Read indexed colors from Vision Sensor
|
||||||
MOTOR_SENSOR: 2, // Set motors to report their position
|
MOTOR_SENSOR: 2, // Set motors to report their position
|
||||||
MOTOR_OUTPUT: 0,
|
|
||||||
UNKNOWN: 0 // Anything else will use the default mode (mode 0)
|
UNKNOWN: 0 // Anything else will use the default mode (mode 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -384,28 +388,28 @@ class BoostMotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {int} -
|
* @return {int} - this motor's current position, in the range of [-MIN_INT32,MAX_INT32]
|
||||||
*/
|
*/
|
||||||
get position () {
|
get position () {
|
||||||
return this._position;
|
return this._position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {int} value -
|
* @param {int} value - set this motor's current position.
|
||||||
*/
|
*/
|
||||||
set position (value) {
|
set position (value) {
|
||||||
this._position = value;
|
this._position = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {int} -
|
* @return {int} - this motor's current zero position, which the current position is relative to.
|
||||||
*/
|
*/
|
||||||
get positionZero () {
|
get positionZero () {
|
||||||
return this._positionZero;
|
return this._positionZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {int} value -
|
* @param {int} value - set this motor's zero position.
|
||||||
*/
|
*/
|
||||||
set positionZero (value) {
|
set positionZero (value) {
|
||||||
this._positionZero = value;
|
this._positionZero = value;
|
||||||
|
@ -450,10 +454,10 @@ class BoostMotor {
|
||||||
BoostOutputExecution.EXECUTE_IMMEDIATELY ^ BoostOutputExecution.COMMAND_FEEDBACK,
|
BoostOutputExecution.EXECUTE_IMMEDIATELY ^ BoostOutputExecution.COMMAND_FEEDBACK,
|
||||||
BoostOutputSubCommand.START_SPEED,
|
BoostOutputSubCommand.START_SPEED,
|
||||||
[this._power * this._direction,
|
[this._power * this._direction,
|
||||||
this._power * this._direction,
|
this._power* this._direction,
|
||||||
BoostMotorProfile.DO_NOT_USE]);
|
BoostMotorProfile.DO_NOT_USE]);
|
||||||
|
|
||||||
this._parent.send(BLECharacteristic, cmd);
|
this._parent.send(BoostBLE.characteristic, cmd);
|
||||||
|
|
||||||
this._status = BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS;
|
this._status = BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS;
|
||||||
this._clearTimeout();
|
this._clearTimeout();
|
||||||
|
@ -485,19 +489,19 @@ class BoostMotor {
|
||||||
BoostOutputSubCommand.START_SPEED_FOR_DEGREES,
|
BoostOutputSubCommand.START_SPEED_FOR_DEGREES,
|
||||||
[...numberToInt32Array(degrees),
|
[...numberToInt32Array(degrees),
|
||||||
this._power * this._direction, // power in range 0-100
|
this._power * this._direction, // power in range 0-100
|
||||||
0xFF, // max speed
|
this._power * this._direction, // max speed
|
||||||
BoostMotorEndState.FLOAT,
|
BoostMotorEndState.BRAKE,
|
||||||
BoostMotorProfile.DO_NOT_USE] // byte for using acceleration/braking profile
|
BoostMotorProfile.DO_NOT_USE] // byte for using acceleration/braking profile
|
||||||
);
|
);
|
||||||
|
|
||||||
this._status = BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS;
|
this._status = BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS;
|
||||||
|
this._parent.send(BoostBLE.characteristic, cmd);
|
||||||
this._parent.send(BLECharacteristic, cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start active braking on this motor. After a short time, the motor will turn off.
|
* Start active braking on this motor. After a short time, the motor will turn off.
|
||||||
* // TODO: rename this to coastAfter?
|
* // TODO: rename this to coastAfter?
|
||||||
|
* // TODO: eliminate this function by changing turnOff() to use BoostMotorEndState.BRAKE?
|
||||||
*/
|
*/
|
||||||
startBraking () {
|
startBraking () {
|
||||||
if (this._power === 0) return;
|
if (this._power === 0) return;
|
||||||
|
@ -511,7 +515,7 @@ class BoostMotor {
|
||||||
BoostMotorProfile.DO_NOT_USE]
|
BoostMotorProfile.DO_NOT_USE]
|
||||||
);
|
);
|
||||||
|
|
||||||
this._parent.send(BLECharacteristic, cmd);
|
this._parent.send(BoostBLE.characteristic, cmd);
|
||||||
|
|
||||||
this._status = BoostOutputCommandFeedback.IDLE;
|
this._status = BoostOutputCommandFeedback.IDLE;
|
||||||
this._setNewTimeout(this.turnOff, BoostMotor.BRAKE_TIME_MS);
|
this._setNewTimeout(this.turnOff, BoostMotor.BRAKE_TIME_MS);
|
||||||
|
@ -533,7 +537,7 @@ class BoostMotor {
|
||||||
BoostMotorProfile.DO_NOT_USE]
|
BoostMotorProfile.DO_NOT_USE]
|
||||||
);
|
);
|
||||||
|
|
||||||
this._parent.send(BLECharacteristic, cmd, useLimiter);
|
this._parent.send(BoostBLE.characteristic, cmd, useLimiter);
|
||||||
|
|
||||||
this._status = BoostOutputCommandFeedback.IDLE;
|
this._status = BoostOutputCommandFeedback.IDLE;
|
||||||
}
|
}
|
||||||
|
@ -615,7 +619,6 @@ class Boost {
|
||||||
this._sensors = {
|
this._sensors = {
|
||||||
tiltX: 0,
|
tiltX: 0,
|
||||||
tiltY: 0,
|
tiltY: 0,
|
||||||
distance: 0,
|
|
||||||
color: 0,
|
color: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -662,10 +665,11 @@ class Boost {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} - the latest value received from the distance sensor.
|
* @return {number} - the latest value received from the distance sensor.
|
||||||
*/
|
*//*
|
||||||
get distance () {
|
get distance () {
|
||||||
return this._sensors.distance;
|
return this._sensors.distance;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} - the latest color value received from the vision sensor.
|
* @return {number} - the latest color value received from the vision sensor.
|
||||||
|
@ -717,7 +721,7 @@ class Boost {
|
||||||
...rgb]
|
...rgb]
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.send(BLECharacteristic, cmd);
|
return this.send(BoostBLE.characteristic, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -732,7 +736,7 @@ class Boost {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.send(BLECharacteristic, cmd);
|
return this.send(BoostBLE.characteristic, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,7 +756,7 @@ class Boost {
|
||||||
}
|
}
|
||||||
this._ble = new BLE(this._runtime, this._extensionId, {
|
this._ble = new BLE(this._runtime, this._extensionId, {
|
||||||
filters: [{
|
filters: [{
|
||||||
services: [BLEService],
|
services: [BoostBLE.service],
|
||||||
manufacturerData: {
|
manufacturerData: {
|
||||||
0: {
|
0: {
|
||||||
dataPrefix: [0x97, 0x03, 0x00, 0x40],
|
dataPrefix: [0x97, 0x03, 0x00, 0x40],
|
||||||
|
@ -783,7 +787,6 @@ class Boost {
|
||||||
this._sensors = {
|
this._sensors = {
|
||||||
tiltX: 0,
|
tiltX: 0,
|
||||||
tiltY: 0,
|
tiltY: 0,
|
||||||
distance: 0,
|
|
||||||
color: 0
|
color: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -819,7 +822,7 @@ class Boost {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._ble.write(
|
return this._ble.write(
|
||||||
BLEService,
|
BoostBLE.service,
|
||||||
uuid,
|
uuid,
|
||||||
Base64Util.uint8ArrayToBase64(message),
|
Base64Util.uint8ArrayToBase64(message),
|
||||||
'base64'
|
'base64'
|
||||||
|
@ -880,8 +883,8 @@ class Boost {
|
||||||
*/
|
*/
|
||||||
_onConnect () {
|
_onConnect () {
|
||||||
this._ble.startNotifications(
|
this._ble.startNotifications(
|
||||||
BLEService,
|
BoostBLE.service,
|
||||||
BLECharacteristic,
|
BoostBLE.characteristic,
|
||||||
this._onMessage
|
this._onMessage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -918,7 +921,7 @@ class Boost {
|
||||||
const event = data[4]
|
const event = data[4]
|
||||||
const typeId = data[5]
|
const typeId = data[5]
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case BoostIOEvent.ATTACHED:
|
case BoostIOEvent.ATTACHED:
|
||||||
this._registerSensorOrMotor(portID, typeId)
|
this._registerSensorOrMotor(portID, typeId)
|
||||||
break;
|
break;
|
||||||
|
@ -949,6 +952,7 @@ class Boost {
|
||||||
if (value > 0x7fffffff) {
|
if (value > 0x7fffffff) {
|
||||||
value = value - 0x100000000;
|
value = value - 0x100000000;
|
||||||
}*/
|
}*/
|
||||||
|
//console.log(data)
|
||||||
this._motors[portID]._position = int32ArrayToNumber(data.slice(4,8))
|
this._motors[portID]._position = int32ArrayToNumber(data.slice(4,8))
|
||||||
break;
|
break;
|
||||||
case BoostIO.CURRENT:
|
case BoostIO.CURRENT:
|
||||||
|
@ -971,18 +975,16 @@ class Boost {
|
||||||
case BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS:
|
case BoostOutputCommandFeedback.BUFFER_EMPTY_COMMAND_IN_PROGRESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log(buf2hex(data))
|
|
||||||
console.log("Got it but didn't find a motor on: " + portID)
|
console.log("Got it but didn't find a motor on: " + portID)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BoostMessage.PORT_INPUT_FORMAT:
|
|
||||||
case BoostMessage.ERROR:
|
case BoostMessage.ERROR:
|
||||||
//DEBUG
|
//DEBUG
|
||||||
console.log(buf2hex(data))
|
console.log("Error in BLE message: " + buf2hex(data))
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//DEBUG
|
//DEBUG
|
||||||
console.log(buf2hex(data))
|
//console.log(buf2hex(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -998,45 +1000,48 @@ class Boost {
|
||||||
// Record which port is connected to what type of device
|
// Record which port is connected to what type of device
|
||||||
this._ports[portID] = type;
|
this._ports[portID] = type;
|
||||||
|
|
||||||
|
|
||||||
// Record motor port
|
// Record motor port
|
||||||
if (type === BoostIO.MOTORINT || type === BoostIO.MOTOREXT) {
|
if (type === BoostIO.MOTORINT || type === BoostIO.MOTOREXT) {
|
||||||
this._motors[portID] = new BoostMotor(this, portID);
|
this._motors[portID] = new BoostMotor(this, portID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set input format for tilt or distance sensor
|
// Set input format for tilt or distance sensor
|
||||||
var typeString = ''
|
|
||||||
|
var m = null
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case BoostIO.MOTORINT:
|
case BoostIO.MOTORINT:
|
||||||
case BoostIO.MOTOREXT:
|
case BoostIO.MOTOREXT:
|
||||||
typeString = 'MOTOR_SENSOR'
|
m = BoostMode.MOTOR_SENSOR
|
||||||
break;
|
break;
|
||||||
case BoostIO.COLOR:
|
case BoostIO.COLOR:
|
||||||
typeString = 'COLOR'
|
m = BoostMode.COLOR
|
||||||
break;
|
break;
|
||||||
case BoostIO.LED:
|
case BoostIO.LED:
|
||||||
typeString = 'LED'
|
m = BoostMode.LED
|
||||||
this.setLEDMode();
|
this.setLEDMode();
|
||||||
this.setLED(0x00FF00);
|
this.setLED(0x00FF00);
|
||||||
break;
|
break;
|
||||||
case BoostIO.TILT:
|
case BoostIO.TILT:
|
||||||
typeString = 'TILT'
|
m = BoostMode.TILT
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
typeString = 'UNKNOWN'
|
m = BoostMode.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmd = this.generateInputCommand(
|
const cmd = this.generateInputCommand(
|
||||||
portID,
|
portID,
|
||||||
BoostMode[typeString],
|
m,
|
||||||
1,
|
1,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
this.send(BLECharacteristic, cmd);
|
this.send(BoostBLE.characteristic, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the sensor or motor present at port 1 or 2.
|
* Clear the sensors or motors present on the ports.
|
||||||
* @param {number} portID - the port to clear.
|
* @param {number} portID - the port to clear.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -1045,8 +1050,8 @@ class Boost {
|
||||||
if (type === BoostIO.TILT) {
|
if (type === BoostIO.TILT) {
|
||||||
this._sensors.tiltX = this._sensors.tiltY = 0;
|
this._sensors.tiltX = this._sensors.tiltY = 0;
|
||||||
}
|
}
|
||||||
if (type === BoostIO.DISTANCE) {
|
if (type === BoostIO.COLOR) {
|
||||||
this._sensors.distance = 0;
|
this._sensors.color = 0;
|
||||||
}
|
}
|
||||||
this._ports[portID] = 'none';
|
this._ports[portID] = 'none';
|
||||||
this._motors[portID] = null;
|
this._motors[portID] = null;
|
||||||
|
@ -1219,7 +1224,7 @@ class Scratch3BoostBlocks {
|
||||||
MOTOR_ID: {
|
MOTOR_ID: {
|
||||||
type: ArgumentType.STRING,
|
type: ArgumentType.STRING,
|
||||||
menu: 'MOTOR_ID',
|
menu: 'MOTOR_ID',
|
||||||
defaultValue: BoostMotorLabel.A
|
defaultValue: BoostMotorLabel.ALL
|
||||||
},
|
},
|
||||||
POWER: {
|
POWER: {
|
||||||
type: ArgumentType.NUMBER,
|
type: ArgumentType.NUMBER,
|
||||||
|
@ -1355,7 +1360,7 @@ class Scratch3BoostBlocks {
|
||||||
description: 'the value returned by the distance sensor'
|
description: 'the value returned by the distance sensor'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.REPORTER
|
blockType: BlockType.REPORTER
|
||||||
},
|
},*/
|
||||||
{
|
{
|
||||||
opcode: 'isTilted',
|
opcode: 'isTilted',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
|
@ -1371,7 +1376,7 @@ class Scratch3BoostBlocks {
|
||||||
defaultValue: BoostTiltDirection.ANY
|
defaultValue: BoostTiltDirection.ANY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},*/
|
},
|
||||||
{
|
{
|
||||||
opcode: 'getTiltAngle',
|
opcode: 'getTiltAngle',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
|
@ -1918,19 +1923,29 @@ class Scratch3BoostBlocks {
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
getMotorPosition (args) {
|
getMotorPosition (args) {
|
||||||
|
var portID = null
|
||||||
switch(args.MOTOR_REPORTER_ID) {
|
switch(args.MOTOR_REPORTER_ID) {
|
||||||
|
|
||||||
case BoostMotorLabel.A:
|
case BoostMotorLabel.A:
|
||||||
return this._peripheral._motors[BoostPort.A].position - this._peripheral._motors[BoostPort.A].positionZero
|
portID = BoostPort.A
|
||||||
|
break;
|
||||||
case BoostMotorLabel.B:
|
case BoostMotorLabel.B:
|
||||||
return this._peripheral._motors[BoostPort.B].position - this._peripheral._motors[BoostPort.B].positionZero
|
portID = BoostPort.B
|
||||||
|
break;
|
||||||
case BoostMotorLabel.C:
|
case BoostMotorLabel.C:
|
||||||
return this._peripheral._motors[BoostPort.C].position - this._peripheral._motors[BoostPort.C].positionZero
|
portID = BoostPort.C
|
||||||
|
break;
|
||||||
case BoostMotorLabel.D:
|
case BoostMotorLabel.D:
|
||||||
return this._peripheral._motors[BoostPort.D].position - this._peripheral._motors[BoostPort.D].positionZero
|
portID = BoostPort.D
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log.warn("Asked for a motor position that doesnt exist!")
|
log.warn("Asked for a motor position that doesnt exist!")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(portID && this._peripheral._motors[portID]) {
|
||||||
|
return this._peripheral._motors[portID].position - this._peripheral._motors[portID].positionZero
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue