use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed
Fork of 11U68_MP3Player with TFTLCD by
Diff: main.cpp
- Revision:
- 6:74271fce2368
- Parent:
- 5:a493361aead2
- Child:
- 7:fc65d965a569
--- a/main.cpp Thu Jul 16 18:18:00 2015 +0000 +++ b/main.cpp Fri Jul 17 21:35:57 2015 +0000 @@ -37,8 +37,8 @@ bool checkTouchBotton_prev(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_PREV_XPOS && xpos <= (BOTTON_PREV_XPOS+60) ) && - (ypos >= BOTTON_PREV_YPOS && ypos <= (BOTTON_PREV_YPOS+60)) ) + if( ( (xpos >= BOTTON_PREV_XPOS+5) && (xpos <= BOTTON_PREV_XPOS+55) ) && + ( (ypos >= BOTTON_PREV_YPOS+5) && (ypos <= BOTTON_PREV_YPOS+55) ) ) { result = 1; } @@ -48,8 +48,8 @@ bool checkTouchBotton_play(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_PLAY_XPOS && xpos <= (BOTTON_PLAY_XPOS+60) ) && - (ypos >= BOTTON_PLAY_YPOS && ypos <= (BOTTON_PLAY_YPOS+60)) ) + if( ( (xpos >= BOTTON_PLAY_XPOS+5) && (xpos <= BOTTON_PLAY_XPOS+55) ) && + ( (ypos >= BOTTON_PLAY_YPOS+5) && (ypos <= BOTTON_PLAY_YPOS+55) ) ) { result = 1; } @@ -59,8 +59,8 @@ bool checkTouchBotton_stop(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_STOP_XPOS && xpos <= (BOTTON_STOP_XPOS+60) ) && - (ypos >= BOTTON_STOP_XPOS && ypos <= (BOTTON_STOP_XPOS+60)) ) + if( ( (xpos >= BOTTON_STOP_XPOS+5) && (xpos <= BOTTON_STOP_XPOS+55) ) && + ( (ypos >= BOTTON_STOP_XPOS+5) && (ypos <= BOTTON_STOP_XPOS+55) ) ) { result = 1; } @@ -70,8 +70,8 @@ bool checkTouchBotton_next(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_NEXT_XPOS && xpos <= (BOTTON_NEXT_XPOS+60) ) && - (ypos >= BOTTON_NEXT_YPOS && ypos <= (BOTTON_NEXT_YPOS+60)) ) + if( ( (xpos >= BOTTON_NEXT_XPOS+5) && (xpos <= BOTTON_NEXT_XPOS+55) ) && + ( (ypos >= BOTTON_NEXT_YPOS+5) && (ypos <= BOTTON_NEXT_YPOS+55) ) ) { result = 1; } @@ -81,8 +81,8 @@ bool checkTouchBotton_volup(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_VOLUP_XPOS && xpos <= (BOTTON_VOLUP_XPOS+60) ) && - (ypos >= BOTTON_VOLUP_YPOS && ypos <= (BOTTON_VOLUP_YPOS+60)) ) + if( ( (xpos >= BOTTON_VOLUP_XPOS+5) && (xpos <= BOTTON_VOLUP_XPOS+55) ) && + ( (ypos >= BOTTON_VOLUP_YPOS+5) && (ypos <= BOTTON_VOLUP_YPOS+55) ) ) { result = 1; } @@ -92,22 +92,71 @@ bool checkTouchBotton_voldown(int32_t xpos,int32_t ypos) { bool result = 0; - if( (xpos >= BOTTON_VOLDOWN_XPOS && xpos <= (BOTTON_VOLDOWN_XPOS+60) ) && - (ypos >= BOTTON_VOLDOWN_YPOS && ypos <= (BOTTON_VOLDOWN_YPOS+60)) ) + if( ( (xpos >= BOTTON_VOLDOWN_XPOS+5) && (xpos <= BOTTON_VOLDOWN_XPOS+55) ) && + ( (ypos >= BOTTON_VOLDOWN_YPOS+5) && (ypos <= BOTTON_VOLDOWN_YPOS+55) ) ) { result = 1; } return result; } +#define TOUCHPANEL_BOTTON_TOUCH_STOP (0) +#define TOUCHPANEL_BOTTON_TOUCH_PLAY (1) +#define TOUCHPANEL_BOTTON_TOUCH_NEXT (2) +#define TOUCHPANEL_BOTTON_TOUCH_PREV (3) +#define TOUCHPANEL_BOTTON_TOUCH_VOLUP (4) +#define TOUCHPANEL_BOTTON_TOUCH_VOLDOWN (5) +#define TOUCHPANEL_BOTTON_NOT_TOUCH (-1) +#define TOUCHPANEL_OTHER_TOUCH (-2) + +int8_t detectTouchBotton(int32_t xpos,int32_t ypos) +{ + int8_t result = 0; + + if( checkTouchBotton_stop(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_STOP; + } + else if( checkTouchBotton_play(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_PLAY; + } + else if( checkTouchBotton_prev(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_PREV; + } + else if( checkTouchBotton_next(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_NEXT; + } + else if( checkTouchBotton_volup(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_VOLUP; + } + else if( checkTouchBotton_voldown(xpos,ypos) ) + { + result = TOUCHPANEL_BOTTON_TOUCH_VOLDOWN; + } + else if( (xpos == -1) || (ypos == -1) ) + { + result = TOUCHPANEL_BOTTON_NOT_TOUCH; + } + else + { + result = TOUCHPANEL_OTHER_TOUCH; + } + + return result; +} + uint8_t g_mp3Player_State = 0; uint16_t g_mp3Player_Volume = 0; bool gf_mp3Playwe_VolmeUpdate = 0; -bool gf_100ms = 0; +bool gf_TimerInt = 0; void Int100msFunc() { - gf_100ms = 1; + gf_TimerInt = 1; } int main() @@ -121,14 +170,14 @@ uint8_t buf[SD_READ_BLOCK_SIZE]; char str[100]; int32_t XReadPos = 0,YReadPos = 0; - static bool touchPanel_Touched = 0; + bool touchPanel_Touched = 0; //Format,Xsize,Ysize,PixelData const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; - const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; - const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; +// const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; +// const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; pc.baud(921600); printf("Power ON\r\n"); @@ -174,8 +223,8 @@ lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); - lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); - lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); +// lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); +// lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); //////////////////////////////////////////////////////////// /* SDCard GetFileList Section */ @@ -210,33 +259,6 @@ } closedir(d); - for(i=0;i<SDFileList_cnt;i++) - { - sprintf(str,"%d:%s",i,SDFileList_short[i]); - lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors - lcd.Print( "*", LEFT, 0 ); // align text to center horizontally and use starndard colors - } - - mp3PlayingFileNo = 0; - sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); - - printf("file count=%d\r\n",SDFileList_cnt); - printf("FirstPlayFile:%s\r\n",mp3PlayingFileName); - g_mp3Player_State = 0; - f_mp3Playwe_Playing = 0; - while(1) - { - -////////////////////////////////////////////////////////////// -/* TouchPanel GetStatas Section */ -////////////////////////////////////////////////////////////// - if(gf_100ms == 1) - { - XReadPos = getTouchPanelPosX(); - YReadPos = getTouchPanelPosY(); - gf_100ms = 0; - } - //g_mp3Player_Stateに対して↓ #define MP3_STATE_STOPPING (0) #define MP3_STATE_STOPREQ (1) @@ -247,79 +269,74 @@ #define MP3_STATE_VOLCHANGEREQ (6) #define MP3_STATE_REPLAY (7) #define MP3_STATE_FILECHANGE (8) + + printf("file count=%d\r\n",SDFileList_cnt); + mp3PlayingFileNo = 0; + g_mp3Player_State = MP3_STATE_FILECHANGE; + f_mp3Playwe_Playing = 0; - if( checkTouchBotton_prev(XReadPos,YReadPos) ) - { - if(touchPanel_Touched == 0) - { - printf("prev touch\r\n"); - g_mp3Player_State = MP3_STATE_PREVREQ; - touchPanel_Touched = 1; - } - } - else if( checkTouchBotton_play(XReadPos,YReadPos) ) - { - if(touchPanel_Touched == 0) - { - printf("play touch\r\n"); - if( (g_mp3Player_State != MP3_STATE_PLAYING) && (g_mp3Player_State != MP3_STATE_PLAYREQ) ) - { - g_mp3Player_State = MP3_STATE_PLAYREQ; - } - touchPanel_Touched = 1; - } - } - else if( checkTouchBotton_stop(XReadPos,YReadPos) ) - { - if(touchPanel_Touched == 0) - { - printf("stop touch\r\n"); - if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) ) - { - g_mp3Player_State = MP3_STATE_STOPREQ; - } - touchPanel_Touched = 1; - } - } - else if( checkTouchBotton_next(XReadPos,YReadPos) ) + while(1) + { + +////////////////////////////////////////////////////////////// +/* TouchPanel GetStatas Section */ +////////////////////////////////////////////////////////////// + if(gf_TimerInt == 1) { - if(touchPanel_Touched == 0) + XReadPos = getTouchPanelPosX(); + YReadPos = getTouchPanelPosY(); +// printf("X:%d Y:%d\r\n",XReadPos,YReadPos); + switch( detectTouchBotton(XReadPos,YReadPos) ) { - printf("next touch\r\n"); - g_mp3Player_State = MP3_STATE_NEXTREQ; - touchPanel_Touched = 1; - } - } - else if( checkTouchBotton_volup(XReadPos,YReadPos) ) - { - if(touchPanel_Touched == 0) - { - printf("volup touch\r\n"); - if(g_mp3Player_Volume >= 6527) - { - g_mp3Player_Volume-=6527; - gf_mp3Playwe_VolmeUpdate = 1; - } - touchPanel_Touched = 1; + case TOUCHPANEL_BOTTON_TOUCH_PREV: + if(touchPanel_Touched == 0) + { + printf("prev touch\r\n"); + g_mp3Player_State = MP3_STATE_PREVREQ; + touchPanel_Touched = 1; + } + break; + case TOUCHPANEL_BOTTON_TOUCH_PLAY: + if(touchPanel_Touched == 0) + { + printf("play touch\r\n"); + if( (g_mp3Player_State != MP3_STATE_PLAYING) && (g_mp3Player_State != MP3_STATE_PLAYREQ) ) + { + g_mp3Player_State = MP3_STATE_PLAYREQ; + } + touchPanel_Touched = 1; + } + break; + case TOUCHPANEL_BOTTON_TOUCH_STOP: + if(touchPanel_Touched == 0) + { + printf("stop touch\r\n"); + if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) ) + { + g_mp3Player_State = MP3_STATE_STOPREQ; + } + touchPanel_Touched = 1; + } + break; + case TOUCHPANEL_BOTTON_TOUCH_NEXT: + if(touchPanel_Touched == 0) + { + printf("next touch\r\n"); + g_mp3Player_State = MP3_STATE_NEXTREQ; + touchPanel_Touched = 1; + } + break; + case TOUCHPANEL_OTHER_TOUCH: + printf("otherTouch\r\n"); + printf("X:%d Y:%d\r\n",XReadPos,YReadPos); + break; + case TOUCHPANEL_BOTTON_NOT_TOUCH: +// printf("notTouch\r\n"); + touchPanel_Touched = 0; + break; + default : + break; } - - } - else if( checkTouchBotton_voldown(XReadPos,YReadPos) ) - { - if(touchPanel_Touched == 0) - { - printf("voldown touch\r\n"); - if(g_mp3Player_Volume <= 0xE57F ) - { - g_mp3Player_Volume+=6527; - gf_mp3Playwe_VolmeUpdate = 1; - } - touchPanel_Touched = 1; - } - } - else //any botton not touched - { - touchPanel_Touched = 0; } ////////////////////////////////////////////////////////////// @@ -337,7 +354,7 @@ { printf("Fail SD init\r\n"); printf("System Stop.\r\n"); - while(1); + NVIC_SystemReset(); } printf("Fail file open n=%d\r\n",SDFileOpenFailCnt); sd.disk_initialize(); @@ -354,20 +371,23 @@ rewind(fp); clearerr(fp); mp3_totalSizeSent = 0; + lcd.DrawRect(15,150,305,160); //Playing Bar g_mp3Player_State = MP3_STATE_PLAYING; } if( g_mp3Player_State == MP3_STATE_PLAYING ) { // printf("totalSendSize:%d\r\n",mp3_totalSizeSent); - if(mp3_totalSizeSent>=mp3_fileSize) //play song end { - g_mp3Player_State = MP3_STATE_STOPREQ; + f_mp3Playwe_Playing = 1; + g_mp3Player_State = MP3_STATE_NEXTREQ; //next song } else //transmit from SDCard to VS1033 { mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); + lcd.FillRect(15,150,15+290*mp3_totalSizeSent/mp3_fileSize,160,-2); + f_mp3Playwe_Playing = 1; } } @@ -386,8 +406,11 @@ } if(stopFailCnt >= 20) { - printf("ERROR! impossible of stop\r\nSystem STOP\r\n"); - while(1); + printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n"); + mp3.hardwareReset(); + mp3.sci_init(); + mp3.sdi_init(); + stopFailCnt = 0; } }while(returnCode != 0); fclose(fp); @@ -436,6 +459,14 @@ if( g_mp3Player_State == MP3_STATE_FILECHANGE ) { printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]); + + for(i=0;i<SDFileList_cnt;i++) + { + sprintf(str,"%d:%s",i,SDFileList_short[i]); + lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors + } + lcd.Print( "*", LEFT, 28*mp3PlayingFileNo ); // align text to center horizontally and use starndard colors + sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); if(f_mp3Playwe_Playing == 1) {