Go Down

Topic: variable name for SD file  (Read 519 times) previous topic - next topic

adwsystems

What parameters have you tried using when calling getDateStr()?

Lucario448

Step 1 is the issue, the function returns the date with periods by default.
It is not, specially when it returns a String object.
Removing or replacing characters in a String is a breeze; in a char array you'll have to create a function but is not that difficult either.


I'm not sure the filename is limited to 8.3 but does have similar restrictions (only one period allowed) as I'm using very_long_file_names.txt and it works (but only one period).
For opening existing files should work as long as the converted SFN matches the SFN version of the target file.

For creating files, I always believed the library will use only the SFN version anyway.
For example, I believe creating a file called "very_long_file_names.txt" will show up as "VERY_L~1.TXT" in the Windows file explorer. If not, then prove me that I'm wrong.
What I do know for sure, is that SdFat supports LFNs by default and for everything.

adwsystems

#17
Sep 26, 2018, 11:35 am Last Edit: Sep 26, 2018, 11:36 am by adwsystems
It is not, specially when it returns a String object.
Not according to the code.

Code: [Select]

 char *getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');


char *DS1302::getDateStr(uint8_t slformat, uint8_t eformat, char divider)
{
 char *output= "xxxxxxxxxx";
 int yr, offset;
 Time t;
 t=getTime();
 switch (eformat)
 {
 case FORMAT_LITTLEENDIAN:
 if (t.date<10)
 output[0]=48;
 else
 output[0]=char((t.date / 10)+48);
 output[1]=char((t.date % 10)+48);
 output[2]=divider;
 if (t.mon<10)
 output[3]=48;
 else
 output[3]=char((t.mon / 10)+48);
 output[4]=char((t.mon % 10)+48);
 output[5]=divider;
 if (slformat==FORMAT_SHORT)
 {
 yr=t.year-2000;
 if (yr<10)
 output[6]=48;
 else
 output[6]=char((yr / 10)+48);
 output[7]=char((yr % 10)+48);
 output[8]=0;
 }
 else
 {
 yr=t.year;
 output[6]=char((yr / 1000)+48);
 output[7]=char(((yr % 1000) / 100)+48);
 output[8]=char(((yr % 100) / 10)+48);
 output[9]=char((yr % 10)+48);
 output[10]=0;
 }
 break;
 case FORMAT_BIGENDIAN:
 if (slformat==FORMAT_SHORT)
 offset=0;
 else
 offset=2;
 if (slformat==FORMAT_SHORT)
 {
 yr=t.year-2000;
 if (yr<10)
 output[0]=48;
 else
 output[0]=char((yr / 10)+48);
 output[1]=char((yr % 10)+48);
 output[2]=divider;
 }
 else
 {
 yr=t.year;
 output[0]=char((yr / 1000)+48);
 output[1]=char(((yr % 1000) / 100)+48);
 output[2]=char(((yr % 100) / 10)+48);
 output[3]=char((yr % 10)+48);
 output[4]=divider;
 }
 if (t.mon<10)
 output[3+offset]=48;
 else
 output[3+offset]=char((t.mon / 10)+48);
 output[4+offset]=char((t.mon % 10)+48);
 output[5+offset]=divider;
 if (t.date<10)
 output[6+offset]=48;
 else
 output[6+offset]=char((t.date / 10)+48);
 output[7+offset]=char((t.date % 10)+48);
 output[8+offset]=0;
 break;
 case FORMAT_MIDDLEENDIAN:
 if (t.mon<10)
 output[0]=48;
 else
 output[0]=char((t.mon / 10)+48);
 output[1]=char((t.mon % 10)+48);
 output[2]=divider;
 if (t.date<10)
 output[3]=48;
 else
 output[3]=char((t.date / 10)+48);
 output[4]=char((t.date % 10)+48);
 output[5]=divider;
 if (slformat==FORMAT_SHORT)
 {
 yr=t.year-2000;
 if (yr<10)
 output[6]=48;
 else
 output[6]=char((yr / 10)+48);
 output[7]=char((yr % 10)+48);
 output[8]=0;
 }
 else
 {
 yr=t.year;
 output[6]=char((yr / 1000)+48);
 output[7]=char(((yr % 1000) / 100)+48);
 output[8]=char(((yr % 100) / 10)+48);
 output[9]=char((yr % 10)+48);
 output[10]=0;
 }
 break;
 }
 return output;
}


I don't see String anywhere in this code and the divider is defaulted to a period.

You may be correct on the filenames using SD versus SDFat. I have SDFat included in my sketches.

Lucario448

I don't see String anywhere in this code
Not in the function, but in the caller. Assigning a char array to a String is possible (because it copies the character sequence).



You may be correct on the filenames using SD versus SDFat. I have SDFat included in my sketches.
Hmm, don't cheat on me.
Well looks like I have to test it myself...

Go Up