Skip to content

Commit bdd141f

Browse files
authored
Fix sleep time, add time to debug log, cleaner RPM display (#1)
Fix sleep time, add time to debug log, cleaner RPM display
2 parents 143fb77 + 0117016 commit bdd141f

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

FanControl++.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static BOOL Cleanup(HWND& hWnd, NOTIFYICONDATAW& nid) {
172172
}
173173

174174
static BOOL MainThread(HWND hWnd) noexcept(false) {
175-
ULONGLONG last_update_thread = 0;
175+
ULONGLONG next_time = GetTickCount64();
176176
while (!thread_term) {
177177
if (asus_control.error_occured) {
178178
_dErr(_ts(L"[Thread] Error occured!"));
@@ -196,15 +196,14 @@ static BOOL MainThread(HWND hWnd) noexcept(false) {
196196

197197
if (current_settings_hwnd) {
198198
std::wstring tool_tip = _ts(L"CPU: ") + _ts(asus_control.current_cpu_thermal) + _ts(L"°C | GPU: ") + _ts(asus_control.current_gpu_thermal) + _ts(L"°C\n")
199-
+ _ts(L"Fan: ") + _ts(asus_control.get_fan_speed()) + _ts(L"RPM (") + _ts(asus_control.current_fan_percent) + _ts(L"%)");
199+
+ _ts(L"Fan: ") + _ts(asus_control.get_fan_speed()) + _ts(L" RPM (") + _ts(asus_control.current_fan_percent) + _ts(L"%)");
200200
SetWindowTextW(GetDlgItem(current_settings_hwnd, IDC_STATIC_INFO), tool_tip.c_str());
201201
}
202202

203-
SYSTEMTIME st;
204-
GetSystemTime(&st);
205-
ULONGLONG time_taken = convert_to_ull(st) - last_update_thread;
206-
if (time_taken < update_interval) {
207-
Sleep(update_interval - time_taken); // sleep until next update
203+
next_time += update_interval;
204+
LONGLONG sleep_time = next_time - GetTickCount64();
205+
if (sleep_time > 0) {
206+
Sleep(sleep_time); // sleep until next update
208207
}
209208
}
210209

tray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ BOOL UpdateTray(HWND hWnd, NOTIFYICONDATAW & nid, AsusDLL & asus_control, int& c
262262

263263
std::wstring tool_tip = _ts(L"Currently ") + (asus_control.current_fan_test_mode ? _ts(L"enabled!") : _ts(L"disabled!"));
264264
tool_tip += _ts(L"\nCPU: ") + _ts(asus_control.current_cpu_thermal) + _ts(L"°C | GPU: ") + _ts(asus_control.current_gpu_thermal) + _ts(L"°C\n")
265-
+ _ts(L"Fan: ") + _ts(asus_control.get_fan_speed()) + _ts(L"RPM (") + _ts(asus_control.current_fan_percent) + _ts(L"%)");
265+
+ _ts(L"Fan: ") + _ts(asus_control.get_fan_speed()) + _ts(L" RPM (") + _ts(asus_control.current_fan_percent) + _ts(L"%)");
266266
ZeroMemory(&nid.szTip, sizeof(nid.szTip)); // clear the string
267267
wmemcpy_s(nid.szTip, 128, tool_tip.c_str(), tool_tip.length());
268268

utils.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
#ifdef _DEBUG
66
void _dInfo(const wchar_t str[]) {
7-
const std::wstring new_str(str);
8-
OutputDebugString((L"[Info] " + new_str + L"\n").c_str());
7+
_dInfo(std::wstring(str));
98
}
109
void _dInfo(const std::wstring str) {
11-
OutputDebugString((L"[Info] " + str + L"\n").c_str());
10+
OutputDebugString((_time_str() + L" [Info] " + str + L"\n").c_str());
1211
}
1312
void _dErr(const wchar_t str[]) {
14-
const std::wstring new_str(str);
15-
OutputDebugString((L"[ERROR] " + new_str + L"\n").c_str());
13+
_dErr(std::wstring(str));
1614
}
1715
void _dErr(const std::wstring str) {
18-
OutputDebugString((L"[ERROR] " + str + L"\n").c_str());
16+
OutputDebugString((_time_str() + L" [ERROR] " + str + L"\n").c_str());
1917
}
2018
#else
2119
void _dInfo(const wchar_t str[]) {}
@@ -55,4 +53,15 @@ ULONGLONG convert_to_ull(SYSTEMTIME& st)
5553
// convert ul to milliseconds
5654
ul.QuadPart /= 10000;
5755
return ul.QuadPart;
56+
}
57+
58+
std::wstring _time_str(SYSTEMTIME st) {
59+
if (st.wYear == 0) {
60+
// If no time has been transmitted, we use the current time
61+
GetSystemTime(&st);
62+
}
63+
64+
wchar_t buffer[24];
65+
swprintf(buffer, 24, L"%04d-%02d-%02d %02d:%02d:%02d.%03d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
66+
return std::wstring(buffer);
5867
}

utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ std::wstring _ts(const wchar_t str[]);
1717
std::wstring _ts(const std::vector<int>& vt);
1818

1919
ULONGLONG convert_to_ull(SYSTEMTIME& st);
20+
std::wstring _time_str(SYSTEMTIME st = {});
2021

2122
#define WM_USER_SHELLICON WM_USER + 1
2223
#define WM_TASKBAR_CREATE RegisterWindowMessage(_T("TaskbarCreated"))

0 commit comments

Comments
 (0)