Преглед на файлове

Encapsulate RGB(W) LEDs

Scott Lahteine преди 7 години
родител
ревизия
8fbb833de9

+ 1
- 1
Marlin/src/Makefile Целия файл

@@ -310,7 +310,7 @@ CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin.cpp \
310 310
 	module/temperature.cpp sd/cardreader.cpp module/configuration_store.cpp \
311 311
 	HAL/watchdog.cpp SPI.cpp HAL/servo.cpp Tone.cpp lcd/ultralcd.cpp libs/digipot_mcp4451.cpp \
312 312
 	feature/dac/dac_mcp4728.cpp libs/vector_3.cpp libs/least_squares_fit.cpp module/endstops.cpp libs/stopwatch.cpp core/utility.cpp \
313
-	module/printcounter.cpp libs/nozzle.cpp core/serial.cpp gcode/parser.cpp libs/Max7219_Debug_LEDs.cpp
313
+	module/printcounter.cpp libs/nozzle.cpp core/serial.cpp gcode/parser.cpp feature/Max7219_Debug_LEDs.cpp
314 314
 ifeq ($(NEOPIXEL), 1)
315 315
 CXXSRC += Adafruit_NeoPixel.cpp
316 316
 endif

+ 3
- 101
Marlin/src/Marlin.cpp Целия файл

@@ -71,19 +71,11 @@
71 71
 #endif
72 72
 
73 73
 #if ENABLED(MAX7219_DEBUG)
74
-  #include "feature/leds/Max7219_Debug_LEDs.h"
74
+  #include "feature/Max7219_Debug_LEDs.h"
75 75
 #endif
76 76
 
77
-#if ENABLED(NEOPIXEL_RGBW_LED)
78
-  #include <Adafruit_NeoPixel.h>
79
-#endif
80
-
81
-#if ENABLED(BLINKM)
82
-  #include "feature/leds/blinkm.h"
83
-#endif
84
-
85
-#if ENABLED(PCA9632)
86
-  #include "feature/leds/pca9632.h"
77
+#if HAS_COLOR_LEDS
78
+  #include "feature/leds/leds.h"
87 79
 #endif
88 80
 
89 81
 #if HAS_SERVOS
@@ -492,96 +484,6 @@ void servo_init() {
492 484
 
493 485
 #endif
494 486
 
495
-#if HAS_COLOR_LEDS
496
-
497
-  #if ENABLED(NEOPIXEL_RGBW_LED)
498
-
499
-    Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEO_GRBW + NEO_KHZ800);
500
-
501
-    void set_neopixel_color(const uint32_t color) {
502
-      for (uint16_t i = 0; i < pixels.numPixels(); ++i)
503
-        pixels.setPixelColor(i, color);
504
-      pixels.show();
505
-    }
506
-
507
-    void setup_neopixel() {
508
-      pixels.setBrightness(255); // 0 - 255 range
509
-      pixels.begin();
510
-      pixels.show(); // initialize to all off
511
-
512
-      #if ENABLED(NEOPIXEL_STARTUP_TEST)
513
-        delay(2000);
514
-        set_neopixel_color(pixels.Color(255, 0, 0, 0));  // red
515
-        delay(2000);
516
-        set_neopixel_color(pixels.Color(0, 255, 0, 0));  // green
517
-        delay(2000);
518
-        set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
519
-        delay(2000);
520
-      #endif
521
-      set_neopixel_color(pixels.Color(0, 0, 0, 255));    // white
522
-    }
523
-
524
-  #endif // NEOPIXEL_RGBW_LED
525
-
526
-  void set_led_color(
527
-    const uint8_t r, const uint8_t g, const uint8_t b
528
-      #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_RGBW_LED)
529
-        , const uint8_t w = 0
530
-        #if ENABLED(NEOPIXEL_RGBW_LED)
531
-          , bool isSequence = false
532
-        #endif
533
-      #endif
534
-  ) {
535
-
536
-    #if ENABLED(NEOPIXEL_RGBW_LED)
537
-
538
-      const uint32_t color = pixels.Color(r, g, b, w);
539
-      static uint16_t nextLed = 0;
540
-
541
-      if (!isSequence)
542
-        set_neopixel_color(color);
543
-      else {
544
-        pixels.setPixelColor(nextLed, color);
545
-        pixels.show();
546
-        if (++nextLed >= pixels.numPixels()) nextLed = 0;
547
-        return;
548
-      }
549
-
550
-    #endif
551
-
552
-    #if ENABLED(BLINKM)
553
-
554
-      // This variant uses i2c to send the RGB components to the device.
555
-      SendColors(r, g, b);
556
-
557
-    #endif
558
-
559
-    #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
560
-
561
-      // This variant uses 3 separate pins for the RGB components.
562
-      // If the pins can do PWM then their intensity will be set.
563
-      WRITE(RGB_LED_R_PIN, r ? HIGH : LOW);
564
-      WRITE(RGB_LED_G_PIN, g ? HIGH : LOW);
565
-      WRITE(RGB_LED_B_PIN, b ? HIGH : LOW);
566
-      analogWrite(RGB_LED_R_PIN, r);
567
-      analogWrite(RGB_LED_G_PIN, g);
568
-      analogWrite(RGB_LED_B_PIN, b);
569
-
570
-      #if ENABLED(RGBW_LED)
571
-        WRITE(RGB_LED_W_PIN, w ? HIGH : LOW);
572
-        analogWrite(RGB_LED_W_PIN, w);
573
-      #endif
574
-
575
-    #endif
576
-
577
-    #if ENABLED(PCA9632)
578
-      // Update I2C LED driver
579
-      PCA9632_SetColor(r, g, b);
580
-    #endif
581
-  }
582
-
583
-#endif // HAS_COLOR_LEDS
584
-
585 487
 #if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE)
586 488
 
587 489
   /**

+ 237
- 0
Marlin/src/feature/Max7219_Debug_LEDs.cpp Целия файл

@@ -0,0 +1,237 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * This module is off by default, but can be enabled to facilitate the display of
25
+ * extra debug information during code development. It assumes the existence of a
26
+ * Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
27
+ * http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
28
+ *
29
+ * Just connect up +5v and GND to give it power, then connect up the pins assigned
30
+ * in Configuration_adv.h. For example, on the Re-ARM you could use:
31
+ *
32
+ *   #define MAX7219_CLK_PIN   77
33
+ *   #define MAX7219_DIN_PIN   78
34
+ *   #define MAX7219_LOAD_PIN  79
35
+ *
36
+ * Max7219_init() is called automatically at startup, and then there are a number of
37
+ * support functions available to control the LEDs in the 8x8 grid.
38
+ *
39
+ * void Max7219_init();
40
+ * void Max7219_PutByte(uint8_t data);
41
+ * void Max7219(uint8_t reg, uint8_t data);
42
+ * void Max7219_LED_On(uint8_t row, uint8_t col);
43
+ * void Max7219_LED_Off(uint8_t row, uint8_t col);
44
+ * void Max7219_LED_Toggle(uint8_t row, uint8_t col);
45
+ * void Max7219_Clear_Row(uint8_t row);
46
+ * void Max7219_Clear_Column(uint8_t col);
47
+ * void Max7219_Set_Row(uint8_t row, uint8_t val);
48
+ * void Max7219_Set_Column(uint8_t col, uint8_t val);
49
+ * void Max7219_idle_tasks();
50
+ */
51
+
52
+#include "../inc/MarlinConfig.h"
53
+
54
+#if ENABLED(MAX7219_DEBUG)
55
+
56
+#include "Max7219_Debug_LEDs.h"
57
+
58
+#include "../module/planner.h"
59
+#include "../module/stepper.h"
60
+#include "../Marlin.h"
61
+
62
+static uint8_t LEDs[8] = { 0 };
63
+
64
+void Max7219_PutByte(uint8_t data) {
65
+  for (uint8_t i = 8; i--;) {
66
+    WRITE(MAX7219_CLK_PIN, LOW);       // tick
67
+    WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW);  // send 1 or 0 based on data bit
68
+    WRITE(MAX7219_CLK_PIN, HIGH);      // tock
69
+    data <<= 1;
70
+  }
71
+}
72
+
73
+void Max7219(const uint8_t reg, const uint8_t data) {
74
+  WRITE(MAX7219_LOAD_PIN, LOW);  // begin
75
+  Max7219_PutByte(reg);          // specify register
76
+  Max7219_PutByte(data);         // put data
77
+  WRITE(MAX7219_LOAD_PIN, LOW);  // and tell the chip to load the data
78
+  WRITE(MAX7219_LOAD_PIN, HIGH);
79
+}
80
+
81
+void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
82
+  if (row > 7 || col > 7) return;
83
+  if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
84
+  if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
85
+  Max7219(8 - row, LEDs[row]);
86
+}
87
+
88
+void Max7219_LED_On(const uint8_t row, const uint8_t col) {
89
+  Max7219_LED_Set(row, col, true);
90
+}
91
+
92
+void Max7219_LED_Off(const uint8_t row, const uint8_t col) {
93
+  Max7219_LED_Set(row, col, false);
94
+}
95
+
96
+void Max7219_LED_Toggle(const uint8_t row, const uint8_t col) {
97
+  if (row > 7 || col > 7) return;
98
+  if (TEST(LEDs[row], col))
99
+    Max7219_LED_Off(row, col);
100
+  else
101
+    Max7219_LED_On(row, col);
102
+}
103
+
104
+void Max7219_Clear_Column(const uint8_t col) {
105
+  if (col > 7) return;
106
+  LEDs[col] = 0;
107
+  Max7219(8 - col, LEDs[col]);
108
+}
109
+
110
+void Max7219_Clear_Row(const uint8_t row) {
111
+  if (row > 7) return;
112
+  for (uint8_t c = 0; c <= 7; c++)
113
+    Max7219_LED_Off(c, row);
114
+}
115
+
116
+void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
117
+  if (row > 7) return;
118
+  for (uint8_t b = 0; b <= 7; b++)
119
+    if (TEST(val, b))
120
+      Max7219_LED_On(7 - b, row);
121
+    else
122
+      Max7219_LED_Off(7 - b, row);
123
+}
124
+
125
+void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
126
+  if (col > 7) return;
127
+  LEDs[col] = val;
128
+  Max7219(8 - col, LEDs[col]);
129
+}
130
+
131
+void Max7219_init() {
132
+  uint8_t i, x, y;
133
+
134
+  SET_OUTPUT(MAX7219_DIN_PIN);
135
+  SET_OUTPUT(MAX7219_CLK_PIN);
136
+
137
+  OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
138
+
139
+  //initiation of the max 7219
140
+  Max7219(max7219_reg_scanLimit, 0x07);
141
+  Max7219(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
142
+  Max7219(max7219_reg_shutdown, 0x01);    // not in shutdown mode
143
+  Max7219(max7219_reg_displayTest, 0x00); // no display test
144
+  Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
145
+                                               // range: 0x00 to 0x0F
146
+  for (i = 0; i <= 7; i++) {      // empty registers, turn all LEDs off
147
+    LEDs[i] = 0x00;
148
+    Max7219(i + 1, 0);
149
+  }
150
+
151
+  for (x = 0; x <= 7; x++)        // Do an aesthetically pleasing pattern to fully test
152
+    for (y = 0; y <= 7; y++) {    // the Max7219 module and LEDs. First, turn them
153
+      Max7219_LED_On(x, y);       // all on.
154
+      delay(3);
155
+    }
156
+
157
+  for (x = 0; x <= 7; x++)        // Now, turn them all off.
158
+    for (y = 0; y <= 7; y++) {
159
+      Max7219_LED_Off(x, y);
160
+      delay(3);                   // delay() is OK here. Max7219_init() is only called from
161
+    }                             // setup() and nothing is running yet.
162
+
163
+  delay(150);
164
+
165
+  for (x = 8; x--;)               // Now, do the same thing from the opposite direction
166
+    for (y = 0; y <= 7; y++) {
167
+      Max7219_LED_On(x, y);
168
+      delay(2);
169
+    }
170
+
171
+  for (x = 8; x--;)
172
+    for (y = 0; y <= 7; y++) {
173
+      Max7219_LED_Off(x, y);
174
+      delay(2);
175
+    }
176
+}
177
+
178
+/**
179
+* These are sample debug features to demonstrate the usage of the 8x8 LED Matrix for debug purposes.
180
+* There is very little CPU burden added to the system by displaying information within the idle()
181
+* task.
182
+*
183
+* But with that said, if your debugging can be facilitated by making calls into the library from
184
+* other places in the code, feel free to do it.  The CPU burden for a few calls to toggle an LED
185
+* or clear a row is not very significant.
186
+*/
187
+void Max7219_idle_tasks() {
188
+  #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
189
+    static int debug_cnt = 0;
190
+    if (debug_cnt++ > 100) {
191
+      Max7219_LED_Toggle(7, 7);
192
+      debug_cnt = 0;
193
+    }
194
+  #endif
195
+
196
+  #ifdef MAX7219_DEBUG_STEPPER_HEAD
197
+    Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD);
198
+    Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD + 1);
199
+    if ( planner.block_buffer_head < 8)
200
+      Max7219_LED_On( planner.block_buffer_head, MAX7219_DEBUG_STEPPER_HEAD);
201
+    else
202
+      Max7219_LED_On( planner.block_buffer_head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
203
+  #endif
204
+
205
+  #ifdef MAX7219_DEBUG_STEPPER_TAIL
206
+    Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL);
207
+    Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL + 1);
208
+    if ( planner.block_buffer_tail < 8)
209
+      Max7219_LED_On( planner.block_buffer_tail, MAX7219_DEBUG_STEPPER_TAIL );
210
+    else
211
+      Max7219_LED_On( planner.block_buffer_tail-8, MAX7219_DEBUG_STEPPER_TAIL+1 );
212
+  #endif
213
+
214
+  #ifdef MAX7219_DEBUG_STEPPER_QUEUE
215
+    static int16_t last_depth = 0;
216
+    int16_t current_depth = planner.block_buffer_head - planner.block_buffer_tail;
217
+    if (current_depth != last_depth) {  // usually, no update will be needed.
218
+      if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
219
+      NOMORE(current_depth, BLOCK_BUFFER_SIZE);
220
+      NOMORE(current_depth, 16);        // if the BLOCK_BUFFER_SIZE is greater than 16, two lines
221
+                                        // of LEDs is enough to see if the buffer is draining
222
+
223
+      const uint8_t st = min(current_depth, last_depth),
224
+                    en = max(current_depth, last_depth);
225
+      if (current_depth < last_depth)
226
+        for (uint8_t i = st; i <= en; i++)   // clear the highest order LEDs
227
+          Max7219_LED_Off(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
228
+      else
229
+        for (uint8_t i = st; i <= en; i++)   // set the highest order LEDs
230
+          Max7219_LED_On(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
231
+
232
+      last_depth = current_depth;
233
+    }
234
+  #endif
235
+}
236
+
237
+#endif // MAX7219_DEBUG

Marlin/src/feature/leds/Max7219_Debug_LEDs.h → Marlin/src/feature/Max7219_Debug_LEDs.h Целия файл

@@ -53,36 +53,36 @@
53 53
 #ifndef __MAX7219_DEBUG_LEDS_H__
54 54
 #define __MAX7219_DEBUG_LEDS_H__
55 55
 
56
-  //
57
-  // define max7219 registers
58
-  //
59
-  #define max7219_reg_noop        0x00
60
-  #define max7219_reg_digit0      0x01
61
-  #define max7219_reg_digit1      0x02
62
-  #define max7219_reg_digit2      0x03
63
-  #define max7219_reg_digit3      0x04
64
-  #define max7219_reg_digit4      0x05
65
-  #define max7219_reg_digit5      0x06
66
-  #define max7219_reg_digit6      0x07
67
-  #define max7219_reg_digit7      0x08
56
+//
57
+// define max7219 registers
58
+//
59
+#define max7219_reg_noop        0x00
60
+#define max7219_reg_digit0      0x01
61
+#define max7219_reg_digit1      0x02
62
+#define max7219_reg_digit2      0x03
63
+#define max7219_reg_digit3      0x04
64
+#define max7219_reg_digit4      0x05
65
+#define max7219_reg_digit5      0x06
66
+#define max7219_reg_digit6      0x07
67
+#define max7219_reg_digit7      0x08
68 68
 
69
-  #define max7219_reg_intensity   0x0A
70
-  #define max7219_reg_displayTest 0x0F
71
-  #define max7219_reg_decodeMode  0x09
72
-  #define max7219_reg_scanLimit   0x0B
73
-  #define max7219_reg_shutdown    0x0C
69
+#define max7219_reg_intensity   0x0A
70
+#define max7219_reg_displayTest 0x0F
71
+#define max7219_reg_decodeMode  0x09
72
+#define max7219_reg_scanLimit   0x0B
73
+#define max7219_reg_shutdown    0x0C
74 74
 
75
-  void Max7219_init();
76
-  void Max7219_PutByte(uint8_t data);
77
-  void Max7219(const uint8_t reg, const uint8_t data);
78
-  void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on);
79
-  void Max7219_LED_On(const uint8_t row, const uint8_t col);
80
-  void Max7219_LED_Off(const uint8_t row, const uint8_t col);
81
-  void Max7219_LED_Toggle(const uint8_t row, const uint8_t col);
82
-  void Max7219_Clear_Row(const uint8_t row);
83
-  void Max7219_Clear_Column(const uint8_t col);
84
-  void Max7219_Set_Row(const uint8_t row, const uint8_t val);
85
-  void Max7219_Set_Column(const uint8_t col, const uint8_t val);
86
-  void Max7219_idle_tasks();
75
+void Max7219_init();
76
+void Max7219_PutByte(uint8_t data);
77
+void Max7219(const uint8_t reg, const uint8_t data);
78
+void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on);
79
+void Max7219_LED_On(const uint8_t row, const uint8_t col);
80
+void Max7219_LED_Off(const uint8_t row, const uint8_t col);
81
+void Max7219_LED_Toggle(const uint8_t row, const uint8_t col);
82
+void Max7219_Clear_Row(const uint8_t row);
83
+void Max7219_Clear_Column(const uint8_t col);
84
+void Max7219_Set_Row(const uint8_t row, const uint8_t val);
85
+void Max7219_Set_Column(const uint8_t col, const uint8_t val);
86
+void Max7219_idle_tasks();
87 87
 
88 88
 #endif // __MAX7219_DEBUG_LEDS_H__

+ 0
- 237
Marlin/src/feature/leds/Max7219_Debug_LEDs.cpp Целия файл

@@ -1,237 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
- *
8
- * This program is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-/**
24
- * This module is off by default, but can be enabled to facilitate the display of
25
- * extra debug information during code development. It assumes the existence of a
26
- * Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
27
- * http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
28
- *
29
- * Just connect up +5v and GND to give it power, then connect up the pins assigned
30
- * in Configuration_adv.h. For example, on the Re-ARM you could use:
31
- *
32
- *   #define MAX7219_CLK_PIN   77
33
- *   #define MAX7219_DIN_PIN   78
34
- *   #define MAX7219_LOAD_PIN  79
35
- *
36
- * Max7219_init() is called automatically at startup, and then there are a number of
37
- * support functions available to control the LEDs in the 8x8 grid.
38
- *
39
- * void Max7219_init();
40
- * void Max7219_PutByte(uint8_t data);
41
- * void Max7219(uint8_t reg, uint8_t data);
42
- * void Max7219_LED_On(uint8_t row, uint8_t col);
43
- * void Max7219_LED_Off(uint8_t row, uint8_t col);
44
- * void Max7219_LED_Toggle(uint8_t row, uint8_t col);
45
- * void Max7219_Clear_Row(uint8_t row);
46
- * void Max7219_Clear_Column(uint8_t col);
47
- * void Max7219_Set_Row(uint8_t row, uint8_t val);
48
- * void Max7219_Set_Column(uint8_t col, uint8_t val);
49
- * void Max7219_idle_tasks();
50
- */
51
-
52
-#include "../../inc/MarlinConfig.h"
53
-
54
-#if ENABLED(MAX7219_DEBUG)
55
-
56
-  #include "Max7219_Debug_LEDs.h"
57
-
58
-  #include "../../module/planner.h"
59
-  #include "../../module/stepper.h"
60
-  #include "../../Marlin.h"
61
-
62
-  static uint8_t LEDs[8] = { 0 };
63
-
64
-  void Max7219_PutByte(uint8_t data) {
65
-    for (uint8_t i = 8; i--;) {
66
-      WRITE(MAX7219_CLK_PIN, LOW);       // tick
67
-      WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW);  // send 1 or 0 based on data bit
68
-      WRITE(MAX7219_CLK_PIN, HIGH);      // tock
69
-      data <<= 1;
70
-    }
71
-  }
72
-
73
-  void Max7219(const uint8_t reg, const uint8_t data) {
74
-    WRITE(MAX7219_LOAD_PIN, LOW);  // begin
75
-    Max7219_PutByte(reg);          // specify register
76
-    Max7219_PutByte(data);         // put data
77
-    WRITE(MAX7219_LOAD_PIN, LOW);  // and tell the chip to load the data
78
-    WRITE(MAX7219_LOAD_PIN, HIGH);
79
-  }
80
-
81
-  void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
82
-    if (row > 7 || col > 7) return;
83
-    if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
84
-    if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
85
-    Max7219(8 - row, LEDs[row]);
86
-  }
87
-
88
-  void Max7219_LED_On(const uint8_t row, const uint8_t col) {
89
-    Max7219_LED_Set(row, col, true);
90
-  }
91
-
92
-  void Max7219_LED_Off(const uint8_t row, const uint8_t col) {
93
-    Max7219_LED_Set(row, col, false);
94
-  }
95
-
96
-  void Max7219_LED_Toggle(const uint8_t row, const uint8_t col) {
97
-    if (row > 7 || col > 7) return;
98
-    if (TEST(LEDs[row], col))
99
-      Max7219_LED_Off(row, col);
100
-    else
101
-      Max7219_LED_On(row, col);
102
-  }
103
-
104
-  void Max7219_Clear_Column(const uint8_t col) {
105
-    if (col > 7) return;
106
-    LEDs[col] = 0;
107
-    Max7219(8 - col, LEDs[col]);
108
-  }
109
-
110
-  void Max7219_Clear_Row(const uint8_t row) {
111
-    if (row > 7) return;
112
-    for (uint8_t c = 0; c <= 7; c++)
113
-      Max7219_LED_Off(c, row);
114
-  }
115
-
116
-  void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
117
-    if (row > 7) return;
118
-    for (uint8_t b = 0; b <= 7; b++)
119
-      if (TEST(val, b))
120
-        Max7219_LED_On(7 - b, row);
121
-      else
122
-        Max7219_LED_Off(7 - b, row);
123
-  }
124
-
125
-  void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
126
-    if (col > 7) return;
127
-    LEDs[col] = val;
128
-    Max7219(8 - col, LEDs[col]);
129
-  }
130
-
131
-  void Max7219_init() {
132
-    uint8_t i, x, y;
133
-
134
-    SET_OUTPUT(MAX7219_DIN_PIN);
135
-    SET_OUTPUT(MAX7219_CLK_PIN);
136
-
137
-    OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
138
-
139
-    //initiation of the max 7219
140
-    Max7219(max7219_reg_scanLimit, 0x07);
141
-    Max7219(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
142
-    Max7219(max7219_reg_shutdown, 0x01);    // not in shutdown mode
143
-    Max7219(max7219_reg_displayTest, 0x00); // no display test
144
-    Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
145
-                                                 // range: 0x00 to 0x0F
146
-    for (i = 0; i <= 7; i++) {      // empty registers, turn all LEDs off
147
-      LEDs[i] = 0x00;
148
-      Max7219(i + 1, 0);
149
-    }
150
-
151
-    for (x = 0; x <= 7; x++)        // Do an aesthetically pleasing pattern to fully test
152
-      for (y = 0; y <= 7; y++) {    // the Max7219 module and LEDs. First, turn them
153
-        Max7219_LED_On(x, y);       // all on.
154
-        delay(3);
155
-      }
156
-
157
-    for (x = 0; x <= 7; x++)        // Now, turn them all off.
158
-      for (y = 0; y <= 7; y++) {
159
-        Max7219_LED_Off(x, y);
160
-        delay(3);                   // delay() is OK here. Max7219_init() is only called from
161
-      }                             // setup() and nothing is running yet.
162
-
163
-    delay(150);
164
-
165
-    for (x = 8; x--;)               // Now, do the same thing from the opposite direction
166
-      for (y = 0; y <= 7; y++) {
167
-        Max7219_LED_On(x, y);
168
-        delay(2);
169
-      }
170
-
171
-    for (x = 8; x--;)
172
-      for (y = 0; y <= 7; y++) {
173
-        Max7219_LED_Off(x, y);
174
-        delay(2);
175
-      }
176
-  }
177
-
178
-/**
179
- * These are sample debug features to demonstrate the usage of the 8x8 LED Matrix for debug purposes.
180
- * There is very little CPU burden added to the system by displaying information within the idle()
181
- * task.
182
- *
183
- * But with that said, if your debugging can be facilitated by making calls into the library from
184
- * other places in the code, feel free to do it.  The CPU burden for a few calls to toggle an LED
185
- * or clear a row is not very significant.
186
- */
187
-  void Max7219_idle_tasks() {
188
-    #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
189
-      static int debug_cnt = 0;
190
-      if (debug_cnt++ > 100) {
191
-        Max7219_LED_Toggle(7, 7);
192
-        debug_cnt = 0;
193
-      }
194
-    #endif
195
-
196
-    #ifdef MAX7219_DEBUG_STEPPER_HEAD
197
-      Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD);
198
-      Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD + 1);
199
-      if ( planner.block_buffer_head < 8)
200
-        Max7219_LED_On( planner.block_buffer_head, MAX7219_DEBUG_STEPPER_HEAD);
201
-      else
202
-        Max7219_LED_On( planner.block_buffer_head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
203
-    #endif
204
-
205
-    #ifdef MAX7219_DEBUG_STEPPER_TAIL
206
-      Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL);
207
-      Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL + 1);
208
-      if ( planner.block_buffer_tail < 8)
209
-        Max7219_LED_On( planner.block_buffer_tail, MAX7219_DEBUG_STEPPER_TAIL );
210
-      else
211
-        Max7219_LED_On( planner.block_buffer_tail-8, MAX7219_DEBUG_STEPPER_TAIL+1 );
212
-    #endif
213
-
214
-    #ifdef MAX7219_DEBUG_STEPPER_QUEUE
215
-      static int16_t last_depth = 0;
216
-      int16_t current_depth = planner.block_buffer_head - planner.block_buffer_tail;
217
-      if (current_depth != last_depth) {  // usually, no update will be needed.
218
-        if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
219
-        NOMORE(current_depth, BLOCK_BUFFER_SIZE);
220
-        NOMORE(current_depth, 16);        // if the BLOCK_BUFFER_SIZE is greater than 16, two lines
221
-                                          // of LEDs is enough to see if the buffer is draining
222
-
223
-        const uint8_t st = min(current_depth, last_depth),
224
-                      en = max(current_depth, last_depth);
225
-        if (current_depth < last_depth)
226
-          for (uint8_t i = st; i <= en; i++)   // clear the highest order LEDs
227
-            Max7219_LED_Off(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
228
-        else
229
-          for (uint8_t i = st; i <= en; i++)   // set the highest order LEDs
230
-            Max7219_LED_On(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
231
-
232
-        last_depth = current_depth;
233
-      }
234
-    #endif
235
-  }
236
-
237
-#endif // MAX7219_DEBUG

+ 5
- 5
Marlin/src/feature/leds/blinkm.cpp Целия файл

@@ -25,20 +25,20 @@
25 25
  * Created by Tim Koster, August 21 2013.
26 26
  */
27 27
 
28
-#include "../../Marlin.h"
28
+#include "../../inc/MarlinConfig.h"
29 29
 
30 30
 #if ENABLED(BLINKM)
31 31
 
32 32
 #include "blinkm.h"
33 33
 
34
-void SendColors(byte red, byte grn, byte blu) {
34
+void blinkm_set_led_color(const byte r, const byte g, const byte b) {
35 35
   Wire.begin();
36 36
   Wire.beginTransmission(0x09);
37 37
   Wire.write('o');                    //to disable ongoing script, only needs to be used once
38 38
   Wire.write('n');
39
-  Wire.write(red);
40
-  Wire.write(grn);
41
-  Wire.write(blu);
39
+  Wire.write(r);
40
+  Wire.write(g);
41
+  Wire.write(b);
42 42
   Wire.endTransmission();
43 43
 }
44 44
 

+ 7
- 2
Marlin/src/feature/leds/blinkm.h Целия файл

@@ -25,7 +25,12 @@
25 25
  * Created by Tim Koster, August 21 2013.
26 26
  */
27 27
 
28
+#ifndef __BLINKM_H__
29
+#define __BLINKM_H__
30
+
28 31
 #include "Arduino.h"
29
-#include "Wire.h"
32
+#include <Wire.h>
33
+
34
+void blinkm_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b);
30 35
 
31
-void SendColors(byte red, byte grn, byte blu);
36
+#endif // __BLINKM_H__

+ 73
- 0
Marlin/src/feature/leds/leds.cpp Целия файл

@@ -0,0 +1,73 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Marlin RGB LED general support
25
+ */
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+
29
+#if HAS_COLOR_LEDS
30
+
31
+#include "leds.h"
32
+
33
+void set_led_color(
34
+  const uint8_t r, const uint8_t g, const uint8_t b
35
+  #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_RGBW_LED)
36
+    , const uint8_t w
37
+    #if ENABLED(NEOPIXEL_RGBW_LED)
38
+      , bool isSequence
39
+    #endif
40
+  #endif
41
+) {
42
+
43
+  #if ENABLED(NEOPIXEL_RGBW_LED)
44
+    if (neopixel_set_led_color(r, g, b, w, isSequence))
45
+      return;
46
+  #endif
47
+
48
+  #if ENABLED(BLINKM)
49
+    blinkm_set_led_color(r, g, b); // Use i2c to send the RGB components to the device.
50
+  #endif
51
+
52
+  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
53
+    // This variant uses 3 separate pins for the RGB components.
54
+    // If the pins can do PWM then their intensity will be set.
55
+    WRITE(RGB_LED_R_PIN, r ? HIGH : LOW);
56
+    WRITE(RGB_LED_G_PIN, g ? HIGH : LOW);
57
+    WRITE(RGB_LED_B_PIN, b ? HIGH : LOW);
58
+    analogWrite(RGB_LED_R_PIN, r);
59
+    analogWrite(RGB_LED_G_PIN, g);
60
+    analogWrite(RGB_LED_B_PIN, b);
61
+
62
+    #if ENABLED(RGBW_LED)
63
+      WRITE(RGB_LED_W_PIN, w ? HIGH : LOW);
64
+      analogWrite(RGB_LED_W_PIN, w);
65
+    #endif
66
+  #endif
67
+
68
+  #if ENABLED(PCA9632)
69
+    pca9632_set_led_color(r, g, b); // Update I2C LED driver
70
+  #endif
71
+}
72
+
73
+#endif // HAS_COLOR_LEDS

+ 53
- 0
Marlin/src/feature/leds/leds.h Целия файл

@@ -0,0 +1,53 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Marlin general RGB LED support
25
+ */
26
+
27
+#ifndef __LEDS_H__
28
+#define __LEDS_H__
29
+
30
+#if ENABLED(NEOPIXEL_RGBW_LED)
31
+  #include <Adafruit_NeoPixel.h>
32
+  #include "neopixel.h"
33
+#endif
34
+
35
+#if ENABLED(BLINKM)
36
+  #include "blinkm.h"
37
+#endif
38
+
39
+#if ENABLED(PCA9632)
40
+  #include "pca9632.h"
41
+#endif
42
+
43
+void set_led_color(
44
+  const uint8_t r, const uint8_t g, const uint8_t b
45
+  #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_RGBW_LED)
46
+    , const uint8_t w = 0
47
+    #if ENABLED(NEOPIXEL_RGBW_LED)
48
+      , bool isSequence = false
49
+    #endif
50
+  #endif
51
+);
52
+
53
+#endif // __LEDS_H__

+ 72
- 0
Marlin/src/feature/leds/neopixel.cpp Целия файл

@@ -0,0 +1,72 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Marlin RGB LED general support
25
+ */
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+
29
+#if ENABLED(NEOPIXEL_RGBW_LED)
30
+
31
+#include "neopixel.h"
32
+
33
+Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEO_GRBW + NEO_KHZ800);
34
+
35
+void set_neopixel_color(const uint32_t color) {
36
+  for (uint16_t i = 0; i < pixels.numPixels(); ++i)
37
+    pixels.setPixelColor(i, color);
38
+  pixels.show();
39
+}
40
+
41
+void setup_neopixel() {
42
+  pixels.setBrightness(255); // 0 - 255 range
43
+  pixels.begin();
44
+  pixels.show(); // initialize to all off
45
+
46
+  #if ENABLED(NEOPIXEL_STARTUP_TEST)
47
+    delay(2000);
48
+    set_neopixel_color(pixels.Color(255, 0, 0, 0));  // red
49
+    delay(2000);
50
+    set_neopixel_color(pixels.Color(0, 255, 0, 0));  // green
51
+    delay(2000);
52
+    set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
53
+    delay(2000);
54
+  #endif
55
+  set_neopixel_color(pixels.Color(0, 0, 0, 255));    // white
56
+}
57
+
58
+bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const bool isSequence) {
59
+  const uint32_t color = pixels.Color(r, g, b, w);
60
+  static uint16_t nextLed = 0;
61
+  if (!isSequence)
62
+    set_neopixel_color(color);
63
+  else {
64
+    pixels.setPixelColor(nextLed, color);
65
+    pixels.show();
66
+    if (++nextLed >= pixels.numPixels()) nextLed = 0;
67
+    return true;
68
+  }
69
+  return false;
70
+}
71
+
72
+#endif // NEOPIXEL_RGBW_LED

