mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Cleaned up documentation and removed extra line breaks in response to @evhan55 PR comments
This commit is contained in:
parent
601c9d230f
commit
7f0355169e
2 changed files with 36 additions and 52 deletions
45
package-lock.json
generated
45
package-lock.json
generated
|
@ -5481,8 +5481,7 @@
|
||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"aproba": {
|
"aproba": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
|
@ -5503,14 +5502,12 @@
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
|
@ -5525,20 +5522,17 @@
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
|
@ -5655,8 +5649,7 @@
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
|
@ -5668,7 +5661,6 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
@ -5683,7 +5675,6 @@
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
|
@ -5691,14 +5682,12 @@
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.1",
|
"safe-buffer": "^5.1.1",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "^3.0.0"
|
||||||
|
@ -5717,7 +5706,6 @@
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
|
@ -5798,8 +5786,7 @@
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
|
@ -5811,7 +5798,6 @@
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
|
@ -5897,8 +5883,7 @@
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"safer-buffer": {
|
"safer-buffer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
|
@ -5934,7 +5919,6 @@
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
|
@ -5954,7 +5938,6 @@
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
|
@ -5998,14 +5981,12 @@
|
||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8409,7 +8390,6 @@
|
||||||
"version": "0.1.4",
|
"version": "0.1.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"kind-of": "^3.0.2",
|
"kind-of": "^3.0.2",
|
||||||
"longest": "^1.0.1",
|
"longest": "^1.0.1",
|
||||||
|
@ -9592,8 +9572,7 @@
|
||||||
"longest": {
|
"longest": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"loose-envify": {
|
"loose-envify": {
|
||||||
"version": "1.3.1",
|
"version": "1.3.1",
|
||||||
|
|
|
@ -25,7 +25,6 @@ const iconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5z
|
||||||
* Boost BLE UUIDs.
|
* Boost BLE UUIDs.
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostBLE = {
|
const BoostBLE = {
|
||||||
service: '00001623-1212-efde-1623-785feabcd123',
|
service: '00001623-1212-efde-1623-785feabcd123',
|
||||||
characteristic: '00001624-1212-efde-1623-785feabcd123',
|
characteristic: '00001624-1212-efde-1623-785feabcd123',
|
||||||
|
@ -37,7 +36,6 @@ const BoostBLE = {
|
||||||
* Boost Motor Max Power.
|
* Boost Motor Max Power.
|
||||||
* @constant {number}
|
* @constant {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostMotorMaxPower = 100;
|
const BoostMotorMaxPower = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +48,6 @@ const BoostPingInterval = 5000;
|
||||||
* The number of continuous samples the color-sensor will evaluate color from.
|
* The number of continuous samples the color-sensor will evaluate color from.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BoostColorSampleSize = 5;
|
const BoostColorSampleSize = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -596,6 +593,11 @@ class Boost {
|
||||||
color: BoostColor.NONE
|
color: BoostColor.NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of values from the Boost Vision Sensor.
|
||||||
|
* @type {Array}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this._colorBucket = [];
|
this._colorBucket = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -820,7 +822,7 @@ class Boost {
|
||||||
generateOutputCommand (portID, execution, subCommand, payload) {
|
generateOutputCommand (portID, execution, subCommand, payload) {
|
||||||
const hubID = 0x00;
|
const hubID = 0x00;
|
||||||
const command = [hubID, BoostMessage.OUTPUT, portID, execution, subCommand, ...payload];
|
const command = [hubID, BoostMessage.OUTPUT, portID, execution, subCommand, ...payload];
|
||||||
command.unshift(command.length + 1);
|
command.unshift(command.length + 1); // Prepend payload with length byte;
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
@ -848,14 +850,13 @@ class Boost {
|
||||||
].concat(numberToInt32Array(delta)).concat([
|
].concat(numberToInt32Array(delta)).concat([
|
||||||
enableNotifications
|
enableNotifications
|
||||||
]);
|
]);
|
||||||
|
command.unshift(command.length + 1); // Prepend payload with length byte;
|
||||||
|
|
||||||
command.unshift(command.length + 1);
|
return command;
|
||||||
|
|
||||||
return command; // Prepend payload with length byte;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets LED mode and initial color and starts reading data from peripheral after BLE has connected.
|
* Starts reading data from peripheral after BLE has connected.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_onConnect () {
|
_onConnect () {
|
||||||
|
@ -880,6 +881,7 @@ class Boost {
|
||||||
* 0: Length of message
|
* 0: Length of message
|
||||||
* 1: Hub ID (always 0x00 at the moment)
|
* 1: Hub ID (always 0x00 at the moment)
|
||||||
* 2: Message Type
|
* 2: Message Type
|
||||||
|
* 3: Port ID
|
||||||
* We base our switch-case on Message Type
|
* We base our switch-case on Message Type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -887,12 +889,6 @@ class Boost {
|
||||||
const portID = data[3];
|
const portID = data[3];
|
||||||
|
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
|
|
||||||
/*
|
|
||||||
* 4: Event
|
|
||||||
* 5: IO Type ID
|
|
||||||
*/
|
|
||||||
|
|
||||||
case BoostMessage.HUB_ATTACHED_IO: { // IO Attach/Detach events
|
case BoostMessage.HUB_ATTACHED_IO: { // IO Attach/Detach events
|
||||||
const event = data[4];
|
const event = data[4];
|
||||||
const typeId = data[5];
|
const typeId = data[5];
|
||||||
|
@ -965,8 +961,8 @@ class Boost {
|
||||||
* Ping the Boost hub. If the Boost hub has disconnected
|
* Ping the Boost hub. If the Boost hub has disconnected
|
||||||
* for some reason, the BLE socket will get an error back and automatically
|
* for some reason, the BLE socket will get an error back and automatically
|
||||||
* close the socket.
|
* close the socket.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_pingDevice () {
|
_pingDevice () {
|
||||||
this._ble.read(
|
this._ble.read(
|
||||||
BoostBLE.service,
|
BoostBLE.service,
|
||||||
|
@ -987,14 +983,12 @@ 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
|
||||||
|
|
||||||
let mode = null;
|
let mode = null;
|
||||||
let delta = 1;
|
let delta = 1;
|
||||||
|
|
||||||
|
@ -1009,6 +1003,10 @@ class Boost {
|
||||||
break;
|
break;
|
||||||
case BoostIO.LED:
|
case BoostIO.LED:
|
||||||
mode = BoostMode.LED;
|
mode = BoostMode.LED;
|
||||||
|
/**
|
||||||
|
* Sets the LED to blue to give an indication on the hub
|
||||||
|
* that it has connected successfully.
|
||||||
|
*/
|
||||||
this.setLEDMode();
|
this.setLEDMode();
|
||||||
this.setLED(0x0000FF);
|
this.setLED(0x0000FF);
|
||||||
break;
|
break;
|
||||||
|
@ -1023,7 +1021,7 @@ class Boost {
|
||||||
portID,
|
portID,
|
||||||
mode,
|
mode,
|
||||||
delta,
|
delta,
|
||||||
true
|
true // Receive feedback
|
||||||
);
|
);
|
||||||
|
|
||||||
this.send(BoostBLE.characteristic, cmd);
|
this.send(BoostBLE.characteristic, cmd);
|
||||||
|
@ -1636,6 +1634,10 @@ class Scratch3BoostBlocks {
|
||||||
motors.push(motorIndex);
|
motors.push(motorIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the motors given in args.MOTOR_ID exist,
|
||||||
|
* and maps a promise for each of the motor-commands to an array.
|
||||||
|
*/
|
||||||
const promises = motors.map(portID => {
|
const promises = motors.map(portID => {
|
||||||
const motor = this._peripheral.motor(portID);
|
const motor = this._peripheral.motor(portID);
|
||||||
if (motor) {
|
if (motor) {
|
||||||
|
@ -1646,7 +1648,10 @@ class Scratch3BoostBlocks {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
// To prevent the block from returning a value, an empty function is added to the .then
|
/**
|
||||||
|
* Make sure all promises are resolved, i.e. all motor-commands have completed.
|
||||||
|
* To prevent the block from returning a value, an empty function is added to the .then
|
||||||
|
*/
|
||||||
return Promise.all(promises).then(() => {});
|
return Promise.all(promises).then(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue