Skip to content

Commit 448ff71

Browse files
committed
πŸ§‘β€πŸ’» Tweak MAX7219 test pattern
1 parent c1e8d46 commit 448ff71

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

β€ŽMarlin/src/feature/max7219.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -480,32 +480,30 @@ void Max7219::register_setup() {
480480
#if MAX7219_INIT_TEST
481481

482482
uint8_t test_mode = 0;
483-
millis_t next_patt_ms;
484483
bool patt_on;
485484

486485
#if MAX7219_INIT_TEST == 2
487486

488487
#define MAX7219_LEDS (MAX7219_X_LEDS * MAX7219_Y_LEDS)
489488

490-
constexpr millis_t pattern_delay = 4;
491-
492-
int8_t spiralx, spiraly, spiral_dir;
489+
xy_int8_t spiral;
490+
int8_t spiral_dir;
493491
uvalue_t(MAX7219_LEDS) spiral_count;
494492

495-
void Max7219::test_pattern() {
496-
constexpr int8_t way[][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
497-
led_set(spiralx, spiraly, patt_on);
498-
const int8_t x = spiralx + way[spiral_dir][0], y = spiraly + way[spiral_dir][1];
499-
if (!WITHIN(x, 0, MAX7219_X_LEDS - 1) || !WITHIN(y, 0, MAX7219_Y_LEDS - 1) || BIT_7219(x, y) == patt_on)
493+
void Max7219::run_test_pattern() {
494+
constexpr xy_int8_t way[] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
495+
led_set(spiral.x, spiral.y, patt_on);
496+
const xy_int8_t xy = spiral + way[spiral_dir];
497+
if (!WITHIN(xy.x, 0, MAX7219_X_LEDS - 1) || !WITHIN(xy.y, 0, MAX7219_Y_LEDS - 1) || BIT_7219(xy.x, xy.y) == patt_on)
500498
spiral_dir = (spiral_dir + 1) & 0x3;
501-
spiralx += way[spiral_dir][0];
502-
spiraly += way[spiral_dir][1];
499+
spiral += way[spiral_dir];
503500
if (!spiral_count--) {
504501
if (!patt_on)
505502
test_mode = 0;
506503
else {
507504
spiral_count = MAX7219_LEDS;
508-
spiralx = spiraly = spiral_dir = 0;
505+
spiral.reset();
506+
spiral_dir = 0;
509507
patt_on = false;
510508
}
511509
}
@@ -516,7 +514,11 @@ void Max7219::register_setup() {
516514
constexpr millis_t pattern_delay = 20;
517515
int8_t sweep_count, sweepx, sweep_dir;
518516

519-
void Max7219::test_pattern() {
517+
void Max7219::run_test_pattern() {
518+
static millis_t next_pattern_ms = 0;
519+
const millis_t ms = millis();
520+
if (PENDING(ms, next_pattern_ms)) return;
521+
next_pattern_ms = ms + pattern_delay;
520522
set_column(sweepx, patt_on ? 0xFFFFFFFF : 0x00000000);
521523
sweepx += sweep_dir;
522524
if (!WITHIN(sweepx, 0, MAX7219_X_LEDS - 1)) {
@@ -527,26 +529,20 @@ void Max7219::register_setup() {
527529
else
528530
sweepx -= MAX7219_X_LEDS * sweep_dir;
529531
FLIP(patt_on);
530-
next_patt_ms += 100;
532+
next_pattern_ms += 100;
531533
if (++test_mode > 4) test_mode = 0;
532534
}
533535
}
534536

535537
#endif
536538

537-
void Max7219::run_test_pattern() {
538-
const millis_t ms = millis();
539-
if (PENDING(ms, next_patt_ms)) return;
540-
next_patt_ms = ms + pattern_delay;
541-
test_pattern();
542-
}
543-
544539
void Max7219::start_test_pattern() {
545540
clear();
546541
test_mode = 1;
547542
patt_on = true;
548543
#if MAX7219_INIT_TEST == 2
549-
spiralx = spiraly = spiral_dir = 0;
544+
spiral.reset();
545+
spiral_dir = 0;
550546
spiral_count = MAX7219_LEDS;
551547
#else
552548
sweep_dir = 1;

0 commit comments

Comments
Β (0)