Files
BlindCane/Core/App/Helper/task_helper.hpp

19 lines
479 B
C++

#pragma once
#include "stm32h5xx_hal.h"
#include <cstdint>
#include <stdexcept>
class TaskHelper {
public:
template <typename Func>
static void WaitFor(Func func, int timeoutMilliseconds) {
auto start = HAL_GetTick();
while (!func()) {
uint32_t now = HAL_GetTick();
if ((now - start) > static_cast<uint32_t>(timeoutMilliseconds)) {
throw std::runtime_error("Operation timed out");
}
}
}
};