Skip to content

Commit 16520ba

Browse files
committed
fix: add file-based logging for LED diagnostics
Writes to FFBPlugin_LED.log in the game directory for easy debugging without needing DebugView.
1 parent 5a02832 commit 16520ba

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

Common Files/LogitechLED.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,23 @@ static const USHORT G29_PID = 0xC24F;
2222
static const BYTE LOGITECH_CMD_SET_LED = 0xF8;
2323
static const BYTE LOGITECH_LED_SUBCMD = 0x12;
2424

25-
// Forward declaration for logging (defined in DllMain.cpp)
26-
extern void LogMessage(const char* fmt, ...);
25+
// File-based logging for LED diagnostics
26+
static FILE* g_ledLogFile = NULL;
27+
28+
static void LEDLogInit()
29+
{
30+
if (g_ledLogFile) return;
31+
g_ledLogFile = fopen("FFBPlugin_LED.log", "w");
32+
}
2733

28-
// Simple log helper - uses OutputDebugString if LogMessage is not available
2934
static void LEDLog(const char* msg)
3035
{
36+
LEDLogInit();
37+
if (g_ledLogFile)
38+
{
39+
fprintf(g_ledLogFile, "%s\n", msg);
40+
fflush(g_ledLogFile);
41+
}
3142
OutputDebugStringA(msg);
3243
OutputDebugStringA("\n");
3344
}
@@ -46,10 +57,15 @@ LogitechLED::~LogitechLED()
4657

4758
bool LogitechLED::Init()
4859
{
60+
LEDLog("LogitechLED::Init() called");
4961
if (m_available)
5062
return true;
5163

5264
m_available = FindAndOpenDevice();
65+
if (m_available)
66+
LEDLog("LogitechLED::Init() SUCCESS - device opened");
67+
else
68+
LEDLog("LogitechLED::Init() FAILED - no compatible device found");
5369
return m_available;
5470
}
5571

@@ -91,21 +107,28 @@ bool LogitechLED::SetLEDs(BYTE ledMask)
91107
report[7] = 0x01;
92108

93109
DWORD bytesWritten = 0;
110+
char buf[256];
111+
sprintf_s(buf, "LogitechLED: SetLEDs mask=0x%02X reportLen=%u", ledMask, m_outputReportLength);
112+
LEDLog(buf);
113+
94114
BOOL result = WriteFile(m_deviceHandle, report, m_outputReportLength, &bytesWritten, NULL);
95115

96116
if (!result)
97117
{
98118
DWORD err = GetLastError();
99-
char buf[256];
100-
sprintf_s(buf, "LogitechLED: WriteFile failed, error=%lu, reportLen=%u, mask=0x%02X",
101-
err, m_outputReportLength, ledMask);
119+
sprintf_s(buf, "LogitechLED: WriteFile FAILED, error=%lu", err);
102120
LEDLog(buf);
103121

104122
if (err == ERROR_DEVICE_NOT_CONNECTED || err == ERROR_GEN_FAILURE)
105123
{
106124
Close();
107125
}
108126
}
127+
else
128+
{
129+
sprintf_s(buf, "LogitechLED: WriteFile OK, bytesWritten=%lu", bytesWritten);
130+
LEDLog(buf);
131+
}
109132

110133
free(report);
111134
return result == TRUE;

0 commit comments

Comments
 (0)