commit
ace3e50898
@ -0,0 +1,140 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* leds.cpp - Marlin RGB LED general support
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MarlinConfig.h"
|
||||||
|
|
||||||
|
#if HAS_COLOR_LEDS
|
||||||
|
|
||||||
|
#include "leds.h"
|
||||||
|
|
||||||
|
#if ENABLED(BLINKM)
|
||||||
|
#include "blinkm.h"
|
||||||
|
#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)
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(BLINKM)
|
||||||
|
|
||||||
|
// 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-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, 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, incol.w ? HIGH : LOW);
|
||||||
|
analogWrite(RGB_LED_W_PIN, incol.w);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(PCA9632)
|
||||||
|
// Update I2C LED driver
|
||||||
|
pca9632_set_led_color(incol);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(LED_CONTROL_MENU)
|
||||||
|
// Don't update the color when OFF
|
||||||
|
lights_on = !incol.is_off();
|
||||||
|
if (lights_on) color = incol;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LEDLights::set_white() {
|
||||||
|
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
|
||||||
|
set_color(LEDColorWhite());
|
||||||
|
#endif
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
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
|
@ -0,0 +1,169 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* leds.h - Marlin general RGB LED support
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LEDS_H__
|
||||||
|
#define __LEDS_H__
|
||||||
|
|
||||||
|
#include "MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
#include "neopixel.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HAS_WHITE_LED (ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LEDcolor type for use with leds.set_color
|
||||||
|
*/
|
||||||
|
typedef struct LEDColor {
|
||||||
|
uint8_t r, g, b
|
||||||
|
#if HAS_WHITE_LED
|
||||||
|
, w
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
, i
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
LEDColor() : r(255), g(255), b(255)
|
||||||
|
#if HAS_WHITE_LED
|
||||||
|
, w(255)
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
, i(NEOPIXEL_BRIGHTNESS)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
{}
|
||||||
|
LEDColor(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
|
||||||
|
) : r(r), g(g), b(b)
|
||||||
|
#if HAS_WHITE_LED
|
||||||
|
, w(w)
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
, i(i)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
{}
|
||||||
|
LEDColor& operator=(const LEDColor &right) {
|
||||||
|
if (this != &right) memcpy(this, &right, sizeof(LEDColor));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
bool operator==(const LEDColor &right) {
|
||||||
|
if (this == &right) return true;
|
||||||
|
return 0 == memcmp(this, &right, sizeof(LEDColor));
|
||||||
|
}
|
||||||
|
bool operator!=(const LEDColor &right) { return !operator==(right); }
|
||||||
|
bool is_off() const {
|
||||||
|
return 3 > r + g + b
|
||||||
|
#if HAS_WHITE_LED
|
||||||
|
+ w
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
}
|
||||||
|
} LEDColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color helpers and presets
|
||||||
|
*/
|
||||||
|
#if HAS_WHITE_LED
|
||||||
|
#define LEDColorWhite() LEDColor(0, 0, 0, 255)
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I)
|
||||||
|
#else
|
||||||
|
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
|
||||||
|
#define LEDColorWhite() LEDColor(255, 255, 255)
|
||||||
|
#endif
|
||||||
|
#define LEDColorOff() LEDColor( 0, 0, 0)
|
||||||
|
#define LEDColorRed() LEDColor(255, 0, 0)
|
||||||
|
#define LEDColorOrange() LEDColor(255, 80, 0)
|
||||||
|
#define LEDColorYellow() LEDColor(255, 255, 0)
|
||||||
|
#define LEDColorGreen() LEDColor( 0, 255, 0)
|
||||||
|
#define LEDColorBlue() LEDColor( 0, 0, 255)
|
||||||
|
#define LEDColorIndigo() LEDColor( 0, 255, 255)
|
||||||
|
#define LEDColorViolet() LEDColor(255, 0, 255)
|
||||||
|
|
||||||
|
class LEDLights {
|
||||||
|
public:
|
||||||
|
LEDLights() {} // ctor
|
||||||
|
|
||||||
|
static void setup(); // init()
|
||||||
|
|
||||||
|
static void set_color(const LEDColor &color
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
, bool isSequence=false
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
FORCE_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)
|
||||||
|
, bool isSequence=false
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
set_color(MakeLEDColor(r, g, b, w, i)
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
, isSequence
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_white();
|
||||||
|
FORCE_INLINE static void set_off() { set_color(LEDColorOff()); }
|
||||||
|
FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); }
|
||||||
|
|
||||||
|
#if ENABLED(LED_COLOR_PRESETS)
|
||||||
|
static const LEDColor defaultLEDColor;
|
||||||
|
FORCE_INLINE static void set_default() { set_color(defaultLEDColor); }
|
||||||
|
FORCE_INLINE static void set_red() { set_color(LEDColorRed()); }
|
||||||
|
FORCE_INLINE static void set_orange() { set_color(LEDColorOrange()); }
|
||||||
|
FORCE_INLINE static void set_yellow() { set_color(LEDColorYellow()); }
|
||||||
|
FORCE_INLINE static void set_blue() { set_color(LEDColorBlue()); }
|
||||||
|
FORCE_INLINE static void set_indigo() { set_color(LEDColorIndigo()); }
|
||||||
|
FORCE_INLINE static 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
|
||||||
|
FORCE_INLINE static void update() { set_color(color); }
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
extern LEDLights leds;
|
||||||
|
|
||||||
|
#endif // __LEDS_H__
|
@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* neopixel.cpp
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
|
||||||
|
#include "neopixel.h"
|
||||||
|
|
||||||
|
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)
|
||||||
|
pixels.setPixelColor(i, color);
|
||||||
|
pixels.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_neopixel() {
|
||||||
|
SET_OUTPUT(NEOPIXEL_PIN);
|
||||||
|
pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
|
||||||
|
pixels.begin();
|
||||||
|
pixels.show(); // initialize to all off
|
||||||
|
|
||||||
|
#if ENABLED(NEOPIXEL_STARTUP_TEST)
|
||||||
|
safe_delay(1000);
|
||||||
|
set_neopixel_color(pixels.Color(255, 0, 0, 0)); // red
|
||||||
|
safe_delay(1000);
|
||||||
|
set_neopixel_color(pixels.Color(0, 255, 0, 0)); // green
|
||||||
|
safe_delay(1000);
|
||||||
|
set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
|
||||||
|
safe_delay(1000);
|
||||||
|
#endif
|
||||||
|
set_neopixel_color(pixels.Color(NEO_WHITE)); // white
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NEOPIXEL_LED
|
||||||
|
|
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* neopixel.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MarlinConfig.h"
|
||||||
|
|
||||||
|
#define NEOPIXEL_IS_RGB (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_RGBW !NEOPIXEL_IS_RGB
|
||||||
|
|
||||||
|
#if NEOPIXEL_IS_RGB
|
||||||
|
#define NEO_WHITE 255, 255, 255, 0
|
||||||
|
#else
|
||||||
|
#define NEO_WHITE 0, 0, 0, 255
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void setup_neopixel();
|
||||||
|
void set_neopixel_color(const uint32_t color);
|
||||||
|
|
||||||
|
extern Adafruit_NeoPixel pixels;
|
Loading…
Reference in new issue