mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
added named variables to onMessage for readability. Changed wording of motor-blocks. Added BLE Advertisement Manufacturer Data as filter for scanning, for https://github.com/LLK/scratch-link/issues/112
This commit is contained in:
parent
5822f762ca
commit
bf02426a4a
1 changed files with 29 additions and 27 deletions
|
@ -366,8 +366,6 @@ class BoostMotor {
|
||||||
*/
|
*/
|
||||||
turnOn () {
|
turnOn () {
|
||||||
if (this._power === 0) return;
|
if (this._power === 0) return;
|
||||||
//console.log(this._index)
|
|
||||||
//console.log(this._power * this._direction)
|
|
||||||
const cmd = this._parent.generateOutputCommand(
|
const cmd = this._parent.generateOutputCommand(
|
||||||
this._index,
|
this._index,
|
||||||
0x51,
|
0x51,
|
||||||
|
@ -677,7 +675,13 @@ class Boost {
|
||||||
}
|
}
|
||||||
this._ble = new BLE(this._runtime, this._extensionId, {
|
this._ble = new BLE(this._runtime, this._extensionId, {
|
||||||
filters: [{
|
filters: [{
|
||||||
services: [BLEService]
|
services: [BLEService],
|
||||||
|
manufacturerData: {
|
||||||
|
0x0397: {
|
||||||
|
dataPrefix: [0x97, 0x03, 0x00, 0x40],
|
||||||
|
mask: [0xFF, 0xFF, 0, 0xFF]
|
||||||
|
}
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
optionalServices: []
|
optionalServices: []
|
||||||
}, this._onConnect);
|
}, this._onConnect);
|
||||||
|
@ -777,7 +781,6 @@ class Boost {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
command.unshift(command.length +1)
|
command.unshift(command.length +1)
|
||||||
console.log(buf2hex(command))
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,9 +810,6 @@ class Boost {
|
||||||
|
|
||||||
command.unshift(command.length+1) // Prepend payload with length byte
|
command.unshift(command.length+1) // Prepend payload with length byte
|
||||||
|
|
||||||
//DEBUG
|
|
||||||
console.log(buf2hex(command))
|
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,21 +842,25 @@ class Boost {
|
||||||
* We base our switch-case on Message Type
|
* We base our switch-case on Message Type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var messageType = data[2];
|
const messageType = data[2];
|
||||||
var portID = data[3];
|
const portID = data[3];
|
||||||
|
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case BoostMessageTypes.HUB_ATTACHED_IO: // IO Attach/Detach events
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 3: Port ID
|
|
||||||
* 4: Event
|
* 4: Event
|
||||||
* 5: IO Type ID
|
* 5: IO Type ID
|
||||||
*/
|
*/
|
||||||
switch (data[4]) {
|
|
||||||
|
case BoostMessageTypes.HUB_ATTACHED_IO: // IO Attach/Detach events
|
||||||
|
|
||||||
|
const event = data[4]
|
||||||
|
const typeId = data[5]
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
case BoostIOEvent.ATTACHED:
|
case BoostIOEvent.ATTACHED:
|
||||||
//case BoostIOEvent.ATTACHED_VIRTUAL:
|
//case BoostIOEvent.ATTACHED_VIRTUAL:
|
||||||
this._registerSensorOrMotor(portID, data[5])
|
this._registerSensorOrMotor(portID, typeId)
|
||||||
break;
|
break;
|
||||||
case BoostIOEvent.DETACHED:
|
case BoostIOEvent.DETACHED:
|
||||||
this._clearPort(portID);
|
this._clearPort(portID);
|
||||||
|
@ -866,9 +870,7 @@ class Boost {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BoostMessageTypes.PORT_VALUE:
|
case BoostMessageTypes.PORT_VALUE:
|
||||||
//console.log(buf2hex(data))
|
|
||||||
var type = this._ports[portID];
|
var type = this._ports[portID];
|
||||||
//var valueFormat = data.length
|
|
||||||
// TODO: Build a proper value-formatting based on the PORT_INPUT_FORMAT-messages instead of hardcoding value-handling
|
// TODO: Build a proper value-formatting based on the PORT_INPUT_FORMAT-messages instead of hardcoding value-handling
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case BoostDevice.TILT:
|
case BoostDevice.TILT:
|
||||||
|
@ -1069,7 +1071,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'motorOnFor',
|
opcode: 'motorOnFor',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorOnFor',
|
id: 'boost.motorOnFor',
|
||||||
default: 'turn [MOTOR_ID] on for [DURATION] seconds',
|
default: 'turn motor [MOTOR_ID] on for [DURATION] seconds',
|
||||||
description: 'turn a motor on for some time'
|
description: 'turn a motor on for some time'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1089,7 +1091,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'motorOnForRotation',
|
opcode: 'motorOnForRotation',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorOnForRotation',
|
id: 'boost.motorOnForRotation',
|
||||||
default: 'turn [MOTOR_ID] on for [ROTATION] rotations',
|
default: 'turn motor [MOTOR_ID] on for [ROTATION] rotations',
|
||||||
description: 'turn a motor on for rotation'
|
description: 'turn a motor on for rotation'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1109,7 +1111,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'motorOn',
|
opcode: 'motorOn',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorOn',
|
id: 'boost.motorOn',
|
||||||
default: 'turn [MOTOR_ID] on',
|
default: 'turn motor [MOTOR_ID] on',
|
||||||
description: 'turn a motor on indefinitely'
|
description: 'turn a motor on indefinitely'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1125,7 +1127,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'motorOff',
|
opcode: 'motorOff',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorOff',
|
id: 'boost.motorOff',
|
||||||
default: 'turn [MOTOR_ID] off',
|
default: 'turn motor [MOTOR_ID] off',
|
||||||
description: 'turn a motor off'
|
description: 'turn a motor off'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1141,7 +1143,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'startMotorPower',
|
opcode: 'startMotorPower',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.startMotorPower',
|
id: 'boost.startMotorPower',
|
||||||
default: 'set [MOTOR_ID] power to [POWER]',
|
default: 'set motor [MOTOR_ID] power to [POWER] %',
|
||||||
description: 'set the motor\'s power and turn it on'
|
description: 'set the motor\'s power and turn it on'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1161,7 +1163,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'setMotorDirection',
|
opcode: 'setMotorDirection',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.setMotorDirection',
|
id: 'boost.setMotorDirection',
|
||||||
default: 'set [MOTOR_ID] direction to [MOTOR_DIRECTION]',
|
default: 'set motor [MOTOR_ID] direction to [MOTOR_DIRECTION]',
|
||||||
description: 'set the motor\'s turn direction'
|
description: 'set the motor\'s turn direction'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1182,7 +1184,7 @@ class Scratch3BoostBlocks {
|
||||||
opcode: 'motorZero',
|
opcode: 'motorZero',
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorZero',
|
id: 'boost.motorZero',
|
||||||
default: 'zero [MOTOR_ID]',
|
default: 'zero motor [MOTOR_ID]',
|
||||||
description: 'set a motor\'s position to 0'
|
description: 'set a motor\'s position to 0'
|
||||||
}),
|
}),
|
||||||
blockType: BlockType.COMMAND,
|
blockType: BlockType.COMMAND,
|
||||||
|
@ -1334,7 +1336,7 @@ class Scratch3BoostBlocks {
|
||||||
{
|
{
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorId.a',
|
id: 'boost.motorId.a',
|
||||||
default: 'motor A',
|
default: 'A',
|
||||||
description: 'label for motor A element in motor menu for LEGO Boost extension'
|
description: 'label for motor A element in motor menu for LEGO Boost extension'
|
||||||
}),
|
}),
|
||||||
value: BoostMotorLabel.A
|
value: BoostMotorLabel.A
|
||||||
|
@ -1342,7 +1344,7 @@ class Scratch3BoostBlocks {
|
||||||
{
|
{
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorId.b',
|
id: 'boost.motorId.b',
|
||||||
default: 'motor B',
|
default: 'B',
|
||||||
description: 'label for motor B element in motor menu for LEGO Boost extension'
|
description: 'label for motor B element in motor menu for LEGO Boost extension'
|
||||||
}),
|
}),
|
||||||
value: BoostMotorLabel.B
|
value: BoostMotorLabel.B
|
||||||
|
@ -1350,7 +1352,7 @@ class Scratch3BoostBlocks {
|
||||||
{
|
{
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorId.c',
|
id: 'boost.motorId.c',
|
||||||
default: 'motor C',
|
default: 'C',
|
||||||
description: 'label for motor C element in motor menu for LEGO Boost extension'
|
description: 'label for motor C element in motor menu for LEGO Boost extension'
|
||||||
}),
|
}),
|
||||||
value: BoostMotorLabel.C
|
value: BoostMotorLabel.C
|
||||||
|
@ -1358,7 +1360,7 @@ class Scratch3BoostBlocks {
|
||||||
{
|
{
|
||||||
text: formatMessage({
|
text: formatMessage({
|
||||||
id: 'boost.motorId.d',
|
id: 'boost.motorId.d',
|
||||||
default: 'motor D',
|
default: 'D',
|
||||||
description: 'label for motor D element in motor menu for LEGO Boost extension'
|
description: 'label for motor D element in motor menu for LEGO Boost extension'
|
||||||
}),
|
}),
|
||||||
value: BoostMotorLabel.D
|
value: BoostMotorLabel.D
|
||||||
|
|
Loading…
Reference in a new issue