Mark Langezaal 3 лет назад
Родитель
Сommit
f23393c1ec
Аккаунт пользователя с таким Email не найден
1 измененных файлов: 24 добавлений и 27 удалений
  1. 24
    27
      Marlin/src/lcd/ultralcd.cpp

+ 24
- 27
Marlin/src/lcd/ultralcd.cpp Просмотреть файл

49
   bool MarlinUI::wait_for_move; // = false
49
   bool MarlinUI::wait_for_move; // = false
50
 #endif
50
 #endif
51
 
51
 
52
+constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
53
+
52
 #if HAS_SPI_LCD
54
 #if HAS_SPI_LCD
53
   #if ENABLED(STATUS_MESSAGE_SCROLLING)
55
   #if ENABLED(STATUS_MESSAGE_SCROLLING)
54
     uint8_t MarlinUI::status_scroll_offset; // = 0
56
     uint8_t MarlinUI::status_scroll_offset; // = 0
440
           #endif
442
           #endif
441
           {
443
           {
442
             #if HAS_LCD_MENU
444
             #if HAS_LCD_MENU
443
-                   if (RRK(EN_KEYPAD_UP))     encoderPosition -= ENCODER_PULSES_PER_STEP;
444
-              else if (RRK(EN_KEYPAD_DOWN))   encoderPosition += ENCODER_PULSES_PER_STEP;
445
+                   if (RRK(EN_KEYPAD_UP))     encoderPosition -= epps;
446
+              else if (RRK(EN_KEYPAD_DOWN))   encoderPosition += epps;
445
               else if (RRK(EN_KEYPAD_LEFT))   { MenuItem_back::action(); quick_feedback(); }
447
               else if (RRK(EN_KEYPAD_LEFT))   { MenuItem_back::action(); quick_feedback(); }
446
               else if (RRK(EN_KEYPAD_RIGHT))  encoderPosition = 0;
448
               else if (RRK(EN_KEYPAD_RIGHT))  encoderPosition = 0;
447
             #else
449
             #else
448
-                   if (RRK(EN_KEYPAD_UP)   || RRK(EN_KEYPAD_LEFT))  encoderPosition -= ENCODER_PULSES_PER_STEP;
449
-              else if (RRK(EN_KEYPAD_DOWN) || RRK(EN_KEYPAD_RIGHT)) encoderPosition += ENCODER_PULSES_PER_STEP;
450
+                   if (RRK(EN_KEYPAD_UP)   || RRK(EN_KEYPAD_LEFT))  encoderPosition -= epps;
451
+              else if (RRK(EN_KEYPAD_DOWN) || RRK(EN_KEYPAD_RIGHT)) encoderPosition += epps;
450
             #endif
452
             #endif
451
           }
453
           }
452
         #endif
454
         #endif
841
         RESET_STATUS_TIMEOUT();
843
         RESET_STATUS_TIMEOUT();
