@@ -480,32 +480,30 @@ void Max7219::register_setup() {
480
480
#if MAX7219_INIT_TEST
481
481
482
482
uint8_t test_mode = 0 ;
483
- millis_t next_patt_ms;
484
483
bool patt_on;
485
484
486
485
#if MAX7219_INIT_TEST == 2
487
486
488
487
#define MAX7219_LEDS (MAX7219_X_LEDS * MAX7219_Y_LEDS)
489
488
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;
493
491
uvalue_t (MAX7219_LEDS) spiral_count;
494
492
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)
500
498
spiral_dir = (spiral_dir + 1 ) & 0x3 ;
501
- spiralx += way[spiral_dir][0 ];
502
- spiraly += way[spiral_dir][1 ];
499
+ spiral += way[spiral_dir];
503
500
if (!spiral_count--) {
504
501
if (!patt_on)
505
502
test_mode = 0 ;
506
503
else {
507
504
spiral_count = MAX7219_LEDS;
508
- spiralx = spiraly = spiral_dir = 0 ;
505
+ spiral.reset ();
506
+ spiral_dir = 0 ;
509
507
patt_on = false ;
510
508
}
511
509
}
@@ -516,7 +514,11 @@ void Max7219::register_setup() {
516
514
constexpr millis_t pattern_delay = 20 ;
517
515
int8_t sweep_count, sweepx, sweep_dir;
518
516
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;
520
522
set_column (sweepx, patt_on ? 0xFFFFFFFF : 0x00000000 );
521
523
sweepx += sweep_dir;
522
524
if (!WITHIN (sweepx, 0 , MAX7219_X_LEDS - 1 )) {
@@ -527,26 +529,20 @@ void Max7219::register_setup() {
527
529
else
528
530
sweepx -= MAX7219_X_LEDS * sweep_dir;
529
531
FLIP (patt_on);
530
- next_patt_ms += 100 ;
532
+ next_pattern_ms += 100 ;
531
533
if (++test_mode > 4 ) test_mode = 0 ;
532
534
}
533
535
}
534
536
535
537
#endif
536
538
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
-
544
539
void Max7219::start_test_pattern () {
545
540
clear ();
546
541
test_mode = 1 ;
547
542
patt_on = true ;
548
543
#if MAX7219_INIT_TEST == 2
549
- spiralx = spiraly = spiral_dir = 0 ;
544
+ spiral.reset ();
545
+ spiral_dir = 0 ;
550
546
spiral_count = MAX7219_LEDS;
551
547
#else
552
548
sweep_dir = 1 ;
0 commit comments