mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-03 04:50:37 +08:00

* Update WebSocket library * Update SSDP library * Update TFT_eSPI library * Update EspLuaEngine library * Update SDFat library * Change to pioarduino * Make ESP3DMessageFIFO and ESP3DMessage more thread safe * Fix sanity checks for BT * Add some C6 support * Refactor ethernet code * Split Ethernet Sta / WiFi sta ESP Commands and settings * Simplify wait and wdtFeed code * Set C3 with 4MB by default in platformio.ini * Apply Disable brown out only on ESP32 to avoid crash e.g:ESP32S3 * Add missing entries in platformio.ini
111 lines
2.7 KiB
C++
111 lines
2.7 KiB
C++
/*
|
|
* Print size, modify date/time, and name for all files in root.
|
|
*/
|
|
#include "SdFat.h"
|
|
|
|
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
|
|
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
|
|
#define SD_FAT_TYPE 3
|
|
/*
|
|
Change the value of SD_CS_PIN if you are using SPI and
|
|
your hardware does not use the default value, SS.
|
|
Common values are:
|
|
Arduino Ethernet shield: pin 4
|
|
Sparkfun SD shield: pin 8
|
|
Adafruit SD shields and modules: pin 10
|
|
*/
|
|
|
|
// SDCARD_SS_PIN is defined for the built-in SD on some boards.
|
|
#ifndef SDCARD_SS_PIN
|
|
const uint8_t SD_CS_PIN = 4;
|
|
#else // SDCARD_SS_PIN
|
|
// Assume built-in SD is used.
|
|
const uint8_t SD_CS_PIN = 4;
|
|
#endif // SDCARD_SS_PIN
|
|
|
|
// Try max SPI clock for an SD. Reduce SPI_CLOCK if errors occur.
|
|
#define SPI_CLOCK SD_SCK_MHZ(30)
|
|
|
|
// Try to select the best SD card configuration.
|
|
#if HAS_SDIO_CLASS
|
|
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
|
#elif ENABLE_DEDICATED_SPI
|
|
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
|
#else // HAS_SDIO_CLASS
|
|
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
|
#endif // HAS_SDIO_CLASS
|
|
|
|
#if SD_FAT_TYPE == 0
|
|
SdFat sd;
|
|
File dir;
|
|
File file;
|
|
#elif SD_FAT_TYPE == 1
|
|
SdFat32 sd;
|
|
File32 dir;
|
|
File32 file;
|
|
#elif SD_FAT_TYPE == 2
|
|
SdExFat sd;
|
|
ExFile dir;
|
|
ExFile file;
|
|
#elif SD_FAT_TYPE == 3
|
|
SdFs sd;
|
|
FsFile dir;
|
|
FsFile file;
|
|
#else // SD_FAT_TYPE
|
|
#error invalid SD_FAT_TYPE
|
|
#endif // SD_FAT_TYPE
|
|
//------------------------------------------------------------------------------
|
|
// Store error strings in flash to save RAM.
|
|
#define error(s) sd.errorHalt(&Serial, F(s))
|
|
//------------------------------------------------------------------------------
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
|
|
// Wait for USB Serial
|
|
while (!Serial) {
|
|
yield();
|
|
}
|
|
|
|
Serial.println("Type any character to start");
|
|
while (!Serial.available()) {
|
|
yield();
|
|
}
|
|
|
|
// Initialize the SD.
|
|
if (!sd.begin(SD_CONFIG)) {
|
|
sd.initErrorHalt(&Serial);
|
|
}
|
|
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
void loop() {
|
|
// Open root directory
|
|
if (!dir.open("/")) {
|
|
error("dir.open failed");
|
|
}
|
|
// Open next file in root.
|
|
// Warning, openNext starts at the current position of dir so a
|
|
// rewind may be necessary in your application.
|
|
while (file.openNext(&dir, O_RDONLY)) {
|
|
file.printFileSize(&Serial);
|
|
Serial.write(' ');
|
|
file.printModifyDateTime(&Serial);
|
|
Serial.write(' ');
|
|
file.printName(&Serial);
|
|
if (file.isDir()) {
|
|
// Indicate a directory.
|
|
Serial.write('/');
|
|
}
|
|
Serial.println();
|
|
file.close();
|
|
}
|
|
if (dir.getError()) {
|
|
Serial.println("openNext failed");
|
|
} else {
|
|
Serial.println("Done!");
|
|
}
|
|
dir.close();
|
|
delay(2000);
|
|
|
|
}
|