842
         if (touch_buttons & (EN_A | EN_B)) {              // Menu arrows, in priority
844
         if (touch_buttons & (EN_A | EN_B)) {              // Menu arrows, in priority
843
           if (ELAPSED(ms, next_button_update_ms)) {
845
           if (ELAPSED(ms, next_button_update_ms)) {
844
-            encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection;
846
+            encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * epps * encoderDirection;
845
             if (touch_buttons & EN_A) encoderDiff *= -1;
847
             if (touch_buttons & EN_A) encoderDiff *= -1;
846
             TERN_(AUTO_BED_LEVELING_UBL, external_encoder());
848
             TERN_(AUTO_BED_LEVELING_UBL, external_encoder());
847
             next_button_update_ms = ms + repeat_delay;    // Assume the repeat delay
849
             next_button_update_ms = ms + repeat_delay;    // Assume the repeat delay
901
       #if ENCODER_PULSES_PER_STEP > 1
903
       #if ENCODER_PULSES_PER_STEP > 1
902
         // When reversing the encoder direction, a movement step can be missed because
904
         // When reversing the encoder direction, a movement step can be missed because
903
         // encoderDiff has a non-zero residual value, making the controller unresponsive.
905
         // encoderDiff has a non-zero residual value, making the controller unresponsive.
904
-        // The fix clears the residual value when the encoder is reversed.
906
+        // The fix clears the residual value when the encoder is idle.
905
         // Also check if past half the threshold to compensate for missed single steps.
907
         // Also check if past half the threshold to compensate for missed single steps.
906
         static int8_t lastEncoderDiff;
908
         static int8_t lastEncoderDiff;
907
-        int8_t prevDiff = lastEncoderDiff;
908
-        lastEncoderDiff = encoderDiff;  // Store before updating encoderDiff to save actual steps
909
-
910
-        // When not past threshold, and reversing... or past half the threshold
911
-        if (WITHIN(abs_diff, 1, (ENCODER_PULSES_PER_STEP) - 1)  // Not past threshold
912
-          && (abs_diff > (ENCODER_PULSES_PER_STEP) / 2          // Passed half the threshold? Done! Call it a full step.
913
-            || (ABS(encoderDiff - prevDiff) >= (ENCODER_PULSES_PER_STEP)  // A big change when abs_diff is small implies reverse
914
-                && ABS(prevDiff) < (ENCODER_PULSES_PER_STEP)    // ...especially when starting from a partial or no step.
915
-               )
916
-             )
917
-        ) {
918
-          abs_diff = ENCODER_PULSES_PER_STEP;
919
-          encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff;  // Treat as full step
909
+
910
+        // Timeout? No decoder change since last check. 10 or 20 times per second.
911
+        if (encoderDiff == lastEncoderDiff && abs_diff <= epps / 2)   // Same direction & size but not over a half-step?
912
+          encoderDiff = 0;                                            // Clear residual pulses.
913
+        else if (WITHIN(abs_diff, epps / 2 + 1, epps - 1)) {          // Past half of threshold?
914
+          abs_diff = epps;                                            // Treat as a full step size
915
+          encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff;        // ...in the spin direction.
920
         }
916
         }
917
+        lastEncoderDiff = encoderDiff;
921
       #endif
918
       #endif
922
 
919
 
923
-      const bool encoderPastThreshold = (abs_diff >= (ENCODER_PULSES_PER_STEP));
920
+      const bool encoderPastThreshold = (abs_diff >= epps);
924
       if (encoderPastThreshold || lcd_clicked) {
921
       if (encoderPastThreshold || lcd_clicked) {
925
         if (encoderPastThreshold) {
922
         if (encoderPastThreshold) {
926
 
923
 
929
             int32_t encoderMultiplier = 1;
926
             int32_t encoderMultiplier = 1;
930
 
927
 
931
             if (encoderRateMultiplierEnabled) {
928
             if (encoderRateMultiplierEnabled) {
932
-              const float encoderMovementSteps = float(abs_diff) / (ENCODER_PULSES_PER_STEP);
929
+              const float encoderMovementSteps = float(abs_diff) / epps;
933
 
930
 
934
               if (lastEncoderMovementMillis) {
931
               if (lastEncoderMovementMillis) {
935
                 // Note that the rate is always calculated between two passes through the
932
                 // Note that the rate is always calculated between two passes through the
958
 
955
 
959
           #endif // ENCODER_RATE_MULTIPLIER
956
           #endif // ENCODER_RATE_MULTIPLIER
960
 
957
 
961
-          encoderPosition += (encoderDiff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
958
+          encoderPosition += (encoderDiff * encoderMultiplier) / epps;
962
           encoderDiff = 0;
959
           encoderDiff = 0;
963
         }
960
         }
964
 
961
 
1191
         //
1188
         //
1192
         #if ANY_BUTTON(UP, DWN, LFT, RT)
1189
         #if ANY_BUTTON(UP, DWN, LFT, RT)
1193
 
1190
 
1194
-          const int8_t pulses = (ENCODER_PULSES_PER_STEP) * encoderDirection;
1191
+          const int8_t pulses = epps * encoderDirection;
1195
 
1192
 
1196
           if (false) {
1193
           if (false) {
1197
             // for the else-ifs below
1194
             // for the else-ifs below
1547
       const int8_t xdir = col < (LCD_WIDTH ) / 2 ? -1 : 1,
1544
       const int8_t xdir = col < (LCD_WIDTH ) / 2 ? -1 : 1,
1548
                    ydir = row < (LCD_HEIGHT) / 2 ? -1 : 1;
1545
                    ydir = row < (LCD_HEIGHT) / 2 ? -1 : 1;
1549
       if (on_edit_screen)
1546
       if (on_edit_screen)
1550
-        encoderDiff = (ENCODER_PULSES_PER_STEP) * ydir;
1547
+        encoderDiff = epps * ydir;
1551
       else if (screen_items > 0) {
1548
       else if (screen_items > 0) {
1552
         // Last 3 cols act as a scroll :-)
1549
         // Last 3 cols act as a scroll :-)
1553
         if (col > (LCD_WIDTH) - 5)
1550
         if (col > (LCD_WIDTH) - 5)
1554
           // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.)
1551
           // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.)
1555
-          encoderDiff = (ENCODER_PULSES_PER_STEP) * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir;
1552
+          encoderDiff = epps * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir;
1556
         else
1553
         else
1557
-          encoderDiff = (ENCODER_PULSES_PER_STEP) * (row - encoderPosition + encoderTopLine);
1554
+          encoderDiff = epps * (row - encoderPosition + encoderTopLine);
1558
       }
1555
       }
1559
       else if (!on_status_screen())
1556
       else if (!on_status_screen())
1560
-        encoderDiff = (ENCODER_PULSES_PER_STEP) * xdir;
1557
+        encoderDiff = epps * xdir;
1561
     }
1558
     }
1562
 
1559
 
1563
   #endif
1560
   #endif

Загрузка…
Отмена
Сохранить