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,4 +148,18 @@ void LEDLights::set_color(const LEDColor &incol
148 148
   void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
149 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 165
 #endif // HAS_COLOR_LEDS

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

@@ -201,6 +201,17 @@ public:
201 201
     static void toggle();  // swap "off" with color
202 202
     static inline void update() { set_color(color); }
203 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 217
 extern LEDLights leds;

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

@@ -36,10 +36,20 @@
36 36
 
37 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 46
 void set_neopixel_color(const uint32_t color) {
40 47
   for (uint16_t i = 0; i < pixels.numPixels(); ++i) {
41 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 53
     #endif
44 54
     pixels.setPixelColor(i, color);
45 55
   }
@@ -52,14 +62,6 @@ void set_neopixel_color_startup(const uint32_t color) {
52 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 65
 void setup_neopixel() {
64 66
   SET_OUTPUT(NEOPIXEL_PIN);
65 67
   pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range

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

@@ -150,6 +150,9 @@
150 150
   #define LCD_CONTRAST_MAX 255
151 151
   #define DEFAULT_LCD_CONTRAST 255
152 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 157
   // Require LED backlighting enabled
155 158
   #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)

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

@@ -1501,6 +1501,13 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
1501 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 1511
  * Basic multi hotend duplication mode
1505 1512
  */
1506 1513
 #if ENABLED(MULTI_NOZZLE_DUPLICATION)

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

@@ -22,6 +22,10 @@
22 22
 
23 23
 #include "../inc/MarlinConfigPre.h"
24 24
 
25
+#ifdef LED_BACKLIGHT_TIMEOUT
26
+  #include "../feature/leds/leds.h"
27
+#endif
28
+
25 29
 // These displays all share the MarlinUI class
26 30
 #if HAS_DISPLAY
27 31
   #include "ultralcd.h"
@@ -563,6 +567,16 @@ void MarlinUI::status_screen() {
563 567
 void MarlinUI::kill_screen(PGM_P lcd_msg) {
564 568
   init();
565 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 580
   draw_kill_screen();
567 581
 }
568 582
 
@@ -714,6 +728,10 @@ void MarlinUI::update() {
714 728
   static millis_t next_lcd_update_ms;
715 729
   millis_t ms = millis();
716 730
 
731
+  #ifdef LED_BACKLIGHT_TIMEOUT
732
+    leds.update_timeout(powersupply_on);
733
+  #endif
734
+
717 735
   #if HAS_LCD_MENU
718 736
 
719 737
     #if LCD_TIMEOUT_TO_STATUS
@@ -777,6 +795,10 @@ void MarlinUI::update() {
777 795
 
778 796
       ms = millis();
779 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 804
   #endif // SDSUPPORT && SD_DETECT_PIN
@@ -851,10 +873,16 @@ void MarlinUI::update() {
851 873
           encoderPosition += (encoderDiff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
852 874
           encoderDiff = 0;
853 875
         }
876
+
854 877
         #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
855 878
           return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
856 879
         #endif
880
+
857 881
         refresh(LCDVIEW_REDRAW_NOW);
882
+
883
+        #ifdef LED_BACKLIGHT_TIMEOUT
884
+          leds.reset_timeout(ms);
885
+        #endif
858 886
       }
859 887
 
860 888
     #endif

Loading…
Cancel
Save