Skip to content

Commit 36a3f85

Browse files
authored
Merge pull request #2965 from aluxrobot/develop-hw-nemolite
nemoLite 오류 수정
2 parents bb33631 + 5f9efea commit 36a3f85

2 files changed

Lines changed: 69 additions & 23 deletions

File tree

src/playground/blocks/hardwareLite/block_alux_nemo_lite.js

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,26 @@ const _throttle = require('lodash/throttle');
3737
};
3838
this.buttonEvent = _throttle(
3939
() => {
40-
Entry.engine.fireEvent('nemolite_event_button');
40+
const prevFlag = this.sendFlag;
41+
try {
42+
Entry.engine.fireEvent('nemolite_event_button');
43+
} catch (e) {
44+
} finally {
45+
this.sendFlag = prevFlag;
46+
}
4147
},
4248
EVENT_INTERVAL,
4349
eventSetting
4450
);
4551
this.motionEvent = _throttle(
4652
() => {
47-
Entry.engine.fireEvent('nemolite_event_motion');
53+
const prevFlag = this.sendFlag;
54+
try {
55+
Entry.engine.fireEvent('nemolite_event_motion');
56+
} catch (e) {
57+
} finally {
58+
this.sendFlag = prevFlag;
59+
}
4860
},
4961
EVENT_INTERVAL,
5062
eventSetting
@@ -621,11 +633,11 @@ const _throttle = require('lodash/throttle');
621633
ledClear: 1,
622634
extension: 0,
623635
melody: {
624-
play: 0,
636+
play: 1,
625637
title: 0,
626638
},
627639
note: {
628-
play: 0,
640+
play: 1,
629641
pitch: 0,
630642
},
631643
ledRead: 0,
@@ -657,7 +669,7 @@ const _throttle = require('lodash/throttle');
657669

658670
this.state = {
659671
led: 0,
660-
sound: 0,
672+
sound: 'm'.charCodeAt(),
661673
note: 0,
662674
soundBlockId: 0,
663675
noteBlockId: 0,
@@ -687,6 +699,7 @@ const _throttle = require('lodash/throttle');
687699

688700
if (Entry.hwLite && Entry.hwLite.serial) {
689701
Entry.hwLite.serial.update();
702+
this.state.sound = 0;
690703
}
691704
}
692705
//endregion
@@ -713,8 +726,16 @@ const _throttle = require('lodash/throttle');
713726

714727
Entry.addEventListener('run', this.handleButtonEventInterval.bind(this));
715728
Entry.addEventListener('run', this.handleMotionlEventInterval.bind(this));
716-
Entry.addEventListener('beforeStop', clearInterval(this.buttonEventIntervalId));
717-
Entry.addEventListener('beforeStop', clearInterval(this.motionEventIntervalId));
729+
Entry.addEventListener('beforeStop', () => {
730+
if (this.buttonEventIntervalId) {
731+
clearInterval(this.buttonEventIntervalId);
732+
this.buttonEventIntervalId = null;
733+
}
734+
if (this.motionEventIntervalId) {
735+
clearInterval(this.motionEventIntervalId);
736+
this.motionEventIntervalId = null;
737+
}
738+
});
718739

719740
this.setZero();
720741

@@ -733,11 +754,35 @@ const _throttle = require('lodash/throttle');
733754
}
734755
//endregion
735756

757+
handleButtonEventInterval() {
758+
if (this.buttonEventIntervalId) {
759+
clearInterval(this.buttonEventIntervalId);
760+
}
761+
this.buttonEventIntervalId = setInterval(() => {
762+
const currentState = this.buttonEvent.bind(this);
763+
currentState();
764+
}, EVENT_INTERVAL);
765+
}
766+
767+
handleMotionlEventInterval() {
768+
if (this.motionEventIntervalId) {
769+
clearInterval(this.motionEventIntervalId);
770+
}
771+
this.motionEventIntervalId = setInterval(() => {
772+
const currentState = this.motionEvent.bind(this);
773+
currentState();
774+
}, EVENT_INTERVAL);
775+
}
776+
736777
// 디바이스에서 값을 읽어온다.
737778
//region handleLocalData
738779
handleLocalData(buffer) {
739780
buffer.forEach((b) => this.qEnqueue(b));
740781

782+
if (this._recoverTimeoutId) {
783+
clearTimeout(this._recoverTimeoutId);
784+
}
785+
741786
while (this.qCount() >= this.receivedPacket.length) {
742787
if (!this.process) {
743788
while (this.qCount() > 0) {
@@ -788,12 +833,21 @@ const _throttle = require('lodash/throttle');
788833
}
789834

790835
if (this.sendFlag) {
791-
setTimeout(() => {
792-
if (Entry.hwLite && Entry.hwLite.serial) {
793-
Entry.hwLite.serial.update();
794-
this.sendFlag = false;
795-
}
796-
}, SERIAL_INTERVAL);
836+
if (this._requestTimeoutId) {
837+
clearTimeout(this._requestTimeoutId);
838+
}
839+
this._requestTimeoutId = setTimeout(
840+
() => {
841+
if (Entry.hwLite && Entry.hwLite.serial) {
842+
Entry.hwLite.serial.update();
843+
this.sendFlag = false;
844+
this._recoverTimeoutId = setTimeout(() => {
845+
this.sendFlag = true;
846+
}, SERIAL_INTERVAL * 3);
847+
}
848+
},
849+
SERIAL_INTERVAL
850+
);
797851
}
798852
} //endregion
799853

@@ -851,14 +905,6 @@ const _throttle = require('lodash/throttle');
851905
: this.qSize - this.qFront + this.qRear;
852906
}
853907

854-
handleButtonEventInterval() {
855-
this.buttonEventIntervalId = setInterval(this.buttonEvent.bind(this), EVENT_INTERVAL);
856-
}
857-
858-
handleMotionlEventInterval() {
859-
this.motionEventIntervalId = setInterval(this.motionEvent.bind(this), EVENT_INTERVAL);
860-
}
861-
862908
checksum(packet) {
863909
let checker = 0;
864910
const length = packet[2] + 2;
@@ -1040,7 +1086,7 @@ const _throttle = require('lodash/throttle');
10401086
for (let i = 0; i < 14; i++) {
10411087
const index = this.sendIndex.led7x1 + i;
10421088
this.sendPacket[index] = this.setData.ledColumm.pixel[i];
1043-
if (index > 6 && this.sendPacket[index] > 0) {
1089+
if (index > 7 && this.sendPacket[index] > 0) {
10441090
nextPage = true;
10451091
}
10461092
}

src/playground/blocks/hardwareLite/metadata_alux_nemo_lite.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ProboNemoLite",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "hardware",
55
"title": "네모",
66
"description": "에이럭스",

0 commit comments

Comments
 (0)