At this time I am basically just starting out doing this but I think I have the basics working (at least some of the time). I'll try to give a paraphrased code example.
This will work, the SD startup located in .ino file as are all related functions.
// Ini file
#include <Arduino.h>
#include <SD.h>
String Infile = "TestFile.txt;
void EraseFile(String Infile) {
// Delete the file:
Serial.println(Infile);
if (SD.exists(Infile)) SD.remove(Infile);
else Serial.println("File Not Found");
}
void setup() {
Serial.begin(74880);
SD.begin(53);
}
void loop() { EraseFile(String Infile); }
This will work, the SD startup located in .cpp file as are all related functions. Functions used to call the SD library's functions.
// Ini file
#include <Arduino.h>
#include "SD_Functions.h"
void setup() {
Serial.begin(74880);
SetupSD();
}
void loop() {
Deletefile();
Serial.println("DONE");
}
// SD_Functions.h
#include <Arduino.h>
#include <SD.h>
#include "SD_Functions.h"
void SetupSD();
void Deletefile();
void EraseFile(String Infile);
// "SD_Functions.cpp"
#include <Arduino.h>
#include <SD.h>
#include "SD_Functions.h"
String Infile = "TestFile.txt";
void SetupSD() { SDBegin(53); }
void Deletefile() { EraseFile(Infile) };
void EraseFile(String Infile) {
Serial.println(Infile);
if (SD.exists(Infile)) SD.remove(Infile);
else Serial.println("File Not Found");
}
This will not work!! The SD startup is done in the .ino file. The erase function is located in the .cpp file.
// Ini file
#include <Arduino.h>
#include <SD.h>
#include "SD_Functions.h"
void setup() {
Serial.begin(74880);
SD.begin(53);
}
void loop() { EraseFile(Infile); }
// SD_Functions.h
#include <Arduino.h>
#include <SD.h>
void EraseFile(String Infile);
// "SD_Functions.cpp"
#include <Arduino.h>
#include <SD.h>
#include "SD_Functions.h"
String Infile = "TestFile.txt;
void EraseFile(String Infile) {
Serial.println(Infile);
if (SD.exists(Infile)) SD.remove(Infile);
else Serial.println("File Not Found");
}
The above three (3) examples are a simple example of the concept of which I am asking about. The code should compile but no guarantees. I am trying to present a concept here not necessarily functional code.
You might ask why I would want to do this but it has to do mostly with the amount of code I have generated to get done what I am trying to get done.
The SD code alone is about 600 lines. The code I have generated to the GPS work is probably closer to 1000 lines of code. The graphics code will certainly exceed 1000 lines of code before I am done and the code I use to collect and display the engine data from the engine's ECU probably runs another 500 lines of code.
This thing is becoming difficult to work on and the compile and linking times are becoming ridicules.
I hope this helps better explain where I am trying to go.
Any in site you can provide will be greatly appreciated. If I have to startup and run the hardware library from the file I use it, so be it. I will just have to work with that limitation.