From 047c76870ca9dae8b23e946e5d89964b7f3e7e77 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 10 May 2022 19:46:09 +0200 Subject: [PATCH] Move idle_mode out from logic subdir --- src/CMakeLists.txt | 2 +- src/{logic => }/idle_mode.cpp | 71 +++++++++---------- src/{logic => }/idle_mode.h | 12 ++-- src/logic/CMakeLists.txt | 1 - src/logic/command_base.cpp | 2 +- src/main.cpp | 6 +- tests/unit/logic/cut_filament/CMakeLists.txt | 2 +- .../unit/logic/eject_filament/CMakeLists.txt | 2 +- tests/unit/logic/failing_tmc/CMakeLists.txt | 2 +- .../logic/feed_to_bondtech/CMakeLists.txt | 2 +- tests/unit/logic/feed_to_finda/CMakeLists.txt | 2 +- tests/unit/logic/homing/CMakeLists.txt | 2 +- tests/unit/logic/load_filament/CMakeLists.txt | 2 +- tests/unit/logic/tool_change/CMakeLists.txt | 2 +- .../unit/logic/unload_filament/CMakeLists.txt | 2 +- .../unit/logic/unload_to_finda/CMakeLists.txt | 2 +- 16 files changed, 53 insertions(+), 61 deletions(-) rename src/{logic => }/idle_mode.cpp (83%) rename src/{logic => }/idle_mode.h (92%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 282331d..391e490 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(firmware PRIVATE main.cpp debug.cpp) +target_sources(firmware PRIVATE main.cpp debug.cpp idle_mode.cpp) target_link_libraries(firmware LUFA) diff --git a/src/logic/idle_mode.cpp b/src/idle_mode.cpp similarity index 83% rename from src/logic/idle_mode.cpp rename to src/idle_mode.cpp index c401929..0d5e6a9 100644 --- a/src/logic/idle_mode.cpp +++ b/src/idle_mode.cpp @@ -1,39 +1,36 @@ /// @file #include "idle_mode.h" -#include "../modules/timebase.h" -#include "../modules/leds.h" -#include "../modules/globals.h" -#include "../modules/user_input.h" -#include "../modules/finda.h" -#include "../modules/fsensor.h" -#include "../modules/serial.h" +#include "modules/leds.h" +#include "modules/globals.h" +#include "modules/user_input.h" +#include "modules/finda.h" +#include "modules/fsensor.h" +#include "modules/serial.h" -#include "command_base.h" -#include "cut_filament.h" -#include "eject_filament.h" -#include "home.h" -#include "load_filament.h" -#include "move_selector.h" -#include "no_command.h" -#include "set_mode.h" -#include "tool_change.h" -#include "unload_filament.h" +#include "logic/command_base.h" +#include "logic/cut_filament.h" +#include "logic/eject_filament.h" +#include "logic/home.h" +#include "logic/load_filament.h" +#include "logic/move_selector.h" +#include "logic/no_command.h" +#include "logic/set_mode.h" +#include "logic/tool_change.h" +#include "logic/unload_filament.h" -#include "../version.h" +#include "version.h" -#include "../panic.h" +#include "panic.h" /// Global instance of the protocol codec static mp::Protocol protocol; -namespace logic { - IdleMode idleMode; IdleMode::IdleMode() : lastCommandProcessedMs(0) - , currentCommand(&noCommand) + , currentCommand(&logic::noCommand) , currentCommandRq(mp::RequestMsgCodes::Reset, 0) {} void IdleMode::CheckManualOperation() { @@ -54,22 +51,22 @@ void IdleMode::CheckManualOperation() { case mui::Event::Left: // move selector left if possible if (mg::globals.ActiveSlot() > 0) { - moveSelector.Reset(mg::globals.ActiveSlot() - 1); - currentCommand = &moveSelector; + logic::moveSelector.Reset(mg::globals.ActiveSlot() - 1); + currentCommand = &logic::moveSelector; } break; case mui::Event::Middle: // plan load if (mg::globals.ActiveSlot() < config::toolCount) { // do we have a meaningful selector position? - loadFilament.Reset(mg::globals.ActiveSlot()); - currentCommand = &loadFilament; + logic::loadFilament.Reset(mg::globals.ActiveSlot()); + currentCommand = &logic::loadFilament; } break; case mui::Event::Right: // move selector right if possible (including the park position) if (mg::globals.ActiveSlot() < config::toolCount) { - moveSelector.Reset(mg::globals.ActiveSlot() + 1); // we allow also the park position - currentCommand = &moveSelector; + logic::moveSelector.Reset(mg::globals.ActiveSlot() + 1); // we allow also the park position + currentCommand = &logic::moveSelector; } break; default: @@ -106,28 +103,28 @@ void IdleMode::PlanCommand(const modules::protocol::RequestMsg &rq) { // before issuing another one - if needed. switch (rq.code) { case mp::RequestMsgCodes::Cut: - currentCommand = &cutFilament; + currentCommand = &logic::cutFilament; break; case mp::RequestMsgCodes::Eject: - currentCommand = &ejectFilament; + currentCommand = &logic::ejectFilament; break; case mp::RequestMsgCodes::Home: currentCommand = &logic::home; break; case mp::RequestMsgCodes::Load: - currentCommand = &loadFilament; + currentCommand = &logic::loadFilament; break; case mp::RequestMsgCodes::Tool: - currentCommand = &toolChange; + currentCommand = &logic::toolChange; break; case mp::RequestMsgCodes::Unload: - currentCommand = &unloadFilament; + currentCommand = &logic::unloadFilament; break; case mp::RequestMsgCodes::Mode: - currentCommand = &setMode; + currentCommand = &logic::setMode; break; default: - currentCommand = &noCommand; + currentCommand = &logic::noCommand; break; } currentCommandRq = rq; // save the Current Command Request for indentification of responses @@ -183,7 +180,7 @@ void IdleMode::ReportVersion(const mp::RequestMsg &rq) { void IdleMode::ReportRunningCommand() { uint8_t rsp[maxMsgLen]; - uint8_t len = protocol.EncodeResponseQueryOperation(currentCommandRq, logic::idleMode.RunningCommandStatus(), rsp); + uint8_t len = protocol.EncodeResponseQueryOperation(currentCommandRq, RunningCommandStatus(), rsp); modules::serial::WriteToUSART(rsp, len); } @@ -260,5 +257,3 @@ void IdleMode::Step() { currentCommand->Step(); } - -} // namespace logic diff --git a/src/logic/idle_mode.h b/src/idle_mode.h similarity index 92% rename from src/logic/idle_mode.h rename to src/idle_mode.h index 2b54b74..f09e5e6 100644 --- a/src/logic/idle_mode.h +++ b/src/idle_mode.h @@ -1,13 +1,13 @@ /// @file #pragma once #include -#include "../modules/timebase.h" -#include "../modules/protocol.h" -#include "error_codes.h" +#include "modules/timebase.h" +#include "modules/protocol.h" +#include "logic/error_codes.h" namespace logic { - class CommandBase; +} class IdleMode { public: @@ -44,7 +44,7 @@ private: uint16_t lastCommandProcessedMs; /// A command that resulted in the currently on-going operation - CommandBase *currentCommand; + logic::CommandBase *currentCommand; /// Remember the request message that started the currently running command /// For the start we report "Reset finished" which in fact corresponds with the MMU state pretty closely @@ -56,5 +56,3 @@ private: }; extern IdleMode idleMode; - -} // namespace logic diff --git a/src/logic/CMakeLists.txt b/src/logic/CMakeLists.txt index 481a2cf..295dcb0 100644 --- a/src/logic/CMakeLists.txt +++ b/src/logic/CMakeLists.txt @@ -6,7 +6,6 @@ target_sources( feed_to_bondtech.cpp feed_to_finda.cpp home.cpp - idle_mode.cpp load_filament.cpp move_selector.cpp no_command.cpp diff --git a/src/logic/command_base.cpp b/src/logic/command_base.cpp index 10a2673..fe702c0 100644 --- a/src/logic/command_base.cpp +++ b/src/logic/command_base.cpp @@ -1,6 +1,6 @@ /// @file command_base.cpp #include "command_base.h" -#include "idle_mode.h" +#include "../idle_mode.h" #include "../modules/globals.h" #include "../modules/finda.h" #include "../modules/fsensor.h" diff --git a/src/main.cpp b/src/main.cpp index d9a2a4b..3b95aed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ #include "modules/motion.h" #include "modules/usb_cdc.h" -#include "logic/idle_mode.h" +#include "idle_mode.h" /// One-time setup of HW and SW components /// Called before entering the loop() function @@ -101,7 +101,7 @@ void setup() { } void Panic(ErrorCode ec) { - logic::idleMode.Panic(ec); + idleMode.Panic(ec); } /// Main loop of the firmware @@ -130,7 +130,7 @@ void loop() { hal::cpu::Step(); mu::cdc.Step(); - logic::idleMode.Step(); + idleMode.Step(); hal::watchdog::Reset(); } diff --git a/tests/unit/logic/cut_filament/CMakeLists.txt b/tests/unit/logic/cut_filament/CMakeLists.txt index 062509f..cd0bc5b 100644 --- a/tests/unit/logic/cut_filament/CMakeLists.txt +++ b/tests/unit/logic/cut_filament/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( cut_filament_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/eject_filament/CMakeLists.txt b/tests/unit/logic/eject_filament/CMakeLists.txt index 6d669a3..f52b44e 100644 --- a/tests/unit/logic/eject_filament/CMakeLists.txt +++ b/tests/unit/logic/eject_filament/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( eject_filament_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/failing_tmc/CMakeLists.txt b/tests/unit/logic/failing_tmc/CMakeLists.txt index 55064e6..120809f 100644 --- a/tests/unit/logic/failing_tmc/CMakeLists.txt +++ b/tests/unit/logic/failing_tmc/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( failing_tmc_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt index a79710e..bfea024 100644 --- a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt +++ b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( feed_to_bondtech_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/feed_to_finda/CMakeLists.txt b/tests/unit/logic/feed_to_finda/CMakeLists.txt index 1350d65..04ab858 100644 --- a/tests/unit/logic/feed_to_finda/CMakeLists.txt +++ b/tests/unit/logic/feed_to_finda/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( feed_to_finda_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/homing/CMakeLists.txt b/tests/unit/logic/homing/CMakeLists.txt index 2736e80..138b48e 100644 --- a/tests/unit/logic/homing/CMakeLists.txt +++ b/tests/unit/logic/homing/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( homing_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/load_filament/CMakeLists.txt b/tests/unit/logic/load_filament/CMakeLists.txt index 3718333..b5ba667 100644 --- a/tests/unit/logic/load_filament/CMakeLists.txt +++ b/tests/unit/logic/load_filament/CMakeLists.txt @@ -1,6 +1,7 @@ # define the test executable add_executable( load_filament_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp @@ -8,7 +9,6 @@ add_executable( ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/tool_change/CMakeLists.txt b/tests/unit/logic/tool_change/CMakeLists.txt index 1aad496..44c0fa6 100644 --- a/tests/unit/logic/tool_change/CMakeLists.txt +++ b/tests/unit/logic/tool_change/CMakeLists.txt @@ -1,6 +1,7 @@ # define the test executable add_executable( tool_change_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp @@ -8,7 +9,6 @@ add_executable( ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/unload_filament/CMakeLists.txt b/tests/unit/logic/unload_filament/CMakeLists.txt index a17424a..9e2b460 100644 --- a/tests/unit/logic/unload_filament/CMakeLists.txt +++ b/tests/unit/logic/unload_filament/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( unload_filament_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp diff --git a/tests/unit/logic/unload_to_finda/CMakeLists.txt b/tests/unit/logic/unload_to_finda/CMakeLists.txt index 54ccadc..bc9ed3f 100644 --- a/tests/unit/logic/unload_to_finda/CMakeLists.txt +++ b/tests/unit/logic/unload_to_finda/CMakeLists.txt @@ -1,13 +1,13 @@ # define the test executable add_executable( unload_to_finda_tests + ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp ${CMAKE_SOURCE_DIR}/src/logic/home.cpp - ${CMAKE_SOURCE_DIR}/src/logic/idle_mode.cpp ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp ${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp