1 |
ron |
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 |
* leds.h - Marlin general RGB LED support
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
#ifndef __LEDS_H__
|
|
|
28 |
#define __LEDS_H__
|
|
|
29 |
|
|
|
30 |
#include "MarlinConfig.h"
|
|
|
31 |
|
|
|
32 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
33 |
#include "neopixel.h"
|
|
|
34 |
#endif
|
|
|
35 |
|
|
|
36 |
#define HAS_WHITE_LED (ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED))
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* LEDcolor type for use with leds.set_color
|
|
|
40 |
*/
|
|
|
41 |
typedef struct LEDColor {
|
|
|
42 |
uint8_t r, g, b
|
|
|
43 |
#if HAS_WHITE_LED
|
|
|
44 |
, w
|
|
|
45 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
46 |
, i
|
|
|
47 |
#endif
|
|
|
48 |
#endif
|
|
|
49 |
;
|
|
|
50 |
LEDColor() : r(255), g(255), b(255)
|
|
|
51 |
#if HAS_WHITE_LED
|
|
|
52 |
, w(255)
|
|
|
53 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
54 |
, i(NEOPIXEL_BRIGHTNESS)
|
|
|
55 |
#endif
|
|
|
56 |
#endif
|
|
|
57 |
{}
|
|
|
58 |
LEDColor(uint8_t r, uint8_t g, uint8_t b
|
|
|
59 |
#if HAS_WHITE_LED
|
|
|
60 |
, uint8_t w=0
|
|
|
61 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
62 |
, uint8_t i=NEOPIXEL_BRIGHTNESS
|
|
|
63 |
#endif
|
|
|
64 |
#endif
|
|
|
65 |
) : r(r), g(g), b(b)
|
|
|
66 |
#if HAS_WHITE_LED
|
|
|
67 |
, w(w)
|
|
|
68 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
69 |
, i(i)
|
|
|
70 |
#endif
|
|
|
71 |
#endif
|
|
|
72 |
{}
|
|
|
73 |
LEDColor(const uint8_t (&rgbw)[4]) : r(rgbw[0]), g(rgbw[1]), b(rgbw[2])
|
|
|
74 |
#if HAS_WHITE_LED
|
|
|
75 |
, w(rgbw[3])
|
|
|
76 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
77 |
, i(NEOPIXEL_BRIGHTNESS)
|
|
|
78 |
#endif
|
|
|
79 |
#endif
|
|
|
80 |
{}
|
|
|
81 |
LEDColor& operator=(const uint8_t (&rgbw)[4]) {
|
|
|
82 |
r = rgbw[0]; g = rgbw[1]; b = rgbw[2];
|
|
|
83 |
#if HAS_WHITE_LED
|
|
|
84 |
w = rgbw[3];
|
|
|
85 |
#endif
|
|
|
86 |
return *this;
|
|
|
87 |
}
|
|
|
88 |
LEDColor& operator=(const LEDColor &right) {
|
|
|
89 |
if (this != &right) memcpy(this, &right, sizeof(LEDColor));
|
|
|
90 |
return *this;
|
|
|
91 |
}
|
|
|
92 |
bool operator==(const LEDColor &right) {
|
|
|
93 |
if (this == &right) return true;
|
|
|
94 |
return 0 == memcmp(this, &right, sizeof(LEDColor));
|
|
|
95 |
}
|
|
|
96 |
bool operator!=(const LEDColor &right) { return !operator==(right); }
|
|
|
97 |
bool is_off() const {
|
|
|
98 |
return 3 > r + g + b
|
|
|
99 |
#if HAS_WHITE_LED
|
|
|
100 |
+ w
|
|
|
101 |
#endif
|
|
|
102 |
;
|
|
|
103 |
}
|
|
|
104 |
} LEDColor;
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* Color helpers and presets
|
|
|
108 |
*/
|
|
|
109 |
#if HAS_WHITE_LED
|
|
|
110 |
#define LEDColorWhite() LEDColor(0, 0, 0, 255)
|
|
|
111 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
112 |
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I)
|
|
|
113 |
#else
|
|
|
114 |
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W)
|
|
|
115 |
#endif
|
|
|
116 |
#else
|
|
|
117 |
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
|
|
|
118 |
#define LEDColorWhite() LEDColor(255, 255, 255)
|
|
|
119 |
#endif
|
|
|
120 |
#define LEDColorOff() LEDColor( 0, 0, 0)
|
|
|
121 |
#define LEDColorRed() LEDColor(255, 0, 0)
|
|
|
122 |
#define LEDColorOrange() LEDColor(255, 80, 0)
|
|
|
123 |
#define LEDColorYellow() LEDColor(255, 255, 0)
|
|
|
124 |
#define LEDColorGreen() LEDColor( 0, 255, 0)
|
|
|
125 |
#define LEDColorBlue() LEDColor( 0, 0, 255)
|
|
|
126 |
#define LEDColorIndigo() LEDColor( 0, 255, 255)
|
|
|
127 |
#define LEDColorViolet() LEDColor(255, 0, 255)
|
|
|
128 |
|
|
|
129 |
class LEDLights {
|
|
|
130 |
public:
|
|
|
131 |
LEDLights() {} // ctor
|
|
|
132 |
|
|
|
133 |
static void setup(); // init()
|
|
|
134 |
|
|
|
135 |
static void set_color(const LEDColor &color
|
|
|
136 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
137 |
, bool isSequence=false
|
|
|
138 |
#endif
|
|
|
139 |
);
|
|
|
140 |
|
|
|
141 |
FORCE_INLINE void set_color(uint8_t r, uint8_t g, uint8_t b
|
|
|
142 |
#if HAS_WHITE_LED
|
|
|
143 |
, uint8_t w=0
|
|
|
144 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
145 |
, uint8_t i=NEOPIXEL_BRIGHTNESS
|
|
|
146 |
#endif
|
|
|
147 |
#endif
|
|
|
148 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
149 |
, bool isSequence=false
|
|
|
150 |
#endif
|
|
|
151 |
) {
|
|
|
152 |
set_color(MakeLEDColor(r, g, b, w, i)
|
|
|
153 |
#if ENABLED(NEOPIXEL_LED)
|
|
|
154 |
, isSequence
|
|
|
155 |
#endif
|
|
|
156 |
);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
static void set_white();
|
|
|
160 |
FORCE_INLINE static void set_off() { set_color(LEDColorOff()); }
|
|
|
161 |
FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); }
|
|
|
162 |
|
|
|
163 |
#if ENABLED(LED_COLOR_PRESETS)
|
|
|
164 |
static const LEDColor defaultLEDColor;
|
|
|
165 |
FORCE_INLINE static void set_default() { set_color(defaultLEDColor); }
|
|
|
166 |
FORCE_INLINE static void set_red() { set_color(LEDColorRed()); }
|
|
|
167 |
FORCE_INLINE static void set_orange() { set_color(LEDColorOrange()); }
|
|
|
168 |
FORCE_INLINE static void set_yellow() { set_color(LEDColorYellow()); }
|
|
|
169 |
FORCE_INLINE static void set_blue() { set_color(LEDColorBlue()); }
|
|
|
170 |
FORCE_INLINE static void set_indigo() { set_color(LEDColorIndigo()); }
|
|
|
171 |
FORCE_INLINE static void set_violet() { set_color(LEDColorViolet()); }
|
|
|
172 |
#endif
|
|
|
173 |
|
|
|
174 |
#if ENABLED(LED_CONTROL_MENU)
|
|
|
175 |
static LEDColor color; // last non-off color
|
|
|
176 |
static bool lights_on; // the last set color was "on"
|
|
|
177 |
static void toggle(); // swap "off" with color
|
|
|
178 |
FORCE_INLINE static void update() { set_color(color); }
|
|
|
179 |
#endif
|
|
|
180 |
};
|
|
|
181 |
|
|
|
182 |
extern LEDLights leds;
|
|
|
183 |
|
|
|
184 |
#endif // __LEDS_H__
|