Skip to content

Commit

Permalink
feat(task): [BREAKING] Simplify task configuration (#342)
Browse files Browse the repository at this point in the history
* feat(task): [BREAKING] Simplify task configuration
* Rename `Task::AdvancedConfig` to `Task::Config`
* Remove `Task::SimpleConfig`

* update bindings, rtsp, timer, and ftp components

* fix examples

* fix remaining examples
  • Loading branch information
finger563 authored Nov 20, 2024
1 parent d5d2dae commit bb71669
Show file tree
Hide file tree
Showing 55 changed files with 351 additions and 477 deletions.
10 changes: 6 additions & 4 deletions components/adc/example/main/adc_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions components/adc/include/continuous_adc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 6 additions & 3 deletions components/ads1x15/example/main/ads1x15_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 12 additions & 6 deletions components/ads7138/example/main/ads7138_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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]
Expand Down
9 changes: 6 additions & 3 deletions components/as5600/example/main/as5600_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions components/as5600/include/as5600.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
9 changes: 6 additions & 3 deletions components/aw9523/example/main/aw9523_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions components/bldc_haptics/include/bldc_haptics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ template <MotorConcept M> 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});
}

Expand Down
11 changes: 7 additions & 4 deletions components/bldc_motor/example/main/bldc_motor_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions components/bm8563/example/main/bm8563_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions components/chsc6x/example/main/chsc6x_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 24 additions & 12 deletions components/controller/example/main/controller_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions components/cst816/example/main/cst816_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions components/display_drivers/example/main/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
9 changes: 6 additions & 3 deletions components/drv2605/example/main/drv2605_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions components/encoder/example/main/encoder_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions components/esp-box/src/esp-box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,14 @@ bool EspBox::initialize_sound(uint32_t default_audio_rate) {

using namespace std::placeholders;
audio_task_ = std::make_unique<espp::Task>(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();
Expand Down
4 changes: 2 additions & 2 deletions components/esp32-timer-cam/src/esp32-timer-cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions components/filters/example/main/filters_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
Loading

0 comments on commit bb71669

Please sign in to comment.