Mil gracias Lucario448 pour tu pronta respuesta y por que me guiaste a una possible solucion. Ahora quite la creacion de la carpeta del loop y solo la hago cuando cuento los archivos.
Lucario448:
¿Por qué no simplemente reinicias ese contador cada vez que se ingrese a una carpeta nueva?
Ahora explico un poco mas:
Includes:
#define FILE_BASE_NAME "Log"
// Temporary log file. Will be deleted if a reset or power failure occurs.
#define TMP_FILE_NAME FILE_BASE_NAME "##.bin"
// Size of file base name.
const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
const uint8_t FILE_NAME_DIM = BASE_NAME_SIZE + 7;
char binName[FILE_NAME_DIM] = FILE_BASE_NAME "00.bin";
SdFat sd;
SdBaseFile binFile;
Loop:
void loop(void) {
boolean bintocsv = digitalRead(CONVERT_BUTTON);
debouncer_rec.update();
// Read any Serial data.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);
if ( debouncer_rec.rose())
logData();
delay(10);
sd.chdir("/"); // Root of SD card
}
Funcion LogData:
void logData() {
createBinFile();
recordBinFile();
renameBinFile();
}
CreateBinFile (no es tan importante para mi problema):
void createBinFile() {
// max number of blocks to erase per erase call
const uint32_t ERASE_SIZE = 262144L;
uint32_t bgnBlock, endBlock;
// Delete old tmp file.
if (sd.exists(TMP_FILE_NAME)) {
Serial.println(F("Deleting tmp file " TMP_FILE_NAME));
if (!sd.remove(TMP_FILE_NAME)) {
error("Can't remove tmp file");
}
}
// Create new file.
Serial.println(F("\nCreating new file"));
binFile.close();
if (!binFile.createContiguous(TMP_FILE_NAME, 512 * FILE_BLOCK_COUNT)) {
error("createContiguous failed");
}
// Get the address of the file on the SD.
if (!binFile.contiguousRange(&bgnBlock, &endBlock)) {
error("contiguousRange failed");
}
// Flash erase all data in the file.
Serial.println(F("Erasing all data"));
uint32_t bgnErase = bgnBlock;
uint32_t endErase;
while (bgnErase < endBlock) {
endErase = bgnErase + ERASE_SIZE;
if (endErase > endBlock) {
endErase = endBlock;
}
if (!sd.card()->erase(bgnErase, endErase)) {
error("erase failed");
}
bgnErase = endErase + 1;
}
}
RenameBinFile: (Aqui es donde estoy hacienda algo mal)
void renameBinFile()
{
timeRTC_t dateTime;
timeDateRTC(&dateTime);
char folderDate[12]; //Name for folder
sprintf(folderDate, "%u", dateTime.minute); //String of name with Date values
sd.chdir("/"); //Return to Root
if (!sd.exists(folderDate))
{
sd.mkdir(folderDate);
//binName = 0;
binName[BASE_NAME_SIZE + 1] = '0'; //Initialize name to X0
binName[BASE_NAME_SIZE] = '0'; //Initialize name to 00
}
else
sd.chdir(folderDate); //Se hace carpeta: folderDate nuevo root
while (sd.exists(binName))
{
if (binName[BASE_NAME_SIZE + 1] != '9') { //x9
binName[BASE_NAME_SIZE + 1]++; //incrementa el numero del archivo segundo digito
}
else
{
binName[BASE_NAME_SIZE + 1] = '0';
if (binName[BASE_NAME_SIZE] == '9') //9x
{
error("Can't create file name");
}
binName[BASE_NAME_SIZE]++; //incrementa el numero del archivo primer digito
}
}
if (!binFile.rename(sd.vwd(), binName)) {
error("Can't rename file");
}
Serial.print(F("File renamed: "));
Serial.println(binName);
Serial.print(F("File size: "));
Serial.print(binFile.fileSize() / 512);
Serial.println(F(" blocks"));
}
Ahora lo que obtengo es:
19/ <--- Nombre de la Carpeta (solo puse el minuto)
Log00.bin
Log01.bin
Log02.bin
Log03.bin
etc...
20/
Log01.bin
Log02.bin
Log03.bin
etc...
/ <--- En la carpeta principal
Log00.bin
Log01.bin
No entiendo porque cuando se crea una carpeta nueva se regresa a la raiz graba un archivo y luego entra a la carpeta para seguir grabando los demas archivos.
sd.chdir("/"); //Return to Root