Move RRW keypad code to a common method (#12429)

This commit is contained in:
Scott Lahteine 2018-11-14 06:00:21 -06:00 committed by GitHub
parent 54ec5528a0
commit f4c128ecaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 83 deletions

View File

@ -235,38 +235,10 @@ bool MarlinUI::get_blink() {
////////////////////////////////////////////
#if ENABLED(REPRAPWORLD_KEYPAD)
volatile uint8_t buttons_reprapworld_keypad;
#endif
#if ENABLED(ADC_KEYPAD)
volatile uint8_t MarlinUI::buttons_reprapworld_keypad;
inline bool handle_adc_keypad() {
#define ADC_MIN_KEY_DELAY 100
if (buttons_reprapworld_keypad) {
#if HAS_ENCODER_ACTION
ui.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;
else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { menu_item_back::action(); ui.quick_feedback(); }
else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { ui.return_to_status(); ui.quick_feedback(); }
#endif
}
else if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_PULSES_PER_STEP;
else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_PULSES_PER_STEP;
else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) encoderPosition = 0;
#endif
next_button_update_ms = millis() + ADC_MIN_KEY_DELAY;
return true;
}
return false;
}
#elif ENABLED(REPRAPWORLD_KEYPAD)
#if HAS_LCD_MENU
#if DISABLED(ADC_KEYPAD) && HAS_LCD_MENU
void lcd_move_x();
void lcd_move_y();
@ -285,7 +257,31 @@ bool MarlinUI::get_blink() {
#endif
inline void handle_reprapworld_keypad() {
bool MarlinUI::handle_keypad() {
#if ENABLED(ADC_KEYPAD)
#define ADC_MIN_KEY_DELAY 100
if (buttons_reprapworld_keypad) {
#if HAS_ENCODER_ACTION
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;
else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { menu_item_back::action(); quick_feedback(); }
else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { return_to_status(); quick_feedback(); }
#endif
}
else if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_PULSES_PER_STEP;
else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_PULSES_PER_STEP;
else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) encoderPosition = 0;
#endif
next_button_update_ms = millis() + ADC_MIN_KEY_DELAY;
return true;
}
#else // !ADC_KEYPAD
static uint8_t keypad_debounce = 0;
@ -303,7 +299,7 @@ bool MarlinUI::get_blink() {
#if HAS_LCD_MENU
if (RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)) ui.goto_screen(menu_move);
if (RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)) goto_screen(menu_move);
#if DISABLED(DELTA) && Z_HOME_DIR == -1
if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1);
@ -323,7 +319,12 @@ bool MarlinUI::get_blink() {
#endif // HAS_LCD_MENU
if (!homed && RRK(EN_REPRAPWORLD_KEYPAD_F1)) enqueue_and_echo_commands_P(PSTR("G28"));
return true;
}
#endif // !ADC_KEYPAD
return false;
}
#endif // REPRAPWORLD_KEYPAD
@ -684,18 +685,19 @@ void MarlinUI::update() {
slow_buttons = read_slow_buttons(); // Buttons that take too long to read in interrupt context
#endif
#if ENABLED(ADC_KEYPAD)
#if ENABLED(REPRAPWORLD_KEYPAD)
if (handle_adc_keypad()) {
if (
#if ENABLED(ADC_KEYPAD)
handle_keypad()
#else
handle_keypad()
#endif
) {
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
#endif
}
#elif ENABLED(REPRAPWORLD_KEYPAD)
handle_reprapworld_keypad();
#endif
const float abs_diff = ABS(encoderDiff);
@ -990,25 +992,26 @@ void MarlinUI::update() {
#endif // LCD_HAS_DIRECTIONAL_BUTTONS
#if ENABLED(ADC_KEYPAD)
buttons = 0;
if (buttons_reprapworld_keypad == 0) {
uint8_t newbutton_reprapworld_keypad = get_ADC_keyValue();
if (WITHIN(newbutton_reprapworld_keypad, 1, 8))
buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1);
}
#else
buttons = newbutton
#if ENABLED(LCD_HAS_SLOW_BUTTONS)
| slow_buttons
#endif
;
#if ENABLED(ADC_KEYPAD)
uint8_t newbutton_reprapworld_keypad = 0;
buttons = 0;
if (buttons_reprapworld_keypad == 0) {
newbutton_reprapworld_keypad = get_ADC_keyValue();
if (WITHIN(newbutton_reprapworld_keypad, 1, 8))
buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1);
}
#elif ENABLED(REPRAPWORLD_KEYPAD)
#if ENABLED(REPRAPWORLD_KEYPAD)
GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad);
#endif
#endif

View File

@ -63,8 +63,6 @@
#endif
#define LCD_UPDATE_INTERVAL 100
#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
#if HAS_LCD_MENU
@ -99,6 +97,9 @@
#define EN_A _BV(BLEN_A)
#define EN_B _BV(BLEN_B)
#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
#if BUTTON_EXISTS(ENC)
#define BLEN_C 2
#define EN_C _BV(BLEN_C)
@ -466,6 +467,10 @@ public:
#if HAS_ENCODER_ACTION
static volatile uint8_t buttons;
#if ENABLED(REPRAPWORLD_KEYPAD)
static volatile uint8_t buttons_reprapworld_keypad;
static bool handle_keypad();
#endif
#if ENABLED(LCD_HAS_SLOW_BUTTONS)
static volatile uint8_t slow_buttons;
static uint8_t read_slow_buttons();

View File

@ -146,7 +146,16 @@ D8 HEATER_BED_PIN CS1 RX4 A12 31 | 46 * * 47 | 34 A15 PWM
#define LCD_PINS_D5 43
#define LCD_PINS_D6 44
#define LCD_PINS_D7 45
#endif
#if ENABLED(NEWPANEL)
#define BTN_EN1 46
#define BTN_EN2 47
#define BTN_ENC 48
#endif
#if ENABLED(REPRAPWORLD_KEYPAD)
#define SHIFT_OUT 40
#define SHIFT_CLK 44
#define SHIFT_LD 42
#endif

View File

@ -74,11 +74,11 @@ exec_test $1 $2 "... Sled Z Probe, Skew, UBL Cartesian moves, Japanese, and Z pr
# ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES
#
restore_configs
opt_enable Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \
opt_enable ZONESTAR_LCD Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \
AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
opt_set NUM_SERVOS 1
opt_enable_adv NO_VOLUMETRICS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET
exec_test $1 $2 "RAMPS with Servo Probe, 3-Point ABL, DEBUG_LEVELING_FEATURE, EEPROM, G38, and more"
exec_test $1 $2 "RAMPS with ZONESTAR_LCD, Servo Probe, 3-Point ABL, DEBUG_LEVELING_FEATURE, EEPROM, G38, and more"
#
# Test MESH_BED_LEVELING feature, with LCD
@ -313,6 +313,7 @@ opt_set Y_DRIVER_TYPE TMC2208
opt_set Z_DRIVER_TYPE TMC2208
opt_set E0_DRIVER_TYPE TMC2208
opt_disable Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
opt_enable REPRAPWORLD_KEYPAD
opt_enable_adv MONITOR_DRIVER_STATUS STEALTHCHOP HYBRID_THRESHOLD TMC_DEBUG
exec_test $1 $2 "TMC2208 Config"
#