diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index b1b15176d..39d84c4bf 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -10,7 +10,6 @@ #include "Configuration.h" #include "pins.h" -#include #include #include "Marlin.h" #include "fastio.h" @@ -635,7 +634,7 @@ uint8_t lcd_draw_update = 2; int16_t lcd_encoder = 0; static int8_t lcd_encoder_diff = 0; -uint8_t lcd_buttons = 0; +uint8_t lcd_click_trigger = 0; uint8_t lcd_update_enabled = 1; static bool lcd_backlight_wake_trigger; // Flag set by interrupt when the knob is pressed or rotated @@ -751,7 +750,6 @@ void lcd_buttons_update(void) { static uint8_t lcd_long_press_active = 0; static uint8_t lcd_button_pressed = 0; - static uint8_t lcd_encoder_bits = 0; if (READ(BTN_ENC) == 0) { //button is pressed if (buttonBlanking.expired_cont(BUTTON_BLANKING_TIME)) { @@ -776,7 +774,7 @@ void lcd_buttons_update(void) lcd_button_pressed = 0; // Reset to prevent double triggering if (!lcd_long_press_active) { //button released before long press gets activated - lcd_buttons |= EN_C; // This flag is reset when the event is consumed + lcd_click_trigger = 1; // This flag is reset when the event is consumed } lcd_backlight_wake_trigger = true; // flag event, knob pressed lcd_long_press_active = 0; @@ -784,24 +782,27 @@ void lcd_buttons_update(void) } //manage encoder rotation - #define ENCODER_SPIN(_E1, _E2) switch (lcd_encoder_bits) { case _E1: lcd_encoder_diff++; break; case _E2: lcd_encoder_diff--; } - uint8_t enc = 0; - if (READ(BTN_EN1) == 0) enc |= B01; - if (READ(BTN_EN2) == 0) enc |= B10; - if (enc != lcd_encoder_bits) + static const int8_t encrot_table[] PROGMEM = { + 0, -1, 1, 2, + 1, 0, 2, -1, + -1, -2, 0, 1, + -2, 1, -1, 0, + }; + + static uint8_t enc_bits_old = 0; + uint8_t enc_bits = 0; + if (!READ(BTN_EN1)) enc_bits |= _BV(0); + if (!READ(BTN_EN2)) enc_bits |= _BV(1); + + if (enc_bits != enc_bits_old) { - 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; - } + int8_t newDiff = pgm_read_byte(&encrot_table[(enc_bits_old << 2) | enc_bits]); + lcd_encoder_diff += newDiff; if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { lcd_backlight_wake_trigger = true; // flag event, knob rotated } - lcd_encoder_bits = enc; + enc_bits_old = enc_bits; } } @@ -810,114 +811,114 @@ void lcd_buttons_update(void) // Custom character data const uint8_t lcd_chardata_bedTemp[8] PROGMEM = { - B00000, - B11111, - B10101, - B10001, - B10101, - B11111, - B00000, - B00000}; //thanks Sonny Mounicou + 0b00000, + 0b11111, + 0b10101, + 0b10001, + 0b10101, + 0b11111, + 0b00000, + 0b00000}; //thanks Sonny Mounicou const uint8_t lcd_chardata_degree[8] PROGMEM = { - B01100, - B10010, - B10010, - B01100, - B00000, - B00000, - B00000, - B00000}; + 0b01100, + 0b10010, + 0b10010, + 0b01100, + 0b00000, + 0b00000, + 0b00000, + 0b00000}; const uint8_t lcd_chardata_thermometer[8] PROGMEM = { - B00100, - B01010, - B01010, - B01010, - B01010, - B10001, - B10001, - B01110}; + 0b00100, + 0b01010, + 0b01010, + 0b01010, + 0b01010, + 0b10001, + 0b10001, + 0b01110}; const uint8_t lcd_chardata_uplevel[8] PROGMEM = { - B00100, - B01110, - B11111, - B00100, - B11100, - B00000, - B00000, - B00000}; //thanks joris + 0b00100, + 0b01110, + 0b11111, + 0b00100, + 0b11100, + 0b00000, + 0b00000, + 0b00000}; //thanks joris const uint8_t lcd_chardata_refresh[8] PROGMEM = { - B00000, - B00110, - B11001, - B11000, - B00011, - B10011, - B01100, - B00000}; //thanks joris + 0b00000, + 0b00110, + 0b11001, + 0b11000, + 0b00011, + 0b10011, + 0b01100, + 0b00000}; //thanks joris const uint8_t lcd_chardata_folder[8] PROGMEM = { - B00000, - B11100, - B11111, - B10001, - B10001, - B11111, - B00000, - B00000}; //thanks joris + 0b00000, + 0b11100, + 0b11111, + 0b10001, + 0b10001, + 0b11111, + 0b00000, + 0b00000}; //thanks joris /*const uint8_t lcd_chardata_feedrate[8] PROGMEM = { - B11100, - B10000, - B11000, - B10111, - B00101, - B00110, - B00101, - B00000};*/ //thanks Sonny Mounicou + 0b11100, + 0b10000, + 0b11000, + 0b10111, + 0b00101, + 0b00110, + 0b00101, + 0b00000};*/ //thanks Sonny Mounicou /*const uint8_t lcd_chardata_feedrate[8] PROGMEM = { - B11100, - B10100, - B11000, - B10100, - B00000, - B00111, - B00010, - B00010};*/ + 0b11100, + 0b10100, + 0b11000, + 0b10100, + 0b00000, + 0b00111, + 0b00010, + 0b00010};*/ /*const uint8_t lcd_chardata_feedrate[8] PROGMEM = { - B01100, - B10011, - B00000, - B01100, - B10011, - B00000, - B01100, - B10011};*/ + 0b01100, + 0b10011, + 0b00000, + 0b01100, + 0b10011, + 0b00000, + 0b01100, + 0b10011};*/ const uint8_t lcd_chardata_feedrate[8] PROGMEM = { - B00000, - B00100, - B10010, - B01001, - B10010, - B00100, - B00000, - B00000}; + 0b00000, + 0b00100, + 0b10010, + 0b01001, + 0b10010, + 0b00100, + 0b00000, + 0b00000}; const uint8_t lcd_chardata_clock[8] PROGMEM = { - B00000, - B01110, - B10011, - B10101, - B10001, - B01110, - B00000, - B00000}; //thanks Sonny Mounicou + 0b00000, + 0b01110, + 0b10011, + 0b10101, + 0b10001, + 0b01110, + 0b00000, + 0b00000}; //thanks Sonny Mounicou void lcd_set_custom_characters(void) { @@ -932,23 +933,24 @@ void lcd_set_custom_characters(void) } const uint8_t lcd_chardata_arr2down[8] PROGMEM = { - B00000, - B00000, - B10001, - B01010, - B00100, - B10001, - B01010, - B00100}; + 0b00000, + 0b00000, + 0b10001, + 0b01010, + 0b00100, + 0b10001, + 0b01010, + 0b00100}; const uint8_t lcd_chardata_confirm[8] PROGMEM = { - B00000, - B00001, - B00011, - B10110, - B11100, - B01000, - B00000}; + 0b00000, + 0b00001, + 0b00011, + 0b10110, + 0b11100, + 0b01000, + 0b00000, + 0b00000}; void lcd_set_custom_characters_nextpage(void) { diff --git a/Firmware/lcd.h b/Firmware/lcd.h index aedfc38d3..2a4682739 100644 --- a/Firmware/lcd.h +++ b/Firmware/lcd.h @@ -100,8 +100,7 @@ extern uint8_t lcd_draw_update; extern int16_t lcd_encoder; -//the last checked lcd_buttons in a bit array. -extern uint8_t lcd_buttons; +extern uint8_t lcd_click_trigger; extern uint8_t lcd_update_enabled; @@ -156,20 +155,7 @@ private: bool m_updateEnabled; }; - //////////////////////////////////// -// Setup button and encode mappings for each panel (into 'lcd_buttons' variable -// -// This is just to map common functions (across different panels) onto the same -// macro name. The mapping is independent of whether the button is directly connected or -// via a shift/i2c register. - -#define BLEN_B 1 -#define BLEN_A 0 -#define EN_B (1<