From 4041fbadc338bc9a9470dde5c7f9fce9f94ecf99 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Thu, 11 Jul 2019 16:10:23 -0400 Subject: [PATCH 1/7] Changed port-mapping to reflect firmware update. --- src/extensions/scratch3_boost/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 8934d5a77..b88178115 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -94,10 +94,10 @@ const BoostPortFeedback = { * @enum {number} */ const BoostPort = { - A: 55, - B: 56, - C: 1, - D: 2 + A: 0, + B: 1, + C: 2, + D: 3 }; /** From dcccae9656911ddfdbfa4fcfbf703daefb03555d Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Thu, 11 Jul 2019 16:23:07 -0400 Subject: [PATCH 2/7] Add case to onMessage to catch responses from the LED --- src/extensions/scratch3_boost/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index b88178115..62b0b006f 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1012,6 +1012,7 @@ class Boost { break; case BoostIO.CURRENT: case BoostIO.VOLTAGE: + case BoostIO.LED: break; default: log.warn(`Unknown sensor value! Type: ${type}`); From e7634d50faed1942298fec6631a3bfc542fef5b3 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Fri, 26 Jul 2019 14:12:05 -0400 Subject: [PATCH 3/7] Add port mappings to support older firmware version 2.0.00.0016 and later as well as newer firmware version 2.0.00.0017 or newer --- src/extensions/scratch3_boost/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 62b0b006f..6c14fd258 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -93,13 +93,24 @@ const BoostPortFeedback = { * @readonly * @enum {number} */ -const BoostPort = { + +const BoostPort20000016OrOlder = { + A: 55, + B: 56, + C: 0, + D: 1 +}; + +const BoostPort20000017OrNewer = { A: 0, B: 1, C: 2, D: 3 }; +// Set default port mapping to support the newer firmware +let BoostPort = BoostPort20000017OrNewer; + /** * Ids for each color sensor value used by the extension. * @readonly From fcbac7516e2914d56af5839e055a1803ffda8192 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Fri, 26 Jul 2019 15:31:37 -0400 Subject: [PATCH 4/7] This commit addresses a discussion in #2229 around backward compatibility. This change creates two different port mappings for the Move Hub. By default the extension will use the newer mapping introduced in firmware version 1.0.00.0224. When connected to the hub, the extension will request the hub's firmware version. If it's older than 1.0.00.0224 it will use the older mapping. --- src/extensions/scratch3_boost/index.js | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 6c14fd258..42c309ff5 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -165,6 +165,45 @@ const BoostMessage = { PORT_FEEDBACK: 0x82 }; +/** + * Enum for Hub Property Types + * @readonly + * @enum {number} + */ + +const BoostHubProperty = { + ADVERTISEMENT_NAME: 0x01, + BUTTON: 0x02, + FW_VERSION: 0x03, + HW_VERSION: 0x04, + RSSI: 0x05, + BATTERY_VOLTAGE: 0x06, + BATTERY_TYPE: 0x07, + MANUFACTURER_NAME: 0x08, + RADIO_FW_VERSION: 0x09, + LEGO_WP_VERSION: 0x0A, + SYSTEM_TYPE_ID: 0x0B, + HW_NETWORK_ID: 0x0C, + PRIMARY_MAC: 0x0D, + SECONDARY_MAC: 0x0E, + HW_NETWORK_FAMILY: 0x0F +}; + +/** + * Enum for Hub Property Operations + * @readonly + * @enum {number} + */ + +const BoostHubPropertyOperation = { + SET: 0x01, + ENABLE_UPDATES: 0x02, + DISABLE_UPDATES: 0x03, + RESET: 0x04, + REQUEST_UPDATE: 0x05, + UPDATE: 0x06 +}; + /** * Enum for Motor Subcommands (for 0x81) * @readonly @@ -956,6 +995,19 @@ class Boost { this._onMessage ); this._pingDeviceId = window.setInterval(this._pingDevice, BoostPingInterval); + + // Send a request for firmware version. + setTimeout(() => { + const command = [ + 0x00, // Hub ID + BoostMessage.HUB_PROPERTIES, + BoostHubProperty.FW_VERSION, + BoostHubPropertyOperation.REQUEST_UPDATE + ]; + command.unshift(command.length + 1); + this.send(BoostBLE.characteristic, command, false); + }, 500); + } /** @@ -979,6 +1031,25 @@ class Boost { const portID = data[3]; switch (messageType) { + + case BoostMessage.HUB_PROPERTIES: { + const property = data[3]; + switch (property) { + case BoostHubProperty.FW_VERSION: { + // Establish firmware version 1.0.00.0224 as a 32-bit signed integer (little endian) + const fwVersion10000224 = int32ArrayToNumber([0x24, 0x02, 0x00, 0x10]); + const fwHub = int32ArrayToNumber(data.slice(5, data.length)); + if (fwHub < fwVersion10000224) { + BoostPort = BoostPort20000016OrOlder; + log.info('Move Hub firmware older than version 1.0.00.0224 detected. Using old port mapping.'); + } else { + BoostPort = BoostPort20000017OrNewer; + } + break; + } + } + break; + } case BoostMessage.HUB_ATTACHED_IO: { // IO Attach/Detach events const event = data[4]; const typeId = data[5]; From 842a8e97780a7383e600556091e9951b4cd282ee Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Fri, 26 Jul 2019 15:34:26 -0400 Subject: [PATCH 5/7] Adjusted portmapping variables to match firmware versions correctly --- src/extensions/scratch3_boost/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 42c309ff5..676a99c6d 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -94,14 +94,14 @@ const BoostPortFeedback = { * @enum {number} */ -const BoostPort20000016OrOlder = { +const BoostPort10000223OrOlder = { A: 55, B: 56, C: 0, D: 1 }; -const BoostPort20000017OrNewer = { +const BoostPort10000224OrNewer = { A: 0, B: 1, C: 2, @@ -109,7 +109,7 @@ const BoostPort20000017OrNewer = { }; // Set default port mapping to support the newer firmware -let BoostPort = BoostPort20000017OrNewer; +let BoostPort = BoostPort10000224OrNewer; /** * Ids for each color sensor value used by the extension. @@ -1040,10 +1040,10 @@ class Boost { const fwVersion10000224 = int32ArrayToNumber([0x24, 0x02, 0x00, 0x10]); const fwHub = int32ArrayToNumber(data.slice(5, data.length)); if (fwHub < fwVersion10000224) { - BoostPort = BoostPort20000016OrOlder; + BoostPort = BoostPort10000223OrOlder; log.info('Move Hub firmware older than version 1.0.00.0224 detected. Using old port mapping.'); } else { - BoostPort = BoostPort20000017OrNewer; + BoostPort = BoostPort10000224OrNewer; } break; } From 4523597a04cbb73c50707db65769b8b15ade18f3 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Mon, 29 Jul 2019 17:59:16 -0400 Subject: [PATCH 6/7] Corrected old port mapping! Thanks for catching that @ericr. --- src/extensions/scratch3_boost/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 676a99c6d..cf460d5a4 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -97,8 +97,8 @@ const BoostPortFeedback = { const BoostPort10000223OrOlder = { A: 55, B: 56, - C: 0, - D: 1 + C: 1, + D: 2 }; const BoostPort10000224OrNewer = { From 7d7ce2db13403bbd7c09fe4f4de1a7dfa90d62a1 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Tue, 30 Jul 2019 10:20:34 -0400 Subject: [PATCH 7/7] Fixed issue where port A motor position was not being reported because the port number was false-y --- src/extensions/scratch3_boost/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index cf460d5a4..594009a23 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1935,7 +1935,7 @@ class Scratch3BoostBlocks { log.warn('Asked for a motor position that doesnt exist!'); return false; } - if (portID && this._peripheral.motor(portID)) { + if (portID !== null && this._peripheral.motor(portID)) { let val = this._peripheral.motor(portID).position; // Boost motor A position direction is reversed by design // so we have to reverse the position here