libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
WutLoggerUsbSerial.cpp
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * WutLoggerUsbSerial.cpp
5 ***************************************************************************/
6#include "WutLoggerUsbSerial.h"
7
8#if WUT_USBSERIAL_AVAILABLE
9
10#include <usbserial/usbserial.h>
11
12// The module's Init() doesn't take a baud rate/port selector - it claims
13// whichever supported USB-to-TTL adapter is plugged in and runs it at a
14// fixed rate the module itself defines. LogConfig::serialBaudRate is kept
15// for backends against modules/adapters that do accept one; it's simply
16// unused here.
17bool WutLoggerUsbSerial::init(const LogConfig & /*config*/)
18{
19 ready = USBSerial_Init();
20 return ready;
21}
22
24{
25 if (ready)
26 {
27 USBSerial_Deinit();
28 ready = false;
29 }
30}
31
32void WutLoggerUsbSerial::write(LogLevel /*level*/, const char * line, size_t len)
33{
34 if (!ready)
35 return;
36
37 // USBSerial_Write() is documented as non-blocking - a full transfer
38 // ring simply drops the write rather than stalling the caller.
39 USBSerial_Write(line, static_cast<uint32_t>(len));
40}
41
42#else // !WUT_USBSERIAL_AVAILABLE
43
44bool WutLoggerUsbSerial::init(const LogConfig & /*config*/) { return false; }
46void WutLoggerUsbSerial::write(LogLevel /*level*/, const char * /*line*/, size_t /*len*/) { }
47
48#endif
bool init(const LogConfig &config) override
Opens whatever handle/socket/file this backend needs, using only fields from config (nothing hardcode...
void shutdown() override
Releases whatever init() acquired.
void write(LogLevel level, const char *line, size_t len) override
Writes one already-formatted, newline-terminated line.
LogLevel
Severity of a single log call.
Definition Logger.h:45
Full runtime configuration for the Logger.
Definition Logger.h:101