Updated the SD card library by including the new changes from the esp8266 arduino framework
This commit is contained in:
parent
c2e9324d95
commit
9e3676a1bb
@ -28,14 +28,14 @@ File root;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications and wait for port to open:
|
// Open serial communications and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
while (!Serial) {
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
; // wait for serial port to connect. Needed for Leonardo only
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
if (!SD.begin(4)) {
|
if (!SD.begin(SS)) {
|
||||||
Serial.println("initialization failed!");
|
Serial.println("initialization failed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -70,11 +70,13 @@ void printDirectory(File dir, int numTabs) {
|
|||||||
} else {
|
} else {
|
||||||
// files have sizes, directories do not
|
// files have sizes, directories do not
|
||||||
Serial.print("\t\t");
|
Serial.print("\t\t");
|
||||||
Serial.println(entry.size(), DEC);
|
Serial.print(entry.size(), DEC);
|
||||||
|
Serial.print("\t\t");
|
||||||
|
time_t ft = entry.getLastWrite();
|
||||||
|
struct tm *tm = localtime(&ft);
|
||||||
|
// US format. Feel free to convert to your own locale...
|
||||||
|
Serial.printf("%02d-%02d-%02d %02d:%02d:%02d\n", tm->tm_mon + 1, tm->tm_mday, tm->tm_year % 100, tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
}
|
}
|
||||||
entry.close();
|
entry.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,10 +21,12 @@ open KEYWORD2
|
|||||||
close KEYWORD2
|
close KEYWORD2
|
||||||
seek KEYWORD2
|
seek KEYWORD2
|
||||||
position KEYWORD2
|
position KEYWORD2
|
||||||
size KEYWORD2
|
size KEYWORD2
|
||||||
|
rename KEYWORD2
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
#######################################
|
#######################################
|
||||||
FILE_READ LITERAL1
|
FILE_READ LITERAL1
|
||||||
FILE_WRITE LITERAL1
|
FILE_WRITE LITERAL1
|
||||||
|
FILE_READWRITE LITERAL1
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
|
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
|
||||||
SDClass SD;
|
SDClass SD;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void (*__SD__userDateTimeCB)(uint16_t*, uint16_t*) = nullptr;
|
||||||
|
@ -49,10 +49,18 @@ public:
|
|||||||
return SDFS.open(filename, getMode(mode));
|
return SDFS.open(filename, getMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File open(const char *filename, const char *mode) {
|
||||||
|
return SDFS.open(filename, mode);
|
||||||
|
}
|
||||||
|
|
||||||
File open(const String &filename, uint8_t mode = FILE_READ) {
|
File open(const String &filename, uint8_t mode = FILE_READ) {
|
||||||
return open(filename.c_str(), mode);
|
return open(filename.c_str(), mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File open(const String &filename, const char *mode) {
|
||||||
|
return open(filename.c_str(), mode);
|
||||||
|
}
|
||||||
|
|
||||||
boolean exists(const char *filepath) {
|
boolean exists(const char *filepath) {
|
||||||
return (boolean)SDFS.exists(filepath);
|
return (boolean)SDFS.exists(filepath);
|
||||||
}
|
}
|
||||||
@ -135,6 +143,17 @@ public:
|
|||||||
return ((uint64_t)clusterSize() * (uint64_t)totalClusters());
|
return ((uint64_t)clusterSize() * (uint64_t)totalClusters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTimeCallback(time_t (*cb)(void)) {
|
||||||
|
SDFS.setTimeCallback(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper to allow obsolete datetimecallback use, silently convert to time_t in wrappertimecb
|
||||||
|
void dateTimeCallback(void (*cb)(uint16_t*, uint16_t*)) {
|
||||||
|
extern void (*__SD__userDateTimeCB)(uint16_t*, uint16_t*);
|
||||||
|
__SD__userDateTimeCB = cb;
|
||||||
|
SDFS.setTimeCallback(wrapperTimeCB);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *getMode(uint8_t mode) {
|
const char *getMode(uint8_t mode) {
|
||||||
bool read = (mode & sdfat::O_READ) ? true : false;
|
bool read = (mode & sdfat::O_READ) ? true : false;
|
||||||
@ -148,8 +167,46 @@ private:
|
|||||||
else { return "r"; }
|
else { return "r"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static time_t wrapperTimeCB(void) {
|
||||||
|
extern void (*__SD__userDateTimeCB)(uint16_t*, uint16_t*);
|
||||||
|
if (__SD__userDateTimeCB) {
|
||||||
|
uint16_t d, t;
|
||||||
|
__SD__userDateTimeCB(&d, &t);
|
||||||
|
return sdfs::SDFSImpl::FatToTimeT(d, t);
|
||||||
|
}
|
||||||
|
return time(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Expose FatStructs.h helpers for MSDOS date/time for use with dateTimeCallback
|
||||||
|
static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) {
|
||||||
|
return (year - 1980) << 9 | month << 5 | day;
|
||||||
|
}
|
||||||
|
static inline uint16_t FAT_YEAR(uint16_t fatDate) {
|
||||||
|
return 1980 + (fatDate >> 9);
|
||||||
|
}
|
||||||
|
static inline uint8_t FAT_MONTH(uint16_t fatDate) {
|
||||||
|
return (fatDate >> 5) & 0XF;
|
||||||
|
}
|
||||||
|
static inline uint8_t FAT_DAY(uint16_t fatDate) {
|
||||||
|
return fatDate & 0X1F;
|
||||||
|
}
|
||||||
|
static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
|
||||||
|
return hour << 11 | minute << 5 | second >> 1;
|
||||||
|
}
|
||||||
|
static inline uint8_t FAT_HOUR(uint16_t fatTime) {
|
||||||
|
return fatTime >> 11;
|
||||||
|
}
|
||||||
|
static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
|
||||||
|
return (fatTime >> 5) & 0X3F;
|
||||||
|
}
|
||||||
|
static inline uint8_t FAT_SECOND(uint16_t fatTime) {
|
||||||
|
return 2*(fatTime & 0X1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
|
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SD)
|
||||||
extern SDClass SD;
|
extern SDClass SD;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user