Touch-select MarlinUI menu items (#18239)

This commit is contained in:
Victor 2020-06-11 18:13:52 -03:00 committed by GitHub
parent fe969ec6d3
commit c6f3511d84
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 6 deletions

View file

@ -23,6 +23,12 @@
#include "xpt2046.h"
#include "../../inc/MarlinConfig.h"
#include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
#define BUTTON_AREA_TOP 175
#define BUTTON_AREA_BOT 234
#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * 240 / (LCD_FULL_PIXEL_HEIGHT))
#define TOUCHABLE_Y_HEIGHT (BUTTON_AREA_TOP - (SCREEN_START_TOP))
#ifndef TOUCH_INT_PIN
#define TOUCH_INT_PIN -1
@ -78,13 +84,23 @@ uint8_t XPT2046::read_buttons() {
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
if (y < 175 || y > 234) return 0;
// Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, 14, 77) ? EN_D
: WITHIN(x, 90, 153) ? EN_A
: WITHIN(x, 166, 229) ? EN_B
: WITHIN(x, 242, 305) ? EN_C
: 0;
if (x > LCD_FULL_PIXEL_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0;
// Column and row above BUTTON_AREA_TOP
int8_t col = x * (LCD_WIDTH) / (LCD_FULL_PIXEL_WIDTH),
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
// Send the touch to the UI (which will simulate the encoder wheel)
MarlinUI::screen_click(row, col, x, y);
return 0;
}
bool XPT2046::isTouched() {

View file

@ -1438,6 +1438,29 @@ void MarlinUI::update() {
#endif
#if ENABLED(TOUCH_BUTTONS)
//
// Screen Click
// - On menu screens move directly to the touched item
// - On menu screens, right side (last 3 cols) acts like a scroll - half up => prev page, half down = next page
// - On select screens (and others) touch the Right Half for +, Left Half for -
//
void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y) {
if (screen_items > 0) {
//last 3 cols act as a scroll :-)
if (col > (LCD_WIDTH) - 3)
//2 * LCD_HEIGHT to scroll to bottom of next page. If we did 1 * LCD_HEIGHT, it just go 1 item down
encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * (row < (LCD_HEIGHT) / 2 ? -1 : 1);
else
encoderDiff = ENCODER_PULSES_PER_STEP * (row - encoderPosition + encoderTopLine);
}
else if (!on_status_screen())
encoderDiff = ENCODER_PULSES_PER_STEP * (col < (LCD_WIDTH) / 2 ? -1 : 1);
}
#endif
#else // !HAS_DISPLAY
//

View file

@ -417,6 +417,10 @@ public:
static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
#endif
#if ENABLED(TOUCH_BUTTONS)
static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
#endif
static void status_screen();
#endif