From 5850b250c97943a8ff3af0327bfbed80aaaaf4c5 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 29 Aug 2023 18:05:59 -0700 Subject: modules/strobe: add explicit "toggle" tap This sets the flash state when driven by something (like rkt). When driven, the toggle tap will override hz altogether. --- src/modules/strobe/strobe.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/modules/strobe/strobe.c b/src/modules/strobe/strobe.c index 789899a..e8dba3c 100644 --- a/src/modules/strobe/strobe.c +++ b/src/modules/strobe/strobe.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -35,13 +36,16 @@ typedef struct strobe_context_t { struct { til_tap_t hz; + til_tap_t toggle; } taps; struct { float hz; + float toggle; } vars; float *hz; + float *toggle; unsigned flash:1; unsigned flash_ready:1; @@ -55,6 +59,11 @@ static void strobe_update_taps(strobe_context_t *ctxt, til_stream_t *stream, flo else ctxt->vars.hz = *ctxt->hz; + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.toggle)) + ctxt->vars.toggle = NAN; + else + ctxt->vars.toggle = *ctxt->toggle; + if (ctxt->vars.hz <= 0.f) ctxt->vars.hz = 0.f; } @@ -72,6 +81,7 @@ static til_module_context_t * strobe_create_context(const til_module_t *module, ctxt->last_flash_ticks = ticks; ctxt->taps.hz = til_tap_init_float(ctxt, &ctxt->hz, 1, &ctxt->vars.hz, "hz"); + ctxt->taps.toggle = til_tap_init_float(ctxt, &ctxt->toggle, 1, &ctxt->vars.toggle, "toggle"); strobe_update_taps(ctxt, stream, 0.f); return &ctxt->til_module_context; @@ -86,6 +96,12 @@ static void strobe_prepare_frame(til_module_context_t *context, til_stream_t *st strobe_update_taps(ctxt, stream, (ticks - context->last_ticks) * .001f); + if (!isnan(ctxt->vars.toggle)) { + ctxt->flash = rintf(ctxt->vars.toggle) >= 1 ? 1 : 0; + ctxt->flash_ready = !ctxt->flash; /* kind of pointless */ + return; + } + if (ctxt->vars.hz <= 0.f) { ctxt->flash = 0; ctxt->flash_ready = 1; -- cgit v1.2.1