Merge pull request #8512 from thinkyhead/bf2_debouncer

[2.0.x] General code clean/comment
This commit is contained in:
Scott Lahteine 2017-11-21 17:46:20 -06:00 committed by GitHub
commit 8d0a45f5d4
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 34 deletions

View file

@ -37,10 +37,10 @@ void GcodeSuite::M42() {
if (!parser.seenval('S')) return; if (!parser.seenval('S')) return;
const byte pin_status = parser.value_byte(); const byte pin_status = parser.value_byte();
int pin_number = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN)); const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
if (pin_number < 0) return; if (pin_index < 0) return;
const pin_t pin = GET_PIN_MAP_PIN(pin_number); const pin_t pin = GET_PIN_MAP_PIN(pin_index);
if (pin_is_protected(pin)) { if (pin_is_protected(pin)) {
SERIAL_ERROR_START(); SERIAL_ERROR_START();
SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN); SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);

View file

@ -4590,14 +4590,20 @@ void lcd_update() {
#if ENABLED(ULTIPANEL) #if ENABLED(ULTIPANEL)
static millis_t return_to_status_ms = 0; static millis_t return_to_status_ms = 0;
// Handle any queued Move Axis motion
manage_manual_move(); manage_manual_move();
// Update button states for LCD_CLICKED, etc.
// After state changes the next button update
// may be delayed 300-500ms.
lcd_buttons_update(); lcd_buttons_update();
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel; // Don't run the debouncer if UBL owns the display
#define UBL_CONDITION !ubl.has_control_of_lcd_panel
#else #else
constexpr bool UBL_CONDITION = true; #define UBL_CONDITION true
#endif #endif
// If the action button is pressed... // If the action button is pressed...
@ -4925,7 +4931,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#define encrot3 1 #define encrot3 1
#endif #endif
#define GET_BUTTON_STATES(DST) \ #define GET_SHIFT_BUTTON_STATES(DST) \
uint8_t new_##DST = 0; \ uint8_t new_##DST = 0; \
WRITE(SHIFT_LD, LOW); \ WRITE(SHIFT_LD, LOW); \
WRITE(SHIFT_LD, HIGH); \ WRITE(SHIFT_LD, HIGH); \
@ -4944,7 +4950,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
*/ */
void lcd_buttons_update() { void lcd_buttons_update() {
static uint8_t lastEncoderBits; static uint8_t lastEncoderBits;
millis_t now = millis(); const millis_t now = millis();
if (ELAPSED(now, next_button_update_ms)) { if (ELAPSED(now, next_button_update_ms)) {
#if ENABLED(NEWPANEL) #if ENABLED(NEWPANEL)
@ -4962,9 +4968,16 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
#endif #endif
buttons = newbutton;
#if ENABLED(LCD_HAS_SLOW_BUTTONS)
buttons |= slow_buttons;
#endif
//
// Directional buttons
//
#if LCD_HAS_DIRECTIONAL_BUTTONS #if LCD_HAS_DIRECTIONAL_BUTTONS
// Manage directional buttons
#if ENABLED(REVERSE_MENU_DIRECTION) #if ENABLED(REVERSE_MENU_DIRECTION)
#define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection) #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
#else #else
@ -5008,11 +5021,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#endif // LCD_HAS_DIRECTIONAL_BUTTONS #endif // LCD_HAS_DIRECTIONAL_BUTTONS
buttons = newbutton;
#if ENABLED(LCD_HAS_SLOW_BUTTONS)
buttons |= slow_buttons;
#endif
#if ENABLED(ADC_KEYPAD) #if ENABLED(ADC_KEYPAD)
uint8_t newbutton_reprapworld_keypad = 0; uint8_t newbutton_reprapworld_keypad = 0;
@ -5025,13 +5033,15 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#elif ENABLED(REPRAPWORLD_KEYPAD) #elif ENABLED(REPRAPWORLD_KEYPAD)
GET_BUTTON_STATES(buttons_reprapworld_keypad); GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad);
#endif #endif
#else #else // !NEWPANEL
GET_BUTTON_STATES(buttons);
#endif // !NEWPANEL GET_SHIFT_BUTTON_STATES(buttons);
#endif
} // next_button_update_ms } // next_button_update_ms

View file

@ -119,7 +119,7 @@ extern volatile uint8_t buttons; //an extended version of the last checked butt
#define B_DW (_BV(BL_DW)) #define B_DW (_BV(BL_DW))
#define B_RI (_BV(BL_RI)) #define B_RI (_BV(BL_RI))
#define B_ST (_BV(BL_ST)) #define B_ST (_BV(BL_ST))
#define LCD_CLICKED ((buttons & B_MI) || (buttons & B_ST)) #define LCD_CLICKED (buttons & (B_MI|B_ST))
#endif #endif
#endif // ULTIPANEL #endif // ULTIPANEL

View file

@ -609,43 +609,43 @@ void Endstops::update() {
if (endstop_change) { if (endstop_change) {
#if HAS_X_MIN #if HAS_X_MIN
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN)); if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", TEST(current_endstop_bits_local, X_MIN));
#endif #endif
#if HAS_X_MAX #if HAS_X_MAX
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX)); if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", TEST(current_endstop_bits_local, X_MAX));
#endif #endif
#if HAS_Y_MIN #if HAS_Y_MIN
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN)); if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", TEST(current_endstop_bits_local, Y_MIN));
#endif #endif
#if HAS_Y_MAX #if HAS_Y_MAX
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX)); if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", TEST(current_endstop_bits_local, Y_MAX));
#endif #endif
#if HAS_Z_MIN #if HAS_Z_MIN
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN)); if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", TEST(current_endstop_bits_local, Z_MIN));
#endif #endif
#if HAS_Z_MAX #if HAS_Z_MAX
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX)); if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", TEST(current_endstop_bits_local, Z_MAX));
#endif #endif
#if HAS_Z_MIN_PROBE_PIN #if HAS_Z_MIN_PROBE_PIN
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE)); if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", TEST(current_endstop_bits_local, Z_MIN_PROBE));
#endif #endif
#if HAS_X2_MIN #if HAS_X2_MIN
if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", !!TEST(current_endstop_bits_local, X2_MIN)); if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", TEST(current_endstop_bits_local, X2_MIN));
#endif #endif
#if HAS_X2_MAX #if HAS_X2_MAX
if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", !!TEST(current_endstop_bits_local, X2_MAX)); if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", TEST(current_endstop_bits_local, X2_MAX));
#endif #endif
#if HAS_Y2_MIN #if HAS_Y2_MIN
if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", !!TEST(current_endstop_bits_local, Y2_MIN)); if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", TEST(current_endstop_bits_local, Y2_MIN));
#endif #endif
#if HAS_Y2_MAX #if HAS_Y2_MAX
if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", !!TEST(current_endstop_bits_local, Y2_MAX)); if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", TEST(current_endstop_bits_local, Y2_MAX));
#endif #endif
#if HAS_Z2_MIN #if HAS_Z2_MIN
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN)); if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", TEST(current_endstop_bits_local, Z2_MIN));
#endif #endif
#if HAS_Z2_MAX #if HAS_Z2_MAX
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX)); if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", TEST(current_endstop_bits_local, Z2_MAX));
#endif #endif
SERIAL_PROTOCOLPGM("\n\n"); SERIAL_PROTOCOLPGM("\n\n");
analogWrite(LED_PIN, local_LED_status); analogWrite(LED_PIN, local_LED_status);