|
6 | 6 | } |
7 | 7 | }(function (scope) { |
8 | 8 | 'use strict'; |
| 9 | + var SENSOR_DFPLAYER = 0x19;//dec:25 |
9 | 10 |
|
10 | 11 | var self; |
11 | 12 | var proto; |
|
27 | 28 | self = this; |
28 | 29 | board.on(webduino.BoardEvent.SYSEX_MESSAGE, |
29 | 30 | function (event) { |
30 | | - sendAndAckCount--; |
31 | 31 | 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); |
37 | 34 | } |
38 | 35 | }); |
39 | | - startQueue(board); |
40 | 36 | self.init(); |
| 37 | + console.log("MP3 ready..."); |
41 | 38 | } |
42 | 39 |
|
43 | 40 | DFPlayer.prototype = proto = Object.create(Module.prototype, { |
|
55 | 52 | }); |
56 | 53 |
|
57 | 54 | 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]; |
60 | 56 | this._board.send(cmd); |
61 | 57 | } |
62 | 58 |
|
63 | 59 | 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); |
67 | 62 | } |
68 | 63 |
|
69 | 64 | 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]); |
72 | 66 | } |
73 | 67 |
|
74 | 68 | 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]); |
77 | 70 | } |
78 | 71 |
|
79 | 72 | 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]); |
82 | 74 | } |
83 | 75 |
|
84 | 76 | 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]); |
87 | 78 | } |
88 | 79 |
|
89 | 80 | 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]); |
92 | 82 | } |
93 | 83 |
|
94 | 84 | 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]); |
97 | 86 | } |
98 | 87 |
|
99 | 88 | 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]); |
102 | 90 | } |
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 | | - |
125 | 91 | scope.module.DFPlayer = DFPlayer; |
126 | 92 | })); |
0 commit comments