Browse Source

🚸 Expose sub-options for E3V2 Enhanced (#23099)

Miguel Risco-Castillo 2 years ago
parent
commit
b4b16b63ff
No account linked to committer's email address

+ 1
- 1
Marlin/Configuration_adv.h View File

@@ -1280,7 +1280,7 @@
1280 1280
 
1281 1281
 #endif // HAS_LCD_MENU
1282 1282
 
1283
-#if HAS_DISPLAY
1283
+#if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
1284 1284
   // The timeout (in ms) to return to the status screen from sub-menus
1285 1285
   //#define LCD_TIMEOUT_TO_STATUS 15000
1286 1286
 

+ 0
- 1
Marlin/src/MarlinCore.cpp View File

@@ -1559,7 +1559,6 @@ void setup() {
1559 1559
     HMI_Init();
1560 1560
     HMI_SetLanguageCache();
1561 1561
     HMI_StartFrame(true);
1562
-    DWIN_StatusChanged(GET_TEXT_F(WELCOME_MSG));
1563 1562
   #endif
1564 1563
 
1565 1564
   #if HAS_SERVICE_INTERVALS && !HAS_DWIN_E3V2_BASIC

+ 90
- 21
Marlin/src/lcd/e3v2/enhanced/dwin.cpp View File

@@ -170,6 +170,7 @@ select_t select_page{0}, select_file{0}, select_print{0};
170 170
 uint8_t index_file     = MROWS;
171 171
 
172 172
 bool dwin_abort_flag = false; // Flag to reset feedrate, return to Home
173
+bool hash_changed = true; // Flag to know if message status was changed
173 174
 
174 175
 constexpr float default_max_feedrate[]        = DEFAULT_MAX_FEEDRATE;
175 176
 constexpr float default_max_acceleration[]    = DEFAULT_MAX_ACCELERATION;
@@ -610,6 +611,86 @@ void Popup_window_PauseOrStop() {
610 611
 
611 612
 #endif
612 613
 
614
+// Draw status line
615
+void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text, const bool center = true) {
616
+  DWIN_Draw_Rectangle(1, bgcolor, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
617
+  if (text) {
618
+    if (center) DWINUI::Draw_CenteredString(color, STATUS_Y + 2, text);
619
+    else        DWINUI::Draw_String(color, 0, STATUS_Y + 2, text);
620
+  }
621
+  DWIN_UpdateLCD();
622
+}
623
+void DWIN_DrawStatusLine(const char *text, const bool center = true) {
624
+  DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, text, center);
625
+}
626
+
627
+// Clear & reset status line
628
+void DWIN_ResetStatusLine() {
629
+  ui.status_message[0] = 0;
630
+  DWIN_CheckStatusMessage();
631
+}
632
+
633
+// Djb2 hash algorithm
634
+void DWIN_CheckStatusMessage() {
635
+  static uint32_t old_hash = 0;
636
+  char * str = &ui.status_message[0];
637
+  uint32_t hash = 5381;
638
+  char c;
639
+  while ((c = *str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
640
+  hash_changed = hash != old_hash;
641
+  old_hash = hash;
642
+};
643
+
644
+void DWIN_DrawStatusMessage() {
645
+  const uint8_t max_status_chars = DWIN_WIDTH / DWINUI::fontWidth(DWINUI::font);
646
+
647
+  #if ENABLED(STATUS_MESSAGE_SCROLLING)
648
+
649
+    // Get the UTF8 character count of the string
650
+    uint8_t slen = utf8_strlen(ui.status_message);
651
+
652
+    // If the string fits the status line do not scroll it
653
+    if (slen <= max_status_chars) {
654
+       if (hash_changed) {
655
+         DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, ui.status_message);
656
+         hash_changed = false;
657
+       }
658
+    }
659
+    else {
660
+      // String is larger than the available line space
661
+
662
+      // Get a pointer to the next valid UTF8 character
663
+      // and the string remaining length
664
+      uint8_t rlen;
665
+      const char *stat = MarlinUI::status_and_len(rlen);
666
+      DWIN_Draw_Rectangle(1, HMI_data.StatusBg_Color, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
667
+      DWINUI::MoveTo(0, STATUS_Y + 2);
668
+      DWINUI::Draw_String(stat, max_status_chars);
669
+
670
+      // If the string doesn't completely fill the line...
671
+      if (rlen < max_status_chars) {
672
+        DWINUI::Draw_Char('.');                   // Always at 1+ spaces left, draw a dot
673
+        uint8_t chars = max_status_chars - rlen;  // Amount of space left in characters
674
+        if (--chars) {                            // Draw a second dot if there's space
675
+          DWINUI::Draw_Char('.');
676
+          if (--chars)
677
+            DWINUI::Draw_String(ui.status_message, chars); // Print a second copy of the message
678
+        }
679
+      }
680
+      MarlinUI::advance_status_scroll();
681
+    }
682
+
683
+  #else
684
+
685
+    if (hash_changed) {
686
+      ui.status_message[max_status_chars] = 0;
687
+      DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, ui.status_message);
688
+      hash_changed = false;
689
+    }
690
+
691
+  #endif
692
+}
693
+
613 694
 void Draw_Print_Labels() {
614 695
   if (HMI_IsChinese()) {
615 696
     Title.FrameCopy(30, 1, 42, 14);                     // "Printing"
@@ -713,7 +794,7 @@ void Draw_Main_Menu() {
713 794
 
714 795
 void Goto_Main_Menu() {
715 796
   checkkey = MainMenu;
716
-  DWIN_StatusChanged();
797
+  ui.reset_status(true);
717 798
   Draw_Main_Menu();
718 799
 }
719 800
 
@@ -1077,6 +1158,7 @@ void Draw_Status_Area(const bool with_update) {
1077 1158
 
1078 1159
 void HMI_StartFrame(const bool with_update) {
1079 1160
   Goto_Main_Menu();
1161
+  DWIN_DrawStatusLine(nullptr);
1080 1162
   Draw_Status_Area(with_update);
1081 1163
 }
1082 1164
 
@@ -1474,7 +1556,7 @@ void DWIN_Update() {
1474 1556
 }
1475 1557
 
1476 1558
 void EachMomentUpdate() {
1477
-  static millis_t next_var_update_ms = 0, next_rts_update_ms = 0;
1559
+  static millis_t next_var_update_ms = 0, next_rts_update_ms = 0, next_status_update_ms = 0;
1478 1560
 
1479 1561
   const millis_t ms = millis();
1480 1562
   if (ELAPSED(ms, next_var_update_ms)) {
@@ -1482,6 +1564,11 @@ void EachMomentUpdate() {
1482 1564
     update_variable();
1483 1565
   }
1484 1566
 
1567
+  if (ELAPSED(ms, next_status_update_ms)) {
1568
+    next_status_update_ms = ms + 500;
1569
+    DWIN_DrawStatusMessage();
1570
+  }
1571
+
1485 1572
   if (PENDING(ms, next_rts_update_ms)) return;
1486 1573
   next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;
1487 1574
 
@@ -1745,7 +1832,7 @@ void Draw_Title(TitleClass* title) {
1745 1832
 void Draw_Menu(MenuClass* menu) {
1746 1833
   DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
1747 1834
   DWIN_Draw_Rectangle(1, DWINUI::backcolor, 0, TITLE_HEIGHT, DWIN_WIDTH - 1, STATUS_Y - 1);
1748
-  ui.set_status("");
1835
+  DWIN_ResetStatusLine();
1749 1836
 }
1750 1837
 
1751 1838
 // Startup routines
@@ -1758,23 +1845,6 @@ void DWIN_Startup() {
1758 1845
   HMI_SetLanguage();
1759 1846
 }
1760 1847
 
1761
-void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char * const text/*=nullptr*/) {
1762
-  DWIN_Draw_Rectangle(1, bgcolor, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
1763
-  if (text) DWINUI::Draw_CenteredString(color, STATUS_Y + 2, text);
1764
-  DWIN_UpdateLCD();
1765
-}
1766
-
1767
-// Update Status line
1768
-void DWIN_StatusChanged(const char * const cstr/*=nullptr*/) {
1769
-  DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, cstr);
1770
-}
1771
-
1772
-void DWIN_StatusChanged(FSTR_P const fstr) {
1773
-  char str[strlen_P(FTOP(fstr)) + 1];
1774
-  strcpy_P(str, FTOP(fstr));
1775
-  DWIN_StatusChanged(str);
1776
-}
1777
-
1778 1848
 // Started a Print Job
1779 1849
 void DWIN_Print_Started(const bool sd) {
1780 1850
   sdprint = card.isPrinting() || sd;
@@ -1866,7 +1936,6 @@ void DWIN_RebootScreen() {
1866 1936
 
1867 1937
 void DWIN_Redraw_screen() {
1868 1938
   Draw_Main_Area();
1869
-  DWIN_StatusChanged(ui.status_message);
1870 1939
   Draw_Status_Area(false);
1871 1940
 }
1872 1941
 

+ 1
- 3
Marlin/src/lcd/e3v2/enhanced/dwin.h View File

@@ -174,9 +174,7 @@ void EachMomentUpdate();
174 174
 void update_variable();
175 175
 void DWIN_HandleScreen();
176 176
 void DWIN_Update();
177
-void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text=nullptr);
178
-void DWIN_StatusChanged(const char * const cstr=nullptr);
179
-void DWIN_StatusChanged(FSTR_P const fstr);
177
+void DWIN_CheckStatusMessage();
180 178
 void DWIN_StartHoming();
181 179
 void DWIN_CompletedHoming();
182 180
 #if HAS_MESH

+ 10
- 9
Marlin/src/lcd/marlinui.cpp View File

@@ -49,6 +49,7 @@ MarlinUI ui;
49 49
 #if ENABLED(DWIN_CREALITY_LCD)
50 50
   #include "e3v2/creality/dwin.h"
51 51
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
52
+  #include "fontutils.h"
52 53
   #include "e3v2/enhanced/dwin.h"
53 54
 #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
54 55
   #include "e3v2/jyersui/dwin.h"
@@ -69,7 +70,7 @@ MarlinUI ui;
69 70
 constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
70 71
 
71 72
 #if HAS_STATUS_MESSAGE
72
-  #if BOTH(HAS_WIRED_LCD, STATUS_MESSAGE_SCROLLING)
73
+  #if ENABLED(STATUS_MESSAGE_SCROLLING) && EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_ENHANCED)
73 74
     uint8_t MarlinUI::status_scroll_offset; // = 0
74 75
   #endif
75 76
   char MarlinUI::status_message[MAX_MESSAGE_LENGTH + 1];
@@ -1481,11 +1482,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
1481 1482
 
1482 1483
   void MarlinUI::finish_status(const bool persist) {
1483 1484
 
1484
-    #if HAS_WIRED_LCD
1485
+    UNUSED(persist);
1485 1486
 
1486
-      #if !(BASIC_PROGRESS_BAR && (PROGRESS_MSG_EXPIRE) > 0)
1487
-        UNUSED(persist);
1488
-      #endif
1487
+    #if HAS_WIRED_LCD
1489 1488
 
1490 1489
       #if BASIC_PROGRESS_BAR || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
1491 1490
         const millis_t ms = millis();
@@ -1502,13 +1501,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
1502 1501
         next_filament_display = ms + 5000UL; // Show status message for 5s
1503 1502
       #endif
1504 1503
 
1505
-      TERN_(STATUS_MESSAGE_SCROLLING, status_scroll_offset = 0);
1506
-    #else // HAS_WIRED_LCD
1507
-      UNUSED(persist);
1504
+    #endif
1505
+
1506
+    #if ENABLED(STATUS_MESSAGE_SCROLLING) && EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_ENHANCED)
1507
+      status_scroll_offset = 0;
1508 1508
     #endif
1509 1509
 
1510 1510
     TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
1511
-    TERN_(HAS_DWIN_E3V2_BASIC, DWIN_StatusChanged(status_message));
1511
+    TERN_(DWIN_CREALITY_LCD, DWIN_StatusChanged(status_message));
1512
+    TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_CheckStatusMessage());
1512 1513
     TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Update_Status(status_message));
1513 1514
   }
1514 1515
 

+ 3
- 4
Marlin/src/lcd/marlinui.h View File

@@ -356,6 +356,9 @@ public:
356 356
 
357 357
   #if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
358 358
     static void kill_screen(FSTR_P const lcd_error, FSTR_P const lcd_component);
359
+    #if DISABLED(LIGHTWEIGHT_UI)
360
+      static void draw_status_message(const bool blink);
361
+    #endif
359 362
   #else
360 363
     static inline void kill_screen(FSTR_P const, FSTR_P const) {}
361 364
   #endif
@@ -444,10 +447,6 @@ public:
444 447
         static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
445 448
       #endif
446 449
 
447
-      #if DISABLED(LIGHTWEIGHT_UI)
448
-        static void draw_status_message(const bool blink);
449
-      #endif
450
-
451 450
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
452 451
         static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
453 452
       #endif

Loading…
Cancel
Save