Skip to content

Commit

Permalink
fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
ursoft committed Mar 2, 2020
1 parent f1eda3c commit 9bd6dec
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,7 @@
// Support for Adafruit Neopixel LED driver
#if (GITHUB_USER==URSOFT)
#define NEOPIXEL_LED
#define NEOPIXEL_EEPROM_STORE_HACK // store user color to EERPOM (unused area) // https://github.com/ursoft/Marlin/issues/33
#endif
#if ENABLED(NEOPIXEL_LED)
#define NEOPIXEL_TYPE NEO_GRBW // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h)
Expand Down
6 changes: 3 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,13 @@
#endif
#if ENABLED(LED_CONTROL_MENU)
#define LED_COLOR_PRESETS // Enable the Preset Color menu option
#if ENABLED(LED_COLOR_PRESETS)
#if ENABLED(LED_COLOR_PRESETS) // UlTi color:
#define LED_USER_PRESET_RED 255 // User defined RED value
#define LED_USER_PRESET_GREEN 128 // User defined GREEN value
#define LED_USER_PRESET_BLUE 0 // User defined BLUE value
#define LED_USER_PRESET_WHITE 0 // User defined WHITE value
#define LED_USER_PRESET_BRIGHTNESS 128 // User defined intensity
//#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#define LED_USER_PRESET_BRIGHTNESS 32 // User defined intensity - very low, you my use EEPROM to improve it
#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#endif
#endif

Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/feature/leds/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
#endif

#if ENABLED(LED_COLOR_PRESETS)
const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
#ifndef NEOPIXEL_EEPROM_STORE_HACK
const
#endif
LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
LED_USER_PRESET_RED,
LED_USER_PRESET_GREEN,
LED_USER_PRESET_BLUE,
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/leds/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ class LEDLights {
static inline void set_white() { set_color(LEDColorWhite()); }

#if ENABLED(LED_COLOR_PRESETS)
#ifdef NEOPIXEL_EEPROM_STORE_HACK
static LEDColor defaultLEDColor;
#else
static const LEDColor defaultLEDColor;
#endif
static inline void set_default() { set_color(defaultLEDColor); }
static inline void set_red() { set_color(LEDColorRed()); }
static inline void set_orange() { set_color(LEDColorOrange()); }
Expand Down
49 changes: 49 additions & 0 deletions Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#include "../gcode/gcode.h"
#include "../MarlinCore.h"

#ifdef NEOPIXEL_EEPROM_STORE_HACK
#include "../feature/leds/leds.h"
#endif

#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "../HAL/shared/persistent_store_api.h"
#endif
Expand Down Expand Up @@ -1137,6 +1141,16 @@ void MarlinSettings::postprocess() {
.E3 = 30, .E4 = 30, .E5 = 30
};
#endif
#ifdef NEOPIXEL_EEPROM_STORE_HACK //good bye E4 & E5
uint8_t *e4 = (uint8_t *)(&tmc_hybrid_threshold.E4);
e4[0] = LEDLights::color.r;
e4[1] = LEDLights::color.g;
e4[2] = LEDLights::color.b;
e4[3] = LEDLights::color.w;
e4[4] = LEDLights::color.i;
e4[5] = ~(e4[0] ^ e4[1] ^ e4[2] ^ e4[3] ^ e4[4]);
LEDLights::defaultLEDColor = LEDLights::color;
#endif
EEPROM_WRITE(tmc_hybrid_threshold);
}

Expand Down Expand Up @@ -1929,6 +1943,18 @@ void MarlinSettings::postprocess() {
tmc_hybrid_threshold_t tmc_hybrid_threshold;
_FIELD_TEST(tmc_hybrid_threshold);
EEPROM_READ(tmc_hybrid_threshold);
#ifdef NEOPIXEL_EEPROM_STORE_HACK //good bye E4 & E5
uint8_t *e4 = (uint8_t *)(&tmc_hybrid_threshold.E4);
if(!validating && e4[5] == uint8_t(~(e4[0] ^ e4[1] ^ e4[2] ^ e4[3] ^ e4[4]))) {
LEDLights::defaultLEDColor.r = e4[0];
LEDLights::defaultLEDColor.g = e4[1];
LEDLights::defaultLEDColor.b = e4[2];
LEDLights::defaultLEDColor.w = e4[3];
LEDLights::defaultLEDColor.i = e4[4];
LEDLights::set_default();
}
e4[0] = e4[1] = e4[2] = e4[3] = e4[4] = e4[5] = 0;
#endif

#if ENABLED(HYBRID_THRESHOLD)
if (!validating) {
Expand Down Expand Up @@ -2430,6 +2456,17 @@ void MarlinSettings::reset() {
planner.settings.min_feedrate_mm_s = feedRate_t(DEFAULT_MINIMUMFEEDRATE);
planner.settings.min_travel_feedrate_mm_s = feedRate_t(DEFAULT_MINTRAVELFEEDRATE);

#ifdef NEOPIXEL_EEPROM_STORE_HACK
LEDLights::defaultLEDColor = MakeLEDColor(
LED_USER_PRESET_RED,
LED_USER_PRESET_GREEN,
LED_USER_PRESET_BLUE,
LED_USER_PRESET_WHITE,
LED_USER_PRESET_BRIGHTNESS
);
LEDLights::set_default();
#endif

#if HAS_CLASSIC_JERK
#ifndef DEFAULT_XJERK
#define DEFAULT_XJERK 0
Expand Down Expand Up @@ -3675,6 +3712,18 @@ void MarlinSettings::reset() {
#endif
);
#endif

#ifdef NEOPIXEL_EEPROM_STORE_HACK
CONFIG_ECHO_HEADING("Display custom light:");
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR(
" M150 B", int(LEDLights::defaultLEDColor.b),
" P", int(LEDLights::defaultLEDColor.i),
" R", int(LEDLights::defaultLEDColor.r),
" U", int(LEDLights::defaultLEDColor.g),
" W", int(LEDLights::defaultLEDColor.w)
);
#endif
}

#endif // !DISABLE_M503
Expand Down

0 comments on commit 9bd6dec

Please sign in to comment.