Bonjour à tous,
J'utilise une fonction de cette maniere
sprint(F("Buz"),2);
void sprint(const __FlashStringHelper * message, int logToSd)
{
if(logToSd == 0 || logToSd == 2)
{
SerialUSB.print(message);
}
if(logToSd == 1 || logToSd == 2)
{
#ifdef LOGGER
sd_write(sd_logFile, message);
#endif
}
}
J'aimerais savoir il y est possible de converti un const __FlashStringHelper pour qu'il puisse etre utilisé par un char
Voir ci-dessous mon commentaire en majuscule
#define LOGGER
sprint(F("Buz"),2);
void sprint(const __FlashStringHelper * message, int logToSd)
{
if(logToSd == 0 || logToSd == 2)
{
SerialUSB.print(message);
}
if(logToSd == 1 || logToSd == 2)
{
#ifdef LOGGER
sd_write(sd_logFile, message);
#endif
}
}
void sd_write(char * fileName, const __FlashStringHelper * text)
{
// CONVERTIR ICI text POUR QU IL PUISSE ETRE UTILISE DANS LA FONCTION SUIVANTE, SOIT UN CHAR
sd_write(fileName, text, false);
}
void sd_write(char * fileName, char * text, bool ln)
{
#ifdef LOGGER
if(isSdReady == true)
{
digitalWrite(PIN_SDLED, HIGH);
logfile = SD.open(fileName, FILE_WRITE);
// if the file opened okay, write to it:
if (logfile)
{
sprint(F("Writing ["),0);
sprint(text,0);
sprint(F("] to "),0);
sprint(F(fileName),0);
if(ln == true)
{
logfile.println(text);
}
else
{
logfile.print(text);
}
logfile.flush();
// close the file:
logfile.close();
sprintln(F(" => Done."),0);
}
else
{
// if the file didn't open, print an error:
sprint(F("\nError opening "),0); sprintln(fileName,0);
}
digitalWrite(PIN_SDLED, LOW);
// delay(100);
}
#endif
}
Voyez-vous? le but étant d'éviter des faire deux mêmes fonctions avec un petit détail qui change.
Je vous remercie!