2017-09-08 14:47:47 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 15:06:53 -06:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-08 14:47:47 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-11-28 01:07:10 -06:00
|
|
|
* leds.cpp - Marlin RGB LED general support
|
2017-09-08 14:47:47 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if HAS_COLOR_LEDS
|
|
|
|
|
|
|
|
#include "leds.h"
|
|
|
|
|
2017-11-28 01:07:10 -06:00
|
|
|
#if ENABLED(BLINKM)
|
|
|
|
#include "blinkm.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PCA9632)
|
|
|
|
#include "pca9632.h"
|
|
|
|
#endif
|
|
|
|
|
2019-01-14 14:29:55 -06:00
|
|
|
#if ENABLED(PCA9533)
|
|
|
|
#include "SailfishRGB_LED.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-28 01:07:10 -06:00
|
|
|
#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
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
|
2017-11-28 01:07:10 -06:00
|
|
|
LEDColor LEDLights::color;
|
|
|
|
bool LEDLights::lights_on;
|
2017-11-09 17:39:01 -06:00
|
|
|
#endif
|
|
|
|
|
2017-11-28 01:07:10 -06:00
|
|
|
LEDLights leds;
|
|
|
|
|
|
|
|
void LEDLights::setup() {
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(RGB_LED, RGBW_LED)
|
2019-03-13 06:51:15 -05:00
|
|
|
if (PWM_PIN(RGB_LED_R_PIN)) SET_PWM(RGB_LED_R_PIN); else SET_OUTPUT(RGB_LED_R_PIN);
|
|
|
|
if (PWM_PIN(RGB_LED_G_PIN)) SET_PWM(RGB_LED_G_PIN); else SET_OUTPUT(RGB_LED_G_PIN);
|
|
|
|
if (PWM_PIN(RGB_LED_B_PIN)) SET_PWM(RGB_LED_B_PIN); else SET_OUTPUT(RGB_LED_B_PIN);
|
2019-01-17 13:20:26 -06:00
|
|
|
#if ENABLED(RGBW_LED)
|
2019-03-13 06:51:15 -05:00
|
|
|
if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
|
2019-01-17 13:20:26 -06:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-11-28 01:07:10 -06:00
|
|
|
#if ENABLED(NEOPIXEL_LED)
|
|
|
|
setup_neopixel();
|
|
|
|
#endif
|
2019-06-10 18:01:42 -05:00
|
|
|
#if ENABLED(PCA9533)
|
|
|
|
RGBinit();
|
|
|
|
#endif
|
2017-11-28 01:07:10 -06:00
|
|
|
#if ENABLED(LED_USER_PRESET_STARTUP)
|
|
|
|
set_default();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEDLights::set_color(const LEDColor &incol
|
|
|
|
#if ENABLED(NEOPIXEL_LED)
|
|
|
|
, bool isSequence/*=false*/
|
|
|
|
#endif
|
2017-09-08 14:47:47 -05:00
|
|
|
) {
|
|
|
|
|
2017-10-05 06:45:36 -05:00
|
|
|
#if ENABLED(NEOPIXEL_LED)
|
2017-11-28 01:07:10 -06:00
|
|
|
|
2018-11-01 17:44:41 -05:00
|
|
|
const uint32_t neocolor = LEDColorWhite() == incol
|
|
|
|
? pixels.Color(NEO_WHITE)
|
|
|
|
: pixels.Color(incol.r, incol.g, incol.b, incol.w);
|
2017-11-28 01:07:10 -06:00
|
|
|
static uint16_t nextLed = 0;
|
|
|
|
|
2019-05-18 02:36:37 -05:00
|
|
|
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
|
|
|
if (NEOPIXEL_BKGD_LED_INDEX == nextLed) { nextLed++; return; }
|
|
|
|
#endif
|
2017-11-28 01:07:10 -06:00
|
|
|
pixels.setBrightness(incol.i);
|
|
|
|
if (!isSequence)
|
|
|
|
set_neopixel_color(neocolor);
|
|
|
|
else {
|
|
|
|
pixels.setPixelColor(nextLed, neocolor);
|
|
|
|
pixels.show();
|
|
|
|
if (++nextLed >= pixels.numPixels()) nextLed = 0;
|
|
|
|
return;
|
2017-10-25 15:50:36 -05:00
|
|
|
}
|
2017-11-28 01:07:10 -06:00
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(BLINKM)
|
2017-11-28 01:07:10 -06:00
|
|
|
|
|
|
|
// This variant uses i2c to send the RGB components to the device.
|
|
|
|
blinkm_set_led_color(incol);
|
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(RGB_LED, RGBW_LED)
|
2017-11-28 01:07:10 -06:00
|
|
|
|
|
|
|
// This variant uses 3-4 separate pins for the RGB(W) components.
|
2017-09-08 14:47:47 -05:00
|
|
|
// If the pins can do PWM then their intensity will be set.
|
2019-03-16 19:05:59 -05:00
|
|
|
#define UPDATE_RGBW(C,c) do{ if (PWM_PIN(RGB_LED_##C##_PIN)) analogWrite(RGB_LED_##C##_PIN, incol.c); else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
|
2019-03-13 06:51:15 -05:00
|
|
|
UPDATE_RGBW(R,r);
|
|
|
|
UPDATE_RGBW(G,g);
|
|
|
|
UPDATE_RGBW(B,b);
|
2017-09-08 14:47:47 -05:00
|
|
|
#if ENABLED(RGBW_LED)
|
2019-03-13 06:51:15 -05:00
|
|
|
UPDATE_RGBW(W,w);
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif
|
2017-11-28 01:07:10 -06:00
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PCA9632)
|
2017-11-28 01:07:10 -06:00
|
|
|
// Update I2C LED driver
|
|
|
|
pca9632_set_led_color(incol);
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif
|
2017-11-09 17:39:01 -06:00
|
|
|
|
2019-01-14 14:29:55 -06:00
|
|
|
#if ENABLED(PCA9533)
|
|
|
|
RGBsetColor(incol.r, incol.g, incol.b, true);
|
|
|
|
#endif
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
|
2017-11-28 01:07:10 -06:00
|
|
|
// Don't update the color when OFF
|
|
|
|
lights_on = !incol.is_off();
|
|
|
|
if (lights_on) color = incol;
|
2017-11-09 17:39:01 -06:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-28 01:07:10 -06:00
|
|
|
#if ENABLED(LED_CONTROL_MENU)
|
|
|
|
void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#endif // HAS_COLOR_LEDS
|