+ 38
- 0
Marlin/src/feature/leds/neopixel.h Целия файл

@@ -0,0 +1,38 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Neopixel support
25
+ */
26
+
27
+#ifndef __NEOPIXEL_H__
28
+#define __NEOPIXEL_H__
29
+
30
+#include <Adafruit_NeoPixel.h>
31
+#include <stdint.h>
32
+
33
+void setup_neopixel();
34
+bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const bool isSequence);
35
+
36
+extern Adafruit_NeoPixel pixels;
37
+
38
+#endif // __NEOPIXEL_H__

+ 1
- 2
Marlin/src/feature/leds/pca9632.cpp Целия файл

@@ -35,7 +35,6 @@
35 35
 #define PCA9632_MODE2_VALUE   0b00010101 //(DIMMING, INVERT, CHANGE ON STOP,TOTEM)
36 36
 #define PCA9632_LEDOUT_VALUE  0b00101010
37 37
 
38
-
39 38
 /* Register addresses */
40 39
 #define PCA9632_MODE1       0x00
41 40
 #define PCA9632_MODE2       0x01
@@ -98,7 +97,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
98 97
   }
99 98
 #endif
100 99
 
101
-void PCA9632_SetColor(const byte r, const byte g, const byte b) {
100
+void pca9632_set_led_color(const byte r, const byte g, const byte b) {
102 101
   if (!PCA_init) {
103 102
     PCA_init = 1;
104 103
     Wire.begin();

+ 2
- 2
Marlin/src/feature/leds/pca9632.h Целия файл

@@ -29,8 +29,8 @@
29 29
 #define __PCA9632_H__
30 30
 
31 31
 #include "Arduino.h"
32
-#include "Wire.h"
32
+#include <Wire.h>
33 33
 
34
-void PCA9632_SetColor(const byte r, const byte g, const byte  b);
34
+void pca9632_set_led_color(const byte r, const byte g, const byte b);
35 35
 
36 36
 #endif // __PCA9632_H__

+ 4
- 0
Marlin/src/gcode/queue.cpp Целия файл

@@ -32,6 +32,10 @@
32 32
 #include "../module/planner.h"
33 33
 #include "../Marlin.h"
34 34
 
35
+#if HAS_COLOR_LEDS
36
+  #include "../feature/leds/leds.h"
37
+#endif
38
+
35 39
 /**
36 40
  * GCode line number handling. Hosts may opt to include line numbers when
37 41
  * sending commands to Marlin, and lines will be checked for sequentiality.

+ 4
- 0
Marlin/src/gcode/temperature/M109.cpp Целия файл

@@ -34,6 +34,10 @@
34 34
   #include "../../module/motion.h"
35 35
 #endif
36 36
 
37
+#if HAS_COLOR_LEDS
38
+  #include "../../feature/leds/leds.h"
39
+#endif
40
+
37 41
 /**
38 42
  * M109: Sxxx Wait for extruder(s) to reach temperature. Waits only when heating.
39 43
  *       Rxxx Wait for extruder(s) to reach temperature. Waits when heating and cooling.

Loading…
Отказ
Запис