update code base to Marlin 2.0.9.2
This commit is contained in:
2
Marlin/src/feature/leds/blinkm.cpp
Executable file → Normal file
2
Marlin/src/feature/leds/blinkm.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
2
Marlin/src/feature/leds/blinkm.h
Executable file → Normal file
2
Marlin/src/feature/leds/blinkm.h
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
147
Marlin/src/feature/leds/leds.cpp
Executable file → Normal file
147
Marlin/src/feature/leds/leds.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -39,20 +39,22 @@
|
||||
#endif
|
||||
|
||||
#if ENABLED(PCA9533)
|
||||
#include <SailfishRGB_LED.h>
|
||||
#include "pca9533.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_RGB_LED)
|
||||
#include "../../feature/caselight.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
|
||||
const LEDColor LEDLights::defaultLEDColor = LEDColor(
|
||||
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE
|
||||
OPTARG(HAS_WHITE_LED, LED_USER_PRESET_WHITE)
|
||||
OPTARG(NEOPIXEL_LED, LED_USER_PRESET_BRIGHTNESS)
|
||||
);
|
||||
#endif
|
||||
|
||||
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
|
||||
#if ANY(LED_CONTROL_MENU, PRINTER_EVENT_LEDS, CASE_LIGHT_IS_COLOR_LED)
|
||||
LEDColor LEDLights::color;
|
||||
bool LEDLights::lights_on;
|
||||
#endif
|
||||
@@ -68,45 +70,41 @@ void LEDLights::setup() {
|
||||
if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
neo.init();
|
||||
#endif
|
||||
#if ENABLED(PCA9533)
|
||||
RGBinit();
|
||||
#endif
|
||||
#if ENABLED(LED_USER_PRESET_STARTUP)
|
||||
set_default();
|
||||
#endif
|
||||
TERN_(NEOPIXEL_LED, neo.init());
|
||||
TERN_(PCA9533, PCA9533_init());
|
||||
TERN_(LED_USER_PRESET_STARTUP, set_default());
|
||||
}
|
||||
|
||||
void LEDLights::set_color(const LEDColor &incol
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, bool isSequence/*=false*/
|
||||
#endif
|
||||
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence/*=false*/)
|
||||
) {
|
||||
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
|
||||
const uint32_t neocolor = LEDColorWhite() == incol
|
||||
? neo.Color(NEO_WHITE)
|
||||
: neo.Color(incol.r, incol.g, incol.b, incol.w);
|
||||
static uint16_t nextLed = 0;
|
||||
: neo.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_LED, incol.w));
|
||||
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
if (NEOPIXEL_BKGD_LED_INDEX == nextLed) {
|
||||
if (++nextLed >= neo.pixels()) nextLed = 0;
|
||||
return;
|
||||
}
|
||||
#if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
|
||||
static uint16_t nextLed = 0;
|
||||
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
|
||||
while (WITHIN(nextLed, NEOPIXEL_BKGD_INDEX_FIRST, NEOPIXEL_BKGD_INDEX_LAST)) {
|
||||
neo.reset_background_color();
|
||||
if (++nextLed >= neo.pixels()) { nextLed = 0; return; }
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
neo.set_brightness(incol.i);
|
||||
|
||||
if (isSequence) {
|
||||
neo.set_pixel_color(nextLed, neocolor);
|
||||
neo.show();
|
||||
if (++nextLed >= neo.pixels()) nextLed = 0;
|
||||
return;
|
||||
}
|
||||
#if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
|
||||
if (isSequence) {
|
||||
neo.set_pixel_color(nextLed, neocolor);
|
||||
neo.show();
|
||||
if (++nextLed >= neo.pixels()) nextLed = 0;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
neo.set_color(neocolor);
|
||||
|
||||
@@ -123,26 +121,23 @@ void LEDLights::set_color(const LEDColor &incol
|
||||
|
||||
// This variant uses 3-4 separate pins for the RGB(W) components.
|
||||
// If the pins can do PWM then their intensity will be set.
|
||||
#define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
|
||||
else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
|
||||
UPDATE_RGBW(R,r);
|
||||
UPDATE_RGBW(G,g);
|
||||
UPDATE_RGBW(B,b);
|
||||
#define _UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), c); \
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, c ? HIGH : LOW); \
|
||||
}while(0)
|
||||
#define UPDATE_RGBW(C,c) _UPDATE_RGBW(C, TERN1(CASE_LIGHT_USE_RGB_LED, caselight.on) ? incol.c : 0)
|
||||
UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
|
||||
#if ENABLED(RGBW_LED)
|
||||
UPDATE_RGBW(W,w);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(PCA9632)
|
||||
// Update I2C LED driver
|
||||
pca9632_set_led_color(incol);
|
||||
#endif
|
||||
|
||||
#if ENABLED(PCA9533)
|
||||
RGBsetColor(incol.r, incol.g, incol.b, true);
|
||||
#endif
|
||||
// Update I2C LED driver
|
||||
TERN_(PCA9632, PCA9632_set_led_color(incol));
|
||||
TERN_(PCA9533, PCA9533_set_rgb(incol.r, incol.g, incol.b));
|
||||
|
||||
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
|
||||
// Don't update the color when OFF
|
||||
@@ -160,13 +155,57 @@ void LEDLights::set_color(const LEDColor &incol
|
||||
millis_t LEDLights::led_off_time; // = 0
|
||||
|
||||
void LEDLights::update_timeout(const bool power_on) {
|
||||
const millis_t ms = millis();
|
||||
if (power_on)
|
||||
reset_timeout(ms);
|
||||
else if (ELAPSED(ms, led_off_time))
|
||||
set_off();
|
||||
if (lights_on) {
|
||||
const millis_t ms = millis();
|
||||
if (power_on)
|
||||
reset_timeout(ms);
|
||||
else if (ELAPSED(ms, led_off_time))
|
||||
set_off();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // HAS_COLOR_LEDS
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
#if ENABLED(NEO2_COLOR_PRESETS)
|
||||
const LEDColor LEDLights2::defaultLEDColor = LEDColor(
|
||||
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE
|
||||
OPTARG(HAS_WHITE_LED2, LED_USER_PRESET_WHITE)
|
||||
OPTARG(NEOPIXEL_LED, LED_USER_PRESET_BRIGHTNESS)
|
||||
);
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
LEDColor LEDLights2::color;
|
||||
bool LEDLights2::lights_on;
|
||||
#endif
|
||||
|
||||
LEDLights2 leds2;
|
||||
|
||||
void LEDLights2::setup() {
|
||||
neo2.init();
|
||||
TERN_(NEO2_USER_PRESET_STARTUP, set_default());
|
||||
}
|
||||
|
||||
void LEDLights2::set_color(const LEDColor &incol) {
|
||||
const uint32_t neocolor = LEDColorWhite() == incol
|
||||
? neo2.Color(NEO2_WHITE)
|
||||
: neo2.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_LED2, incol.w));
|
||||
neo2.set_brightness(incol.i);
|
||||
neo2.set_color(neocolor);
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
// Don't update the color when OFF
|
||||
lights_on = !incol.is_off();
|
||||
if (lights_on) color = incol;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
void LEDLights2::toggle() { if (lights_on) set_off(); else update(); }
|
||||
#endif
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
||||
#endif // HAS_COLOR_LEDS
|
||||
|
153
Marlin/src/feature/leds/leds.h
Executable file → Normal file
153
Marlin/src/feature/leds/leds.h
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -29,65 +29,42 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
#include "neopixel.h"
|
||||
// A white component can be passed
|
||||
#if EITHER(RGBW_LED, PCA9632_RGBW)
|
||||
#define HAS_WHITE_LED 1
|
||||
#endif
|
||||
|
||||
// A white component can be passed
|
||||
#define HAS_WHITE_LED EITHER(RGBW_LED, NEOPIXEL_LED)
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
#define _NEOPIXEL_INCLUDE_
|
||||
#include "neopixel.h"
|
||||
#undef _NEOPIXEL_INCLUDE_
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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
|
||||
OPTARG(HAS_WHITE_LED, w)
|
||||
OPTARG(NEOPIXEL_LED, i)
|
||||
;
|
||||
|
||||
LEDColor() : r(255), g(255), b(255)
|
||||
#if HAS_WHITE_LED
|
||||
, w(255)
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, i(NEOPIXEL_BRIGHTNESS)
|
||||
#endif
|
||||
#endif
|
||||
OPTARG(HAS_WHITE_LED, w(255))
|
||||
OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS))
|
||||
{}
|
||||
|
||||
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(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w=0) OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS))
|
||||
: r(r), g(g), b(b) OPTARG(HAS_WHITE_LED, w(w)) OPTARG(NEOPIXEL_LED, i(i)) {}
|
||||
|
||||
LEDColor(const uint8_t (&rgbw)[4]) : r(rgbw[0]), g(rgbw[1]), b(rgbw[2])
|
||||
#if HAS_WHITE_LED
|
||||
, w(rgbw[3])
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, i(NEOPIXEL_BRIGHTNESS)
|
||||
#endif
|
||||
#endif
|
||||
OPTARG(HAS_WHITE_LED, w(rgbw[3]))
|
||||
OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS))
|
||||
{}
|
||||
|
||||
LEDColor& operator=(const uint8_t (&rgbw)[4]) {
|
||||
r = rgbw[0]; g = rgbw[1]; b = rgbw[2];
|
||||
#if HAS_WHITE_LED
|
||||
w = rgbw[3];
|
||||
#endif
|
||||
TERN_(HAS_WHITE_LED, w = rgbw[3]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -104,26 +81,13 @@ typedef struct LEDColor {
|
||||
bool operator!=(const LEDColor &right) { return !operator==(right); }
|
||||
|
||||
bool is_off() const {
|
||||
return 3 > r + g + b
|
||||
#if HAS_WHITE_LED
|
||||
+ w
|
||||
#endif
|
||||
;
|
||||
return 3 > r + g + b + TERN0(HAS_WHITE_LED, w);
|
||||
}
|
||||
} LEDColor;
|
||||
|
||||
/**
|
||||
* Color helpers and presets
|
||||
* Color presets
|
||||
*/
|
||||
#if HAS_WHITE_LED
|
||||
#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)
|
||||
#endif
|
||||
|
||||
#define LEDColorOff() LEDColor( 0, 0, 0)
|
||||
#define LEDColorRed() LEDColor(255, 0, 0)
|
||||
@@ -151,27 +115,15 @@ public:
|
||||
static void setup(); // init()
|
||||
|
||||
static void set_color(const LEDColor &color
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, bool isSequence=false
|
||||
#endif
|
||||
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
|
||||
);
|
||||
|
||||
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
|
||||
static inline void set_color(uint8_t r, uint8_t g, uint8_t b
|
||||
OPTARG(HAS_WHITE_LED, uint8_t w=0)
|
||||
OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
|
||||
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
|
||||
) {
|
||||
set_color(MakeLEDColor(r, g, b, w, i)
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, isSequence
|
||||
#endif
|
||||
);
|
||||
set_color(LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, i)) OPTARG(NEOPIXEL_IS_SEQUENTIAL, isSequence));
|
||||
}
|
||||
|
||||
static inline void set_off() { set_color(LEDColorOff()); }
|
||||
@@ -193,13 +145,15 @@ public:
|
||||
static inline LEDColor get_color() { return lights_on ? color : LEDColorOff(); }
|
||||
#endif
|
||||
|
||||
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
|
||||
#if ANY(LED_CONTROL_MENU, PRINTER_EVENT_LEDS, CASE_LIGHT_IS_COLOR_LED)
|
||||
static LEDColor color; // last non-off color
|
||||
static bool lights_on; // the last set color was "on"
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
static void toggle(); // swap "off" with color
|
||||
#endif
|
||||
#if EITHER(LED_CONTROL_MENU, CASE_LIGHT_USE_RGB_LED)
|
||||
static inline void update() { set_color(color); }
|
||||
#endif
|
||||
|
||||
@@ -209,10 +163,57 @@ public:
|
||||
public:
|
||||
static inline void reset_timeout(const millis_t &ms) {
|
||||
led_off_time = ms + LED_BACKLIGHT_TIMEOUT;
|
||||
if (!lights_on) set_default();
|
||||
if (!lights_on) update();
|
||||
}
|
||||
static void update_timeout(const bool power_on);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern LEDLights leds;
|
||||
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
class LEDLights2 {
|
||||
public:
|
||||
LEDLights2() {}
|
||||
|
||||
static void setup(); // init()
|
||||
|
||||
static void set_color(const LEDColor &color);
|
||||
|
||||
static inline void set_color(uint8_t r, uint8_t g, uint8_t b
|
||||
OPTARG(HAS_WHITE_LED, uint8_t w=0)
|
||||
OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
|
||||
) {
|
||||
set_color(LEDColor(r, g, b
|
||||
OPTARG(HAS_WHITE_LED, w)
|
||||
OPTARG(NEOPIXEL_LED, i)
|
||||
));
|
||||
}
|
||||
|
||||
static inline void set_off() { set_color(LEDColorOff()); }
|
||||
static inline void set_green() { set_color(LEDColorGreen()); }
|
||||
static inline void set_white() { set_color(LEDColorWhite()); }
|
||||
|
||||
#if ENABLED(NEO2_COLOR_PRESETS)
|
||||
static const LEDColor defaultLEDColor;
|
||||
static inline void set_default() { set_color(defaultLEDColor); }
|
||||
static inline void set_red() { set_color(LEDColorRed()); }
|
||||
static inline void set_orange() { set_color(LEDColorOrange()); }
|
||||
static inline void set_yellow() { set_color(LEDColorYellow()); }
|
||||
static inline void set_blue() { set_color(LEDColorBlue()); }
|
||||
static inline void set_indigo() { set_color(LEDColorIndigo()); }
|
||||
static inline void set_violet() { set_color(LEDColorViolet()); }
|
||||
#endif
|
||||
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
static LEDColor color; // last non-off color
|
||||
static bool lights_on; // the last set color was "on"
|
||||
static void toggle(); // swap "off" with color
|
||||
static inline void update() { set_color(color); }
|
||||
#endif
|
||||
};
|
||||
|
||||
extern LEDLights2 leds2;
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
147
Marlin/src/feature/leds/neopixel.cpp
Executable file → Normal file
147
Marlin/src/feature/leds/neopixel.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -28,38 +28,50 @@
|
||||
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
|
||||
#include "neopixel.h"
|
||||
#include "leds.h"
|
||||
|
||||
#if ENABLED(NEOPIXEL_STARTUP_TEST)
|
||||
#if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
|
||||
#include "../../core/utility.h"
|
||||
#endif
|
||||
|
||||
Marlin_NeoPixel neo;
|
||||
int8_t Marlin_NeoPixel::neoindex;
|
||||
|
||||
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
, Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
|
||||
#endif
|
||||
;
|
||||
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
|
||||
#if CONJOINED_NEOPIXEL
|
||||
Adafruit_NeoPixel Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800);
|
||||
#endif
|
||||
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
|
||||
|
||||
void Marlin_NeoPixel::set_color_background() {
|
||||
uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
|
||||
set_pixel_color(NEOPIXEL_BKGD_LED_INDEX, adaneo1.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
|
||||
void Marlin_NeoPixel::set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
for (int background_led = NEOPIXEL_BKGD_INDEX_FIRST; background_led <= NEOPIXEL_BKGD_INDEX_LAST; background_led++)
|
||||
set_pixel_color(background_led, adaneo1.Color(r, g, b, w));
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel::reset_background_color() {
|
||||
constexpr uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
|
||||
set_background_color(background_color[0], background_color[1], background_color[2], background_color[3]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Marlin_NeoPixel::set_color(const uint32_t color) {
|
||||
for (uint16_t i = 0; i < pixels(); ++i) {
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
|
||||
set_color_background();
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
set_pixel_color(i, color);
|
||||
if (neoindex >= 0) {
|
||||
set_pixel_color(neoindex, color);
|
||||
neoindex = -1;
|
||||
}
|
||||
else {
|
||||
for (uint16_t i = 0; i < pixels(); ++i) {
|
||||
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
|
||||
if (i == NEOPIXEL_BKGD_INDEX_FIRST && TERN(NEOPIXEL_BKGD_ALWAYS_ON, true, color != 0x000000)) {
|
||||
reset_background_color();
|
||||
i += NEOPIXEL_BKGD_INDEX_LAST - (NEOPIXEL_BKGD_INDEX_FIRST);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
set_pixel_color(i, color);
|
||||
}
|
||||
}
|
||||
show();
|
||||
}
|
||||
@@ -71,47 +83,86 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel::init() {
|
||||
SET_OUTPUT(NEOPIXEL_PIN);
|
||||
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
|
||||
neoindex = -1; // -1 .. NEOPIXEL_PIXELS-1 range
|
||||
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
|
||||
begin();
|
||||
show(); // initialize to all off
|
||||
|
||||
#if ENABLED(NEOPIXEL_STARTUP_TEST)
|
||||
safe_delay(1000);
|
||||
set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
|
||||
safe_delay(1000);
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
|
||||
safe_delay(1000);
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
|
||||
safe_delay(1000);
|
||||
safe_delay(500);
|
||||
#if HAS_WHITE_LED
|
||||
set_color_startup(adaneo1.Color(0, 0, 0, 255)); // white
|
||||
safe_delay(500);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
set_color_background();
|
||||
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
|
||||
reset_background_color();
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_USER_PRESET_STARTUP)
|
||||
set_color(adaneo1.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
|
||||
#else
|
||||
set_color(adaneo1.Color(0, 0, 0, 0));
|
||||
#endif
|
||||
set_color(adaneo1.Color
|
||||
TERN(LED_USER_PRESET_STARTUP,
|
||||
(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE),
|
||||
(0, 0, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool Marlin_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 = adaneo1.Color(r, g, b, w);
|
||||
set_brightness(p);
|
||||
#if DISABLED(NEOPIXEL_IS_SEQUENTIAL)
|
||||
set_color(color);
|
||||
return false;
|
||||
#else
|
||||
static uint16_t nextLed = 0;
|
||||
set_pixel_color(nextLed, color);
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
Marlin_NeoPixel2 neo2;
|
||||
|
||||
int8_t Marlin_NeoPixel2::neoindex;
|
||||
Adafruit_NeoPixel Marlin_NeoPixel2::adaneo(NEOPIXEL2_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE);
|
||||
|
||||
void Marlin_NeoPixel2::set_color(const uint32_t color) {
|
||||
if (neoindex >= 0) {
|
||||
set_pixel_color(neoindex, color);
|
||||
neoindex = -1;
|
||||
}
|
||||
else {
|
||||
for (uint16_t i = 0; i < pixels(); ++i)
|
||||
set_pixel_color(i, color);
|
||||
}
|
||||
show();
|
||||
if (++nextLed >= pixels()) nextLed = 0;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel2::set_color_startup(const uint32_t color) {
|
||||
for (uint16_t i = 0; i < pixels(); ++i)
|
||||
set_pixel_color(i, color);
|
||||
show();
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel2::init() {
|
||||
neoindex = -1; // -1 .. NEOPIXEL2_PIXELS-1 range
|
||||
set_brightness(NEOPIXEL2_BRIGHTNESS); // 0 .. 255 range
|
||||
begin();
|
||||
show(); // initialize to all off
|
||||
|
||||
#if ENABLED(NEOPIXEL2_STARTUP_TEST)
|
||||
set_color_startup(adaneo.Color(255, 0, 0, 0)); // red
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo.Color(0, 255, 0, 0)); // green
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
|
||||
safe_delay(500);
|
||||
#if HAS_WHITE_LED2
|
||||
set_color_startup(adaneo.Color(0, 0, 0, 255)); // white
|
||||
safe_delay(500);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
set_color(adaneo.Color
|
||||
TERN(NEO2_USER_PRESET_STARTUP,
|
||||
(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE),
|
||||
(0, 0, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
||||
#endif // NEOPIXEL_LED
|
||||
|
126
Marlin/src/feature/leds/neopixel.h
Executable file → Normal file
126
Marlin/src/feature/leds/neopixel.h
Executable file → Normal file
@@ -16,15 +16,19 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Neopixel support
|
||||
* NeoPixel support
|
||||
*/
|
||||
|
||||
#ifndef _NEOPIXEL_INCLUDE_
|
||||
#error "Always include 'leds.h' and not 'neopixel.h' directly."
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Includes
|
||||
// ------------------------
|
||||
@@ -38,15 +42,24 @@
|
||||
// Defines
|
||||
// ------------------------
|
||||
|
||||
#define MULTIPLE_NEOPIXEL_TYPES (defined(NEOPIXEL2_TYPE) && (NEOPIXEL2_TYPE != NEOPIXEL_TYPE))
|
||||
#define _NEO_IS_RGB(N) (N == NEO_RGB || N == NEO_RBG || N == NEO_GRB || N == NEO_GBR || N == NEO_BRG || N == NEO_BGR)
|
||||
|
||||
#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 !_NEO_IS_RGB(NEOPIXEL_TYPE)
|
||||
#define HAS_WHITE_LED 1
|
||||
#endif
|
||||
|
||||
#if NEOPIXEL_IS_RGB
|
||||
#define NEO_WHITE 255, 255, 255, 0
|
||||
#else
|
||||
#if HAS_WHITE_LED
|
||||
#define NEO_WHITE 0, 0, 0, 255
|
||||
#else
|
||||
#define NEO_WHITE 255, 255, 255
|
||||
#endif
|
||||
|
||||
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
|
||||
#define MULTIPLE_NEOPIXEL_TYPES 1
|
||||
#endif
|
||||
|
||||
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
|
||||
#define CONJOINED_NEOPIXEL 1
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
@@ -55,66 +68,113 @@
|
||||
|
||||
class Marlin_NeoPixel {
|
||||
private:
|
||||
static Adafruit_NeoPixel adaneo1
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
, adaneo2
|
||||
#endif
|
||||
;
|
||||
static Adafruit_NeoPixel adaneo1;
|
||||
#if CONJOINED_NEOPIXEL
|
||||
static Adafruit_NeoPixel adaneo2;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static int8_t neoindex;
|
||||
|
||||
static void init();
|
||||
static void set_color_startup(const uint32_t c);
|
||||
|
||||
static void set_color(const uint32_t c);
|
||||
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
static void set_color_background();
|
||||
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
|
||||
static void set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
static void reset_background_color();
|
||||
#endif
|
||||
|
||||
static inline void begin() {
|
||||
adaneo1.begin();
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
adaneo2.begin();
|
||||
#endif
|
||||
TERN_(CONJOINED_NEOPIXEL, adaneo2.begin());
|
||||
}
|
||||
|
||||
static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
|
||||
adaneo1.setPixelColor(n, c);
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
adaneo2.setPixelColor(n, c);
|
||||
#if ENABLED(NEOPIXEL2_INSERIES)
|
||||
if (n >= NEOPIXEL_PIXELS) adaneo2.setPixelColor(n - (NEOPIXEL_PIXELS), c);
|
||||
else adaneo1.setPixelColor(n, c);
|
||||
#else
|
||||
adaneo1.setPixelColor(n, c);
|
||||
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void set_brightness(const uint8_t b) {
|
||||
adaneo1.setBrightness(b);
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
adaneo2.setBrightness(b);
|
||||
#endif
|
||||
TERN_(CONJOINED_NEOPIXEL, adaneo2.setBrightness(b));
|
||||
}
|
||||
|
||||
static inline void show() {
|
||||
// Some platforms cannot maintain PWM output when NeoPixel disables interrupts for long durations.
|
||||
TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT());
|
||||
adaneo1.show();
|
||||
#if PIN_EXISTS(NEOPIXEL2)
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
#if CONJOINED_NEOPIXEL
|
||||
adaneo2.show();
|
||||
#else
|
||||
adaneo1.setPin(NEOPIXEL2_PIN);
|
||||
adaneo1.show();
|
||||
adaneo1.setPin(NEOPIXEL_PIN);
|
||||
#endif
|
||||
#endif
|
||||
TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
|
||||
#endif
|
||||
|
||||
// Accessors
|
||||
static inline uint16_t pixels() { return adaneo1.numPixels(); }
|
||||
static inline uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); }
|
||||
|
||||
static inline uint8_t brightness() { return adaneo1.getBrightness(); }
|
||||
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
return adaneo1.Color(r, g, b, w);
|
||||
|
||||
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) {
|
||||
return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_LED, w));
|
||||
}
|
||||
};
|
||||
|
||||
extern Marlin_NeoPixel neo;
|
||||
|
||||
// Neo pixel channel 2
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
#if _NEO_IS_RGB(NEOPIXEL2_TYPE)
|
||||
#define NEOPIXEL2_IS_RGB 1
|
||||
#define NEO2_WHITE 255, 255, 255
|
||||
#else
|
||||
#define NEOPIXEL2_IS_RGBW 1
|
||||
#define HAS_WHITE_LED2 1 // A white component can be passed for NEOPIXEL2
|
||||
#define NEO2_WHITE 0, 0, 0, 255
|
||||
#endif
|
||||
|
||||
class Marlin_NeoPixel2 {
|
||||
private:
|
||||
static Adafruit_NeoPixel adaneo;
|
||||
|
||||
public:
|
||||
static int8_t neoindex;
|
||||
|
||||
static void init();
|
||||
static void set_color_startup(const uint32_t c);
|
||||
|
||||
static void set_color(const uint32_t c);
|
||||
|
||||
static inline void begin() { adaneo.begin(); }
|
||||
static inline void set_pixel_color(const uint16_t n, const uint32_t c) { adaneo.setPixelColor(n, c); }
|
||||
static inline void set_brightness(const uint8_t b) { adaneo.setBrightness(b); }
|
||||
static inline void show() {
|
||||
adaneo.show();
|
||||
adaneo.setPin(NEOPIXEL2_PIN);
|
||||
}
|
||||
|
||||
// Accessors
|
||||
static inline uint16_t pixels() { return adaneo.numPixels();}
|
||||
static inline uint8_t brightness() { return adaneo.getBrightness(); }
|
||||
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) {
|
||||
return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w));
|
||||
}
|
||||
};
|
||||
|
||||
extern Marlin_NeoPixel2 neo2;
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
||||
#undef _NEO_IS_RGB
|
||||
|
127
Marlin/src/feature/leds/pca9533.cpp
Normal file
127
Marlin/src/feature/leds/pca9533.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* PCA9533 LED controller driver (MightyBoard, FlashForge Creator Pro, etc.)
|
||||
* by @grauerfuchs - 1 Apr 2020
|
||||
*/
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(PCA9533)
|
||||
|
||||
#include "pca9533.h"
|
||||
#include <Wire.h>
|
||||
|
||||
void PCA9533_init() {
|
||||
Wire.begin();
|
||||
PCA9533_reset();
|
||||
}
|
||||
|
||||
static void PCA9533_writeAllRegisters(uint8_t psc0, uint8_t pwm0, uint8_t psc1, uint8_t pwm1, uint8_t ls0) {
|
||||
uint8_t data[6] = { PCA9533_REG_PSC0 | PCA9533_REGM_AI, psc0, pwm0, psc1, pwm1, ls0 };
|
||||
Wire.beginTransmission(PCA9533_Addr >> 1);
|
||||
Wire.write(data, 6);
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
static void PCA9533_writeRegister(uint8_t reg, uint8_t val) {
|
||||
uint8_t data[2] = { reg, val };
|
||||
Wire.beginTransmission(PCA9533_Addr >> 1);
|
||||
Wire.write(data, 2);
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
// Reset (clear) all registers
|
||||
void PCA9533_reset() {
|
||||
PCA9533_writeAllRegisters(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Turn all LEDs off
|
||||
void PCA9533_setOff() {
|
||||
PCA9533_writeRegister(PCA9533_REG_SEL, 0);
|
||||
}
|
||||
|
||||
void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
uint8_t r_pwm0 = 0; // Register data - PWM value
|
||||
uint8_t r_pwm1 = 0; // Register data - PWM value
|
||||
|
||||
uint8_t op_g = 0, op_r = 0, op_b = 0; // Opcodes - Green, Red, Blue
|
||||
|
||||
// Light theory! GREEN takes priority because
|
||||
// it's the most visible to the human eye.
|
||||
if (green == 0) op_g = PCA9533_LED_OP_OFF;
|
||||
else if (green == 255) op_g = PCA9533_LED_OP_ON;
|
||||
else { r_pwm0 = green; op_g = PCA9533_LED_OP_PWM0; }
|
||||
|
||||
// RED
|
||||
if (red == 0) op_r = PCA9533_LED_OP_OFF;
|
||||
else if (red == 255) op_r = PCA9533_LED_OP_ON;
|
||||
else if (r_pwm0 == 0 || r_pwm0 == red) {
|
||||
r_pwm0 = red; op_r = PCA9533_LED_OP_PWM0;
|
||||
}
|
||||
else {
|
||||
r_pwm1 = red; op_r = PCA9533_LED_OP_PWM1;
|
||||
}
|
||||
|
||||
// BLUE
|
||||
if (blue == 0) op_b = PCA9533_LED_OP_OFF;
|
||||
else if (blue == 255) op_b = PCA9533_LED_OP_ON;
|
||||
else if (r_pwm0 == 0 || r_pwm0 == blue) {
|
||||
r_pwm0 = blue; op_b = PCA9533_LED_OP_PWM0;
|
||||
}
|
||||
else if (r_pwm1 == 0 || r_pwm1 == blue) {
|
||||
r_pwm1 = blue; op_b = PCA9533_LED_OP_PWM1;
|
||||
}
|
||||
else {
|
||||
/**
|
||||
* Conflict. 3 values are requested but only 2 channels exist.
|
||||
* G is on channel 0 and R is on channel 1, so work from there.
|
||||
* Find the closest match, average the values, then use the free channel.
|
||||
*/
|
||||
uint8_t dgb = ABS(green - blue),
|
||||
dgr = ABS(green - red),
|
||||
dbr = ABS(blue - red);
|
||||
if (dgb < dgr && dgb < dbr) { // Mix with G on channel 0.
|
||||
op_b = PCA9533_LED_OP_PWM0;
|
||||
r_pwm0 = uint8_t(((uint16_t)green + (uint16_t)blue) / 2);
|
||||
}
|
||||
else if (dbr <= dgr && dbr <= dgb) { // Mix with R on channel 1.
|
||||
op_b = PCA9533_LED_OP_PWM1;
|
||||
r_pwm1 = uint8_t(((uint16_t)red + (uint16_t)blue) / 2);
|
||||
}
|
||||
else { // Mix R+G on 0 and put B on 1.
|
||||
op_r = PCA9533_LED_OP_PWM0;
|
||||
r_pwm0 = uint8_t(((uint16_t)green + (uint16_t)red) / 2);
|
||||
op_b = PCA9533_LED_OP_PWM1;
|
||||
r_pwm1 = blue;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the changes to the hardware
|
||||
PCA9533_writeAllRegisters(0, r_pwm0, 0, r_pwm1,
|
||||
(op_g << PCA9533_LED_OFS_GRN) | (op_r << PCA9533_LED_OFS_RED) | (op_b << PCA9533_LED_OFS_BLU)
|
||||
);
|
||||
}
|
||||
|
||||
#endif // PCA9533
|
59
Marlin/src/feature/leds/pca9533.h
Normal file
59
Marlin/src/feature/leds/pca9533.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Driver for the PCA9533 LED controller found on the MightyBoard
|
||||
* used by FlashForge Creator Pro, MakerBot, etc.
|
||||
* Written 2020 APR 01 by grauerfuchs
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
#define ENABLE_I2C_PULLUPS
|
||||
|
||||
// Chip address (for Wire)
|
||||
#define PCA9533_Addr 0xC4
|
||||
|
||||
// Control registers
|
||||
#define PCA9533_REG_READ 0x00
|
||||
#define PCA9533_REG_PSC0 0x01
|
||||
#define PCA9533_REG_PWM0 0x02
|
||||
#define PCA9533_REG_PSC1 0x03
|
||||
#define PCA9533_REG_PWM1 0x04
|
||||
#define PCA9533_REG_SEL 0x05
|
||||
#define PCA9533_REGM_AI 0x10
|
||||
|
||||
// LED selector operation
|
||||
#define PCA9533_LED_OP_OFF 0B00
|
||||
#define PCA9533_LED_OP_ON 0B01
|
||||
#define PCA9533_LED_OP_PWM0 0B10
|
||||
#define PCA9533_LED_OP_PWM1 0B11
|
||||
|
||||
// Select register bit offsets for LED colors
|
||||
#define PCA9533_LED_OFS_RED 0
|
||||
#define PCA9533_LED_OFS_GRN 2
|
||||
#define PCA9533_LED_OFS_BLU 4
|
||||
|
||||
void PCA9533_init();
|
||||
void PCA9533_reset();
|
||||
void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void PCA9533_setOff();
|
48
Marlin/src/feature/leds/pca9632.cpp
Executable file → Normal file
48
Marlin/src/feature/leds/pca9632.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#define PCA9632_AUTOGLO 0xC0
|
||||
#define PCA9632_AUTOGI 0xE0
|
||||
|
||||
// Red=LED0 Green=LED1 Blue=LED2
|
||||
// Red=LED0 Green=LED1 Blue=LED2 White=LED3
|
||||
#ifndef PCA9632_RED
|
||||
#define PCA9632_RED 0x00
|
||||
#endif
|
||||
@@ -68,9 +68,12 @@
|
||||
#ifndef PCA9632_BLU
|
||||
#define PCA9632_BLU 0x04
|
||||
#endif
|
||||
#if HAS_WHITE_LED && !defined(PCA9632_WHT)
|
||||
#define PCA9632_WHT 0x06
|
||||
#endif
|
||||
|
||||
// If any of the color indexes are greater than 0x04 they can't use auto increment
|
||||
#if !defined(PCA9632_NO_AUTO_INC) && (PCA9632_RED > 0x04 || PCA9632_GRN > 0x04 || PCA9632_BLU > 0x04)
|
||||
#if !defined(PCA9632_NO_AUTO_INC) && (PCA9632_RED > 0x04 || PCA9632_GRN > 0x04 || PCA9632_BLU > 0x04 || PCA9632_WHT > 0x04)
|
||||
#define PCA9632_NO_AUTO_INC
|
||||
#endif
|
||||
|
||||
@@ -89,25 +92,26 @@ static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte vr, const byte vg, const byte vb) {
|
||||
static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte vr, const byte vg, const byte vb
|
||||
OPTARG(PCA9632_RGBW, const byte vw)
|
||||
) {
|
||||
#if DISABLED(PCA9632_NO_AUTO_INC)
|
||||
uint8_t data[4], len = 4;
|
||||
uint8_t data[4];
|
||||
data[0] = PCA9632_AUTO_IND | regadd;
|
||||
data[1 + (PCA9632_RED >> 1)] = vr;
|
||||
data[1 + (PCA9632_GRN >> 1)] = vg;
|
||||
data[1 + (PCA9632_BLU >> 1)] = vb;
|
||||
Wire.beginTransmission(I2C_ADDRESS(addr));
|
||||
Wire.write(data, sizeof(data));
|
||||
Wire.endTransmission();
|
||||
#else
|
||||
uint8_t data[6], len = 6;
|
||||
data[0] = regadd + (PCA9632_RED >> 1);
|
||||
data[1] = vr;
|
||||
data[2] = regadd + (PCA9632_GRN >> 1);
|
||||
data[3] = vg;
|
||||
data[4] = regadd + (PCA9632_BLU >> 1);
|
||||
data[5] = vb;
|
||||
PCA9632_WriteRegister(addr, regadd + (PCA9632_RED >> 1), vr);
|
||||
PCA9632_WriteRegister(addr, regadd + (PCA9632_GRN >> 1), vg);
|
||||
PCA9632_WriteRegister(addr, regadd + (PCA9632_BLU >> 1), vb);
|
||||
#if ENABLED(PCA9632_RGBW)
|
||||
PCA9632_WriteRegister(addr, regadd + (PCA9632_WHT >> 1), vw);
|
||||
#endif
|
||||
#endif
|
||||
Wire.beginTransmission(I2C_ADDRESS(addr));
|
||||
Wire.write(data, len);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -120,7 +124,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
|
||||
}
|
||||
#endif
|
||||
|
||||
void pca9632_set_led_color(const LEDColor &color) {
|
||||
void PCA9632_set_led_color(const LEDColor &color) {
|
||||
Wire.begin();
|
||||
if (!PCA_init) {
|
||||
PCA_init = 1;
|
||||
@@ -130,15 +134,21 @@ void pca9632_set_led_color(const LEDColor &color) {
|
||||
|
||||
const byte LEDOUT = (color.r ? LED_PWM << PCA9632_RED : 0)
|
||||
| (color.g ? LED_PWM << PCA9632_GRN : 0)
|
||||
| (color.b ? LED_PWM << PCA9632_BLU : 0);
|
||||
| (color.b ? LED_PWM << PCA9632_BLU : 0)
|
||||
#if ENABLED(PCA9632_RGBW)
|
||||
| (color.w ? LED_PWM << PCA9632_WHT : 0)
|
||||
#endif
|
||||
;
|
||||
|
||||
PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b);
|
||||
PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b
|
||||
OPTARG(PCA9632_RGBW, color.w)
|
||||
);
|
||||
PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
|
||||
}
|
||||
|
||||
#if ENABLED(PCA9632_BUZZER)
|
||||
|
||||
void pca9632_buzz(const long, const uint16_t) {
|
||||
void PCA9632_buzz(const long, const uint16_t) {
|
||||
uint8_t data[] = PCA9632_BUZZER_DATA;
|
||||
Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
|
||||
Wire.write(data, sizeof(data));
|
||||
|
6
Marlin/src/feature/leds/pca9632.h
Executable file → Normal file
6
Marlin/src/feature/leds/pca9632.h
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -29,9 +29,9 @@
|
||||
struct LEDColor;
|
||||
typedef LEDColor LEDColor;
|
||||
|
||||
void pca9632_set_led_color(const LEDColor &color);
|
||||
void PCA9632_set_led_color(const LEDColor &color);
|
||||
|
||||
#if ENABLED(PCA9632_BUZZER)
|
||||
#include <stdint.h>
|
||||
void pca9632_buzz(const long, const uint16_t);
|
||||
void PCA9632_buzz(const long, const uint16_t);
|
||||
#endif
|
||||
|
36
Marlin/src/feature/leds/printer_event_leds.cpp
Executable file → Normal file
36
Marlin/src/feature/leds/printer_event_leds.cpp
Executable file → Normal file
@@ -16,12 +16,12 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* printer_event_leds.cpp - LED color changing based on printer status
|
||||
* feature/leds/printer_event_leds.cpp - LED color changing based on printer status
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
@@ -40,24 +40,23 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
uint8_t PrinterEventLEDs::old_intensity = 0;
|
||||
|
||||
inline uint8_t pel_intensity(const float &start, const float ¤t, const float &target) {
|
||||
return (uint8_t)map(constrain(current, start, target), start, target, 0.f, 255.f);
|
||||
inline uint8_t pel_intensity(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
if (start == target) return 255;
|
||||
return (uint8_t)map(constrain(current, start, target), start, target, 0, 255);
|
||||
}
|
||||
|
||||
inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b) {
|
||||
inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b OPTARG(HAS_WHITE_LED, const uint8_t w=0)) {
|
||||
leds.set_color(
|
||||
MakeLEDColor(r, g, b, 0, neo.brightness())
|
||||
#if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
|
||||
, true
|
||||
#endif
|
||||
);
|
||||
LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, neo.brightness()))
|
||||
OPTARG(NEOPIXEL_IS_SEQUENTIAL, true)
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if HAS_TEMP_HOTEND
|
||||
|
||||
void PrinterEventLEDs::onHotendHeating(const float &start, const float ¤t, const float &target) {
|
||||
void PrinterEventLEDs::onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t blue = pel_intensity(start, current, target);
|
||||
if (blue != old_intensity) {
|
||||
old_intensity = blue;
|
||||
@@ -69,13 +68,26 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
|
||||
void PrinterEventLEDs::onBedHeating(const float &start, const float ¤t, const float &target) {
|
||||
void PrinterEventLEDs::onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t red = pel_intensity(start, current, target);
|
||||
if (red != old_intensity) {
|
||||
old_intensity = red;
|
||||
pel_set_rgb(red, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_CHAMBER
|
||||
|
||||
void PrinterEventLEDs::onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t green = pel_intensity(start, current, target);
|
||||
if (green != old_intensity) {
|
||||
old_intensity = green;
|
||||
pel_set_rgb(255, green, 255);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // PRINTER_EVENT_LEDS
|
||||
|
25
Marlin/src/feature/leds/printer_event_leds.h
Executable file → Normal file
25
Marlin/src/feature/leds/printer_event_leds.h
Executable file → Normal file
@@ -16,13 +16,13 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* printer_event_leds.h - LED color changing based on printer status
|
||||
* feature/leds/printer_event_leds.h - LED color changing based on printer status
|
||||
*/
|
||||
|
||||
#include "leds.h"
|
||||
@@ -36,27 +36,26 @@ private:
|
||||
static bool leds_off_after_print;
|
||||
#endif
|
||||
|
||||
static inline void set_done() {
|
||||
#if ENABLED(LED_COLOR_PRESETS)
|
||||
leds.set_default();
|
||||
#else
|
||||
leds.set_off();
|
||||
#endif
|
||||
}
|
||||
static inline void set_done() { TERN(LED_COLOR_PRESETS, leds.set_default(), leds.set_off()); }
|
||||
|
||||
public:
|
||||
#if HAS_TEMP_HOTEND
|
||||
static inline LEDColor onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
|
||||
static void onHotendHeating(const float &start, const float ¤t, const float &target);
|
||||
static void onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
static inline LEDColor onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
|
||||
static void onBedHeating(const float &start, const float ¤t, const float &target);
|
||||
static void onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_TEMP_HOTEND || HAS_HEATED_BED
|
||||
static inline void onHeatingDone() { leds.set_white(); }
|
||||
#if HAS_HEATED_CHAMBER
|
||||
static inline LEDColor onChamberHeatingStart() { old_intensity = 127; return leds.get_color(); }
|
||||
static void onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_HEATED_CHAMBER
|
||||
static inline void onHeatingDone() { leds.set_white(); }
|
||||
static inline void onPidTuningDone(LEDColor c) { leds.set_color(c); }
|
||||
#endif
|
||||
|
||||
|
11
Marlin/src/feature/leds/tempstat.cpp
Executable file → Normal file
11
Marlin/src/feature/leds/tempstat.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -36,13 +36,10 @@ void handle_status_leds() {
|
||||
static millis_t next_status_led_update_ms = 0;
|
||||
if (ELAPSED(millis(), next_status_led_update_ms)) {
|
||||
next_status_led_update_ms += 500; // Update every 0.5s
|
||||
float max_temp = 0.0;
|
||||
#if HAS_HEATED_BED
|
||||
max_temp = _MAX(thermalManager.degTargetBed(), thermalManager.degBed());
|
||||
#endif
|
||||
celsius_t max_temp = TERN0(HAS_HEATED_BED, _MAX(thermalManager.degTargetBed(), thermalManager.wholeDegBed()));
|
||||
HOTEND_LOOP()
|
||||
max_temp = _MAX(max_temp, thermalManager.degHotend(e), thermalManager.degTargetHotend(e));
|
||||
const int8_t new_red = (max_temp > 55.0) ? HIGH : (max_temp < 54.0 || old_red < 0) ? LOW : old_red;
|
||||
max_temp = _MAX(max_temp, thermalManager.wholeDegHotend(e), thermalManager.degTargetHotend(e));
|
||||
const int8_t new_red = (max_temp > 55) ? HIGH : (max_temp < 54 || old_red < 0) ? LOW : old_red;
|
||||
if (new_red != old_red) {
|
||||
old_red = new_red;
|
||||
#if PIN_EXISTS(STAT_LED_RED)
|
||||
|
2
Marlin/src/feature/leds/tempstat.h
Executable file → Normal file
2
Marlin/src/feature/leds/tempstat.h
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* 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/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
Reference in New Issue
Block a user