Restore LED light color after pid tuning (#12082)

This commit is contained in:
Giuliano Zaro 2018-11-01 23:44:41 +01:00 committed by Scott Lahteine
parent 9f77df2590
commit 323c088356
4 changed files with 26 additions and 23 deletions

View File

@ -48,7 +48,7 @@
); );
#endif #endif
#if ENABLED(LED_CONTROL_MENU) #if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
LEDColor LEDLights::color; LEDColor LEDLights::color;
bool LEDLights::lights_on; bool LEDLights::lights_on;
#endif #endif
@ -72,7 +72,9 @@ void LEDLights::set_color(const LEDColor &incol
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w); const uint32_t neocolor = LEDColorWhite() == incol
? pixels.Color(NEO_WHITE)
: pixels.Color(incol.r, incol.g, incol.b, incol.w);
static uint16_t nextLed = 0; static uint16_t nextLed = 0;
pixels.setBrightness(incol.i); pixels.setBrightness(incol.i);
@ -117,22 +119,13 @@ void LEDLights::set_color(const LEDColor &incol
pca9632_set_led_color(incol); pca9632_set_led_color(incol);
#endif #endif
#if ENABLED(LED_CONTROL_MENU) #if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
// Don't update the color when OFF // Don't update the color when OFF
lights_on = !incol.is_off(); lights_on = !incol.is_off();
if (lights_on) color = incol; if (lights_on) color = incol;
#endif #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) #if ENABLED(LED_CONTROL_MENU)
void LEDLights::toggle() { if (lights_on) set_off(); else update(); } void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
#endif #endif

View File

@ -115,12 +115,12 @@ typedef struct LEDColor {
* Color helpers and presets * Color helpers and presets
*/ */
#if HAS_WHITE_LED #if HAS_WHITE_LED
#define LEDColorWhite() LEDColor(0, 0, 0, 255)
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I) #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I)
#else #else
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W) #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W)
#endif #endif
#define LEDColorWhite() LEDColor(0, 0, 0, 255)
#else #else
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B) #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
#define LEDColorWhite() LEDColor(255, 255, 255) #define LEDColorWhite() LEDColor(255, 255, 255)
@ -164,9 +164,9 @@ public:
); );
} }
static void set_white();
FORCE_INLINE static void set_off() { set_color(LEDColorOff()); } FORCE_INLINE static void set_off() { set_color(LEDColorOff()); }
FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); } FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); }
FORCE_INLINE static void set_white() { set_color(LEDColorWhite()); }
#if ENABLED(LED_COLOR_PRESETS) #if ENABLED(LED_COLOR_PRESETS)
static const LEDColor defaultLEDColor; static const LEDColor defaultLEDColor;
@ -179,9 +179,15 @@ public:
FORCE_INLINE static void set_violet() { set_color(LEDColorViolet()); } FORCE_INLINE static void set_violet() { set_color(LEDColorViolet()); }
#endif #endif
#if ENABLED(LED_CONTROL_MENU) #if ENABLED(PRINTER_EVENT_LEDS)
FORCE_INLINE static LEDColor get_color() { return lights_on ? color : LEDColorOff(); }
#endif
#if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
static LEDColor color; // last non-off color static LEDColor color; // last non-off color
static bool lights_on; // the last set color was "on" static bool lights_on; // the last set color was "on"
#endif
#if ENABLED(LED_CONTROL_MENU)
static void toggle(); // swap "off" with color static void toggle(); // swap "off" with color
FORCE_INLINE static void update() { set_color(color); } FORCE_INLINE static void update() { set_color(color); }
#endif #endif

View File

@ -38,18 +38,18 @@ private:
public: public:
#if HAS_TEMP_HOTEND #if HAS_TEMP_HOTEND
FORCE_INLINE static void onHotendHeatingStart() { old_intensity = 0; } FORCE_INLINE static LEDColor onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
static void onHotendHeating(const float &start, const float &current, const float &target); static void onHotendHeating(const float &start, const float &current, const float &target);
#endif #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED
FORCE_INLINE static void onBedHeatingStart() { old_intensity = 127; } FORCE_INLINE static LEDColor onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
static void onBedHeating(const float &start, const float &current, const float &target); static void onBedHeating(const float &start, const float &current, const float &target);
#endif #endif
#if HAS_TEMP_HOTEND || HAS_HEATED_BED #if HAS_TEMP_HOTEND || HAS_HEATED_BED
FORCE_INLINE static void onHeated() { leds.set_white(); } FORCE_INLINE static void onHeated() { leds.set_color(LEDColorWhite()); }
FORCE_INLINE static void onHeatersOff() { leds.set_off(); } FORCE_INLINE static void onPidTuningDone(LEDColor c) { leds.set_color(c); }
#endif #endif
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)

View File

@ -251,7 +251,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if HAS_PID_FOR_BOTH #if HAS_PID_FOR_BOTH
#define GHV(B,H) (hotend < 0 ? (B) : (H)) #define GHV(B,H) (hotend < 0 ? (B) : (H))
#define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0) #define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0)
#define ONHEATINGSTART() do{ if (hotend < 0) printerEventLEDs.onBedHeatingStart(); else printerEventLEDs.onHotendHeatingStart(); }while(0) #define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
#define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0) #define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
#elif ENABLED(PIDTEMPBED) #elif ENABLED(PIDTEMPBED)
#define GHV(B,H) B #define GHV(B,H) B
@ -311,7 +311,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
wait_for_heatup = true; // Can be interrupted with M108 wait_for_heatup = true; // Can be interrupted with M108
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]); const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
ONHEATINGSTART(); LEDColor color = ONHEATINGSTART();
#endif #endif
// PID Tuning loop // PID Tuning loop
@ -492,13 +492,17 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
_SET_BED_PID(); _SET_BED_PID();
#endif #endif
} }
#if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onPidTuningDone(color);
#endif
return; return;
} }
lcd_update(); lcd_update();
} }
disable_all_heaters(); disable_all_heaters();
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onHeatersOff(); printerEventLEDs.onPidTuningDone(color);
#endif #endif
} }
@ -2525,7 +2529,7 @@ void Temperature::isr() {
if (wait_for_heatup) { if (wait_for_heatup) {
lcd_reset_status(); lcd_reset_status();
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onHeated(); printerEventLEDs.onHeatingDone();
#endif #endif
} }