mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Merge pull request 'debug-printf' (#13) from debug-printf into main
Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/sta-core/pulls/13
This commit is contained in:
commit
0aa0995c70
@ -19,7 +19,7 @@ namespace sta
|
||||
*
|
||||
* @ingroup sta_core_debug
|
||||
*/
|
||||
# define STA_DEBUG_PRINT(...) sta::Debug->print(__VA_ARGS__)
|
||||
# define STA_DEBUG_PRINT(...) sta::Debug->print(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Debug print message followed by new-line to UART.
|
||||
@ -28,12 +28,21 @@ namespace sta
|
||||
*
|
||||
* @ingroup sta_core_debug
|
||||
*/
|
||||
# define STA_DEBUG_PRINTLN(...) sta::Debug->println(__VA_ARGS__)
|
||||
# define STA_DEBUG_PRINTLN(...) sta::Debug->println(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Formatted debug printing with new-line.
|
||||
*
|
||||
* @param fmt See @ref sta::PrintableUART::printf
|
||||
* @param ... See @ref sta::PrintableUART::printf
|
||||
*/
|
||||
# define STA_DEBUG_PRINTF(fmt, ...) sta::Debug->printf(fmt, __VA_ARGS__)
|
||||
|
||||
#else // !STA_DEBUGGING_ENABLED
|
||||
|
||||
# define STA_DEBUG_PRINT(...) ((void)0)
|
||||
# define STA_DEBUG_PRINTLN(...) ((void)0)
|
||||
# define STA_DEBUG_PRINT(...) ((void)0)
|
||||
# define STA_DEBUG_PRINTLN(...) ((void)0)
|
||||
# define STA_DEBUG_PRINTF(fmt, ...) ((void)0)
|
||||
|
||||
#endif // STA_DEBUGGING_ENABLED
|
||||
|
||||
|
@ -26,6 +26,12 @@ namespace sta
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief fmt The string defining the desired format.
|
||||
* @breif ... The parameters for the formatted string.
|
||||
*/
|
||||
void printf(const char * fmt, ...);
|
||||
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
|
@ -3,12 +3,30 @@
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void Printable::printf(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
|
||||
char temp[1];
|
||||
int n = vsnprintf(temp, 1, fmt, args);
|
||||
|
||||
va_start (args, fmt);
|
||||
char str[n+1];
|
||||
vsnprintf(str, n+1, fmt, args);
|
||||
STA_ASSERT(n > 0);
|
||||
|
||||
println(str);
|
||||
}
|
||||
|
||||
void Printable::print(char c)
|
||||
{
|
||||
print(&c, 1);
|
||||
@ -182,4 +200,4 @@ namespace sta
|
||||
print(buffer, digits);
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
} // namespace sta
|
||||
|
Loading…
x
Reference in New Issue
Block a user