From d7eaf6341470c4902ef0e8b0fcc44a41b2c61dbb Mon Sep 17 00:00:00 2001 From: Tnks2U Date: Mon, 24 Apr 2023 18:33:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EB=A7=88=EC=9D=B4=ED=81=AC=EB=A1=9C?= =?UTF-8?q?=EB=B9=84=ED=8A=B82=20=EC=9B=B9=EC=97=B0=EA=B2=B0=20=EC=84=BC?= =?UTF-8?q?=EC=84=9C=EA=B0=92=20=EC=98=A4=EB=A5=98=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hardwareLite/block_microbit2_lite.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/playground/blocks/hardwareLite/block_microbit2_lite.js b/src/playground/blocks/hardwareLite/block_microbit2_lite.js index a74f28e860..dc2f70e81e 100644 --- a/src/playground/blocks/hardwareLite/block_microbit2_lite.js +++ b/src/playground/blocks/hardwareLite/block_microbit2_lite.js @@ -4,12 +4,12 @@ const _throttle = require('lodash/throttle'); const EVENT_INTERVAL = 150; -(function () { +(function() { Entry.Microbit2lite = new (class Microbit2Lite { constructor() { this.commandStatus = {}; this.btnEventIntervalId = -1; - this.retryLimitCnt = 5; + this.retryLimitCnt = 3; this.portData = { baudRate: 115200, dataBits: 8, @@ -292,7 +292,7 @@ const EVENT_INTERVAL = 150; async initialHandshake() { const defaultCMD = `${this.functionKeys.LOCALDATA}`; - const response = await Entry.hwLite.sendAsync(defaultCMD); + const response = await Entry.hwLite.sendAsyncWithThrottle(defaultCMD); if (response && response.indexOf('localdata') > -1) { const version = response.split(';')[1]; if (!version) { @@ -306,14 +306,19 @@ const EVENT_INTERVAL = 150; if (this.version === '2') { Entry.addEventListener('run', this.handleBtnEventInterval.bind(this)); - Entry.addEventListener('beforeStop', () => { clearInterval(this.btnEventIntervalId) }); + Entry.addEventListener('beforeStop', () => { + clearInterval(this.btnEventIntervalId); + }); } return response; } handleBtnEventInterval() { - this.btnEventIntervalId = setInterval(this.listenBtnPressedEvent.bind(this), this.duration); + this.btnEventIntervalId = setInterval( + this.listenBtnPressedEvent.bind(this), + this.duration + ); } async listenBtnPressedEvent() { @@ -372,9 +377,8 @@ const EVENT_INTERVAL = 150; return; } const result = await Entry.hwLite.sendAsyncWithThrottle(command); - - if (!result || - this.getCommandType(command) !== this.getCommandType(result) || + if ( + (!result || this.getCommandType(command) !== this.getCommandType(result)) && // INFO : localdata 명령어는 우선순위가 낮으므로 반복하지 않음 command !== `${this.functionKeys.LOCALDATA};` ) { @@ -582,7 +586,8 @@ const EVENT_INTERVAL = 150; microbit2lite_get_btn: "선택한 버튼이 눌렸다면 '참'으로 판단합니다.", microbit2lite_get_logo: "로고를 터치했다면 '참'으로 판단합니다.", microbit2lite_get_gesture: "선택한 움직임이 감지되면 '참'으로 판단합니다.", - microbit2lite_get_acc: '선택한 버튼이 눌리면 아래에 연결된 블록들을 실행합니다.', + microbit2lite_get_acc: + '선택한 버튼이 눌리면 아래에 연결된 블록들을 실행합니다.', microbit2lite_btn_event: '%1 %2 버튼을 눌렀을 때', microbit2lite_get_direction: '나침반 방향 값입니다. (0~360) ', microbit2lite_get_field_strength_axis: '선택한 축의 자기장 세기 값입니다.', @@ -793,7 +798,8 @@ const EVENT_INTERVAL = 150; microbit2lite_get_gesture: "When the selected movement is detected, it is judged as 'True'.", microbit2lite_get_acc: 'The acceleration value of the selected axis.', - microbit2lite_btn_event: 'When the selected button is pressed, the connected blocks below will run', + microbit2lite_btn_event: + 'When the selected button is pressed, the connected blocks below will run', microbit2lite_get_direction: 'The compass direction value. (0~360)', microbit2lite_get_field_strength_axis: 'The magnetic field strength value of the selected axis.', @@ -1012,7 +1018,7 @@ const EVENT_INTERVAL = 150; }; } - getBlocks = function () { + getBlocks = function() { return { microbit2lite_common_title: { skeleton: 'basic_text', @@ -1952,7 +1958,7 @@ const EVENT_INTERVAL = 150; }, ], def: { - type: 'microbit2lite_btn_event' + type: 'microbit2lite_btn_event', }, paramsKeyMap: { VALUE: 1, From 6230cbb4c2dffffca4d0a1888ee54cb057df38f5 Mon Sep 17 00:00:00 2001 From: Tnks2U Date: Mon, 24 Apr 2023 18:49:00 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20retryLimit=20=EA=B0=92=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 저사양 기기들 고려해서 4정도로 수정 --- src/playground/blocks/hardwareLite/block_microbit2_lite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playground/blocks/hardwareLite/block_microbit2_lite.js b/src/playground/blocks/hardwareLite/block_microbit2_lite.js index dc2f70e81e..4226cc6f94 100644 --- a/src/playground/blocks/hardwareLite/block_microbit2_lite.js +++ b/src/playground/blocks/hardwareLite/block_microbit2_lite.js @@ -9,7 +9,7 @@ const EVENT_INTERVAL = 150; constructor() { this.commandStatus = {}; this.btnEventIntervalId = -1; - this.retryLimitCnt = 3; + this.retryLimitCnt = 4; this.portData = { baudRate: 115200, dataBits: 8,