From a129659bde2520b6f7eecc51873cacb7fbf748c8 Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Thu, 7 Mar 2024 10:22:04 -0800 Subject: [PATCH] :bug: Remove HAL_CHECK from serial_coroutines --- .github/workflows/4.0.1.yml | 11 +++++++++++ CMakeLists.txt | 1 + include/libhal-util/as_bytes.hpp | 3 +++ include/libhal-util/serial_coroutines.hpp | 8 ++++---- include/libhal-util/timeout.hpp | 4 +++- tests/serial_coroutines.test.cpp | 15 +++++++++++++++ 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/4.0.1.yml create mode 100644 tests/serial_coroutines.test.cpp diff --git a/.github/workflows/4.0.1.yml b/.github/workflows/4.0.1.yml new file mode 100644 index 0000000..f185668 --- /dev/null +++ b/.github/workflows/4.0.1.yml @@ -0,0 +1,11 @@ +name: 🚀 4.0.1 + +on: + workflow_dispatch: + +jobs: + deploy: + uses: libhal/ci/.github/workflows/deploy_all.yml@5.x.y + with: + version: 4.0.1 + secrets: inherit diff --git a/CMakeLists.txt b/CMakeLists.txt index e86f8d2..44f9850 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ libhal_test_and_make_library( tests/serial.test.cpp tests/spi.test.cpp tests/static_callable.test.cpp + tests/serial_coroutines.test.cpp tests/static_list.test.cpp tests/steady_clock.test.cpp tests/streams.test.cpp diff --git a/include/libhal-util/as_bytes.hpp b/include/libhal-util/as_bytes.hpp index 76b8450..c0b90cb 100644 --- a/include/libhal-util/as_bytes.hpp +++ b/include/libhal-util/as_bytes.hpp @@ -49,11 +49,14 @@ constexpr std::span as_bytes(const T* p_address, return std::span(start, number_of_bytes); } +// Turning off clang-format because concepts because give it an aneurysm. +// clang-format off template concept convertible_to_bytes = requires(T a) { *a.data(); a.size(); }; +// clang-format on constexpr std::span as_writable_bytes( convertible_to_bytes auto& p_container) diff --git a/include/libhal-util/serial_coroutines.hpp b/include/libhal-util/serial_coroutines.hpp index a65e3e9..9907a18 100644 --- a/include/libhal-util/serial_coroutines.hpp +++ b/include/libhal-util/serial_coroutines.hpp @@ -73,12 +73,12 @@ class skip_past * * Call this function again to resume reading from the port. * - * @return result - work_state::in_progress if the sequence hasn't + * @return work_state::in_progress - if the sequence hasn't * been met and the buffer still has space. - * @return result - work_state::finished if the sequence was + * @return work_state::finished - if the sequence was * found before the buffer was filled completely. */ - result operator()() + work_state operator()() { if (m_search_index == m_sequence.size()) { return work_state::finished; @@ -86,7 +86,7 @@ class skip_past for (size_t read_limit = 0; read_limit < m_read_limit; read_limit++) { std::array buffer; - auto read_result = HAL_CHECK(m_serial->read(buffer)); + auto read_result = m_serial->read(buffer); if (read_result.data.size() != buffer.size()) { return work_state::in_progress; diff --git a/include/libhal-util/timeout.hpp b/include/libhal-util/timeout.hpp index 8648d2a..4e89fcb 100644 --- a/include/libhal-util/timeout.hpp +++ b/include/libhal-util/timeout.hpp @@ -63,13 +63,15 @@ constexpr bool failed(work_state p_state) { return p_state == work_state::failed; } - +// Turning off clang-format because concepts because give it an aneurysm. +// clang-format off template concept has_work_state = requires(T a) { { a.state() } -> std::same_as; }; +// clang-format on constexpr bool terminated(has_work_state auto p_worker) { diff --git a/tests/serial_coroutines.test.cpp b/tests/serial_coroutines.test.cpp new file mode 100644 index 0000000..96c2a41 --- /dev/null +++ b/tests/serial_coroutines.test.cpp @@ -0,0 +1,15 @@ +// Copyright 2024 Khalil Estell +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include \ No newline at end of file