1 2 |
//EX. SD2SPIFFS("/mp3/bgm001.mp3", "/bgm001.mp3"); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
//======================================================================== //FILE TRANSFER //======================================================================== const int BUFFER_SIZE = 512; bool SD2SPIFFS(const char *filename_S, const char *filename_D) { bool rs = true; //SD_FILE_OPEN_CHECK File SD_FILE = SD.open(filename_S, FILE_READ ); if (!SD_FILE || SD_FILE.isDirectory()) { return false; } //SPIFFS_FILE_Find_out_what_already_exists if (SPIFFS.exists(filename_D)) { SD_FILE.close(); return false; } // M5.Lcd.print("SD2SPIFFS FILE:"); M5.Lcd.print(filename_S); //SIZE READ size_t F_SIZE_S = SD_FILE.size(); //SPIFFS SPACE CHECK 2019/3/31 Add if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < F_SIZE_S) { M5.Lcd.print("\nNO SPACE for SPIFFS!\n"); SD_FILE.close(); delay(200); return false; } //SPIFFS_FILE_OPEN File SPI_FILE = SPIFFS.open(filename_D, FILE_WRITE ); if (!SPI_FILE) { SD_FILE.close(); SPI_FILE.close(); return false; } // M5.Lcd.print("\nPLEASE WAIT..."); //FILE DATA COPY SD To SPIFFS uint8_t buf[BUFFER_SIZE]; size_t CT = 0, NCT = 0; while (1) { if (CT + BUFFER_SIZE >= F_SIZE_S) { if (SD_FILE.read(buf, F_SIZE_S - CT) == -1) { rs = false; break; } if (SPI_FILE.write(buf, F_SIZE_S - CT) == -1) { rs = false; break; } break; } CT += BUFFER_SIZE; if (SD_FILE.read(buf, BUFFER_SIZE) == -1) { rs = false; break; } if (SPI_FILE.write(buf, BUFFER_SIZE) == -1) { rs = false; break; } if (NCT % 50 == 0)M5.Lcd.print("@"); NCT++; delay(1); } M5.Lcd.print("\n"); //CLOSE SD_FILE.close(); SPI_FILE.close(); return rs; } |