fix: Engine-Grenzen für Segmente und Blink-Anzahl
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user