diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4c69ff293bdc..9e1c7d97ef3f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -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) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a30400a4983d..9f5d7f7edf15 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -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 diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp index 995693ffc50c..25ad1e267aff 100644 --- a/Marlin/src/feature/leds/leds.cpp +++ b/Marlin/src/feature/leds/leds.cpp @@ -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, diff --git a/Marlin/src/feature/leds/leds.h b/Marlin/src/feature/leds/leds.h index 22184381fc4d..b5458e6dd7ac 100644 --- a/Marlin/src/feature/leds/leds.h +++ b/Marlin/src/feature/leds/leds.h @@ -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()); } diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index afe6e99dbd56..88d1e60af402 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -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 @@ -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); } @@ -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) { @@ -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 @@ -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