Skip to content

Commit

Permalink
🐛 Remove HAL_CHECK from serial_coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
kammce committed Mar 7, 2024
1 parent 5392fbe commit 5d4f3ea
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/4.0.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 🚀 4.0.1

on:
workflow_dispatch:

jobs:
deploy:
uses: libhal/ci/.github/workflows/[email protected]
with:
version: 4.0.1
secrets: inherit
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions include/libhal-util/as_bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ constexpr std::span<const hal::byte> as_bytes(const T* p_address,
return std::span<const hal::byte>(start, number_of_bytes);
}

// Turning off clang-format because concepts because give it an aneurysm.
// clang-format off
template<typename T>
concept convertible_to_bytes = requires(T a) {
*a.data();
a.size();
};
// clang-format on

constexpr std::span<hal::byte> as_writable_bytes(
convertible_to_bytes auto& p_container)
Expand Down
8 changes: 4 additions & 4 deletions include/libhal-util/serial_coroutines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ class skip_past
*
* Call this function again to resume reading from the port.
*
* @return result<work_state> - 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> - work_state::finished if the sequence was
* @return work_state::finished - if the sequence was
* found before the buffer was filled completely.
*/
result<work_state> operator()()
work_state operator()()
{
if (m_search_index == m_sequence.size()) {
return work_state::finished;
}

for (size_t read_limit = 0; read_limit < m_read_limit; read_limit++) {
std::array<hal::byte, 1> 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;
Expand Down
3 changes: 1 addition & 2 deletions include/libhal-util/steady_clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ void delay(hal::steady_clock& p_steady_clock, hal::time_duration p_duration);
*/
inline auto timeout_generator(hal::steady_clock& p_steady_clock)
{
return [&p_steady_clock](hal::time_duration p_duration) -> auto
{
return [&p_steady_clock](hal::time_duration p_duration) {
return create_timeout(p_steady_clock, p_duration);
};
}
Expand Down
4 changes: 3 additions & 1 deletion include/libhal-util/timeout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
concept has_work_state = requires(T a) {
{
a.state()
} -> std::same_as<work_state>;
};
// clang-format on

constexpr bool terminated(has_work_state auto p_worker)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/serial_coroutines.test.cpp
Original file line number Diff line number Diff line change
@@ -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 <libhal-util/serial_coroutines.hpp>
3 changes: 1 addition & 2 deletions tests/static_list.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ void static_list_test()

"static_list::dtor() handles dandling list items"_test = []() {
// Setup
auto destroy_list_keep_items = []() -> auto
{
auto destroy_list_keep_items = []() {
static_list<int> list;

return std::array<static_list<int>::item, 5>{
Expand Down

0 comments on commit 5d4f3ea

Please sign in to comment.