Pārlūkot izejas kodu

Give names to lcdDrawUpdate values

Scott Lahteine 9 gadus atpakaļ
vecāks
revīzija
240b71ee1c
1 mainītis faili ar 63 papildinājumiem un 21 dzēšanām
  1. 63
    21
      Marlin/ultralcd.cpp

+ 63
- 21
Marlin/ultralcd.cpp Parādīt failu

@@ -252,7 +252,7 @@ static void lcd_status_screen();
252 252
   #endif //!ENCODER_RATE_MULTIPLIER
253 253
   #define END_MENU() \
254 254
       if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
255
-      if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
255
+      if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
256 256
       } } while(0)
257 257
 
258 258
   /** Used variables to keep track of the menu */
@@ -280,7 +280,15 @@ uint8_t lcd_status_update_delay;
280 280
 bool ignore_click = false;
281 281
 bool wait_for_unclick;
282 282
 bool defer_return_to_status = false;
283
-uint8_t lcdDrawUpdate = 2;                  /* Set to none-zero when the LCD needs to draw, decreased after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial) */
283
+
284
+enum LCDHandlerAction {
285
+  LCD_DRAW_UPDATE_NONE,
286
+  LCD_DRAW_UPDATE_CALL_REDRAW,
287
+  LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW,
288
+  LCD_DRAW_UPDATE_CALL_NO_REDRAW,
289
+};
290
+
291
+uint8_t lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW; // Set 1 or 2 when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
284 292
 
285 293
 // Variables used when editing values.
286 294
 const char* editLabel;
@@ -298,7 +306,7 @@ float raw_Ki, raw_Kd;
298 306
 static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
299 307
   if (currentMenu != menu) {
300 308
     currentMenu = menu;
301
-    lcdDrawUpdate = 2;
309
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
302 310
     #if ENABLED(NEWPANEL)
303 311
       encoderPosition = encoder;
304 312
       if (feedback) lcd_quick_feedback();
@@ -524,7 +532,7 @@ void lcd_set_home_offsets() {
524 532
     if (encoderPosition != 0) {
525 533
       int distance =  (int)encoderPosition * BABYSTEP_MULTIPLICATOR;
526 534
       encoderPosition = 0;
527
-      lcdDrawUpdate = 1;
535
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
528 536
       #if ENABLED(COREXY) || ENABLED(COREXZ)
529 537
         #if ENABLED(BABYSTEP_XY)
530 538
           switch(axis) {
@@ -948,7 +956,7 @@ static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
948 956
     if (max_software_endstops) NOMORE(current_position[axis], max);
949 957
     encoderPosition = 0;
950 958
     line_to_current(axis);
951
-    lcdDrawUpdate = 1;
959
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
952 960
   }
953 961
   if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
954 962
   if (LCD_CLICKED) lcd_goto_previous_menu();
@@ -977,7 +985,7 @@ static void lcd_move_e(
977 985
     current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
978 986
     encoderPosition = 0;
979 987
     line_to_current(E_AXIS);
980
-    lcdDrawUpdate = 1;
988
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
981 989
   }
982 990
   if (lcdDrawUpdate) {
983 991
     PGM_P pos_label;
@@ -1449,7 +1457,7 @@ static void lcd_control_volumetric_menu() {
1449 1457
         lcd_contrast &= 0x3F;
1450 1458
       #endif
1451 1459
       encoderPosition = 0;
1452
-      lcdDrawUpdate = 1;
1460
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1453 1461
       u8g.setContrast(lcd_contrast);
1454 1462
     }
1455 1463
     if (lcdDrawUpdate) {
@@ -1590,7 +1598,7 @@ static void lcd_control_volumetric_menu() {
1590 1598
   static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
1591 1599
     lcd_save_previous_menu(); \
1592 1600
     \
1593
-    lcdDrawUpdate = 2; \
1601
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW; \
1594 1602
     currentMenu = menu_edit_ ## _name; \
1595 1603
     \
1596 1604
     editLabel = pstr; \
@@ -1672,7 +1680,7 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
1672 1680
 #endif
1673 1681
 
1674 1682
 void lcd_quick_feedback() {
1675
-  lcdDrawUpdate = 2;
1683
+  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1676 1684
   next_button_update_ms = millis() + 500;
1677 1685
 
1678 1686
   #if ENABLED(LCD_USE_I2C_BUZZER)
@@ -1837,11 +1845,27 @@ bool lcd_blink() {
1837 1845
  *   - Act on RepRap World keypad input
1838 1846
  *   - Update the encoder position
1839 1847
  *   - Apply acceleration to the encoder position
1848
+ *   - Set lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW on controller events
1840 1849
  *   - Reset the Info Screen timeout if there's any input
1841 1850
  *   - Update status indicators, if any
1842
- *   - Clear the LCD if lcdDrawUpdate == 2
1843 1851
  *
1844
- * Warning: This function is called from interrupt context!
1852
+ *   Run the current LCD menu handler callback function:
1853
+ *   - Call the handler only if lcdDrawUpdate != LCD_DRAW_UPDATE_NONE
1854
+ *   - Before calling the handler, LCD_DRAW_UPDATE_CALL_NO_REDRAW => LCD_DRAW_UPDATE_NONE
1855
+ *   - Call the menu handler. Menu handlers should do the following:
1856
+ *     - If a value changes, set lcdDrawUpdate to LCD_DRAW_UPDATE_CALL_REDRAW
1857
+ *     - if (lcdDrawUpdate) { redraw }
1858
+ *     - Before exiting the handler set lcdDrawUpdate to:
1859
+ *       - LCD_DRAW_UPDATE_CALL_REDRAW or LCD_DRAW_UPDATE_NONE for no callbacks until the next controller event.
1860
+ *       - LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW to clear screen, LCD_DRAW_UPDATE_CALL_REDRAW on the next loop.
1861
+ *       - LCD_DRAW_UPDATE_CALL_NO_REDRAW for a callback with no forced redraw on the next loop.
1862
+ *     - NOTE: For some displays, the menu handler may be called 2 or more times per loop.
1863
+ *
1864
+ *   After the menu handler callback runs (or not):
1865
+ *   - Clear the LCD if lcdDrawUpdate == LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW
1866
+ *   - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
1867
+ *
1868
+ * No worries. This function is only called from the main thread.
1845 1869
  */
1846 1870
 void lcd_update() {
1847 1871
   #if ENABLED(ULTIPANEL)
@@ -1854,7 +1878,7 @@ void lcd_update() {
1854 1878
 
1855 1879
     bool sd_status = IS_SD_INSERTED;
1856 1880
     if (sd_status != lcd_sd_status && lcd_detected()) {
1857
-      lcdDrawUpdate = 2;
1881
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1858 1882
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
1859 1883
         #if ENABLED(LCD_PROGRESS_BAR)
1860 1884
           currentMenu == lcd_status_screen
@@ -1933,13 +1957,13 @@ void lcd_update() {
1933 1957
           encoderDiff = 0;
1934 1958
         }
1935 1959
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1936
-        lcdDrawUpdate = 1;
1960
+        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1937 1961
       }
1938 1962
     #endif //ULTIPANEL
1939 1963
 
1940 1964
     if (currentMenu == lcd_status_screen) {
1941 1965
       if (!lcd_status_update_delay) {
1942
-        lcdDrawUpdate = 1;
1966
+        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1943 1967
         lcd_status_update_delay = 10;   /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
1944 1968
       }
1945 1969
       else {
@@ -1948,6 +1972,9 @@ void lcd_update() {
1948 1972
     }
1949 1973
 
1950 1974
     if (lcdDrawUpdate) {
1975
+
1976
+      if (lcdDrawUpdate == LCD_DRAW_UPDATE_CALL_NO_REDRAW) lcdDrawUpdate = LCD_DRAW_UPDATE_NONE;
1977
+
1951 1978
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
1952 1979
         bool blink = lcd_blink();
1953 1980
         u8g.firstPage();
@@ -1971,14 +1998,29 @@ void lcd_update() {
1971 1998
     #if ENABLED(ULTIPANEL)
1972 1999
 
1973 2000
       // Return to Status Screen after a timeout
1974
-      if (!defer_return_to_status && currentMenu != lcd_status_screen && millis() > return_to_status_ms) {
2001
+      if (defer_return_to_status)
2002
+        return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
2003
+      else if (currentMenu != lcd_status_screen && millis() > return_to_status_ms) {
1975 2004
         lcd_return_to_status();
1976
-        lcdDrawUpdate = 2;
1977 2005
       }
1978 2006
 
1979 2007
     #endif // ULTIPANEL
1980 2008
 
1981
-    if (lcdDrawUpdate && --lcdDrawUpdate) lcd_implementation_clear();
2009
+    switch (lcdDrawUpdate) {
2010
+      case LCD_DRAW_UPDATE_NONE:
2011
+        // do nothing
2012
+      case LCD_DRAW_UPDATE_CALL_NO_REDRAW:
2013
+        // changes to LCD_DRAW_UPDATE_NONE before call
2014
+        break;
2015
+      case LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW:
2016
+        lcd_implementation_clear();
2017
+        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
2018
+        break;
2019
+      case LCD_DRAW_UPDATE_CALL_REDRAW:
2020
+        lcdDrawUpdate = LCD_DRAW_UPDATE_NONE;
2021
+        break;
2022
+    }
2023
+
1982 2024
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
1983 2025
   }
1984 2026
 }
@@ -1995,7 +2037,7 @@ void lcd_finishstatus(bool persist=false) {
1995 2037
       expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
1996 2038
     #endif
1997 2039
   #endif
1998
-  lcdDrawUpdate = 2;
2040
+  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1999 2041
 
2000 2042
   #if ENABLED(FILAMENT_LCD_DISPLAY)
2001 2043
     previous_lcd_status_ms = millis();  //get status message to show up for a while
@@ -2449,7 +2491,7 @@ char* ftostr52(const float& x) {
2449 2491
       if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
2450 2492
       encoderPosition = 0;
2451 2493
       line_to_current(Z_AXIS);
2452
-      lcdDrawUpdate = 1;
2494
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
2453 2495
     }
2454 2496
     if (lcdDrawUpdate) {
2455 2497
       float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
@@ -2458,7 +2500,7 @@ char* ftostr52(const float& x) {
2458 2500
     static bool debounce_click = false;
2459 2501
     if (LCD_CLICKED) {
2460 2502
       if (!debounce_click) {
2461
-        debounce_click = true;
2503
+        debounce_click = true; // ignore multiple "clicks" in a row
2462 2504
         int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
2463 2505
             iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
2464 2506
         if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
@@ -2489,7 +2531,7 @@ char* ftostr52(const float& x) {
2489 2531
           current_position[X_AXIS] = mbl.get_x(ix);
2490 2532
           current_position[Y_AXIS] = mbl.get_y(iy);
2491 2533
           line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
2492
-          lcdDrawUpdate = 1;
2534
+          lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
2493 2535
         }
2494 2536
       }
2495 2537
     }

Notiek ielāde…
Atcelt
Saglabāt