Browse Source

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

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

+ 1
- 1
Marlin/Configuration_adv.h View File

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

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

1559
     HMI_Init();
1559
     HMI_Init();
1560
     HMI_SetLanguageCache();
1560
     HMI_SetLanguageCache();
1561
     HMI_StartFrame(true);
1561
     HMI_StartFrame(true);
1562
-    DWIN_StatusChanged(GET_TEXT_F(WELCOME_MSG));
1563
   #endif
1562
   #endif
1564
 
1563
 
1565
   #if HAS_SERVICE_INTERVALS && !HAS_DWIN_E3V2_BASIC
1564
   #if HAS_SERVICE_INTERVALS && !HAS_DWIN_E3V2_BASIC

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

170
 uint8_t index_file     = MROWS;
170
 uint8_t index_file     = MROWS;
171
 
171
 
172
 bool dwin_abort_flag = false; // Flag to reset feedrate, return to Home
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
 constexpr float default_max_feedrate[]        = DEFAULT_MAX_FEEDRATE;
175
 constexpr float default_max_feedrate[]        = DEFAULT_MAX_FEEDRATE;
175
 constexpr float default_max_acceleration[]    = DEFAULT_MAX_ACCELERATION;
176
 constexpr float default_max_acceleration[]    = DEFAULT_MAX_ACCELERATION;
610
 
611
 
611
 #endif
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
 void Draw_Print_Labels() {
694
 void Draw_Print_Labels() {
614
   if (HMI_IsChinese()) {
695
   if (HMI_IsChinese()) {
615
     Title.FrameCopy(30, 1, 42, 14);                     // "Printing"
696
     Title.FrameCopy(30, 1, 42, 14);                     // "Printing"
713
 
794
 
714
 void Goto_Main_Menu() {
795
 void Goto_Main_Menu() {
715
   checkkey = MainMenu;
796
   checkkey = MainMenu;
716
-  DWIN_StatusChanged();
797
+  ui.reset_status(true);
717
   Draw_Main_Menu();
798
   Draw_Main_Menu();
718
 }
799
 }
719
 
800
 
1077
 
1158
 
1078
 void HMI_StartFrame(const bool with_update) {
1159
 void HMI_StartFrame(const bool with_update) {
1079
   Goto_Main_Menu();
1160
   Goto_Main_Menu();
1161
+  DWIN_DrawStatusLine(nullptr);
1080
   Draw_Status_Area(with_update);
1162
   Draw_Status_Area(with_update);
1081
 }
1163
 }
1082
 
1164
 
1474
 }
1556
 }
1475
 
1557
 
1476
 void EachMomentUpdate() {
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
   const millis_t ms = millis();
1561
   const millis_t ms = millis();
1480
   if (ELAPSED(ms, next_var_update_ms)) {
1562
   if (ELAPSED(ms, next_var_update_ms)) {
1482
     update_variable();
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
   if (PENDING(ms, next_rts_update_ms)) return;
1572
   if (PENDING(ms, next_rts_update_ms)) return;
1486
   next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;
1573
   next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;
1487
 
1574
 
1745
 void Draw_Menu(MenuClass* menu) {
1832
 void Draw_Menu(MenuClass* menu) {
1746
   DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
1833
   DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
1747
   DWIN_Draw_Rectangle(1, DWINUI::backcolor, 0, TITLE_HEIGHT, DWIN_WIDTH - 1, STATUS_Y - 1);
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
 // Startup routines
1838
 // Startup routines
1758
   HMI_SetLanguage();
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
 // Started a Print Job
1848
 // Started a Print Job
1779
 void DWIN_Print_Started(const bool sd) {
1849
 void DWIN_Print_Started(const bool sd) {
1780
   sdprint = card.isPrinting() || sd;
1850
   sdprint = card.isPrinting() || sd;
1866
 
1936
 
1867
 void DWIN_Redraw_screen() {
1937
 void DWIN_Redraw_screen() {
1868
   Draw_Main_Area();
1938
   Draw_Main_Area();
1869
-  DWIN_StatusChanged(ui.status_message);
1870
   Draw_Status_Area(false);
1939
   Draw_Status_Area(false);
1871
 }
1940
 }
1872
 
1941
 

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

174
 void update_variable();
174
 void update_variable();
175
 void DWIN_HandleScreen();
175
 void DWIN_HandleScreen();
176
 void DWIN_Update();
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
 void DWIN_StartHoming();
178
 void DWIN_StartHoming();
181
 void DWIN_CompletedHoming();
179
 void DWIN_CompletedHoming();
182
 #if HAS_MESH
180
 #if HAS_MESH

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

49
 #if ENABLED(DWIN_CREALITY_LCD)
49
 #if ENABLED(DWIN_CREALITY_LCD)
50
   #include "e3v2/creality/dwin.h"
50
   #include "e3v2/creality/dwin.h"
51
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
51
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
52
+  #include "fontutils.h"
52
   #include "e3v2/enhanced/dwin.h"
53
   #include "e3v2/enhanced/dwin.h"
53
 #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
54
 #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
54
   #include "e3v2/jyersui/dwin.h"
55
   #include "e3v2/jyersui/dwin.h"
69
 constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
70
 constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
70
 
71
 
71
 #if HAS_STATUS_MESSAGE
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
     uint8_t MarlinUI::status_scroll_offset; // = 0
74
     uint8_t MarlinUI::status_scroll_offset; // = 0
74
   #endif
75
   #endif
75
   char MarlinUI::status_message[MAX_MESSAGE_LENGTH + 1];
76
   char MarlinUI::status_message[MAX_MESSAGE_LENGTH + 1];
1481
 
1482
 
1482
   void MarlinUI::finish_status(const bool persist) {
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
       #if BASIC_PROGRESS_BAR || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
1489
       #if BASIC_PROGRESS_BAR || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
1491
         const millis_t ms = millis();
1490
         const millis_t ms = millis();
1502
         next_filament_display = ms + 5000UL; // Show status message for 5s
1501
         next_filament_display = ms + 5000UL; // Show status message for 5s
1503
       #endif
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
     #endif
1508
     #endif
1509
 
1509
 
1510
     TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
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
     TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Update_Status(status_message));
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
 
356
 
357
   #if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
357
   #if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
358
     static void kill_screen(FSTR_P const lcd_error, FSTR_P const lcd_component);
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
   #else
362
   #else
360
     static inline void kill_screen(FSTR_P const, FSTR_P const) {}
363
     static inline void kill_screen(FSTR_P const, FSTR_P const) {}
361
   #endif
364
   #endif
444
         static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
447
         static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
445
       #endif
448
       #endif
446
 
449
 
447
-      #if DISABLED(LIGHTWEIGHT_UI)
448
-        static void draw_status_message(const bool blink);
449
-      #endif
450
-
451
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
450
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
452
         static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
451
         static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
453
       #endif
452
       #endif

Loading…
Cancel
Save