diff --git a/src/playground/blocks/hardwareLite/block_microbit2_lite.js b/src/playground/blocks/hardwareLite/block_microbit2_lite.js index a74f28e860..4226cc6f94 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 = 4; 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,