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
@@ -124,6 +124,147 @@ void test_effects_end_with_the_right_image()
|
||||
}
|
||||
}
|
||||
|
||||
// Stricter than assertPanelShows(): shownPixel() would also agree with a leftover streak
|
||||
static void assertPanelHasPattern(int seed)
|
||||
{
|
||||
for (int x = 0; x < W; x++)
|
||||
for (int y = 0; y < H; y++)
|
||||
if (panel.dot[x][y] != (((x * 7 + y * 3 + seed) % 5) == 0))
|
||||
{
|
||||
char msg[64];
|
||||
snprintf(msg, sizeof(msg), "dot %d,%d is wrong", x, y);
|
||||
TEST_FAIL_MESSAGE(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void test_matrix_ends_with_the_right_image_and_reaches_every_dot_after_boot()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
d->setEffect(EFFECT_MATRIX, 500);
|
||||
drawPattern(*d, 0);
|
||||
d->display();
|
||||
finish(*d);
|
||||
TEST_ASSERT_EQUAL(W * H, dotsFlippedAtLeast(1));
|
||||
assertPanelHasPattern(0);
|
||||
drawPattern(*d, 2);
|
||||
d->display();
|
||||
finish(*d);
|
||||
assertPanelHasPattern(2);
|
||||
delete d;
|
||||
}
|
||||
|
||||
void test_matrix_flips_only_changed_columns_with_the_right_pulses()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
d->setEffect(EFFECT_MATRIX, 500);
|
||||
d->fillScreen(0);
|
||||
d->drawPixel(40, 3, 1); // stays yellow
|
||||
d->drawPixel(40, 9, 1); // yellow to black
|
||||
d->display();
|
||||
finish(*d);
|
||||
panel.clearCounts();
|
||||
|
||||
d->drawPixel(40, 9, 0);
|
||||
d->drawPixel(40, 12, 1); // black to yellow
|
||||
d->display();
|
||||
finish(*d);
|
||||
for (int x = 0; x < W; x++)
|
||||
for (int y = 0; y < H; y++)
|
||||
{
|
||||
int expected = x != 40 ? 0 : y == 3 ? 0 : y == 9 ? 3 : y == 12 ? 3 : 1 + 3;
|
||||
if (panel.flips[x][y] != expected)
|
||||
{
|
||||
char msg[64];
|
||||
snprintf(msg, sizeof(msg), "dot %d,%d: %d pulses, not %d", x, y, panel.flips[x][y], expected);
|
||||
TEST_FAIL_MESSAGE(msg);
|
||||
}
|
||||
}
|
||||
TEST_ASSERT_TRUE(panel.dot[40][3]);
|
||||
TEST_ASSERT_FALSE(panel.dot[40][9]);
|
||||
TEST_ASSERT_TRUE(panel.dot[40][12]);
|
||||
delete d;
|
||||
}
|
||||
|
||||
void test_matrix_streak_falls_from_the_top_and_takes_the_effect_time()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
d->setEffect(EFFECT_MATRIX, 1000);
|
||||
d->fillScreen(0);
|
||||
d->display();
|
||||
finish(*d);
|
||||
|
||||
d->drawPixel(40, 18, 1);
|
||||
uint32_t start = fake_micros;
|
||||
d->display();
|
||||
int highest = -1, longest = 0;
|
||||
while (d->busy())
|
||||
{
|
||||
d->update();
|
||||
int lit = 0, bottom = -1;
|
||||
for (int y = 0; y < H; y++)
|
||||
if (panel.dot[40][y])
|
||||
{
|
||||
lit++;
|
||||
bottom = y;
|
||||
}
|
||||
TEST_ASSERT_LESS_OR_EQUAL(highest + 1, bottom); // one row at a time, never upwards
|
||||
if (bottom > highest)
|
||||
highest = bottom;
|
||||
if (lit > longest)
|
||||
longest = lit;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(H - 1, highest);
|
||||
TEST_ASSERT_EQUAL(MATRIX_STREAK + 1, longest); // the tail goes after the head moved
|
||||
uint32_t took = fake_micros - start;
|
||||
TEST_ASSERT_UINT32_WITHIN(100000, 1000000, took);
|
||||
delete d;
|
||||
}
|
||||
|
||||
void test_matrix_full_screen_change_never_blocks_and_finishes_soon_enough()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
d->setEffect(EFFECT_MATRIX, 1500);
|
||||
drawPattern(*d, 0);
|
||||
d->display();
|
||||
finish(*d);
|
||||
drawPattern(*d, 1);
|
||||
uint32_t start = fake_micros;
|
||||
d->display();
|
||||
finish(*d);
|
||||
assertPanelHasPattern(1);
|
||||
uint32_t took = fake_micros - start;
|
||||
// DRIVE_MATRIX_EXTRA_TIME on the ESP32 keeps the power on for this much longer
|
||||
TEST_ASSERT_LESS_THAN(1500000 + 5000000, took);
|
||||
delete d;
|
||||
}
|
||||
|
||||
void test_matrix_interrupted_by_a_new_frame_leaves_no_streaks()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
d->setEffect(EFFECT_MATRIX, 1000);
|
||||
drawPattern(*d, 0);
|
||||
d->display();
|
||||
finish(*d);
|
||||
drawPattern(*d, 1);
|
||||
d->display();
|
||||
// Until streaks are visible: dots yellow that are in neither image
|
||||
int streak_dots = 0;
|
||||
while (d->busy() && streak_dots < 10)
|
||||
{
|
||||
d->update();
|
||||
streak_dots = 0;
|
||||
for (int x = 0; x < W; x++)
|
||||
for (int y = 0; y < H; y++)
|
||||
streak_dots += panel.dot[x][y] && ((x * 7 + y * 3) % 5) != 0 && ((x * 7 + y * 3 + 1) % 5) != 0;
|
||||
}
|
||||
TEST_ASSERT_TRUE(d->busy());
|
||||
drawPattern(*d, 2);
|
||||
d->display(false, true); // a moving page: instant
|
||||
finish(*d);
|
||||
assertPanelHasPattern(2);
|
||||
delete d;
|
||||
}
|
||||
|
||||
void test_refresh_flips_every_dot_once_without_blocking()
|
||||
{
|
||||
BROSE9323 *d = make();
|
||||
@@ -264,6 +405,11 @@ int main()
|
||||
RUN_TEST(test_first_frame_flips_every_dot_without_blocking);
|
||||
RUN_TEST(test_instant_frame_flips_only_the_changed_dots_with_all_pulses);
|
||||
RUN_TEST(test_effects_end_with_the_right_image);
|
||||
RUN_TEST(test_matrix_ends_with_the_right_image_and_reaches_every_dot_after_boot);
|
||||
RUN_TEST(test_matrix_flips_only_changed_columns_with_the_right_pulses);
|
||||
RUN_TEST(test_matrix_streak_falls_from_the_top_and_takes_the_effect_time);
|
||||
RUN_TEST(test_matrix_full_screen_change_never_blocks_and_finishes_soon_enough);
|
||||
RUN_TEST(test_matrix_interrupted_by_a_new_frame_leaves_no_streaks);
|
||||
RUN_TEST(test_refresh_flips_every_dot_once_without_blocking);
|
||||
RUN_TEST(test_refresh_pauses_while_a_frame_arrives_and_then_finishes);
|
||||
RUN_TEST(test_refresh_waits_for_a_running_effect);
|
||||
|
||||
@@ -756,6 +756,11 @@ void test_effect_time_is_zero_when_instant()
|
||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d));
|
||||
d.effect = DRIVE_EFFECT_RANDOM; // can be a push
|
||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d));
|
||||
d.effect = DRIVE_EFFECT_MATRIX; // flips most dots of a changed column twice
|
||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_MATRIX_EXTRA_TIME, (int)effectTime(d));
|
||||
Settings s;
|
||||
s.drive.effect = DRIVE_EFFECT_MATRIX;
|
||||
TEST_ASSERT_NULL(validateSettings(s));
|
||||
}
|
||||
|
||||
void test_settings_off_page_blank_or_bitmap_name()
|
||||
|
||||
@@ -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