Ver código fonte

Give names to lcdDrawUpdate values

Scott Lahteine 9 anos atrás
pai
commit
240b71ee1c
1 arquivos alterados com 63 adições e 21 exclusões
  1. 63
    21
      Marlin/ultralcd.cpp

+ 63
- 21
Marlin/ultralcd.cpp Ver arquivo

252
   #endif //!ENCODER_RATE_MULTIPLIER
252
   #endif //!ENCODER_RATE_MULTIPLIER
253
   #define END_MENU() \
253
   #define END_MENU() \
254
       if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
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
       } } while(0)
256
       } } while(0)
257
 
257
 
258
   /** Used variables to keep track of the menu */
258
   /** Used variables to keep track of the menu */
280
 bool ignore_click = false;
280
 bool ignore_click = false;
281
 bool wait_for_unclick;
281
 bool wait_for_unclick;
282
 bool defer_return_to_status = false;
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
 // Variables used when editing values.
293
 // Variables used when editing values.
286
 const char* editLabel;
294
 const char* editLabel;
298
 static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
306
 static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
299
   if (currentMenu != menu) {
307
   if (currentMenu != menu) {
300
     currentMenu = menu;
308
     currentMenu = menu;
301
-    lcdDrawUpdate = 2;
309
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
302
     #if ENABLED(NEWPANEL)
310
     #if ENABLED(NEWPANEL)
303
       encoderPosition = encoder;
311
       encoderPosition = encoder;
304
       if (feedback) lcd_quick_feedback();
312
       if (feedback) lcd_quick_feedback();
524
     if (encoderPosition != 0) {
532
     if (encoderPosition != 0) {
525
       int distance =  (int)encoderPosition * BABYSTEP_MULTIPLICATOR;
533
       int distance =  (int)encoderPosition * BABYSTEP_MULTIPLICATOR;
526
       encoderPosition = 0;
534
       encoderPosition = 0;
527
-      lcdDrawUpdate = 1;
535
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
528
       #if ENABLED(COREXY) || ENABLED(COREXZ)
536
       #if ENABLED(COREXY) || ENABLED(COREXZ)
529
         #if ENABLED(BABYSTEP_XY)
537
         #if ENABLED(BABYSTEP_XY)
530
           switch(axis) {
538
           switch(axis) {
948
     if (max_software_endstops) NOMORE(current_position[axis], max);
956
     if (max_software_endstops) NOMORE(current_position[axis], max);
949
     encoderPosition = 0;
957
     encoderPosition = 0;
950
     line_to_current(axis);
958
     line_to_current(axis);
951
-    lcdDrawUpdate = 1;
959
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
952
   }
960
   }
953
   if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
961
   if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
954
   if (LCD_CLICKED) lcd_goto_previous_menu();
962
   if (LCD_CLICKED) lcd_goto_previous_menu();
977
     current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
985
     current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
978
     encoderPosition = 0;
986
     encoderPosition = 0;
979
     line_to_current(E_AXIS);
987
     line_to_current(E_AXIS);
980
-    lcdDrawUpdate = 1;
988
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
981
   }
989
   }
982
   if (lcdDrawUpdate) {
990
   if (lcdDrawUpdate) {
983
     PGM_P pos_label;
991
     PGM_P pos_label;
1449
         lcd_contrast &= 0x3F;
1457
         lcd_contrast &= 0x3F;
1450
       #endif
1458
       #endif
1451
       encoderPosition = 0;
1459
       encoderPosition = 0;
1452
-      lcdDrawUpdate = 1;
1460
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1453
       u8g.setContrast(lcd_contrast);
1461
       u8g.setContrast(lcd_contrast);
1454
     }
1462
     }
1455
     if (lcdDrawUpdate) {
1463
     if (lcdDrawUpdate) {
1590
   static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
1598
   static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
1591
     lcd_save_previous_menu(); \
1599
     lcd_save_previous_menu(); \
1592
     \
1600
     \
1593
-    lcdDrawUpdate = 2; \
1601
+    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW; \
1594
     currentMenu = menu_edit_ ## _name; \
1602
     currentMenu = menu_edit_ ## _name; \
1595
     \
1603
     \
1596
     editLabel = pstr; \
1604
     editLabel = pstr; \
1672
 #endif
1680
 #endif
1673
 
1681
 
1674
 void lcd_quick_feedback() {
1682
 void lcd_quick_feedback() {
1675
-  lcdDrawUpdate = 2;
1683
+  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1676
   next_button_update_ms = millis() + 500;
1684
   next_button_update_ms = millis() + 500;
1677
 
1685
 
1678
   #if ENABLED(LCD_USE_I2C_BUZZER)
1686
   #if ENABLED(LCD_USE_I2C_BUZZER)
1837
  *   - Act on RepRap World keypad input
1845
  *   - Act on RepRap World keypad input
1838
  *   - Update the encoder position
1846
  *   - Update the encoder position
1839
  *   - Apply acceleration to the encoder position
1847
  *   - Apply acceleration to the encoder position
1848
+ *   - Set lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW on controller events
1840
  *   - Reset the Info Screen timeout if there's any input
1849
  *   - Reset the Info Screen timeout if there's any input
1841
  *   - Update status indicators, if any
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
 void lcd_update() {
1870
 void lcd_update() {
1847
   #if ENABLED(ULTIPANEL)
1871
   #if ENABLED(ULTIPANEL)
1854
 
1878
 
1855
     bool sd_status = IS_SD_INSERTED;
1879
     bool sd_status = IS_SD_INSERTED;
1856
     if (sd_status != lcd_sd_status && lcd_detected()) {
1880
     if (sd_status != lcd_sd_status && lcd_detected()) {
1857
-      lcdDrawUpdate = 2;
1881
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1858
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
1882
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
1859
         #if ENABLED(LCD_PROGRESS_BAR)
1883
         #if ENABLED(LCD_PROGRESS_BAR)
1860
           currentMenu == lcd_status_screen
1884
           currentMenu == lcd_status_screen
1933
           encoderDiff = 0;
1957
           encoderDiff = 0;
1934
         }
1958
         }
1935
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1959
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1936
-        lcdDrawUpdate = 1;
1960
+        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1937
       }
1961
       }
1938
     #endif //ULTIPANEL
1962
     #endif //ULTIPANEL
1939
 
1963
 
1940
     if (currentMenu == lcd_status_screen) {
1964
     if (currentMenu == lcd_status_screen) {
1941
       if (!lcd_status_update_delay) {
1965
       if (!lcd_status_update_delay) {
1942
-        lcdDrawUpdate = 1;
1966
+        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1943
         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 */
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
       else {
1969
       else {
1948
     }
1972
     }
1949
 
1973
 
1950
     if (lcdDrawUpdate) {
1974
     if (lcdDrawUpdate) {
1975
+
1976
+      if (lcdDrawUpdate == LCD_DRAW_UPDATE_CALL_NO_REDRAW) lcdDrawUpdate = LCD_DRAW_UPDATE_NONE;
1977
+
1951
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
1978
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
1952
         bool blink = lcd_blink();
1979
         bool blink = lcd_blink();
1953
         u8g.firstPage();
1980
         u8g.firstPage();
1971
     #if ENABLED(ULTIPANEL)
1998
     #if ENABLED(ULTIPANEL)
1972
 
1999
 
1973
       // Return to Status Screen after a timeout
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
         lcd_return_to_status();
2004
         lcd_return_to_status();
1976
-        lcdDrawUpdate = 2;
1977
       }
2005
       }
1978
 
2006
 
1979
     #endif // ULTIPANEL
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
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
2024
     next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
1983
   }
2025
   }
1984
 }
2026
 }
1995
       expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
2037
       expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
1996
     #endif
2038
     #endif
1997
   #endif
2039
   #endif
1998
-  lcdDrawUpdate = 2;
2040
+  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1999
 
2041
 
2000
   #if ENABLED(FILAMENT_LCD_DISPLAY)
2042
   #if ENABLED(FILAMENT_LCD_DISPLAY)
2001
     previous_lcd_status_ms = millis();  //get status message to show up for a while
2043
     previous_lcd_status_ms = millis();  //get status message to show up for a while
2449
       if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
2491
       if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
2450
       encoderPosition = 0;
2492
       encoderPosition = 0;
2451
       line_to_current(Z_AXIS);
2493
       line_to_current(Z_AXIS);
2452
-      lcdDrawUpdate = 1;
2494
+      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
2453
     }
2495
     }
2454
     if (lcdDrawUpdate) {
2496
     if (lcdDrawUpdate) {
2455
       float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
2497
       float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
2458
     static bool debounce_click = false;
2500
     static bool debounce_click = false;
2459
     if (LCD_CLICKED) {
2501
     if (LCD_CLICKED) {
2460
       if (!debounce_click) {
2502
       if (!debounce_click) {
2461
-        debounce_click = true;
2503
+        debounce_click = true; // ignore multiple "clicks" in a row
2462
         int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
2504
         int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
2463
             iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
2505
             iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
2464
         if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
2506
         if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
2489
           current_position[X_AXIS] = mbl.get_x(ix);
2531
           current_position[X_AXIS] = mbl.get_x(ix);
2490
           current_position[Y_AXIS] = mbl.get_y(iy);
2532
           current_position[Y_AXIS] = mbl.get_y(iy);
2491
           line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
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
     }

Carregando…
Cancelar
Salvar