Skip to content

Commit 9af9ae4

Browse files
authored
fix(lib): update so lib build works (#227)
* Update logger so return type of get_time() is std::string instead of auto, to help lib building * Update lib to have interfaces and include/src files updated for base_peripheral, base_component, and logger.cpp * Update python examples with updated APIs for task configs
1 parent 1804100 commit 9af9ae4

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

components/logger/include/logger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class Logger {
286286
* Get the current time in seconds since the start of the logging system.
287287
* @return time in seconds since the start of the logging system.
288288
*/
289-
static auto get_time() {
289+
static std::string get_time() {
290290
#if defined(ESP_PLATFORM)
291291
// use esp_timer_get_time to get the time in microseconds
292292
uint64_t time = esp_timer_get_time();

lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(EXTERNAL "../external")
1717
set(ESPP_INCLUDES
1818
${EXTERNAL}/fmt/include
1919
${EXTERNAL}/alpaca/include
20+
${COMPONENTS}/base_component/include
21+
${COMPONENTS}/base_peripheral/include
2022
${COMPONENTS}/ftp/include
2123
${COMPONENTS}/format/include
2224
${COMPONENTS}/logger/include
@@ -28,6 +30,7 @@ set(ESPP_INCLUDES
2830
)
2931

3032
set(ESPP_SOURCES
33+
${COMPONENTS}/logger/src/logger.cpp
3134
lib.cpp
3235
)
3336

lib/bind.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,27 @@ PYBIND11_MODULE(espp, m) {
3232
// std::mutex and std::condition_variable which pybind does not support.
3333
// Therefore we use the SimpleConfig, whose callback function has no
3434
// arguments and return bool
35-
py::class_<Task::SimpleConfig>(m, "TaskSimpleConfig")
36-
.def(py::init<const std::string &, Task::simple_callback_fn, size_t, size_t, int,
37-
Logger::Verbosity>(),
38-
py::arg("name"), py::arg("callback"), py::arg("stack_size") = 4 * 1024,
39-
py::arg("priority") = 0, py::arg("core_id") = -1,
40-
py::arg("verbosity") = Logger::Verbosity::WARN);
35+
py::class_<Task::BaseConfig>(m, "TaskBaseConfig")
36+
.def(py::init<const std::string &, size_t, size_t, int>(), py::arg("name"),
37+
py::arg("stack_size") = 4 * 1024, py::arg("priority") = 0, py::arg("core_id") = -1);
4138
py::class_<Task::Config>(m, "TaskConfig")
4239
.def(py::init<const std::string &, Task::callback_fn, size_t, size_t, int,
4340
Logger::Verbosity>(),
4441
py::arg("name"), py::arg("callback"), py::arg("stack_size") = 4 * 1024,
4542
py::arg("priority") = 0, py::arg("core_id") = -1,
4643
py::arg("verbosity") = Logger::Verbosity::WARN);
44+
py::class_<Task::SimpleConfig>(m, "TaskSimpleConfig")
45+
.def(py::init<Task::simple_callback_fn, Task::BaseConfig, Logger::Verbosity>(),
46+
py::arg("callback"), py::arg("task_config"),
47+
py::arg("verbosity") = Logger::Verbosity::WARN);
48+
py::class_<Task::AdvancedConfig>(m, "TaskAdvancedConfig")
49+
.def(py::init<Task::callback_fn, Task::BaseConfig, Logger::Verbosity>(), py::arg("callback"),
50+
py::arg("task_config"), py::arg("verbosity") = Logger::Verbosity::WARN);
4751

4852
py::class_<Task>(m, "Task")
53+
.def(py::init<const Task::Config &>())
4954
.def(py::init<const Task::SimpleConfig &>())
55+
.def(py::init<const Task::AdvancedConfig &>())
5056
.def("start", &Task::start)
5157
.def("stop", &Task::stop)
5258
.def("is_started", &Task::is_started)

python/task.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def task_func():
2121
return False # we don't want to stop the task
2222

2323
task = espp.Task(espp.TaskSimpleConfig(
24-
"test task", #name
25-
task_func
24+
task_func, #function
25+
# config
26+
espp.TaskBaseConfig("test task")
2627
))
2728
task.start()
2829

python/udp_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def task_func():
3030
return False # we don't want to stop the task
3131

3232
task = espp.Task(espp.TaskSimpleConfig(
33-
"test task", #name
34-
task_func
33+
task_func, #function
34+
# config
35+
espp.TaskBaseConfig("test task")
3536
))
3637
task.start()
3738

0 commit comments

Comments
 (0)