New Feature: LED_CONTROL_MENU
This commit is contained in:
@ -30,6 +30,32 @@
|
||||
|
||||
#include "leds.h"
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
#if ENABLED(LED_COLOR_PRESETS)
|
||||
uint8_t led_intensity_red = LED_USER_PRESET_RED,
|
||||
led_intensity_green = LED_USER_PRESET_GREEN,
|
||||
led_intensity_blue = LED_USER_PRESET_BLUE
|
||||
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
|
||||
, led_intensity_white = LED_USER_PRESET_WHITE
|
||||
#endif
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, led_intensity = NEOPIXEL_BRIGHTNESS
|
||||
#endif
|
||||
;
|
||||
#else
|
||||
uint8_t led_intensity_red = 255,
|
||||
led_intensity_green = 255,
|
||||
led_intensity_blue = 255
|
||||
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
|
||||
, led_intensity_white = 0
|
||||
#endif
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, led_intensity = NEOPIXEL_BRIGHTNESS
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void set_led_color(
|
||||
const uint8_t r, const uint8_t g, const uint8_t b
|
||||
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
|
||||
@ -42,20 +68,11 @@ void set_led_color(
|
||||
) {
|
||||
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
|
||||
const uint32_t color = pixels.Color(r, g, b, w);
|
||||
static uint16_t nextLed = 0;
|
||||
|
||||
pixels.setBrightness(p);
|
||||
if (!isSequence)
|
||||
set_neopixel_color(color);
|
||||
else {
|
||||
pixels.setPixelColor(nextLed, color);
|
||||
pixels.show();
|
||||
if (++nextLed >= pixels.numPixels()) nextLed = 0;
|
||||
return;
|
||||
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);
|
||||
#endif
|
||||
|
||||
#if ENABLED(BLINKM)
|
||||
@ -81,6 +98,34 @@ void set_led_color(
|
||||
#if ENABLED(PCA9632)
|
||||
pca9632_set_led_color(r, g, b); // Update I2C LED driver
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
if ((r + g + b
|
||||
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
|
||||
+ w
|
||||
#endif
|
||||
) >= 3) {
|
||||
led_intensity_red = r;
|
||||
led_intensity_green = g;
|
||||
led_intensity_blue = b;
|
||||
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
|
||||
led_intensity_white = w;
|
||||
#endif
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
led_intensity = p;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_led_white(){
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
neopixel_set_led_color(NEO_WHITE, pixels.getBrightness());
|
||||
#elif (RGBW_LED)
|
||||
set_led_color(0, 0, 0, 255);
|
||||
#else
|
||||
set_led_color(255, 255, 255);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // HAS_COLOR_LEDS
|
||||
|
@ -65,4 +65,6 @@ void set_led_color(
|
||||
#endif
|
||||
);
|
||||
|
||||
void set_led_white();
|
||||
|
||||
#endif // __LEDS_H__
|
||||
|
@ -53,7 +53,27 @@ void setup_neopixel() {
|
||||
set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
|
||||
safe_delay(1000);
|
||||
#endif
|
||||
set_neopixel_color(pixels.Color(NEO_WHITE)); // white
|
||||
|
||||
#if ENABLED(LED_USER_PRESET_STARTUP)
|
||||
set_neopixel_color(pixels.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
|
||||
#else
|
||||
set_neopixel_color(pixels.Color(0, 0, 0, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
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);
|
||||
pixels.setBrightness(p);
|
||||
#if !ENABLED(NEOPIXEL_IS_SEQUENTIAL)
|
||||
set_neopixel_color(color);
|
||||
return false;
|
||||
#else
|
||||
static uint16_t nextLed = 0;
|
||||
pixels.setPixelColor(nextLed, color);
|
||||
pixels.show();
|
||||
if (++nextLed >= pixels.numPixels()) nextLed = 0;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // NEOPIXEL_LED
|
||||
|
@ -36,13 +36,14 @@
|
||||
#define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB
|
||||
|
||||
#if NEOPIXEL_IS_RGB
|
||||
#define NEO_WHITE 255, 255, 255
|
||||
#define NEO_WHITE 255, 255, 255, 0
|
||||
#else
|
||||
#define NEO_WHITE 0, 0, 0, 255
|
||||
#endif
|
||||
|
||||
void setup_neopixel();
|
||||
void set_neopixel_color(const uint32_t color);
|
||||
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;
|
||||
|
||||
|
Reference in New Issue
Block a user