diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 391e490..f60e12c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(firmware PRIVATE main.cpp debug.cpp idle_mode.cpp) +target_sources(firmware PRIVATE application.cpp debug.cpp main.cpp) target_link_libraries(firmware LUFA) diff --git a/src/idle_mode.cpp b/src/application.cpp similarity index 92% rename from src/idle_mode.cpp rename to src/application.cpp index 0d5e6a9..69d743b 100644 --- a/src/idle_mode.cpp +++ b/src/application.cpp @@ -1,5 +1,5 @@ /// @file -#include "idle_mode.h" +#include "application.h" #include "modules/leds.h" #include "modules/globals.h" @@ -26,14 +26,14 @@ /// Global instance of the protocol codec static mp::Protocol protocol; -IdleMode idleMode; +Application application; -IdleMode::IdleMode() +Application::Application() : lastCommandProcessedMs(0) , currentCommand(&logic::noCommand) , currentCommandRq(mp::RequestMsgCodes::Reset, 0) {} -void IdleMode::CheckManualOperation() { +void Application::CheckManualOperation() { uint16_t ms = mt::timebase.Millis(); constexpr uint16_t idleDelay = 1000U; if (ms - lastCommandProcessedMs < idleDelay) { @@ -76,7 +76,7 @@ void IdleMode::CheckManualOperation() { } } -mp::ResponseCommandStatus IdleMode::RunningCommandStatus() const { +mp::ResponseCommandStatus Application::RunningCommandStatus() const { switch (currentCommand->Error()) { case ErrorCode::RUNNING: return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Processing, (uint16_t)currentCommand->State()); @@ -89,13 +89,13 @@ mp::ResponseCommandStatus IdleMode::RunningCommandStatus() const { static constexpr const uint8_t maxMsgLen = 10; -void IdleMode::ReportCommandAccepted(const mp::RequestMsg &rq, mp::ResponseMsgParamCodes status) { +void Application::ReportCommandAccepted(const mp::RequestMsg &rq, mp::ResponseMsgParamCodes status) { uint8_t tmp[maxMsgLen]; uint8_t len = protocol.EncodeResponseCmdAR(rq, status, tmp); modules::serial::WriteToUSART(tmp, len); } -void IdleMode::PlanCommand(const modules::protocol::RequestMsg &rq) { +void Application::PlanCommand(const modules::protocol::RequestMsg &rq) { if (currentCommand->State() == ProgressCode::OK) { // We are allowed to start a new command as the previous one is in the OK finished state // The previous command may be in an error state, but as long as it is in ProgressCode::OK (aka finished) @@ -135,7 +135,7 @@ void IdleMode::PlanCommand(const modules::protocol::RequestMsg &rq) { } } -void IdleMode::ReportFINDA(const mp::RequestMsg &rq) { +void Application::ReportFINDA(const mp::RequestMsg &rq) { #ifdef DEBUG_FINDA using namespace hal; hu::usart1.puts("FINDA:"); @@ -150,7 +150,7 @@ void IdleMode::ReportFINDA(const mp::RequestMsg &rq) { modules::serial::WriteToUSART(rsp, len); } -void IdleMode::ReportVersion(const mp::RequestMsg &rq) { +void Application::ReportVersion(const mp::RequestMsg &rq) { uint8_t v = 0; switch (rq.value) { @@ -178,13 +178,13 @@ void IdleMode::ReportVersion(const mp::RequestMsg &rq) { modules::serial::WriteToUSART(rsp, len); } -void IdleMode::ReportRunningCommand() { +void Application::ReportRunningCommand() { uint8_t rsp[maxMsgLen]; uint8_t len = protocol.EncodeResponseQueryOperation(currentCommandRq, RunningCommandStatus(), rsp); modules::serial::WriteToUSART(rsp, len); } -void IdleMode::ProcessRequestMsg(const mp::RequestMsg &rq) { +void Application::ProcessRequestMsg(const mp::RequestMsg &rq) { switch (rq.code) { case mp::RequestMsgCodes::Button: // behave just like if the user pressed a button @@ -225,7 +225,7 @@ void IdleMode::ProcessRequestMsg(const mp::RequestMsg &rq) { } } -bool IdleMode::CheckMsgs() { +bool Application::CheckMsgs() { using mpd = mp::DecodeStatus; while (modules::serial::Available()) { switch (protocol.DecodeRequest(modules::serial::ConsumeByte())) { @@ -244,11 +244,11 @@ bool IdleMode::CheckMsgs() { return false; } -void IdleMode::Panic(ErrorCode ec) { +void Application::Panic(ErrorCode ec) { currentCommand->Panic(ec); } -void IdleMode::Step() { +void Application::Step() { CheckManualOperation(); if (CheckMsgs()) { diff --git a/src/idle_mode.h b/src/application.h similarity index 96% rename from src/idle_mode.h rename to src/application.h index f09e5e6..fe69cf0 100644 --- a/src/idle_mode.h +++ b/src/application.h @@ -9,9 +9,9 @@ namespace logic { class CommandBase; } -class IdleMode { +class Application { public: - IdleMode(); + Application(); inline void CommandFinishedCorrectly() { lastCommandProcessedMs = mt::timebase.Millis(); @@ -55,4 +55,4 @@ private: mp::RequestMsg currentCommandRq; }; -extern IdleMode idleMode; +extern Application application; diff --git a/src/logic/command_base.cpp b/src/logic/command_base.cpp index fe702c0..17d9121 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 "../application.h" #include "../modules/globals.h" #include "../modules/finda.h" #include "../modules/fsensor.h" @@ -210,7 +210,7 @@ void CommandBase::GoToErrEngagingIdler() { void CommandBase::FinishedOK() { state = ProgressCode::OK; error = ErrorCode::OK; - idleMode.CommandFinishedCorrectly(); + application.CommandFinishedCorrectly(); } } // namespace logic diff --git a/src/main.cpp b/src/main.cpp index 3b95aed..b963ee4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ #include "modules/motion.h" #include "modules/usb_cdc.h" -#include "idle_mode.h" +#include "application.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) { - idleMode.Panic(ec); + application.Panic(ec); } /// Main loop of the firmware @@ -130,7 +130,7 @@ void loop() { hal::cpu::Step(); mu::cdc.Step(); - idleMode.Step(); + application.Step(); hal::watchdog::Reset(); } diff --git a/tests/unit/logic/cut_filament/CMakeLists.txt b/tests/unit/logic/cut_filament/CMakeLists.txt index cd0bc5b..d736517 100644 --- a/tests/unit/logic/cut_filament/CMakeLists.txt +++ b/tests/unit/logic/cut_filament/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( cut_filament_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/eject_filament/CMakeLists.txt b/tests/unit/logic/eject_filament/CMakeLists.txt index f52b44e..701239d 100644 --- a/tests/unit/logic/eject_filament/CMakeLists.txt +++ b/tests/unit/logic/eject_filament/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( eject_filament_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/failing_tmc/CMakeLists.txt b/tests/unit/logic/failing_tmc/CMakeLists.txt index 120809f..6e2026f 100644 --- a/tests/unit/logic/failing_tmc/CMakeLists.txt +++ b/tests/unit/logic/failing_tmc/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( failing_tmc_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt index bfea024..2d6e8f0 100644 --- a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt +++ b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( feed_to_bondtech_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/feed_to_finda/CMakeLists.txt b/tests/unit/logic/feed_to_finda/CMakeLists.txt index 04ab858..53741ab 100644 --- a/tests/unit/logic/feed_to_finda/CMakeLists.txt +++ b/tests/unit/logic/feed_to_finda/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( feed_to_finda_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/homing/CMakeLists.txt b/tests/unit/logic/homing/CMakeLists.txt index 138b48e..2856390 100644 --- a/tests/unit/logic/homing/CMakeLists.txt +++ b/tests/unit/logic/homing/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( homing_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/load_filament/CMakeLists.txt b/tests/unit/logic/load_filament/CMakeLists.txt index b5ba667..ae1f669 100644 --- a/tests/unit/logic/load_filament/CMakeLists.txt +++ b/tests/unit/logic/load_filament/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( load_filament_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/tool_change/CMakeLists.txt b/tests/unit/logic/tool_change/CMakeLists.txt index 44c0fa6..86fbe1d 100644 --- a/tests/unit/logic/tool_change/CMakeLists.txt +++ b/tests/unit/logic/tool_change/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( tool_change_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/unload_filament/CMakeLists.txt b/tests/unit/logic/unload_filament/CMakeLists.txt index 9e2b460..b06a670 100644 --- a/tests/unit/logic/unload_filament/CMakeLists.txt +++ b/tests/unit/logic/unload_filament/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( unload_filament_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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 diff --git a/tests/unit/logic/unload_to_finda/CMakeLists.txt b/tests/unit/logic/unload_to_finda/CMakeLists.txt index bc9ed3f..84ba51f 100644 --- a/tests/unit/logic/unload_to_finda/CMakeLists.txt +++ b/tests/unit/logic/unload_to_finda/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( unload_to_finda_tests - ${CMAKE_SOURCE_DIR}/src/idle_mode.cpp + ${CMAKE_SOURCE_DIR}/src/application.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