+mp3

Dependencies:   mbed

Fork of VS1053 by SGMP Coperations

Revision:
6:447108751338
Parent:
5:ce3a3ce60f30
--- a/player.cpp	Tue Dec 12 14:04:24 2017 +0000
+++ b/player.cpp	Tue Dec 12 19:05:24 2017 +0000
@@ -5,6 +5,8 @@
 vs10xx vs1053(D11, D12, D13, D6, D7, D2, D8);//mosi,miso,sclk,xcs,xdcs,dreq,xreset
 Serial aa(USBTX, USBRX);
 Serial pc(D1, D0);
+Serial lcd(PA_11,PA_12);
+Serial bt(PA_15,PB_7);
 playerStatetype  playerState;
 static unsigned char fileBuf[48000];
 unsigned char *bufptr;
@@ -16,7 +18,13 @@
 char list[20][50];            //song list
 
 char data ;
-DigitalIn sw_in(USER_BUTTON);
+
+char button,press,test_pop;
+uint8_t test,test_get;
+int state,size,count_ok,mode_name,mode_button,count_press,page,game_mode,set_mode_loop;
+char alphabet [26]  = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
+char user_name[10];
+
 
 void Player::begin(void)
 {
@@ -70,38 +78,198 @@
     playerState =PS_STOP;
     }
     
