Public Access
Matrix refresh effect, and Random really picks from all effects
Yellow streaks fall down the columns that changed, at random moments, and leave the new image behind them. The start ticks come from a hash, so the only new RAM is one bit per column. Only a dot's final flip gets all pulses. Random took micros() % 8, but micros() only gives multiples of 4 on the Nano, so it could only pick sparkle or diagonal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35e678d78d
commit
8fcb17c395
13 files changed
+345
-19
No files matched your search
@@ -478,7 +478,7 @@ void test_effect_without_saving()
|
||||
|
||||
void test_invalid_effect_is_rejected()
|
||||
{
|
||||
send("E10,1500\n"); // unknown effect
|
||||
send("E11,1500\n"); // unknown effect
|
||||
send("E1,1500,4\n"); // unknown flag
|
||||
send("E1,50\n"); // too fast
|
||||
send("E1\n"); // no duration
|
||||
@@ -486,6 +486,18 @@ void test_invalid_effect_is_rejected()
|
||||
TEST_ASSERT_TRUE(replied("ERR"));
|
||||
}
|
||||
|
||||
void test_matrix_effect_is_accepted_and_stored()
|
||||
{
|
||||
send("E10,2000\n");
|
||||
TEST_ASSERT_EQUAL(EFFECT_MATRIX, display.last("effect")->a);
|
||||
TEST_ASSERT_FALSE(replied("ERR"));
|
||||
display.calls.clear();
|
||||
setup();
|
||||
TEST_ASSERT_EQUAL(EFFECT_MATRIX, display.last("effect")->a);
|
||||
TEST_ASSERT_EQUAL(2000, display.last("effect")->b);
|
||||
send("E0,1500,0\n");
|
||||
}
|
||||
|
||||
// Every effect order visits each dot exactly once
|
||||
static void checkSequence(uint8_t effect, uint8_t w, uint8_t h, uint16_t seed)
|
||||
{
|
||||
@@ -574,6 +586,59 @@ void test_sparkle_order_is_scrambled()
|
||||
TEST_ASSERT_LESS_THAN(n / 20, neighbours);
|
||||
}
|
||||
|
||||
void test_random_effect_reaches_all_effects_with_nano_micros()
|
||||
{
|
||||
// micros() on the Nano: multiples of 4. Taking the modulo of that directly only ever
|
||||
// gave sparkle and diagonal.
|
||||
int seen[EFFECT_COUNT] = {};
|
||||
for (uint32_t now = 0; now < 4000; now += 4)
|
||||
{
|
||||
uint8_t effect = randomEffect(now);
|
||||
TEST_ASSERT_LESS_THAN(EFFECT_COUNT, effect);
|
||||
seen[effect]++;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0, seen[EFFECT_INSTANT]);
|
||||
TEST_ASSERT_EQUAL(0, seen[EFFECT_RANDOM]);
|
||||
for (uint8_t effect = EFFECT_SPARKLE; effect < EFFECT_COUNT; effect++)
|
||||
if (effect != EFFECT_RANDOM)
|
||||
TEST_ASSERT_GREATER_THAN(100, seen[effect]);
|
||||
}
|
||||
|
||||
void test_matrix_start_ticks_are_spread_without_a_pattern()
|
||||
{
|
||||
const uint8_t spread = matrixStartSpread(19);
|
||||
TEST_ASSERT_EQUAL(matrixTicks(19), spread + 19 + MATRIX_STREAK);
|
||||
for (int seed = 0; seed < 256; seed++)
|
||||
{
|
||||
int starts[46] = {};
|
||||
int steps[46] = {};
|
||||
int close = 0, previous = 0;
|
||||
for (int x = 0; x < 84; x++)
|
||||
{
|
||||
int start = matrixStartTick(x, seed, spread);
|
||||
TEST_ASSERT_LESS_THAN(spread, start);
|
||||
starts[start]++;
|
||||
if (x)
|
||||
{
|
||||
close += abs(start - previous) <= 1;
|
||||
steps[(start - previous + spread) % spread]++;
|
||||
}
|
||||
previous = start;
|
||||
}
|
||||
for (int i = 0; i < spread; i++)
|
||||
{
|
||||
TEST_ASSERT_LESS_THAN(9, starts[i]); // no walls of streaks
|
||||
TEST_ASSERT_LESS_THAN(15, steps[i]); // no diagonal lines
|
||||
}
|
||||
TEST_ASSERT_LESS_THAN(20, close); // no wide bands
|
||||
}
|
||||
// A new frame gets other columns first
|
||||
int same = 0;
|
||||
for (int x = 0; x < 84; x++)
|
||||
same += matrixStartTick(x, 1, spread) == matrixStartTick(x, 2, spread);
|
||||
TEST_ASSERT_LESS_THAN(20, same);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Periodic full redraw
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -750,9 +815,12 @@ int main()
|
||||
RUN_TEST(test_effect_is_applied_and_stored);
|
||||
RUN_TEST(test_effect_without_saving);
|
||||
RUN_TEST(test_invalid_effect_is_rejected);
|
||||
RUN_TEST(test_matrix_effect_is_accepted_and_stored);
|
||||
RUN_TEST(test_every_effect_visits_each_dot_once);
|
||||
RUN_TEST(test_wipe_goes_left_to_right_and_center_starts_in_the_middle);
|
||||
RUN_TEST(test_sparkle_order_is_scrambled);
|
||||
RUN_TEST(test_random_effect_reaches_all_effects_with_nano_micros);
|
||||
RUN_TEST(test_matrix_start_ticks_are_spread_without_a_pattern);
|
||||
|
||||
RUN_TEST(test_refresh_when_due);
|
||||
RUN_TEST(test_refresh_only_once_per_interval);
|
||||
|
||||
Reference in new issue
Block a user