Replaced the rest of sprintf() to snprintf_P() functions.

dev
Holger Wirtz 2 years ago
parent d0944d43be
commit 00de27798a
  1. 36
      MicroDexed.ino
  2. 44
      dexed_sd.cpp

@ -2630,25 +2630,25 @@ uint8_t check_sd_cards(void)
#endif #endif
switch (card.type()) { switch (card.type()) {
case SD_CARD_TYPE_SD1: case SD_CARD_TYPE_SD1:
sprintf(sd_string, "%-5s", "SD1"); snprintf_P(sd_string, strlen(sd_string), PSTR("%-5s"), PSTR("SD1"));
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("SD1")); Serial.println(F("SD1"));
#endif #endif
break; break;
case SD_CARD_TYPE_SD2: case SD_CARD_TYPE_SD2:
sprintf(sd_string, "%-5s", "SD2"); snprintf_P(sd_string, strlen(sd_string), PSTR("%-5s"), PSTR("SD2"));
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("SD2")); Serial.println(F("SD2"));
#endif #endif
break; break;
case SD_CARD_TYPE_SDHC: case SD_CARD_TYPE_SDHC:
sprintf(sd_string, "%-5s", "SD2"); snprintf_P(sd_string, strlen(sd_string), PSTR("%-5s"), PSTR("SD2"));
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("SDHC")); Serial.println(F("SDHC"));
#endif #endif
break; break;
default: default:
sprintf(sd_string, "%-5s", "UKNW"); snprintf_P(sd_string, strlen(sd_string), PSTR("%-5s"), PSTR("UKNW"));
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Unknown")); Serial.println(F("Unknown"));
#endif #endif
@ -2679,7 +2679,7 @@ uint8_t check_sd_cards(void)
Serial.println(volumesize); Serial.println(volumesize);
#endif #endif
sprintf(sd_string + 5, "FAT%2d %02dGB", volume.fatType(), int(volumesize)); snprintf_P(sd_string + 5, strlen(sd_string), PSTR("FAT%2d %02dGB"), volume.fatType(), int(volumesize));
} }
#ifdef DEBUG #ifdef DEBUG
@ -2702,7 +2702,7 @@ void check_and_create_directories(void)
// create directories for banks // create directories for banks
for (i = 0; i < MAX_BANKS; i++) for (i = 0; i < MAX_BANKS; i++)
{ {
sprintf(tmp, "/%d", i); snprintf_P(tmp, strlen(tmp), PSTR("/%d"), i);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2713,7 +2713,7 @@ void check_and_create_directories(void)
} }
} }
sprintf(tmp, "/%s", PERFORMANCE_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), PERFORMANCE_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2725,7 +2725,7 @@ void check_and_create_directories(void)
/* /*
// create directories for configuration files // create directories for configuration files
sprintf(tmp, "/%s", VOICE_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), VOICE_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2734,7 +2734,7 @@ void check_and_create_directories(void)
#endif #endif
SD.mkdir(tmp); SD.mkdir(tmp);
} }
sprintf(tmp, "/%s", PERFORMANCE_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), PERFORMANCE_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2743,7 +2743,7 @@ void check_and_create_directories(void)
#endif #endif
SD.mkdir(tmp); SD.mkdir(tmp);
} }
sprintf(tmp, "/%s", FX_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), FX_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2752,7 +2752,7 @@ void check_and_create_directories(void)
#endif #endif
SD.mkdir(tmp); SD.mkdir(tmp);
} }
sprintf(tmp, "/%s", DRUM_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), DRUM_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2761,7 +2761,7 @@ void check_and_create_directories(void)
#endif #endif
SD.mkdir(tmp); SD.mkdir(tmp);
} }
sprintf(tmp, "/%s", FAV_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), FAV_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2772,7 +2772,7 @@ void check_and_create_directories(void)
} }
*/ */
sprintf(tmp, "/%s", PERFORMANCE_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s"), PERFORMANCE_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
{ {
#ifdef DEBUG #ifdef DEBUG
@ -2783,14 +2783,14 @@ void check_and_create_directories(void)
} }
//check if updated Fav-System is ready or if setup has to run once. //check if updated Fav-System is ready or if setup has to run once.
sprintf(tmp, "/%s/fav-v2", FAV_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s/fav-v2"), FAV_CONFIG_PATH);
if (!SD.exists(tmp)) { if (!SD.exists(tmp)) {
// Clear now obsolte marker files from Favs. // Clear now obsolte marker files from Favs.
// Only needs to run once. // Only needs to run once.
for (uint8_t i = 0; i < MAX_BANKS; i++) for (uint8_t i = 0; i < MAX_BANKS; i++)
{ {
sprintf(tmp, "/%s/%d/hasfav", FAV_CONFIG_PATH, i); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d/hasfav"), FAV_CONFIG_PATH, i);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Delete Marker File")); Serial.print(F("Delete Marker File"));
Serial.println(tmp); Serial.println(tmp);
@ -2802,7 +2802,7 @@ void check_and_create_directories(void)
// Only needs to run once. // Only needs to run once.
for (uint8_t i = 0; i < MAX_BANKS; i++) for (uint8_t i = 0; i < MAX_BANKS; i++)
{ {
sprintf(tmp, "/%s/%d", FAV_CONFIG_PATH, i); snprintf_P(tmp, strlen(tmp), PSTR("/%s/%d"), FAV_CONFIG_PATH, i);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Delete empty folder ")); Serial.print(F("Delete empty folder "));
Serial.println(tmp); Serial.println(tmp);
@ -2810,7 +2810,7 @@ void check_and_create_directories(void)
if (SD.exists(tmp)) if (SD.exists(tmp))
SD.rmdir(tmp); SD.rmdir(tmp);
} }
sprintf(tmp, "/%s/fav-v2", FAV_CONFIG_PATH); snprintf_P(tmp, strlen(tmp), PSTR("/%s/fav-v2"), FAV_CONFIG_PATH);
if (!SD.exists(tmp)) if (!SD.exists(tmp))
SD.mkdir(tmp); // Set Marker so that the Cleanup loops only run once. SD.mkdir(tmp); // Set Marker so that the Cleanup loops only run once.
} }
@ -3087,7 +3087,7 @@ void SerialPrintFormatInt3(uint8_t num)
{ {
char buf[4]; char buf[4];
memset(buf, 0, 4); memset(buf, 0, 4);
sprintf(buf, "%3d", num); snprintf_P(buf, strlen(buf), PSTR("%3d"), num);
Serial.print(buf); Serial.print(buf);
} }

@ -83,7 +83,7 @@ bool load_sd_voice(uint8_t b, uint8_t v, uint8_t instance_id)
uint8_t data[128]; uint8_t data[128];
get_bank_name(b, bank_name, sizeof(bank_name)); get_bank_name(b, bank_name, sizeof(bank_name));
sprintf(filename, "/%d/%s.syx", b, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), b, bank_name);
AudioNoInterrupts(); AudioNoInterrupts();
sysex = SD.open(filename); sysex = SD.open(filename);
@ -154,7 +154,7 @@ bool save_sd_voice(uint8_t b, uint8_t v, uint8_t instance_id)
uint8_t data[128]; uint8_t data[128];
get_bank_name(b, bank_name, sizeof(bank_name)); get_bank_name(b, bank_name, sizeof(bank_name));
sprintf(filename, "/%d/%s.syx", b, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), b, bank_name);
AudioNoInterrupts(); AudioNoInterrupts();
sysex = SD.open(filename, FILE_WRITE); sysex = SD.open(filename, FILE_WRITE);
@ -369,7 +369,7 @@ bool save_sd_bank(const char* bank_filename, uint8_t* data)
// first remove old bank // first remove old bank
sscanf(bank_filename, "/%d/%s", &bank_number, tmp); sscanf(bank_filename, "/%d/%s", &bank_number, tmp);
sprintf(tmp, "/%d", bank_number); snprintf_P(tmp, strlen(tmp), PSTR("/%d"), bank_number);
AudioNoInterrupts(); AudioNoInterrupts();
root = SD.open(tmp); root = SD.open(tmp);
while (42 == 42) while (42 == 42)
@ -385,7 +385,7 @@ bool save_sd_bank(const char* bank_filename, uint8_t* data)
Serial.print(F("/")); Serial.print(F("/"));
Serial.println(entry.name()); Serial.println(entry.name());
#endif #endif
sprintf(tmp2, "%s/%s", tmp, entry.name()); snprintf_P(tmp2, strlen(tmp2), PSTR("%s/%s"), tmp, entry.name());
entry.close(); entry.close();
#ifndef DEBUG #ifndef DEBUG
SD.remove(tmp2); SD.remove(tmp2);
@ -444,7 +444,7 @@ bool load_sd_drumsettings_json(uint8_t number)
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -518,7 +518,7 @@ bool save_sd_drumsettings_json(uint8_t number)
if (check_performance_directory(number)) if (check_performance_directory(number))
{ {
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, DRUMS_CONFIG_NAME);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving drums config ")); Serial.print(F("Saving drums config "));
@ -598,7 +598,7 @@ bool load_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id)
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id + 1); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s%d.json"), PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id + 1);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -691,7 +691,7 @@ bool save_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id)
{ {
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id + 1); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s%d.json"), PERFORMANCE_CONFIG_PATH, vc, VOICE_CONFIG_NAME, instance_id + 1);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving voice config ")); Serial.print(F("Saving voice config "));
@ -782,7 +782,7 @@ bool load_sd_fx_json(uint8_t number)
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, FX_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, FX_CONFIG_NAME);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -882,7 +882,7 @@ bool save_sd_fx_json(uint8_t number)
{ {
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, FX_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, FX_CONFIG_NAME);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving fx config ")); Serial.print(F("Saving fx config "));
@ -968,7 +968,7 @@ bool load_sd_epiano_json(uint8_t number)
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, EPIANO_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, EPIANO_CONFIG_NAME);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -1048,7 +1048,7 @@ bool save_sd_epiano_json(uint8_t number)
{ {
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, EPIANO_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, EPIANO_CONFIG_NAME);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving epiano config ")); Serial.print(F("Saving epiano config "));
@ -1117,7 +1117,7 @@ bool load_sd_sys_json(void)
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s.json", SYS_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s.json"), SYS_CONFIG_NAME);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -1182,7 +1182,7 @@ bool save_sd_sys_json(void)
{ {
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s.json", SYS_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s.json"), SYS_CONFIG_NAME);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving sys config to ")); Serial.print(F("Saving sys config to "));
@ -1249,7 +1249,7 @@ bool save_sd_performance_json(uint8_t number)
for (uint8_t i = 0; i < MAX_DEXED; i++) for (uint8_t i = 0; i < MAX_DEXED; i++)
{ {
sprintf(filename, "/%s/%d/%s%d.json", PERFORMANCE_CONFIG_PATH, number, VOICE_CONFIG_NAME, i); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s%d.json"), PERFORMANCE_CONFIG_PATH, number, VOICE_CONFIG_NAME, i);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Write Voice-Config")); Serial.print(F("Write Voice-Config"));
Serial.println(filename); Serial.println(filename);
@ -1261,7 +1261,7 @@ bool save_sd_performance_json(uint8_t number)
{ {
File json; File json;
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Saving performance config ")); Serial.print(F("Saving performance config "));
Serial.print(number); Serial.print(number);
@ -1309,7 +1309,7 @@ bool check_performance_directory(uint8_t number)
if (sd_card > 0) if (sd_card > 0)
{ {
sprintf(dir, "/%s/%d", PERFORMANCE_CONFIG_PATH, number); snprintf_P(dir, strlen(dir), PSTR("/%s/%d"), PERFORMANCE_CONFIG_PATH, number);
AudioNoInterrupts(); AudioNoInterrupts();
SD.begin(); SD.begin();
@ -1353,7 +1353,7 @@ void get_sd_performance_name_json(uint8_t number)
StaticJsonDocument<JSON_BUFFER_SIZE> data_json; StaticJsonDocument<JSON_BUFFER_SIZE> data_json;
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME);
// first check if file exists... // first check if file exists...
AudioNoInterrupts(); AudioNoInterrupts();
@ -1439,7 +1439,7 @@ bool check_sd_performance_exists(uint8_t number)
{ {
char filename[CONFIG_FILENAME_LEN]; char filename[CONFIG_FILENAME_LEN];
sprintf(filename, "/%s/%d/%s.json", PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME); snprintf_P(filename, strlen(filename), PSTR("/%s/%d/%s.json"), PERFORMANCE_CONFIG_PATH, number, PERFORMANCE_CONFIG_NAME);
// check if file exists... // check if file exists...
if (SD.exists(filename)) if (SD.exists(filename))
@ -1647,7 +1647,7 @@ bool get_bank_name(uint8_t b, char* name, uint8_t len)
memset(name, 0, len); memset(name, 0, len);
sprintf(bankdir, "/%d", b); snprintf_P(bankdir, strlen(bankdir), PSTR("/%d"), b);
// try to open directory // try to open directory
sysex = SD.open(bankdir); sysex = SD.open(bankdir);
@ -1698,7 +1698,7 @@ bool get_voice_name(uint8_t b, uint8_t v, char* name, uint8_t len)
v = constrain(v, 0, MAX_VOICES - 1); v = constrain(v, 0, MAX_VOICES - 1);
get_bank_name(b, bank_name, sizeof(bank_name)); get_bank_name(b, bank_name, sizeof(bank_name));
sprintf(filename, "/%d/%s.syx", b, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), b, bank_name);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Reading voice-name from [")); Serial.print(F("Reading voice-name from ["));
Serial.print(filename); Serial.print(filename);
@ -1742,7 +1742,7 @@ bool get_voice_by_bank_name(uint8_t b, const char* bank_name, uint8_t v, char* v
{ {
char filename[FILENAME_LEN]; char filename[FILENAME_LEN];
sprintf(filename, "/%d/%s.syx", b, bank_name); snprintf_P(filename, strlen(filename), PSTR("/%d/%s.syx"), b, bank_name);
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Reading voice-name from [")); Serial.print(F("Reading voice-name from ["));
Serial.print(filename); Serial.print(filename);

Loading…
Cancel
Save