diff --git a/components/adc/example/main/adc_example.cpp b/components/adc/example/main/adc_example.cpp index b0b2992d4..12b184968 100644 --- a/components/adc/example/main/adc_example.cpp +++ b/components/adc/example/main/adc_example.cpp @@ -51,8 +51,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Oneshot ADC", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Oneshot ADC"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); //! [oneshot adc example] std::this_thread::sleep_for(num_seconds_to_run * 1s); @@ -97,8 +98,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Read ADC", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Read ADC"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); // test stopping and starting the adc diff --git a/components/adc/include/continuous_adc.hpp b/components/adc/include/continuous_adc.hpp index 6caf9bac9..c52232f89 100644 --- a/components/adc/include/continuous_adc.hpp +++ b/components/adc/include/continuous_adc.hpp @@ -63,9 +63,12 @@ class ContinuousAdc : public espp::BaseComponent { // and start the task using namespace std::placeholders; task_ = espp::Task::make_unique( - {.name = "ContinuousAdc Task", - .callback = std::bind(&ContinuousAdc::update_task, this, _1, _2, _3), - .priority = config.task_priority, + {.callback = std::bind(&ContinuousAdc::update_task, this, _1, _2, _3), + .task_config = + { + .name = "ContinuousAdc Task", + .priority = config.task_priority, + }, .log_level = espp::Logger::Verbosity::WARN}); task_->start(); } diff --git a/components/ads1x15/example/main/ads1x15_example.cpp b/components/ads1x15/example/main/ads1x15_example.cpp index d49047f71..08c28319c 100644 --- a/components/ads1x15/example/main/ads1x15_example.cpp +++ b/components/ads1x15/example/main/ads1x15_example.cpp @@ -56,9 +56,12 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto ads_task = espp::Task::make_unique({.name = "ADS", - .callback = ads_read_task_fn, - .stack_size_bytes{4 * 1024}, + auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn, + .task_config = + { + .name = "ADS", + .stack_size_bytes{4 * 1024}, + }, .log_level = espp::Logger::Verbosity::INFO}); ads_task->start(); //! [ads1x15 example] diff --git a/components/ads7138/example/main/ads7138_example.cpp b/components/ads7138/example/main/ads7138_example.cpp index 9d820a22e..ba35e67b5 100644 --- a/components/ads7138/example/main/ads7138_example.cpp +++ b/components/ads7138/example/main/ads7138_example.cpp @@ -124,8 +124,7 @@ extern "C" void app_main(void) { gpio_isr_handler_add(ALERT_PIN, gpio_isr_handler, (void *)ALERT_PIN); // start the gpio task - auto alert_task = espp::Task::make_unique(espp::Task::Config{ - .name = "alert", + auto alert_task = espp::Task::make_unique({ .callback = [&ads](auto &m, auto &cv) -> bool { static uint32_t io_num; // block until we get a message from the interrupt handler @@ -156,7 +155,11 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }, - .stack_size_bytes = 4 * 1024, + .task_config = + { + .name = "alert", + .stack_size_bytes = 4 * 1024, + }, }); alert_task->start(); @@ -241,9 +244,12 @@ extern "C" void app_main(void) { return false; }; - auto ads_task = espp::Task::make_unique({.name = "ADS", - .callback = ads_read_task_fn, - .stack_size_bytes{8 * 1024}, + auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn, + .task_config = + { + .name = "ADS", + .stack_size_bytes{8 * 1024}, + }, .log_level = espp::Logger::Verbosity::INFO}); ads_task->start(); //! [ads7138 example] diff --git a/components/as5600/example/main/as5600_example.cpp b/components/as5600/example/main/as5600_example.cpp index 0964695cc..2a2b32a42 100644 --- a/components/as5600/example/main/as5600_example.cpp +++ b/components/as5600/example/main/as5600_example.cpp @@ -61,9 +61,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "As5600 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "As5600 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("%time(s), count, radians, degrees, rpm\n"); task.start(); diff --git a/components/as5600/include/as5600.hpp b/components/as5600/include/as5600.hpp index d3abeb90e..c2f869a40 100644 --- a/components/as5600/include/as5600.hpp +++ b/components/as5600/include/as5600.hpp @@ -238,8 +238,10 @@ class As5600 : public BasePeripheral<> { accumulator_ = count; // start the task using namespace std::placeholders; - task_ = Task::make_unique( - {.name = "As5600", .callback = std::bind(&As5600::update_task, this, _1, _2, _3)}); + task_ = Task::make_unique({ + .callback = std::bind(&As5600::update_task, this, _1, _2, _3), + .task_config = {.name = "As5600"}, + }); task_->start(); } diff --git a/components/aw9523/example/main/aw9523_example.cpp b/components/aw9523/example/main/aw9523_example.cpp index 2d7db00e8..d2b5ae57c 100644 --- a/components/aw9523/example/main/aw9523_example.cpp +++ b/components/aw9523/example/main/aw9523_example.cpp @@ -118,9 +118,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Aw9523 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Aw9523 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("%time(s), pin values, r, g, b\n"); task.start(); diff --git a/components/bldc_haptics/include/bldc_haptics.hpp b/components/bldc_haptics/include/bldc_haptics.hpp index a9905f52b..ac5c27194 100644 --- a/components/bldc_haptics/include/bldc_haptics.hpp +++ b/components/bldc_haptics/include/bldc_haptics.hpp @@ -135,10 +135,13 @@ template class BldcHaptics : public BaseComponent { motor_.get().set_motion_control_type(detail::MotionControlType::TORQUE); // create the motor task motor_task_ = Task::make_unique( - {.name = "haptic_motor", - .callback = std::bind(&BldcHaptics::motor_task, this, std::placeholders::_1, + {.callback = std::bind(&BldcHaptics::motor_task, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), - .stack_size_bytes = 1024 * 6, + .task_config = + { + .name = "haptic_motor", + .stack_size_bytes = 1024 * 6, + }, .log_level = Logger::Verbosity::WARN}); } diff --git a/components/bldc_motor/example/main/bldc_motor_example.cpp b/components/bldc_motor/example/main/bldc_motor_example.cpp index e76866f56..f2c0d269c 100644 --- a/components/bldc_motor/example/main/bldc_motor_example.cpp +++ b/components/bldc_motor/example/main/bldc_motor_example.cpp @@ -182,8 +182,8 @@ extern "C" void app_main(void) { return false; }; auto target_task = espp::Task({ - .name = "Target Task", .callback = target_task_fn, + .task_config = {.name = "Target Task"}, }); target_task.start(); @@ -218,9 +218,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Logging Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Logging Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); if (motion_control_type == espp::detail::MotionControlType::VELOCITY || motion_control_type == espp::detail::MotionControlType::VELOCITY_OPENLOOP) { diff --git a/components/bm8563/example/main/bm8563_example.cpp b/components/bm8563/example/main/bm8563_example.cpp index e8b1428ad..99c4a1d5d 100644 --- a/components/bm8563/example/main/bm8563_example.cpp +++ b/components/bm8563/example/main/bm8563_example.cpp @@ -67,8 +67,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "BM8563 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "BM8563 Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [bm8563 example] while (true) { diff --git a/components/chsc6x/example/main/chsc6x_example.cpp b/components/chsc6x/example/main/chsc6x_example.cpp index fc174dd37..28e8911dd 100644 --- a/components/chsc6x/example/main/chsc6x_example.cpp +++ b/components/chsc6x/example/main/chsc6x_example.cpp @@ -64,8 +64,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "Chsc6x Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Chsc6x Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [chsc6x example] while (true) { diff --git a/components/controller/example/main/controller_example.cpp b/components/controller/example/main/controller_example.cpp index 8286ec0dd..c36c2cc99 100644 --- a/components/controller/example/main/controller_example.cpp +++ b/components/controller/example/main/controller_example.cpp @@ -52,9 +52,12 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task({.name = "Controller Task", - .callback = task_fn, - .stack_size_bytes = 6 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Controller Task", + .stack_size_bytes = 6 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [digital controller example] @@ -155,9 +158,12 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task({.name = "Controller Task", - .callback = task_fn, - .stack_size_bytes = 6 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Controller Task", + .stack_size_bytes = 6 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [analog controller example] @@ -217,9 +223,12 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto ads_task = espp::Task::make_unique({.name = "ADS", - .callback = ads_read_task_fn, - .stack_size_bytes{4 * 1024}, + auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn, + .task_config = + { + .name = "ADS Task", + .stack_size_bytes{4 * 1024}, + }, .log_level = espp::Logger::Verbosity::INFO}); ads_task->start(); // make the read joystick function used by the controller @@ -285,9 +294,12 @@ extern "C" void app_main(void) { // we don't want to stop, return false return false; }; - auto task = espp::Task({.name = "Controller Task", - .callback = task_fn, - .stack_size_bytes = 6 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Controller Task", + .stack_size_bytes = 6 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [i2c analog controller example] diff --git a/components/cst816/example/main/cst816_example.cpp b/components/cst816/example/main/cst816_example.cpp index e76cba937..66e60ac1c 100644 --- a/components/cst816/example/main/cst816_example.cpp +++ b/components/cst816/example/main/cst816_example.cpp @@ -67,8 +67,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "Cst816 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Cst816 Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [cst816 example] while (true) { diff --git a/components/display_drivers/example/main/gui.hpp b/components/display_drivers/example/main/gui.hpp index a6bffb2d9..fedd13d14 100644 --- a/components/display_drivers/example/main/gui.hpp +++ b/components/display_drivers/example/main/gui.hpp @@ -18,9 +18,9 @@ class Gui { init_ui(); // now start the gui updater task using namespace std::placeholders; - task_ = espp::Task::make_unique({.name = "Gui Task", - .callback = std::bind(&Gui::update, this, _1, _2, _3), - .stack_size_bytes = 6 * 1024}); + task_ = espp::Task::make_unique( + {.callback = std::bind(&Gui::update, this, _1, _2, _3), + .task_config = {.name = "Gui Task", .stack_size_bytes = 6 * 1024}}); task_->start(); } diff --git a/components/drv2605/example/main/drv2605_example.cpp b/components/drv2605/example/main/drv2605_example.cpp index c171dab30..c09573a26 100644 --- a/components/drv2605/example/main/drv2605_example.cpp +++ b/components/drv2605/example/main/drv2605_example.cpp @@ -80,9 +80,12 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task::make_unique({.name = "example", - .callback = task_fn, - .stack_size_bytes{4 * 1024}, + auto task = espp::Task::make_unique({.callback = task_fn, + .task_config = + { + .name = "example", + .stack_size_bytes{4 * 1024}, + }, .log_level = espp::Logger::Verbosity::INFO}); task->start(); //! [drv2605 example] diff --git a/components/encoder/example/main/encoder_example.cpp b/components/encoder/example/main/encoder_example.cpp index bc326e130..8afa59189 100644 --- a/components/encoder/example/main/encoder_example.cpp +++ b/components/encoder/example/main/encoder_example.cpp @@ -34,8 +34,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Abi Encoder", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Abi Encoder"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); //! [abi encoder rotational example] std::this_thread::sleep_for(num_seconds_to_run * 1s); @@ -64,8 +65,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Abi Encoder", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Abi Encoder"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); //! [abi encoder linear example] std::this_thread::sleep_for(num_seconds_to_run * 1s); diff --git a/components/esp-box/src/esp-box.cpp b/components/esp-box/src/esp-box.cpp index 49cc991fb..db9a340e2 100644 --- a/components/esp-box/src/esp-box.cpp +++ b/components/esp-box/src/esp-box.cpp @@ -620,11 +620,14 @@ bool EspBox::initialize_sound(uint32_t default_audio_rate) { using namespace std::placeholders; audio_task_ = std::make_unique(espp::Task::Config{ - .name = "audio task", .callback = std::bind(&EspBox::audio_task_callback, this, _1, _2, _3), - .stack_size_bytes = 1024 * 4, - .priority = 19, - .core_id = 1, + .task_config = + { + .name = "audio task", + .stack_size_bytes = 1024 * 4, + .priority = 19, + .core_id = 1, + }, }); audio_task_->start(); diff --git a/components/esp32-timer-cam/src/esp32-timer-cam.cpp b/components/esp32-timer-cam/src/esp32-timer-cam.cpp index b2f8558d7..727e5394f 100644 --- a/components/esp32-timer-cam/src/esp32-timer-cam.cpp +++ b/components/esp32-timer-cam/src/esp32-timer-cam.cpp @@ -22,8 +22,8 @@ bool EspTimerCam::initialize_led(float breathing_period) { }); using namespace std::placeholders; led_task_ = espp::Task::make_unique( - {.name = "breathe", - .callback = std::bind(&EspTimerCam::led_task_callback, this, _1, _2, _3)}); + {.callback = std::bind(&EspTimerCam::led_task_callback, this, _1, _2, _3), + .task_config = {.name = "breathe"}}); set_led_breathing_period(breathing_period); return true; } diff --git a/components/event_manager/example/main/event_manager_example.cpp b/components/event_manager/example/main/event_manager_example.cpp index 03cd70d18..27cc38ce7 100644 --- a/components/event_manager/example/main/event_manager_example.cpp +++ b/components/event_manager/example/main/event_manager_example.cpp @@ -91,7 +91,7 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task1 = espp::Task({.name = "Task 1", .callback = task_1_fn}); + auto task1 = espp::Task({.callback = task_1_fn, .task_config = {.name = "Task 1"}}); // Now let's make another task which will have pub/sub as well auto task_2_fn = [&](auto &m, auto &cv) { @@ -160,7 +160,7 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task2 = espp::Task({.name = "Task 2", .callback = task_2_fn}); + auto task2 = espp::Task({.callback = task_2_fn, .task_config = {.name = "Task 2"}}); // now start the tasks task1.start(); diff --git a/components/filters/example/main/filters_example.cpp b/components/filters/example/main/filters_example.cpp index 78a509788..d3c9f514a 100644 --- a/components/filters/example/main/filters_example.cpp +++ b/components/filters/example/main/filters_example.cpp @@ -62,8 +62,8 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Lowpass Filter", - .callback = task_fn, + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Lowpass Filter"}, .log_level = espp::Logger::Verbosity::INFO}); fmt::print("% time (s), input, simple_lpf_output, lpf_output, " "bwf_df1_o1_output, bwf_df1_o2_output, bwf_df2_o2_output, " diff --git a/components/ft5x06/example/main/ft5x06_example.cpp b/components/ft5x06/example/main/ft5x06_example.cpp index b659802f4..1c19e523d 100644 --- a/components/ft5x06/example/main/ft5x06_example.cpp +++ b/components/ft5x06/example/main/ft5x06_example.cpp @@ -49,8 +49,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "Ft5x06 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Ft5x06 Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [ft5x06 example] while (true) { diff --git a/components/ftp/include/ftp_client_session.hpp b/components/ftp/include/ftp_client_session.hpp index da69eade1..4537627ed 100644 --- a/components/ftp/include/ftp_client_session.hpp +++ b/components/ftp/include/ftp_client_session.hpp @@ -41,9 +41,12 @@ class FtpClientSession : public BaseComponent { send_welcome_message(); using namespace std::placeholders; task_ = std::make_unique(Task::Config{ - .name = "FtpClientSession", .callback = std::bind(&FtpClientSession::task_function, this, _1, _2, _3), - .stack_size_bytes = 1024 * 6, + .task_config = + { + .name = "FtpClientSession", + .stack_size_bytes = 1024 * 6, + }, .log_level = Logger::Verbosity::WARN, }); task_->start(); diff --git a/components/ftp/include/ftp_server.hpp b/components/ftp/include/ftp_server.hpp index 33c64974a..f6e9acd56 100644 --- a/components/ftp/include/ftp_server.hpp +++ b/components/ftp/include/ftp_server.hpp @@ -64,9 +64,12 @@ class FtpServer : public BaseComponent { using namespace std::placeholders; accept_task_ = std::make_unique(Task::Config{ - .name = "FtpServer::accept_task", .callback = std::bind(&FtpServer::accept_task_function, this, _1, _2, _3), - .stack_size_bytes = 1024 * 4, + .task_config = + { + .name = "FtpServer::accept_task", + .stack_size_bytes = 1024 * 4, + }, .log_level = Logger::Verbosity::WARN, }); accept_task_->start(); diff --git a/components/gt911/example/main/gt911_example.cpp b/components/gt911/example/main/gt911_example.cpp index 342a01cca..158daa694 100644 --- a/components/gt911/example/main/gt911_example.cpp +++ b/components/gt911/example/main/gt911_example.cpp @@ -71,8 +71,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "Gt911 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Gt911 Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [gt911 example] while (true) { diff --git a/components/joystick/example/main/joystick_example.cpp b/components/joystick/example/main/joystick_example.cpp index 6d6fc1832..dfabc718f 100644 --- a/components/joystick/example/main/joystick_example.cpp +++ b/components/joystick/example/main/joystick_example.cpp @@ -107,8 +107,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Joystick", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Joystick"}, + .log_level = espp::Logger::Verbosity::INFO}); fmt::print("js1 x, js1 y, js2 x, js2 y\n"); task.start(); //! [adc joystick example] diff --git a/components/kts1622/example/main/kts1622_example.cpp b/components/kts1622/example/main/kts1622_example.cpp index 90db04b2e..526f9fe2d 100644 --- a/components/kts1622/example/main/kts1622_example.cpp +++ b/components/kts1622/example/main/kts1622_example.cpp @@ -75,9 +75,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Kts1622 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Kts1622 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("% time(s), pin values\n"); task.start(); diff --git a/components/led/example/main/led_example.cpp b/components/led/example/main/led_example.cpp index 59ce0371c..2e48d819f 100644 --- a/components/led/example/main/led_example.cpp +++ b/components/led/example/main/led_example.cpp @@ -83,7 +83,8 @@ extern "C" void app_main(void) { cv.wait_for(lk, 10ms); return false; }; - auto led_task = espp::Task::make_unique({.name = "breathe", .callback = led_callback}); + auto led_task = + espp::Task::make_unique({.callback = led_callback, .task_config = {.name = "breathe"}}); led_task->start(); float wait_time = num_periods_to_run * breathing_period; fmt::print("Sleeping for {:.1f}s...\n", wait_time); diff --git a/components/led_strip/example/main/led_strip_example.cpp b/components/led_strip/example/main/led_strip_example.cpp index e1fbcc921..03f89d3c4 100644 --- a/components/led_strip/example/main/led_strip_example.cpp +++ b/components/led_strip/example/main/led_strip_example.cpp @@ -177,9 +177,12 @@ extern "C" void app_main(void) { return false; }; - auto task = espp::Task({.name = "LedStrip Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "LedStrip Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [led strip ex1] diff --git a/components/max1704x/example/main/max1704x_example.cpp b/components/max1704x/example/main/max1704x_example.cpp index a3a5afc6b..30ace18f6 100644 --- a/components/max1704x/example/main/max1704x_example.cpp +++ b/components/max1704x/example/main/max1704x_example.cpp @@ -58,9 +58,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Max1704x Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Max1704x Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("%time(s), voltage (V), SoC (%), Charge Rate (%/hr)\n"); task.start(); diff --git a/components/mcp23x17/example/main/mcp23x17_example.cpp b/components/mcp23x17/example/main/mcp23x17_example.cpp index 5afccbdd3..33c05f35e 100644 --- a/components/mcp23x17/example/main/mcp23x17_example.cpp +++ b/components/mcp23x17/example/main/mcp23x17_example.cpp @@ -81,9 +81,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Mcp23x17 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Mcp23x17 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("%time(s), port_a pins, port_b pins\n"); task.start(); diff --git a/components/monitor/example/main/monitor_example.cpp b/components/monitor/example/main/monitor_example.cpp index b5434c695..a03e8478d 100644 --- a/components/monitor/example/main/monitor_example.cpp +++ b/components/monitor/example/main/monitor_example.cpp @@ -34,9 +34,9 @@ extern "C" void app_main(void) { tasks.resize(num_tasks); for (size_t i = 0; i < num_tasks; i++) { std::string task_name = fmt::format("Task {}", i); - auto task = espp::Task::make_unique({.name = task_name, - .callback = std::bind(task_fn, i, _1, _2, _3), - .stack_size_bytes = 5 * 1024}); + auto task = espp::Task::make_unique( + {.callback = std::bind(task_fn, i, _1, _2, _3), + .task_config = {.name = task_name, .stack_size_bytes = 5 * 1024}}); tasks[i] = std::move(task); tasks[i]->start(); } @@ -64,9 +64,9 @@ extern "C" void app_main(void) { tasks.resize(num_tasks); for (size_t i = 0; i < num_tasks; i++) { std::string task_name = fmt::format("Task {}", i); - auto task = espp::Task::make_unique({.name = task_name, - .callback = std::bind(task_fn, i, _1, _2, _3), - .stack_size_bytes = 5 * 1024}); + auto task = espp::Task::make_unique( + {.callback = std::bind(task_fn, i, _1, _2, _3), + .task_config = {.name = task_name, .stack_size_bytes = 5 * 1024}}); tasks[i] = std::move(task); tasks[i]->start(); } @@ -98,9 +98,9 @@ extern "C" void app_main(void) { tasks.resize(num_tasks); for (size_t i = 0; i < num_tasks; i++) { std::string task_name = fmt::format("Task {}", i); - auto task = espp::Task::make_unique({.name = task_name, - .callback = std::bind(task_fn, i, _1, _2, _3), - .stack_size_bytes = 5 * 1024}); + auto task = espp::Task::make_unique( + {.callback = std::bind(task_fn, i, _1, _2, _3), + .task_config = {.name = task_name, .stack_size_bytes = 5 * 1024}}); tasks[i] = std::move(task); tasks[i]->start(); } diff --git a/components/monitor/include/task_monitor.hpp b/components/monitor/include/task_monitor.hpp index 672ee44d9..61c785724 100644 --- a/components/monitor/include/task_monitor.hpp +++ b/components/monitor/include/task_monitor.hpp @@ -67,9 +67,11 @@ class TaskMonitor : public BaseComponent { , period_(config.period) { #if CONFIG_FREERTOS_USE_TRACE_FACILITY && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS using namespace std::placeholders; - task_ = Task::make_unique({.name = "TaskMonitor Task", - .callback = std::bind(&TaskMonitor::task_callback, this, _1, _2, _3), - .stack_size_bytes = config.task_stack_size_bytes}); + task_ = Task::make_unique( + {.callback = std::bind(&TaskMonitor::task_callback, this, _1, _2, _3), .task_config = { + .name = "TaskMonitor Task", + .stack_size_bytes = config.task_stack_size_bytes, + }}); task_->start(); #else logger_.warn("Project was not built with " diff --git a/components/motorgo-mini/example/main/motorgo_mini_example.cpp b/components/motorgo-mini/example/main/motorgo_mini_example.cpp index 49a7be0f8..3b4ae10ad 100644 --- a/components/motorgo-mini/example/main/motorgo_mini_example.cpp +++ b/components/motorgo-mini/example/main/motorgo_mini_example.cpp @@ -114,9 +114,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto logging_task = espp::Task({.name = "Logging Task", - .callback = logging_fn, - .stack_size_bytes = 5 * 1024, + auto logging_task = espp::Task({.callback = logging_fn, + .task_config = + { + .name = "Logging Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); logging_task.start(); @@ -161,8 +164,8 @@ extern "C" void app_main(void) { return false; }; auto target_task = espp::Task({ - .name = "Target Task", .callback = target_task_fn, + .task_config = {.name = "Target Task"}, }); target_task.start(); diff --git a/components/mt6701/example/main/mt6701_example.cpp b/components/mt6701/example/main/mt6701_example.cpp index 3c3127aaa..88f8c5e7a 100644 --- a/components/mt6701/example/main/mt6701_example.cpp +++ b/components/mt6701/example/main/mt6701_example.cpp @@ -72,9 +72,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Mt6701 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Mt6701 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("% time(s), count, radians, degrees, rpm\n"); task.start(); @@ -197,9 +200,12 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task({.name = "Mt6701 Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Mt6701 Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); fmt::print("% time(s), count, radians, degrees, rpm\n"); task.start(); diff --git a/components/pid/example/main/pid_example.cpp b/components/pid/example/main/pid_example.cpp index 1ebb71458..dc2d79596 100644 --- a/components/pid/example/main/pid_example.cpp +++ b/components/pid/example/main/pid_example.cpp @@ -56,8 +56,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "PID Update", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "PID Update"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); for (int i = 0; i < num_seconds_to_run; i++) { // change PID gains here diff --git a/components/qwiicnes/example/main/qwiicnes_example.cpp b/components/qwiicnes/example/main/qwiicnes_example.cpp index 77ac31ca1..be4ae4dee 100644 --- a/components/qwiicnes/example/main/qwiicnes_example.cpp +++ b/components/qwiicnes/example/main/qwiicnes_example.cpp @@ -51,8 +51,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "Qwiicnes Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Qwiicnes Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [qwiicnes example] while (!quit_test) { diff --git a/components/rmt/example/main/rmt_example.cpp b/components/rmt/example/main/rmt_example.cpp index bcee632d8..1fdd63020 100644 --- a/components/rmt/example/main/rmt_example.cpp +++ b/components/rmt/example/main/rmt_example.cpp @@ -144,9 +144,12 @@ extern "C" void app_main(void) { return false; }; - auto task = espp::Task({.name = "Rmt Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "Rmt Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [rmt example] diff --git a/components/rtsp/src/rtsp_server.cpp b/components/rtsp/src/rtsp_server.cpp index 7c605f7ae..dabe8db8c 100644 --- a/components/rtsp/src/rtsp_server.cpp +++ b/components/rtsp/src/rtsp_server.cpp @@ -47,9 +47,12 @@ bool RtspServer::start() { using namespace std::placeholders; accept_task_ = std::make_unique(Task::Config{ - .name = "RTSP Accept Task", .callback = std::bind(&RtspServer::accept_task_function, this, _1, _2, _3), - .stack_size_bytes = 6 * 1024, + .task_config = + { + .name = "RTSP Accept Task", + .stack_size_bytes = 6 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN, }); accept_task_->start(); @@ -180,9 +183,12 @@ bool RtspServer::accept_task_function(std::mutex &m, std::condition_variable &cv if (!session_task_ || !session_task_->is_started()) { logger_.info("Starting session task"); session_task_ = std::make_unique(Task::Config{ - .name = "RtspSessionTask", .callback = std::bind(&RtspServer::session_task_function, this, _1, _2, _3), - .stack_size_bytes = 6 * 1024, + .task_config = + { + .name = "RtspSessionTask", + .stack_size_bytes = 6 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN, }); session_task_->start(); diff --git a/components/rtsp/src/rtsp_session.cpp b/components/rtsp/src/rtsp_session.cpp index 2b2e8dd79..40802a51b 100644 --- a/components/rtsp/src/rtsp_session.cpp +++ b/components/rtsp/src/rtsp_session.cpp @@ -16,9 +16,12 @@ RtspSession::RtspSession(std::unique_ptr control_socket, const Config // start the session task to handle RTSP commands using namespace std::placeholders; control_task_ = std::make_unique(Task::Config{ - .name = "RtspSession " + std::to_string(session_id_), .callback = std::bind(&RtspSession::control_task_fn, this, _1, _2, _3), - .stack_size_bytes = 6 * 1024, + .task_config = + { + .name = "RtspSession " + std::to_string(session_id_), + .stack_size_bytes = 6 * 1024, + }, .log_level = Logger::Verbosity::WARN, }); control_task_->start(); diff --git a/components/socket/example/main/socket_example.cpp b/components/socket/example/main/socket_example.cpp index 47ba843be..43693f094 100644 --- a/components/socket/example/main/socket_example.cpp +++ b/components/socket/example/main/socket_example.cpp @@ -77,8 +77,9 @@ auto client_task_fn = [&server_address, &client_socket, &port](auto &, auto &) { // don't want to stop the task return false; }; -auto client_task = espp::Task::make_unique( - {.name = "Client Task", .callback = client_task_fn, .stack_size_bytes = 5 * 1024}); +auto client_task = + espp::Task::make_unique({.callback = client_task_fn, + .task_config = {.name = "Client Task", .stack_size_bytes = 5 * 1024}}); client_task->start(); //! [UDP Client example] // now sleep for a while to let the monitor do its thing @@ -137,8 +138,9 @@ auto client_task_fn = [&server_address, &client_socket, &port](auto &, auto &) { // don't want to stop the task return false; }; -auto client_task = espp::Task::make_unique( - {.name = "Client Task", .callback = client_task_fn, .stack_size_bytes = 5 * 1024}); +auto client_task = + espp::Task::make_unique({.callback = client_task_fn, + .task_config = {.name = "Client Task", .stack_size_bytes = 5 * 1024}}); client_task->start(); //! [UDP Client Response example] // now sleep for a while to let the monitor do its thing @@ -202,8 +204,9 @@ auto client_task_fn = [&client_socket, &port, &multicast_group](auto &, auto &) // don't want to stop the task return false; }; -auto client_task = espp::Task::make_unique( - {.name = "Client Task", .callback = client_task_fn, .stack_size_bytes = 5 * 1024}); +auto client_task = + espp::Task::make_unique({.callback = client_task_fn, + .task_config = {.name = "Client Task", .stack_size_bytes = 5 * 1024}}); client_task->start(); //! [UDP Multicast Client example] // now sleep for a while to let the monitor do its thing @@ -248,9 +251,12 @@ fmt::print(fg(fmt::terminal_color::yellow) | fmt::emphasis::bold, "Staring Basic }; auto server_task_config = espp::Task::Config{ - .name = "TcpServer", .callback = server_task_fn, - .stack_size_bytes = 6 * 1024, + .task_config = + { + .name = "TcpServer", + .stack_size_bytes = 6 * 1024, + }, }; auto server_task = espp::Task::make_unique(server_task_config); server_task->start(); @@ -272,7 +278,8 @@ fmt::print(fg(fmt::terminal_color::yellow) | fmt::emphasis::bold, "Staring Basic return false; }; auto client_task = espp::Task::make_unique( - {.name = "Client Task", .callback = client_task_fn, .stack_size_bytes = 5 * 1024}); + {.callback = client_task_fn, + .task_config = {.name = "Client Task", .stack_size_bytes = 5 * 1024}}); client_task->start(); //! [TCP Client example] // now sleep for a while to let the monitor do its thing @@ -322,9 +329,12 @@ fmt::print(fg(fmt::terminal_color::yellow) | fmt::emphasis::bold, }; auto server_task_config = espp::Task::Config{ - .name = "TcpServer", .callback = server_task_fn, - .stack_size_bytes = 6 * 1024, + .task_config = + { + .name = "TcpServer", + .stack_size_bytes = 6 * 1024, + }, }; auto server_task = espp::Task::make_unique(server_task_config); server_task->start(); @@ -356,7 +366,8 @@ fmt::print(fg(fmt::terminal_color::yellow) | fmt::emphasis::bold, return false; }; auto client_task = espp::Task::make_unique( - {.name = "Client Task", .callback = client_task_fn, .stack_size_bytes = 5 * 1024}); + {.callback = client_task_fn, + .task_config = {.name = "Client Task", .stack_size_bytes = 5 * 1024}}); client_task->start(); //! [TCP Client Response example] // now sleep for a while to let the monitor do its thing diff --git a/components/socket/include/udp_socket.hpp b/components/socket/include/udp_socket.hpp index bbf5095fa..38bd75c7c 100644 --- a/components/socket/include/udp_socket.hpp +++ b/components/socket/include/udp_socket.hpp @@ -132,7 +132,7 @@ class UdpSocket : public Socket { * @brief Configure a server socket and start a thread to continuously * receive and handle data coming in on that socket. * - * @param task_config Task::Config struct for configuring the receive task. + * @param task_config Task::BaseConfig struct for configuring the receive task. * @param receive_config ReceiveConfig struct with socket and callback info. * @return true if the socket was created and task was started, false otherwise. */ diff --git a/components/st25dv/example/main/st25dv_example.cpp b/components/st25dv/example/main/st25dv_example.cpp index e92ba6c92..51e4cecc6 100644 --- a/components/st25dv/example/main/st25dv_example.cpp +++ b/components/st25dv/example/main/st25dv_example.cpp @@ -152,9 +152,12 @@ extern "C" void app_main(void) { // we don't want to stop the task, so return false return false; }; - auto task = espp::Task({.name = "St25dv Task", - .callback = task_fn, - .stack_size_bytes = 5 * 1024, + auto task = espp::Task({.callback = task_fn, + .task_config = + { + .name = "St25dv Task", + .stack_size_bytes = 5 * 1024, + }, .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [st25dv example] diff --git a/components/state_machine/example/main/hfsm_example.cpp b/components/state_machine/example/main/hfsm_example.cpp index a70d0165a..c9745ba0b 100644 --- a/components/state_machine/example/main/hfsm_example.cpp +++ b/components/state_machine/example/main/hfsm_example.cpp @@ -57,8 +57,9 @@ extern "C" void app_main(void) { // stop the task if the hfsm has stopped (reached its end state) return complex_root.has_stopped(); }; - auto task = espp::Task( - {.name = "HFSM", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "HFSM"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); // from other contexts you can spawn events into the HFSM. the functions are @@ -125,8 +126,9 @@ extern "C" void app_main(void) { // stop the task if the hfsm has stopped (reached its end state) return complex_root.has_stopped(); }; - auto task = espp::Task( - {.name = "HFSM", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "HFSM"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); // NOTE: this is just a copy of the HFSM code from the generated test bench, diff --git a/components/t_keyboard/include/t_keyboard.hpp b/components/t_keyboard/include/t_keyboard.hpp index fbc31f431..6750285b4 100644 --- a/components/t_keyboard/include/t_keyboard.hpp +++ b/components/t_keyboard/include/t_keyboard.hpp @@ -61,9 +61,12 @@ class TKeyboard : public BasePeripheral<> { logger_.info("TKeyboard created"); using namespace std::placeholders; task_ = std::make_shared(espp::Task::Config{ - .name = "tkeyboard_task", .callback = std::bind(&TKeyboard::key_task, this, _1, _2, _3), - .stack_size_bytes = 4 * 1024, + .task_config = + { + .name = "tkeyboard_task", + .stack_size_bytes = 4 * 1024, + }, }); if (config.auto_start) { start(); diff --git a/components/task/example/main/task_example.cpp b/components/task/example/main/task_example.cpp index f96b2bf63..bbf27dfc8 100644 --- a/components/task/example/main/task_example.cpp +++ b/components/task/example/main/task_example.cpp @@ -65,8 +65,9 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task( - {.name = "Task 1", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Task 1"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); task.start_watchdog(); // start the watchdog timer for this task std::this_thread::sleep_for(num_seconds_to_run * 1s); @@ -110,8 +111,9 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task( - {.name = "Task 1", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Task 1"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); task.start_watchdog(); // start the watchdog timer for this task std::this_thread::sleep_for(500ms); @@ -162,7 +164,8 @@ extern "C" void app_main(void) { return false; }; std::string task_name = fmt::format("Task {}", i); - auto task = espp::Task::make_unique({.name = task_name, .callback = task_fn}); + auto task = + espp::Task::make_unique({.callback = task_fn, .task_config = {.name = task_name}}); tasks[i] = std::move(task); tasks[i]->start(); } @@ -200,7 +203,7 @@ extern "C" void app_main(void) { return false; }; std::string task_name = fmt::format("Task {}", i); - auto task = espp::Task::make_unique(espp::Task::AdvancedConfig{ + auto task = espp::Task::make_unique({ .callback = task_fn, .task_config = { @@ -261,8 +264,9 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task( - {.name = "Complex Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Complex Task"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); //! [LongRunningTask example] std::this_thread::sleep_for(num_seconds_to_run * 1s); @@ -313,8 +317,8 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task({.name = "Notified Complex Task", - .callback = task_fn, + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Notified Complex Task"}, .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); //! [LongRunningTaskNotified example] @@ -349,8 +353,9 @@ extern "C" void app_main(void) { // we don't want to stop, so return false return false; }; - auto task = espp::Task( - {.name = "DynamicTask", .callback = task_fn, .log_level = espp::Logger::Verbosity::DEBUG}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "DynamicTask"}, + .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); auto now = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration(now - test_start).count(); @@ -391,8 +396,8 @@ extern "C" void app_main(void) { // we don't want to stop yet, so return false return false; }; - auto task = espp::Task({.name = "AutoStop Task", - .callback = task_fn, + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "AutoStop Task"}, .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); while (task.is_started()) { @@ -432,8 +437,8 @@ extern "C" void app_main(void) { // we don't want to stop yet, so return false return false; }; - auto task = espp::Task({.name = "AutoStop Task", - .callback = task_fn, + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "AutoStop Task"}, .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); while (task.is_started()) { @@ -478,8 +483,8 @@ extern "C" void app_main(void) { // we don't want to stop yet, so return false return false; }; - auto task = espp::Task({.name = "Multithreaded Stop Task", - .callback = task_fn, + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Multithreaded Stop Task"}, .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); auto stop_fn = [&task]() { @@ -513,8 +518,7 @@ extern "C" void app_main(void) { logger.info("Task Request Stop From Within Task example"); //! [Task Request Stop From Within Task example] espp::Task task = - espp::Task({.name = "Self Stopping Task", - .callback = + espp::Task({.callback = [&num_seconds_to_run, &task](std::mutex &m, std::condition_variable &cv) { static auto begin = std::chrono::high_resolution_clock::now(); auto now = std::chrono::high_resolution_clock::now(); @@ -537,7 +541,7 @@ extern "C" void app_main(void) { // we don't want to stop yet, so return false return false; }, - + .task_config = {.name = "Self Stopping Task"}, .log_level = espp::Logger::Verbosity::DEBUG}); task.start(); while (task.is_started()) { diff --git a/components/task/include/run_on_core.hpp b/components/task/include/run_on_core.hpp index 5a240eec4..ce8b15d1d 100644 --- a/components/task/include/run_on_core.hpp +++ b/components/task/include/run_on_core.hpp @@ -42,8 +42,7 @@ static auto run_on_core(const auto &f, int core_id, size_t stack_size_bytes = 20 if constexpr (!std::is_void_v) { // the function returns something decltype(f()) ret_val; - auto f_task = espp::Task::make_unique(espp::Task::Config{ - .name = name, + auto f_task = espp::Task::make_unique({ .callback = [&mutex, &cv, &f, &ret_val, ¬ified](auto &cb_m, auto &cb_cv) -> bool { // synchronize with the main thread - block here until the main thread // waits on the condition variable (cv), then run the function @@ -55,17 +54,20 @@ static auto run_on_core(const auto &f, int core_id, size_t stack_size_bytes = 20 cv.notify_all(); return true; // stop the task }, - .stack_size_bytes = stack_size_bytes, - .priority = priority, - .core_id = core_id, + .task_config = + { + .name = name, + .stack_size_bytes = stack_size_bytes, + .priority = priority, + .core_id = core_id, + }, }); f_task->start(); cv.wait(lock, [¬ified] { return notified; }); return ret_val; } else { // the function returns void - auto f_task = espp::Task::make_unique(espp::Task::Config{ - .name = name, + auto f_task = espp::Task::make_unique({ .callback = [&mutex, &cv, &f, ¬ified](auto &cb_m, auto &cb_cv) -> bool { // synchronize with the main thread - block here until the main thread // waits on the condition variable (cv), then run the function @@ -77,9 +79,13 @@ static auto run_on_core(const auto &f, int core_id, size_t stack_size_bytes = 20 cv.notify_all(); return true; // stop the task }, - .stack_size_bytes = stack_size_bytes, - .priority = priority, - .core_id = core_id, + .task_config = + { + .name = name, + .stack_size_bytes = stack_size_bytes, + .priority = priority, + .core_id = core_id, + }, }); f_task->start(); cv.wait(lock, [¬ified] { return notified; }); diff --git a/components/task/include/task.hpp b/components/task/include/task.hpp index f0b0c36df..96cbcc268 100644 --- a/components/task/include/task.hpp +++ b/components/task/include/task.hpp @@ -163,42 +163,10 @@ class Task : public espp::BaseComponent { /** * @brief Configuration struct for the Task. - * @note This is the recommended way to configure the Task, and allows you to - * use the condition variable and mutex from the task to wait_for and - * wait_until. - * @note This is an older configuration struct, and is kept for backwards - * compatibility. It is recommended to use the AdvancedConfig struct - * instead. + * Can be initialized with any of the supported callback function + * signatures. */ struct Config { - std::string name; /**< Name of the task */ - espp::Task::callback_variant callback; /**< Callback function */ - size_t stack_size_bytes{4096}; /**< Stack Size (B) allocated to the task. */ - size_t priority{0}; /**< Priority of the task, 0 is lowest priority on ESP / FreeRTOS. */ - int core_id{-1}; /**< Core ID of the task, -1 means it is not pinned to any core. */ - espp::Logger::Verbosity log_level{ - espp::Logger::Verbosity::WARN}; /**< Log verbosity for the task. */ - }; - - /** - * @brief Simple configuration struct for the Task. - * @note This is useful for when you don't need to use the condition variable - * or mutex in the callback. - */ - struct SimpleConfig { - espp::Task::callback_no_params_fn callback; /**< Callback function */ - espp::Task::BaseConfig task_config; /**< Base configuration for the task. */ - espp::Logger::Verbosity log_level{ - espp::Logger::Verbosity::WARN}; /**< Log verbosity for the task. */ - }; - - /** - * @brief Advanced configuration struct for the Task. - * @note This is the recommended way to configure the Task, and allows you to - * use the condition variable and mutex from the task to wait_for and - * wait_until. - */ - struct AdvancedConfig { espp::Task::callback_variant callback; /**< Callback function */ espp::Task::BaseConfig task_config; /**< Base configuration for the task. */ espp::Logger::Verbosity log_level{ @@ -211,18 +179,6 @@ class Task : public espp::BaseComponent { */ explicit Task(const espp::Task::Config &config); - /** - * @brief Construct a new Task object using the SimpleConfig struct. - * @param config SimpleConfig struct to initialize the Task with. - */ - explicit Task(const espp::Task::SimpleConfig &config); - - /** - * @brief Construct a new Task object using the AdvancedConfig struct. - * @param config AdvancedConfig struct to initialize the Task with. - */ - explicit Task(const espp::Task::AdvancedConfig &config); - /** * @brief Get a unique pointer to a new task created with \p config. * Useful to not have to use templated std::make_unique (less typing). @@ -231,22 +187,6 @@ class Task : public espp::BaseComponent { */ static std::unique_ptr make_unique(const espp::Task::Config &config); - /** - * @brief Get a unique pointer to a new task created with \p config. - * Useful to not have to use templated std::make_unique (less typing). - * @param config SimpleConfig struct to initialize the Task with. - * @return std::unique_ptr pointer to the newly created task. - */ - static std::unique_ptr make_unique(const espp::Task::SimpleConfig &config); - - /** - * @brief Get a unique pointer to a new task created with \p config. - * Useful to not have to use templated std::make_unique (less typing). - * @param config AdvancedConfig struct to initialize the Task with. - * @return std::unique_ptr pointer to the newly created task. - */ - static std::unique_ptr make_unique(const espp::Task::AdvancedConfig &config); - /** * @brief Destroy the task, stopping it if it was started. */ diff --git a/components/task/include/task_formatters.hpp b/components/task/include/task_formatters.hpp index bc6f6426a..699f0c41e 100644 --- a/components/task/include/task_formatters.hpp +++ b/components/task/include/task_formatters.hpp @@ -21,32 +21,8 @@ template <> struct fmt::formatter { template auto format(const espp::Task::Config &config, FormatContext &ctx) const { - return fmt::format_to( - ctx.out(), "Task::Config{{name: '{}', stack_size_bytes: {}, priority: {}, core_id: {}}}", - config.name, config.stack_size_bytes, config.priority, config.core_id); - } -}; - -// for printing of Task::SimpleConfig using libfmt -template <> struct fmt::formatter { - constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); } - - template - auto format(const espp::Task::SimpleConfig &config, FormatContext &ctx) const { - return fmt::format_to(ctx.out(), - "Task::SimpleConfig{{callback: '{}', task_config: {}, log_level: {}}}", - config.callback, config.task_config, config.log_level); - } -}; - -// for printing of Task::AdvancedConfig using libfmt -template <> struct fmt::formatter { - constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); } - - template - auto format(const espp::Task::AdvancedConfig &config, FormatContext &ctx) const { return fmt::format_to(ctx.out(), - "Task::AdvancedConfig{{callback: '{}', task_config: {}, log_level: {}}}", + "Task::Config{{callback: '{}', task_config: {}, log_level: {}}}", config.callback, config.task_config, config.log_level); } }; diff --git a/components/task/src/task.cpp b/components/task/src/task.cpp index e047673e9..10aac7f90 100644 --- a/components/task/src/task.cpp +++ b/components/task/src/task.cpp @@ -3,18 +3,6 @@ using namespace espp; Task::Task(const Task::Config &config) - : BaseComponent(config.name, config.log_level) - , name_(config.name) - , callback_(config.callback) - , config_({config.name, config.stack_size_bytes, config.priority, config.core_id}) {} - -Task::Task(const Task::SimpleConfig &config) - : BaseComponent(config.task_config.name, config.log_level) - , name_(config.task_config.name) - , callback_(config.callback) - , config_(config.task_config) {} - -Task::Task(const Task::AdvancedConfig &config) : BaseComponent(config.task_config.name, config.log_level) , name_(config.task_config.name) , callback_(config.callback) @@ -24,14 +12,6 @@ std::unique_ptr Task::make_unique(const Task::Config &config) { return std::make_unique(config); } -std::unique_ptr Task::make_unique(const Task::SimpleConfig &config) { - return std::make_unique(config); -} - -std::unique_ptr Task::make_unique(const Task::AdvancedConfig &config) { - return std::make_unique(config); -} - Task::~Task() { logger_.debug("Destroying task"); stop(); diff --git a/components/thermistor/example/main/thermistor_example.cpp b/components/thermistor/example/main/thermistor_example.cpp index d95ff9393..b00a3cefb 100644 --- a/components/thermistor/example/main/thermistor_example.cpp +++ b/components/thermistor/example/main/thermistor_example.cpp @@ -131,8 +131,9 @@ extern "C" void app_main(void) { // don't want to stop the task return false; }; - auto task = espp::Task( - {.name = "Read Thermistor", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "Read Thermistor"}, + .log_level = espp::Logger::Verbosity::INFO}); task.start(); //! [thermistor adc example] diff --git a/components/timer/src/timer.cpp b/components/timer/src/timer.cpp index 334afdac3..f91bf1663 100644 --- a/components/timer/src/timer.cpp +++ b/components/timer/src/timer.cpp @@ -11,12 +11,15 @@ Timer::Timer(const Timer::Config &config) logger_.set_rate_limit(std::chrono::milliseconds(100)); // make the task task_ = espp::Task::make_unique({ - .name = std::string(config.name) + "_task", .callback = std::bind(&Timer::timer_callback_fn, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), - .stack_size_bytes = config.stack_size_bytes, - .priority = config.priority, - .core_id = config.core_id, + .task_config = + { + .name = std::string(config.name) + "_task", + .stack_size_bytes = config.stack_size_bytes, + .priority = config.priority, + .core_id = config.core_id, + }, .log_level = config.log_level, }); period_float = std::chrono::duration(period_).count(); diff --git a/components/tla2528/example/main/tla2528_example.cpp b/components/tla2528/example/main/tla2528_example.cpp index 944767c9c..1a78109d7 100644 --- a/components/tla2528/example/main/tla2528_example.cpp +++ b/components/tla2528/example/main/tla2528_example.cpp @@ -94,9 +94,12 @@ extern "C" void app_main(void) { return false; }; - auto tla_task = espp::Task::make_unique({.name = "TLA", - .callback = tla_read_task_fn, - .stack_size_bytes{8 * 1024}, + auto tla_task = espp::Task::make_unique({.callback = tla_read_task_fn, + .task_config = + { + .name = "TLA", + .stack_size_bytes{8 * 1024}, + }, .log_level = espp::Logger::Verbosity::INFO}); tla_task->start(); //! [tla2528 example] diff --git a/components/tt21100/example/main/tt21100_example.cpp b/components/tt21100/example/main/tt21100_example.cpp index 6dfd48e6b..e10e9d710 100644 --- a/components/tt21100/example/main/tt21100_example.cpp +++ b/components/tt21100/example/main/tt21100_example.cpp @@ -61,8 +61,9 @@ extern "C" void app_main(void) { } return false; // don't stop the task }; - auto task = espp::Task( - {.name = "TT21100 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN}); + auto task = espp::Task({.callback = task_fn, + .task_config = {.name = "TT21100 Task"}, + .log_level = espp::Logger::Verbosity::WARN}); task.start(); //! [tt21100 example] while (true) { diff --git a/lib/python_bindings/espp/__init__.pyi b/lib/python_bindings/espp/__init__.pyi index dc6bba18f..3ea1edef9 100644 --- a/lib/python_bindings/espp/__init__.pyi +++ b/lib/python_bindings/espp/__init__.pyi @@ -3119,10 +3119,12 @@ class Task: * \snippet task_example.cpp ManyTask example * \section task_ex4 Long Running Task Example * \snippet task_example.cpp LongRunningTask example - * \section task_ex4 Long Running Task Example using notification flag (recommended to avoid - * spurious wakeups) \snippet task_example.cpp LongRunningTaskNotified example \section task_ex5 - * Task Info Example \snippet task_example.cpp Task Info example \section task_ex6 Task Request Stop - * Example \snippet task_example.cpp Task Request Stop example + * \section task_ex5 Long Running Task Notified Example (Recommended) + * \snippet task_example.cpp LongRunningTaskNotified example + * \section task_ex6 Task Info Example + * \snippet task_example.cpp Task Info example + * \section task_ex7 Task Request Stop Example + * \snippet task_example.cpp Task Request Stop example * * \section run_on_core_ex1 Run on Core Example * \snippet task_example.cpp run on core example @@ -3159,57 +3161,8 @@ class Task: class Config: """* * @brief Configuration struct for the Task. - * @note This is the recommended way to configure the Task, and allows you to - * use the condition variable and mutex from the task to wait_for and - * wait_until. - * @note This is an older configuration struct, and is kept for backwards - * compatibility. It is recommended to use the AdvancedConfig struct - * instead. - - """ - name: str #*< Name of the task - callback: Task.callback_variant #*< Callback function - stack_size_bytes: int = int(4096) #*< Stack Size (B) allocated to the task. - priority: int = int(0) #*< Priority of the task, 0 is lowest priority on ESP / FreeRTOS. - core_id: int = int(-1) #*< Core ID of the task, -1 means it is not pinned to any core. - log_level: Logger.Verbosity = Logger.Verbosity(Logger.Verbosity.warn) #*< Log verbosity for the task. - def __init__( - self, - name: str = "", - callback: Task.callback_variant = Task.callback_variant(), - stack_size_bytes: int = int(4096), - priority: int = int(0), - core_id: int = int(-1), - log_level: Logger.Verbosity = Logger.Verbosity(Logger.Verbosity.warn) - ) -> None: - """Auto-generated default constructor with named params""" - pass - - class SimpleConfig: - """* - * @brief Simple configuration struct for the Task. - * @note This is useful for when you don't need to use the condition variable - * or mutex in the callback. - - """ - callback: Task.callback_no_params_fn #*< Callback function - task_config: Task.BaseConfig #*< Base configuration for the task. - log_level: Logger.Verbosity = Logger.Verbosity(Logger.Verbosity.warn) #*< Log verbosity for the task. - def __init__( - self, - callback: Task.callback_no_params_fn = Task.callback_no_params_fn(), - task_config: Task.BaseConfig = Task.BaseConfig(), - log_level: Logger.Verbosity = Logger.Verbosity(Logger.Verbosity.warn) - ) -> None: - """Auto-generated default constructor with named params""" - pass - - class AdvancedConfig: - """* - * @brief Advanced configuration struct for the Task. - * @note This is the recommended way to configure the Task, and allows you to - * use the condition variable and mutex from the task to wait_for and - * wait_until. + * Can be initialized with any of the supported callback function + * signatures. """ callback: Task.callback_variant #*< Callback function @@ -3225,10 +3178,7 @@ class Task: pass - - @staticmethod - @overload def make_unique(config: Task.Config) -> Task: """* * @brief Get a unique pointer to a new task created with \p config. @@ -3239,30 +3189,6 @@ class Task: """ pass - @staticmethod - @overload - def make_unique(config: Task.SimpleConfig) -> Task: - """* - * @brief Get a unique pointer to a new task created with \p config. - * Useful to not have to use templated std::make_unique (less typing). - * @param config SimpleConfig struct to initialize the Task with. - * @return std::unique_ptr pointer to the newly created task. - - """ - pass - - @staticmethod - @overload - def make_unique(config: Task.AdvancedConfig) -> Task: - """* - * @brief Get a unique pointer to a new task created with \p config. - * Useful to not have to use templated std::make_unique (less typing). - * @param config AdvancedConfig struct to initialize the Task with. - * @return std::unique_ptr pointer to the newly created task. - - """ - pass - def start(self) -> bool: """* diff --git a/lib/python_bindings/pybind_espp.cpp b/lib/python_bindings/pybind_espp.cpp index d5bc6ffed..03b7dd3cb 100644 --- a/lib/python_bindings/pybind_espp.cpp +++ b/lib/python_bindings/pybind_espp.cpp @@ -1882,14 +1882,13 @@ void py_init_module_espp(py::module &m) { "\\section task_ex2 Task Watchdog Example\n * \\snippet task_example.cpp task watchdog " "example\n * \\section task_ex3 Many Task Example\n * \\snippet task_example.cpp ManyTask " "example\n * \\section task_ex4 Long Running Task Example\n * \\snippet task_example.cpp " - "LongRunningTask example\n * \\section task_ex4 Long Running Task Example using notification " - "flag (recommended to avoid\n * spurious wakeups) \\snippet task_example.cpp " - "LongRunningTaskNotified example \\section task_ex5\n * Task Info Example \\snippet " - "task_example.cpp Task Info example \\section task_ex6 Task Request Stop\n * Example " - "\\snippet task_example.cpp Task Request Stop example\n *\n * \\section run_on_core_ex1 Run " - "on Core Example\n * \\snippet task_example.cpp run on core example\n * \\section " - "run_on_core_ex2 Run on Core (Non-Blocking) Example\n * \\snippet task_example.cpp run on " - "core nonblocking example\n"); + "LongRunningTask example\n * \\section task_ex5 Long Running Task Notified Example " + "(Recommended)\n * \\snippet task_example.cpp LongRunningTaskNotified example\n * \\section " + "task_ex6 Task Info Example\n * \\snippet task_example.cpp Task Info example\n * \\section " + "task_ex7 Task Request Stop Example\n * \\snippet task_example.cpp Task Request Stop " + "example\n *\n * \\section run_on_core_ex1 Run on Core Example\n * \\snippet " + "task_example.cpp run on core example\n * \\section run_on_core_ex2 Run on Core " + "(Non-Blocking) Example\n * \\snippet task_example.cpp run on core nonblocking example\n"); { // inner classes & enums of Task auto pyClassTask_ClassBaseConfig = @@ -1919,76 +1918,13 @@ void py_init_module_espp(py::module &m) { auto pyClassTask_ClassConfig = py::class_( pyClassTask, "Config", py::dynamic_attr(), - "*\n * @brief Configuration struct for the Task.\n * @note This is the recommended " - "way to configure the Task, and allows you to\n * use the condition variable " - "and mutex from the task to wait_for and\n * wait_until.\n * @note This is " - "an older configuration struct, and is kept for backwards\n * compatibility. " - "It is recommended to use the AdvancedConfig struct\n * instead.\n") - .def(py::init<>( - [](std::string name = std::string(), - espp::Task::callback_variant callback = espp::Task::callback_variant(), - size_t stack_size_bytes = {4096}, size_t priority = {0}, int core_id = {-1}, - espp::Logger::Verbosity log_level = {espp::Logger::Verbosity::WARN}) { - auto r = std::make_unique(); - r->name = name; - r->callback = callback; - r->stack_size_bytes = stack_size_bytes; - r->priority = priority; - r->core_id = core_id; - r->log_level = log_level; - return r; - }), - py::arg("name") = std::string(), - py::arg("callback") = espp::Task::callback_variant(), - py::arg("stack_size_bytes") = size_t{4096}, py::arg("priority") = size_t{0}, - py::arg("core_id") = int{-1}, - py::arg("log_level") = espp::Logger::Verbosity{espp::Logger::Verbosity::WARN}) - .def_readwrite("name", &espp::Task::Config::name, "*< Name of the task") - .def_readwrite("callback", &espp::Task::Config::callback, "*< Callback function") - .def_readwrite("stack_size_bytes", &espp::Task::Config::stack_size_bytes, - "*< Stack Size (B) allocated to the task.") - .def_readwrite("priority", &espp::Task::Config::priority, - "*< Priority of the task, 0 is lowest priority on ESP / FreeRTOS.") - .def_readwrite("core_id", &espp::Task::Config::core_id, - "*< Core ID of the task, -1 means it is not pinned to any core.") - .def_readwrite("log_level", &espp::Task::Config::log_level, - "*< Log verbosity for the task."); - auto pyClassTask_ClassSimpleConfig = - py::class_( - pyClassTask, "SimpleConfig", py::dynamic_attr(), - "*\n * @brief Simple configuration struct for the Task.\n * @note This is useful " - "for when you don't need to use the condition variable\n * or mutex in the " - "callback.\n") - .def( - py::init<>([](espp::Task::callback_no_params_fn callback = - espp::Task::callback_no_params_fn(), - espp::Task::BaseConfig task_config = espp::Task::BaseConfig(), - espp::Logger::Verbosity log_level = {espp::Logger::Verbosity::WARN}) { - auto r = std::make_unique(); - r->callback = callback; - r->task_config = task_config; - r->log_level = log_level; - return r; - }), - py::arg("callback") = espp::Task::callback_no_params_fn(), - py::arg("task_config") = espp::Task::BaseConfig(), - py::arg("log_level") = espp::Logger::Verbosity{espp::Logger::Verbosity::WARN}) - .def_readwrite("callback", &espp::Task::SimpleConfig::callback, "*< Callback function") - .def_readwrite("task_config", &espp::Task::SimpleConfig::task_config, - "*< Base configuration for the task.") - .def_readwrite("log_level", &espp::Task::SimpleConfig::log_level, - "*< Log verbosity for the task."); - auto pyClassTask_ClassAdvancedConfig = - py::class_( - pyClassTask, "AdvancedConfig", py::dynamic_attr(), - "*\n * @brief Advanced configuration struct for the Task.\n * @note This is the " - "recommended way to configure the Task, and allows you to\n * use the " - "condition variable and mutex from the task to wait_for and\n * wait_until.\n") + "*\n * @brief Configuration struct for the Task.\n * Can be initialized " + "with any of the supported callback function\n * signatures.\n") .def(py::init<>( [](espp::Task::callback_variant callback = espp::Task::callback_variant(), espp::Task::BaseConfig task_config = espp::Task::BaseConfig(), espp::Logger::Verbosity log_level = {espp::Logger::Verbosity::WARN}) { - auto r = std::make_unique(); + auto r = std::make_unique(); r->callback = callback; r->task_config = task_config; r->log_level = log_level; @@ -1997,38 +1933,19 @@ void py_init_module_espp(py::module &m) { py::arg("callback") = espp::Task::callback_variant(), py::arg("task_config") = espp::Task::BaseConfig(), py::arg("log_level") = espp::Logger::Verbosity{espp::Logger::Verbosity::WARN}) - .def_readwrite("callback", &espp::Task::AdvancedConfig::callback, - "*< Callback function") - .def_readwrite("task_config", &espp::Task::AdvancedConfig::task_config, + .def_readwrite("callback", &espp::Task::Config::callback, "*< Callback function") + .def_readwrite("task_config", &espp::Task::Config::task_config, "*< Base configuration for the task.") - .def_readwrite("log_level", &espp::Task::AdvancedConfig::log_level, + .def_readwrite("log_level", &espp::Task::Config::log_level, "*< Log verbosity for the task."); } // end of inner classes & enums of Task pyClassTask.def(py::init()) - .def(py::init()) - .def(py::init()) - .def_static("make_unique", - py::overload_cast(&espp::Task::make_unique), - py::arg("config"), + .def_static("make_unique", &espp::Task::make_unique, py::arg("config"), "*\n * @brief Get a unique pointer to a new task created with \\p config.\n " "* Useful to not have to use templated std::make_unique (less typing).\n " " * @param config Config struct to initialize the Task with.\n * @return " "std::unique_ptr pointer to the newly created task.\n") - .def_static("make_unique", - py::overload_cast(&espp::Task::make_unique), - py::arg("config"), - "*\n * @brief Get a unique pointer to a new task created with \\p config.\n " - "* Useful to not have to use templated std::make_unique (less typing).\n " - " * @param config SimpleConfig struct to initialize the Task with.\n * @return " - "std::unique_ptr pointer to the newly created task.\n") - .def_static("make_unique", - py::overload_cast(&espp::Task::make_unique), - py::arg("config"), - "*\n * @brief Get a unique pointer to a new task created with \\p config.\n " - "* Useful to not have to use templated std::make_unique (less typing).\n " - " * @param config AdvancedConfig struct to initialize the Task with.\n * " - "@return std::unique_ptr pointer to the newly created task.\n") .def("start", &espp::Task::start, "*\n * @brief Start executing the task.\n *\n * @return True if the task started, " "False if it was already started.\n")