diff --git a/src/button_utils.cpp b/src/button_utils.cpp index 5b18cb0..7928546 100644 --- a/src/button_utils.cpp +++ b/src/button_utils.cpp @@ -1,5 +1,6 @@ #include #include "configuration.h" +#include "station_utils.h" #include "button_utils.h" #include "msg_utils.h" #include "display.h" @@ -74,6 +75,7 @@ namespace BUTTON_Utils { display_toggle(true); displayTime = millis(); show_display("__INFO____", "", "CHANGING CALLSIGN ...", 1000); + STATION_Utils::saveCallsingIndex(myBeaconsIndex); } else if (menuDisplay == 1) { MSG_Utils::deleteFile(); show_display("__INFO____", "", "ALL MESSAGES DELETED!", 2000); diff --git a/src/station_utils.cpp b/src/station_utils.cpp index 2ef648b..8a63376 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "station_utils.h" #include "configuration.h" @@ -426,4 +427,34 @@ namespace STATION_Utils { } } + void saveCallsingIndex(int index) { + if(!SPIFFS.begin(true)) { + Serial.println("An Error has occurred while mounting SPIFFS"); + return; + } + + /*if (SPIFFS.exists("/file.txt")) { + Serial.println("File exists in SPIFFS"); + } else { + Serial.println("File does not exist in SPIFFS"); + }*/ + + File fileCallsignIndex = SPIFFS.open("/callsignIndex.txt", "w"); + if(!fileCallsignIndex){ + Serial.println("no existe archivo, se escribe"); + Serial.println("Failed to open APRS_Msg for reading"); + //return; + } else { + Serial.println("ya existe archivo pero se SOBRE escribe"); + } + String dataToSave = String(index); + + if (fileCallsignIndex.println(dataToSave)) { + Serial.println("Callsign Index saved to SPIFFS"); + } else { + Serial.println("Error saving data to file"); + } + fileCallsignIndex.close(); + } + } \ No newline at end of file diff --git a/src/station_utils.h b/src/station_utils.h index 18b0d58..26a1597 100644 --- a/src/station_utils.h +++ b/src/station_utils.h @@ -17,6 +17,7 @@ void checkSmartBeaconInterval(int speed); void checkStandingUpdateTime(); void checkSmartBeaconState(); void sendBeacon(); +void saveCallsingIndex(int index); }