From 472d2398acced49da4916d6805d0f605c3c7e74f Mon Sep 17 00:00:00 2001 From: Michael Sauer Date: Fri, 11 Sep 2026 13:17:21 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Engine-Grenzen=20f=C3=BCr=20Segmente=20u?= =?UTF-8?q?nd=20Blink-Anzahl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/light/nl_engine.c | 4 ++++ src/light/nl_engine.h | 1 + test/test_engine.c | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/light/nl_engine.c b/src/light/nl_engine.c index 3de3f41..039f89a 100644 --- a/src/light/nl_engine.c +++ b/src/light/nl_engine.c @@ -38,6 +38,8 @@ static int32_t lerp(int32_t a, int32_t b, uint32_t e, uint32_t d) static void push(const nl_visual_t *from, const nl_visual_t *to, uint32_t dur) { + if (s_nseg >= sizeof s_seg / sizeof s_seg[0]) + return; seg_t *s = &s_seg[s_nseg++]; s->from = *from; s->to = *to; @@ -165,6 +167,8 @@ void nl_engine_current(nl_visual_t *out) void nl_engine_blink(uint8_t count) { + if (count > NL_BLINK_MAX) + count = NL_BLINK_MAX; s_blink_left = (uint8_t)(count * 2u); s_blink_t = 0; emit(); diff --git a/src/light/nl_engine.h b/src/light/nl_engine.h index 1c8f59c..6a62cc4 100644 --- a/src/light/nl_engine.h +++ b/src/light/nl_engine.h @@ -8,6 +8,7 @@ #include "light/nl_light_types.h" #define NL_BLINK_PHASE_MS 300u +#define NL_BLINK_MAX 100u #define NL_PULSE_PERIOD_MS 3000u typedef void (*nl_output_fn)(const uint8_t ch[NL_CH_COUNT], void *ctx); diff --git a/test/test_engine.c b/test/test_engine.c index e5af686..84963a0 100644 --- a/test/test_engine.c +++ b/test/test_engine.c @@ -171,6 +171,18 @@ static void test_pulse(void) TEST_ASSERT_TRUE(nl_engine_idle()); } +static void test_blink_max_clamped(void) +{ + nl_engine_blink(200); /* > NL_BLINK_MAX, should clamp to 100 */ + TEST_ASSERT_FALSE(nl_engine_idle()); + /* After 99 blinks (99*2 phases = 198), should still be blinking */ + nl_engine_tick(300 * 99 * 2); + TEST_ASSERT_FALSE(nl_engine_idle()); + /* After 2 more phases to complete the last blink (total 100 blinks), should be idle */ + nl_engine_tick(300 * 2); + TEST_ASSERT_TRUE(nl_engine_idle()); +} + int main(void) { UNITY_BEGIN(); @@ -184,5 +196,6 @@ int main(void) RUN_TEST(test_color_interpolates); RUN_TEST(test_blink_overrides_and_restores); RUN_TEST(test_pulse); + RUN_TEST(test_blink_max_clamped); return UNITY_END(); }