Different NEOPIXEL types

Same as #7728 but for 2.0.x,
Lot of cleanup and remove references in whole code to other "LED files" than leds.h. Now will be much easier to add next drivers/libraries. e.g. FastLED. But bad news, currently FastLED is suporting only RGB devices (no RGBW)
This commit is contained in:
Slawomir Ciunczyk
2017-10-05 13:45:36 +02:00
committed by Scott Lahteine
parent b30b55307c
commit a11e6a1022
49 changed files with 646 additions and 300 deletions

View File

@ -31,18 +31,15 @@
#include "leds.h"
void set_led_color(
const uint8_t r, const uint8_t g, const uint8_t b
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_RGBW_LED)
, const uint8_t w
#if ENABLED(NEOPIXEL_RGBW_LED)
, bool isSequence
#endif
#endif
const uint8_t r, const uint8_t g, const uint8_t b , const uint8_t w , const uint8_t p
) {
#if ENABLED(NEOPIXEL_RGBW_LED)
if (neopixel_set_led_color(r, g, b, w, isSequence))
return;
#if ENABLED(NEOPIXEL_LED)
if (w == 255 || (r == 255 && g == 255 && b == 255))
neopixel_set_led_color(NEO_WHITE, p);
else
neopixel_set_led_color(r, g, b, w, p);
return;
#endif
#if ENABLED(BLINKM)

View File

@ -27,7 +27,7 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#if ENABLED(NEOPIXEL_RGBW_LED)
#if ENABLED(NEOPIXEL_LED)
#include <Adafruit_NeoPixel.h>
#include "neopixel.h"
#endif
@ -40,14 +40,28 @@
#include "pca9632.h"
#endif
void set_led_color(
const uint8_t r, const uint8_t g, const uint8_t b
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_RGBW_LED)
, const uint8_t w = 0
#if ENABLED(NEOPIXEL_RGBW_LED)
, bool isSequence = false
#endif
#if ENABLED(NEOPIXEL_LED)
#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 NEO_WHITE 255, 255, 255
#else
#define NEO_WHITE 0, 0, 0, 255
#endif
#endif
#if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
#define LED_WHITE 255, 255, 255
#elif ENABLED(RGBW_LED)
#define LED_WHITE 0, 0, 0, 255
#endif
#if ENABLED(NEOPIXEL_LED)
#define LED_BRIGHTNESS pixels.getBrightness()
#else
#define LED_BRIGHTNESS 255
#endif
void set_led_color(
const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w = 0, const uint8_t p = 255
);
#endif // __LEDS_H__

View File

@ -26,11 +26,11 @@
#include "../../inc/MarlinConfig.h"
#if ENABLED(NEOPIXEL_RGBW_LED)
#if ENABLED(NEOPIXEL_LED)
#include "neopixel.h"
Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
void set_neopixel_color(const uint32_t color) {
for (uint16_t i = 0; i < pixels.numPixels(); ++i)
@ -39,7 +39,7 @@ void set_neopixel_color(const uint32_t color) {
}
void setup_neopixel() {
pixels.setBrightness(255); // 0 - 255 range
pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
pixels.begin();
pixels.show(); // initialize to all off
@ -55,18 +55,19 @@ void setup_neopixel() {
set_neopixel_color(pixels.Color(0, 0, 0, 255)); // white
}
bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const bool isSequence) {
bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
const uint32_t color = pixels.Color(r, g, b, w);
static uint16_t nextLed = 0;
if (!isSequence)
pixels.setBrightness(p);
#if !ENABLED(NEOPIXEL_IS_SEQUENTIAL)
set_neopixel_color(color);
else {
return false;
#else
static uint16_t nextLed = 0;
pixels.setPixelColor(nextLed, color);
pixels.show();
if (++nextLed >= pixels.numPixels()) nextLed = 0;
return true;
}
return false;
#endif
}
#endif // NEOPIXEL_RGBW_LED
#endif // NEOPIXEL_LED

View File

@ -31,7 +31,7 @@
#include <stdint.h>
void setup_neopixel();
bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const bool isSequence);
bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
extern Adafruit_NeoPixel pixels;