Browse Source

More fine-grained control of LCD redraw

Scott Lahteine 9 years ago
parent
commit
2ae7394640
1 changed files with 60 additions and 57 deletions
  1. 60
    57
      Marlin/ultralcd.cpp

+ 60
- 57
Marlin/ultralcd.cpp View File

249
   #endif //!ENCODER_RATE_MULTIPLIER
249
   #endif //!ENCODER_RATE_MULTIPLIER
250
   #define END_MENU() \
250
   #define END_MENU() \
251
       if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
251
       if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
252
-      if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
252
+      if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
253
       } } while(0)
253
       } } while(0)
254
 
254
 
255
   /** Used variables to keep track of the menu */
255
   /** Used variables to keep track of the menu */
289
 bool wait_for_unclick;
289
 bool wait_for_unclick;
290
 bool defer_return_to_status = false;
290
 bool defer_return_to_status = false;
291
 
291
 
292
-enum LCDHandlerAction {
293
-  LCD_DRAW_UPDATE_NONE,
294
-  LCD_DRAW_UPDATE_CALL_REDRAW,
295
-  LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW,
296
-  LCD_DRAW_UPDATE_CALL_NO_REDRAW
292
+enum LCDViewAction {
293
+  LCDVIEW_NONE,
294
+  LCDVIEW_REDRAW_NOW,
295
+  LCDVIEW_CALL_REDRAW_NEXT,
296
+  LCDVIEW_CLEAR_CALL_REDRAW,
297
+  LCDVIEW_CALL_NO_REDRAW
297
 };
298
 };
298
 
299
 
299
-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)
300
+uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set 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)
300
 
301
 
301
 // Variables used when editing values.
302
 // Variables used when editing values.
302
 const char* editLabel;
303
 const char* editLabel;
314
 static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
315
 static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
315
   if (currentMenu != menu) {
316
   if (currentMenu != menu) {
316
     currentMenu = menu;
317
     currentMenu = menu;
317
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
318
+    lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
318
     #if ENABLED(NEWPANEL)
319
     #if ENABLED(NEWPANEL)
319
       encoderPosition = encoder;
320
       encoderPosition = encoder;
320
       if (feedback) lcd_quick_feedback();
321
       if (feedback) lcd_quick_feedback();
556
     if (encoderPosition) {
557
     if (encoderPosition) {
557
       int distance =  (int32_t)encoderPosition * BABYSTEP_MULTIPLICATOR;
558
       int distance =  (int32_t)encoderPosition * BABYSTEP_MULTIPLICATOR;
558
       encoderPosition = 0;
559
       encoderPosition = 0;
559
-      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
560
+      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
560
       #if ENABLED(COREXY) || ENABLED(COREXZ)
561
       #if ENABLED(COREXY) || ENABLED(COREXZ)
561
         #if ENABLED(BABYSTEP_XY)
562
         #if ENABLED(BABYSTEP_XY)
562
           switch(axis) {
563
           switch(axis) {
894
     // if they call st_synchronize or plan_buffer_line. So
895
     // if they call st_synchronize or plan_buffer_line. So
895
     // while waiting for a move we just ignore new input.
896
     // while waiting for a move we just ignore new input.
896
     if (mbl_wait_for_move) {
897
     if (mbl_wait_for_move) {
897
-      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
898
+      lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
898
       return;
899
       return;
899
     }
900
     }
900
 
901
 
908
       if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
909
       if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
909
       encoderPosition = 0;
910
       encoderPosition = 0;
910
       line_to_current(Z_AXIS);
911
       line_to_current(Z_AXIS);
911
-      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
912
+      lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
912
     }
913
     }
913
 
914
 
914
     // Update on first display, then only on updates to Z position
915
     // Update on first display, then only on updates to Z position
919
 
920
 
920
     // We want subsequent calls, but don't force redraw
921
     // We want subsequent calls, but don't force redraw
921
     // Set here so it can be overridden by lcd_return_to_status below
922
     // Set here so it can be overridden by lcd_return_to_status below
922
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
923
+    lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
923
 
924
 
924
     // Click sets the current Z and moves to the next position
925
     // Click sets the current Z and moves to the next position
925
     static bool debounce_click = false;
926
     static bool debounce_click = false;
970
 
971
 
971
   static void _lcd_level_bed_homing_done() {
972
   static void _lcd_level_bed_homing_done() {
972
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING), NULL);
973
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING), NULL);
973
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
974
+    lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
974
     if (LCD_CLICKED) {
975
     if (LCD_CLICKED) {
975
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
976
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
976
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
977
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
987
    */
988
    */
988
   static void _lcd_level_bed_homing() {
989
   static void _lcd_level_bed_homing() {
989
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
990
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
990
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_NO_REDRAW;
991
+    lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
991
     if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])
992
     if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])
992
       lcd_goto_menu(_lcd_level_bed_homing_done);
993
       lcd_goto_menu(_lcd_level_bed_homing_done);
993
   }
994
   }
