Fix keypad-related compile error (#12306)

This commit is contained in:
Ludy 2018-11-03 04:29:32 +01:00 committed by Scott Lahteine
parent 2fb2e286ee
commit 5ba6607181
5 changed files with 66 additions and 100 deletions

View File

@ -44,9 +44,9 @@
#elif ENABLED(ZONESTAR_LCD) #elif ENABLED(ZONESTAR_LCD)
#define ADC_KEYPAD
#define REPRAPWORLD_KEYPAD #define REPRAPWORLD_KEYPAD
#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 #define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0
#define ADC_KEYPAD
#define ADC_KEY_NUM 8 #define ADC_KEY_NUM 8
#define ULTIPANEL #define ULTIPANEL

View File

@ -224,26 +224,6 @@ bool lcd_blink() {
volatile uint8_t buttons_reprapworld_keypad; volatile uint8_t buttons_reprapworld_keypad;
#endif #endif
#if ENABLED(REPRAPWORLD_KEYPAD) || ENABLED(ADC_KEYPAD)
#define REPRAPWORLD_BTN_OFFSET 0 // bit offset into buttons for shift register values
#define BLEN_REPRAPWORLD_KEYPAD_F3 0
#define BLEN_REPRAPWORLD_KEYPAD_F2 1
#define BLEN_REPRAPWORLD_KEYPAD_F1 2
#define BLEN_REPRAPWORLD_KEYPAD_DOWN 3
#define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4
#define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5
#define BLEN_REPRAPWORLD_KEYPAD_UP 6
#define BLEN_REPRAPWORLD_KEYPAD_LEFT 7
#define EN_REPRAPWORLD_KEYPAD_DOWN (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_DOWN))
#define EN_REPRAPWORLD_KEYPAD_RIGHT (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_RIGHT))
#define EN_REPRAPWORLD_KEYPAD_MIDDLE (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_MIDDLE))
#define EN_REPRAPWORLD_KEYPAD_UP (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_UP))
#define EN_REPRAPWORLD_KEYPAD_LEFT (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_LEFT))
#endif // REPRAPWORLD_KEYPAD || ADC_KEYPAD
#if ENABLED(ADC_KEYPAD) #if ENABLED(ADC_KEYPAD)
inline bool handle_adc_keypad() { inline bool handle_adc_keypad() {
@ -251,22 +231,15 @@ bool lcd_blink() {
if (buttons_reprapworld_keypad) { if (buttons_reprapworld_keypad) {
lcdDrawUpdate = LCDVIEW_REDRAW_NOW; lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
if (encoderDirection == -1) { // side effect which signals we are inside a menu if (encoderDirection == -1) { // side effect which signals we are inside a menu
if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM; if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_LEFT) { menu_action_back(); lcd_quick_feedback(true); } else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { menu_action_back(); lcd_quick_feedback(true); }
else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) { lcd_return_to_status(); lcd_quick_feedback(true); } else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { lcd_return_to_status(); lcd_quick_feedback(true); }
} }
else { else if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_PULSES_PER_STEP;
if (buttons_reprapworld_keypad & (EN_REPRAPWORLD_KEYPAD_DOWN|EN_REPRAPWORLD_KEYPAD_UP|EN_REPRAPWORLD_KEYPAD_RIGHT)) { else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_PULSES_PER_STEP;
if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition += ENCODER_PULSES_PER_STEP; else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) encoderPosition = 0;
else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition -= ENCODER_PULSES_PER_STEP;
else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) encoderPosition = 0;
}
}
#if ENABLED(ADC_KEYPAD_DEBUG)
SERIAL_PROTOCOLLNPAIR("buttons_reprapworld_keypad = ", (uint32_t)buttons_reprapworld_keypad);
SERIAL_PROTOCOLLNPAIR("encoderPosition = ", (uint32_t)encoderPosition);
#endif
next_button_update_ms = millis() + ADC_MIN_KEY_DELAY; next_button_update_ms = millis() + ADC_MIN_KEY_DELAY;
return true; return true;
} }
@ -276,34 +249,6 @@ bool lcd_blink() {
#elif ENABLED(REPRAPWORLD_KEYPAD) #elif ENABLED(REPRAPWORLD_KEYPAD)
#define KEYPAD_HOME EN_REPRAPWORLD_KEYPAD_F1
#define KEYPAD_EN_C EN_REPRAPWORLD_KEYPAD_MIDDLE
#define EN_REPRAPWORLD_KEYPAD_F1 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F1))
#define EN_REPRAPWORLD_KEYPAD_F2 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F2))
#define EN_REPRAPWORLD_KEYPAD_F3 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F3))
#define REPRAPWORLD_KEYPAD_MOVE_Z_UP (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_F2)
#define REPRAPWORLD_KEYPAD_MOVE_Z_DOWN (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_F3)
#define REPRAPWORLD_KEYPAD_MOVE_Y_DOWN (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN)
#define REPRAPWORLD_KEYPAD_MOVE_X_RIGHT (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT)
#define REPRAPWORLD_KEYPAD_MOVE_Y_UP (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP)
#define REPRAPWORLD_KEYPAD_MOVE_X_LEFT (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_LEFT)
#define REPRAPWORLD_KEYPAD_MOVE_HOME (buttons_reprapworld_keypad & KEYPAD_HOME)
#define REPRAPWORLD_KEYPAD_MOVE_MENU (buttons_reprapworld_keypad & KEYPAD_EN_C)
#define REPRAPWORLD_KEYPAD_PRESSED (buttons_reprapworld_keypad & ( \
EN_REPRAPWORLD_KEYPAD_F1 | \
EN_REPRAPWORLD_KEYPAD_F2 | \
EN_REPRAPWORLD_KEYPAD_F3 | \
EN_REPRAPWORLD_KEYPAD_DOWN | \
EN_REPRAPWORLD_KEYPAD_RIGHT | \
EN_REPRAPWORLD_KEYPAD_MIDDLE | \
EN_REPRAPWORLD_KEYPAD_UP | \
EN_REPRAPWORLD_KEYPAD_LEFT) \
)
void lcd_move_x(); void lcd_move_x();
void lcd_move_y(); void lcd_move_y();
void lcd_move_z(); void lcd_move_z();
@ -318,42 +263,38 @@ bool lcd_blink() {
default: break; default: break;
} }
} }
inline void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
inline void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
inline void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
inline void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
inline void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
inline void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
inline void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
inline void reprapworld_keypad_move_menu() { lcd_goto_screen(menu_move); }
inline void handle_reprapworld_keypad() { inline void handle_reprapworld_keypad() {
static uint8_t keypad_debounce = 0; static uint8_t keypad_debounce = 0;
if (!REPRAPWORLD_KEYPAD_PRESSED) { if (!RRK( EN_REPRAPWORLD_KEYPAD_F1 | EN_REPRAPWORLD_KEYPAD_F2
| EN_REPRAPWORLD_KEYPAD_F3 | EN_REPRAPWORLD_KEYPAD_DOWN
| EN_REPRAPWORLD_KEYPAD_RIGHT | EN_REPRAPWORLD_KEYPAD_MIDDLE
| EN_REPRAPWORLD_KEYPAD_UP | EN_REPRAPWORLD_KEYPAD_LEFT )
) {
if (keypad_debounce > 0) keypad_debounce--; if (keypad_debounce > 0) keypad_debounce--;
} }
else if (!keypad_debounce) { else if (!keypad_debounce) {
keypad_debounce = 2; keypad_debounce = 2;
if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu(); if (RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)) lcd_goto_screen(menu_move);
#if DISABLED(DELTA) && Z_HOME_DIR == -1 #if DISABLED(DELTA) && Z_HOME_DIR == -1
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up(); if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1);
#endif #endif
if (all_axes_homed()) { if (all_axes_homed()) {
#if ENABLED(DELTA) || Z_HOME_DIR != -1 #if ENABLED(DELTA) || Z_HOME_DIR != -1
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up(); if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1);
#endif #endif
if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down(); if (RRK(EN_REPRAPWORLD_KEYPAD_F3)) _reprapworld_keypad_move(Z_AXIS, -1);
if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left(); if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) _reprapworld_keypad_move(X_AXIS, -1);
if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right(); if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) _reprapworld_keypad_move(X_AXIS, 1);
if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down(); if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) _reprapworld_keypad_move(Y_AXIS, 1);
if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up(); if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) _reprapworld_keypad_move(Y_AXIS, -1);
} }
else if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home(); else if (RRK(EN_REPRAPWORLD_KEYPAD_F1)) enqueue_and_echo_commands_P(PSTR("G28"));
} }
} }
@ -1038,22 +979,19 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
static const _stADCKeypadTable_ stADCKeyTable[] PROGMEM = { static const _stADCKeypadTable_ stADCKeyTable[] PROGMEM = {
// VALUE_MIN, VALUE_MAX, KEY // VALUE_MIN, VALUE_MAX, KEY
{ 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F1 + 1 }, // F1 { 4000, 4096, 1 + BLEN_REPRAPWORLD_KEYPAD_F1 }, // F1
{ 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F2 + 1 }, // F2 { 4000, 4096, 1 + BLEN_REPRAPWORLD_KEYPAD_F2 }, // F2
{ 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F3 + 1 }, // F3 { 4000, 4096, 1 + BLEN_REPRAPWORLD_KEYPAD_F3 }, // F3
{ 300, 500, BLEN_REPRAPWORLD_KEYPAD_LEFT + 1 }, // LEFT { 300, 500, 1 + BLEN_REPRAPWORLD_KEYPAD_LEFT }, // LEFT
{ 1900, 2200, BLEN_REPRAPWORLD_KEYPAD_RIGHT + 1 }, // RIGHT { 1900, 2200, 1 + BLEN_REPRAPWORLD_KEYPAD_RIGHT }, // RIGHT
{ 570, 870, BLEN_REPRAPWORLD_KEYPAD_UP + 1 }, // UP { 570, 870, 1 + BLEN_REPRAPWORLD_KEYPAD_UP }, // UP
{ 2670, 2870, BLEN_REPRAPWORLD_KEYPAD_DOWN + 1 }, // DOWN { 2670, 2870, 1 + BLEN_REPRAPWORLD_KEYPAD_DOWN }, // DOWN
{ 1150, 1450, BLEN_REPRAPWORLD_KEYPAD_MIDDLE + 1 }, // ENTER { 1150, 1450, 1 + BLEN_REPRAPWORLD_KEYPAD_MIDDLE }, // ENTER
}; };
uint8_t get_ADC_keyValue(void) { uint8_t get_ADC_keyValue(void) {
if (thermalManager.ADCKey_count >= 16) { if (thermalManager.ADCKey_count >= 16) {
const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2; const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2;
#if ENABLED(ADC_KEYPAD_DEBUG)
SERIAL_PROTOCOLLN(currentkpADCValue);
#endif
thermalManager.current_ADCKey_raw = 0; thermalManager.current_ADCKey_raw = 0;
thermalManager.ADCKey_count = 0; thermalManager.ADCKey_count = 0;
if (currentkpADCValue < 4000) if (currentkpADCValue < 4000)

View File

@ -408,16 +408,43 @@
#endif #endif
#if ENABLED(REPRAPWORLD_KEYPAD) #if ENABLED(REPRAPWORLD_KEYPAD)
#define REPRAPWORLD_BTN_OFFSET 0 // Bit offset into buttons for shift register values
#define BLEN_REPRAPWORLD_KEYPAD_F3 0
#define BLEN_REPRAPWORLD_KEYPAD_F2 1
#define BLEN_REPRAPWORLD_KEYPAD_F1 2
#define BLEN_REPRAPWORLD_KEYPAD_DOWN 3
#define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4
#define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5
#define BLEN_REPRAPWORLD_KEYPAD_UP 6
#define BLEN_REPRAPWORLD_KEYPAD_LEFT 7
#define EN_REPRAPWORLD_KEYPAD_F1 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F1))
#define EN_REPRAPWORLD_KEYPAD_F2 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F2))
#define EN_REPRAPWORLD_KEYPAD_F3 (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_F3))
#define EN_REPRAPWORLD_KEYPAD_DOWN (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_DOWN))
#define EN_REPRAPWORLD_KEYPAD_RIGHT (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_RIGHT))
#define EN_REPRAPWORLD_KEYPAD_MIDDLE (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_MIDDLE))
#define EN_REPRAPWORLD_KEYPAD_UP (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_UP))
#define EN_REPRAPWORLD_KEYPAD_LEFT (_BV(REPRAPWORLD_BTN_OFFSET + BLEN_REPRAPWORLD_KEYPAD_LEFT))
#define RRK(B) (buttons_reprapworld_keypad & (B))
#ifdef EN_C #ifdef EN_C
#define LCD_CLICKED() ((buttons & EN_C) || REPRAPWORLD_KEYPAD_MOVE_MENU) #define LCD_CLICKED() ((buttons & EN_C) || RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE))
#else #else
#define LCD_CLICKED() REPRAPWORLD_KEYPAD_MOVE_MENU #define LCD_CLICKED() RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)
#endif #endif
#elif defined(EN_C)
#endif // REPRAPWORLD_KEYPAD
#ifndef LCD_CLICKED
#ifdef EN_C
#define LCD_CLICKED() (buttons & EN_C) #define LCD_CLICKED() (buttons & EN_C)
#else #else
#define LCD_CLICKED() false #define LCD_CLICKED() false
#endif #endif
#endif
extern uint8_t lcd_status_update_delay; extern uint8_t lcd_status_update_delay;
extern char lcd_status_message[]; extern char lcd_status_message[];

View File

@ -1831,6 +1831,7 @@ void Temperature::isr() {
static uint8_t pwm_count = _BV(SOFT_PWM_SCALE); static uint8_t pwm_count = _BV(SOFT_PWM_SCALE);
// avoid multiple loads of pwm_count // avoid multiple loads of pwm_count
uint8_t pwm_count_tmp = pwm_count; uint8_t pwm_count_tmp = pwm_count;
#if ENABLED(ADC_KEYPAD) #if ENABLED(ADC_KEYPAD)
static unsigned int raw_ADCKey_value = 0; static unsigned int raw_ADCKey_value = 0;
#endif #endif