ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.17k stars 386 forks source link

callback_timer: expose callback_timer_data::is_active() as icallback_timer public method #919

Closed ilya-a1 closed 1 month ago

ilya-a1 commented 2 months ago

Applications quite often need to check if a timer is active/running or is stopped. It would be nice if icallback_timer can provide bool is_active( etl::timer::id::type id_ ) method for checking if a timer is active. Since callback_timer_data struct already implements is_active, icallback_timer's implementation could simply be the following

bool is_active(etl::timer::id::type id_) const
{
  if (has_active)
  {
    // Valid timer id?
    if (id_ != etl::timer::id::NO_TIMER)
    {
      const etl::callback_timer_data& timer = timer_array[id_];

      // Registered timer?
      if (timer.id != etl::timer::id::NO_TIMER)
      {
        return timer.is_active();
      }
    }
  }
  return false;
}
jwellbelove commented 1 month ago

Fixed 20.39.3