Skip to content

Commit c488070

Browse files
committed
Minor cleanup w/r/t LEDs
1 parent 4b12435 commit c488070

16 files changed

+34
-43
lines changed

Marlin/Configuration.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@
23632363
//#define NEOPIXEL2_TYPE NEOPIXEL_TYPE
23642364
//#define NEOPIXEL2_PIN 5
23652365
//#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel
2366-
#define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used
2366+
#define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 NeoPixel strips are used
23672367
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
23682368
#define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255)
23692369
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup

Marlin/src/feature/leds/leds.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ void LEDLights::set_color(const LEDColor &incol
129129

130130
#endif
131131

132-
#if ENABLED(PCA9632)
133-
// Update I2C LED driver
134-
pca9632_set_led_color(incol);
135-
#endif
136-
137-
TERN_(PCA9533, PCA9533_setColor(incol.r, incol.g, incol.b));
132+
// Update I2C LED driver
133+
TERN_(PCA9632, PCA9632_set_led_color(incol));
134+
TERN_(PCA9533, PCA9533_set_rgb(incol.r, incol.g, incol.b));
138135

139136
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
140137
// Don't update the color when OFF

Marlin/src/feature/leds/leds.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ typedef struct LEDColor {
104104
bool operator!=(const LEDColor &right) { return !operator==(right); }
105105

106106
bool is_off() const {
107-
return 3 > r + g + b
108-
#if HAS_WHITE_LED
109-
+ w
110-
#endif
111-
;
107+
return 3 > r + g + b + TERN0(HAS_WHITE_LED, w);
112108
}
113109
} LEDColor;
114110

@@ -156,7 +152,7 @@ class LEDLights {
156152
#endif
157153
);
158154

159-
inline void set_color(uint8_t r, uint8_t g, uint8_t b
155+
static inline void set_color(uint8_t r, uint8_t g, uint8_t b
160156
#if HAS_WHITE_LED
161157
, uint8_t w=0
162158
#if ENABLED(NEOPIXEL_LED)

Marlin/src/feature/leds/neopixel.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
5353
#endif
5454

5555
void Marlin_NeoPixel::set_color(const uint32_t color) {
56-
if (get_neo_index() >= 0) {
57-
set_pixel_color(get_neo_index(), color);
58-
set_neo_index(-1);
56+
if (neoindex >= 0) {
57+
set_pixel_color(neoindex, color);
58+
neoindex = -1;
5959
}
6060
else {
6161
for (uint16_t i = 0; i < pixels(); ++i) {
@@ -78,18 +78,17 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
7878
}
7979

8080
void Marlin_NeoPixel::init() {
81-
set_neo_index(-1); // -1 .. NEOPIXEL_PIXELS-1 range
81+
neoindex = -1; // -1 .. NEOPIXEL_PIXELS-1 range
8282
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
8383
begin();
8484
show(); // initialize to all off
8585

8686
#if ENABLED(NEOPIXEL_STARTUP_TEST)
8787
set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
88-
safe_delay(1000);
88+
safe_delay(500);
8989
set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
90-
safe_delay(1000);
90+
safe_delay(500);
9191
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
92-
safe_delay(1000);
9392
#endif
9493

9594
#ifdef NEOPIXEL_BKGD_LED_INDEX

Marlin/src/feature/leds/neopixel.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ class Marlin_NeoPixel {
6565
, adaneo2
6666
#endif
6767
;
68-
static int8_t neoindex;
6968

7069
public:
70+
static int8_t neoindex;
71+
7172
static void init();
7273
static void set_color_startup(const uint32_t c);
7374

7475
static void set_color(const uint32_t c);
7576

76-
FORCE_INLINE static void set_neo_index(const int8_t neoIndex) { neoindex = neoIndex; }
77-
FORCE_INLINE static int8_t get_neo_index() { return neoindex; }
78-
7977
#ifdef NEOPIXEL_BKGD_LED_INDEX
8078
static void set_color_background();
8179
#endif

Marlin/src/feature/leds/pca9533.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void PCA9533_setOff() {
6262
PCA9533_writeRegister(PCA9533_REG_SEL, 0);
6363
}
6464

65-
void PCA9533_setColor(uint8_t red, uint8_t green, uint8_t blue) {
65+
void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue) {
6666
uint8_t r_pwm0 = 0; // Register data - PWM value
6767
uint8_t r_pwm1 = 0; // Register data - PWM value
6868

Marlin/src/feature/leds/pca9533.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@
5555

5656
void PCA9533_init();
5757
void PCA9533_reset();
58-
void PCA9533_setColor(uint8_t red, uint8_t green, uint8_t blue);
58+
void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue);
5959
void PCA9533_setOff();

Marlin/src/feature/leds/pca9632.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
120120
}
121121
#endif
122122

123-
void pca9632_set_led_color(const LEDColor &color) {
123+
void PCA9632_set_led_color(const LEDColor &color) {
124124
Wire.begin();
125125
if (!PCA_init) {
126126
PCA_init = 1;
@@ -138,7 +138,7 @@ void pca9632_set_led_color(const LEDColor &color) {
138138

139139
#if ENABLED(PCA9632_BUZZER)
140140

141-
void pca9632_buzz(const long, const uint16_t) {
141+
void PCA9632_buzz(const long, const uint16_t) {
142142
uint8_t data[] = PCA9632_BUZZER_DATA;
143143
Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
144144
Wire.write(data, sizeof(data));

Marlin/src/feature/leds/pca9632.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
struct LEDColor;
3030
typedef LEDColor LEDColor;
3131

32-
void pca9632_set_led_color(const LEDColor &color);
32+
void PCA9632_set_led_color(const LEDColor &color);
3333

3434
#if ENABLED(PCA9632_BUZZER)
3535
#include <stdint.h>
36-
void pca9632_buzz(const long, const uint16_t);
36+
void PCA9632_buzz(const long, const uint16_t);
3737
#endif

Marlin/src/feature/password/password.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* GNU General Public License for more details.
1717
*
1818
* 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/>.
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*
2121
*/
2222

Marlin/src/feature/password/password.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* GNU General Public License for more details.
1717
*
1818
* 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/>.
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*
2121
*/
2222
#pragma once

Marlin/src/gcode/feature/password/M510-M512.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* GNU General Public License for more details.
1717
*
1818
* 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/>.
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*
2121
*/
2222

Marlin/src/gcode/gcode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
* M141 - Set heated chamber target temp. S<temp> (Requires a chamber heater)
156156
* M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS)
157157
* M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
158-
* M150 - Set Status LED Color as R<red> U<green> B<blue> P<bright>. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632).
158+
* M150 - Set Status LED Color as R<red> U<green> B<blue> W<white> P<bright>. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632).
159159
* M155 - Auto-report temperatures with interval of S<seconds>. (Requires AUTO_REPORT_TEMPERATURES)
160160
* M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER)
161161
* M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER)

Marlin/src/lcd/menu/menu_led.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@
3434
#include "../../feature/leds/leds.h"
3535

3636
#if ENABLED(LED_COLOR_PRESETS)
37+
3738
void menu_led_presets() {
3839
START_MENU();
3940
#if LCD_HEIGHT > 2
4041
STATIC_ITEM(MSG_LED_PRESETS, SS_DEFAULT|SS_INVERT);
4142
#endif
4243
BACK_ITEM(MSG_LED_CONTROL);
43-
ACTION_ITEM(MSG_SET_LEDS_WHITE, leds.set_white);
44-
ACTION_ITEM(MSG_SET_LEDS_RED, leds.set_red);
44+
ACTION_ITEM(MSG_SET_LEDS_WHITE, leds.set_white);
45+
ACTION_ITEM(MSG_SET_LEDS_RED, leds.set_red);
4546
ACTION_ITEM(MSG_SET_LEDS_ORANGE, leds.set_orange);
46-
ACTION_ITEM(MSG_SET_LEDS_YELLOW,leds.set_yellow);
47-
ACTION_ITEM(MSG_SET_LEDS_GREEN, leds.set_green);
48-
ACTION_ITEM(MSG_SET_LEDS_BLUE, leds.set_blue);
47+
ACTION_ITEM(MSG_SET_LEDS_YELLOW, leds.set_yellow);
48+
ACTION_ITEM(MSG_SET_LEDS_GREEN, leds.set_green);
49+
ACTION_ITEM(MSG_SET_LEDS_BLUE, leds.set_blue);
4950
ACTION_ITEM(MSG_SET_LEDS_INDIGO, leds.set_indigo);
5051
ACTION_ITEM(MSG_SET_LEDS_VIOLET, leds.set_violet);
5152
END_MENU();
@@ -83,11 +84,10 @@
8384
#endif
8485
#endif
8586

86-
87-
8887
void menu_led() {
8988
START_MENU();
9089
BACK_ITEM(MSG_MAIN);
90+
9191
#if ENABLED(LED_CONTROL_MENU)
9292
bool led_on = leds.lights_on;
9393
EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
@@ -97,6 +97,7 @@ void menu_led() {
9797
#endif
9898
SUBMENU(MSG_CUSTOM_LEDS, menu_led_custom);
9999
#endif
100+
100101
//
101102
// Set Case light on/off/brightness
102103
//

Marlin/src/lcd/ultralcd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
8181
#endif
8282
void MarlinUI::buzz(const long duration, const uint16_t freq) {
8383
#if ENABLED(PCA9632_BUZZER)
84-
pca9632_buzz(duration, freq);
84+
PCA9632_buzz(duration, freq);
8585
#elif USE_BEEPER
8686
buzzer.tone(duration, freq);
8787
#endif

Marlin/src/pins/stm32f1/pins_CCROBOT_MEEB_3DP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
#define FAN1_PIN PA8 // FAN (fan0 on board) e0 cool fan
114114
#define FAN2_PIN PB9 // FAN (fan1 on board) controller cool fan
115115

116-
// One neopixel onboard and a connector for other neopixels
116+
// One NeoPixel onboard and a connector for other NeoPixels
117117
#define NEOPIXEL_PIN PC7 // The NEOPIXEL LED driving pin
118118

119119
/**

0 commit comments

Comments
 (0)