123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #include <SPI.h>
- #include "SdFat.h"
- #include "sdios.h"
- SdFat sd;
- SdFile file;
- const uint8_t chipSelect = SS;
- ArduinoOutStream cout(Serial);
- #define error(s) sd.errorHalt(F(s))
- uint16_t year = 2014;
- uint8_t month = 10;
- uint8_t day = 1;
- uint8_t hour = 20;
- uint8_t minute = 30;
- uint8_t second = 40;
- void dateTime(uint16_t* date, uint16_t* time) {
-
-
-
- *date = FAT_DATE(year, month, day);
-
- *time = FAT_TIME(hour, minute, second);
- }
- void printTimestamps(SdFile& f) {
- cout << F("Creation: ");
- f.printCreateDateTime(&Serial);
- cout << endl << F("Modify: ");
- f.printModifyDateTime(&Serial);
- cout << endl << F("Access: ");
- f.printAccessDateTime(&Serial);
- cout << endl;
- }
- void setup(void) {
- Serial.begin(9600);
-
- while (!Serial) {
- SysCall::yield();
- }
- cout << F("Type any character to start\n");
- while (!Serial.available()) {
- SysCall::yield();
- }
-
-
- if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
- sd.initErrorHalt();
- }
-
- sd.remove("callback.txt");
- sd.remove("default.txt");
- sd.remove("stamp.txt");
-
- if (!file.open("default.txt", O_WRONLY | O_CREAT)) {
- error("open default.txt failed");
- }
- cout << F("\nOpen with default times\n");
- printTimestamps(file);
-
- file.close();
-
-
- SdFile::dateTimeCallback(dateTime);
-
- if (!file.open("callback.txt", O_WRONLY | O_CREAT)) {
- error("open callback.txt failed");
- }
- cout << ("\nOpen with callback times\n");
- printTimestamps(file);
-
- day += 1;
-
- second += 2;
-
- file.write('t');
-
- file.sync();
- cout << F("\nTimes after write\n");
- printTimestamps(file);
-
- file.close();
-
- SdFile::dateTimeCallbackCancel();
-
- if (!file.open("stamp.txt", O_WRONLY | O_CREAT)) {
- error("open stamp.txt failed");
- }
-
- if (!file.timestamp(T_CREATE, 2014, 11, 10, 1, 2, 3)) {
- error("set create time failed");
- }
-
- if (!file.timestamp(T_WRITE, 2014, 11, 11, 4, 5, 6)) {
- error("set write time failed");
- }
-
- if (!file.timestamp(T_ACCESS, 2014, 11, 12, 7, 8, 9)) {
- error("set access time failed");
- }
- cout << F("\nTimes after timestamp() calls\n");
- printTimestamps(file);
- file.close();
- cout << F("\nDone\n");
- }
- void loop() {}
|