| 27 | } |
| 28 | |
| 29 | void SD_Logger::data_callback(int id, unsigned int timestamp, const String & data_string) { |
| 30 | if (id == -1) { |
| 31 | dump_to_sd(); |
| 32 | _file.close(); |
| 33 | _opened = false; |
| 34 | return; |
| 35 | }; |
| 36 | |
| 37 | String text = String(id); |
| 38 | text += ", " + String(timestamp); |
| 39 | text += ", " + data_string; |
| 40 | text += "\r\n"; |
| 41 | |
| 42 | if (text.length() + _index > LOGGER_BUFFER_SIZE) { |
| 43 | dump_to_sd(); |
| 44 | } |
| 45 | |
| 46 | text.toCharArray(&(_buffer[_index]), text.length()); |
| 47 | _index += text.length() - 1; // -1 to remove null terminator |
| 48 | } |
| 49 | |
| 50 | void SD_Logger::dump_to_sd() { |
| 51 | if (!open_file()) return; |