1131
     if (max_software_endstops) NOMORE(current_position[axis], max);
1132
     if (max_software_endstops) NOMORE(current_position[axis], max);
1132
     encoderPosition = 0;
1133
     encoderPosition = 0;
1133
     line_to_current(axis);
1134
     line_to_current(axis);
1134
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1135
+    lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1135
   }
1136
   }
1136
   if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
1137
   if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
1137
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1138
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1160
     current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
1161
     current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
1161
     encoderPosition = 0;
1162
     encoderPosition = 0;
1162
     line_to_current(E_AXIS);
1163
     line_to_current(E_AXIS);
1163
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1164
+    lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1164
   }
1165
   }
1165
   if (lcdDrawUpdate) {
1166
   if (lcdDrawUpdate) {
1166
     PGM_P pos_label;
1167
     PGM_P pos_label;
1650
         lcd_contrast &= 0x3F;
1651
         lcd_contrast &= 0x3F;
1651
       #endif
1652
       #endif
1652
       encoderPosition = 0;
1653
       encoderPosition = 0;
1653
-      lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
1654
+      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1654
       u8g.setContrast(lcd_contrast);
1655
       u8g.setContrast(lcd_contrast);
1655
     }
1656
     }
1656
     if (lcdDrawUpdate) {
1657
     if (lcdDrawUpdate) {
1791
   static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
1792
   static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
1792
     lcd_save_previous_menu(); \
1793
     lcd_save_previous_menu(); \
1793
     \
1794
     \
1794
-    lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW; \
1795
+    lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
1795
     \
1796
     \
1796
     editLabel = pstr; \
1797
     editLabel = pstr; \
1797
     editValue = ptr; \
1798
     editValue = ptr; \
1872
 #endif
1873
 #endif
1873
 
1874
 
1874
 void lcd_quick_feedback() {
1875
 void lcd_quick_feedback() {
1875
-  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
1876
+  lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
1876
   next_button_update_ms = millis() + 500;
1877
   next_button_update_ms = millis() + 500;
1877
 
1878
 
1878
   #if ENABLED(LCD_USE_I2C_BUZZER)
1879
   #if ENABLED(LCD_USE_I2C_BUZZER)
2039
  *   - Act on RepRap World keypad input
2040
  *   - Act on RepRap World keypad input
2040
  *   - Update the encoder position
2041
  *   - Update the encoder position
2041
  *   - Apply acceleration to the encoder position
2042
  *   - Apply acceleration to the encoder position
2042
- *   - Set lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW on controller events
2043
+ *   - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT on controller events
2043
  *   - Reset the Info Screen timeout if there's any input
2044
  *   - Reset the Info Screen timeout if there's any input
2044
  *   - Update status indicators, if any
2045
  *   - Update status indicators, if any
2045
  *
2046
  *
2046
  *   Run the current LCD menu handler callback function:
2047
  *   Run the current LCD menu handler callback function:
2047
- *   - Call the handler only if lcdDrawUpdate != LCD_DRAW_UPDATE_NONE
2048
- *   - Before calling the handler, LCD_DRAW_UPDATE_CALL_NO_REDRAW => LCD_DRAW_UPDATE_NONE
2048
+ *   - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
2049
+ *   - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
2049
  *   - Call the menu handler. Menu handlers should do the following:
2050
  *   - Call the menu handler. Menu handlers should do the following:
2050
- *     - If a value changes, set lcdDrawUpdate to LCD_DRAW_UPDATE_CALL_REDRAW
2051
+ *     - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW
2051
  *     - if (lcdDrawUpdate) { redraw }
2052
  *     - if (lcdDrawUpdate) { redraw }
2052
  *     - Before exiting the handler set lcdDrawUpdate to:
2053
  *     - Before exiting the handler set lcdDrawUpdate to:
2053
- *       - LCD_DRAW_UPDATE_CALL_REDRAW or LCD_DRAW_UPDATE_NONE for no callbacks until the next controller event.
2054
- *       - LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW to clear screen, LCD_DRAW_UPDATE_CALL_REDRAW on the next loop.
2055
- *       - LCD_DRAW_UPDATE_CALL_NO_REDRAW for a callback with no forced redraw on the next loop.
2054
+ *       - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE for no callbacks until the next controller event.
2055
+ *       - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
2056
+ *       - LCDVIEW_CALL_NO_REDRAW for a callback with no forced redraw on the next loop.
2056
  *     - NOTE: For some displays, the menu handler may be called 2 or more times per loop.
2057
  *     - NOTE: For some displays, the menu handler may be called 2 or more times per loop.
2057
  *
2058
  *
2058
  *   After the menu handler callback runs (or not):
2059
  *   After the menu handler callback runs (or not):
2059
- *   - Clear the LCD if lcdDrawUpdate == LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW
2060
+ *   - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
2060
  *   - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
2061
  *   - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
2061
  *
2062
  *
2062
  * No worries. This function is only called from the main thread.
2063
  * No worries. This function is only called from the main thread.
2072
 
2073
 
2073
     bool sd_status = IS_SD_INSERTED;
2074
     bool sd_status = IS_SD_INSERTED;
2074
     if (sd_status != lcd_sd_status && lcd_detected()) {
2075
     if (sd_status != lcd_sd_status && lcd_detected()) {
2075
-      lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
2076
+      lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
2076
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
2077
       lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
2077
         #if ENABLED(LCD_PROGRESS_BAR)
2078
         #if ENABLED(LCD_PROGRESS_BAR)
2078
           currentMenu == lcd_status_screen
2079
           currentMenu == lcd_status_screen
2096
   millis_t ms = millis();
2097
   millis_t ms = millis();
2097
   if (ELAPSED(ms, next_lcd_update_ms)) {
2098
   if (ELAPSED(ms, next_lcd_update_ms)) {
2098
 
2099
 
2100
+    next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
2101
+
2102
+    #if ENABLED(LCD_HAS_STATUS_INDICATORS)
2103
+      lcd_implementation_update_indicators();
2104
+    #endif
2105
+
2099
     #if ENABLED(LCD_HAS_SLOW_BUTTONS)
2106
     #if ENABLED(LCD_HAS_SLOW_BUTTONS)
2100
       slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
2107
       slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
2101
     #endif
2108
     #endif
2160
           encoderDiff = 0;
2167
           encoderDiff = 0;
2161
         }
2168
         }
2162
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
2169
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
2163
-        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
2170
+        lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2164
       }
2171
       }
2165
     #endif //ULTIPANEL
2172
     #endif //ULTIPANEL
2166
 
2173
 
2167
-    if (currentMenu == lcd_status_screen) {
2168
-      if (!lcd_status_update_delay) {
2169
-        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
2170
-        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 */
2171
-      }
2172
-      else {
2173
-        lcd_status_update_delay--;
2174
-      }
2175
-    }
2174
+    // Simply redraw the Info Screen 10 times a second
2175
+    if (currentMenu == lcd_status_screen && !(++lcd_status_update_delay % 10))
2176
+      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2176
 
2177
 
2177
     if (lcdDrawUpdate) {
2178
     if (lcdDrawUpdate) {
2178
 
2179
 
2179
-      if (lcdDrawUpdate == LCD_DRAW_UPDATE_CALL_NO_REDRAW) lcdDrawUpdate = LCD_DRAW_UPDATE_NONE;
2180
+      switch (lcdDrawUpdate) {
2181
+        case LCDVIEW_CALL_NO_REDRAW:
2182
+          lcdDrawUpdate = LCDVIEW_NONE;
2183
+          break;
2184
+        case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
2185
+        case LCDVIEW_CALL_REDRAW_NEXT:  // set by handlers, then altered after (never occurs here?)
2186
+          lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2187
+        case LCDVIEW_REDRAW_NOW:        // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
2188
+        case LCDVIEW_NONE:
2189
+          break;
2190
+      }
2180
 
2191
 
2181
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
2192
       #if ENABLED(DOGLCD)  // Changes due to different driver architecture of the DOGM display
2182
         bool blink = lcd_blink();
2193
         bool blink = lcd_blink();
2194
       #endif
2205
       #endif
2195
     }
2206
     }
2196
 
2207
 
2197
-    #if ENABLED(LCD_HAS_STATUS_INDICATORS)
2198
-      lcd_implementation_update_indicators();
2199
-    #endif
2200
-
2201
     #if ENABLED(ULTIPANEL)
2208
     #if ENABLED(ULTIPANEL)
2202
 
2209
 
2203
       // Return to Status Screen after a timeout
2210
       // Return to Status Screen after a timeout
2204
-      if (defer_return_to_status)
2211
+      if (currentMenu == lcd_status_screen || defer_return_to_status)
2205
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
2212
         return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
2206
-      else if (currentMenu != lcd_status_screen && ms > return_to_status_ms) {
2213
+      else if (ELAPSED(ms, return_to_status_ms))
2207
         lcd_return_to_status();
2214
         lcd_return_to_status();
2208
-      }
2209
 
2215
 
2210
     #endif // ULTIPANEL
2216
     #endif // ULTIPANEL
2211
 
2217
 
2212
     switch (lcdDrawUpdate) {
2218
     switch (lcdDrawUpdate) {
2213
-      case LCD_DRAW_UPDATE_NONE:
2214
-        // do nothing
2215
-      case LCD_DRAW_UPDATE_CALL_NO_REDRAW:
2216
-        // changes to LCD_DRAW_UPDATE_NONE before call
2217
-        break;
2218
-      case LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW:
2219
+      case LCDVIEW_CLEAR_CALL_REDRAW:
2219
         lcd_implementation_clear();
2220
         lcd_implementation_clear();
2220
-        lcdDrawUpdate = LCD_DRAW_UPDATE_CALL_REDRAW;
2221
+      case LCDVIEW_CALL_REDRAW_NEXT:
2222
+        lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2221
         break;
2223
         break;
2222
-      case LCD_DRAW_UPDATE_CALL_REDRAW:
2223
-        lcdDrawUpdate = LCD_DRAW_UPDATE_NONE;
2224
+      case LCDVIEW_REDRAW_NOW:
2225
+        lcdDrawUpdate = LCDVIEW_NONE;
2226
+        break;
2227
+      case LCDVIEW_NONE:
2224
         break;
2228
         break;
2225
     }
2229
     }
2226
 
2230
 
2227
-    next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
2228
   }
2231
   }
2229
 }
2232
 }
2230
 
2233
 
2244
       expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
2247
       expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
2245
     #endif
2248
     #endif
2246
   #endif
2249
   #endif
2247
-  lcdDrawUpdate = LCD_DRAW_UPDATE_CLEAR_CALL_REDRAW;
2250
+  lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
2248
 
2251
 
2249
   #if ENABLED(FILAMENT_LCD_DISPLAY)
2252
   #if ENABLED(FILAMENT_LCD_DISPLAY)
2250
     previous_lcd_status_ms = millis();  //get status message to show up for a while
2253
     previous_lcd_status_ms = millis();  //get status message to show up for a while

Loading…
Cancel
Save