+//--------------------------------------------------------------------//
+    
+void Player::SGMP_First_Page(void){
+    pc.printf("SGMP\nPress Enter to start\n");
+    lcd.printf("p001f");
+    selectfile(3);
+    playFile(list[green]);
+    while(1){
+        
+        if(bt.readable()) {
+            button = bt.getc();
+            if (button == 'E'){
+                button = NULL;
+                break;
+            }
+        }
+    }
+}
+
+void Player::set_name(void) {
+    lcd.puts("p002f");
+    wait_ms(500);
+    lcd.printf("%c",char(alphabet[state]));
+    state = 0;
+    size = 0;
+    count_ok = 0;
+    mode_name = 1;
+    
+    while(mode_name){
+        if(bt.readable()) {
+            button = bt.getc();
+//            pc.printf("button = %c \n",button);
+//            }}}
+            switch(button){
+                case 'U':                      //UP Button
+                    if(state == 0){
+                        state = 25;
+                    }
+                    else{
+                        state--; 
+                    }
+                    lcd.printf("%c",char(alphabet[state]));
+                    pc.printf("alphabet = %c     ",alphabet[state]);
+                    pc.printf("    name = %s     \n",user_name);
+//                    pc.printf("    size = %d     ",size);
+//                    pc.printf("    state = %d \n",state);
+                    wait_ms(600);
+                    count_ok = 0;
+                    break;
+                case 'D':                     //DOWN Button
+                    if(state == 25){
+                        state = 0;
+                    }
+                    else{
+                        state++; 
+                    }
+                    lcd.printf("%c",char(alphabet[state]));
+                    pc.printf("alphabet = %c     ",alphabet[state]);
+                    pc.printf("    name = %s     \n",user_name);
+//                    pc.printf("    size = %d     ",size);
+//                    pc.printf("    state = %d \n",state);
+//                    pc.printf("DOWN\n");
+                    wait_ms(600);
+                    count_ok = 0;
+                    break;
+                case 'O':                     //OK Button
+                    user_name[size++] = alphabet[state];
+                    lcd.printf("k%sf",user_name);
+                    pc.printf("alphabet = %c     ",alphabet[state]);
+                    pc.printf("    name = %s     \n",user_name);
+//                    pc.printf("    size = %d     ",size);
+//                    pc.printf("    state = %d \n",state);
+                    
+//                    pc.printf("%c\n",button);
+                    
+                    wait_ms(600);
+                    
+                    break;
+                case 'C':                     //OK Button
+                    if(size > 0){
+                        size--;
+                        user_name[size] = NULL;
+                    }
+                    lcd.printf("k%sf",user_name);
+                    pc.printf("alphabet = %c     ",alphabet[state]);
+                    pc.printf("    name = %s     \n",user_name);
+//                    pc.printf("    size = %d     ",size);
+//                    pc.printf("    state = %d \n",state);
+                    
+//                    pc.printf("%c\n",button);
+                    
+                    wait_ms(600);
+                    
+                    break;
+                case 'E':                     //Enter Button
+                    page = 3;
+                    lcd.printf("x");
+                    mode_name = 0;
+                    
+//                    pc.printf("ENTER\n");
+//                    wait_ms(600);
+                    break;
+                    
+            }
+        }
+
+    }
+    button = NULL;
+    wait_ms(600);
+//    lcd.printf("Name = %s",user_name);
+//    pc.printf("alphabet = %c     ",alphabet[state]);
+    pc.printf("    name = %s     \n",user_name);
+//    pc.printf("    size = %d     ",size);
+//    pc.printf("    state = %d \n",state);
+//    return user_name;
+	pc.printf("finish your name is : %s \n",user_name);
+}
+
+void Player::set_mode(void){
+    lcd.puts("p003f");
+    button = NULL;
+    wait_ms(600);
+    set_mode_loop = 1;
+//    lcd.printf("%d",game_mode);
+    while(set_mode_loop){
+        if(bt.readable()) {
+            button = bt.getc();
+            switch(button){
+                case 'U':
+                    if(game_mode == 1){
+                        game_mode = 3;
+                    }
+                    else{
+                        game_mode--;
+                    }
+                    wait_ms(600);
+                    lcd.printf("%d",game_mode);
+                    pc.printf("set_mode = %d \n",game_mode);
+                    break;
+                case 'D':
+                    if(game_mode == 3){
+                        game_mode = 1;
+                    }
+                    else{
+                        game_mode++;
+                    }
+                    wait_ms(600);
+                    lcd.printf("%d",game_mode);
+                    pc.printf("set_mode = %d \n",game_mode);
+                    break;
+                case 'E':
+                    set_mode_loop = 0;
+                    break;
+            }
+        }
+    }
+    pc.printf("finish set_mode = %d \n",game_mode);
+}
+    
+//--------------------------------------------------------------------//
     
 void Player::run(void){	
 			if(datainput=='0'){
 				selectfile(0);
 				playFile(list[green]);
-    			//stop();
+    	
 				}
 			if(datainput=='1'){
 				selectfile(1);
 				playFile(list[green]);
-				//stop();
+				
 				
 				}
 			if(datainput=='2'){
 				selectfile(2);
 				playFile(list[green]);
-    			//stop();
+    		
 				}
 			if(datainput=='3'){
 				selectfile(3);
 				playFile(list[green]);
-    			//stop();
+    			
 				}
 			if(datainput=='4'){
 				selectfile(4);
 				playFile(list[green]);
-    			//stop();
+
 				}
 			if(datainput=='5'){
 				selectfile(5);
 				playFile(list[green]);
-    			//stop();
+
 				}
 			else{
 				stop();
@@ -110,11 +278,11 @@
 
 
 
-void Player::read(void){
-	pc.readable();
-	datainput = pc.getc();
-
-    }
+//void Player::read(void){
+//	bt.readable();
+//	datainput = bt.getc();
+//
+//    }
 
     
     
@@ -140,10 +308,8 @@
         /* Main playback loop */
         while((bytes = fp->read(fileBuf,48000)) > 0) {	
        {
-            pc.printf("green\n");
-            if(pc.readable()){
+            if(bt.readable()){
             	break;
-    			//stop();
     			}
     		vs1053.setFreq(24000000); 
             bufptr = fileBuf;
@@ -154,9 +320,8 @@
                 vs1053.writeData(bufptr,n);
                 bytes -= n;
                 bufptr += n;
-                if(pc.readable()){
+                if(bt.readable()){
                 	break;
-    				//stop();
     			}
                 
             }