diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index df9bb4a8b7..bc8b637e3e 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -10,6 +10,11 @@ #include #include +#ifdef _WIN32 +#include +#pragma comment(lib, "Winmm.lib") +#endif // _WIN32 + #include "ErrorsInternal.h" #include "HALInitializer.h" #include "MockHooksInternal.h" @@ -285,6 +290,23 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) { HAL_InitializeDriverStation(); initialized = true; + +// Set Timer Precision to 1ms on Windows +#ifdef _WIN32 + TIMECAPS tc; + if (timeGetDevCaps(&tc, sizeof(tc)) == TIMERR_NOERROR) { + UINT target = min(1, tc.wPeriodMin); + timeBeginPeriod(target); + std::atexit([]() { + TIMECAPS tc; + if (timeGetDevCaps(&tc, sizeof(tc)) == TIMERR_NOERROR) { + UINT target = min(1, tc.wPeriodMin); + timeEndPeriod(target); + } + }); + } +#endif // _WIN32 + return true; // Add initialization if we need to at a later point }