Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» More direct encoder spin
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 16, 2022
1 parent a121c80 commit ac5464c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
7 changes: 0 additions & 7 deletions Marlin/src/lcd/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
#define HAS_SLOW_BUTTONS 1
#endif

#if HAS_ENCODER_WHEEL
#define ENCODER_PHASE_0 0
#define ENCODER_PHASE_1 2
#define ENCODER_PHASE_2 3
#define ENCODER_PHASE_3 1
#endif

#if EITHER(HAS_DIGITAL_BUTTONS, HAS_DWIN_E3V2)
// Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
#define BLEN_A 0
Expand Down
24 changes: 12 additions & 12 deletions Marlin/src/lcd/e3v2/common/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ EncoderState Encoder_ReceiveAnalyze() {
}
if (newbutton != lastEncoderBits) {
switch (newbutton) {
case ENCODER_PHASE_0:
if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
case 0:
if (lastEncoderBits == 1) temp_diff++;
else if (lastEncoderBits == 2) temp_diff--;
break;
case ENCODER_PHASE_1:
if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
case 2:
if (lastEncoderBits == 0) temp_diff++;
else if (lastEncoderBits == 3) temp_diff--;
break;
case ENCODER_PHASE_2:
if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
case 3:
if (lastEncoderBits == 2) temp_diff++;
else if (lastEncoderBits == 1) temp_diff--;
break;
case ENCODER_PHASE_3:
if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
case 1:
if (lastEncoderBits == 3) temp_diff++;
else if (lastEncoderBits == 0) temp_diff--;
break;
}
lastEncoderBits = newbutton;
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,10 @@ void MarlinUI::init() {
if (buttons & EN_B) enc |= B10;
if (enc != lastEncoderBits) {
switch (enc) {
case ENCODER_PHASE_0: ENCODER_SPIN(ENCODER_PHASE_3, ENCODER_PHASE_1); break;
case ENCODER_PHASE_1: ENCODER_SPIN(ENCODER_PHASE_0, ENCODER_PHASE_2); break;
case ENCODER_PHASE_2: ENCODER_SPIN(ENCODER_PHASE_1, ENCODER_PHASE_3); break;
case ENCODER_PHASE_3: ENCODER_SPIN(ENCODER_PHASE_2, ENCODER_PHASE_0); break;
case 0: ENCODER_SPIN(1, 2); break;
case 2: ENCODER_SPIN(0, 3); break;
case 3: ENCODER_SPIN(2, 1); break;
case 1: ENCODER_SPIN(3, 0); break;
}
#if BOTH(HAS_MARLINUI_MENU, AUTO_BED_LEVELING_UBL)
external_encoder();
Expand Down

0 comments on commit ac5464c

Please sign in to comment.