Browse Source

Scroll static screens more simply

Scott Lahteine 9 years ago
parent
commit
13dc619f43
1 changed files with 25 additions and 19 deletions
  1. 25
    19
      Marlin/ultralcd.cpp

+ 25
- 19
Marlin/ultralcd.cpp View File

214
    * START_SCREEN generates the init code for a screen function
214
    * START_SCREEN generates the init code for a screen function
215
    *
215
    *
216
    *   encoderLine is the position based on the encoder
216
    *   encoderLine is the position based on the encoder
217
-   *   currentMenuViewOffset is the top menu line to display
217
+   *   encoderTopLine is the top menu line to display
218
    *   _drawLineNr is the index of the LCD line (0-3)
218
    *   _drawLineNr is the index of the LCD line (0-3)
219
    *   _lineNr is the menu item to draw and process
219
    *   _lineNr is the menu item to draw and process
220
    *   _menuItemNr is the index of each MENU_ITEM
220
    *   _menuItemNr is the index of each MENU_ITEM
221
    */
221
    */
222
-  #define _START_SCREEN(CODE) do { \
222
+  #define _START_SCREEN(CODE) \
223
     ENCODER_DIRECTION_MENUS(); \
223
     ENCODER_DIRECTION_MENUS(); \
224
     encoderRateMultiplierEnabled = false; \
224
     encoderRateMultiplierEnabled = false; \
225
     if (encoderPosition > 0x8000) encoderPosition = 0; \
225
     if (encoderPosition > 0x8000) encoderPosition = 0; \
226
     uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
226
     uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
227
-    NOMORE(currentMenuViewOffset, encoderLine); \
228
-    uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
227
+    NOMORE(encoderTopLine, encoderLine); \
228
+    uint8_t _lineNr = encoderTopLine, _menuItemNr; \
229
     CODE; \
229
     CODE; \
230
     for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
230
     for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
231
       _menuItemNr = 0;
231
       _menuItemNr = 0;
292
     _menuItemNr++
292
     _menuItemNr++
293
 
293
 
294
   #define END_SCREEN() \
294
   #define END_SCREEN() \
295
-      if (encoderLine >= _menuItemNr) { \
296
-        encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; \
297
-        encoderLine = _menuItemNr - 1; \
298
-      } \
299
-      if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { \
300
-        currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; \
301
-        lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
302
-        _lineNr = currentMenuViewOffset - 1; \
303
-        _drawLineNr = -1; \
304
-      } \
305
-    } } while(0)
295
+    } \
296
+    NOMORE(encoderLine, _menuItemNr - LCD_HEIGHT); \
297
+    NOLESS(encoderLine, 0); \
298
+    encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
299
+    if (encoderTopLine != encoderLine) { \
300
+      encoderTopLine = encoderLine; \
301
+      lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
302
+    }
306
 
303
 
307
-  #define END_MENU() END_SCREEN()
304
+  #define END_MENU() \
305
+    } \
306
+    if (encoderLine >= _menuItemNr) { \
307
+      encoderLine = _menuItemNr - 1; \
308
+      encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
309
+    } \
310
+    if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \
311
+      encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \
312
+      lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
313
+    }
308
 
314
 
309
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
315
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
310
 
316
 
342
   #if ENABLED(LCD_HAS_SLOW_BUTTONS)
348
   #if ENABLED(LCD_HAS_SLOW_BUTTONS)
343
     volatile uint8_t slow_buttons; // Bits of the pressed buttons.
349
     volatile uint8_t slow_buttons; // Bits of the pressed buttons.
344
   #endif
350
   #endif
345
-  uint8_t currentMenuViewOffset;              /* scroll offset in the current menu */
351
+  int8_t encoderTopLine;              /* scroll offset in the current menu */
346
   millis_t next_button_update_ms;
352
   millis_t next_button_update_ms;
347
   uint8_t lastEncoderBits;
353
   uint8_t lastEncoderBits;
348
   uint32_t encoderPosition;
354
   uint32_t encoderPosition;
1888
     #if !PIN_EXISTS(SD_DETECT)
1894
     #if !PIN_EXISTS(SD_DETECT)
1889
       static void lcd_sd_refresh() {
1895
       static void lcd_sd_refresh() {
1890
         card.initsd();
1896
         card.initsd();
1891
-        currentMenuViewOffset = 0;
1897
+        encoderTopLine = 0;
1892
       }
1898
       }
1893
     #endif
1899
     #endif
1894
 
1900
 
1895
     static void lcd_sd_updir() {
1901
     static void lcd_sd_updir() {
1896
       card.updir();
1902
       card.updir();
1897
-      currentMenuViewOffset = 0;
1903
+      encoderTopLine = 0;
1898
     }
1904
     }
1899
 
1905
 
1900
     /**
1906
     /**

Loading…
Cancel
Save