Apply LEDColor, language fixes

This commit is contained in:
Scott Lahteine
2017-11-28 01:07:10 -06:00
parent 8f90642eea
commit e37dd64548
15 changed files with 323 additions and 286 deletions

View File

@ -21,7 +21,7 @@
*/
/**
* Marlin RGB LED general support
* leds.cpp - Marlin RGB LED general support
*/
#include "../../inc/MarlinConfig.h"
@ -30,102 +30,111 @@
#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
#if ENABLED(BLINKM)
#include "blinkm.h"
#endif
void set_led_color(
const uint8_t r, const uint8_t g, const uint8_t b
#if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
, const uint8_t w // = 0
#if ENABLED(NEOPIXEL_LED)
, const uint8_t p // = NEOPIXEL_BRIGHTNESS
, const bool isSequence // = false
#endif
#endif
#if ENABLED(PCA9632)
#include "pca9632.h"
#endif
#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
);
#endif
#if ENABLED(LED_CONTROL_MENU)
LEDColor LEDLights::color;
bool LEDLights::lights_on;
#endif
LEDLights leds;
void LEDLights::setup() {
#if ENABLED(NEOPIXEL_LED)
setup_neopixel();
#endif
#if ENABLED(LED_USER_PRESET_STARTUP)
set_default();
#endif
}
void LEDLights::set_color(const LEDColor &incol
#if ENABLED(NEOPIXEL_LED)
, bool isSequence/*=false*/
#endif
) {
#if ENABLED(NEOPIXEL_LED)
if ((w == 255) || ((r == 255) && (g == 255) && (b == 255))) {
neopixel_set_led_color(NEO_WHITE, p);
const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w);
static uint16_t nextLed = 0;
pixels.setBrightness(incol.i);
if (!isSequence)
set_neopixel_color(neocolor);
else {
pixels.setPixelColor(nextLed, neocolor);
pixels.show();
if (++nextLed >= pixels.numPixels()) nextLed = 0;
return;
}
else
neopixel_set_led_color(r, g, b, w, p);
#endif
#if ENABLED(BLINKM)
blinkm_set_led_color(r, g, b); // Use i2c to send the RGB components to the device.
// This variant uses i2c to send the RGB components to the device.
blinkm_set_led_color(incol);
#endif
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
// This variant uses 3 separate pins for the RGB components.
// This variant uses 3-4 separate pins for the RGB(W) components.
// If the pins can do PWM then their intensity will be set.
WRITE(RGB_LED_R_PIN, r ? HIGH : LOW);
WRITE(RGB_LED_G_PIN, g ? HIGH : LOW);
WRITE(RGB_LED_B_PIN, b ? HIGH : LOW);
analogWrite(RGB_LED_R_PIN, r);
analogWrite(RGB_LED_G_PIN, g);
analogWrite(RGB_LED_B_PIN, b);
WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW);
WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW);
WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW);
analogWrite(RGB_LED_R_PIN, incol.r);
analogWrite(RGB_LED_G_PIN, incol.g);
analogWrite(RGB_LED_B_PIN, incol.b);
#if ENABLED(RGBW_LED)
WRITE(RGB_LED_W_PIN, w ? HIGH : LOW);
analogWrite(RGB_LED_W_PIN, w);
WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
analogWrite(RGB_LED_W_PIN, incol.w);
#endif
#endif
#if ENABLED(PCA9632)
pca9632_set_led_color(r, g, b); // Update I2C LED driver
// Update I2C LED driver
pca9632_set_led_color(incol);
#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
}
// Don't update the color when OFF
lights_on = !incol.is_off();
if (lights_on) color = incol;
#endif
}
void set_led_white(){
void LEDLights::set_white() {
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
set_color(LEDColorWhite());
#endif
#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);
set_neopixel_color(pixels.Color(NEO_WHITE));
#endif
}
#if ENABLED(LED_CONTROL_MENU)
void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
#endif
#endif // HAS_COLOR_LEDS