-
Notifications
You must be signed in to change notification settings - Fork 496
Issue/5643 #2471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/5643 #2471
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,14 @@ | ||||||||||||||||||||||
| 'use strict'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (function() { | ||||||||||||||||||||||
| const _throttle = require('lodash/throttle'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const EVENT_INTERVAL = 150; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| (function () { | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| Entry.Microbit2lite = new (class Microbit2Lite { | ||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||
| this.commandStatus = {}; | ||||||||||||||||||||||
| this.btnEventIntervalId = -1; | ||||||||||||||||||||||
| this.retryLimitCnt = 5; | ||||||||||||||||||||||
| this.portData = { | ||||||||||||||||||||||
| baudRate: 115200, | ||||||||||||||||||||||
|
|
@@ -13,7 +18,7 @@ | |||||||||||||||||||||
| bufferSize: 512, | ||||||||||||||||||||||
| connectionType: 'ascii', | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| this.duration = 32; | ||||||||||||||||||||||
| this.duration = 64; | ||||||||||||||||||||||
| this.functionKeys = { | ||||||||||||||||||||||
| LOCALDATA: 'localdata', | ||||||||||||||||||||||
| GET_ANALOG: 'get-analog', | ||||||||||||||||||||||
|
|
@@ -258,11 +263,19 @@ | |||||||||||||||||||||
| 'microbit2lite_set_pwm', | ||||||||||||||||||||||
| 'microbit2lite_v2_title', | ||||||||||||||||||||||
| 'microbit2lite_get_logo', | ||||||||||||||||||||||
| 'microbit2lite_btn_event', | ||||||||||||||||||||||
| 'microbit2lite_speaker_toggle', | ||||||||||||||||||||||
| 'microbit2lite_play_sound_effect', | ||||||||||||||||||||||
| 'microbit2lite_get_sound_level', | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| this.version = '2'; | ||||||||||||||||||||||
| this.firePressedBtnEventWithThrottle = _throttle( | ||||||||||||||||||||||
| (pressedBtn) => { | ||||||||||||||||||||||
| Entry.engine.fireEventWithValue('microbit2lite_btn_pressed', pressedBtn); | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| EVENT_INTERVAL, | ||||||||||||||||||||||
| { leading: true, trailing: false } | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| _clamp(value, min, max) { | ||||||||||||||||||||||
| if (value < min) { | ||||||||||||||||||||||
|
|
@@ -277,6 +290,48 @@ | |||||||||||||||||||||
| return Entry.hwLite.sendAsyncWithThrottle(this.functionKeys.RESET); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async initialHandshake() { | ||||||||||||||||||||||
| const defaultCMD = `${this.functionKeys.LOCALDATA}`; | ||||||||||||||||||||||
| const response = await Entry.hwLite.sendAsync(defaultCMD); | ||||||||||||||||||||||
| if (response && response.indexOf('localdata') > -1) { | ||||||||||||||||||||||
| const version = response.split(';')[1]; | ||||||||||||||||||||||
| if (!version) { | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| const major = version[0]; | ||||||||||||||||||||||
| if (this.version !== major) { | ||||||||||||||||||||||
| this.version = major; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (this.version === '2') { | ||||||||||||||||||||||
| Entry.addEventListener('run', this.handleBtnEventInterval.bind(this)); | ||||||||||||||||||||||
| Entry.addEventListener('beforeStop', () => { clearInterval(this.btnEventIntervalId) }); | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return response; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| handleBtnEventInterval() { | ||||||||||||||||||||||
| this.btnEventIntervalId = setInterval(this.listenBtnPressedEvent.bind(this), this.duration); | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async listenBtnPressedEvent() { | ||||||||||||||||||||||
| if (Object.keys(this.commandStatus).length > 0) { | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const defaultCMD = `${this.functionKeys.LOCALDATA};`; | ||||||||||||||||||||||
| const response = await Entry.hwLite.sendAsyncWithThrottle(defaultCMD); | ||||||||||||||||||||||
| // const response = await this.getResponseWithSync(defaultCMD); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // INFO: A,B 버튼이벤트 관련 로직 | ||||||||||||||||||||||
| const pressedBtn = response.split(':btn:')[1]; | ||||||||||||||||||||||
| if (pressedBtn) { | ||||||||||||||||||||||
| this.firePressedBtnEventWithThrottle(pressedBtn); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| waitMilliSec(milli) { | ||||||||||||||||||||||
| this.blockReq = true; | ||||||||||||||||||||||
| setTimeout(() => { | ||||||||||||||||||||||
|
|
@@ -318,7 +373,11 @@ | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| const result = await Entry.hwLite.sendAsyncWithThrottle(command); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!result || this.getCommandType(command) !== this.getCommandType(result)) { | ||||||||||||||||||||||
| if (!result || | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||
| this.getCommandType(command) !== this.getCommandType(result) || | ||||||||||||||||||||||
| // INFO : localdata 명령어는 우선순위가 낮으므로 반복하지 않음 | ||||||||||||||||||||||
| command !== `${this.functionKeys.LOCALDATA};` | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
| if (!this.commandStatus[command]) { | ||||||||||||||||||||||
| this.commandStatus[command] = 1; | ||||||||||||||||||||||
| throw new Entry.Utils.AsyncError(); | ||||||||||||||||||||||
|
|
@@ -367,6 +426,7 @@ | |||||||||||||||||||||
| microbit2lite_get_logo: '로고를 터치했는가?', | ||||||||||||||||||||||
| microbit2lite_get_gesture: '움직임이 %1 인가?', | ||||||||||||||||||||||
| microbit2lite_get_acc: '%1 의 가속도 값', | ||||||||||||||||||||||
| microbit2lite_btn_event: '%1 %2 버튼을 눌렀을 때', | ||||||||||||||||||||||
| microbit2lite_get_direction: '나침반 방향', | ||||||||||||||||||||||
| microbit2lite_get_field_strength_axis: '%1 의 자기장 세기 값', | ||||||||||||||||||||||
| microbit2lite_get_light_level: '빛 센서 값', | ||||||||||||||||||||||
|
|
@@ -522,7 +582,8 @@ | |||||||||||||||||||||
| microbit2lite_get_btn: "선택한 버튼이 눌렸다면 '참'으로 판단합니다.", | ||||||||||||||||||||||
| microbit2lite_get_logo: "로고를 터치했다면 '참'으로 판단합니다.", | ||||||||||||||||||||||
| microbit2lite_get_gesture: "선택한 움직임이 감지되면 '참'으로 판단합니다.", | ||||||||||||||||||||||
| microbit2lite_get_acc: '선택한 축의 가속도 값입니다.', | ||||||||||||||||||||||
| microbit2lite_get_acc: '선택한 버튼이 눌리면 아래에 연결된 블록들을 실행합니다.', | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||
| microbit2lite_btn_event: '%1 %2 버튼을 눌렀을 때', | ||||||||||||||||||||||
| microbit2lite_get_direction: '나침반 방향 값입니다. (0~360) ', | ||||||||||||||||||||||
| microbit2lite_get_field_strength_axis: '선택한 축의 자기장 세기 값입니다.', | ||||||||||||||||||||||
| microbit2lite_get_light_level: '빛 센서의 값입니다.', | ||||||||||||||||||||||
|
|
@@ -565,6 +626,7 @@ | |||||||||||||||||||||
| microbit2lite_get_logo: 'logo touched?', | ||||||||||||||||||||||
| microbit2lite_get_gesture: 'Is the movement %1?', | ||||||||||||||||||||||
| microbit2lite_get_acc: 'acceleration value of %1', | ||||||||||||||||||||||
| microbit2lite_btn_event: '%1 When %2 button pressed', | ||||||||||||||||||||||
| microbit2lite_get_direction: 'compass direction', | ||||||||||||||||||||||
| microbit2lite_get_field_strength_axis: | ||||||||||||||||||||||
| 'magnetic field strength value of %1 ', | ||||||||||||||||||||||
|
|
@@ -731,6 +793,7 @@ | |||||||||||||||||||||
| 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', | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||
| microbit2lite_get_direction: 'The compass direction value. (0~360)', | ||||||||||||||||||||||
| microbit2lite_get_field_strength_axis: | ||||||||||||||||||||||
| 'The magnetic field strength value of the selected axis.', | ||||||||||||||||||||||
|
|
@@ -949,7 +1012,7 @@ | |||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| getBlocks = function() { | ||||||||||||||||||||||
| getBlocks = function () { | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| microbit2lite_common_title: { | ||||||||||||||||||||||
| skeleton: 'basic_text', | ||||||||||||||||||||||
|
|
@@ -1862,6 +1925,45 @@ | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| microbit2lite_btn_event: { | ||||||||||||||||||||||
| color: EntryStatic.colorSet.block.default.HARDWARE, | ||||||||||||||||||||||
| outerLine: EntryStatic.colorSet.block.darken.HARDWARE, | ||||||||||||||||||||||
| fontColor: '#fff', | ||||||||||||||||||||||
| skeleton: 'basic_event', | ||||||||||||||||||||||
| statements: [], | ||||||||||||||||||||||
| params: [ | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| type: 'Indicator', | ||||||||||||||||||||||
| img: 'block_icon/start_icon_hardware.svg', | ||||||||||||||||||||||
| size: 14, | ||||||||||||||||||||||
| position: { x: 0, y: -2 }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| type: 'Dropdown', | ||||||||||||||||||||||
| options: [ | ||||||||||||||||||||||
| ['A', '1'], | ||||||||||||||||||||||
| ['B', '2'], | ||||||||||||||||||||||
| ['A+B', '3'], | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| value: '1', | ||||||||||||||||||||||
| fontSize: 11, | ||||||||||||||||||||||
| bgColor: EntryStatic.colorSet.block.darken.HARDWARE, | ||||||||||||||||||||||
| arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| def: { | ||||||||||||||||||||||
| type: 'microbit2lite_btn_event' | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| paramsKeyMap: { | ||||||||||||||||||||||
| VALUE: 1, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| class: 'microbit2litev2', | ||||||||||||||||||||||
| isNotFor: ['Microbit2lite'], | ||||||||||||||||||||||
| event: 'microbit2lite_btn_pressed', | ||||||||||||||||||||||
| func: (sprite, script) => { | ||||||||||||||||||||||
| return script.callReturn(); | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
|
Comment on lines
+1963
to
+1965
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| microbit2lite_get_acc: { | ||||||||||||||||||||||
| color: EntryStatic.colorSet.block.default.HARDWARE, | ||||||||||||||||||||||
| outerLine: EntryStatic.colorSet.block.darken.HARDWARE, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Delete
·