Browse Source

Tweak mark/range/quantity conditions

Scott Lahteine 5 years ago
parent
commit
a589456a14
1 changed files with 35 additions and 38 deletions
  1. 35
    38
      Marlin/src/feature/Max7219_Debug_LEDs.cpp

+ 35
- 38
Marlin/src/feature/Max7219_Debug_LEDs.cpp View File

@@ -273,24 +273,24 @@ void Max7219::set(const uint8_t line, const uint8_t bits) {
273 273
 
274 274
 // Modify a single LED bit and send the changed line
275 275
 void Max7219::led_set(const uint8_t x, const uint8_t y, const bool on) {
276
-  if (x > MAX7219_X_LEDS - 1 || y > MAX7219_Y_LEDS - 1) return error(PSTR("led_set"), x, y);
276
+  if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_set"), x, y);
277 277
   if (BIT_7219(x, y) == on) return;
278 278
   XOR_7219(x, y);
279 279
   refresh_unit_line(LED_IND(x, y));
280 280
 }
281 281
 
282 282
 void Max7219::led_on(const uint8_t x, const uint8_t y) {
283
-  if (x > MAX7219_X_LEDS - 1 || y > MAX7219_Y_LEDS - 1) return error(PSTR("led_on"), x, y);
283
+  if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_on"), x, y);
284 284
   led_set(x, y, true);
285 285
 }
286 286
 
287 287
 void Max7219::led_off(const uint8_t x, const uint8_t y) {
288
-  if (x > MAX7219_X_LEDS - 1 || y > MAX7219_Y_LEDS - 1) return error(PSTR("led_off"), x, y);
288
+  if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_off"), x, y);
289 289
   led_set(x, y, false);
290 290
 }
291 291
 
292 292
 void Max7219::led_toggle(const uint8_t x, const uint8_t y) {
293
-  if (x > MAX7219_X_LEDS - 1 || y > MAX7219_Y_LEDS - 1) return error(PSTR("led_toggle"), x, y);
293
+  if (x >= MAX7219_X_LEDS || y >= MAX7219_Y_LEDS) return error(PSTR("led_toggle"), x, y);
294 294
   led_set(x, y, !BIT_7219(x, y));
295 295
 }
296 296
 
@@ -462,7 +462,7 @@ void Max7219::register_setup() {
462 462
       led_set(px, py, on);
463 463
       delay(del);
464 464
       const int8_t x = px + way[dir], y = py + way[dir + 1];
465
-      if (!WITHIN(x, 0, MAX7219_X_LEDS-1) || !WITHIN(y, 0, MAX7219_Y_LEDS-1) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
465
+      if (!WITHIN(x, 0, MAX7219_X_LEDS - 1) || !WITHIN(y, 0, MAX7219_Y_LEDS - 1) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
466 466
       px += way[dir]; py += way[dir + 1];
467 467
     }
468 468
   }
@@ -470,7 +470,7 @@ void Max7219::register_setup() {
470 470
 #else
471 471
 
472 472
   void Max7219::sweep(const int8_t dir, const uint16_t ms, const bool on) {
473
-    uint8_t x = dir > 0 ? 0 : MAX7219_X_LEDS-1;
473
+    uint8_t x = dir > 0 ? 0 : MAX7219_X_LEDS - 1;
474 474
     for (uint8_t i = MAX7219_X_LEDS; i--; x += dir) {
475 475
       set_column(x, on ? 0xFFFFFFFF : 0x00000000);
476 476
       delay(ms);
@@ -519,54 +519,51 @@ void Max7219::init() {
519 519
 
520 520
 // Apply changes to update a marker
521 521
 void Max7219::mark16(const uint8_t pos, const uint8_t v1, const uint8_t v2) {
522
-  #if MAX7219_X_LEDS == 8
523
-    #if MAX7219_Y_LEDS == 8
524
-      led_off(v1 & 0x7, pos + (v1 >= 8));
525
-       led_on(v2 & 0x7, pos + (v2 >= 8));
526
-    #else
527
-      led_off(pos, v1 & 0xF); // At least 16 LEDs down. Use a single column.
528
-       led_on(pos, v2 & 0xF);
529
-    #endif
530
-  #else
531
-    led_off(v1 & 0xF, pos);   // At least 16 LEDs across. Use a single row.
522
+  #if MAX7219_X_LEDS > 8    // At least 16 LEDs on the X-Axis. Use single line.
523
+    led_off(v1 & 0xF, pos);
532 524
      led_on(v2 & 0xF, pos);
525
+  #elif MAX7219_Y_LEDS > 8  // At least 16 LEDs on the Y-Axis. Use a single column.
526
+    led_off(pos, v1 & 0xF);
527
+     led_on(pos, v2 & 0xF);
528
+  #else                     // Single 8x8 LED matrix. Use two lines to get 16 LEDs.
529
+    led_off(v1 & 0x7, pos + (v1 >= 8));
530
+     led_on(v2 & 0x7, pos + (v2 >= 8));
533 531
   #endif
534 532
 }
535 533
 
536 534
 // Apply changes to update a tail-to-head range
537 535
 void Max7219::range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh) {
538
-  #if MAX7219_X_LEDS == 8
539
-    #if MAX7219_Y_LEDS == 8
540
-      if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
541
-        led_off(n & 0x7, y + (n >= 8));
542
-      if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
543
-         led_on(n & 0x7, y + (n >= 8));
544
-    #else // The Max7219 Y-Axis has at least 16 LED's.  So use a single column
545
-      if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
546
-        led_off(y, n & 0xF);
547
-      if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
548
-         led_on(y, n & 0xF);
549
-    #endif
550
-  #else   // LED matrix has at least 16 LED's on the X-Axis.  Use single line of LED's
536
+  #if MAX7219_X_LEDS > 8    // At least 16 LEDs on the X-Axis. Use single line.
551 537
     if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
552 538
       led_off(n & 0xF, y);
553 539
     if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
554 540
        led_on(n & 0xF, y);
555
- #endif
541
+  #elif MAX7219_Y_LEDS > 8  // At least 16 LEDs on the Y-Axis. Use a single column.
542
+    if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
543
+      led_off(y, n & 0xF);
544
+    if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
545
+       led_on(y, n & 0xF);
546
+  #else                     // Single 8x8 LED matrix. Use two lines to get 16 LEDs.
547
+    if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
548
+      led_off(n & 0x7, y + (n >= 8));
549
+    if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
550
+       led_on(n & 0x7, y + (n >= 8));
551
+  #endif
556 552
 }
557 553
 
558 554
 // Apply changes to update a quantity
559 555
 void Max7219::quantity16(const uint8_t pos, const uint8_t ov, const uint8_t nv) {
560 556
   for (uint8_t i = _MIN(nv, ov); i < _MAX(nv, ov); i++)
561
-    #if MAX7219_X_LEDS == 8
562
-      #if MAX7219_Y_LEDS == 8
563
-        led_set(i >> 1, pos + (i & 1), nv >= ov); // Single 8x8 LED matrix.  Use two lines to get 16 LED's
564
-      #else
565
-        led_set(pos, i, nv >= ov);                // The Max7219 Y-Axis has at least 16 LED's.  So use a single column
557
+    led_set(
558
+      #if MAX7219_X_LEDS > 8    // At least 16 LEDs on the X-Axis. Use single line.
559
+        i, pos
560
+      #elif MAX7219_Y_LEDS > 8  // At least 16 LEDs on the Y-Axis. Use a single column.
561
+        pos, i
562
+      #else                     // Single 8x8 LED matrix. Use two lines to get 16 LEDs.
563
+        i >> 1, pos + (i & 1)
566 564
       #endif
567
-    #else
568
-      led_set(i, pos, nv >= ov);                  // LED matrix has at least 16 LED's on the X-Axis.  Use single line of LED's
569
-    #endif
565
+      , nv >= ov
566
+    );
570 567
 }
571 568
 
572 569
 void Max7219::idle_tasks() {

Loading…
Cancel
Save