Rename idle_mode to application

pull/165/head
D.R.racer 2022-05-10 19:52:31 +02:00 committed by DRracer
parent 047c76870c
commit 9c1204dad9
15 changed files with 33 additions and 33 deletions

View File

@ -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) target_link_libraries(firmware LUFA)

View File

@ -1,5 +1,5 @@
/// @file /// @file
#include "idle_mode.h" #include "application.h"
#include "modules/leds.h" #include "modules/leds.h"
#include "modules/globals.h" #include "modules/globals.h"
@ -26,14 +26,14 @@
/// Global instance of the protocol codec /// Global instance of the protocol codec
static mp::Protocol protocol; static mp::Protocol protocol;
IdleMode idleMode; Application application;
IdleMode::IdleMode() Application::Application()
: lastCommandProcessedMs(0) : lastCommandProcessedMs(0)
, currentCommand(&logic::noCommand) , currentCommand(&logic::noCommand)
, currentCommandRq(mp::RequestMsgCodes::Reset, 0) {} , currentCommandRq(mp::RequestMsgCodes::Reset, 0) {}
void IdleMode::CheckManualOperation() { void Application::CheckManualOperation() {
uint16_t ms = mt::timebase.Millis(); uint16_t ms = mt::timebase.Millis();
constexpr uint16_t idleDelay = 1000U; constexpr uint16_t idleDelay = 1000U;
if (ms - lastCommandProcessedMs < idleDelay) { if (ms - lastCommandProcessedMs < idleDelay) {
@ -76,7 +76,7 @@ void IdleMode::CheckManualOperation() {
} }
} }
mp::ResponseCommandStatus IdleMode::RunningCommandStatus() const { mp::ResponseCommandStatus Application::RunningCommandStatus() const {
switch (currentCommand->Error()) { switch (currentCommand->Error()) {
case ErrorCode::RUNNING: case ErrorCode::RUNNING:
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Processing, (uint16_t)currentCommand->State()); 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; 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 tmp[maxMsgLen];
uint8_t len = protocol.EncodeResponseCmdAR(rq, status, tmp); uint8_t len = protocol.EncodeResponseCmdAR(rq, status, tmp);
modules::serial::WriteToUSART(tmp, len); 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) { if (currentCommand->State() == ProgressCode::OK) {
// We are allowed to start a new command as the previous one is in the OK finished state // 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) // 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 #ifdef DEBUG_FINDA
using namespace hal; using namespace hal;
hu::usart1.puts("FINDA:"); hu::usart1.puts("FINDA:");
@ -150,7 +150,7 @@ void IdleMode::ReportFINDA(const mp::RequestMsg &rq) {
modules::serial::WriteToUSART(rsp, len); modules::serial::WriteToUSART(rsp, len);
} }
void IdleMode::ReportVersion(const mp::RequestMsg &rq) { void Application::ReportVersion(const mp::RequestMsg &rq) {
uint8_t v = 0; uint8_t v = 0;
switch (rq.value) { switch (rq.value) {
@ -178,13 +178,13 @@ void IdleMode::ReportVersion(const mp::RequestMsg &rq) {
modules::serial::WriteToUSART(rsp, len); modules::serial::WriteToUSART(rsp, len);
} }
void IdleMode::ReportRunningCommand() { void Application::ReportRunningCommand() {
uint8_t rsp[maxMsgLen]; uint8_t rsp[maxMsgLen];
uint8_t len = protocol.EncodeResponseQueryOperation(currentCommandRq, RunningCommandStatus(), rsp); uint8_t len = protocol.EncodeResponseQueryOperation(currentCommandRq, RunningCommandStatus(), rsp);
modules::serial::WriteToUSART(rsp, len); modules::serial::WriteToUSART(rsp, len);
} }
void IdleMode::ProcessRequestMsg(const mp::RequestMsg &rq) { void Application::ProcessRequestMsg(const mp::RequestMsg &rq) {
switch (rq.code) { switch (rq.code) {
case mp::RequestMsgCodes::Button: case mp::RequestMsgCodes::Button:
// behave just like if the user pressed a 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; using mpd = mp::DecodeStatus;
while (modules::serial::Available()) { while (modules::serial::Available()) {
switch (protocol.DecodeRequest(modules::serial::ConsumeByte())) { switch (protocol.DecodeRequest(modules::serial::ConsumeByte())) {
@ -244,11 +244,11 @@ bool IdleMode::CheckMsgs() {
return false; return false;
} }
void IdleMode::Panic(ErrorCode ec) { void Application::Panic(ErrorCode ec) {
currentCommand->Panic(ec); currentCommand->Panic(ec);
} }
void IdleMode::Step() { void Application::Step() {
CheckManualOperation(); CheckManualOperation();
if (CheckMsgs()) { if (CheckMsgs()) {

View File

@ -9,9 +9,9 @@ namespace logic {
class CommandBase; class CommandBase;
} }
class IdleMode { class Application {
public: public:
IdleMode(); Application();
inline void CommandFinishedCorrectly() { inline void CommandFinishedCorrectly() {
lastCommandProcessedMs = mt::timebase.Millis(); lastCommandProcessedMs = mt::timebase.Millis();
@ -55,4 +55,4 @@ private:
mp::RequestMsg currentCommandRq; mp::RequestMsg currentCommandRq;
}; };
extern IdleMode idleMode; extern Application application;

View File

@ -1,6 +1,6 @@
/// @file command_base.cpp /// @file command_base.cpp
#include "command_base.h" #include "command_base.h"
#include "../idle_mode.h" #include "../application.h"
#include "../modules/globals.h" #include "../modules/globals.h"
#include "../modules/finda.h" #include "../modules/finda.h"
#include "../modules/fsensor.h" #include "../modules/fsensor.h"
@ -210,7 +210,7 @@ void CommandBase::GoToErrEngagingIdler() {
void CommandBase::FinishedOK() { void CommandBase::FinishedOK() {
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
idleMode.CommandFinishedCorrectly(); application.CommandFinishedCorrectly();
} }
} // namespace logic } // namespace logic

View File

@ -25,7 +25,7 @@
#include "modules/motion.h" #include "modules/motion.h"
#include "modules/usb_cdc.h" #include "modules/usb_cdc.h"
#include "idle_mode.h" #include "application.h"
/// One-time setup of HW and SW components /// One-time setup of HW and SW components
/// Called before entering the loop() function /// Called before entering the loop() function
@ -101,7 +101,7 @@ void setup() {
} }
void Panic(ErrorCode ec) { void Panic(ErrorCode ec) {
idleMode.Panic(ec); application.Panic(ec);
} }
/// Main loop of the firmware /// Main loop of the firmware
@ -130,7 +130,7 @@ void loop() {
hal::cpu::Step(); hal::cpu::Step();
mu::cdc.Step(); mu::cdc.Step();
idleMode.Step(); application.Step();
hal::watchdog::Reset(); hal::watchdog::Reset();
} }

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
cut_filament_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
eject_filament_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
failing_tmc_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
feed_to_bondtech_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
feed_to_finda_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
homing_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
load_filament_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
tool_change_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
unload_filament_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp

View File

@ -1,7 +1,7 @@
# define the test executable # define the test executable
add_executable( add_executable(
unload_to_finda_tests 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/command_base.cpp
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp