Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b4d329a
Merge pull request #1 from MarlinFirmware/bugfix-2.0.x
Bacon-Fixation Aug 22, 2020
6a9442d
seperate neopixel control with M151
Bacon-Fixation Aug 22, 2020
5363276
Update Configuration.h
Bacon-Fixation Aug 22, 2020
bd39337
further intergration
Bacon-Fixation Aug 22, 2020
757ac62
Merge branch 'bugfix-2.0.x' of https://github.com/Bacon-Fixation/Marl…
Bacon-Fixation Aug 22, 2020
465092b
-Fixed TYPO for the Smart effector
Bacon-Fixation Aug 22, 2020
970005f
better intergration
Bacon-Fixation Aug 23, 2020
7a2c6d5
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/19115
thinkyhead Aug 23, 2020
7243dd1
Neo 2 initial cleanup
thinkyhead Aug 23, 2020
1593471
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/19115
thinkyhead Aug 23, 2020
0a97a4c
Clean up, extend M150
thinkyhead Aug 23, 2020
5992942
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/19115
thinkyhead Aug 23, 2020
42150e3
Rename some pca9632 functions
thinkyhead Aug 23, 2020
356715d
Rename adaneo# and other vars
thinkyhead Aug 23, 2020
cd9d80d
Re-use LEDColor
thinkyhead Aug 23, 2020
0dbe7ff
Misc. cleanup
thinkyhead Aug 23, 2020
ffb781c
Fix set_color binding
thinkyhead Aug 23, 2020
bdb4722
Adding conflict protection with other neopixel features
Bacon-Fixation Aug 23, 2020
c8b9ec6
Merge branch 'bugfix-2.0.x' of https://github.com/Bacon-Fixation/Marl…
Bacon-Fixation Aug 23, 2020
4434b88
reverting change
Bacon-Fixation Aug 23, 2020
1abbb8c
fixed compiling Error with the LPC1769
Bacon-Fixation Aug 24, 2020
3ffa4ca
second index to stop M150 from bleeding into the second neopixel channel
Bacon-Fixation Aug 24, 2020
ca79f2b
Who needs accessors?
thinkyhead Aug 24, 2020
c60bea4
Thanks but no thanks for your configs
thinkyhead Aug 24, 2020
b41a733
Condition for conjoined strips
thinkyhead Aug 24, 2020
85b0a48
Fix M150 to fit current design
thinkyhead Aug 24, 2020
7d57af2
Patch neoindex
thinkyhead Aug 24, 2020
d3624ad
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/19115
thinkyhead Aug 24, 2020
0cf88aa
dont know how i lost this config
Bacon-Fixation Aug 24, 2020
8a35574
Update Configuration.h
thinkyhead Aug 24, 2020
971e130
Update leds.h
Bacon-Fixation Aug 25, 2020
563029d
Update neopixel.h
Bacon-Fixation Aug 25, 2020
066ac3d
not needed
Bacon-Fixation Aug 25, 2020
dfa25dc
add an extra example to M150 for Sn
Bacon-Fixation Aug 25, 2020
b540b00
Fixed Typo for Neo2 color presets
Bacon-Fixation Aug 25, 2020
4d7cd2c
Merge branch 'bugfix-2.0.x' into bugfix-2.0.x
thinkyhead Aug 26, 2020
9b3a4a1
tinkering
Bacon-Fixation Aug 26, 2020
88f050d
NEOPIXEL_SEPERATE to run diferent neopixel types
Bacon-Fixation Aug 27, 2020
8b12f7b
ffs
thinkyhead Aug 27, 2020
dc7e169
Update neopixel.h
thinkyhead Aug 27, 2020
5f0fd8c
Update leds.h
thinkyhead Aug 27, 2020
b201138
Update leds.h
thinkyhead Aug 27, 2020
ceeea2f
Update neopixel.h
thinkyhead Aug 27, 2020
dd9bb52
Update leds.cpp
thinkyhead Aug 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2362,12 +2362,21 @@
#define NEOPIXEL_PIN 4 // LED driving pin
//#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. (Longest strip when NEOPIXEL2_SEPARATE is disabled.)
#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

// Support for second Adafruit NeoPixel LED driver controlled with M150 S1 ...
//#define NEOPIXEL2_SEPARATE
#if ENABLED(NEOPIXEL2_SEPARATE)
#define NEOPIXEL2_PIXELS 15 // Number of LEDs in the second strip
#define NEOPIXEL2_BRIGHTNESS 127 // Initial brightness (0-255)
#define NEOPIXEL2_STARTUP_TEST // Cycle through colors at startup
#else
//#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel
#endif

// Use a single NeoPixel LED for static (background) lighting
//#define NEOPIXEL_BKGD_LED_INDEX 0 // Index of the LED to use
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
Expand Down
9 changes: 9 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@
//#define LED_CONTROL_MENU
#if ENABLED(LED_CONTROL_MENU)
#define LED_COLOR_PRESETS // Enable the Preset Color menu option
//#define NEO2_COLOR_PRESETS // Enable a second NeoPixel Preset Color menu option
#if ENABLED(LED_COLOR_PRESETS)
#define LED_USER_PRESET_RED 255 // User defined RED value
#define LED_USER_PRESET_GREEN 128 // User defined GREEN value
Expand All @@ -1073,6 +1074,14 @@
#define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#endif
#if ENABLED(NEO2_COLOR_PRESETS)
#define NEO2_USER_PRESET_RED 255 // User defined RED value
#define NEO2_USER_PRESET_GREEN 128 // User defined GREEN value
#define NEO2_USER_PRESET_BLUE 0 // User defined BLUE value
#define NEO2_USER_PRESET_WHITE 255 // User defined WHITE value
#define NEO2_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define NEO2_USER_PRESET_STARTUP // Have the printer display the user preset color on startup for the second strip
#endif
#endif

#endif // HAS_LCD_MENU
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ void setup() {
SETUP_RUN(leds.setup());
#endif

#if ENABLED(NEOPIXEL2_SEPARATE)
SETUP_RUN(leds2.setup());
#endif

#if ENABLED(USE_CONTROLLER_FAN) // Set up fan controller to initialize also the default configurations.
SETUP_RUN(controllerFan.setup());
#endif
Expand Down
51 changes: 40 additions & 11 deletions Marlin/src/feature/leds/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@

#if ENABLED(LED_COLOR_PRESETS)
const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
LED_USER_PRESET_RED,
LED_USER_PRESET_GREEN,
LED_USER_PRESET_BLUE,
LED_USER_PRESET_WHITE,
LED_USER_PRESET_BRIGHTNESS
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE,
LED_USER_PRESET_WHITE, LED_USER_PRESET_BRIGHTNESS
);
#endif

Expand Down Expand Up @@ -117,12 +114,13 @@ void LEDLights::set_color(const LEDColor &incol

// This variant uses 3-4 separate pins for the RGB(W) components.
// If the pins can do PWM then their intensity will be set.
#define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
#define UPDATE_RGBW(C,c) do { \
if (PWM_PIN(RGB_LED_##C##_PIN)) \
analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
UPDATE_RGBW(R,r);
UPDATE_RGBW(G,g);
UPDATE_RGBW(B,b);
else \
WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); \
}while(0)
UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
#if ENABLED(RGBW_LED)
UPDATE_RGBW(W,w);
#endif
Expand Down Expand Up @@ -158,4 +156,35 @@ void LEDLights::set_color(const LEDColor &incol

#endif

#endif // HAS_COLOR_LEDS
#if ENABLED(NEOPIXEL2_SEPARATE)

#if ENABLED(NEO2_COLOR_PRESETS)
const LEDColor LEDLights2::defaultLEDColor = MakeLEDColor(
NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE,
NEO2_USER_PRESET_WHITE, NEO2_USER_PRESET_BRIGHTNESS
);
#endif

#if ENABLED(LED_CONTROL_MENU)
LEDColor LEDLights2::color;
bool LEDLights2::lights_on;
#endif

LEDLights2 leds2;

void LEDLights2::setup() {
neo2.init();
TERN_(NEO2_USER_PRESET_STARTUP, set_default());
}

void LEDLights2::set_color(const LEDColor &incol) {
const uint32_t neocolor = LEDColorWhite() == incol
? neo2.Color(NEO2_WHITE)
: neo2.Color(incol.r, incol.g, incol.b, incol.w);
neo2.set_brightness(incol.i);
neo2.set_color(neocolor);
}

#endif // NEOPIXEL2_SEPARATE

#endif // HAS_COLOR_LEDS
45 changes: 42 additions & 3 deletions Marlin/src/feature/leds/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ class LEDLights {
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)
, uint8_t i=NEOPIXEL_BRIGHTNESS
#endif
#endif
#if ENABLED(NEOPIXEL_LED)
, uint8_t i=NEOPIXEL_BRIGHTNESS
, bool isSequence=false
#endif
) {
Expand Down Expand Up @@ -212,3 +210,44 @@ class LEDLights {
};

extern LEDLights leds;

#if ENABLED(NEOPIXEL2_SEPARATE)

class LEDLights2 {
public:
LEDLights2() {}

static void setup(); // init()

static void set_color(const LEDColor &color);

inline void set_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0, uint8_t i=NEOPIXEL2_BRIGHTNESS) {
set_color(MakeLEDColor(r, g, b, w, i));
}

static inline void set_off() { set_color(LEDColorOff()); }
static inline void set_green() { set_color(LEDColorGreen()); }
static inline void set_white() { set_color(LEDColorWhite()); }

#if ENABLED(NEO2_COLOR_PRESETS)
static const LEDColor defaultLEDColor;
static inline void set_default() { set_color(defaultLEDColor); }
static inline void set_red() { set_color(LEDColorRed()); }
static inline void set_orange() { set_color(LEDColorOrange()); }
static inline void set_yellow() { set_color(LEDColorYellow()); }
static inline void set_blue() { set_color(LEDColorBlue()); }
static inline void set_indigo() { set_color(LEDColorIndigo()); }
static inline void set_violet() { set_color(LEDColorViolet()); }
#endif

#if ENABLED(LED_CONTROL_MENU)
static LEDColor color; // last non-off color
static bool lights_on; // the last set color was "on"
static void toggle(); // swap "off" with color
static inline void update() { set_color(color); }
#endif
};

extern LEDLights2 leds2;

#endif // NEOPIXEL2_SEPARATE
54 changes: 52 additions & 2 deletions Marlin/src/feature/leds/neopixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

#include "neopixel.h"

#if ENABLED(NEOPIXEL_STARTUP_TEST)
#if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
#include "../../core/utility.h"
#endif

Marlin_NeoPixel neo;
int8_t Marlin_NeoPixel::neoindex;

Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
#if CONJOINED_NEOPIXEL
, Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
#endif
;
Expand Down Expand Up @@ -89,6 +89,7 @@ void Marlin_NeoPixel::init() {
set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
safe_delay(500);
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
safe_delay(500);
#endif

#ifdef NEOPIXEL_BKGD_LED_INDEX
Expand Down Expand Up @@ -119,4 +120,53 @@ bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint
}
#endif

#if ENABLED(NEOPIXEL2_SEPARATE)

Marlin_NeoPixel2 neo2;

int8_t Marlin_NeoPixel2::neoindex;
Adafruit_NeoPixel Marlin_NeoPixel2::adaneo(NEOPIXEL2_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE);

void Marlin_NeoPixel2::set_color(const uint32_t color) {
if (neoindex >= 0) {
set_pixel_color(neoindex, color);
neoindex = -1;
}
else {
for (uint16_t i = 0; i < pixels(); ++i)
set_pixel_color(i, color);
}
show();
}

void Marlin_NeoPixel2::set_color_startup(const uint32_t color) {
for (uint16_t i = 0; i < pixels(); ++i)
set_pixel_color(i, color);
show();
}

void Marlin_NeoPixel2::init() {
neoindex = -1; // -1 .. NEOPIXEL2_PIXELS-1 range
set_brightness(NEOPIXEL2_BRIGHTNESS); // 0 .. 255 range
begin();
show(); // initialize to all off

#if ENABLED(NEOPIXEL2_STARTUP_TEST)
set_color_startup(adaneo.Color(255, 0, 0, 0)); // red
safe_delay(500);
set_color_startup(adaneo.Color(0, 255, 0, 0)); // green
safe_delay(500);
set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
safe_delay(500);
#endif

#if ENABLED(NEO2_USER_PRESET_STARTUP)
set_color(adaneo.Color(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE));
#else
set_color(adaneo.Color(0, 0, 0, 0));
#endif
}

#endif // NEOPIXEL2_SEPARATE

#endif // NEOPIXEL_LED
70 changes: 56 additions & 14 deletions Marlin/src/feature/leds/neopixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@
// Defines
// ------------------------

#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
#define MULTIPLE_NEOPIXEL_TYPES 1
#endif

#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
#define CONJOINED_NEOPIXEL 1
#endif

#if NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR
#define NEOPIXEL_IS_RGB 1
#else
Expand All @@ -61,7 +65,7 @@
class Marlin_NeoPixel {
private:
static Adafruit_NeoPixel adaneo1
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
#if CONJOINED_NEOPIXEL
, adaneo2
#endif
;
Expand All @@ -80,11 +84,7 @@ class Marlin_NeoPixel {

static inline void begin() {
adaneo1.begin();
#if ENABLED(NEOPIXEL2_INSERIES)
adaneo2.begin();
#else
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin());
#endif
TERN_(CONJOINED_NEOPIXEL, adaneo2.begin());
}

static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
Expand All @@ -93,23 +93,21 @@ class Marlin_NeoPixel {
else adaneo1.setPixelColor(n, c);
#else
adaneo1.setPixelColor(n, c);
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
#if MULTIPLE_NEOPIXEL_TYPES
adaneo2.setPixelColor(n, c);
#endif
#endif
}

static inline void set_brightness(const uint8_t b) {
adaneo1.setBrightness(b);
#if ENABLED(NEOPIXEL2_INSERIES)
adaneo2.setBrightness(b);
#else
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b));
#endif
TERN_(CONJOINED_NEOPIXEL, adaneo2.setBrightness(b));
}

static inline void show() {
adaneo1.show();
#if PIN_EXISTS(NEOPIXEL2)
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
#if CONJOINED_NEOPIXEL
adaneo2.show();
#else
adaneo1.setPin(NEOPIXEL2_PIN);
Expand All @@ -132,3 +130,47 @@ class Marlin_NeoPixel {
};

extern Marlin_NeoPixel neo;

// Neo pixel channel 2
#if ENABLED(NEOPIXEL2_SEPARATE)

#if NEOPIXEL2_TYPE == NEO_RGB || NEOPIXEL2_TYPE == NEO_RBG || NEOPIXEL2_TYPE == NEO_GRB || NEOPIXEL2_TYPE == NEO_GBR || NEOPIXEL2_TYPE == NEO_BRG || NEOPIXEL2_TYPE == NEO_BGR
#define NEOPIXEL2_IS_RGB 1
#else
#define NEOPIXEL2_IS_RGBW 1
#endif

#if NEOPIXEL2_IS_RGB
#define NEO2_WHITE 255, 255, 255, 0
#else
#define NEO2_WHITE 0, 0, 0, 255
#endif

class Marlin_NeoPixel2 {
private:
static Adafruit_NeoPixel adaneo;

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);

static inline void begin() { adaneo.begin(); }
static inline void set_pixel_color(const uint16_t n, const uint32_t c) { adaneo.setPixelColor(n, c); }
static inline void set_brightness(const uint8_t b) { adaneo.setBrightness(b); }
static inline void show() { adaneo.show(); }

// Accessors
static inline uint16_t pixels() { return adaneo.numPixels();}
static inline uint8_t brightness() { return adaneo.getBrightness(); }
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return adaneo.Color(r, g, b, w);
}
};

extern Marlin_NeoPixel2 neo2;

#endif // NEOPIXEL2_SEPARATE
Loading