Skip to content

move all functionality to apptask#863

Draft
sarthak shaha (Sarthak-Shaha) wants to merge 10 commits intomainfrom
feature/CRTP_lighting
Draft

move all functionality to apptask#863
sarthak shaha (Sarthak-Shaha) wants to merge 10 commits intomainfrom
feature/CRTP_lighting

Conversation

@Sarthak-Shaha
Copy link
Contributor

@Sarthak-Shaha sarthak shaha (Sarthak-Shaha) commented Feb 17, 2026

Summary

This PR refactors the Silabs lighting-app example by merging LightingManager into AppTask and introducing a CRTP-based extensibility layer. The new design centralizes light logic in AppTask and uses AppTaskImpl for targeted customization without modifying core behavior.


1. Merging of LightingManager and AppTask

Before: LightingManager was a separate singleton managing light state, timers, and actions, with callbacks wired to AppTask.

After: All lighting functionality is moved into AppTask:

  • Light state (mLightState), level, and color attributes live in AppTask
  • Timer handling (mLightTimer, auto-turn-off, off-with-effect) is in AppTask
  • InitLight(), InitiateAction(), IsLightOn(), EnableAutoTurnOff(), etc. are implemented in AppTask
  • LightTypes.h keeps only LightingManager::Action_t and LightingManager::State_t as shared enums to preserve the API surface and avoid circular includes; implementation stays in AppTask

Benefits: Single object for app and light logic, no callback indirection, simpler ownership and data flow.


2. CRTP in AppTaskImpl and Using CustomAppTask

Design: AppTaskImpl<Derived> is a CRTP base inheriting from AppTask that forwards every overridable operation to a *Impl() method on the derived class.

  • Public API: Methods (AppInit(), StartAppTask(), PostLightActionRequest(), InitLight(), etc.) forward to Derived::*Impl() via macros (CRTP_RETURN_AND_VERIFY, CRTP_VOID_AND_VERIFY, etc.)
  • Override points: All *Impl() methods have default implementations that call AppTask; override only what you need
  • Static callbacks: Static handlers (ButtonHandler, LightActionEventHandler) use CRTP_APP_TASK to call instance methods on the derived AppTask singleton

Using CustomAppTask:

  1. Derive from AppTaskImpl<YourCustomClass>:
class CustomAppTask : public AppTaskImpl<CustomAppTask>
  1. Implement GetAppTask() and sAppTask:
static CustomAppTask & GetAppTask() { return sAppTask; }
static CustomAppTask sAppTask;
  1. Override only the needed *Impl() methods (e.g. AppInitImpl, ButtonEventHandlerImpl, InitLightImpl, InitiateActionImpl).

  2. Wire AppTask::GetAppTask() to the custom singleton:

AppTask & AppTask::GetAppTask()
{
    return CustomAppTask::GetAppTask();
}

CustomAppTask in this PR demonstrates this by overriding AppInitImpl() and ButtonEventHandlerImpl().

Related issues

Testing

Readability checklist

The checklist below will help the reviewer finish PR review in time and keep the
code readable:

  • PR title is
    descriptive
  • Apply the
    “When in Rome…”
    rule (coding style)
  • PR size is short
  • Try to avoid "squashing" and "force-update" in commit history
  • CI time didn't increase

See: Pull Request Guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant