| 584 | } |
| 585 | |
| 586 | bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char *key, bool autoSave) { |
| 587 | FS *fs; |
| 588 | String filename = ""; |
| 589 | |
| 590 | if (!getFsStorage(fs)) { |
| 591 | displayError("No space left on device", true); |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | if (!codes.key && codes.data == "") { |
| 596 | Serial.println("Empty signal, it was not saved."); |
| 597 | return false; |
| 598 | } |
| 599 | |
| 600 | String subfile_out = "Filetype: Bruce SubGhz File\nVersion 1\n"; |
| 601 | subfile_out += "Frequency: " + String(int(frequency * 1000000)) + "\n"; |
| 602 | if (!raw) { |
| 603 | subfile_out += "Preset: " + String(codes.preset) + "\n"; |
| 604 | subfile_out += "Protocol: RcSwitch\n"; |
| 605 | subfile_out += "Bit: " + String(codes.Bit) + "\n"; |
| 606 | if (codes.hop != 0) { |
| 607 | subfile_out += "Manufacturer: " + String(codes.mf_name) + "\n"; |
| 608 | char hexString[64] = {0}; |
| 609 | |
| 610 | decimalToHexString(codes.serial, hexString); |
| 611 | |
| 612 | subfile_out += "Serial: " + String(hexString) + "\n"; |
| 613 | subfile_out += "Button: " + String(codes.btn) + "\n"; |
| 614 | subfile_out += "Counter: " + String(codes.cnt) + "\n"; |
| 615 | } else { |
| 616 | subfile_out += "Key: " + String(key) + "\n"; |
| 617 | } |
| 618 | subfile_out += "TE: " + String(codes.te) + "\n"; |
| 619 | filename = "rcs.sub"; |
| 620 | // subfile_out += "RAW_Data: " + codes.data; |
| 621 | } else { |
| 622 | // save as raw |
| 623 | if (codes.preset == "1") { |
| 624 | codes.preset = "FuriHalSubGhzPresetOok270Async"; |
| 625 | } else if (codes.preset == "2") { |
| 626 | codes.preset = "FuriHalSubGhzPresetOok650Async"; |
| 627 | } |
| 628 | |
| 629 | subfile_out += "Preset: " + String(codes.preset) + "\n"; |
| 630 | subfile_out += "Protocol: RAW\n"; |
| 631 | subfile_out += "RAW_Data: " + codes.data; |
| 632 | filename = "raw.sub"; |
| 633 | } |
| 634 | |
| 635 | String filepath = "/BruceRF"; |
| 636 | if (autoSave) filepath += "/autoSaved"; |
| 637 | File file = createNewFile(fs, filepath, filename); |
| 638 | |
| 639 | if (file) { |
| 640 | file.println(subfile_out); |
| 641 | if (!autoSave) displaySuccess(file.path()); |
| 642 | } else { |
| 643 | displayError("Error saving file", true); |
no test coverage detected