Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rf Save File fix interaction with filesystem #663

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ lib_deps =
https://github.com/rennancockles/MFRC522-I2C
https://github.com/rennancockles/ESP-ChameleonUltra
https://github.com/rennancockles/ESP-Amiibolink
;https://github.com/epiHATR/ESP-PN532BLE
https://github.com/whywilson/ESP-PN532BLE
NTPClient
Timezone
Expand Down
51 changes: 18 additions & 33 deletions src/modules/rf/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,14 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) {

bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key)
{
FS *fs;
String filename = "";

if(!getFsStorage(fs)) {
displayError("No space left on device", true);
return false;
}

if (!codes.key && codes.data=="") {
Serial.println("Empty signal, it was not saved.");
return false;
Expand All @@ -843,6 +851,7 @@ bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key)
subfile_out += "Bit: " + String(codes.Bit) + "\n";
subfile_out += "Key: " + String(key) + "\n";
subfile_out += "TE: " + String(codes.te) + "\n";
filename = "rcs_";
//subfile_out += "RAW_Data: " + codes.data;
} else {
// save as raw
Expand All @@ -856,45 +865,21 @@ bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char* key)
subfile_out += "Preset: " + String(codes.preset) + "\n";
subfile_out += "Protocol: RAW\n";
subfile_out += "RAW_Data: " + codes.data;
filename = "raw_";
}

int i = 0;
File file;
String FS = "";

if (SD.begin()) {
if (!SD.exists("/BruceRF")) {
SD.mkdir("/BruceRF");
}

while (SD.exists("/BruceRF/bruce_" + String(i) + ".sub")) {
i++;
}

file = SD.open("/BruceRF/bruce_"+ String(i) +".sub", FILE_WRITE);
FS="SD";
} else if (LittleFS.begin()) {
sdcardMounted=false;
if (!checkLittleFsSize()) {
return false;
}
if (!LittleFS.exists("/BruceRF")) {
LittleFS.mkdir("/BruceRF");
}

while(LittleFS.exists("/BruceRF/bruce_" + String(i) + ".sub")) {
i++;
}

file = LittleFS.open("/BruceRF/bruce_" + String(i) +".sub", FILE_WRITE);
FS = "LittleFS";
}
if (!(*fs).exists("/BruceRF")) (*fs).mkdir("/BruceRF");
while((*fs).exists("/BruceRF/" + filename + String(i) + ".sub")) i++;

file = (*fs).open("/BruceRF/" + filename + String(i) + ".sub", FILE_WRITE);

if (file) {
file.println(subfile_out);
displaySuccess(FS + "/bruce_" + String(i) + ".sub");
displaySuccess("/BruceRF/" + filename + String(i) + ".sub");
} else {
Serial.println("Fail saving data to LittleFS");
displayError("Error saving file", true);
}

Expand Down Expand Up @@ -1652,7 +1637,7 @@ void rf_scan_copy() {
goto RestartScan;
}

if (option == 1) { // Range
if (option == 1) { // Range submenu
option=0;
options = {
{ String("Fxd [" + String(bruceConfig.rfFreq) + "]").c_str(), [=]() { bruceConfig.setRfScanRange(bruceConfig.rfScanRange, 1); } },
Expand All @@ -1665,7 +1650,7 @@ void rf_scan_copy() {

loopOptions(options);

if(option == 1) {
if(option == 1) { // Range
options = {};
int ind=0;
int arraySize = sizeof(subghz_frequency_list) / sizeof(subghz_frequency_list[0]);
Expand All @@ -1689,7 +1674,7 @@ void rf_scan_copy() {
decimalToHexString(received.key,hexString);
RCSwitch_SaveSignal(found_freq, received, received.protocol=="RAW"? true:false, hexString);
deinitRfModule();
delay(200);
delay(1500);
goto RestartScan;
}
else if (option == 3) { // Set Default
Expand Down
Loading