Browse Source

Fysetc LCD backlight timeout (#14265)

MastS 5 years ago
parent
commit
18904c42f6

+ 14
- 0
Marlin/src/feature/leds/leds.cpp View File

148
   void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
148
   void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
149
 #endif
149
 #endif
150
 
150
 
151
+#ifdef LED_BACKLIGHT_TIMEOUT
152
+
153
+  millis_t LEDLights::led_off_time; // = 0
154
+
155
+  void LEDLights::update_timeout(const bool power_on) {
156
+    const millis_t ms = millis();
157
+    if (power_on)
158
+      reset_timeout(ms);
159
+    else if (ELAPSED(ms, led_off_time))
160
+      set_off();
161
+  }
162
+
163
+#endif
164
+
151
 #endif // HAS_COLOR_LEDS
165
 #endif // HAS_COLOR_LEDS

+ 11
- 0
Marlin/src/feature/leds/leds.h View File

201
     static void toggle();  // swap "off" with color
201
     static void toggle();  // swap "off" with color
202
     static inline void update() { set_color(color); }
202
     static inline void update() { set_color(color); }
203
   #endif
203
   #endif
204
+
205
+  #ifdef LED_BACKLIGHT_TIMEOUT
206
+    private:
207
+      static millis_t led_off_time;
208
+    public:
209
+      static inline void reset_timeout(const millis_t &ms) {
210
+        led_off_time = ms + LED_BACKLIGHT_TIMEOUT;
211
+        if (!lights_on) set_default();
212
+      }
213
+      static void update_timeout(const bool power_on);
214
+  #endif
204
 };
215
 };
205
 
216
 
206
 extern LEDLights leds;
217
 extern LEDLights leds;

+ 11
- 9
Marlin/src/feature/leds/neopixel.cpp View File

36
 
36
 
37
 Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
37
 Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
38
 
38
 
39
+#ifdef NEOPIXEL_BKGD_LED_INDEX
40
+  void set_neopixel_color_background() {
41
+    uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
42
+    pixels.setPixelColor(NEOPIXEL_BKGD_LED_INDEX, pixels.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
43
+  }
44
+#endif
45
+
39
 void set_neopixel_color(const uint32_t color) {
46
 void set_neopixel_color(const uint32_t color) {
40
   for (uint16_t i = 0; i < pixels.numPixels(); ++i) {
47
   for (uint16_t i = 0; i < pixels.numPixels(); ++i) {
41
     #ifdef NEOPIXEL_BKGD_LED_INDEX
48
     #ifdef NEOPIXEL_BKGD_LED_INDEX
42
-      if (NEOPIXEL_BKGD_LED_INDEX == i) i++;
49
+      if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
50
+        set_neopixel_color_background();
51
+        continue;
52
+      }
43
     #endif
53
     #endif
44
     pixels.setPixelColor(i, color);
54
     pixels.setPixelColor(i, color);
45
   }
55
   }
52
   pixels.show();
62
   pixels.show();
53
 }
63
 }
54
 
64
 
