Skip to content

Commit b464f61

Browse files
authored
Merge pull request #2967 from aluxrobot/develop-hw-technicpowerlite
Technicpowerlite 오류 수정
2 parents cf89b91 + 36820c8 commit b464f61

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

src/playground/blocks/hardwareLite/block_alux_teachnic_power_lite.js

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,26 @@ const _throttle = require('lodash/throttle');
141141
}
142142
this.remoteEvent = _throttle(
143143
() => {
144-
Entry.engine.fireEvent('technicpowerlite_event_remote_input');
144+
const prevFlag = this.sendFlag;
145+
try {
146+
Entry.engine.fireEvent('technicpowerlite_event_remote_input');
147+
} catch (e) {
148+
} finally {
149+
this.sendFlag = prevFlag;
150+
}
145151
},
146152
EVENT_INTERVAL,
147153
eventSetting
148154
);
149155
this.digitalEvent = _throttle(
150156
() => {
151-
Entry.engine.fireEvent('technicpowerlite_event_digital_input');
157+
const prevFlag = this.sendFlag;
158+
try {
159+
Entry.engine.fireEvent('technicpowerlite_event_digital_input');
160+
} catch (e) {
161+
} finally {
162+
this.sendFlag = prevFlag;
163+
}
152164
}
153165
,
154166
EVENT_INTERVAL,
@@ -656,8 +668,17 @@ const _throttle = require('lodash/throttle');
656668

657669
Entry.addEventListener('run', this.handleRemoteEventInterval.bind(this));
658670
Entry.addEventListener('run', this.handleDigitalEventInterval.bind(this));
659-
Entry.addEventListener('beforeStop', clearInterval(this.remoteEventIntervalId));
660-
Entry.addEventListener('beforeStop', clearInterval(this.digitalEventIntervalId));
671+
Entry.addEventListener('beforeStop', () => {
672+
if (this.remoteEventIntervalId) {
673+
clearInterval(this.remoteEventIntervalId);
674+
this.remoteEventIntervalId = null;
675+
}
676+
if (this.digitalEventIntervalId) {
677+
clearInterval(this.digitalEventIntervalId);
678+
this.digitalEventIntervalId = null;
679+
}
680+
});
681+
661682
this.setZero();
662683

663684
if (this.version === 0) {
@@ -675,17 +696,33 @@ const _throttle = require('lodash/throttle');
675696
}
676697

677698
handleRemoteEventInterval() {
678-
this.remoteEventIntervalId = setInterval(this.remoteEvent.bind(this), EVENT_INTERVAL);
699+
if (this.remoteEventIntervalId) {
700+
clearInterval(this.remoteEventIntervalId);
701+
}
702+
this.remoteEventIntervalId = setInterval(() => {
703+
const currentState = this.remoteEvent.bind(this);
704+
currentState();
705+
}, EVENT_INTERVAL);
679706
}
680707

681708
handleDigitalEventInterval() {
682-
this.digitalEventIntervalId = setInterval(this.digitalEvent.bind(this), EVENT_INTERVAL);
709+
if (this.digitalEventIntervalId) {
710+
clearInterval(this.digitalEventIntervalId);
711+
}
712+
this.digitalEventIntervalId = setInterval(() => {
713+
const currentState = this.digitalEvent.bind(this);
714+
currentState();
715+
}, EVENT_INTERVAL);
683716
}
684717

685718
// 디바이스에서 값을 읽어온다.
686719
handleLocalData(buffer) {
687720
buffer.forEach(b => this.qEnqueue(b));
688721

722+
if (this._recoverTimeoutId) {
723+
clearTimeout(this._recoverTimeoutId);
724+
}
725+
689726
while(this.qCount() >= this.inputPacket.length) {
690727
if (!this.process) {
691728
while(this.qCount() > 0) {
@@ -718,16 +755,22 @@ const _throttle = require('lodash/throttle');
718755
}
719756

720757
if (this.sendFlag) {
721-
setTimeout(
722-
() => {
758+
if (this._requestTimeoutId) {
759+
clearTimeout(this._requestTimeoutId);
760+
}
761+
this._requestTimeoutId = setTimeout(
762+
() => {
723763
if (Entry.hwLite && Entry.hwLite.serial) {
724764
Entry.hwLite.serial.update();
725765
this.sendFlag = false;
766+
this._recoverTimeoutId = setTimeout(() => {
767+
this.sendFlag = true;
768+
}, SERIAL_INTERVAL * 3);
726769
}
727770
},
728771
SERIAL_INTERVAL
729772
);
730-
};
773+
}
731774
}
732775

733776
//디바이스에 값을 쓴다.
@@ -3633,7 +3676,7 @@ const _throttle = require('lodash/throttle');
36333676
let value = script.getNumberValue('PARAM2');
36343677

36353678
if (value != 0) {
3636-
count = Number(value / 255).toFixed(0);
3679+
count = Math.floor(value / 255);
36373680
value = value % 255;
36383681
} else {
36393682
count = 0;

src/playground/blocks/hardwareLite/metadata_alux_teachnic_power_lite.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ProboTechnicPowerLite",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "hardware",
55
"title": "프로보 테크닉(파워)",
66
"description": "에이럭스",

0 commit comments

Comments
 (0)