generated from Template/H563ZI-HAL-CMake-Template
新增 DfPlayer 和 CanMv 类,优化 UART 读写方法,更新 CommonCenter 以支持新类实例化
Some checks failed
Build and Upload Artifact / build and upload-artifact (push) Has been cancelled
Some checks failed
Build and Upload Artifact / build and upload-artifact (push) Has been cancelled
This commit is contained in:
@@ -29,7 +29,10 @@ public:
|
||||
char c;
|
||||
ReadByte();
|
||||
while (true) {
|
||||
HAL_UART_Receive(handle, reinterpret_cast<uint8_t*>(&c), sizeof(c), HAL_MAX_DELAY);
|
||||
auto r = HAL_UART_Receive(handle, reinterpret_cast<uint8_t*>(&c), sizeof(c), timeout);
|
||||
if (r != HAL_OK) {
|
||||
throw std::runtime_error("UART receive error");
|
||||
}
|
||||
if (c == '\n') {
|
||||
if (!result.empty() && result.back() == '\r') {
|
||||
result.pop_back();
|
||||
@@ -41,6 +44,13 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
void ReadBytesBlocking(uint8_t* data, size_t size) {
|
||||
auto r = HAL_UART_Receive(handle, data, size, timeout);
|
||||
if (r != HAL_OK) {
|
||||
throw std::runtime_error("UART receive error");
|
||||
}
|
||||
}
|
||||
|
||||
void WriteBytesBlocking(const uint8_t* data, size_t size) {
|
||||
HAL_UART_Transmit(handle, const_cast<uint8_t*>(data), size, timeout);
|
||||
}
|
||||
@@ -56,7 +66,7 @@ public:
|
||||
}
|
||||
HAL_UART_Transmit(handle, reinterpret_cast<uint8_t*>(buffer.get()), strlen(buffer.get()), timeout);
|
||||
}
|
||||
|
||||
|
||||
void WriteLineBlocking(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
Reference in New Issue
Block a user