| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | // Helpers for log messages.#pragma once#include <stdint.h>#include <stddef.h>// Get total number of bytes that have been written to loguint32_t log_get_buffer_len();// Get log as a string.// If startpos is given, continues log reading from previous position and updates the position.// If available is given, number of bytes available is written there.const char *log_get_buffer(uint32_t *startpos, uint32_t *available = nullptr);// Whether to enable debug messagesextern bool g_log_debug;// Firmware version stringextern const char *g_log_firmwareversion;// Log stringvoid log_raw(const char *str);// Log byte as hexvoid log_raw(uint8_t value);// Log integer as hexvoid log_raw(uint32_t value);// Log integer as hexvoid log_raw(uint64_t value);// Log integer as decimalvoid log_raw(int value);// Log doublevoid log_raw(double value);// Log array of bytesstruct bytearray {    bytearray(const uint8_t *data, size_t len): data(data), len(len) {}    const uint8_t *data;    size_t len;};void log_raw(bytearray array);inline void log_raw(){    // End of template recursion}extern "C" unsigned long millis();// Variadic template for printing multiple itemstemplate<typename T, typename T2, typename... Rest>inline void log_raw(T first, T2 second, Rest... rest){    log_raw(first);    log_raw(second);    log_raw(rest...);}// Format a complete log messagetemplate<typename... Params>inline void log(Params... params){    if (g_log_debug)    {        log_raw("[", (int)millis(), "ms] ");    }    log_raw(params...);    log_raw("\n");}// Format a complete debug messagetemplate<typename... Params>inline void debuglog(Params... params){    if (g_log_debug)    {        log_raw("[", (int)millis(), "ms] DBG ");        log_raw(params...);        log_raw("\n");    }}
 |