Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#define ENCODER_PULSES_PER_STEP 1
#define ENCODER_STEPS_PER_MENU_ITEM 1
#define ENCODER_FEEDRATE_DEADZONE 2
#define REVERSE_MENU_DIRECTION

#elif ENABLED(RADDS_DISPLAY)
#define ULTIPANEL
Expand Down Expand Up @@ -306,7 +305,8 @@
#define HAS_GRAPHICAL_LCD ENABLED(DOGLCD)
#define HAS_CHARACTER_LCD (HAS_SPI_LCD && !HAS_GRAPHICAL_LCD)
#define HAS_LCD_MENU (ENABLED(ULTIPANEL) && DISABLED(NO_LCD_MENUS))
#define HAS_DIGITAL_ENCODER ENABLED(NEWPANEL)
#define HAS_DIGITAL_BUTTONS ENABLED(NEWPANEL)
#define HAS_ENCODER_WHEEL (ENABLED(NEWPANEL) && DISABLED(ADC_KEYPAD))

#if HAS_GRAPHICAL_LCD
/**
Expand Down
85 changes: 41 additions & 44 deletions Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void MarlinUI::init() {

init_lcd();

#if HAS_DIGITAL_ENCODER
#if HAS_DIGITAL_BUTTONS

#if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1);
Expand Down Expand Up @@ -217,7 +217,7 @@ void MarlinUI::init() {
SET_INPUT(BTN_RT);
#endif

#else // !HAS_DIGITAL_ENCODER
#else // !HAS_DIGITAL_BUTTONS

#if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
SET_OUTPUT(SR_DATA_PIN);
Expand All @@ -229,7 +229,7 @@ void MarlinUI::init() {
SET_INPUT_PULLUP(SHIFT_OUT);
#endif // SR_LCD_2W_NL

#endif // !HAS_DIGITAL_ENCODER
#endif // !HAS_DIGITAL_BUTTONS

#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
SET_INPUT_PULLUP(SD_DETECT_PIN);
Expand Down Expand Up @@ -262,7 +262,7 @@ bool MarlinUI::get_blink() {
///////////// Keypad Handling //////////////
////////////////////////////////////////////

#if ENABLED(REPRAPWORLD_KEYPAD)
#if ENABLED(REPRAPWORLD_KEYPAD) && HAS_ENCODER_ACTION

volatile uint8_t MarlinUI::buttons_reprapworld_keypad;

Expand Down Expand Up @@ -295,8 +295,8 @@ bool MarlinUI::get_blink() {
refresh(LCDVIEW_REDRAW_NOW);
if (encoderDirection == -1) { // side effect which signals we are inside a menu
#if HAS_LCD_MENU
if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { MenuItem_back::action(); quick_feedback(); }
else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { return_to_status(); quick_feedback(); }
#endif
Expand Down Expand Up @@ -443,7 +443,7 @@ void MarlinUI::status_screen() {

#endif // HAS_LCD_MENU

#if ENABLED(ULTIPANEL_FEEDMULTIPLY)
#if ENABLED(ULTIPANEL_FEEDMULTIPLY) && HAS_ENCODER_ACTION

const int16_t new_frm = feedrate_percentage + (int32_t)encoderPosition;
// Dead zone at 100% feedrate
Expand Down Expand Up @@ -708,17 +708,12 @@ void MarlinUI::update() {

#if ENABLED(REPRAPWORLD_KEYPAD)

if (
#if ENABLED(ADC_KEYPAD)
handle_keypad()
#else
handle_keypad()
#endif
) {
if (handle_keypad()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! I wonder how I let this one slip by. Zzzzz…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That happens in the late hour

#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
#endif
}

#endif

const float abs_diff = ABS(encoderDiff);
Expand Down Expand Up @@ -923,7 +918,7 @@ void MarlinUI::update() {

#if HAS_ENCODER_ACTION

#if DISABLED(ADC_KEYPAD) && (ENABLED(REPRAPWORLD_KEYPAD) || !HAS_DIGITAL_ENCODER)
#if DISABLED(ADC_KEYPAD) && (ENABLED(REPRAPWORLD_KEYPAD) || !HAS_DIGITAL_BUTTONS)

/**
* Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
Expand All @@ -944,13 +939,6 @@ void MarlinUI::update() {

#endif

#if defined(EN_A) && defined(EN_B)
#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1
#endif

/**
* Read encoder buttons from the hardware registers
* Warning: This function is called from interrupt context!
Expand All @@ -960,7 +948,7 @@ void MarlinUI::update() {
const millis_t now = millis();
if (ELAPSED(now, next_button_update_ms)) {

#if HAS_DIGITAL_ENCODER
#if HAS_DIGITAL_BUTTONS
uint8_t newbutton = 0;

#if BUTTON_EXISTS(EN1)
Expand Down Expand Up @@ -1036,35 +1024,44 @@ void MarlinUI::update() {

#endif

#else // !HAS_DIGITAL_ENCODER
#else // !HAS_DIGITAL_BUTTONS

GET_SHIFT_BUTTON_STATES(buttons);

#endif

} // next_button_update_ms

// Manage encoder rotation
#define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; case _E2: encoderDiff -= encoderDirection; }

uint8_t enc = 0;
if (buttons & EN_A) enc |= B01;
if (buttons & EN_B) enc |= B10;
if (enc != lastEncoderBits) {
switch (enc) {
case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
}
if (external_control) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.encoder_diff = encoderDiff; // Make encoder rotation available to UBL G29 mesh editing.
#endif
encoderDiff = 0; // Hide the encoder event from the current screen handler.
#if HAS_ENCODER_WHEEL

#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1

// Manage encoder rotation
#define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; case _E2: encoderDiff -= encoderDirection; }

uint8_t enc = 0;
if (buttons & EN_A) enc |= B01;
if (buttons & EN_B) enc |= B10;
if (enc != lastEncoderBits) {
switch (enc) {
case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
}
if (external_control) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.encoder_diff = encoderDiff; // Make encoder rotation available to UBL G29 mesh editing.
#endif
encoderDiff = 0; // Hide the encoder event from the current screen handler.
}
lastEncoderBits = enc;
}
lastEncoderBits = enc;
}

#endif // HAS_ENCODER_WHEEL
}

#if ENABLED(LCD_HAS_SLOW_BUTTONS)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

#endif

#if HAS_DIGITAL_ENCODER
#if HAS_DIGITAL_BUTTONS

// Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
#define BLEN_A 0
Expand Down