Kaynağa Gözat

Merge pull request #4512 from thinkyhead/rc_encoder_flex

Improved SCREEN / MENU macros
Scott Lahteine 9 yıl önce
ebeveyn
işleme
52b6b8e36b
1 değiştirilmiş dosya ile 35 ekleme ve 42 silme
  1. 35
    42
      Marlin/ultralcd.cpp

+ 35
- 42
Marlin/ultralcd.cpp Dosyayı Görüntüle

@@ -190,34 +190,54 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
190 190
   #endif
191 191
 
192 192
   /**
193
-   * START_SCREEN generates the init code for a screen function
193
+   * START_SCREEN_OR_MENU generates init code for a screen or menu
194 194
    *
195 195
    *   encoderLine is the position based on the encoder
196 196
    *   encoderTopLine is the top menu line to display
197 197
    *   _lcdLineNr is the index of the LCD line (e.g., 0-3)
198 198
    *   _menuLineNr is the menu item to draw and process
199 199
    *   _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
200
+   *   _countedItems is the total number of items in the menu (after one call)
200 201
    */
201
-  #define _START_SCREEN(CODE, SKIP) \
202
+  #define START_SCREEN_OR_MENU(LIMIT) \
202 203
     ENCODER_DIRECTION_MENUS(); \
203 204
     encoderRateMultiplierEnabled = false; \
204 205
     if (encoderPosition > 0x8000) encoderPosition = 0; \
206
+    static int8_t _countedItems = 0; \
205 207
     int8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
206
-    NOMORE(encoderTopLine, encoderLine); \
208
+    if (_countedItems > 0 && encoderLine >= _countedItems - LIMIT) { \
209
+      encoderLine = _countedItems - LIMIT; \
210
+      encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
211
+    }
212
+
213
+  #define SCREEN_OR_MENU_LOOP() \
207 214
     int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
208
-    bool _skipStatic = SKIP; \
209
-    CODE; \
210 215
     for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
211
-      _thisItemNr = 0;
212
-
213
-  #define START_SCREEN() _START_SCREEN(NOOP, false)
216
+      _thisItemNr = 0
214 217
 
215 218
   /**
216
-   * START_MENU generates the init code for a menu function
219
+   * START_SCREEN  Opening code for a screen having only static items.
220
+   *               Do simplified scrolling of the entire screen.
217 221
    *
218
-   *   wasClicked indicates the controller was clicked
222
+   * START_MENU    Opening code for a screen with menu items.
223
+   *               Scroll as-needed to keep the selected line in view.
224
+   *               'wasClicked' indicates the controller was clicked.
219 225
    */
220
-  #define START_MENU() _START_SCREEN(bool wasClicked = LCD_CLICKED, true)
226
+  #define START_SCREEN() \
227
+    START_SCREEN_OR_MENU(LCD_HEIGHT); \
228
+    encoderTopLine = encoderLine; \
229
+    bool _skipStatic = false; \
230
+    SCREEN_OR_MENU_LOOP()
231
+
232
+  #define START_MENU() \
233
+    START_SCREEN_OR_MENU(1); \
234
+    NOMORE(encoderTopLine, encoderLine); \
235
+    if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \
236
+      encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \
237
+    } \
238
+    bool wasClicked = LCD_CLICKED; \
239
+    bool _skipStatic = true; \
240
+    SCREEN_OR_MENU_LOOP()
221 241
 
222 242
   /**
223 243
    * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
@@ -252,7 +272,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
252 272
         return; \
253 273
       } \
254 274
     } \
255
-    _thisItemNr++
275
+    ++_thisItemNr
256 276
 
257 277
   #define MENU_ITEM(TYPE, LABEL, ARGS...) do { \
258 278
       _skipStatic = false; \
@@ -270,42 +290,15 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
270 290
       if (lcdDrawUpdate) \
271 291
         lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## ARGS); \
272 292
     } \
273
-    _thisItemNr++
274
-
275
-  /**
276
-   *
277
-   * END_SCREEN  Closing code for a screen having only static items.
278
-   *             Do simplified scrolling of the entire screen.
279
-   *
280
-   * END_MENU    Closing code for a screen with menu items.
281
-   *             Scroll as-needed to keep the selected line in view.
282
-   *
283
-   * At this point _thisItemNr equals the total number of items.
284
-   *
285
-   */
293
+    ++_thisItemNr
286 294
 
287
-  // Simple-scroll by using encoderLine as encoderTopLine
288 295
   #define END_SCREEN() \
289 296
     } \
290
-    NOMORE(encoderLine, _thisItemNr - LCD_HEIGHT); \
291
-    NOLESS(encoderLine, 0); \
292
-    encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
293
-    if (encoderTopLine != encoderLine) { \
294
-      encoderTopLine = encoderLine; \
295
-      lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
296
-    }
297
+    _countedItems = _thisItemNr
297 298
 
298
-  // Scroll through menu items, scrolling as-needed to stay in view
299 299
   #define END_MENU() \
300 300
     } \
301
-    if (encoderLine >= _thisItemNr) { \
302
-      encoderLine = _thisItemNr - 1; \
303
-      encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
304
-    } \
305
-    if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \
306
-      encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \
307
-      lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
308
-    } \
301
+    _countedItems = _thisItemNr; \
309 302
     UNUSED(_skipStatic)
310 303
 
311 304
   #if ENABLED(ENCODER_RATE_MULTIPLIER)

Loading…
İptal
Kaydet