libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1#pragma once
2#ifndef __DSY_LOGGER_H__
3#define __DSY_LOGGER_H__
4
5#include <cmath>
6#include <cstdarg>
7#include <cstdio>
8#include "logger_impl.h"
9
10namespace daisy
11{
28#define LOGGER_NEWLINE "\r\n"
29#define LOGGER_BUFFER 128
34#define PPCAT_NX(A, B) A##B
35#define PPCAT(A, B) PPCAT_NX(A, B)
36#define STRINGIZE_NX(A) #A
37#define STRINGIZE(A) STRINGIZE_NX(A)
42// clang-format off
43#define FLT_FMT(_n) STRINGIZE(PPCAT(PPCAT(%c%d.%0, _n), d))
44// clang-format on
45
49#define FLT_VAR(_n, _x) \
50 (_x < 0 ? '-' : ' '), (int)(abs(_x)), \
51 (int)(((abs(_x)) - (int)(abs(_x))) * pow(10, (_n)))
52
55#define FLT_FMT3 FLT_FMT(3)
58#define FLT_VAR3(_x) FLT_VAR(3, _x)
59
// End logging_macros
61
70template <LoggerDestination dest = LOGGER_INTERNAL>
71class Logger
72{
73 public:
76 Logger() {}
77
80 static void Print(const char* format, ...);
81
84 static void PrintLine(const char* format, ...);
85
89 static void StartLog(bool wait_for_pc = false);
90
93 static void PrintV(const char* format, va_list va);
94
97 static void PrintLineV(const char* format, va_list va);
98
99 protected:
108
111 static void TransmitSync(const void* buffer, size_t bytes)
112 {
113 while(false == impl_.Transmit(buffer, bytes)) {}
114 }
115
118 static void TransmitBuf();
119
122 static void AppendNewLine();
123
126 static constexpr size_t NewLineSeqLength()
127 {
128 size_t len = 0;
129 constexpr const char* nl = LOGGER_NEWLINE;
130 while(nl[len] != '\0')
131 {
132 len++;
133 }
134 return len;
135 }
136
140 static char tx_buff_[LOGGER_BUFFER];
141 static size_t tx_ptr_;
142 static size_t pc_sync_;
144};
145
153template <LoggerDestination dest>
155
158template <LoggerDestination dest>
159size_t Logger<dest>::pc_sync_ = LOGGER_SYNC_OUT;
160
161template <LoggerDestination dest>
162size_t Logger<dest>::tx_ptr_ = 0;
163
164template <LoggerDestination dest>
166
// end logger_statics
168
171template <>
173{
174 public:
175 Logger() {}
176 static void Print(const char* format, ...) {}
177 static void PrintLine(const char* format, ...) {}
178 static void StartLog(bool wait_for_pc = false) {}
179 static void PrintV(const char* format, va_list va) {}
180 static void PrintLineV(const char* format, va_list va) {}
181};
182
184} // namespace daisy
185
186#endif // __DSY_LOGGER_H__
Definition leddriver.h:33
static void PrintLineV(const char *format, va_list va)
Definition logger.h:180
Logger()
Definition logger.h:175
static void Print(const char *format,...)
Definition logger.h:176
static void StartLog(bool wait_for_pc=false)
Definition logger.h:178
static void PrintV(const char *format, va_list va)
Definition logger.h:179
static void PrintLine(const char *format,...)
Definition logger.h:177
Interface for simple USB logging.
Definition logger.h:72
static void AppendNewLine()
static void PrintLineV(const char *format, va_list va)
Logger()
Definition logger.h:76
static void TransmitBuf()
static constexpr size_t NewLineSeqLength()
Definition logger.h:126
static void PrintV(const char *format, va_list va)
static void StartLog(bool wait_for_pc=false)
static void Print(const char *format,...)
LoggerConsts
Definition logger.h:103
@ LOGGER_SYNC_OUT
Definition logger.h:104
@ LOGGER_SYNC_IN
Definition logger.h:105
static void PrintLine(const char *format,...)
static void TransmitSync(const void *buffer, size_t bytes)
Definition logger.h:111
static size_t tx_ptr_
Definition logger.h:141
static LoggerImpl< dest > impl_
Definition logger.h:143
static size_t pc_sync_
Definition logger.h:142
static char tx_buff_[128]
Definition logger.h:140
#define LOGGER_NEWLINE
Definition logger.h:28
#define LOGGER_BUFFER
Definition logger.h:29
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ LOGGER_NONE
Definition logger_impl.h:16