void SDcard::writefile(uint64_t timestamp_sd, int eeprom){ myfile = SD.open("data.txt", FILE_WRITE); if (myfile) { myfile.print("G|"); uint64_t xx = timestamp_sd/1000000000ULL; if (xx >0) myfile.print((long)xx); myfile.print((long)(timestamp_sd-xx*1000000000)); myfile.print("|"); myfile.print(eeprom); myfile.print("|"); for(int i = 0; i<3;i++){ // nombre de capteurs = 3 String data = this->mem->getNext(); myfile.print(data); if (i!=2) myfile.print("|"); } myfile.write('\n'); //myfile.print("|H,"); //myfile.println(value); myfile.close(); } else { Serial.println("error opening data.txt"); } }
// Get the full path/filename of the GIF file with specified index void getGIFFilenameByIndex(const char *directoryName, int index, char *pnBuffer) { char fname[30]; // Make sure index is in range if ((index < 0) || (index >= numberOfFiles)) return; File directory = sd.open(directoryName); if (!directory) return; File file = directory.openNextFile(); while (file && (index >= 0)) { file.getName(fname, sizeof(fname)); if (isAnimationFile(fname)) { index--; // Copy the directory name into the pathname buffer strcpy(pnBuffer, directoryName); // Append the filename to the pathname strcat(pnBuffer, fname); } file.close(); file = directory.openNextFile(); } file.close(); directory.close(); }
// Enumerate and possibly display the animated GIF filenames in GIFS directory int enumerateGIFFiles(const char *directoryName, boolean displayFilenames) { char fname[30]; numberOfFiles = 0; File directory = sd.open(directoryName); if (!directory) { return -1; } File file = directory.openNextFile(); while (file) { file.getName(fname, sizeof(fname)); Serial.println(fname); if (isAnimationFile(fname)) { numberOfFiles++; if (displayFilenames) { Serial.println(fname); } } file.close(); file = directory.openNextFile(); } file.close(); directory.close(); return numberOfFiles; }
/** * Function starts the SD card service and makes sure that the appropriate directory * structure exists, then creates the file to use for logging data. Data will be logged * to a file called fileNamePrefix_0.csv or fileNamePrefix_0.bin (number will be incremented * for each new log file) * * @param chipSelectPin Arduino pin SD card reader CS pin is attached to * @param fileNamePrefix string to prefix at beginning of data file * @param csvData boolean flag whether we are writing csv data or binary data (used for filename) * * @return true if successful, false if failed */ bool beginDataLog(int chipSelectPin, const char *fileNamePrefix, bool csvData) { bool ret; int i = 0; int max_len; char fileName[19]; char prefix[8]; char rootPath[] = "/data"; if (_output_buffer != NULL) { delete []_output_buffer; } OUTPUT_BUF_SIZE = 512; _output_buffer = vol.cacheAddress()->output_buf; if (freeMemory() < 400) { strcpy_P(_getOutBuf(), sd_card_error); Serial.print(_getOutBuf()); Serial.print(freeMemory()); Serial.println(", need 400)"); ret = false; } else { ret = sd.begin(chipSelectPin, SPI_FULL_SPEED); } //Filenames need to fit the 8.3 filename convention, so truncate down the //given filename if it is too long. memcpy(prefix, fileNamePrefix, 7); prefix[7] = '\0'; if (ret) { if (!sd.exists(rootPath)) ret = sd.mkdir(rootPath); if (ret) { while (true) { if (i < 10) { max_len = 7; } else if (i < 100) { max_len = 6; } else if (i < 1000) { max_len = 5; } else { break; } prefix[max_len - 1] = '\0'; sprintf(fileName, "%s/%s%d.%s", rootPath, prefix, i, csvData ? "csv" : "bin"); if (!sd.exists(fileName)) { file = sd.open(fileName, FILE_WRITE); break; } i++; } } } return file.isOpen(); }
void TicketflySDBeacon::writeToSD (String writeThisString, String fileName, SdFat& SD) { File myFile; const char* conversion = fileName.c_str(); Serial.println (conversion); myFile = SD.open(conversion); if (myFile) { myFile.println(writeThisString); myFile.close(); } else { Serial.println(F("error opening example.txt")); } }
void SDcard::readfile(){ // re-open the file for reading: myfile = SD.open("data.txt"); if (myfile) { // read from the file until there's nothing else in it: while (myfile.available()) { Serial.write(myfile.read()); } // close the file: myfile.close(); } else { Serial.println("error opening data.txt"); } }
void TicketflySDBeacon::simpleReadSD (String fileName, SdFat& SD){ File myFile; const char* conversion = fileName.c_str(); myFile = SD.open(conversion, FILE_READ); if (myFile) { while (myFile.available()) { Serial.write(myFile.read()); } myFile.close(); } else { Serial.print(F("Error opening ")); Serial.println (fileName); } }
bool TicketflySDBeacon::searchDatabaseForTicket(String TicketString, SdFat& SD){ File myFile; const char* TicketNo = TicketString.c_str(); myFile = SD.open("example.txt"); if (myFile) { char buf[16]; myFile.read(buf, 16); if (strncmp(buf, TicketNo, 14) == 0) { Serial.println(F("Match!")); return true; } else { Serial.println (F("No Match")); return false; } myFile.close(); } else { Serial.println(F("error opening file")); } }
void TicketflySDBeacon::fileRemove (String fileName, SdFat& SD) { File myFile; const char* conversion = fileName.c_str(); myFile = SD.open(conversion); SD.remove(conversion); }