summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-11-22 03:39:50 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2025-11-23 02:06:39 -0600
commitf9a5051bae25fd298aafb020224f2ced174d47fb (patch)
tree541eb29a38dcc6f828b3cf8961838e13cc47fe61 /Source/Core/InputCommon
parent30dbcb2f808093ed93107297b4e76c27687cef84 (diff)
GCAdapter: Calculate poll rate for display in UI. It's currently updated every 50 reads.
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/GCAdapter.cpp27
-rw-r--r--Source/Core/InputCommon/GCAdapter.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp
index df212e8f4e..5ec245a56d 100644
--- a/Source/Core/InputCommon/GCAdapter.cpp
+++ b/Source/Core/InputCommon/GCAdapter.cpp
@@ -163,6 +163,8 @@ static std::optional<Config::ConfigChangedCallbackID> s_config_callback_id = std
static bool s_is_adapter_wanted = false;
static std::array<bool, SerialInterface::MAX_SI_CHANNELS> s_config_rumble_enabled{};
+static std::atomic<double> s_adapter_poll_rate{};
+
static void ReadThreadFunc()
{
Common::SetCurrentThreadName("GCAdapter Read Thread");
@@ -199,6 +201,11 @@ static void ReadThreadFunc()
// Reset rumble once on initial reading
ResetRumble();
+ // Measure poll rate for display in UI.
+ constexpr int POLL_RATE_MEASUREMENT_SAMPLE_COUNT = 50;
+ auto poll_rate_measurement_start_time = Clock::now();
+ int poll_rate_measurement_count = 0;
+
while (s_read_adapter_thread_running.IsSet())
{
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
@@ -242,6 +249,19 @@ static void ReadThreadFunc()
}
#endif
+ // Update poll rate measurement.
+ if (++poll_rate_measurement_count == POLL_RATE_MEASUREMENT_SAMPLE_COUNT)
+ {
+ const auto now = Clock::now();
+
+ const auto poll_rate =
+ POLL_RATE_MEASUREMENT_SAMPLE_COUNT / DT_s(now - poll_rate_measurement_start_time).count();
+ s_adapter_poll_rate.store(poll_rate, std::memory_order_relaxed);
+
+ poll_rate_measurement_start_time = now;
+ poll_rate_measurement_count = 0;
+ }
+
Common::YieldCPU();
}
@@ -259,6 +279,8 @@ static void ReadThreadFunc()
s_detected = false;
#endif
+ s_adapter_poll_rate.store(0.0, std::memory_order_relaxed);
+
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GCAdapter read thread stopped");
}
@@ -1013,4 +1035,9 @@ bool IsDetected(const char** error_message)
#endif
}
+double GetCurrentPollRate()
+{
+ return s_adapter_poll_rate.load(std::memory_order_relaxed);
+}
+
} // namespace GCAdapter
diff --git a/Source/Core/InputCommon/GCAdapter.h b/Source/Core/InputCommon/GCAdapter.h
index e6f62e035b..50e24ae940 100644
--- a/Source/Core/InputCommon/GCAdapter.h
+++ b/Source/Core/InputCommon/GCAdapter.h
@@ -28,4 +28,7 @@ bool DeviceConnected(int chan);
void ResetDeviceType(int chan);
bool UseAdapter();
+// Callable from any thread. Returns 0 when the adapter is not detected.
+double GetCurrentPollRate();
+
} // namespace GCAdapter