Audio

Dependencies:   Lib_DFPlayerMini

Committer:
bluefish
Date:
Fri Sep 15 14:54:35 2017 +0000
Revision:
0:6e015ec7e3a7
Child:
1:e64636383d8c
???????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bluefish 0:6e015ec7e3a7 1 #include "Lib_DFPlayerMini.h"
bluefish 0:6e015ec7e3a7 2
bluefish 0:6e015ec7e3a7 3 DFPlayerMini::DFPlayerMini( PinName busy, PinName tx, PinName rx ) : _busy(busy), _serial( tx, rx ){
bluefish 0:6e015ec7e3a7 4 _func = NULL;
bluefish 0:6e015ec7e3a7 5 return;
bluefish 0:6e015ec7e3a7 6 }
bluefish 0:6e015ec7e3a7 7
bluefish 0:6e015ec7e3a7 8 DFPlayerMini::~DFPlayerMini(){
bluefish 0:6e015ec7e3a7 9 return;
bluefish 0:6e015ec7e3a7 10 }
bluefish 0:6e015ec7e3a7 11
bluefish 0:6e015ec7e3a7 12 // スタート
bluefish 0:6e015ec7e3a7 13 void DFPlayerMini::begin(){
bluefish 0:6e015ec7e3a7 14 _busy.mode( PullUp );
bluefish 0:6e015ec7e3a7 15 _serial.baud(9600);
bluefish 0:6e015ec7e3a7 16 _serial.format( 8, RawSerial::None, 1 );
bluefish 0:6e015ec7e3a7 17 return;
bluefish 0:6e015ec7e3a7 18 }
bluefish 0:6e015ec7e3a7 19
bluefish 0:6e015ec7e3a7 20 void DFPlayerMini::attachBusyInterrupt( BUSYFUNCPTR func ){
bluefish 0:6e015ec7e3a7 21 _func = func;
bluefish 0:6e015ec7e3a7 22 if( _func != NULL ){
bluefish 0:6e015ec7e3a7 23 _busy.fall( _func );
bluefish 0:6e015ec7e3a7 24 }
bluefish 0:6e015ec7e3a7 25 return;
bluefish 0:6e015ec7e3a7 26 }
bluefish 0:6e015ec7e3a7 27
bluefish 0:6e015ec7e3a7 28 // play next track
bluefish 0:6e015ec7e3a7 29 void DFPlayerMini::playNext(){
bluefish 0:6e015ec7e3a7 30 _send_command( DFPLAYER_NEXT, 0x00, 0x00 );
bluefish 0:6e015ec7e3a7 31 return;
bluefish 0:6e015ec7e3a7 32 }
bluefish 0:6e015ec7e3a7 33
bluefish 0:6e015ec7e3a7 34 // play previous track
bluefish 0:6e015ec7e3a7 35 void DFPlayerMini::playPrev(){
bluefish 0:6e015ec7e3a7 36 _send_command( DFPLAYER_PREV, 0x00, 0x00 );
bluefish 0:6e015ec7e3a7 37 return;
bluefish 0:6e015ec7e3a7 38 }
bluefish 0:6e015ec7e3a7 39
bluefish 0:6e015ec7e3a7 40 // play previous track
bluefish 0:6e015ec7e3a7 41 void DFPlayerMini::playNumber( uint16_t num ){
bluefish 0:6e015ec7e3a7 42 _send_command(
bluefish 0:6e015ec7e3a7 43 DFPLAYER_NUM,
bluefish 0:6e015ec7e3a7 44 (uint8_t)( ( num >> 8 ) & 0xFF ),
bluefish 0:6e015ec7e3a7 45 (uint8_t)( ( num >> 0 ) & 0xFF )
bluefish 0:6e015ec7e3a7 46 );
bluefish 0:6e015ec7e3a7 47 return;
bluefish 0:6e015ec7e3a7 48 }
bluefish 0:6e015ec7e3a7 49
bluefish 0:6e015ec7e3a7 50 // play previous track
bluefish 0:6e015ec7e3a7 51 void DFPlayerMini::playFolder( uint8_t folder, uint8_t num ){
bluefish 0:6e015ec7e3a7 52 _send_command( DFPLAYER_PLAYBACKFOLDER, folder, num );
bluefish 0:6e015ec7e3a7 53 return;
bluefish 0:6e015ec7e3a7 54 }
bluefish 0:6e015ec7e3a7 55
bluefish 0:6e015ec7e3a7 56 // increase volume
bluefish 0:6e015ec7e3a7 57 void DFPlayerMini::volumePlus(){
bluefish 0:6e015ec7e3a7 58 _send_command( DFPLAYER_VOL_PLUS, 0x00, 0x00 );
bluefish 0:6e015ec7e3a7 59 return;
bluefish 0:6e015ec7e3a7 60 }
bluefish 0:6e015ec7e3a7 61
bluefish 0:6e015ec7e3a7 62 // decrease volume
bluefish 0:6e015ec7e3a7 63 void DFPlayerMini::volumeMinus(){
bluefish 0:6e015ec7e3a7 64 _send_command( DFPLAYER_VOL_MINUS, 0x00, 0x00 );
bluefish 0:6e015ec7e3a7 65 return;
bluefish 0:6e015ec7e3a7 66 }
bluefish 0:6e015ec7e3a7 67
bluefish 0:6e015ec7e3a7 68 // ボリュームの設定
bluefish 0:6e015ec7e3a7 69 void DFPlayerMini::volumeSet( uint8_t vol ){
bluefish 0:6e015ec7e3a7 70 vol = ( vol > 30 ) ? 30 : vol ;
bluefish 0:6e015ec7e3a7 71 _send_command( DFPLAYER_VOL_SET, 0x00, vol );
bluefish 0:6e015ec7e3a7 72 return;
bluefish 0:6e015ec7e3a7 73 }
bluefish 0:6e015ec7e3a7 74
bluefish 0:6e015ec7e3a7 75 // コマンドの送信
bluefish 0:6e015ec7e3a7 76 void DFPlayerMini::_send_command( DFPLAYERMINICOM com, uint8_t param1, uint8_t param2 ){
bluefish 0:6e015ec7e3a7 77 uint8_t buf[8];
bluefish 0:6e015ec7e3a7 78
bluefish 0:6e015ec7e3a7 79 buf[0] = DFPLAYER_STX;
bluefish 0:6e015ec7e3a7 80 buf[1] = DFPLAYER_VER;
bluefish 0:6e015ec7e3a7 81 buf[2] = 0x06;
bluefish 0:6e015ec7e3a7 82 buf[3] = com;
bluefish 0:6e015ec7e3a7 83 buf[4] = 0x00;
bluefish 0:6e015ec7e3a7 84 buf[5] = param1;
bluefish 0:6e015ec7e3a7 85 buf[6] = param2;
bluefish 0:6e015ec7e3a7 86 buf[7] = DFPLAYER_ETX;
bluefish 0:6e015ec7e3a7 87
bluefish 0:6e015ec7e3a7 88 _serial.write( buf, 8 );
bluefish 0:6e015ec7e3a7 89
bluefish 0:6e015ec7e3a7 90 return;
bluefish 0:6e015ec7e3a7 91 }