Skip to content

Commit 9cab93a

Browse files
author
Marty
committed
remove ack confirm function
1 parent 8e1af78 commit 9cab93a

1 file changed

Lines changed: 14 additions & 48 deletions

File tree

DFPlayer.js

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77
}(function (scope) {
88
'use strict';
9+
var SENSOR_DFPLAYER = 0x19;//dec:25
910

1011
var self;
1112
var proto;
@@ -27,17 +28,13 @@
2728
self = this;
2829
board.on(webduino.BoardEvent.SYSEX_MESSAGE,
2930
function (event) {
30-
sendAndAckCount--;
3131
var m = event.message;
32-
var resp = m[2];
33-
sending = false;
34-
if (waitAckAndSend.length > 0) {
35-
var cmd = waitAckAndSend.shift();
36-
self._board.send(cmd);
32+
if (m[0] == 0x04 && m[1] == SENSOR_DFPLAYER) {
33+
console.log("mp3 response:",m);
3734
}
3835
});
39-
startQueue(board);
4036
self.init();
37+
console.log("MP3 ready...");
4138
}
4239

4340
DFPlayer.prototype = proto = Object.create(Module.prototype, {
@@ -55,72 +52,41 @@
5552
});
5653

5754
proto.init = function () {
58-
var cmd = [0xF0, 0x04, 0x19, 0x0 /*init*/ , this._rx, this._tx, 0xF7];
59-
sendAndAckCount++;
55+
var cmd = [0xF0, 0x04, SENSOR_DFPLAYER, 0x0 /*init*/ , this._rx, this._tx, 0xF7];
6056
this._board.send(cmd);
6157
}
6258

6359
proto.play = function (num) {
64-
var cmd = [0xF0, 0x04, 0x19, 0x01, num, 0xF7];
65-
sendAndAckCount++;
66-
waitAckAndSend.push(cmd);
60+
var cmd = [0xF0, 0x04, SENSOR_DFPLAYER, 0x01, num, 0xF7];
61+
this._board.send(cmd);
6762
}
6863

6964
proto.start = function () {
70-
sendAndAckCount++;
71-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x02 /*Start*/ , 0xF7]);
65+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x02 /*Start*/ , 0xF7]);
7266
}
7367

7468
proto.stop = function () {
75-
sendAndAckCount++;
76-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x03 /*Stop*/ , 0xF7]);
69+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x03 /*Stop*/ , 0xF7]);
7770
}
7871

7972
proto.pause = function () {
80-
sendAndAckCount++;
81-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x04 /*Pause*/ , 0xF7]);
73+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x04 /*Pause*/ , 0xF7]);
8274
}
8375

8476
proto.volume = function (volume) {
85-
sendAndAckCount++;
86-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x05, volume, 0xF7]);
77+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x05, volume, 0xF7]);
8778
}
8879

8980
proto.previous = function () {
90-
sendAndAckCount++;
91-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x06 /*Previous*/ , 0xF7]);
81+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x06 /*Previous*/ , 0xF7]);
9282
}
9383

9484
proto.next = function () {
95-
sendAndAckCount++;
96-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x07 /*Next*/ , 0xF7]);
85+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x07 /*Next*/ , 0xF7]);
9786
}
9887

9988
proto.loop = function (num) {
100-
sendAndAckCount++;
101-
waitAckAndSend.push([0xF0, 0x04, 0x19, 0x08, num, 0xF7]);
89+
this._board.send([0xF0, 0x04, SENSOR_DFPLAYER, 0x08, num, 0xF7]);
10290
}
103-
104-
function startQueue(board) {
105-
setInterval(function () {
106-
if (sendAndAckCount == waitAckAndSend.length && waitAckAndSend.length > 0) {
107-
var cmd = waitAckAndSend.shift();
108-
board.send(cmd);
109-
}
110-
if (sending || sendArray.length == 0) {
111-
return;
112-
}
113-
sending = true;
114-
var sendObj = sendArray.shift();
115-
sendAck = sendObj.ack;
116-
if (sendAck > 0) {
117-
board.send(sendObj.obj);
118-
} else {
119-
sending = false;
120-
sendCallback();
121-
}
122-
}, 0);
123-
}
124-
12591
scope.module.DFPlayer = DFPlayer;
12692
}));

0 commit comments

Comments
 (0)