55
-#ifdef NEOPIXEL_BKGD_LED_INDEX
56
-  void set_neopixel_color_background() {
57
-    uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
58
-    pixels.setPixelColor(NEOPIXEL_BKGD_LED_INDEX, pixels.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
59
-    pixels.show();
60
-  }
61
-#endif
62
-
63
 void setup_neopixel() {
65
 void setup_neopixel() {
64
   SET_OUTPUT(NEOPIXEL_PIN);
66
   SET_OUTPUT(NEOPIXEL_PIN);
65
   pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
67
   pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range

+ 3
- 0
Marlin/src/inc/Conditionals_LCD.h View File

150
   #define LCD_CONTRAST_MAX 255
150
   #define LCD_CONTRAST_MAX 255
151
   #define DEFAULT_LCD_CONTRAST 255
151
   #define DEFAULT_LCD_CONTRAST 255
152
   #define LED_COLORS_REDUCE_GREEN
152
   #define LED_COLORS_REDUCE_GREEN
153
+  #if POWER_SUPPLY > 0 && EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
154
+    #define LED_BACKLIGHT_TIMEOUT 10000
155
+  #endif
153
 
156
 
154
   // Require LED backlighting enabled
157
   // Require LED backlighting enabled
155
   #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)
158
   #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)

+ 7
- 0
Marlin/src/inc/SanityCheck.h View File

1501
 #endif
1501
 #endif
1502
 
1502
 
1503
 /**
1503
 /**
1504
+ * LED Backlight Timeout
1505
+ */
1506
+#if defined(LED_BACKLIGHT_TIMEOUT) && !(EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1) && POWER_SUPPLY > 0)
1507
+  #error "LED_BACKLIGHT_TIMEOUT requires a Fysetc Mini Panel and a Power Switch."
1508
+#endif
1509
+
1510
+/**
1504
  * Basic multi hotend duplication mode
1511
  * Basic multi hotend duplication mode
1505
  */
1512
  */
1506
 #if ENABLED(MULTI_NOZZLE_DUPLICATION)
1513
 #if ENABLED(MULTI_NOZZLE_DUPLICATION)

+ 28
- 0
Marlin/src/lcd/ultralcd.cpp View File

22
 
22
 
23
 #include "../inc/MarlinConfigPre.h"
23
 #include "../inc/MarlinConfigPre.h"
24
 
24
 
25
+#ifdef LED_BACKLIGHT_TIMEOUT
26
+  #include "../feature/leds/leds.h"
27
+#endif
28
+
25
 // These displays all share the MarlinUI class
29
 // These displays all share the MarlinUI class
26
 #if HAS_DISPLAY
30
 #if HAS_DISPLAY
27
   #include "ultralcd.h"
31
   #include "ultralcd.h"
563
 void MarlinUI::kill_screen(PGM_P lcd_msg) {
567
 void MarlinUI::kill_screen(PGM_P lcd_msg) {
564
   init();
568
   init();
565
   set_alert_status_P(lcd_msg);
569
   set_alert_status_P(lcd_msg);
570
+
571
+  // RED ALERT. RED ALERT.
572
+  #ifdef LED_BACKLIGHT_TIMEOUT
573
+    leds.set_color(LEDColorRed());
574
+    #ifdef NEOPIXEL_BKGD_LED_INDEX
575
+      pixels.setPixelColor(NEOPIXEL_BKGD_LED_INDEX, 255, 0, 0, 0);
576
+      pixels.show();
577
+    #endif
578
+  #endif
579
+
566
   draw_kill_screen();
580
   draw_kill_screen();
567
 }
581
 }
568
 
582
 
714
   static millis_t next_lcd_update_ms;
728
   static millis_t next_lcd_update_ms;
715
   millis_t ms = millis();
729
   millis_t ms = millis();
716
 
730
 
731
+  #ifdef LED_BACKLIGHT_TIMEOUT
732
+    leds.update_timeout(powersupply_on);
733
+  #endif
734
+
717
   #if HAS_LCD_MENU
735
   #if HAS_LCD_MENU
718
 
736
 
719
     #if LCD_TIMEOUT_TO_STATUS
737
     #if LCD_TIMEOUT_TO_STATUS
777
 
795
 
778
       ms = millis();
796
       ms = millis();
779
       next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;  // delay LCD update until after SD activity completes
797
       next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;  // delay LCD update until after SD activity completes
798
+
799
+      #ifdef LED_BACKLIGHT_TIMEOUT
800
+        leds.reset_timeout(ms);
801
+      #endif
780
     }
802
     }
781
 
803
 
782
   #endif // SDSUPPORT && SD_DETECT_PIN
804
   #endif // SDSUPPORT && SD_DETECT_PIN
851
           encoderPosition += (encoderDiff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
873
           encoderPosition += (encoderDiff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
852
           encoderDiff = 0;
874
           encoderDiff = 0;
853
         }
875
         }
876
+
854
         #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
877
         #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
855
           return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
878
           return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
856
         #endif
879
         #endif
880
+
857
         refresh(LCDVIEW_REDRAW_NOW);
881
         refresh(LCDVIEW_REDRAW_NOW);
882
+
883
+        #ifdef LED_BACKLIGHT_TIMEOUT
884
+          leds.reset_timeout(ms);
885
+        #endif
858
       }
886
       }
859
 
887
 
860
     #endif
888
     #endif

Loading…
Cancel
Save