30 lines
806 B
C
30 lines
806 B
C
#include "base/usb_logging.h"
|
|
|
|
void reset_log_buffer(void) {
|
|
// If debug, then memset buffer
|
|
memset(log_buffer, 0, sizeof(log_buffer));
|
|
m_log_usage = 0;
|
|
m_log_buffer_send_index = 0;
|
|
tx_complete = true;
|
|
full_tx_complete = false;
|
|
}
|
|
|
|
void add_to_log_buffer(String str) {
|
|
// Bounds check the buffer:
|
|
if (m_log_usage + str.count >= sizeof(log_buffer)) {
|
|
// Failure!.. How to handle? Turn on LEDs?
|
|
return; // Do not add to buffer
|
|
}
|
|
memcpy(&log_buffer[m_log_usage], str.data, str.count);
|
|
m_log_usage += str.count;
|
|
}
|
|
|
|
// #TODO: Inline
|
|
void add_format_string_to_log_buffer(void) {
|
|
// Replace null terminator with \n where required.
|
|
sprint_buffer[sprint_length] = '\n';
|
|
String s = {sprint_length+1, sprint_buffer};
|
|
add_to_log_buffer(s);
|
|
}
|
|
|