Skip to content

Commit

Permalink
Minor cleanup w/r/t LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 24, 2020
1 parent 4b12435 commit c488070
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@
//#define NEOPIXEL2_TYPE NEOPIXEL_TYPE
//#define NEOPIXEL2_PIN 5
//#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel
#define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used
#define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 NeoPixel strips are used
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
#define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255)
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup
Expand Down
9 changes: 3 additions & 6 deletions Marlin/src/feature/leds/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,9 @@ void LEDLights::set_color(const LEDColor &incol

#endif

#if ENABLED(PCA9632)
// Update I2C LED driver
pca9632_set_led_color(incol);
#endif

TERN_(PCA9533, PCA9533_setColor(incol.r, incol.g, incol.b));
// Update I2C LED driver
TERN_(PCA9632, PCA9632_set_led_color(incol));
TERN_(PCA9533, PCA9533_set_rgb(incol.r, incol.g, incol.b));

#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
// Don't update the color when OFF
Expand Down
8 changes: 2 additions & 6 deletions Marlin/src/feature/leds/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ typedef struct LEDColor {
bool operator!=(const LEDColor &right) { return !operator==(right); }

bool is_off() const {
return 3 > r + g + b
#if HAS_WHITE_LED
+ w
#endif
;
return 3 > r + g + b + TERN0(HAS_WHITE_LED, w);
}
} LEDColor;

Expand Down Expand Up @@ -156,7 +152,7 @@ class LEDLights {
#endif
);

inline void set_color(uint8_t r, uint8_t g, uint8_t b
static inline void set_color(uint8_t r, uint8_t g, uint8_t b
#if HAS_WHITE_LED
, uint8_t w=0
#if ENABLED(NEOPIXEL_LED)
Expand Down
13 changes: 6 additions & 7 deletions Marlin/src/feature/leds/neopixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
#endif

void Marlin_NeoPixel::set_color(const uint32_t color) {
if (get_neo_index() >= 0) {
set_pixel_color(get_neo_index(), color);
set_neo_index(-1);
if (neoindex >= 0) {
set_pixel_color(neoindex, color);
neoindex = -1;
}
else {
for (uint16_t i = 0; i < pixels(); ++i) {
Expand All @@ -78,18 +78,17 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
}

void Marlin_NeoPixel::init() {
set_neo_index(-1); // -1 .. NEOPIXEL_PIXELS-1 range
neoindex = -1; // -1 .. NEOPIXEL_PIXELS-1 range
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
begin();
show(); // initialize to all off

#if ENABLED(NEOPIXEL_STARTUP_TEST)
set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
safe_delay(1000);
safe_delay(500);
set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
safe_delay(1000);
safe_delay(500);
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
safe_delay(1000);
#endif

#ifdef NEOPIXEL_BKGD_LED_INDEX
Expand Down
6 changes: 2 additions & 4 deletions Marlin/src/feature/leds/neopixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ class Marlin_NeoPixel {
, adaneo2
#endif
;
static int8_t neoindex;

public:
static int8_t neoindex;

static void init();
static void set_color_startup(const uint32_t c);

static void set_color(const uint32_t c);

FORCE_INLINE static void set_neo_index(const int8_t neoIndex) { neoindex = neoIndex; }
FORCE_INLINE static int8_t get_neo_index() { return neoindex; }

#ifdef NEOPIXEL_BKGD_LED_INDEX
static void set_color_background();
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/leds/pca9533.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void PCA9533_setOff() {
PCA9533_writeRegister(PCA9533_REG_SEL, 0);
}

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

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/leds/pca9533.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@

void PCA9533_init();
void PCA9533_reset();
void PCA9533_setColor(uint8_t red, uint8_t green, uint8_t blue);
void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue);
void PCA9533_setOff();
4 changes: 2 additions & 2 deletions Marlin/src/feature/leds/pca9632.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
}
#endif

void pca9632_set_led_color(const LEDColor &color) {
void PCA9632_set_led_color(const LEDColor &color) {
Wire.begin();
if (!PCA_init) {
PCA_init = 1;
Expand All @@ -138,7 +138,7 @@ void pca9632_set_led_color(const LEDColor &color) {

#if ENABLED(PCA9632_BUZZER)

void pca9632_buzz(const long, const uint16_t) {
void PCA9632_buzz(const long, const uint16_t) {
uint8_t data[] = PCA9632_BUZZER_DATA;
Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
Wire.write(data, sizeof(data));
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/leds/pca9632.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
struct LEDColor;
typedef LEDColor LEDColor;

void pca9632_set_led_color(const LEDColor &color);
void PCA9632_set_led_color(const LEDColor &color);

#if ENABLED(PCA9632_BUZZER)
#include <stdint.h>
void pca9632_buzz(const long, const uint16_t);
void PCA9632_buzz(const long, const uint16_t);
#endif
2 changes: 1 addition & 1 deletion Marlin/src/feature/password/password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/password/password.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/password/M510-M512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
* M141 - Set heated chamber target temp. S<temp> (Requires a chamber heater)
* M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS)
* M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
* 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).
* 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).
* M155 - Auto-report temperatures with interval of S<seconds>. (Requires AUTO_REPORT_TEMPERATURES)
* M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER)
* M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER)
Expand Down
15 changes: 8 additions & 7 deletions Marlin/src/lcd/menu/menu_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
#include "../../feature/leds/leds.h"

#if ENABLED(LED_COLOR_PRESETS)

void menu_led_presets() {
START_MENU();
#if LCD_HEIGHT > 2
STATIC_ITEM(MSG_LED_PRESETS, SS_DEFAULT|SS_INVERT);
#endif
BACK_ITEM(MSG_LED_CONTROL);
ACTION_ITEM(MSG_SET_LEDS_WHITE, leds.set_white);
ACTION_ITEM(MSG_SET_LEDS_RED, leds.set_red);
ACTION_ITEM(MSG_SET_LEDS_WHITE, leds.set_white);
ACTION_ITEM(MSG_SET_LEDS_RED, leds.set_red);
ACTION_ITEM(MSG_SET_LEDS_ORANGE, leds.set_orange);
ACTION_ITEM(MSG_SET_LEDS_YELLOW,leds.set_yellow);
ACTION_ITEM(MSG_SET_LEDS_GREEN, leds.set_green);
ACTION_ITEM(MSG_SET_LEDS_BLUE, leds.set_blue);
ACTION_ITEM(MSG_SET_LEDS_YELLOW, leds.set_yellow);
ACTION_ITEM(MSG_SET_LEDS_GREEN, leds.set_green);
ACTION_ITEM(MSG_SET_LEDS_BLUE, leds.set_blue);
ACTION_ITEM(MSG_SET_LEDS_INDIGO, leds.set_indigo);
ACTION_ITEM(MSG_SET_LEDS_VIOLET, leds.set_violet);
END_MENU();
Expand Down Expand Up @@ -83,11 +84,10 @@
#endif
#endif



void menu_led() {
START_MENU();
BACK_ITEM(MSG_MAIN);

#if ENABLED(LED_CONTROL_MENU)
bool led_on = leds.lights_on;
EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
Expand All @@ -97,6 +97,7 @@ void menu_led() {
#endif
SUBMENU(MSG_CUSTOM_LEDS, menu_led_custom);
#endif

//
// Set Case light on/off/brightness
//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif
void MarlinUI::buzz(const long duration, const uint16_t freq) {
#if ENABLED(PCA9632_BUZZER)
pca9632_buzz(duration, freq);
PCA9632_buzz(duration, freq);
#elif USE_BEEPER
buzzer.tone(duration, freq);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32f1/pins_CCROBOT_MEEB_3DP.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#define FAN1_PIN PA8 // FAN (fan0 on board) e0 cool fan
#define FAN2_PIN PB9 // FAN (fan1 on board) controller cool fan

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

/**
Expand Down

0 comments on commit c488070

Please sign in to comment.