1
1
/* !
2
- * @file SparkFun_MY1690_MP3_Library .cpp
3
- * @brief This is a library written for the MY1690 Serial MP3 player
2
+ * @file SparkFun_SparkFunMY1690_MP3_Library .cpp
3
+ * @brief This is a library written for the SparkFunMY1690 Serial MP3 player
4
4
*
5
5
* SparkFun sells these at its website: www.sparkfun.com
6
6
*
7
7
* Do you like this library? Help support SparkFun. Buy a board!
8
8
* https://www.sparkfun.com/products/15050
9
9
*
10
- * https://github.com/sparkfun/SparkFun_MY1690_MP3_Decoder_Arduino_Library
10
+ * https://github.com/sparkfun/SparkFun_SparkFunMY1690_MP3_Decoder_Arduino_Library
11
11
*
12
12
* @author SparkFun Electronics
13
13
* @date 2024
17
17
*/
18
18
#include " SparkFun_MY1690_MP3_Library.h"
19
19
20
- MY1690::MY1690 ()
20
+ SparkFunMY1690::SparkFunMY1690 ()
21
21
{
22
22
}
23
23
24
- bool MY1690 ::begin (Stream &serialPort, uint8_t pin)
24
+ bool SparkFunMY1690 ::begin (Stream &serialPort, uint8_t pin)
25
25
{
26
26
_serialPort = &serialPort;
27
27
_busyPin = pin;
@@ -43,7 +43,7 @@ bool MY1690::begin(Stream &serialPort, uint8_t pin)
43
43
}
44
44
45
45
// Try to get the version number from the device
46
- uint16_t MY1690 ::getVersion (void )
46
+ uint16_t SparkFunMY1690 ::getVersion (void )
47
47
{
48
48
commandBytes[0 ] = MP3_COMMAND_GET_VERSION_NUMBER;
49
49
@@ -71,7 +71,7 @@ uint16_t MY1690::getVersion(void)
71
71
}
72
72
73
73
// Verify the device responds correctly with a version number
74
- bool MY1690 ::isConnected (void )
74
+ bool SparkFunMY1690 ::isConnected (void )
75
75
{
76
76
int version = getVersion ();
77
77
if (version == 100 || version == 101 )
@@ -81,7 +81,7 @@ bool MY1690::isConnected(void)
81
81
}
82
82
83
83
// Play all songs on the SD card, then loop
84
- bool MY1690 ::setPlayModeFull (void )
84
+ bool SparkFunMY1690 ::setPlayModeFull (void )
85
85
{
86
86
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
87
87
commandBytes[1 ] = MP3_LOOP_MODE_FULL;
@@ -90,7 +90,7 @@ bool MY1690::setPlayModeFull(void)
90
90
}
91
91
92
92
// Play all songs in the folder, then loop
93
- bool MY1690 ::setPlayModeFolder (void )
93
+ bool SparkFunMY1690 ::setPlayModeFolder (void )
94
94
{
95
95
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
96
96
commandBytes[1 ] = MP3_LOOP_MODE_FOLDER;
@@ -99,7 +99,7 @@ bool MY1690::setPlayModeFolder(void)
99
99
}
100
100
101
101
// Play song, then loop
102
- bool MY1690 ::setPlayModeSingle (void )
102
+ bool SparkFunMY1690 ::setPlayModeSingle (void )
103
103
{
104
104
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
105
105
commandBytes[1 ] = MP3_LOOP_MODE_SINGLE;
@@ -108,7 +108,7 @@ bool MY1690::setPlayModeSingle(void)
108
108
}
109
109
110
110
// Play random song, then play another random song, with no end
111
- bool MY1690 ::setPlayModeRandom (void )
111
+ bool SparkFunMY1690 ::setPlayModeRandom (void )
112
112
{
113
113
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
114
114
commandBytes[1 ] = MP3_LOOP_MODE_RANDOM;
@@ -117,47 +117,47 @@ bool MY1690::setPlayModeRandom(void)
117
117
}
118
118
119
119
// Play a song, then stop
120
- bool MY1690 ::setPlayModeNoLoop (void )
120
+ bool SparkFunMY1690 ::setPlayModeNoLoop (void )
121
121
{
122
122
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
123
123
commandBytes[1 ] = MP3_LOOP_MODE_NO_LOOP;
124
124
sendCommand (2 );
125
125
return (getOKResponse ());
126
126
}
127
127
128
- uint16_t MY1690 ::getSongCount (void )
128
+ uint16_t SparkFunMY1690 ::getSongCount (void )
129
129
{
130
130
commandBytes[0 ] = MP3_COMMAND_GET_SONG_COUNT;
131
131
sendCommand (1 );
132
132
133
133
return (getNumberResponse ());
134
134
}
135
135
136
- uint16_t MY1690 ::getTrackNumber (void )
136
+ uint16_t SparkFunMY1690 ::getTrackNumber (void )
137
137
{
138
138
commandBytes[0 ] = MP3_COMMAND_GET_CURRENT_TRACK;
139
139
sendCommand (1 );
140
140
141
141
return (getNumberResponse ());
142
142
}
143
143
144
- uint16_t MY1690 ::getTrackElapsedTime (void )
144
+ uint16_t SparkFunMY1690 ::getTrackElapsedTime (void )
145
145
{
146
146
commandBytes[0 ] = MP3_COMMAND_GET_CURRENT_TRACK_TIME;
147
147
sendCommand (1 );
148
148
149
149
return (getNumberResponse ());
150
150
}
151
151
152
- uint16_t MY1690 ::getTrackTotalTime (void )
152
+ uint16_t SparkFunMY1690 ::getTrackTotalTime (void )
153
153
{
154
154
commandBytes[0 ] = MP3_COMMAND_GET_CURRENT_TRACK_TIME_TOTAL;
155
155
sendCommand (1 );
156
156
157
157
return (getNumberResponse ());
158
158
}
159
159
160
- bool MY1690 ::playTrackNumber (uint16_t trackNumber)
160
+ bool SparkFunMY1690 ::playTrackNumber (uint16_t trackNumber)
161
161
{
162
162
commandBytes[0 ] = MP3_COMMAND_SELECT_TRACK_PLAY;
163
163
commandBytes[1 ] = trackNumber >> 8 ; // MSB
@@ -166,9 +166,9 @@ bool MY1690::playTrackNumber(uint16_t trackNumber)
166
166
return (getOKResponse ());
167
167
}
168
168
169
- bool MY1690 ::setVolume (uint8_t volumeLevel)
169
+ bool SparkFunMY1690 ::setVolume (uint8_t volumeLevel)
170
170
{
171
- // Any number above 30 will be automatically set to 30 by MY1690
171
+ // Any number above 30 will be automatically set to 30 by SparkFunMY1690
172
172
// Trim value so return is true
173
173
if (volumeLevel > 30 )
174
174
volumeLevel = 30 ;
@@ -183,58 +183,58 @@ bool MY1690::setVolume(uint8_t volumeLevel)
183
183
return (false );
184
184
}
185
185
186
- uint8_t MY1690 ::getVolume (void )
186
+ uint8_t SparkFunMY1690 ::getVolume (void )
187
187
{
188
188
commandBytes[0 ] = MP3_COMMAND_GET_VOLUME;
189
189
sendCommand (1 );
190
190
uint8_t volLevel = getNumberResponse () & 0xFF ;
191
191
return (volLevel);
192
192
}
193
193
194
- bool MY1690 ::volumeUp (void )
194
+ bool SparkFunMY1690 ::volumeUp (void )
195
195
{
196
196
commandBytes[0 ] = MP3_COMMAND_VOLUME_UP;
197
197
sendCommand (1 );
198
198
return (getOKResponse ());
199
199
}
200
- bool MY1690 ::volumeDown (void )
200
+ bool SparkFunMY1690 ::volumeDown (void )
201
201
{
202
202
commandBytes[0 ] = MP3_COMMAND_VOLUME_DOWN;
203
203
sendCommand (1 );
204
204
return (getOKResponse ());
205
205
}
206
206
207
- uint8_t MY1690 ::getEQ (void )
207
+ uint8_t SparkFunMY1690 ::getEQ (void )
208
208
{
209
209
commandBytes[0 ] = MP3_COMMAND_GET_EQ;
210
210
sendCommand (1 );
211
211
return (getNumberResponse ());
212
212
}
213
213
214
- bool MY1690 ::setEQ (uint8_t eqType)
214
+ bool SparkFunMY1690 ::setEQ (uint8_t eqType)
215
215
{
216
216
commandBytes[0 ] = MP3_COMMAND_SET_EQ_MODE;
217
217
commandBytes[1 ] = eqType;
218
218
sendCommand (2 );
219
219
return (getOKResponse ());
220
220
}
221
221
222
- bool MY1690 ::setPlayMode (uint8_t playMode)
222
+ bool SparkFunMY1690 ::setPlayMode (uint8_t playMode)
223
223
{
224
224
commandBytes[0 ] = MP3_COMMAND_SET_LOOP_MODE;
225
225
commandBytes[1 ] = playMode;
226
226
sendCommand (2 );
227
227
return (getOKResponse ());
228
228
}
229
229
230
- uint8_t MY1690 ::getPlayMode (void )
230
+ uint8_t SparkFunMY1690 ::getPlayMode (void )
231
231
{
232
232
commandBytes[0 ] = MP3_COMMAND_GET_LOOP_MODE;
233
233
sendCommand (1 );
234
234
return (getNumberResponse ());
235
235
}
236
236
237
- bool MY1690 ::isPlaying (void )
237
+ bool SparkFunMY1690 ::isPlaying (void )
238
238
{
239
239
if (_busyPin == 255 )
240
240
{
@@ -249,14 +249,14 @@ bool MY1690::isPlaying(void)
249
249
}
250
250
251
251
// Responds with '0000 \r\n' (note the space), '0001 \r\n', etc
252
- uint8_t MY1690 ::getPlayStatus (void )
252
+ uint8_t SparkFunMY1690 ::getPlayStatus (void )
253
253
{
254
254
commandBytes[0 ] = MP3_COMMAND_GET_STATUS;
255
255
sendCommand (1 );
256
256
return (getNumberResponse ());
257
257
}
258
258
259
- void MY1690 ::play (void )
259
+ void SparkFunMY1690 ::play (void )
260
260
{
261
261
commandBytes[0 ] = MP3_COMMAND_PLAY;
262
262
sendCommand (1 );
@@ -265,21 +265,21 @@ void MY1690::play(void)
265
265
// User can also use the isPlaying() after 30ms to see if song has started
266
266
}
267
267
268
- bool MY1690 ::pause (void )
268
+ bool SparkFunMY1690 ::pause (void )
269
269
{
270
270
commandBytes[0 ] = MP3_COMMAND_PAUSE;
271
271
sendCommand (1 );
272
272
return (getOKResponse ());
273
273
}
274
274
275
- bool MY1690 ::playNext (void )
275
+ bool SparkFunMY1690 ::playNext (void )
276
276
{
277
277
commandBytes[0 ] = MP3_COMMAND_NEXT;
278
278
sendCommand (1 );
279
279
return (getOKResponse ());
280
280
}
281
281
282
- bool MY1690 ::playPrevious (void )
282
+ bool SparkFunMY1690 ::playPrevious (void )
283
283
{
284
284
commandBytes[0 ] = MP3_COMMAND_PREVIOUS;
285
285
sendCommand (1 );
@@ -288,7 +288,7 @@ bool MY1690::playPrevious(void)
288
288
289
289
// Device responds with 'OK'
290
290
// If a song is playing, then ~14ms later 'STOP' is reported
291
- bool MY1690 ::stopPlaying (void )
291
+ bool SparkFunMY1690 ::stopPlaying (void )
292
292
{
293
293
// Use hardware pins or software command
294
294
if (isPlaying () == false )
@@ -308,7 +308,7 @@ bool MY1690::stopPlaying(void)
308
308
return (false );
309
309
}
310
310
311
- bool MY1690 ::reset (void )
311
+ bool SparkFunMY1690 ::reset (void )
312
312
{
313
313
// Device responds with 'OK'
314
314
// Then 'STOPMP3' ~18ms later
@@ -319,34 +319,34 @@ bool MY1690::reset(void)
319
319
}
320
320
321
321
// Advance track ~1s
322
- bool MY1690 ::fastForward (void )
322
+ bool SparkFunMY1690 ::fastForward (void )
323
323
{
324
324
commandBytes[0 ] = MP3_COMMAND_FASTFOWARD;
325
325
sendCommand (1 );
326
326
return (getOKResponse ());
327
327
}
328
328
329
329
// Rewind track ~1s
330
- bool MY1690 ::rewind (void )
330
+ bool SparkFunMY1690 ::rewind (void )
331
331
{
332
332
commandBytes[0 ] = MP3_COMMAND_REWIND;
333
333
sendCommand (1 );
334
334
return (getOKResponse ());
335
335
}
336
336
337
337
// Toggle play/pause on this track
338
- bool MY1690 ::playPause (void )
338
+ bool SparkFunMY1690 ::playPause (void )
339
339
{
340
340
commandBytes[0 ] = MP3_COMMAND_PLAY_PAUSE;
341
341
sendCommand (1 );
342
342
return (getOKResponse ());
343
343
}
344
344
345
- // In version 1.1, sometimes MY1690 responds with '0000 \r\n' to a get command. No OK, and a space.
345
+ // In version 1.1, sometimes SparkFunMY1690 responds with '0000 \r\n' to a get command. No OK, and a space.
346
346
// Sometimes 'OK0001 \r\n'. Ok, and a space. Yay!
347
347
// In version 1.0 it was lower case letters. In v1.1, it's upper case HEX.
348
348
// Convert the four letters to a decimal value
349
- uint16_t MY1690 ::getNumberResponse (void )
349
+ uint16_t SparkFunMY1690 ::getNumberResponse (void )
350
350
{
351
351
const uint8_t maxLength = 9 ;
352
352
uint8_t okResponseOffset = 0 ;
@@ -406,13 +406,13 @@ uint16_t MY1690::getNumberResponse(void)
406
406
}
407
407
408
408
// MY1690 responds with OK (no \n \r) in ASCII to a control command
409
- bool MY1690 ::getOKResponse (void )
409
+ bool SparkFunMY1690 ::getOKResponse (void )
410
410
{
411
411
return (getStringResponse (" OK" ));
412
412
}
413
413
414
414
// Returns true if MY1690 responds with a given string
415
- bool MY1690 ::getStringResponse (const char *expectedResponse)
415
+ bool SparkFunMY1690 ::getStringResponse (const char *expectedResponse)
416
416
{
417
417
uint8_t expectedLength = strlen (expectedResponse);
418
418
@@ -448,7 +448,7 @@ bool MY1690::getStringResponse(const char *expectedResponse)
448
448
}
449
449
450
450
// Returns false if no serial data is seen after maxTimeout
451
- bool MY1690 ::responseAvailable (uint8_t maxTimeout)
451
+ bool SparkFunMY1690 ::responseAvailable (uint8_t maxTimeout)
452
452
{
453
453
uint8_t counter = 0 ;
454
454
@@ -462,7 +462,7 @@ bool MY1690::responseAvailable(uint8_t maxTimeout)
462
462
return (true );
463
463
}
464
464
465
- void MY1690 ::clearBuffer (void )
465
+ void SparkFunMY1690 ::clearBuffer (void )
466
466
{
467
467
while (_serialPort->available ())
468
468
{
@@ -472,7 +472,7 @@ void MY1690::clearBuffer(void)
472
472
return ;
473
473
}
474
474
475
- void MY1690 ::sendCommand (uint8_t commandLength)
475
+ void SparkFunMY1690 ::sendCommand (uint8_t commandLength)
476
476
{
477
477
clearBuffer (); // Clear anything in the buffer
478
478
0 commit comments