libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
OgcLoggerUsbGecko.cpp
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * OgcLoggerUsbGecko.cpp
5 ***************************************************************************/
6#include "OgcLoggerUsbGecko.h"
7#include <ogc/usbgecko.h>
8
9namespace
10{
11 constexpr uint32_t PROBE_INTERVAL_MS = 1000;
12 constexpr int GECKO_RETRY_SPINS_PER_BYTE = 64;
13}
14
15bool OgcLoggerUsbGecko::probe()
16{
17 attached = usb_isgeckoalive(channel) != 0;
18 lastProbe = SystemTime::now();
19 probed = true;
20 return attached;
21}
22
24{
25 channel = config.geckoChannel;
26 probed = false;
27 probe();
28 return true;
29}
30
32{
33 attached = false;
34 probed = false;
35}
36
37void OgcLoggerUsbGecko::write(LogLevel /*level*/, const char * line, size_t len)
38{
39 if (len == 0)
40 return;
41
42 if (!attached)
43 {
44 // Detached: re-probe at a bounded rate, drop the line otherwise.
45 if (probed && SystemTime::diffMillisecs(lastProbe, SystemTime::now()) < PROBE_INTERVAL_MS)
46 return;
47 if (!probe())
48 return;
49 }
50
51 int retries = static_cast<int>(len) * GECKO_RETRY_SPINS_PER_BYTE;
52 int sent = usb_sendbuffer_safe_ex(channel, line, static_cast<int>(len), retries);
53
54 if (sent < static_cast<int>(len))
55 {
56 // Unplugged, or the host stopped draining the Gecko's buffer.
57 // Drop the rest of this line and go back to the detached state;
58 attached = false;
59 lastProbe = SystemTime::now();
60 probed = true;
61 }
62}
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.
bool init(const LogConfig &config) override
Opens whatever handle/socket/file this backend needs, using only fields from config (nothing hardcode...
static Ticks now()
Definition Time.h:28
static uint32_t diffMillisecs(Ticks start, Ticks end)
Definition Time.h:52
LogLevel
Severity of a single log call.
Definition Logger.h:45
Full runtime configuration for the Logger.
Definition Logger.h:101
int geckoChannel
EXI channel (GC/Wii): 0 = memory card slot A, 1 = memory card slot B (where a USB Gecko is normally i...
Definition Logger.h:125