1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-30 15:26:18 +00:00

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
#if ENABLED(LED_CONTROL_MENU)
#if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
LEDColor LEDLights::color;
bool LEDLights::lights_on;
#endif
@ -72,7 +72,9 @@ void LEDLights::set_color(const LEDColor &incol
#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;
pixels.setBrightness(incol.i);
@ -117,22 +119,13 @@ void LEDLights::set_color(const LEDColor &incol
pca9632_set_led_color(incol);
#endif
#if ENABLED(LED_CONTROL_MENU)
#if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
// 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

View File

@ -115,12 +115,12 @@ typedef struct 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
#define LEDColorWhite() LEDColor(0, 0, 0, 255)
#else
#define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
#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_green() { set_color(LEDColorGreen()); }
FORCE_INLINE static void set_white() { set_color(LEDColorWhite()); }
#if ENABLED(LED_COLOR_PRESETS)
static const LEDColor defaultLEDColor;
@ -179,9 +179,15 @@ public:
FORCE_INLINE static void set_violet() { set_color(LEDColorViolet()); }
#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 bool lights_on; // the last set color was "on"
#endif
#if ENABLED(LED_CONTROL_MENU)
static void toggle(); // swap "off" with color
FORCE_INLINE static void update() { set_color(color); }
#endif

View File

@ -38,18 +38,18 @@ private:
public:
#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);
#endif
#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);
#endif
#if HAS_TEMP_HOTEND || HAS_HEATED_BED
FORCE_INLINE static void onHeated() { leds.set_white(); }
FORCE_INLINE static void onHeatersOff() { leds.set_off(); }
FORCE_INLINE static void onHeated() { leds.set_color(LEDColorWhite()); }
FORCE_INLINE static void onPidTuningDone(LEDColor c) { leds.set_color(c); }
#endif
#if ENABLED(SDSUPPORT)

View File

@ -251,7 +251,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if HAS_PID_FOR_BOTH
#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 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)
#elif ENABLED(PIDTEMPBED)
#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
#if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
ONHEATINGSTART();
LEDColor color = ONHEATINGSTART();
#endif
// PID Tuning loop
@ -492,13 +492,17 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
_SET_BED_PID();
#endif
}
#if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onPidTuningDone(color);
#endif
return;
}
lcd_update();
}
disable_all_heaters();
#if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onHeatersOff();
printerEventLEDs.onPidTuningDone(color);
#endif
}
@ -2525,7 +2529,7 @@ void Temperature::isr() {
if (wait_for_heatup) {
lcd_reset_status();
#if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onHeated();
printerEventLEDs.onHeatingDone();
#endif
}