Browse Source

SWTimer (periodic_task) - callback add arg time_now

master
heck 9 months ago
parent
commit
3f343f2b59
  1. 6
      src/main_osp.cc
  2. 5
      src/utils.cc
  3. 2
      src/utils.hh

6
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],

5
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;

2
src/utils.hh

@ -16,7 +16,7 @@ namespace Heck {
namespace Heck {
class SWTimer {
public:
using Callback = std::function<void(void)>;
using Callback = std::function<void(u32 time)>;
void set_period(u32 time_units);
void set_callback(const Callback& cb);

Loading…
Cancel
Save