MCPcopy Create free account
hub / github.com/BruceDevices/firmware / readSubFile

Function readSubFile

src/modules/rf/rf_send.cpp:221–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221bool readSubFile(FS *fs, String filepath, RfCodes &data) {
222 struct RfCodes selected_code;
223 File databaseFile;
224 String line;
225 String txt;
226
227 if (!fs) return false;
228
229 databaseFile = fs->open(filepath, FILE_READ);
230
231 if (!databaseFile) {
232 Serial.println("Failed to open database file.");
233 displayError("Fail to open file", true);
234 return false;
235 }
236 Serial.println("Opened sub file.");
237 selected_code.filepath = filepath.substring(1 + filepath.lastIndexOf("/"));
238
239 if (!databaseFile) Serial.println("Fail opening file");
240 // Store the code(s) in the signal
241 while (databaseFile.available()) {
242 line = databaseFile.readStringUntil('\n');
243 txt = line.substring(line.indexOf(":") + 1);
244 if (txt.endsWith("\r")) txt.remove(txt.length() - 1);
245 txt.trim();
246 if (line.startsWith("Protocol:")) selected_code.protocol = txt;
247 if (line.startsWith("Preset:")) selected_code.preset = txt;
248 if (line.startsWith("Frequency:")) selected_code.frequency = txt.toInt();
249 if (line.startsWith("TE:")) selected_code.te = txt.toInt();
250 if (line.startsWith("Bit:")) bitList.push_back(txt.toInt()); // selected_code.Bit = txt.toInt();
251
252 if (line.startsWith("Manufacturer:")) selected_code.mf_name = txt;
253 if (line.startsWith("Serial:")) selected_code.serial = hexStringToDecimal(txt.c_str());
254 if (line.startsWith("Button:")) selected_code.btn = txt.toInt();
255 if (line.startsWith("Counter:")) selected_code.cnt = txt.toInt();
256
257 if (line.startsWith("Bit_RAW:"))
258 bitRawList.push_back(txt.toInt()); // selected_code.BitRAW = txt.toInt();
259 if (line.startsWith("Key:"))
260 keyList.push_back(
261 hexStringToDecimal(txt.c_str())
262 ); // selected_code.key = hexStringToDecimal(txt.c_str());
263 if (line.startsWith("RAW_Data:") || line.startsWith("Data_RAW:"))
264 rawDataList.push_back(txt); // selected_code.data = txt;
265
266 if (check(EscPress)) break;
267 }
268
269 databaseFile.close();
270
271 data = selected_code;
272
273 return true;
274}
275
276bool txSubFile(RfCodes &selected_code, bool hideDefaultUI) {
277 int sent = 0;

Callers 4

sendCustomRFFunction · 0.85
loopSDFunction · 0.85
rfTxFileCallbackFunction · 0.85
rfTxBufferCallbackFunction · 0.85

Calls 7

displayErrorFunction · 0.85
hexStringToDecimalFunction · 0.85
checkFunction · 0.85
closeMethod · 0.80
printlnMethod · 0.45
availableMethod · 0.45
readStringUntilMethod · 0.45

Tested by

no test coverage detected