diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 80ccb6c9..4de7e25e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,10 +29,7 @@ jobs: python-version: '3.8' - name: Install conan - uses: BSFishy/pip-action@v1 - with: - packages: | - conan + run: pip install "conan<2.0" pytest && conan --version #Install the latest cmake - name : Get the latest CMake version @@ -40,7 +37,7 @@ jobs: - name: Run build for MSVC compiler run: | - cmake -G"Visual Studio 16 2019" -Ax64 -S"${{ github.workspace }}/Firmware/" -B"${{ env.buildDir }}" -DPACKAGE_TESTS=ON -DTARGET_PLATFORM:STRING="FIRMWARE_SIMULATOR" -DCMAKE_BUILD_TYPE=Release + cmake -G"Visual Studio 17 2022" -Ax64 -S"${{ github.workspace }}/Firmware/" -B"${{ env.buildDir }}" -DPACKAGE_TESTS=ON -DTARGET_PLATFORM:STRING="FIRMWARE_SIMULATOR" -DCMAKE_BUILD_TYPE=Release cd ${{ env.buildDir }} cmake --build . --config Release - name : Run firmware testing @@ -140,10 +137,7 @@ jobs: python-version: '3.8' - name: Install conan - uses: BSFishy/pip-action@v1 - with: - packages: | - conan + run: pip install "conan<2.0" pytest && conan --version - name: Intall system required packages run: | diff --git a/Firmware/CMakeLists.txt b/Firmware/CMakeLists.txt index 8fae51f7..fa2d5a0e 100644 --- a/Firmware/CMakeLists.txt +++ b/Firmware/CMakeLists.txt @@ -31,11 +31,10 @@ if( ${TARGET_PLATFORM} STREQUAL "ARM_CORTEX" ) elseif(${TARGET_PLATFORM} STREQUAL "FIRMWARE_SIMULATOR") if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") - message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") - file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.16.1/conan.cmake" - "${CMAKE_BINARY_DIR}/conan.cmake" - EXPECTED_HASH SHA256=396e16d0f5eabdc6a14afddbcfff62a54a7ee75c6da23f32f7a31bc85db23484 - TLS_VERIFY ON) + message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") + file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake" + TLS_VERIFY ON) endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) diff --git a/Firmware/drivers/board/watchboard.cpp b/Firmware/drivers/board/watchboard.cpp index 5817185e..c327767a 100644 --- a/Firmware/drivers/board/watchboard.cpp +++ b/Firmware/drivers/board/watchboard.cpp @@ -21,7 +21,7 @@ APP_TIMER_DEF(m_ledDriverTimer); #include "delay/delay_provider.hpp" #include "logger/logger_service.hpp" -#if defined (USE_DEVICE_SPECIFIC) +#if defined(USE_DEVICE_SPECIFIC) #define FMT_HEADER_ONLY #endif @@ -32,7 +32,7 @@ namespace { static void TimerExpiredCallback(void* _pExpiredContext) noexcept { - std::coroutine_handle<>::from_address(_pExpiredContext).resume(); + stdcoro::coroutine_handle<>::from_address(_pExpiredContext).resume(); } } // namespace @@ -65,7 +65,7 @@ auto operator co_await(std::chrono::milliseconds _duration) app_timer_stop(m_ledDriverTimer); } #else - bool await_suspend(std::coroutine_handle<> _coroLedHandle) noexcept + bool await_suspend(stdcoro::coroutine_handle<> _coroLedHandle) noexcept { return false; } diff --git a/Firmware/drivers/display/inc/display/display_coro_compact_gc9a01.hpp b/Firmware/drivers/display/inc/display/display_coro_compact_gc9a01.hpp index ebf1f8d1..e96c994e 100644 --- a/Firmware/drivers/display/inc/display/display_coro_compact_gc9a01.hpp +++ b/Firmware/drivers/display/inc/display/display_coro_compact_gc9a01.hpp @@ -123,7 +123,7 @@ class GC9A01Compact std::uint16_t _y, std::uint16_t _width, std::uint16_t _height, - TBaseSpiDisplay::TColor* _colorToFill) noexcept + typename TBaseSpiDisplay::TColor* _colorToFill) noexcept { const std::uint16_t DisplayHeight = TBaseSpiDisplay::getHeight(); @@ -140,8 +140,8 @@ class GC9A01Compact const size_t BytesSizeX = (_width - _x + 1); const size_t BytesSizeY = (_height - _y + 1); const size_t BytesSquare = BytesSizeX * BytesSizeY; - const size_t TransferBufferSize - = (BytesSquare * sizeof(typename TBaseSpiDisplay::TColor)); + const size_t TransferBufferSize = + (BytesSquare * sizeof(typename TBaseSpiDisplay::TColor)); co_await TBaseSpiDisplay::m_displayInitialized; diff --git a/Firmware/drivers/display/inc/display/display_spi_common_coro.hpp b/Firmware/drivers/display/inc/display/display_spi_common_coro.hpp index 5cac0fd8..a5544517 100644 --- a/Firmware/drivers/display/inc/display/display_spi_common_coro.hpp +++ b/Firmware/drivers/display/inc/display/display_spi_common_coro.hpp @@ -77,7 +77,7 @@ class BaseSpiDisplayCoroutine if (resetDcPin) pBaseDisplay->setDcPin(); } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { if (resetDcPin) pBaseDisplay->resetDcPin(); diff --git a/Firmware/drivers/spi/inc/backends/spi_backend_desktop.hpp b/Firmware/drivers/spi/inc/backends/spi_backend_desktop.hpp index 45b922bb..8cf85b7f 100644 --- a/Firmware/drivers/spi/inc/backends/spi_backend_desktop.hpp +++ b/Firmware/drivers/spi/inc/backends/spi_backend_desktop.hpp @@ -5,14 +5,14 @@ #include #include #include +#include #include #include #include #include +#include #include #include -#include -#include #include @@ -33,14 +33,14 @@ class SpiBusDesktopBackend { #ifdef USE_THREADING_ASYNC_BACKEND - m_dmaThread = std::make_unique([this]()mutable { + m_dmaThread = std::make_unique([this]() mutable { while (m_processSpiTransactions) { if (m_newDataArrived) { using namespace std::chrono_literals; - std::unique_lock(m_transactionBufferGuard); + std::unique_lock transactionWrap(m_transactionBufferGuard); fmt::print("[Desktop SPI simultator]{}\n", m_dataBuffer); m_newDataArrived.store(false); @@ -59,7 +59,6 @@ class SpiBusDesktopBackend } public: - void setCsPinHigh() noexcept { } @@ -74,7 +73,7 @@ class SpiBusDesktopBackend m_dataBuffer.clear(); m_dataBuffer.reserve(_bufferSize); - std::unique_lock(m_transactionBufferGuard); + std::unique_lock transactionWrap(m_transactionBufferGuard); std::copy(_pBuffer, _pBuffer + _bufferSize, std::back_inserter(m_dataBuffer)); m_newDataArrived.store(true, std::memory_order_release); diff --git a/Firmware/drivers/spi/inc/spi/spi_wrapper_async_templated.hpp b/Firmware/drivers/spi/inc/spi/spi_wrapper_async_templated.hpp index 6db3c4b2..a708d4fa 100644 --- a/Firmware/drivers/spi/inc/spi/spi_wrapper_async_templated.hpp +++ b/Firmware/drivers/spi/inc/spi/spi_wrapper_async_templated.hpp @@ -1,11 +1,11 @@ #pragma once #include -#include #include #include #include #include +#include #include #include @@ -48,7 +48,7 @@ template class SpiBus : private Utils::noncopyable { m_backendImpl.setTransactionCompletedHandler([this] { transmitCompleted(); }); - m_coroHandle = std::coroutine_handle<>::from_address(_pUserData); + m_coroHandle = stdcoro::coroutine_handle<>::from_address(_pUserData); TransactionContext newContext{ .restoreInSpiCtx = _restoreInSpiCtx, @@ -68,7 +68,7 @@ template class SpiBus : private Utils::noncopyable void* _pUserData, bool _restoreInSpiCtx) noexcept { - m_coroHandle = std::coroutine_handle<>::from_address(_pUserData); + m_coroHandle = stdcoro::coroutine_handle<>::from_address(_pUserData); m_backendImpl.setTransactionCompletedHandler([this] { transmitCompleted(); }); const size_t TransferBufferSize = _pBuffer.size(); @@ -97,8 +97,8 @@ template class SpiBus : private Utils::noncopyable m_backendImpl.sendChunk(_pBuffer.data(), _pBuffer.size()); } } -public: +public: void setCsPinHigh() noexcept { getBackendImpl().setCsPinHigh(); @@ -168,7 +168,7 @@ template class SpiBus : private Utils::noncopyable private: SpiBackendImpl m_backendImpl; - std::coroutine_handle<> m_coroHandle; + stdcoro::coroutine_handle<> m_coroHandle; struct TransactionContext { diff --git a/Firmware/drivers/winbondflash/inc/windbondflash/winbond_flash_templated.hpp b/Firmware/drivers/winbondflash/inc/windbondflash/winbond_flash_templated.hpp index db92b31a..27cb466d 100644 --- a/Firmware/drivers/winbondflash/inc/windbondflash/winbond_flash_templated.hpp +++ b/Firmware/drivers/winbondflash/inc/windbondflash/winbond_flash_templated.hpp @@ -250,7 +250,7 @@ template class WinbondFlashDriver void await_resume() const noexcept { } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { pThis->getSpiBus()->xferBuffer( pTransmitBuffer, pReceiveBuffer, thisCoroutine.address(), restoreInSpiCtx); @@ -271,7 +271,7 @@ template class WinbondFlashDriver void await_resume() const noexcept { } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { pThis->getSpiBus()->transmitBuffer( pTransmitBuffer, diff --git a/Firmware/firmware_tests/article_example/coroutine_utils.hpp b/Firmware/firmware_tests/article_example/coroutine_utils.hpp index 57334928..4e248fa3 100644 --- a/Firmware/firmware_tests/article_example/coroutine_utils.hpp +++ b/Firmware/firmware_tests/article_example/coroutine_utils.hpp @@ -1,7 +1,18 @@ #pragma once #include #include + +#ifdef _MSC_VER +#include +namespace stdcoro = std; +#elif defined(__GNUC__) && !defined(__clang__) #include +namespace stdcoro = std; +#else +#include +namespace stdcoro = std::experimental::coroutines_v1; +#endif + #include #include #include @@ -11,11 +22,11 @@ struct Promise { auto initial_suspend() noexcept { - return std::suspend_never{}; + return stdcoro::suspend_never{}; } auto final_suspend() noexcept { - return std::suspend_never{}; + return stdcoro::suspend_never{}; } void get_return_object() @@ -33,7 +44,7 @@ struct Promise } }; -template struct std::coroutine_traits +template struct stdcoro::coroutine_traits { using promise_type = Promise; }; @@ -79,7 +90,7 @@ template struct SyncWaitTask using promise_type = SyncTaskPromise; using TResultRef = TResultType&&; - SyncWaitTask(std::coroutine_handle _suspendedRoutine) + SyncWaitTask(stdcoro::coroutine_handle _suspendedRoutine) : m_suspendedRoutine{_suspendedRoutine} { } @@ -96,10 +107,10 @@ template struct SyncWaitTask return false; } template - void await_suspend(std::coroutine_handle coroutine) noexcept + void await_suspend(stdcoro::coroutine_handle coroutine) noexcept { - // ïî îêîí÷àíèþ ðàáîòû ñîïðîãðàììû óñòàíàâëèâàåì blockingEvent â set, òåì ñàìûì - // âîññòàíàâëèâàÿ òåêóùèé ïîòîê âûïîëíåíèÿ + // �� ��������� ������ ����������� ������������� blockingEvent � set, ��� ����� + // �������������� ������� ����� ���������� SyncTaskPromise& promise = coroutine.promise(); promise.m_event->set(); } @@ -113,16 +124,16 @@ template struct SyncWaitTask auto get_return_object() noexcept { - return SyncWaitTask{std::coroutine_handle::from_promise(*this)}; + return SyncWaitTask{stdcoro::coroutine_handle::from_promise(*this)}; } void start(BlockingEvent* _pEvent) noexcept { m_event = _pEvent; - std::coroutine_handle::from_promise(*this).resume(); + stdcoro::coroutine_handle::from_promise(*this).resume(); } auto initial_suspend() noexcept { - return std::suspend_always{}; + return stdcoro::suspend_always{}; } auto final_suspend() noexcept @@ -132,7 +143,7 @@ template struct SyncWaitTask auto yield_value(TResultRef result) noexcept { - // äëÿ ïîääåðæêè operator co_yield + // ��� ��������� operator co_yield m_value = std::addressof(result); return final_suspend(); } @@ -168,7 +179,7 @@ template struct SyncWaitTask { m_suspendedRoutine.promise().start(&_event); } - std::coroutine_handle m_suspendedRoutine; + stdcoro::coroutine_handle m_suspendedRoutine; }; template < @@ -196,11 +207,11 @@ template struct Task } Task get_return_object() noexcept { - return Task{std::coroutine_handle::from_promise(*this)}; + return Task{stdcoro::coroutine_handle::from_promise(*this)}; } auto initial_suspend() noexcept { - return std::suspend_always{}; + return stdcoro::suspend_always{}; } void return_value(const TResult& _value) noexcept @@ -208,7 +219,7 @@ template struct Task m_coroutineResult = _value; } - void set_continuation(std::coroutine_handle<> continuation) + void set_continuation(stdcoro::coroutine_handle<> continuation) { m_continuation = continuation; } @@ -225,7 +236,7 @@ template struct Task return false; } template - void await_suspend(std::coroutine_handle coroutine) noexcept + void await_suspend(stdcoro::coroutine_handle coroutine) noexcept { ResultTaskPromise& promise = coroutine.promise(); if (promise.m_continuation) @@ -245,19 +256,19 @@ template struct Task } TResult m_coroutineResult; - std::coroutine_handle<> m_continuation; + stdcoro::coroutine_handle<> m_continuation; }; struct task_awaitable { - task_awaitable(std::coroutine_handle coroutine) : m_coroutine{coroutine} + task_awaitable(stdcoro::coroutine_handle coroutine) : m_coroutine{coroutine} { } bool await_ready() const noexcept { return !m_coroutine || m_coroutine.done(); } - void await_suspend(std::coroutine_handle<> awaitingRoutine) + void await_suspend(stdcoro::coroutine_handle<> awaitingRoutine) { m_coroutine.promise().set_continuation(awaitingRoutine); m_coroutine.resume(); @@ -268,10 +279,10 @@ template struct Task return m_coroutine.promise().result(); } - std::coroutine_handle m_coroutine; + stdcoro::coroutine_handle m_coroutine; }; - Task(std::coroutine_handle suspendedCoroutine) + Task(stdcoro::coroutine_handle suspendedCoroutine) : m_coroutine{suspendedCoroutine} { } @@ -296,7 +307,7 @@ template struct Task { } - std::coroutine_handle m_coroutine; + stdcoro::coroutine_handle m_coroutine; }; struct VoidTask @@ -318,12 +329,12 @@ struct VoidTask } VoidTask get_return_object() noexcept { - return VoidTask{std::coroutine_handle::from_promise(*this)}; + return VoidTask{stdcoro::coroutine_handle::from_promise(*this)}; } auto initial_suspend() noexcept { - return std::suspend_always{}; + return stdcoro::suspend_always{}; } struct final_awaitable @@ -333,7 +344,7 @@ struct VoidTask return false; } template - void await_suspend(std::coroutine_handle coroutine) noexcept + void await_suspend(stdcoro::coroutine_handle coroutine) noexcept { task_promise& promise = coroutine.promise(); if (promise.m_continuation) @@ -347,7 +358,7 @@ struct VoidTask } }; - void set_continuation(std::coroutine_handle<> continuation) + void set_continuation(stdcoro::coroutine_handle<> continuation) { m_continuation = continuation; } @@ -357,19 +368,19 @@ struct VoidTask return final_awaitable{}; } - std::coroutine_handle<> m_continuation; + stdcoro::coroutine_handle<> m_continuation; }; struct task_awaitable { - task_awaitable(std::coroutine_handle coroutine) : m_coroutine{coroutine} + task_awaitable(stdcoro::coroutine_handle coroutine) : m_coroutine{coroutine} { } bool await_ready() const noexcept { return !m_coroutine || m_coroutine.done(); } - void await_suspend(std::coroutine_handle<> awaitingRoutine) + void await_suspend(stdcoro::coroutine_handle<> awaitingRoutine) { m_coroutine.resume(); m_coroutine.promise().set_continuation(awaitingRoutine); @@ -379,10 +390,10 @@ struct VoidTask { } - std::coroutine_handle m_coroutine; + stdcoro::coroutine_handle m_coroutine; }; - VoidTask(std::coroutine_handle suspendedCoroutine) + VoidTask(stdcoro::coroutine_handle suspendedCoroutine) : m_coroutine{suspendedCoroutine} { } @@ -407,7 +418,7 @@ struct VoidTask { } - std::coroutine_handle m_coroutine; + stdcoro::coroutine_handle m_coroutine; }; template @@ -430,7 +441,7 @@ struct CoroQueueMainLoop return instance; } - void pushToLater(std::coroutine_handle<> coroHandle) + void pushToLater(stdcoro::coroutine_handle<> coroHandle) { executionQueue.push(coroHandle); } @@ -440,7 +451,7 @@ struct CoroQueueMainLoop while (!executionQueue.empty()) { - std::coroutine_handle<> coroHandle = executionQueue.front(); + stdcoro::coroutine_handle<> coroHandle = executionQueue.front(); if (!coroHandle.done()) { executionQueue.pop(); @@ -449,7 +460,7 @@ struct CoroQueueMainLoop } } - std::queue> executionQueue; + std::queue> executionQueue; }; template struct WhenAllSequence @@ -469,7 +480,7 @@ template struct WhenAllSequence return false; } - void await_suspend(std::coroutine_handle<> handle) noexcept + void await_suspend(stdcoro::coroutine_handle<> handle) noexcept { co_await launchAll(std::make_integer_sequence{}); handle.resume(); @@ -502,7 +513,7 @@ struct Event return m_isSet; } - void await_suspend(std::coroutine_handle<> handle) + void await_suspend(stdcoro::coroutine_handle<> handle) { m_continuation = handle; } @@ -533,7 +544,7 @@ struct Event } std::atomic_bool m_isSet; - std::coroutine_handle<> m_continuation; + stdcoro::coroutine_handle<> m_continuation; }; }; // namespace CoroUtils diff --git a/Firmware/firmware_tests/article_example/display_common_coroutine.hpp b/Firmware/firmware_tests/article_example/display_common_coroutine.hpp index 561f6736..5d6949d4 100644 --- a/Firmware/firmware_tests/article_example/display_common_coroutine.hpp +++ b/Firmware/firmware_tests/article_example/display_common_coroutine.hpp @@ -74,7 +74,7 @@ class BaseSpiDisplayCoroutine if (resetDcPin) pBaseDisplay->setDcPin(); } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { if (resetDcPin) pBaseDisplay->resetDcPin(); @@ -87,19 +87,13 @@ class BaseSpiDisplayCoroutine auto sendCommandImpl(const std::uint8_t* _command) noexcept { return Awaiter{ - .resetDcPin = true, - .pTransmitBuffer = _command, - .pBaseDisplay = this, - .bufferSize = 1}; + .resetDcPin = true, .pTransmitBuffer = _command, .pBaseDisplay = this, .bufferSize = 1}; } auto sendCommandImplFast(const std::uint8_t* _command) noexcept { return Awaiter{ - .resetDcPin = true, - .pTransmitBuffer = _command, - .pBaseDisplay = this, - .bufferSize = 1}; + .resetDcPin = true, .pTransmitBuffer = _command, .pBaseDisplay = this, .bufferSize = 1}; } auto sendChunk(const std::uint8_t* _pBuffer, std::size_t _bufferSize) noexcept diff --git a/Firmware/firmware_tests/article_example/display_gc9a01.hpp b/Firmware/firmware_tests/article_example/display_gc9a01.hpp index e20aacf8..a8fbf469 100644 --- a/Firmware/firmware_tests/article_example/display_gc9a01.hpp +++ b/Firmware/firmware_tests/article_example/display_gc9a01.hpp @@ -122,7 +122,7 @@ class GC9A01Compact std::uint16_t _y, std::uint16_t _width, std::uint16_t _height, - TBaseSpiDisplay::TColor* _colorToFill) noexcept + typename TBaseSpiDisplay::TColor* _colorToFill) noexcept { const std::uint16_t DisplayHeight = TBaseSpiDisplay::getHeight(); diff --git a/Firmware/firmware_tests/article_example/spi_driver_high_level.hpp b/Firmware/firmware_tests/article_example/spi_driver_high_level.hpp index 905787d6..e52746bb 100644 --- a/Firmware/firmware_tests/article_example/spi_driver_high_level.hpp +++ b/Firmware/firmware_tests/article_example/spi_driver_high_level.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include #include #include @@ -43,7 +42,7 @@ template class SpiBus { m_backendImpl.setTransactionCompletedHandler([this] { transmitCompleted(); }); - m_coroHandle = std::coroutine_handle<>::from_address(_pUserData); + m_coroHandle = stdcoro::coroutine_handle<>::from_address(_pUserData); TransactionContext newContext{ .restoreInSpiCtx = _restoreInSpiCtx, @@ -64,7 +63,7 @@ template class SpiBus void* _pUserData, bool _restoreInSpiCtx) noexcept { - m_coroHandle = std::coroutine_handle<>::from_address(_pUserData); + m_coroHandle = stdcoro::coroutine_handle<>::from_address(_pUserData); m_backendImpl.setTransactionCompletedHandler([this] { transmitCompleted(); }); const size_t TransferBufferSize = _pBufferSize; @@ -153,7 +152,7 @@ template class SpiBus private: SpiBackendImpl m_backendImpl; - std::coroutine_handle<> m_coroHandle; + stdcoro::coroutine_handle<> m_coroHandle; struct TransactionContext { diff --git a/Firmware/firmware_tests/buttons_driver/buttons_fake_event_handler.hpp b/Firmware/firmware_tests/buttons_driver/buttons_fake_event_handler.hpp index 108d7c2f..e6e38f5a 100644 --- a/Firmware/firmware_tests/buttons_driver/buttons_fake_event_handler.hpp +++ b/Firmware/firmware_tests/buttons_driver/buttons_fake_event_handler.hpp @@ -3,6 +3,7 @@ #include "ih/gs_events.hpp" #include "ih/gs_ievent_handler.hpp" +#include "gs_event_dispatcher.hpp" #include "widgets_layer/gs_event_handler_base.hpp" namespace FakeButton @@ -44,6 +45,18 @@ class FakeButtonEventsHandler return m_button; } +public: + void initSubscriptions(Graphics::Events::EventDispatcher& eventDispatcher) override + { + eventDispatcher.subscribe( + Graphics::Events::EventGroup::Buttons, + [this](const Graphics::Events::TEvent& _event) { handleEvent(_event); }); + } + + void deinitHandler() override + { + } + protected: void handleEventImpl( const Graphics::Events::TButtonsEvents& _event, diff --git a/Firmware/firmware_tests/buttons_driver/buttons_fixture.hpp b/Firmware/firmware_tests/buttons_driver/buttons_fixture.hpp index 6abed442..a79c5b95 100644 --- a/Firmware/firmware_tests/buttons_driver/buttons_fixture.hpp +++ b/Firmware/firmware_tests/buttons_driver/buttons_fixture.hpp @@ -30,10 +30,7 @@ class ButtonsDriverTest : public ::testing::Test m_pFakeTimer = m_pButtonsDriver.getTimeWrapper(); m_pFakeButtonsBackend = m_pButtonsDriver.getButtonsBackend(); - m_pEventDispatcher->subscribe( - Graphics::Events::EventGroup::Buttons, [this](const Graphics::Events::TEvent& _event) { - m_pFakeEventHandler->handleEvent(_event); - }); + m_pFakeEventHandler->initSubscriptions(*m_pEventDispatcher); m_pButtonsDriver.onButtonEvent.connect([this](const Buttons::ButtonEvent& _buttonEvent) { m_pEventDispatcher->postEvent( diff --git a/Firmware/firmware_tests/clock_page_handler/clock_page_handler_fixture.hpp b/Firmware/firmware_tests/clock_page_handler/clock_page_handler_fixture.hpp index 31a58e8a..50269cb8 100644 --- a/Firmware/firmware_tests/clock_page_handler/clock_page_handler_fixture.hpp +++ b/Firmware/firmware_tests/clock_page_handler/clock_page_handler_fixture.hpp @@ -40,7 +40,7 @@ class ClockPageHandlerTest : public ::testing::Test EXPECT_CALL(fakePageMock, setHours("14")).Times(1); EXPECT_CALL(fakePageMock, setMinutes("24")).Times(1); EXPECT_CALL(fakePageMock, setSeconds("43")).Times(1); - EXPECT_CALL(fakePageMock, setWeekday(std::string_view("MON"))).Times(1); + EXPECT_CALL(fakePageMock, setWeekday("MON")).Times(1); EXPECT_CALL(fakePageMock, setFullDate("JUN/22/2020")).Times(1); pageMockWatchHandler->handleEvent( diff --git a/Firmware/firmware_tests/clock_page_handler/clock_page_view_handler_test.cpp b/Firmware/firmware_tests/clock_page_handler/clock_page_view_handler_test.cpp index 2fc1fb92..c9b450e0 100644 --- a/Firmware/firmware_tests/clock_page_handler/clock_page_view_handler_test.cpp +++ b/Firmware/firmware_tests/clock_page_handler/clock_page_view_handler_test.cpp @@ -116,7 +116,7 @@ TEST_F(ClockPageHandlerTest, WeekdayChangeHandledCorrectly) EXPECT_CALL(fakePageMock, isVisible()).Times(1).WillOnce(Return(true)); - EXPECT_CALL(fakePageMock, setWeekday(std::string_view("TUE"))).Times(1); + EXPECT_CALL(fakePageMock, setWeekday("TUE")).Times(1); EXPECT_CALL(fakePageMock, setFullDate("JUN/23/2020")).Times(1); pageMockWatchHandler->handleEvent( @@ -132,7 +132,7 @@ TEST_F(ClockPageHandlerTest, WeekdayChangeFromSundayToMondayHandledCorrectly) EXPECT_CALL(fakePageMock, isVisible()).Times(2).WillRepeatedly(Return(true)); - EXPECT_CALL(fakePageMock, setWeekday(std::string_view("SUN"))).Times(1); + EXPECT_CALL(fakePageMock, setWeekday("SUN")).Times(1); EXPECT_CALL(fakePageMock, setFullDate("JUN/28/2020")).Times(1); pageMockWatchHandler->handleEvent( @@ -140,7 +140,7 @@ TEST_F(ClockPageHandlerTest, WeekdayChangeFromSundayToMondayHandledCorrectly) Graphics::Events::TDateTimeEvents::DateTimeChanged, TimeWrapper("2020/06/28 14:24:43", '/', ':')}); - EXPECT_CALL(fakePageMock, setWeekday(std::string_view("MON"))).Times(1); + EXPECT_CALL(fakePageMock, setWeekday("MON")).Times(1); EXPECT_CALL(fakePageMock, setFullDate("JUN/29/2020")).Times(1); pageMockWatchHandler->handleEvent( diff --git a/Firmware/firmware_tests/coroutine/coroutine_thoughts.cpp b/Firmware/firmware_tests/coroutine/coroutine_thoughts.cpp index b6fe4d01..52acee34 100644 --- a/Firmware/firmware_tests/coroutine/coroutine_thoughts.cpp +++ b/Firmware/firmware_tests/coroutine/coroutine_thoughts.cpp @@ -1,7 +1,13 @@ #include #include #include + +#if defined(__clang__) +#include +#else #include +#endif + #include #include #include diff --git a/Firmware/firmware_tests/drivers/spi/spi_driver_fixture.hpp b/Firmware/firmware_tests/drivers/spi/spi_driver_fixture.hpp index ad56f652..5cf5d25e 100644 --- a/Firmware/firmware_tests/drivers/spi/spi_driver_fixture.hpp +++ b/Firmware/firmware_tests/drivers/spi/spi_driver_fixture.hpp @@ -38,7 +38,7 @@ class SpiDriverTest void await_resume() const noexcept { } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { pThis->testSpiDriver.transmitBuffer( std::span(pTransmitBuffer, bufferSize), thisCoroutine.address(), restoreInSpiCtx); @@ -60,7 +60,7 @@ class SpiDriverTest void await_resume() const noexcept { } - void await_suspend(std::coroutine_handle<> thisCoroutine) const + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) const { pThis->testSpiDriver.xferBuffer( pTransmitBuffer, pReceiveBuffer, thisCoroutine.address(), restoreInSpiCtx); diff --git a/Firmware/firmware_tests/drivers/spi/spi_driver_test_suite.cpp b/Firmware/firmware_tests/drivers/spi/spi_driver_test_suite.cpp index 0b4156df..27a15879 100644 --- a/Firmware/firmware_tests/drivers/spi/spi_driver_test_suite.cpp +++ b/Firmware/firmware_tests/drivers/spi/spi_driver_test_suite.cpp @@ -44,9 +44,10 @@ TEST_P(SpiDriverTest, CheckRandomSequenceWithLengthTransmissionCorrect) std::random_device randomDevice; std::mt19937 generator(randomDevice()); std::uniform_int_distribution<> distribution(0x00, 0xFF); - std::ranges::generate(ExpectedStream, [&distribution, generator]() mutable { - return std::byte(distribution(generator)); - }); + std::generate( + ExpectedStream.begin(), ExpectedStream.end(), [&distribution, generator]() mutable { + return std::byte(distribution(generator)); + }); CoroUtils::syncWait(sendChunk( reinterpret_cast(ExpectedStream.data()), ExpectedStream.size())); @@ -59,7 +60,7 @@ TEST_F(SpiDriverTest, CheckXferTransaction) constexpr std::uint8_t ReceivedDataLength = 8; auto& transmitBuffer = testSpiDriver.getDmaBufferTransmit(); - std::ranges::fill_n(transmitBuffer.begin(), ReceivedDataLength + 1, 0x00); + std::fill_n(transmitBuffer.begin(), ReceivedDataLength + 1, 0x00); transmitBuffer[0] = ReadUniqueId; TDataStream ExpectedStream{ReceivedDataLength}; @@ -68,15 +69,15 @@ TEST_F(SpiDriverTest, CheckXferTransaction) std::mt19937 generator(randomDevice()); std::uniform_int_distribution<> distribution(0x00, 0xFF); - std::ranges::generate(ExpectedStream, [&distribution, generator]() mutable { - return std::byte(distribution(generator)); - }); + std::generate( + ExpectedStream.begin(), ExpectedStream.end(), [&distribution, generator]() mutable { + return std::byte(distribution(generator)); + }); - EXPECT_CALL( - testSpiDriver.getBackendImpl().accessToSpiMock(), - receivedData()).Times(1).WillOnce( - Return(std::span(reinterpret_cast(ExpectedStream.data()), ExpectedStream.size())) - ); + EXPECT_CALL(testSpiDriver.getBackendImpl().accessToSpiMock(), receivedData()) + .Times(1) + .WillOnce(Return(std::span( + reinterpret_cast(ExpectedStream.data()), ExpectedStream.size()))); auto receivedStreamSpan = CoroUtils::syncWait(xferTransaction( std::span( @@ -84,10 +85,11 @@ TEST_F(SpiDriverTest, CheckXferTransaction) std::span(testSpiDriver.getDmaBufferReceive().data(), ReceivedDataLength))); TDataStream receivedStream; - std::ranges::transform( - receivedStreamSpan, std::back_inserter(receivedStream), [](auto receivedItem) { - return static_cast(receivedItem); - }); + std::transform( + receivedStreamSpan.begin(), + receivedStreamSpan.end(), + std::back_inserter(receivedStream), + [](auto receivedItem) { return static_cast(receivedItem); }); EXPECT_EQ(ExpectedStream, receivedStream); } diff --git a/Firmware/firmware_tests/drivers/spi/spi_fake_backend.hpp b/Firmware/firmware_tests/drivers/spi/spi_fake_backend.hpp index 3c4052d3..2fdc5fab 100644 --- a/Firmware/firmware_tests/drivers/spi/spi_fake_backend.hpp +++ b/Firmware/firmware_tests/drivers/spi/spi_fake_backend.hpp @@ -1,14 +1,14 @@ #pragma once +#include #include #include -#include #include #include -#include #include "mock_gpio.hpp" #include "mock_spi.hpp" +#include namespace Testing::Spi { @@ -20,7 +20,7 @@ class SpiBusBackendStub void sendChunk(const std::uint8_t* _pBuffer, const size_t _bufferSize) noexcept { BusTransactionsTransmit.emplace_back(_pBuffer, _bufferSize); - m_spiMocker.sentData(std::span(_pBuffer,_bufferSize)); + m_spiMocker.sentData(std::span(_pBuffer, _bufferSize)); m_completedTransaction(); } @@ -28,7 +28,7 @@ class SpiBusBackendStub { const auto& receivedRange = m_spiMocker.receivedData(); auto arraySpan = std::span(_pDestinationArray, _receiveSize); - std::ranges::copy_n(receivedRange.begin(), _receiveSize, arraySpan.begin() ); + std::copy_n(receivedRange.begin(), _receiveSize, arraySpan.begin()); m_completedTransaction(); } @@ -44,11 +44,10 @@ class SpiBusBackendStub const auto& receivedRange = m_spiMocker.receivedData(); auto streamSpan = std::span( - reinterpret_cast(receivedRange.data()), - receivedRange.size()); + reinterpret_cast(receivedRange.data()), receivedRange.size()); BusTransactionsReceive.emplace_back(streamSpan.data(), streamSpan.size()); - std::ranges::copy(streamSpan, _receiveArray.begin()); + std::copy(streamSpan.begin(), streamSpan.end(), _receiveArray.begin()); m_completedTransaction(); } @@ -79,13 +78,15 @@ class SpiBusBackendStub TDataStream getTransmittedData() const { TDataStream stream; - std::ranges::for_each( - BusTransactionsTransmit, + std::for_each( + BusTransactionsTransmit.begin(), + BusTransactionsTransmit.end(), [&stream](const auto& _transaction) { const auto& [pArray, blockSize] = _transaction; auto arraySpan = std::span{pArray, blockSize}; - std::ranges::transform( - arraySpan, + std::transform( + arraySpan.begin(), + arraySpan.end(), std::back_inserter(stream), [](std::uint8_t _dataByte) { return std::byte{_dataByte}; }); }); @@ -115,7 +116,6 @@ class SpiBusBackendStub return m_spiMocker; } - protected: using TTransacation = std::pair; std::vector BusTransactionsTransmit; diff --git a/Firmware/firmware_tests/drivers/windond_flash/flash_driver_test_suite.cpp b/Firmware/firmware_tests/drivers/windond_flash/flash_driver_test_suite.cpp index 9e4f7160..f0e72c1c 100644 --- a/Firmware/firmware_tests/drivers/windond_flash/flash_driver_test_suite.cpp +++ b/Firmware/firmware_tests/drivers/windond_flash/flash_driver_test_suite.cpp @@ -9,8 +9,8 @@ #include #include -using ::testing::Return; using ::testing::ContainerEq; +using ::testing::Return; TEST_F(FlashDriverTest, RequestJedecId) { @@ -21,7 +21,8 @@ TEST_F(FlashDriverTest, RequestJedecId) EXPECT_CALL(spiMockAccess(), receivedData) .Times(1) - .WillOnce(Return(std::span(reinterpret_cast(ExpectedStream.data()), ExpectedStream.size()))); + .WillOnce(Return(std::span( + reinterpret_cast(ExpectedStream.data()), ExpectedStream.size()))); auto fToJedecId = [](const TDataStream& _jedecId) { std::uint32_t result{}; @@ -38,7 +39,8 @@ TEST_F(FlashDriverTest, RequestJedecId) MATCHER_P(SpanChecker, spanItem, "Span content equals") { - const bool isEqual = std::ranges::equal(spanItem, std::get<0>(arg)); + const auto argEl{std::get<0>(arg)}; + const bool isEqual = std::equal(spanItem.begin(), spanItem.end(), argEl.begin()); return isEqual; } TEST_F(FlashDriverTest, RequestWriteBlock) @@ -52,15 +54,15 @@ TEST_F(FlashDriverTest, RequestWriteBlock) constexpr std::uint32_t address{0x10'00}; constexpr std::size_t WriteEnableCommandLength = 1; - constexpr const std::array writeEnableCommand {WindbondCommandSet::WriteEnable}; + constexpr const std::array writeEnableCommand{ + WindbondCommandSet::WriteEnable}; constexpr std::size_t ProgramPageCommandLength = 4; constexpr const std::array pageProgramCommand{ WindbondCommandSet::PageProgram, static_cast(address & 0x00'FF'00'00 >> 16), static_cast(address & 0x00'00'FF'00 >> 8), - static_cast(address & 0x00'00'00'FF) - }; + static_cast(address & 0x00'00'00'FF)}; testing::Sequence sequence; @@ -69,7 +71,8 @@ TEST_F(FlashDriverTest, RequestWriteBlock) const auto writeEnableSpan = std::span(writeEnableCommand.data(), writeEnableCommand.size()); - const auto ProgramCommandSpan = std::span(pageProgramCommand.data(), pageProgramCommand.size()); + const auto ProgramCommandSpan = + std::span(pageProgramCommand.data(), pageProgramCommand.size()); EXPECT_CALL(spiMockAccess(), sentData) .With(SpanChecker(writeEnableSpan)) .Times(1) @@ -96,8 +99,7 @@ TEST_F(FlashDriverTest, RequestReadBlock) using TStream = std::array; - auto ReceiveData{ - TStream{0xEF, 0xFF, 0x18, 0x19, 0x20, 0x21, 0x22}}; + auto ReceiveData{TStream{0xEF, 0xFF, 0x18, 0x19, 0x20, 0x21, 0x22}}; auto Dummy{TStream{}}; @@ -121,8 +123,7 @@ TEST_F(FlashDriverTest, RequestReadBlock) const auto DummySpan = std::span(Dummy.data(), Dummy.size()); - const auto ReadDataSpan = - std::span(readCommand.data(), readCommand.size()); + const auto ReadDataSpan = std::span(readCommand.data(), readCommand.size()); EXPECT_CALL(spiMockAccess(), sentData) .With(SpanChecker(ReadDataSpan)) @@ -136,5 +137,6 @@ TEST_F(FlashDriverTest, RequestReadBlock) auto task = flashDriver.requestReadBlock(address, ReceiveData.size()); auto readSpan = CoroUtils::syncWait(task); - EXPECT_TRUE(std::ranges::equal(readSpan, ReceiveData)); + EXPECT_TRUE( + std::equal(readSpan.begin(), readSpan.end(), ReceiveData.begin(), ReceiveData.end())); } \ No newline at end of file diff --git a/Firmware/firmware_tests/stubs/pages/clock_watch_fake_view.hpp b/Firmware/firmware_tests/stubs/pages/clock_watch_fake_view.hpp index 7af224f8..08a28a34 100644 --- a/Firmware/firmware_tests/stubs/pages/clock_watch_fake_view.hpp +++ b/Firmware/firmware_tests/stubs/pages/clock_watch_fake_view.hpp @@ -36,7 +36,7 @@ class FakeClockPage : public FakeBasePage m_secondsValue = _newSecondsValue; }; - void setWeekday(std::string_view _newWeekDay) noexcept override + void setWeekday(const char* const _newWeekDay) noexcept override { m_weekdayValue = _newWeekDay; }; @@ -47,27 +47,27 @@ class FakeClockPage : public FakeBasePage }; public: - std::string_view getHours() const noexcept + const std::string& getHours() const noexcept { return m_hoursValue; } - std::string_view getMinutes() const noexcept + const std::string& getMinutes() const noexcept { return m_minutesValue; } - std::string_view getSeconds() const noexcept + const std::string& getSeconds() const noexcept { return m_secondsValue; } - std::string_view getWeekday() const noexcept + const char* const getWeekday() const noexcept { return m_weekdayValue; } - std::string_view getFullDate() const noexcept + const std::string& getFullDate() const noexcept { return m_fulldateValue; } @@ -76,7 +76,7 @@ class FakeClockPage : public FakeBasePage std::string m_hoursValue; std::string m_minutesValue; std::string m_secondsValue; - std::string m_weekdayValue; + const char* m_weekdayValue; std::string m_fulldateValue; }; @@ -87,6 +87,6 @@ class FakeClockPageMock : public FakeBasePageMock; diff --git a/Firmware/graphics/ih/pages/gs_iclock_page_view.hpp b/Firmware/graphics/ih/pages/gs_iclock_page_view.hpp index da6d7070..72713c61 100644 --- a/Firmware/graphics/ih/pages/gs_iclock_page_view.hpp +++ b/Firmware/graphics/ih/pages/gs_iclock_page_view.hpp @@ -17,7 +17,7 @@ class IClockWatchPage : public IPageViewObject virtual void setSeconds(const std::string& _newSecondsValue) noexcept = 0; - virtual void setWeekday(std::string_view _newWeekDay) noexcept = 0; + virtual void setWeekday(const char* const _newWeekDay) noexcept = 0; virtual void setFullDate(const std::string& _fullDate) noexcept = 0; diff --git a/Firmware/graphics/widgets_layer/gs_main_window.cpp b/Firmware/graphics/widgets_layer/gs_main_window.cpp index 37d0961f..372afc7b 100644 --- a/Firmware/graphics/widgets_layer/gs_main_window.cpp +++ b/Firmware/graphics/widgets_layer/gs_main_window.cpp @@ -145,16 +145,10 @@ void GsMainWindow::initWidgets() noexcept m_pBluetoothWidget = m_pWidgetsCreator->createBluetoothWidget(getThemeController()); m_pBluetoothWidgetController = Widgets::createBluetoothWidgetHandler(m_pBluetoothWidget.get()); - m_pBatteryWidgetController = Widgets::createBatteryWidgetHandler(m_pBatteryWidget.get()); - - getEventDispatcher().subscribe( - Events::EventGroup::BleDevice, [this](const Events::TEvent& _event) { - m_pBluetoothWidgetController->handleEvent(_event); - }); + m_pBluetoothWidgetController->initSubscriptions(getEventDispatcher()); - getEventDispatcher().subscribe( - Events::EventGroup::Battery, - [this](const Events::TEvent& _event) { m_pBatteryWidgetController->handleEvent(_event); }); + m_pBatteryWidgetController = Widgets::createBatteryWidgetHandler(m_pBatteryWidget.get()); + m_pBatteryWidgetController->initSubscriptions(getEventDispatcher()); onActivePageChanged.connect( [this](std::string_view _activePage) { m_pPagesSwitch->setActivePage(_activePage); }); @@ -168,10 +162,7 @@ void GsMainWindow::initWatchPage() noexcept pClockPage->addWidget(m_pBluetoothWidget.get()); m_pClockPageController = Views::createPageWatchHandler(pClockPage.get()); - - getEventDispatcher().subscribe( - Events::EventGroup::DateTime, - [this](const Events::TEvent& _event) { m_pClockPageController->handleEvent(_event); }); + m_pClockPageController->initSubscriptions(getEventDispatcher()); addPage(std::move(pClockPage)); } @@ -206,9 +197,8 @@ void GsMainWindow::initMainWindowSubscriptions() noexcept auto& activePage = getActivePage(); activePage.reloadStyle(); }); - getEventDispatcher().subscribe( - Events::EventGroup::Buttons, - [this](const Events::TEvent& _event) { m_pMainWindowHandler->handleEvent(_event); }); + + m_pMainWindowHandler->initSubscriptions(getEventDispatcher()); } Views::IPageViewObject* GsMainWindow::getPagePointer(std::string_view _pageName) noexcept diff --git a/Firmware/graphics/widgets_layer/gs_main_window_event_handler.cpp b/Firmware/graphics/widgets_layer/gs_main_window_event_handler.cpp index 6767151c..675e46b3 100644 --- a/Firmware/graphics/widgets_layer/gs_main_window_event_handler.cpp +++ b/Firmware/graphics/widgets_layer/gs_main_window_event_handler.cpp @@ -7,6 +7,8 @@ #include "ih/pages/gs_ihealth_page_view.hpp" #include "ih/pages/gs_iplayer_page_view.hpp" +#include "gs_event_dispatcher.hpp" + namespace Graphics::MainWindow { @@ -57,6 +59,16 @@ void MainWindowHandler::navigateToPreviousPage() noexcept m_pMainWindowModel->setPageActive(Graphics::Views::IClockWatchPage::ClockPageName); } +void MainWindowHandler::initSubscriptions(Events::EventDispatcher& eventDispatcher) +{ + eventDispatcher.subscribe( + Events::EventGroup::Buttons, [this](const Events::TEvent& _event) { handleEvent(_event); }); +} + +void MainWindowHandler::deinitHandler() +{ +} + std::unique_ptr createMainWindowEventHandler( IGsMainWindowModel* _pMainWindowModel) noexcept { diff --git a/Firmware/graphics/widgets_layer/gs_main_window_event_handler.hpp b/Firmware/graphics/widgets_layer/gs_main_window_event_handler.hpp index 3e375f92..abfa220d 100644 --- a/Firmware/graphics/widgets_layer/gs_main_window_event_handler.hpp +++ b/Firmware/graphics/widgets_layer/gs_main_window_event_handler.hpp @@ -25,6 +25,11 @@ class MainWindowHandler ~MainWindowHandler() override = default; +public: + void initSubscriptions(Events::EventDispatcher& eventDispatcher) override; + + void deinitHandler() override; + protected: void handleEventImpl(const Events::TButtonsEvents& _event, const std::any& _eventData) noexcept override; diff --git a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.cpp b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.cpp index a6f4a9e5..60341f05 100644 --- a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.cpp +++ b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.cpp @@ -1,8 +1,8 @@ #include "gs_clock_page_handler.hpp" +#include "gs_event_dispatcher.hpp" #include "ih/gs_events.hpp" #include "ih/pages/gs_iclock_page_view.hpp" - #include "utils/MetaUtils.hpp" #include @@ -54,7 +54,7 @@ void ClockPageHandler::handleEventImpl( if (newDateTime.getWeekDayString() != m_lastReceivedTime.getWeekDayString() || m_forceUpdateAfterVisibilityChange) - pClockView->setWeekday(newDateTime.getWeekDayString()); + pClockView->setWeekday(newDateTime.getWeekDayString().data()); const bool bShouldApplyNewDate{shouldApplyNewDate(newDateTime)}; @@ -68,6 +68,17 @@ void ClockPageHandler::handleEventImpl( m_lastReceivedTime = newDateTime; } +void ClockPageHandler::initSubscriptions(Events::EventDispatcher& eventDispatcher) +{ + eventDispatcher.subscribe(Events::EventGroup::DateTime, [this](const Events::TEvent& _event) { + handleEvent(_event); + }); +} + +void ClockPageHandler::deinitHandler() +{ +} + bool ClockPageHandler::shouldApplyNewDate(const TimeWrapper& _toCheck) noexcept { return m_lastReceivedTime.getMonthDay() != _toCheck.getMonthDay() || diff --git a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.hpp b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.hpp index 169ca4df..03e48bc9 100644 --- a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.hpp +++ b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_handler.hpp @@ -23,6 +23,11 @@ class ClockPageHandler ~ClockPageHandler() override = default; +public: + void initSubscriptions(Events::EventDispatcher& eventDispatcher) override; + + void deinitHandler() override; + protected: void handleEventImpl(const Events::TDateTimeEvents& _event, const std::any& _eventData) noexcept override; diff --git a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.cpp b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.cpp index 668ac238..d616362c 100644 --- a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.cpp +++ b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.cpp @@ -38,10 +38,10 @@ void ClockWatch::setSeconds(const std::string& _newSecondsValue) noexcept lv_label_set_text(m_pSecondsLabel.get(), m_secondsValue.c_str()); } -void ClockWatch::setWeekday(std::string_view _newWeekDay) noexcept +void ClockWatch::setWeekday(const char* const _newWeekDay) noexcept { m_weekdayValue = _newWeekDay; - lv_label_set_text(m_pWeekDayLabel.get(), m_weekdayValue.c_str()); + lv_label_set_text(m_pWeekDayLabel.get(), m_weekdayValue); } void ClockWatch::setFullDate(const std::string& _fullDate) noexcept @@ -167,7 +167,7 @@ void ClockWatch::restoreLabelsText() noexcept lv_label_set_text(m_pMinutesLabel.get(), m_minutesValue.c_str()); lv_label_set_text(m_pSecondsLabel.get(), m_secondsValue.c_str()); lv_label_set_text(m_pFullDateLabel.get(), m_fulldateValue.c_str()); - lv_label_set_text(m_pWeekDayLabel.get(), m_weekdayValue.c_str()); + lv_label_set_text(m_pWeekDayLabel.get(), m_weekdayValue); } std::unique_ptr createClockWatchView( diff --git a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.hpp b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.hpp index 855d2958..8db2e640 100644 --- a/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.hpp +++ b/Firmware/graphics/widgets_layer/pages/clock_page/gs_clock_page_view.hpp @@ -25,7 +25,7 @@ class ClockWatch : public PageViewObject void setSeconds(const std::string& _newSecondsValue) noexcept override; - void setWeekday(std::string_view _newWeekDay) noexcept override; + void setWeekday(const char* const _newWeekDay) noexcept override; void setFullDate(const std::string& _fullDate) noexcept override; @@ -69,7 +69,7 @@ class ClockWatch : public PageViewObject std::string m_hoursValue; std::string m_minutesValue; std::string m_secondsValue; - std::string m_weekdayValue; + const char* m_weekdayValue; std::string m_fulldateValue; Meta::PointerWrapper m_pHoursLabel; diff --git a/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.cpp b/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.cpp index 0f459266..1c35376f 100644 --- a/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.cpp +++ b/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.cpp @@ -2,6 +2,7 @@ #include "ih/widgets/gs_ibattery_widget.hpp" +#include "gs_event_dispatcher.hpp" #include "ih/gs_events.hpp" #include "utils/MetaUtils.hpp" @@ -47,6 +48,16 @@ void BatteryWidgetHandler::handleEventImpl( } } +void BatteryWidgetHandler::initSubscriptions(Events::EventDispatcher& eventDispatcher) +{ + eventDispatcher.subscribe( + Events::EventGroup::Battery, [this](const Events::TEvent& _event) { handleEvent(_event); }); +} + +void BatteryWidgetHandler::deinitHandler() +{ +} + std::unique_ptr createBatteryWidgetHandler( IBatteryWidget* _batteryWidget) noexcept { diff --git a/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.hpp b/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.hpp index eaec65bf..d65e66c7 100644 --- a/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.hpp +++ b/Firmware/graphics/widgets_layer/widgets/battery/gs_battery_handler.hpp @@ -20,6 +20,11 @@ class BatteryWidgetHandler ~BatteryWidgetHandler() override = default; +public: + void initSubscriptions(Events::EventDispatcher& eventDispatcher) override; + + void deinitHandler() override; + protected: void handleEventImpl(const Events::TBatteryEvents& _event, const std::any& _eventData) noexcept override; diff --git a/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.cpp b/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.cpp index 1a230f3e..ffb14811 100644 --- a/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.cpp +++ b/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.cpp @@ -2,6 +2,7 @@ #include "ih/gs_events.hpp" +#include "gs_event_dispatcher.hpp" #include "ih/widgets/gs_ibluetooth_widget.hpp" #include @@ -28,6 +29,17 @@ void BluetoothWidgetHandler::handleEventImpl( } } +void BluetoothWidgetHandler::initSubscriptions(Events::EventDispatcher& eventDispatcher) +{ + eventDispatcher.subscribe(Events::EventGroup::BleDevice, [this](const Events::TEvent& _event) { + handleEvent(_event); + }); +} + +void BluetoothWidgetHandler::deinitHandler() +{ +} + std::unique_ptr createBluetoothWidgetHandler( IBluetoothWidget* _bluetoothWidget) noexcept { diff --git a/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.hpp b/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.hpp index c3f94ae0..fc600ce4 100644 --- a/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.hpp +++ b/Firmware/graphics/widgets_layer/widgets/bluetooth/gs_bluetooth_widget_handler.hpp @@ -20,6 +20,11 @@ class BluetoothWidgetHandler ~BluetoothWidgetHandler() override = default; +public: + void initSubscriptions(Events::EventDispatcher& eventDispatcher) override; + + void deinitHandler() override; + protected: void handleEventImpl( const Events::TBleClientEvents& _event, diff --git a/Firmware/utils/inc/utils/TimeWrapper.hpp b/Firmware/utils/inc/utils/TimeWrapper.hpp index 12e9f07f..5ceb2c02 100644 --- a/Firmware/utils/inc/utils/TimeWrapper.hpp +++ b/Firmware/utils/inc/utils/TimeWrapper.hpp @@ -1,11 +1,11 @@ #pragma once +#include "MetaUtils.hpp" #include #include #include #include - -#include "MetaUtils.hpp" +#include constexpr std::array Months = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "NOV", "DEC", "UND"}; diff --git a/Firmware/utils/inc/utils/coroutine/Common.hpp b/Firmware/utils/inc/utils/coroutine/Common.hpp index 62983190..2f959085 100644 --- a/Firmware/utils/inc/utils/coroutine/Common.hpp +++ b/Firmware/utils/inc/utils/coroutine/Common.hpp @@ -4,19 +4,18 @@ #include #include -#include #include #ifdef _MSC_VER #include #include namespace stdcoro = std; -#elif __GNUC__ +#elif defined(__GNUC__) && !defined(__clang__) #include namespace stdcoro = std; #else #include -namespace stdcoro = std::experimental +namespace stdcoro = std::experimental::coroutines_v1; #endif #include diff --git a/Firmware/utils/inc/utils/coroutine/ExecutionQueueCoro.hpp b/Firmware/utils/inc/utils/coroutine/ExecutionQueueCoro.hpp index 9d9e82f1..6d18eb48 100644 --- a/Firmware/utils/inc/utils/coroutine/ExecutionQueueCoro.hpp +++ b/Firmware/utils/inc/utils/coroutine/ExecutionQueueCoro.hpp @@ -12,14 +12,14 @@ struct CoroQueueMainLoop return instance; } - void pushToLater(std::coroutine_handle<> coroHandle) + void pushToLater(stdcoro::coroutine_handle<> coroHandle) { executionQueue.push(coroHandle); } void processQueue() { - std::coroutine_handle<> handle; + stdcoro::coroutine_handle<> handle; while (executionQueue.pop(handle)) { if (!handle.done()) @@ -31,7 +31,7 @@ struct CoroQueueMainLoop using TQueueStorageType = etl::queue_spsc_atomic; - TQueueStorageType> executionQueue; + TQueueStorageType> executionQueue; }; } // namespace CoroUtils \ No newline at end of file diff --git a/Firmware/utils/inc/utils/coroutine/SyncWait.hpp b/Firmware/utils/inc/utils/coroutine/SyncWait.hpp index 48b11b31..4952a126 100644 --- a/Firmware/utils/inc/utils/coroutine/SyncWait.hpp +++ b/Firmware/utils/inc/utils/coroutine/SyncWait.hpp @@ -23,20 +23,17 @@ auto awaiterGetterImpl(TAwaiter&& _awaiter, long) return operator co_await(static_cast(_awaiter)); } -template -auto awaiterGetterImpl(TAwaiter&& _awaiter, double) +template auto awaiterGetterImpl(TAwaiter&& _awaiter, double) { return static_cast(_awaiter); } - template -auto awaiterGetter(TAwaiter&& _awaiter) -> decltype(awaiterGetterImpl(_awaiter,0)) +auto awaiterGetter(TAwaiter&& _awaiter) -> decltype(awaiterGetterImpl(_awaiter, 0)) { return awaiterGetterImpl(static_cast(_awaiter), 0); } - class BlockingEvent { public: @@ -58,31 +55,25 @@ class BlockingEvent std::condition_variable condEvent; }; -template -struct AwaitResultGetter +template struct AwaitResultGetter { using Type = decltype(awaiterGetter(std::declval())); using Result = decltype(std::declval().await_resume()); }; - -template -struct ResultTypeRefHolder +template struct ResultTypeRefHolder { using Type = TResult&&; }; -template<> -struct ResultTypeRefHolder +template <> struct ResultTypeRefHolder { using Type = void; }; -template -struct SyncTaskPromise; +template struct SyncTaskPromise; -template -struct SyncWaitTask +template struct SyncWaitTask { using promise_type = SyncTaskPromise; using TResultRef = typename ResultTypeRefHolder::Type; @@ -113,9 +104,7 @@ struct SyncWaitTask stdcoro::coroutine_handle> m_suspendedRoutine; }; - -template -struct SyncTaskPromise +template struct SyncTaskPromise { using TResultRef = TResultType&&; @@ -138,7 +127,8 @@ struct SyncTaskPromise auto get_return_object() noexcept { - return SyncWaitTask{ stdcoro::coroutine_handle>::from_promise(*this) }; + return SyncWaitTask{ + stdcoro::coroutine_handle>::from_promise(*this)}; } void start(BlockingEvent* _pEvent) noexcept { @@ -147,7 +137,7 @@ struct SyncTaskPromise } auto initial_suspend() noexcept { - return std::suspend_always{}; + return stdcoro::suspend_always{}; } auto final_suspend() noexcept @@ -179,8 +169,7 @@ struct SyncTaskPromise std::remove_reference_t* m_value; }; -template<> -struct SyncTaskPromise +template <> struct SyncTaskPromise { struct FinalAwaitableVoid { @@ -198,7 +187,7 @@ struct SyncTaskPromise }; auto get_return_object() noexcept { - return SyncWaitTask{ stdcoro::coroutine_handle>::from_promise(*this) }; + return SyncWaitTask{stdcoro::coroutine_handle>::from_promise(*this)}; } void start(BlockingEvent* _pEvent) noexcept { @@ -207,7 +196,7 @@ struct SyncTaskPromise } auto initial_suspend() noexcept { - return std::suspend_always{}; + return stdcoro::suspend_always{}; } auto final_suspend() noexcept @@ -227,7 +216,9 @@ struct SyncTaskPromise BlockingEvent* m_event; }; -template ::Result> +template < + typename TAwaitable, + typename TTaskResult = typename AwaitResultGetter::Result> SyncWaitTask makeSyncWaitTask(TAwaitable&& _awaitable) { if constexpr (!std::is_same_v) @@ -241,8 +232,8 @@ namespace CoroUtils { template -auto syncWait(TCoroutine&& _coroutineTask) - -> typename AwaitResultGetter(_coroutineTask))>::Result +auto syncWait(TCoroutine&& _coroutineTask) -> + typename AwaitResultGetter(_coroutineTask))>::Result { BlockingEvent waitOn; @@ -250,7 +241,10 @@ auto syncWait(TCoroutine&& _coroutineTask) task.start(waitOn); waitOn.wait(); - if constexpr (!std::is_same_v(_coroutineTask))>::Result,void>) + if constexpr (!std::is_same_v< + typename AwaitResultGetter( + _coroutineTask))>::Result, + void>) return task.result(); } diff --git a/Firmware/utils/inc/utils/coroutine/WnenAllReady.hpp b/Firmware/utils/inc/utils/coroutine/WnenAllReady.hpp index 50cc8d69..3a43f658 100644 --- a/Firmware/utils/inc/utils/coroutine/WnenAllReady.hpp +++ b/Firmware/utils/inc/utils/coroutine/WnenAllReady.hpp @@ -12,7 +12,7 @@ namespace CoroUtils { } - void setCoroutineForWaiting( std::coroutine_handle<> _awaitingCoroutine )noexcept + void setCoroutineForWaiting( stdcoro::coroutine_handle<> _awaitingCoroutine )noexcept { m_suspendedCoroutine = _awaitingCoroutine; m_whenAllCounter.fetch_sub(1, std::memory_order_acq_rel); @@ -27,7 +27,7 @@ namespace CoroUtils } } - std::coroutine_handle<> m_suspendedCoroutine; + stdcoro::coroutine_handle<> m_suspendedCoroutine; std::atomic m_whenAllCounter; }; @@ -49,7 +49,7 @@ namespace CoroUtils m_whenAllCounter->notifyAwaitingCompleted(); } - void await_suspend(std::coroutine_handle<> thisCoroutine) noexcept + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) noexcept { co_await m_taskItem; thisCoroutine.resume(); @@ -83,7 +83,7 @@ namespace CoroUtils return m_taskList; } - void await_suspend(std::coroutine_handle<> thisCoroutine) noexcept + void await_suspend(stdcoro::coroutine_handle<> thisCoroutine) noexcept { m_whenAllCounter.setCoroutineForWaiting(thisCoroutine); std::apply(