generated from Template/H563ZI-HAL-CMake-Template
新增 Ultrasonic 类和 TaskHelper 类,提供超声波测距功能及任务等待辅助方法
This commit is contained in:
19
Core/App/Helper/task_helper.hpp
Normal file
19
Core/App/Helper/task_helper.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#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");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user