use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: TFTLCDwithFastIO FastIO SDFileSystem TouchPanel VS1033 mbed
main.cpp@9:96b053c0865e, 2015-07-30 (annotated)
- Committer:
- nameless129
- Date:
- Thu Jul 30 06:54:23 2015 +0000
- Revision:
- 9:96b053c0865e
- Parent:
- 8:198b69e78c39
- Child:
- 10:93267d24ad1a
???????????if???swtch case??????; ???????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nameless129 | 7:fc65d965a569 | 1 | #pragma O3 |
nameless129 | 7:fc65d965a569 | 2 | |
nameless129 | 8:198b69e78c39 | 3 | #include "FastIO.h" |
nameless129 | 0:5f0e931ae677 | 4 | #include "ili9328.h" |
nameless129 | 5:a493361aead2 | 5 | #include "stdio.h" |
nameless129 | 5:a493361aead2 | 6 | #include "string.h" |
nameless129 | 2:0090839c8276 | 7 | #include "SDFileSystem.h" |
nameless129 | 2:0090839c8276 | 8 | #include "VS1053.h" |
nameless129 | 3:67e97c846cec | 9 | #include "image.h" |
nameless129 | 3:67e97c846cec | 10 | #include "TouchPanel.h" |
nameless129 | 3:67e97c846cec | 11 | #include "mbed.h" |
nameless129 | 2:0090839c8276 | 12 | |
nameless129 | 0:5f0e931ae677 | 13 | // prepare the data bus for writing commands and pixel data |
nameless129 | 0:5f0e931ae677 | 14 | // create the lcd instance |
nameless129 | 0:5f0e931ae677 | 15 | //(PinName CS, PinName RESET, PinName RS, PinName WR, BusOut *DATA_PORT, PinName BL=NC, PinName RD=NC, backlight_t blType=Constant, float defaultBackLightLevel=1.0) |
nameless129 | 8:198b69e78c39 | 16 | ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, NULL, NC, P1_9 ); // control pins and data bus |
nameless129 | 2:0090839c8276 | 17 | |
nameless129 | 9:96b053c0865e | 18 | SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); |
nameless129 | 2:0090839c8276 | 19 | VS1053 mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23, |
nameless129 | 7:fc65d965a569 | 20 | /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 5000000); |
nameless129 | 5:a493361aead2 | 21 | Ticker Int100ms; |
nameless129 | 3:67e97c846cec | 22 | |
nameless129 | 3:67e97c846cec | 23 | Serial pc(P0_19,P0_18); |
nameless129 | 9:96b053c0865e | 24 | #define SD_READ_BLOCK_SIZE (256) |
nameless129 | 2:0090839c8276 | 25 | |
nameless129 | 3:67e97c846cec | 26 | #define BOTTON_PREV_XPOS (15) |
nameless129 | 7:fc65d965a569 | 27 | #define BOTTON_PREV_YPOS (180) |
nameless129 | 3:67e97c846cec | 28 | #define BOTTON_PLAY_XPOS (91) |
nameless129 | 7:fc65d965a569 | 29 | #define BOTTON_PLAY_YPOS (180) |
nameless129 | 3:67e97c846cec | 30 | #define BOTTON_STOP_XPOS (168) |
nameless129 | 7:fc65d965a569 | 31 | #define BOTTON_STOP_YPOS (180) |
nameless129 | 3:67e97c846cec | 32 | #define BOTTON_NEXT_XPOS (245) |
nameless129 | 7:fc65d965a569 | 33 | #define BOTTON_NEXT_YPOS (180) |
nameless129 | 3:67e97c846cec | 34 | #define BOTTON_VOLUP_XPOS (245) |
nameless129 | 3:67e97c846cec | 35 | #define BOTTON_VOLUP_YPOS (10) |
nameless129 | 3:67e97c846cec | 36 | #define BOTTON_VOLDOWN_XPOS (245) |
nameless129 | 3:67e97c846cec | 37 | #define BOTTON_VOLDOWN_YPOS (80) |
nameless129 | 3:67e97c846cec | 38 | |
nameless129 | 3:67e97c846cec | 39 | bool checkTouchBotton_prev(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 40 | { |
nameless129 | 3:67e97c846cec | 41 | bool result = 0; |
nameless129 | 6:74271fce2368 | 42 | if( ( (xpos >= BOTTON_PREV_XPOS+5) && (xpos <= BOTTON_PREV_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 43 | ( (ypos >= BOTTON_PREV_YPOS+5) && (ypos <= BOTTON_PREV_YPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 44 | { |
nameless129 | 3:67e97c846cec | 45 | result = 1; |
nameless129 | 3:67e97c846cec | 46 | } |
nameless129 | 3:67e97c846cec | 47 | return result; |
nameless129 | 3:67e97c846cec | 48 | } |
nameless129 | 3:67e97c846cec | 49 | |
nameless129 | 3:67e97c846cec | 50 | bool checkTouchBotton_play(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 51 | { |
nameless129 | 3:67e97c846cec | 52 | bool result = 0; |
nameless129 | 6:74271fce2368 | 53 | if( ( (xpos >= BOTTON_PLAY_XPOS+5) && (xpos <= BOTTON_PLAY_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 54 | ( (ypos >= BOTTON_PLAY_YPOS+5) && (ypos <= BOTTON_PLAY_YPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 55 | { |
nameless129 | 3:67e97c846cec | 56 | result = 1; |
nameless129 | 3:67e97c846cec | 57 | } |
nameless129 | 3:67e97c846cec | 58 | return result; |
nameless129 | 3:67e97c846cec | 59 | } |
nameless129 | 3:67e97c846cec | 60 | |
nameless129 | 3:67e97c846cec | 61 | bool checkTouchBotton_stop(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 62 | { |
nameless129 | 3:67e97c846cec | 63 | bool result = 0; |
nameless129 | 6:74271fce2368 | 64 | if( ( (xpos >= BOTTON_STOP_XPOS+5) && (xpos <= BOTTON_STOP_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 65 | ( (ypos >= BOTTON_STOP_XPOS+5) && (ypos <= BOTTON_STOP_XPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 66 | { |
nameless129 | 3:67e97c846cec | 67 | result = 1; |
nameless129 | 3:67e97c846cec | 68 | } |
nameless129 | 3:67e97c846cec | 69 | return result; |
nameless129 | 3:67e97c846cec | 70 | } |
nameless129 | 3:67e97c846cec | 71 | |
nameless129 | 3:67e97c846cec | 72 | bool checkTouchBotton_next(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 73 | { |
nameless129 | 3:67e97c846cec | 74 | bool result = 0; |
nameless129 | 6:74271fce2368 | 75 | if( ( (xpos >= BOTTON_NEXT_XPOS+5) && (xpos <= BOTTON_NEXT_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 76 | ( (ypos >= BOTTON_NEXT_YPOS+5) && (ypos <= BOTTON_NEXT_YPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 77 | { |
nameless129 | 3:67e97c846cec | 78 | result = 1; |
nameless129 | 3:67e97c846cec | 79 | } |
nameless129 | 3:67e97c846cec | 80 | return result; |
nameless129 | 3:67e97c846cec | 81 | } |
nameless129 | 3:67e97c846cec | 82 | |
nameless129 | 3:67e97c846cec | 83 | bool checkTouchBotton_volup(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 84 | { |
nameless129 | 3:67e97c846cec | 85 | bool result = 0; |
nameless129 | 6:74271fce2368 | 86 | if( ( (xpos >= BOTTON_VOLUP_XPOS+5) && (xpos <= BOTTON_VOLUP_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 87 | ( (ypos >= BOTTON_VOLUP_YPOS+5) && (ypos <= BOTTON_VOLUP_YPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 88 | { |
nameless129 | 3:67e97c846cec | 89 | result = 1; |
nameless129 | 3:67e97c846cec | 90 | } |
nameless129 | 3:67e97c846cec | 91 | return result; |
nameless129 | 3:67e97c846cec | 92 | } |
nameless129 | 3:67e97c846cec | 93 | |
nameless129 | 3:67e97c846cec | 94 | bool checkTouchBotton_voldown(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 95 | { |
nameless129 | 3:67e97c846cec | 96 | bool result = 0; |
nameless129 | 6:74271fce2368 | 97 | if( ( (xpos >= BOTTON_VOLDOWN_XPOS+5) && (xpos <= BOTTON_VOLDOWN_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 98 | ( (ypos >= BOTTON_VOLDOWN_YPOS+5) && (ypos <= BOTTON_VOLDOWN_YPOS+55) ) ) |
nameless129 | 3:67e97c846cec | 99 | { |
nameless129 | 3:67e97c846cec | 100 | result = 1; |
nameless129 | 3:67e97c846cec | 101 | } |
nameless129 | 3:67e97c846cec | 102 | return result; |
nameless129 | 3:67e97c846cec | 103 | } |
nameless129 | 3:67e97c846cec | 104 | |
nameless129 | 6:74271fce2368 | 105 | #define TOUCHPANEL_BOTTON_TOUCH_STOP (0) |
nameless129 | 6:74271fce2368 | 106 | #define TOUCHPANEL_BOTTON_TOUCH_PLAY (1) |
nameless129 | 6:74271fce2368 | 107 | #define TOUCHPANEL_BOTTON_TOUCH_NEXT (2) |
nameless129 | 6:74271fce2368 | 108 | #define TOUCHPANEL_BOTTON_TOUCH_PREV (3) |
nameless129 | 6:74271fce2368 | 109 | #define TOUCHPANEL_BOTTON_TOUCH_VOLUP (4) |
nameless129 | 6:74271fce2368 | 110 | #define TOUCHPANEL_BOTTON_TOUCH_VOLDOWN (5) |
nameless129 | 6:74271fce2368 | 111 | #define TOUCHPANEL_BOTTON_NOT_TOUCH (-1) |
nameless129 | 6:74271fce2368 | 112 | #define TOUCHPANEL_OTHER_TOUCH (-2) |
nameless129 | 6:74271fce2368 | 113 | |
nameless129 | 6:74271fce2368 | 114 | int8_t detectTouchBotton(int32_t xpos,int32_t ypos) |
nameless129 | 6:74271fce2368 | 115 | { |
nameless129 | 6:74271fce2368 | 116 | int8_t result = 0; |
nameless129 | 6:74271fce2368 | 117 | |
nameless129 | 6:74271fce2368 | 118 | if( checkTouchBotton_stop(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 119 | { |
nameless129 | 6:74271fce2368 | 120 | result = TOUCHPANEL_BOTTON_TOUCH_STOP; |
nameless129 | 6:74271fce2368 | 121 | } |
nameless129 | 6:74271fce2368 | 122 | else if( checkTouchBotton_play(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 123 | { |
nameless129 | 6:74271fce2368 | 124 | result = TOUCHPANEL_BOTTON_TOUCH_PLAY; |
nameless129 | 6:74271fce2368 | 125 | } |
nameless129 | 6:74271fce2368 | 126 | else if( checkTouchBotton_prev(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 127 | { |
nameless129 | 6:74271fce2368 | 128 | result = TOUCHPANEL_BOTTON_TOUCH_PREV; |
nameless129 | 6:74271fce2368 | 129 | } |
nameless129 | 6:74271fce2368 | 130 | else if( checkTouchBotton_next(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 131 | { |
nameless129 | 6:74271fce2368 | 132 | result = TOUCHPANEL_BOTTON_TOUCH_NEXT; |
nameless129 | 6:74271fce2368 | 133 | } |
nameless129 | 6:74271fce2368 | 134 | else if( checkTouchBotton_volup(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 135 | { |
nameless129 | 6:74271fce2368 | 136 | result = TOUCHPANEL_BOTTON_TOUCH_VOLUP; |
nameless129 | 6:74271fce2368 | 137 | } |
nameless129 | 6:74271fce2368 | 138 | else if( checkTouchBotton_voldown(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 139 | { |
nameless129 | 6:74271fce2368 | 140 | result = TOUCHPANEL_BOTTON_TOUCH_VOLDOWN; |
nameless129 | 6:74271fce2368 | 141 | } |
nameless129 | 6:74271fce2368 | 142 | else if( (xpos == -1) || (ypos == -1) ) |
nameless129 | 6:74271fce2368 | 143 | { |
nameless129 | 6:74271fce2368 | 144 | result = TOUCHPANEL_BOTTON_NOT_TOUCH; |
nameless129 | 6:74271fce2368 | 145 | } |
nameless129 | 6:74271fce2368 | 146 | else |
nameless129 | 6:74271fce2368 | 147 | { |
nameless129 | 6:74271fce2368 | 148 | result = TOUCHPANEL_OTHER_TOUCH; |
nameless129 | 6:74271fce2368 | 149 | } |
nameless129 | 6:74271fce2368 | 150 | |
nameless129 | 6:74271fce2368 | 151 | return result; |
nameless129 | 6:74271fce2368 | 152 | } |
nameless129 | 6:74271fce2368 | 153 | |
nameless129 | 5:a493361aead2 | 154 | uint8_t g_mp3Player_State = 0; |
nameless129 | 5:a493361aead2 | 155 | uint16_t g_mp3Player_Volume = 0; |
nameless129 | 5:a493361aead2 | 156 | bool gf_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 6:74271fce2368 | 157 | bool gf_TimerInt = 0; |
nameless129 | 5:a493361aead2 | 158 | |
nameless129 | 5:a493361aead2 | 159 | void Int100msFunc() |
nameless129 | 5:a493361aead2 | 160 | { |
nameless129 | 6:74271fce2368 | 161 | gf_TimerInt = 1; |
nameless129 | 5:a493361aead2 | 162 | } |
nameless129 | 2:0090839c8276 | 163 | |
nameless129 | 0:5f0e931ae677 | 164 | int main() |
nameless129 | 0:5f0e931ae677 | 165 | { |
nameless129 | 2:0090839c8276 | 166 | static FILE *fp = NULL; |
nameless129 | 3:67e97c846cec | 167 | uint8_t SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 168 | size_t mp3_ReadFileSize = 0; |
nameless129 | 3:67e97c846cec | 169 | size_t mp3_totalSizeSent=0; |
nameless129 | 3:67e97c846cec | 170 | size_t mp3_fileSize=0; |
nameless129 | 3:67e97c846cec | 171 | bool f_mp3Playwe_Playing = 0; |
nameless129 | 2:0090839c8276 | 172 | uint8_t buf[SD_READ_BLOCK_SIZE]; |
nameless129 | 3:67e97c846cec | 173 | char str[100]; |
nameless129 | 3:67e97c846cec | 174 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 9:96b053c0865e | 175 | uint32_t aveXReadPos = 0,aveYReadPos = 0; |
nameless129 | 9:96b053c0865e | 176 | uint8_t c_TouchPanelAve = 0; |
nameless129 | 6:74271fce2368 | 177 | bool touchPanel_Touched = 0; |
nameless129 | 7:fc65d965a569 | 178 | uint32_t totalPlay = 0; |
nameless129 | 7:fc65d965a569 | 179 | int dot1_FileSize = 0; |
nameless129 | 7:fc65d965a569 | 180 | int dot_XPos = 0,old_dot_XPos = 0; |
nameless129 | 8:198b69e78c39 | 181 | int lcd_FileViewPage = 0,old_lcd_FileViewPage = 0; |
nameless129 | 8:198b69e78c39 | 182 | int lcd_FileViewListEnd = 0; |
nameless129 | 8:198b69e78c39 | 183 | |
nameless129 | 3:67e97c846cec | 184 | //Format,Xsize,Ysize,PixelData |
nameless129 | 3:67e97c846cec | 185 | const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; |
nameless129 | 3:67e97c846cec | 186 | const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; |
nameless129 | 3:67e97c846cec | 187 | const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; |
nameless129 | 3:67e97c846cec | 188 | const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; |
nameless129 | 8:198b69e78c39 | 189 | const bitmap_t img_button_pause = { RGB16, 60, 60, &bmp_button_pause }; |
nameless129 | 8:198b69e78c39 | 190 | |
nameless129 | 6:74271fce2368 | 191 | // const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; |
nameless129 | 6:74271fce2368 | 192 | // const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; |
nameless129 | 9:96b053c0865e | 193 | |
nameless129 | 9:96b053c0865e | 194 | |
nameless129 | 5:a493361aead2 | 195 | pc.baud(921600); |
nameless129 | 5:a493361aead2 | 196 | printf("Power ON\r\n"); |
nameless129 | 2:0090839c8276 | 197 | |
nameless129 | 9:96b053c0865e | 198 | Int100ms.attach_us(&Int100msFunc, 10000); |
nameless129 | 2:0090839c8276 | 199 | |
nameless129 | 3:67e97c846cec | 200 | //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ |
nameless129 | 3:67e97c846cec | 201 | sd.disk_initialize(); |
nameless129 | 9:96b053c0865e | 202 | printf("SDCard inited.\r\n"); |
nameless129 | 3:67e97c846cec | 203 | |
nameless129 | 2:0090839c8276 | 204 | //LCD Init. |
nameless129 | 0:5f0e931ae677 | 205 | lcd.Initialize(LANDSCAPE,RGB16); |
nameless129 | 9:96b053c0865e | 206 | printf("LCD inited.\r\n"); |
nameless129 | 2:0090839c8276 | 207 | |
nameless129 | 2:0090839c8276 | 208 | /* for sine test mode */ |
nameless129 | 2:0090839c8276 | 209 | // mp3.sine_test_activate(SineWave_10k); |
nameless129 | 2:0090839c8276 | 210 | // while(1); |
nameless129 | 3:67e97c846cec | 211 | |
nameless129 | 2:0090839c8276 | 212 | //MP3 decoder Init. |
nameless129 | 2:0090839c8276 | 213 | mp3.hardwareReset(); |
nameless129 | 2:0090839c8276 | 214 | mp3.sci_init(); |
nameless129 | 2:0090839c8276 | 215 | mp3.sdi_init(); |
nameless129 | 2:0090839c8276 | 216 | wait(0.1); |
nameless129 | 9:96b053c0865e | 217 | printf("VS1033 inited.\r\n"); |
nameless129 | 2:0090839c8276 | 218 | printf("init CMPL.\r\n"); |
nameless129 | 2:0090839c8276 | 219 | |
nameless129 | 0:5f0e931ae677 | 220 | lcd.SetBackground(COLOR_BLUE); |
nameless129 | 0:5f0e931ae677 | 221 | lcd.FillScreen(-1); |
nameless129 | 5:a493361aead2 | 222 | lcd.SetFont( &TerminusBigFont ); |
nameless129 | 2:0090839c8276 | 223 | |
nameless129 | 5:a493361aead2 | 224 | //for Caliblation |
nameless129 | 5:a493361aead2 | 225 | while(0) |
nameless129 | 5:a493361aead2 | 226 | { |
nameless129 | 5:a493361aead2 | 227 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 5:a493361aead2 | 228 | lcd.DrawCircle(40,40,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 229 | lcd.DrawCircle(280,200,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 230 | XReadPos = getTouchPanelPosX(); |
nameless129 | 5:a493361aead2 | 231 | YReadPos = getTouchPanelPosY(); |
nameless129 | 5:a493361aead2 | 232 | printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 5:a493361aead2 | 233 | wait_ms(500); |
nameless129 | 5:a493361aead2 | 234 | } |
nameless129 | 5:a493361aead2 | 235 | |
nameless129 | 3:67e97c846cec | 236 | //Xpos, Ypos, ImageData(type:bitmap_t), Scale |
nameless129 | 3:67e97c846cec | 237 | lcd.DrawBitmap( BOTTON_PREV_XPOS, BOTTON_PREV_YPOS, (const bitmap_t*)&img_button_prev, 1 ); |
nameless129 | 3:67e97c846cec | 238 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 3:67e97c846cec | 239 | lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); |
nameless129 | 3:67e97c846cec | 240 | lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); |
nameless129 | 8:198b69e78c39 | 241 | |
nameless129 | 6:74271fce2368 | 242 | // lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); |
nameless129 | 6:74271fce2368 | 243 | // lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); |
nameless129 | 2:0090839c8276 | 244 | |
nameless129 | 5:a493361aead2 | 245 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 246 | /* SDCard GetFileList Section */ |
nameless129 | 5:a493361aead2 | 247 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 248 | #define SD_MAX_FILENAME_LENGTH (256) //MAX 256 |
nameless129 | 8:198b69e78c39 | 249 | #define SD_MAX_FILE_COUNT (50) |
nameless129 | 5:a493361aead2 | 250 | |
nameless129 | 5:a493361aead2 | 251 | char SDFileList[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 252 | char SDFileList_short[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 253 | char SDFileList_cnt = 0; |
nameless129 | 5:a493361aead2 | 254 | char mp3PlayingFileName[SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 255 | uint8_t mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 256 | int i = 0; |
nameless129 | 5:a493361aead2 | 257 | DIR *d; |
nameless129 | 5:a493361aead2 | 258 | struct dirent *p; |
nameless129 | 5:a493361aead2 | 259 | |
nameless129 | 5:a493361aead2 | 260 | d = opendir("/sd"); |
nameless129 | 5:a493361aead2 | 261 | if ( d != NULL ) |
nameless129 | 5:a493361aead2 | 262 | { |
nameless129 | 5:a493361aead2 | 263 | while ( (p = readdir(d)) != NULL ) |
nameless129 | 5:a493361aead2 | 264 | { |
nameless129 | 5:a493361aead2 | 265 | char *ret; |
nameless129 | 5:a493361aead2 | 266 | ret = strstr(p->d_name,"System"); //System Vol..フォルダは除外 |
nameless129 | 5:a493361aead2 | 267 | if(ret == 0) |
nameless129 | 5:a493361aead2 | 268 | { |
nameless129 | 5:a493361aead2 | 269 | sprintf((char *)(SDFileList_short[i]+0),"%s",(const char *)p->d_name); |
nameless129 | 5:a493361aead2 | 270 | sprintf((char *)(SDFileList[i]+0),"/sd/%s",(const char *)p->d_name); |
nameless129 | 8:198b69e78c39 | 271 | printf("FileFound:%d,%s\r\n",i,SDFileList[i]); |
nameless129 | 5:a493361aead2 | 272 | i+=1; |
nameless129 | 5:a493361aead2 | 273 | } |
nameless129 | 5:a493361aead2 | 274 | } |
nameless129 | 5:a493361aead2 | 275 | SDFileList_cnt = i; |
nameless129 | 5:a493361aead2 | 276 | } |
nameless129 | 5:a493361aead2 | 277 | closedir(d); |
nameless129 | 5:a493361aead2 | 278 | |
nameless129 | 5:a493361aead2 | 279 | //g_mp3Player_Stateに対して↓ |
nameless129 | 3:67e97c846cec | 280 | #define MP3_STATE_STOPPING (0) |
nameless129 | 3:67e97c846cec | 281 | #define MP3_STATE_STOPREQ (1) |
nameless129 | 3:67e97c846cec | 282 | #define MP3_STATE_PLAYREQ (2) |
nameless129 | 3:67e97c846cec | 283 | #define MP3_STATE_PLAYING (3) |
nameless129 | 3:67e97c846cec | 284 | #define MP3_STATE_NEXTREQ (4) |
nameless129 | 3:67e97c846cec | 285 | #define MP3_STATE_PREVREQ (5) |
nameless129 | 3:67e97c846cec | 286 | #define MP3_STATE_VOLCHANGEREQ (6) |
nameless129 | 5:a493361aead2 | 287 | #define MP3_STATE_REPLAY (7) |
nameless129 | 5:a493361aead2 | 288 | #define MP3_STATE_FILECHANGE (8) |
nameless129 | 8:198b69e78c39 | 289 | #define MP3_STATE_PAUSEREQ (9) |
nameless129 | 8:198b69e78c39 | 290 | #define MP3_STATE_PAUSEING (10) |
nameless129 | 8:198b69e78c39 | 291 | #define MP3_STATE_RESUMEREQ (11) |
nameless129 | 6:74271fce2368 | 292 | |
nameless129 | 6:74271fce2368 | 293 | printf("file count=%d\r\n",SDFileList_cnt); |
nameless129 | 9:96b053c0865e | 294 | |
nameless129 | 6:74271fce2368 | 295 | mp3PlayingFileNo = 0; |
nameless129 | 6:74271fce2368 | 296 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 6:74271fce2368 | 297 | f_mp3Playwe_Playing = 0; |
nameless129 | 9:96b053c0865e | 298 | lcd.Print("STOP ",15,145); |
nameless129 | 9:96b053c0865e | 299 | lcd.DrawRect(135,155,310,165,COLOR_WHITE); |
nameless129 | 9:96b053c0865e | 300 | lcd.FillRect(136,156,309,164,COLOR_BLUE); |
nameless129 | 3:67e97c846cec | 301 | |
nameless129 | 6:74271fce2368 | 302 | while(1) |
nameless129 | 6:74271fce2368 | 303 | { |
nameless129 | 6:74271fce2368 | 304 | |
nameless129 | 6:74271fce2368 | 305 | ////////////////////////////////////////////////////////////// |
nameless129 | 6:74271fce2368 | 306 | /* TouchPanel GetStatas Section */ |
nameless129 | 6:74271fce2368 | 307 | ////////////////////////////////////////////////////////////// |
nameless129 | 6:74271fce2368 | 308 | if(gf_TimerInt == 1) |
nameless129 | 3:67e97c846cec | 309 | { |
nameless129 | 9:96b053c0865e | 310 | gf_TimerInt = 0; |
nameless129 | 9:96b053c0865e | 311 | |
nameless129 | 6:74271fce2368 | 312 | XReadPos = getTouchPanelPosX(); |
nameless129 | 6:74271fce2368 | 313 | YReadPos = getTouchPanelPosY(); |
nameless129 | 9:96b053c0865e | 314 | |
nameless129 | 9:96b053c0865e | 315 | if( detectTouchBotton(XReadPos,YReadPos) == TOUCHPANEL_BOTTON_NOT_TOUCH ) |
nameless129 | 9:96b053c0865e | 316 | { |
nameless129 | 9:96b053c0865e | 317 | c_TouchPanelAve = 0; |
nameless129 | 9:96b053c0865e | 318 | touchPanel_Touched = 0; |
nameless129 | 9:96b053c0865e | 319 | aveXReadPos = 0; |
nameless129 | 9:96b053c0865e | 320 | aveYReadPos = 0; |
nameless129 | 9:96b053c0865e | 321 | } |
nameless129 | 9:96b053c0865e | 322 | #define TOUCHPANEL_AVERAGE_COUNT (5) |
nameless129 | 9:96b053c0865e | 323 | else if(c_TouchPanelAve <= TOUCHPANEL_AVERAGE_COUNT) |
nameless129 | 3:67e97c846cec | 324 | { |
nameless129 | 9:96b053c0865e | 325 | printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 9:96b053c0865e | 326 | aveXReadPos = aveXReadPos + XReadPos; |
nameless129 | 9:96b053c0865e | 327 | aveYReadPos = aveYReadPos + YReadPos; |
nameless129 | 9:96b053c0865e | 328 | c_TouchPanelAve++; |
nameless129 | 9:96b053c0865e | 329 | } |
nameless129 | 9:96b053c0865e | 330 | if(c_TouchPanelAve == TOUCHPANEL_AVERAGE_COUNT) |
nameless129 | 9:96b053c0865e | 331 | { |
nameless129 | 9:96b053c0865e | 332 | aveXReadPos = aveXReadPos/TOUCHPANEL_AVERAGE_COUNT; |
nameless129 | 9:96b053c0865e | 333 | aveYReadPos = aveYReadPos/TOUCHPANEL_AVERAGE_COUNT; |
nameless129 | 9:96b053c0865e | 334 | c_TouchPanelAve = (TOUCHPANEL_AVERAGE_COUNT+1); |
nameless129 | 9:96b053c0865e | 335 | printf("Xave:%d Yave:%d\r\n",aveXReadPos,aveYReadPos); |
nameless129 | 9:96b053c0865e | 336 | } |
nameless129 | 9:96b053c0865e | 337 | if(c_TouchPanelAve == (TOUCHPANEL_AVERAGE_COUNT+1) ) |
nameless129 | 9:96b053c0865e | 338 | { |
nameless129 | 9:96b053c0865e | 339 | switch( detectTouchBotton(aveXReadPos,aveYReadPos) ) |
nameless129 | 9:96b053c0865e | 340 | { |
nameless129 | 9:96b053c0865e | 341 | case TOUCHPANEL_BOTTON_TOUCH_PREV: |
nameless129 | 9:96b053c0865e | 342 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 343 | { |
nameless129 | 9:96b053c0865e | 344 | printf("prev touch\r\n"); |
nameless129 | 9:96b053c0865e | 345 | g_mp3Player_State = MP3_STATE_PREVREQ; |
nameless129 | 9:96b053c0865e | 346 | touchPanel_Touched = 1; |
nameless129 | 8:198b69e78c39 | 347 | } |
nameless129 | 9:96b053c0865e | 348 | break; |
nameless129 | 9:96b053c0865e | 349 | case TOUCHPANEL_BOTTON_TOUCH_PLAY: |
nameless129 | 9:96b053c0865e | 350 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 351 | { |
nameless129 | 9:96b053c0865e | 352 | printf("play touch\r\n"); |
nameless129 | 9:96b053c0865e | 353 | if( (g_mp3Player_State == MP3_STATE_STOPPING) ) |
nameless129 | 9:96b053c0865e | 354 | { |
nameless129 | 9:96b053c0865e | 355 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 9:96b053c0865e | 356 | printf("MP3_STATE_PLAYREQ\r\n"); |
nameless129 | 9:96b053c0865e | 357 | } |
nameless129 | 9:96b053c0865e | 358 | if( g_mp3Player_State == MP3_STATE_PLAYING ) |
nameless129 | 9:96b053c0865e | 359 | { |
nameless129 | 9:96b053c0865e | 360 | g_mp3Player_State = MP3_STATE_PAUSEREQ; |
nameless129 | 9:96b053c0865e | 361 | printf("MP3_STATE_PAUSEREQ\r\n"); |
nameless129 | 9:96b053c0865e | 362 | } |
nameless129 | 9:96b053c0865e | 363 | if( g_mp3Player_State == MP3_STATE_PAUSEING ) |
nameless129 | 9:96b053c0865e | 364 | { |
nameless129 | 9:96b053c0865e | 365 | g_mp3Player_State = MP3_STATE_RESUMEREQ; |
nameless129 | 9:96b053c0865e | 366 | printf("MP3_STATE_RESUMEREQ\r\n"); |
nameless129 | 9:96b053c0865e | 367 | } |
nameless129 | 9:96b053c0865e | 368 | |
nameless129 | 9:96b053c0865e | 369 | touchPanel_Touched = 1; |
nameless129 | 6:74271fce2368 | 370 | } |
nameless129 | 9:96b053c0865e | 371 | break; |
nameless129 | 9:96b053c0865e | 372 | case TOUCHPANEL_BOTTON_TOUCH_STOP: |
nameless129 | 9:96b053c0865e | 373 | if(touchPanel_Touched == 0) |
nameless129 | 9:96b053c0865e | 374 | { |
nameless129 | 9:96b053c0865e | 375 | printf("stop touch\r\n"); |
nameless129 | 9:96b053c0865e | 376 | if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) ) |
nameless129 | 9:96b053c0865e | 377 | { |
nameless129 | 9:96b053c0865e | 378 | g_mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 9:96b053c0865e | 379 | } |
nameless129 | 9:96b053c0865e | 380 | touchPanel_Touched = 1; |
nameless129 | 9:96b053c0865e | 381 | } |
nameless129 | 9:96b053c0865e | 382 | break; |
nameless129 | 9:96b053c0865e | 383 | case TOUCHPANEL_BOTTON_TOUCH_NEXT: |
nameless129 | 9:96b053c0865e | 384 | if(touchPanel_Touched == 0) |
nameless129 | 9:96b053c0865e | 385 | { |
nameless129 | 9:96b053c0865e | 386 | printf("next touch\r\n"); |
nameless129 | 9:96b053c0865e | 387 | g_mp3Player_State = MP3_STATE_NEXTREQ; |
nameless129 | 9:96b053c0865e | 388 | touchPanel_Touched = 1; |
nameless129 | 9:96b053c0865e | 389 | } |
nameless129 | 9:96b053c0865e | 390 | break; |
nameless129 | 9:96b053c0865e | 391 | case TOUCHPANEL_OTHER_TOUCH: |
nameless129 | 9:96b053c0865e | 392 | //printf("otherTouch\r\n"); |
nameless129 | 9:96b053c0865e | 393 | //printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 9:96b053c0865e | 394 | break; |
nameless129 | 9:96b053c0865e | 395 | case TOUCHPANEL_BOTTON_NOT_TOUCH: |
nameless129 | 9:96b053c0865e | 396 | //printf("notTouch\r\n"); |
nameless129 | 9:96b053c0865e | 397 | touchPanel_Touched = 0; |
nameless129 | 9:96b053c0865e | 398 | break; |
nameless129 | 9:96b053c0865e | 399 | default : |
nameless129 | 9:96b053c0865e | 400 | break; |
nameless129 | 9:96b053c0865e | 401 | } |
nameless129 | 3:67e97c846cec | 402 | } |
nameless129 | 3:67e97c846cec | 403 | } |
nameless129 | 5:a493361aead2 | 404 | |
nameless129 | 3:67e97c846cec | 405 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 406 | /* MP3 Player Control Section */ |
nameless129 | 3:67e97c846cec | 407 | ////////////////////////////////////////////////////////////// |
nameless129 | 9:96b053c0865e | 408 | switch(g_mp3Player_State) |
nameless129 | 3:67e97c846cec | 409 | { |
nameless129 | 9:96b053c0865e | 410 | case MP3_STATE_PLAYREQ: |
nameless129 | 4:28900cff8f48 | 411 | { |
nameless129 | 9:96b053c0865e | 412 | printf("FileOpen:%s\r\n",mp3PlayingFileName); |
nameless129 | 9:96b053c0865e | 413 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 9:96b053c0865e | 414 | SDFileOpenFailCnt = 0; |
nameless129 | 9:96b053c0865e | 415 | while(!fp) |
nameless129 | 4:28900cff8f48 | 416 | { |
nameless129 | 9:96b053c0865e | 417 | SDFileOpenFailCnt+=1; |
nameless129 | 9:96b053c0865e | 418 | if(SDFileOpenFailCnt >= 3) |
nameless129 | 9:96b053c0865e | 419 | { |
nameless129 | 9:96b053c0865e | 420 | printf("Fail SD init\r\n"); |
nameless129 | 9:96b053c0865e | 421 | printf("System Stop.\r\n"); |
nameless129 | 9:96b053c0865e | 422 | NVIC_SystemReset(); |
nameless129 | 9:96b053c0865e | 423 | } |
nameless129 | 9:96b053c0865e | 424 | printf("Fail file open n=%d\r\n",SDFileOpenFailCnt); |
nameless129 | 9:96b053c0865e | 425 | sd.disk_initialize(); |
nameless129 | 9:96b053c0865e | 426 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 7:fc65d965a569 | 427 | wait(1); |
nameless129 | 4:28900cff8f48 | 428 | } |
nameless129 | 9:96b053c0865e | 429 | |
nameless129 | 9:96b053c0865e | 430 | //Get file size |
nameless129 | 9:96b053c0865e | 431 | fseek( fp, 0, SEEK_END ); |
nameless129 | 9:96b053c0865e | 432 | mp3_fileSize = ftell( fp ); |
nameless129 | 9:96b053c0865e | 433 | printf("FileOpen. size=%dbit\r\n",mp3_fileSize); |
nameless129 | 9:96b053c0865e | 434 | |
nameless129 | 9:96b053c0865e | 435 | //move file pointer to top. |
nameless129 | 9:96b053c0865e | 436 | rewind(fp); |
nameless129 | 9:96b053c0865e | 437 | clearerr(fp); |
nameless129 | 9:96b053c0865e | 438 | mp3_totalSizeSent = 0; |
nameless129 | 9:96b053c0865e | 439 | lcd.Print("Playing ",15,145); |
nameless129 | 9:96b053c0865e | 440 | |
nameless129 | 9:96b053c0865e | 441 | lcd.DrawRect(135,155,310,165,COLOR_WHITE); |
nameless129 | 9:96b053c0865e | 442 | lcd.FillRect(136,156,309,164,COLOR_BLUE); |
nameless129 | 9:96b053c0865e | 443 | dot1_FileSize = mp3_fileSize/175; |
nameless129 | 9:96b053c0865e | 444 | |
nameless129 | 9:96b053c0865e | 445 | g_mp3Player_State = MP3_STATE_PLAYING; |
nameless129 | 9:96b053c0865e | 446 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_pause, 1 ); |
nameless129 | 9:96b053c0865e | 447 | |
nameless129 | 9:96b053c0865e | 448 | totalPlay++; |
nameless129 | 9:96b053c0865e | 449 | printf("PlayCount=%d\r\n",totalPlay); |
nameless129 | 9:96b053c0865e | 450 | break; |
nameless129 | 9:96b053c0865e | 451 | } |
nameless129 | 9:96b053c0865e | 452 | case MP3_STATE_PLAYING: |
nameless129 | 5:a493361aead2 | 453 | { |
nameless129 | 9:96b053c0865e | 454 | if(mp3_totalSizeSent>=mp3_fileSize) //play song end |
nameless129 | 9:96b053c0865e | 455 | { |
nameless129 | 9:96b053c0865e | 456 | f_mp3Playwe_Playing = 1; |
nameless129 | 9:96b053c0865e | 457 | g_mp3Player_State = MP3_STATE_NEXTREQ; //next song |
nameless129 | 9:96b053c0865e | 458 | } |
nameless129 | 9:96b053c0865e | 459 | else //transmit from SDCard to VS1033 |
nameless129 | 9:96b053c0865e | 460 | { |
nameless129 | 9:96b053c0865e | 461 | if( mp3.checkDREQ() == 1 ) |
nameless129 | 9:96b053c0865e | 462 | { |
nameless129 | 9:96b053c0865e | 463 | mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); |
nameless129 | 9:96b053c0865e | 464 | mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); |
nameless129 | 9:96b053c0865e | 465 | dot_XPos = mp3_totalSizeSent / dot1_FileSize; |
nameless129 | 9:96b053c0865e | 466 | if(old_dot_XPos != dot_XPos) |
nameless129 | 9:96b053c0865e | 467 | { |
nameless129 | 9:96b053c0865e | 468 | lcd.DrawLine(135+dot_XPos, 156, 135+dot_XPos, 164); //x1:135 y1:155 x2:310 y3:165 |
nameless129 | 9:96b053c0865e | 469 | } |
nameless129 | 9:96b053c0865e | 470 | old_dot_XPos = dot_XPos; |
nameless129 | 9:96b053c0865e | 471 | //printf("SendedSize:%d LinePos:%d\r\n",mp3_totalSizeSent,dot_XPos); |
nameless129 | 9:96b053c0865e | 472 | //printf(" HDAT0:0x%x HDAT1:0x%x\r\n",mp3.readReg(mp3.SCI_HDAT0),mp3.readReg(mp3.SCI_HDAT1)); |
nameless129 | 9:96b053c0865e | 473 | } |
nameless129 | 9:96b053c0865e | 474 | f_mp3Playwe_Playing = 1; |
nameless129 | 9:96b053c0865e | 475 | } |
nameless129 | 9:96b053c0865e | 476 | break; |
nameless129 | 5:a493361aead2 | 477 | } |
nameless129 | 9:96b053c0865e | 478 | case MP3_STATE_PAUSEREQ: |
nameless129 | 5:a493361aead2 | 479 | { |
nameless129 | 9:96b053c0865e | 480 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 9:96b053c0865e | 481 | g_mp3Player_State = MP3_STATE_PAUSEING; |
nameless129 | 9:96b053c0865e | 482 | break; |
nameless129 | 5:a493361aead2 | 483 | } |
nameless129 | 9:96b053c0865e | 484 | case MP3_STATE_PAUSEING: |
nameless129 | 9:96b053c0865e | 485 | { |
nameless129 | 9:96b053c0865e | 486 | break; |
nameless129 | 9:96b053c0865e | 487 | } |
nameless129 | 9:96b053c0865e | 488 | case MP3_STATE_RESUMEREQ: |
nameless129 | 5:a493361aead2 | 489 | { |
nameless129 | 9:96b053c0865e | 490 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_pause, 1 ); |
nameless129 | 9:96b053c0865e | 491 | g_mp3Player_State = MP3_STATE_PLAYING; |
nameless129 | 9:96b053c0865e | 492 | break; |
nameless129 | 5:a493361aead2 | 493 | } |
nameless129 | 9:96b053c0865e | 494 | |
nameless129 | 9:96b053c0865e | 495 | case MP3_STATE_STOPREQ: |
nameless129 | 9:96b053c0865e | 496 | case MP3_STATE_REPLAY: |
nameless129 | 5:a493361aead2 | 497 | { |
nameless129 | 9:96b053c0865e | 498 | uint16_t returnCode=0; |
nameless129 | 9:96b053c0865e | 499 | uint16_t stopFailCnt = 0; |
nameless129 | 9:96b053c0865e | 500 | uint16_t readHDAT0,readHDAT1; |
nameless129 | 9:96b053c0865e | 501 | |
nameless129 | 9:96b053c0865e | 502 | lcd.Print("STOP ",15,145); |
nameless129 | 9:96b053c0865e | 503 | lcd.DrawRect(135,155,310,165,COLOR_WHITE); |
nameless129 | 9:96b053c0865e | 504 | lcd.FillRect(136,156,309,164,COLOR_BLUE); |
nameless129 | 9:96b053c0865e | 505 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 9:96b053c0865e | 506 | |
nameless129 | 9:96b053c0865e | 507 | do |
nameless129 | 9:96b053c0865e | 508 | { |
nameless129 | 9:96b053c0865e | 509 | returnCode = mp3.stop(); |
nameless129 | 9:96b053c0865e | 510 | readHDAT0 = mp3.readReg(mp3.SCI_HDAT0); |
nameless129 | 9:96b053c0865e | 511 | readHDAT1 = mp3.readReg(mp3.SCI_HDAT1); |
nameless129 | 9:96b053c0865e | 512 | returnCode = readHDAT0||readHDAT1; |
nameless129 | 9:96b053c0865e | 513 | |
nameless129 | 9:96b053c0865e | 514 | printf("STOP\r\nSTOP CODE:%d\r\n",returnCode); |
nameless129 | 9:96b053c0865e | 515 | printf(" HDAT0:0x%x HDAT1:0x%x\r\n",readHDAT0,readHDAT1); |
nameless129 | 9:96b053c0865e | 516 | |
nameless129 | 9:96b053c0865e | 517 | if(returnCode != 0 ) |
nameless129 | 9:96b053c0865e | 518 | { |
nameless129 | 9:96b053c0865e | 519 | stopFailCnt++; |
nameless129 | 9:96b053c0865e | 520 | } |
nameless129 | 9:96b053c0865e | 521 | if(stopFailCnt >= 20) |
nameless129 | 9:96b053c0865e | 522 | { |
nameless129 | 9:96b053c0865e | 523 | printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n"); |
nameless129 | 9:96b053c0865e | 524 | mp3.hardwareReset(); |
nameless129 | 9:96b053c0865e | 525 | mp3.sci_init(); |
nameless129 | 9:96b053c0865e | 526 | mp3.sdi_init(); |
nameless129 | 9:96b053c0865e | 527 | wait(1); |
nameless129 | 9:96b053c0865e | 528 | stopFailCnt = 0; |
nameless129 | 9:96b053c0865e | 529 | returnCode = 0; |
nameless129 | 9:96b053c0865e | 530 | } |
nameless129 | 9:96b053c0865e | 531 | }while(returnCode != 0); |
nameless129 | 9:96b053c0865e | 532 | |
nameless129 | 9:96b053c0865e | 533 | fclose(fp); |
nameless129 | 9:96b053c0865e | 534 | fp = NULL; |
nameless129 | 9:96b053c0865e | 535 | f_mp3Playwe_Playing = 0; |
nameless129 | 9:96b053c0865e | 536 | |
nameless129 | 9:96b053c0865e | 537 | if(g_mp3Player_State == MP3_STATE_STOPREQ) |
nameless129 | 9:96b053c0865e | 538 | { |
nameless129 | 9:96b053c0865e | 539 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 9:96b053c0865e | 540 | } |
nameless129 | 9:96b053c0865e | 541 | if(g_mp3Player_State == MP3_STATE_REPLAY) |
nameless129 | 9:96b053c0865e | 542 | { |
nameless129 | 9:96b053c0865e | 543 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 9:96b053c0865e | 544 | } |
nameless129 | 9:96b053c0865e | 545 | break; |
nameless129 | 5:a493361aead2 | 546 | } |
nameless129 | 9:96b053c0865e | 547 | case MP3_STATE_STOPPING: |
nameless129 | 8:198b69e78c39 | 548 | { |
nameless129 | 9:96b053c0865e | 549 | f_mp3Playwe_Playing = 0; |
nameless129 | 9:96b053c0865e | 550 | break; |
nameless129 | 8:198b69e78c39 | 551 | } |
nameless129 | 9:96b053c0865e | 552 | case MP3_STATE_NEXTREQ: |
nameless129 | 6:74271fce2368 | 553 | { |
nameless129 | 9:96b053c0865e | 554 | if( mp3PlayingFileNo >= (SDFileList_cnt -1) ) |
nameless129 | 8:198b69e78c39 | 555 | { |
nameless129 | 9:96b053c0865e | 556 | mp3PlayingFileNo = 0; |
nameless129 | 8:198b69e78c39 | 557 | } |
nameless129 | 8:198b69e78c39 | 558 | else |
nameless129 | 8:198b69e78c39 | 559 | { |
nameless129 | 9:96b053c0865e | 560 | mp3PlayingFileNo+=1; |
nameless129 | 8:198b69e78c39 | 561 | } |
nameless129 | 9:96b053c0865e | 562 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 9:96b053c0865e | 563 | break; |
nameless129 | 6:74271fce2368 | 564 | } |
nameless129 | 9:96b053c0865e | 565 | case MP3_STATE_PREVREQ: |
nameless129 | 8:198b69e78c39 | 566 | { |
nameless129 | 9:96b053c0865e | 567 | if( mp3PlayingFileNo <= 0 ) |
nameless129 | 8:198b69e78c39 | 568 | { |
nameless129 | 9:96b053c0865e | 569 | mp3PlayingFileNo = (SDFileList_cnt - 1); |
nameless129 | 8:198b69e78c39 | 570 | } |
nameless129 | 9:96b053c0865e | 571 | else |
nameless129 | 9:96b053c0865e | 572 | { |
nameless129 | 9:96b053c0865e | 573 | mp3PlayingFileNo-=1; |
nameless129 | 9:96b053c0865e | 574 | } |
nameless129 | 9:96b053c0865e | 575 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 9:96b053c0865e | 576 | break; |
nameless129 | 8:198b69e78c39 | 577 | } |
nameless129 | 9:96b053c0865e | 578 | |
nameless129 | 9:96b053c0865e | 579 | case MP3_STATE_FILECHANGE: |
nameless129 | 8:198b69e78c39 | 580 | { |
nameless129 | 9:96b053c0865e | 581 | printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]); |
nameless129 | 9:96b053c0865e | 582 | |
nameless129 | 9:96b053c0865e | 583 | lcd_FileViewPage = mp3PlayingFileNo/5; |
nameless129 | 9:96b053c0865e | 584 | if(old_lcd_FileViewPage != lcd_FileViewPage) |
nameless129 | 9:96b053c0865e | 585 | { |
nameless129 | 9:96b053c0865e | 586 | lcd.FillRect(0,0,320,140,COLOR_BLUE); |
nameless129 | 9:96b053c0865e | 587 | } |
nameless129 | 9:96b053c0865e | 588 | old_lcd_FileViewPage = lcd_FileViewPage; |
nameless129 | 9:96b053c0865e | 589 | |
nameless129 | 9:96b053c0865e | 590 | if(SDFileList_cnt >= 5) |
nameless129 | 9:96b053c0865e | 591 | { |
nameless129 | 9:96b053c0865e | 592 | if( (SDFileList_cnt-(5*lcd_FileViewPage)) >= 5 ) |
nameless129 | 9:96b053c0865e | 593 | { |
nameless129 | 9:96b053c0865e | 594 | lcd_FileViewListEnd = (5*lcd_FileViewPage+5); |
nameless129 | 9:96b053c0865e | 595 | |
nameless129 | 9:96b053c0865e | 596 | } |
nameless129 | 9:96b053c0865e | 597 | else |
nameless129 | 9:96b053c0865e | 598 | { |
nameless129 | 9:96b053c0865e | 599 | lcd_FileViewListEnd = (5*lcd_FileViewPage+ ((SDFileList_cnt-(5*lcd_FileViewPage))%5) ); |
nameless129 | 9:96b053c0865e | 600 | } |
nameless129 | 9:96b053c0865e | 601 | printf("FilePage:%d max:%d\r\n",lcd_FileViewPage, lcd_FileViewListEnd); |
nameless129 | 9:96b053c0865e | 602 | |
nameless129 | 9:96b053c0865e | 603 | for(i=(5*lcd_FileViewPage); i<lcd_FileViewListEnd; i++) |
nameless129 | 9:96b053c0865e | 604 | { |
nameless129 | 9:96b053c0865e | 605 | sprintf(str,"%d:%s",i,SDFileList_short[i]); |
nameless129 | 9:96b053c0865e | 606 | lcd.Print( str, LEFT, (i%5)*28 ); // align text to center horizontally and use starndard colors |
nameless129 | 9:96b053c0865e | 607 | } |
nameless129 | 9:96b053c0865e | 608 | } |
nameless129 | 9:96b053c0865e | 609 | else |
nameless129 | 9:96b053c0865e | 610 | { |
nameless129 | 9:96b053c0865e | 611 | for(i=0;i<SDFileList_cnt;i++) |
nameless129 | 9:96b053c0865e | 612 | { |
nameless129 | 9:96b053c0865e | 613 | sprintf(str,"%d:%s",i,SDFileList_short[i]); |
nameless129 | 9:96b053c0865e | 614 | lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors |
nameless129 | 9:96b053c0865e | 615 | } |
nameless129 | 9:96b053c0865e | 616 | } |
nameless129 | 9:96b053c0865e | 617 | |
nameless129 | 9:96b053c0865e | 618 | sprintf(str,"%d:%s",mp3PlayingFileNo,SDFileList_short[mp3PlayingFileNo]); |
nameless129 | 9:96b053c0865e | 619 | lcd.Print( str, LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors |
nameless129 | 9:96b053c0865e | 620 | if(mp3PlayingFileNo >= 10) |
nameless129 | 9:96b053c0865e | 621 | { |
nameless129 | 9:96b053c0865e | 622 | lcd.Print( "**", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0); // align text to center horizontally and use starndard colors |
nameless129 | 9:96b053c0865e | 623 | } |
nameless129 | 9:96b053c0865e | 624 | else |
nameless129 | 9:96b053c0865e | 625 | { |
nameless129 | 9:96b053c0865e | 626 | lcd.Print( "*", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors |
nameless129 | 9:96b053c0865e | 627 | } |
nameless129 | 9:96b053c0865e | 628 | |
nameless129 | 9:96b053c0865e | 629 | sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); |
nameless129 | 9:96b053c0865e | 630 | if(f_mp3Playwe_Playing == 1) |
nameless129 | 9:96b053c0865e | 631 | { |
nameless129 | 9:96b053c0865e | 632 | g_mp3Player_State = MP3_STATE_REPLAY; |
nameless129 | 9:96b053c0865e | 633 | } |
nameless129 | 9:96b053c0865e | 634 | else |
nameless129 | 9:96b053c0865e | 635 | { |
nameless129 | 9:96b053c0865e | 636 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 9:96b053c0865e | 637 | } |
nameless129 | 9:96b053c0865e | 638 | break; |
nameless129 | 8:198b69e78c39 | 639 | } |
nameless129 | 9:96b053c0865e | 640 | default: |
nameless129 | 5:a493361aead2 | 641 | { |
nameless129 | 9:96b053c0865e | 642 | break; |
nameless129 | 5:a493361aead2 | 643 | } |
nameless129 | 5:a493361aead2 | 644 | } |
nameless129 | 2:0090839c8276 | 645 | } |
nameless129 | 0:5f0e931ae677 | 646 | } |