From 3f343f2b5971d99de048aa9381a4ebe1c6162b38 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 26 Sep 2024 05:45:29 +0200 Subject: [PATCH] SWTimer (periodic_task) - callback add arg time_now --- src/main_osp.cc | 6 +++--- src/utils.cc | 5 ++--- src/utils.hh | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main_osp.cc b/src/main_osp.cc index 55b0fc8..5ff6a30 100644 --- a/src/main_osp.cc +++ b/src/main_osp.cc @@ -219,14 +219,14 @@ namespace Heck { SWTimer heartbeat{}; heartbeat.set_period(500); - heartbeat.set_callback([&heartbeat_led_state](){ + heartbeat.set_callback([&heartbeat_led_state](u32 time_now) { heartbeat_led_state = !heartbeat_led_state; hw.SetLed(heartbeat_led_state); }); SWTimer async_log_tx{}; async_log_tx.set_period(5); - async_log_tx.set_callback([time_boot_ms](){ + async_log_tx.set_callback([](u32 time_now) { if (!event_log.IsEmpty()) { auto msg = event_log.PopFront(); switch (msg.type) { @@ -252,7 +252,7 @@ namespace Heck { outstr, "time-last:\t%ld\ttype: %s\tChannel: %d\tData MSB: " "%d\tData LSB: %d\n", - time_boot_ms, + time_now, type_str, msg.channel, msg.data[0], diff --git a/src/utils.cc b/src/utils.cc index 75229a6..3c5ca3f 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -108,11 +108,10 @@ namespace Heck { bool SWTimer::is_it_already_time_again(u32 time_now) { if (time_now - time_last_exec_ >= time_period_) { - time_last_exec_ = time_now; if (callback_) { - //todo: constexpr if metrics - callback_(); + callback_(time_now); } + time_last_exec_ = time_now; return true; } return false; diff --git a/src/utils.hh b/src/utils.hh index 9ca24b9..9f2fd99 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -16,7 +16,7 @@ namespace Heck { namespace Heck { class SWTimer { public: - using Callback = std::function; + using Callback = std::function; void set_period(u32 time_units); void set_callback(const Callback& cb);