Skip to content

Commit bb71669

Browse files
authored
feat(task): [BREAKING] Simplify task configuration (#342)
* 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
1 parent d5d2dae commit bb71669

File tree

55 files changed

+351
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+351
-477
lines changed

components/adc/example/main/adc_example.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ extern "C" void app_main(void) {
5151
// don't want to stop the task
5252
return false;
5353
};
54-
auto task = espp::Task(
55-
{.name = "Oneshot ADC", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO});
54+
auto task = espp::Task({.callback = task_fn,
55+
.task_config = {.name = "Oneshot ADC"},
56+
.log_level = espp::Logger::Verbosity::INFO});
5657
task.start();
5758
//! [oneshot adc example]
5859
std::this_thread::sleep_for(num_seconds_to_run * 1s);
@@ -97,8 +98,9 @@ extern "C" void app_main(void) {
9798
// don't want to stop the task
9899
return false;
99100
};
100-
auto task = espp::Task(
101-
{.name = "Read ADC", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO});
101+
auto task = espp::Task({.callback = task_fn,
102+
.task_config = {.name = "Read ADC"},
103+
.log_level = espp::Logger::Verbosity::INFO});
102104
task.start();
103105

104106
// test stopping and starting the adc

components/adc/include/continuous_adc.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ class ContinuousAdc : public espp::BaseComponent {
6363
// and start the task
6464
using namespace std::placeholders;
6565
task_ = espp::Task::make_unique(
66-
{.name = "ContinuousAdc Task",
67-
.callback = std::bind(&ContinuousAdc::update_task, this, _1, _2, _3),
68-
.priority = config.task_priority,
66+
{.callback = std::bind(&ContinuousAdc::update_task, this, _1, _2, _3),
67+
.task_config =
68+
{
69+
.name = "ContinuousAdc Task",
70+
.priority = config.task_priority,
71+
},
6972
.log_level = espp::Logger::Verbosity::WARN});
7073
task_->start();
7174
}

components/ads1x15/example/main/ads1x15_example.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ extern "C" void app_main(void) {
5656
// we don't want to stop, so return false
5757
return false;
5858
};
59-
auto ads_task = espp::Task::make_unique({.name = "ADS",
60-
.callback = ads_read_task_fn,
61-
.stack_size_bytes{4 * 1024},
59+
auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn,
60+
.task_config =
61+
{
62+
.name = "ADS",
63+
.stack_size_bytes{4 * 1024},
64+
},
6265
.log_level = espp::Logger::Verbosity::INFO});
6366
ads_task->start();
6467
//! [ads1x15 example]

components/ads7138/example/main/ads7138_example.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ extern "C" void app_main(void) {
124124
gpio_isr_handler_add(ALERT_PIN, gpio_isr_handler, (void *)ALERT_PIN);
125125

126126
// start the gpio task
127-
auto alert_task = espp::Task::make_unique(espp::Task::Config{
128-
.name = "alert",
127+
auto alert_task = espp::Task::make_unique({
129128
.callback = [&ads](auto &m, auto &cv) -> bool {
130129
static uint32_t io_num;
131130
// block until we get a message from the interrupt handler
@@ -156,7 +155,11 @@ extern "C" void app_main(void) {
156155
// don't want to stop the task
157156
return false;
158157
},
159-
.stack_size_bytes = 4 * 1024,
158+
.task_config =
159+
{
160+
.name = "alert",
161+
.stack_size_bytes = 4 * 1024,
162+
},
160163
});
161164
alert_task->start();
162165

@@ -241,9 +244,12 @@ extern "C" void app_main(void) {
241244
return false;
242245
};
243246

244-
auto ads_task = espp::Task::make_unique({.name = "ADS",
245-
.callback = ads_read_task_fn,
246-
.stack_size_bytes{8 * 1024},
247+
auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn,
248+
.task_config =
249+
{
250+
.name = "ADS",
251+
.stack_size_bytes{8 * 1024},
252+
},
247253
.log_level = espp::Logger::Verbosity::INFO});
248254
ads_task->start();
249255
//! [ads7138 example]

components/as5600/example/main/as5600_example.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ extern "C" void app_main(void) {
6161
// don't want to stop the task
6262
return false;
6363
};
64-
auto task = espp::Task({.name = "As5600 Task",
65-
.callback = task_fn,
66-
.stack_size_bytes = 5 * 1024,
64+
auto task = espp::Task({.callback = task_fn,
65+
.task_config =
66+
{
67+
.name = "As5600 Task",
68+
.stack_size_bytes = 5 * 1024,
69+
},
6770
.log_level = espp::Logger::Verbosity::WARN});
6871
fmt::print("%time(s), count, radians, degrees, rpm\n");
6972
task.start();

components/as5600/include/as5600.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ class As5600 : public BasePeripheral<> {
238238
accumulator_ = count;
239239
// start the task
240240
using namespace std::placeholders;
241-
task_ = Task::make_unique(
242-
{.name = "As5600", .callback = std::bind(&As5600::update_task, this, _1, _2, _3)});
241+
task_ = Task::make_unique({
242+
.callback = std::bind(&As5600::update_task, this, _1, _2, _3),
243+
.task_config = {.name = "As5600"},
244+
});
243245
task_->start();
244246
}
245247

components/aw9523/example/main/aw9523_example.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ extern "C" void app_main(void) {
118118
// don't want to stop the task
119119
return false;
120120
};
121-
auto task = espp::Task({.name = "Aw9523 Task",
122-
.callback = task_fn,
123-
.stack_size_bytes = 5 * 1024,
121+
auto task = espp::Task({.callback = task_fn,
122+
.task_config =
123+
{
124+
.name = "Aw9523 Task",
125+
.stack_size_bytes = 5 * 1024,
126+
},
124127
.log_level = espp::Logger::Verbosity::WARN});
125128
fmt::print("%time(s), pin values, r, g, b\n");
126129
task.start();

components/bldc_haptics/include/bldc_haptics.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,13 @@ template <MotorConcept M> class BldcHaptics : public BaseComponent {
135135
motor_.get().set_motion_control_type(detail::MotionControlType::TORQUE);
136136
// create the motor task
137137
motor_task_ = Task::make_unique(
138-
{.name = "haptic_motor",
139-
.callback = std::bind(&BldcHaptics::motor_task, this, std::placeholders::_1,
138+
{.callback = std::bind(&BldcHaptics::motor_task, this, std::placeholders::_1,
140139
std::placeholders::_2, std::placeholders::_3),
141-
.stack_size_bytes = 1024 * 6,
140+
.task_config =
141+
{
142+
.name = "haptic_motor",
143+
.stack_size_bytes = 1024 * 6,
144+
},
142145
.log_level = Logger::Verbosity::WARN});
143146
}
144147

components/bldc_motor/example/main/bldc_motor_example.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ extern "C" void app_main(void) {
182182
return false;
183183
};
184184
auto target_task = espp::Task({
185-
.name = "Target Task",
186185
.callback = target_task_fn,
186+
.task_config = {.name = "Target Task"},
187187
});
188188
target_task.start();
189189

@@ -218,9 +218,12 @@ extern "C" void app_main(void) {
218218
// don't want to stop the task
219219
return false;
220220
};
221-
auto task = espp::Task({.name = "Logging Task",
222-
.callback = task_fn,
223-
.stack_size_bytes = 5 * 1024,
221+
auto task = espp::Task({.callback = task_fn,
222+
.task_config =
223+
{
224+
.name = "Logging Task",
225+
.stack_size_bytes = 5 * 1024,
226+
},
224227
.log_level = espp::Logger::Verbosity::WARN});
225228
if (motion_control_type == espp::detail::MotionControlType::VELOCITY ||
226229
motion_control_type == espp::detail::MotionControlType::VELOCITY_OPENLOOP) {

components/bm8563/example/main/bm8563_example.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ extern "C" void app_main(void) {
6767
}
6868
return false; // don't stop the task
6969
};
70-
auto task = espp::Task(
71-
{.name = "BM8563 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN});
70+
auto task = espp::Task({.callback = task_fn,
71+
.task_config = {.name = "BM8563 Task"},
72+
.log_level = espp::Logger::Verbosity::WARN});
7273
task.start();
7374
//! [bm8563 example]
7475
while (true) {

components/chsc6x/example/main/chsc6x_example.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ extern "C" void app_main(void) {
6464
}
6565
return false; // don't stop the task
6666
};
67-
auto task = espp::Task(
68-
{.name = "Chsc6x Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN});
67+
auto task = espp::Task({.callback = task_fn,
68+
.task_config = {.name = "Chsc6x Task"},
69+
.log_level = espp::Logger::Verbosity::WARN});
6970
task.start();
7071
//! [chsc6x example]
7172
while (true) {

components/controller/example/main/controller_example.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ extern "C" void app_main(void) {
5252
// we don't want to stop, so return false
5353
return false;
5454
};
55-
auto task = espp::Task({.name = "Controller Task",
56-
.callback = task_fn,
57-
.stack_size_bytes = 6 * 1024,
55+
auto task = espp::Task({.callback = task_fn,
56+
.task_config =
57+
{
58+
.name = "Controller Task",
59+
.stack_size_bytes = 6 * 1024,
60+
},
5861
.log_level = espp::Logger::Verbosity::WARN});
5962
task.start();
6063
//! [digital controller example]
@@ -155,9 +158,12 @@ extern "C" void app_main(void) {
155158
// we don't want to stop, so return false
156159
return false;
157160
};
158-
auto task = espp::Task({.name = "Controller Task",
159-
.callback = task_fn,
160-
.stack_size_bytes = 6 * 1024,
161+
auto task = espp::Task({.callback = task_fn,
162+
.task_config =
163+
{
164+
.name = "Controller Task",
165+
.stack_size_bytes = 6 * 1024,
166+
},
161167
.log_level = espp::Logger::Verbosity::WARN});
162168
task.start();
163169
//! [analog controller example]
@@ -217,9 +223,12 @@ extern "C" void app_main(void) {
217223
// we don't want to stop, so return false
218224
return false;
219225
};
220-
auto ads_task = espp::Task::make_unique({.name = "ADS",
221-
.callback = ads_read_task_fn,
222-
.stack_size_bytes{4 * 1024},
226+
auto ads_task = espp::Task::make_unique({.callback = ads_read_task_fn,
227+
.task_config =
228+
{
229+
.name = "ADS Task",
230+
.stack_size_bytes{4 * 1024},
231+
},
223232
.log_level = espp::Logger::Verbosity::INFO});
224233
ads_task->start();
225234
// make the read joystick function used by the controller
@@ -285,9 +294,12 @@ extern "C" void app_main(void) {
285294
// we don't want to stop, return false
286295
return false;
287296
};
288-
auto task = espp::Task({.name = "Controller Task",
289-
.callback = task_fn,
290-
.stack_size_bytes = 6 * 1024,
297+
auto task = espp::Task({.callback = task_fn,
298+
.task_config =
299+
{
300+
.name = "Controller Task",
301+
.stack_size_bytes = 6 * 1024,
302+
},
291303
.log_level = espp::Logger::Verbosity::WARN});
292304
task.start();
293305
//! [i2c analog controller example]

components/cst816/example/main/cst816_example.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ extern "C" void app_main(void) {
6767
}
6868
return false; // don't stop the task
6969
};
70-
auto task = espp::Task(
71-
{.name = "Cst816 Task", .callback = task_fn, .log_level = espp::Logger::Verbosity::WARN});
70+
auto task = espp::Task({.callback = task_fn,
71+
.task_config = {.name = "Cst816 Task"},
72+
.log_level = espp::Logger::Verbosity::WARN});
7273
task.start();
7374
//! [cst816 example]
7475
while (true) {

components/display_drivers/example/main/gui.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class Gui {
1818
init_ui();
1919
// now start the gui updater task
2020
using namespace std::placeholders;
21-
task_ = espp::Task::make_unique({.name = "Gui Task",
22-
.callback = std::bind(&Gui::update, this, _1, _2, _3),
23-
.stack_size_bytes = 6 * 1024});
21+
task_ = espp::Task::make_unique(
22+
{.callback = std::bind(&Gui::update, this, _1, _2, _3),
23+
.task_config = {.name = "Gui Task", .stack_size_bytes = 6 * 1024}});
2424
task_->start();
2525
}
2626

components/drv2605/example/main/drv2605_example.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ extern "C" void app_main(void) {
8080
// we don't want to stop, so return false
8181
return false;
8282
};
83-
auto task = espp::Task::make_unique({.name = "example",
84-
.callback = task_fn,
85-
.stack_size_bytes{4 * 1024},
83+
auto task = espp::Task::make_unique({.callback = task_fn,
84+
.task_config =
85+
{
86+
.name = "example",
87+
.stack_size_bytes{4 * 1024},
88+
},
8689
.log_level = espp::Logger::Verbosity::INFO});
8790
task->start();
8891
//! [drv2605 example]

components/encoder/example/main/encoder_example.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ extern "C" void app_main(void) {
3434
// don't want to stop the task
3535
return false;
3636
};
37-
auto task = espp::Task(
38-
{.name = "Abi Encoder", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO});
37+
auto task = espp::Task({.callback = task_fn,
38+
.task_config = {.name = "Abi Encoder"},
39+
.log_level = espp::Logger::Verbosity::INFO});
3940
task.start();
4041
//! [abi encoder rotational example]
4142
std::this_thread::sleep_for(num_seconds_to_run * 1s);
@@ -64,8 +65,9 @@ extern "C" void app_main(void) {
6465
// don't want to stop the task
6566
return false;
6667
};
67-
auto task = espp::Task(
68-
{.name = "Abi Encoder", .callback = task_fn, .log_level = espp::Logger::Verbosity::INFO});
68+
auto task = espp::Task({.callback = task_fn,
69+
.task_config = {.name = "Abi Encoder"},
70+
.log_level = espp::Logger::Verbosity::INFO});
6971
task.start();
7072
//! [abi encoder linear example]
7173
std::this_thread::sleep_for(num_seconds_to_run * 1s);

components/esp-box/src/esp-box.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,14 @@ bool EspBox::initialize_sound(uint32_t default_audio_rate) {
620620

621621
using namespace std::placeholders;
622622
audio_task_ = std::make_unique<espp::Task>(espp::Task::Config{
623-
.name = "audio task",
624623
.callback = std::bind(&EspBox::audio_task_callback, this, _1, _2, _3),
625-
.stack_size_bytes = 1024 * 4,
626-
.priority = 19,
627-
.core_id = 1,
624+
.task_config =
625+
{
626+
.name = "audio task",
627+
.stack_size_bytes = 1024 * 4,
628+
.priority = 19,
629+
.core_id = 1,
630+
},
628631
});
629632

630633
audio_task_->start();

components/esp32-timer-cam/src/esp32-timer-cam.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ bool EspTimerCam::initialize_led(float breathing_period) {
2222
});
2323
using namespace std::placeholders;
2424
led_task_ = espp::Task::make_unique(
25-
{.name = "breathe",
26-
.callback = std::bind(&EspTimerCam::led_task_callback, this, _1, _2, _3)});
25+
{.callback = std::bind(&EspTimerCam::led_task_callback, this, _1, _2, _3),
26+
.task_config = {.name = "breathe"}});
2727
set_led_breathing_period(breathing_period);
2828
return true;
2929
}

components/event_manager/example/main/event_manager_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ extern "C" void app_main(void) {
9191
// we don't want to stop, so return false
9292
return false;
9393
};
94-
auto task1 = espp::Task({.name = "Task 1", .callback = task_1_fn});
94+
auto task1 = espp::Task({.callback = task_1_fn, .task_config = {.name = "Task 1"}});
9595

9696
// Now let's make another task which will have pub/sub as well
9797
auto task_2_fn = [&](auto &m, auto &cv) {
@@ -160,7 +160,7 @@ extern "C" void app_main(void) {
160160
// we don't want to stop, so return false
161161
return false;
162162
};
163-
auto task2 = espp::Task({.name = "Task 2", .callback = task_2_fn});
163+
auto task2 = espp::Task({.callback = task_2_fn, .task_config = {.name = "Task 2"}});
164164

165165
// now start the tasks
166166
task1.start();

components/filters/example/main/filters_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ extern "C" void app_main(void) {
6262
// don't want to stop the task
6363
return false;
6464
};
65-
auto task = espp::Task({.name = "Lowpass Filter",
66-
.callback = task_fn,
65+
auto task = espp::Task({.callback = task_fn,
66+
.task_config = {.name = "Lowpass Filter"},
6767
.log_level = espp::Logger::Verbosity::INFO});
6868
fmt::print("% time (s), input, simple_lpf_output, lpf_output, "
6969
"bwf_df1_o1_output, bwf_df1_o2_output, bwf_df2_o2_output, "

0 commit comments

Comments
 (0)