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