[light] Take trigger args as const ref in ApplyFn; drop hard-coded byte sizes

This commit is contained in:
J. Nick Koston
2026-04-29 06:52:29 -05:00
parent 040f4874b0
commit 83a634b58d
2 changed files with 7 additions and 6 deletions
+5 -5
View File
@@ -32,13 +32,13 @@ template<bool HasTransitionLength, typename... Ts> class ToggleAction : public A
};
// All configured fields are baked into a single stateless lambda whose
// constants live in flash. The action only stores a function pointer
// (4 bytes) plus the parent (4 bytes), regardless of how many fields the
// user set. Trigger args are forwarded to the apply function so user
// lambdas (e.g. `brightness: !lambda "return x;"`) keep working.
// constants live in flash. The action only stores one function pointer
// plus one parent pointer, regardless of how many fields the user set.
// Trigger args are forwarded to the apply function so user lambdas
// (e.g. `brightness: !lambda "return x;"`) keep working.
template<typename... Ts> class LightControlAction : public Action<Ts...> {
public:
using ApplyFn = void (*)(LightState *, LightCall &, Ts...);
using ApplyFn = void (*)(LightState *, LightCall &, const Ts &...);
LightControlAction(LightState *parent, ApplyFn apply) : parent_(parent), apply_(apply) {}
void play(const Ts &...x) override {
+2 -1
View File
@@ -230,10 +230,11 @@ async def light_control_to_code(config, action_id, template_arg, args):
f"call.set_effect(static_cast<uint32_t>({_resolve_effect_index(config)}));"
)
# Match LightControlAction::ApplyFn signature: const Ts &... for trigger args.
apply_args = [
(LightState.operator("ptr"), "parent"),
(LightCall.operator("ref"), "call"),
*args,
*((t.operator("const").operator("ref"), n) for t, n in args),
]
apply_lambda = LambdaExpression(
["\n".join(body_lines)],