diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ef94533..a76809c 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -186,7 +186,7 @@ set(headers qrimport.h rotary.h screens.h - serial.h + serial_bobby.h settings.h settingspersister.h settingsutils.h @@ -402,7 +402,7 @@ set(sources qrimport.cpp rotary.cpp screens.cpp - serial.cpp + serial_bobby.cpp settings.cpp settingspersister.cpp settingsutils.cpp diff --git a/main/main.cpp b/main/main.cpp index 3b17cff..b079924 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -122,17 +122,6 @@ extern "C" void app_main() task.setup(); } -#ifdef FEATURE_SERIAL - bootLabel.redraw("front Serial begin"); - controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1); - - bootLabel.redraw("back Serial begin"); - controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2); - - bootLabel.redraw("swap front back"); - updateSwapFrontBack(); -#endif - #ifdef FEATURE_LEDSTRIP bootLabel.redraw("LED strip"); initLedStrip(); @@ -250,11 +239,6 @@ extern "C" void app_main() performance.lastTime = now; } -#ifdef FEATURE_SERIAL - for (Controller &controller : controllers) - controller.parser.update(); -#endif - #ifdef FEATURE_OTA handleOta(); #endif diff --git a/main/serial.cpp b/main/serial.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/serial.h b/main/serial.h deleted file mode 100644 index e69de29..0000000 diff --git a/main/serial_bobby.cpp b/main/serial_bobby.cpp new file mode 100644 index 0000000..088dd0a --- /dev/null +++ b/main/serial_bobby.cpp @@ -0,0 +1,27 @@ +#include "serial_bobby.h" + +// local includes +#include "globals.h" +#include "screens.h" + +#ifdef FEATURE_SERIAL + +void initSerial() +{ + bootLabel.redraw("front Serial begin"); + controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1); + + bootLabel.redraw("back Serial begin"); + controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2); + + bootLabel.redraw("swap front back"); + updateSwapFrontBack(); +} + +void updateSerial() +{ + for (Controller &controller : controllers) + controller.parser.update(); +} + +#endif diff --git a/main/serial_bobby.h b/main/serial_bobby.h new file mode 100644 index 0000000..9436c59 --- /dev/null +++ b/main/serial_bobby.h @@ -0,0 +1,8 @@ +#pragma once + +#ifdef FEATURE_SERIAL + +void initSerial(); +void updateSerial(); + +#endif diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index e8ce310..7b4afcd 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -45,6 +45,9 @@ #include "can.h" #endif #include "debuginputhandler.h" +#ifdef FEATURE_SERIAL +#include "serial_bobby.h" +#endif using namespace std::chrono_literals; @@ -87,6 +90,9 @@ espcpputils::SchedulerTask schedulerTasksArr[] { espcpputils::SchedulerTask { "can", can::initCan, can::parseCanInput, 50ms }, #endif espcpputils::SchedulerTask { "debuginput", initDebugInput, handleDebugInput, 50ms }, +#ifdef FEATURE_SERIAL + espcpputils::SchedulerTask { "serial", initSerial, updateSerial, 50ms }, +#endif }; } // namespace