Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/playground/blocks/hardwareLite/block_microbit2_lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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};`
) {
Expand Down Expand Up @@ -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: '선택한 축의 자기장 세기 값입니다.',
Expand Down Expand Up @@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <max-len> reported by reviewdog 🐶
This line has a length of 103. Maximum allowed is 100.

microbit2lite_get_direction: 'The compass direction value. (0~360)',
microbit2lite_get_field_strength_axis:
'The magnetic field strength value of the selected axis.',
Expand Down Expand Up @@ -1012,7 +1018,7 @@ const EVENT_INTERVAL = 150;
};
}

getBlocks = function () {
getBlocks = function() {
return {
microbit2lite_common_title: {
skeleton: 'basic_text',
Expand Down Expand Up @@ -1952,7 +1958,7 @@ const EVENT_INTERVAL = 150;
},
],
def: {
type: 'microbit2lite_btn_event'
type: 'microbit2lite_btn_event',
},
paramsKeyMap: {
VALUE: 1,
Expand Down