Skip to content

Commit 0346e6e

Browse files
committed
Improve g3.js
1 parent 85fd82e commit 0346e6e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

G3.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@
5050
}
5151

5252
function processG3Data(self, data) {
53-
var str = '',
54-
i = 1;
55-
for (var i = 2; i < data.length; i++) {
56-
str += String.fromCharCode(data[i]);
57-
}
58-
str = str.split(',');
53+
var stringValue = data.slice(2).map(function (val) {
54+
return String.fromCharCode(val);
55+
}).join('');
56+
57+
var value = stringValue.split(',').map(function (val) {
58+
return parseInt(val);
59+
});
5960
self._lastRecv = Date.now();
60-
self.emit(G3Event.READ, str[0], str[1]);
61+
self.emit(G3Event.READ, value[0], value[1]);
6162
}
6263

6364
G3.prototype = proto = Object.create(Module.prototype, {
@@ -81,7 +82,6 @@
8182
proto.trigger = function (state, delaySec, repeatTime) {
8283
var self = this;
8384
var recvPin = this._rx._number;
84-
//board.send([0xF0, 0x04, 0x10, 0x40, 0x01, 0x04, 0x3E, 0x3E, 0x10, 0x03, 0x0A, 0x00, 0xF7]);
8585
var delayHigh6bit = (delaySec & 0x0FC0) >> 6;
8686
var delayLow6bit = (delaySec & 0x3F);
8787
var repeatHigh6bit = (repeatTime & 0x0FC0) >> 6;
@@ -95,8 +95,6 @@
9595
} else {
9696
self._board.sendSysex(G3_MESSAGE[0], [G3_MESSAGE[1], 0x41]);
9797
}
98-
//console.log("state:", state);
99-
//console.log("recvPin:", recvPin, ",sec:", delaySec, ",time:", repeatTime);
10098
}
10199

102100
proto.read = function (callback, interval) {

0 commit comments

Comments
 (0)