Skip to content

Commit

Permalink
Merge pull request #663 from dexxter00/rf-fs-fix
Browse files Browse the repository at this point in the history
Rf Save File fix interaction with filesystem
  • Loading branch information
pr3y authored Jan 13, 2025
2 parents b427deb + ece34bb commit b4a42cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
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

0 comments on commit b4a42cf

Please sign in to comment.