Browse Source

Restore LED light color after pid tuning (#12082)

Giuliano Zaro 5 years ago
parent
commit
323c088356

+ 5
- 12
Marlin/src/feature/leds/leds.cpp View File

@@ -48,7 +48,7 @@
48 48
   );
49 49
 #endif
50 50
 
51
-#if ENABLED(LED_CONTROL_MENU)
51
+#if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
52 52
   LEDColor LEDLights::color;
53 53
   bool LEDLights::lights_on;
54 54
 #endif
@@ -72,7 +72,9 @@ void LEDLights::set_color(const LEDColor &incol
72 72
 
73 73
   #if ENABLED(NEOPIXEL_LED)
74 74
 
75
-    const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w);
75
+    const uint32_t neocolor = LEDColorWhite() == incol
76
+                            ? pixels.Color(NEO_WHITE)
77
+                            : pixels.Color(incol.r, incol.g, incol.b, incol.w);
76 78
     static uint16_t nextLed = 0;
77 79
 
78 80
     pixels.setBrightness(incol.i);
@@ -117,22 +119,13 @@ void LEDLights::set_color(const LEDColor &incol
117 119
     pca9632_set_led_color(incol);
118 120
   #endif
119 121
 
120
-  #if ENABLED(LED_CONTROL_MENU)
122
+  #if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
121 123
     // Don't update the color when OFF
122 124
     lights_on = !incol.is_off();
123 125
     if (lights_on) color = incol;
124 126
   #endif
125 127
 }
126 128
 
127
-void LEDLights::set_white() {
128
-  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
129
-    set_color(LEDColorWhite());
130
-  #endif
131
-  #if ENABLED(NEOPIXEL_LED)
132
-    set_neopixel_color(pixels.Color(NEO_WHITE));
133
-  #endif
134
-}
135
-
136 129
 #if ENABLED(LED_CONTROL_MENU)
137 130
   void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
138 131
 #endif

+ 9
- 3
Marlin/src/feature/leds/leds.h View File

@@ -115,12 +115,12 @@ typedef struct LEDColor {
115 115
  * Color helpers and presets
116 116
  */
117 117
 #if HAS_WHITE_LED
118
-  #define LEDColorWhite() LEDColor(0, 0, 0, 255)
119 118
   #if ENABLED(NEOPIXEL_LED)
120 119
     #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W, I)
121 120
   #else
122 121
     #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B, W)
123 122
   #endif
123
+  #define LEDColorWhite() LEDColor(0, 0, 0, 255)
124 124
 #else
125 125
   #define MakeLEDColor(R,G,B,W,I) LEDColor(R, G, B)
126 126
   #define LEDColorWhite() LEDColor(255, 255, 255)
@@ -164,9 +164,9 @@ public:
164 164
     );
165 165
   }
166 166
 
167
-  static void set_white();
168 167
   FORCE_INLINE static void set_off()   { set_color(LEDColorOff()); }
169 168
   FORCE_INLINE static void set_green() { set_color(LEDColorGreen()); }
169
+  FORCE_INLINE static void set_white() { set_color(LEDColorWhite()); }
170 170
 
171 171
   #if ENABLED(LED_COLOR_PRESETS)
172 172
     static const LEDColor defaultLEDColor;
@@ -179,9 +179,15 @@ public:
179 179
     FORCE_INLINE static void set_violet()   { set_color(LEDColorViolet()); }
180 180
   #endif
181 181
 
182
-  #if ENABLED(LED_CONTROL_MENU)
182
+  #if ENABLED(PRINTER_EVENT_LEDS)
183
+    FORCE_INLINE static LEDColor get_color() { return lights_on ? color : LEDColorOff(); }
184
+  #endif
185
+
186
+  #if ENABLED(LED_CONTROL_MENU) || ENABLED(PRINTER_EVENT_LEDS)
183 187
     static LEDColor color; // last non-off color
184 188
     static bool lights_on; // the last set color was "on"
189
+  #endif
190
+  #if ENABLED(LED_CONTROL_MENU)
185 191
     static void toggle();  // swap "off" with color
186 192
     FORCE_INLINE static void update() { set_color(color); }
187 193
   #endif

+ 4
- 4
Marlin/src/feature/leds/printer_event_leds.h View File

@@ -38,18 +38,18 @@ private:
38 38
 
39 39
 public:
40 40
   #if HAS_TEMP_HOTEND
41
-    FORCE_INLINE static void onHotendHeatingStart() { old_intensity = 0; }
41
+    FORCE_INLINE static LEDColor onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
42 42
     static void onHotendHeating(const float &start, const float &current, const float &target);
43 43
   #endif
44 44
 
45 45
   #if HAS_HEATED_BED
46
-    FORCE_INLINE static void onBedHeatingStart() { old_intensity = 127; }
46
+    FORCE_INLINE static LEDColor onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
47 47
     static void onBedHeating(const float &start, const float &current, const float &target);
48 48
   #endif
49 49
 
50 50
   #if HAS_TEMP_HOTEND || HAS_HEATED_BED
51
-    FORCE_INLINE static void onHeated()     { leds.set_white(); }
52
-    FORCE_INLINE static void onHeatersOff() { leds.set_off(); }
51
+    FORCE_INLINE static void onHeated() { leds.set_color(LEDColorWhite()); }
52
+    FORCE_INLINE static void onPidTuningDone(LEDColor c) { leds.set_color(c); }
53 53
   #endif
54 54
 
55 55
   #if ENABLED(SDSUPPORT)

+ 8
- 4
Marlin/src/module/temperature.cpp View File

@@ -251,7 +251,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
251 251
     #if HAS_PID_FOR_BOTH
252 252
       #define GHV(B,H) (hotend < 0 ? (B) : (H))
253 253
       #define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0)
254
-      #define ONHEATINGSTART() do{ if (hotend < 0) printerEventLEDs.onBedHeatingStart(); else printerEventLEDs.onHotendHeatingStart(); }while(0)
254
+      #define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
255 255
       #define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
256 256
     #elif ENABLED(PIDTEMPBED)
257 257
       #define GHV(B,H) B
@@ -311,7 +311,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
311 311
     wait_for_heatup = true; // Can be interrupted with M108
312 312
     #if ENABLED(PRINTER_EVENT_LEDS)
313 313
       const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
314
-      ONHEATINGSTART();
314
+      LEDColor color = ONHEATINGSTART();
315 315
     #endif
316 316
 
317 317
     // PID Tuning loop
@@ -492,13 +492,17 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
492 492
             _SET_BED_PID();
493 493
           #endif
494 494
         }
495
+        #if ENABLED(PRINTER_EVENT_LEDS)
496
+          printerEventLEDs.onPidTuningDone(color);
497
+        #endif
498
+
495 499
         return;
496 500
       }
497 501
       lcd_update();
498 502
     }
499 503
     disable_all_heaters();
500 504
     #if ENABLED(PRINTER_EVENT_LEDS)
501
-      printerEventLEDs.onHeatersOff();
505
+      printerEventLEDs.onPidTuningDone(color);
502 506
     #endif
503 507
   }
504 508
 
@@ -2525,7 +2529,7 @@ void Temperature::isr() {
2525 2529
       if (wait_for_heatup) {
2526 2530
         lcd_reset_status();
2527 2531
         #if ENABLED(PRINTER_EVENT_LEDS)
2528
-          printerEventLEDs.onHeated();
2532
+          printerEventLEDs.onHeatingDone();
2529 2533
         #endif
2530 2534
       }
2531 2535
 

Loading…
Cancel
Save