-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (32 loc) · 1 KB
/
main.cpp
File metadata and controls
39 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <atomic>
#include <chrono>
#include <thread>
#include "logger.hpp"
#include "task.hpp"
using namespace std::chrono_literals;
extern "C" void app_main(void) {
espp::Logger logger({.tag = "Template", .level = espp::Logger::Verbosity::DEBUG});
logger.info("Bootup");
// counter to show the number of prints, shared between main and task
std::atomic<int> counter = 0;
// make a simple task that prints "Hello World!" every second
espp::Task task({
.callback = [&](auto &m, auto &cv) -> bool {
logger.debug("[{}] Hello from the task!", counter++);
std::unique_lock<std::mutex> lock(m);
cv.wait_for(lock, 1s);
// we don't want to stop the task, so return false
return false;
},
.task_config = {
.name = "Hello World",
.stack_size_bytes = 4096,
}
});
task.start();
// also print in the main thread
while (true) {
logger.debug("[{}] Hello World!", counter++);
std::this_thread::sleep_for(1s);
}
}