0

I'm currently using the SDFat library and am passing a global FatFile

enter image description here

I if have a function that requires an SdFile type and I know that a given instance of FatFile is a valid SdFile what is the best way to reopen FatFile F as SdFile J?

Right now I'm doing:

SdFile ActiveFile;  //Global Active File
...
void SDRun (FatFile &RunFat)
{
  SdFile RunRoot;
  RunRoot.open("/", O_READ);
  ActiveFile.close();
  ActiveFile.open(&RunRoot,RunFat.dirIndex(),O_READ);
  ....

However, this only works when RunFat is in the root directory.

ATE-ENGE
  • 941
  • 3
  • 19
  • 32

1 Answers1

1

If RunFat is an instance of SdFile you can just cast it:

SdFile& RunRoot = dynamic_cast<SdFile&>(RunFat);

RunRoot and RunFat are now the exact same file in the exact same state (no need to open it or anything) but seen as an SdFile not a FatFile.

Majenko
  • 105,851
  • 5
  • 82
  • 139