Skip to content

Commit

Permalink
common code
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 16, 2023
1 parent b7eafd0 commit 6568edd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 116 deletions.
7 changes: 5 additions & 2 deletions Marlin/src/lcd/tft/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Touch {

static bool get_point(int16_t *x, int16_t *y);
static void touch(touch_control_t *control);
static void hold(touch_control_t *control, millis_t delay = 0);
static void hold(touch_control_t *control, millis_t delay=0);

public:
static void init();
Expand All @@ -121,7 +121,10 @@ class Touch {
static void sleepTimeout();
static void wakeUp();
#endif
static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data=0);
static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, void (*handler)()) {
add_control(type, x, y, width, height, intptr_t(handler));
}
};

extern Touch touch;
47 changes: 45 additions & 2 deletions Marlin/src/lcd/tft/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,54 @@
void menu_pause_option();

static xy_uint_t cursor;

#if ENABLED(TOUCH_SCREEN)
bool draw_menu_navigation = false;
#endif

void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if ALL(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);
#endif
#endif
}

#if ENABLED(TOUCH_SCREEN)

void do_home() {
quick_feedback();
drawMessage(GET_TEXT_F(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
touch.disable();
TERN_(HAS_EXTRUDERS, drawAxisValue(E_AXIS));
TERN_(HAS_X_AXIS, drawAxisValue(X_AXIS));
TERN_(HAS_Y_AXIS, drawAxisValue(Y_AXIS));
TERN_(HAS_Z_AXIS, drawAxisValue(Z_AXIS));
}

#if HAS_EXTRUDERS
void e_select() {
if (++motionAxisState.e_selection >= EXTRUDERS)
motionAxisState.e_selection = 0;
quick_feedback();
drawCurESelection();
drawAxisValue(E_AXIS);
}
#endif

void step_size() {
motionAxisState.currentStepSize = motionAxisState.currentStepSize / 10.0;
if (motionAxisState.currentStepSize < 0.0015) motionAxisState.currentStepSize = 10.0;
quick_feedback();
drawCurStepValue();
}

#endif

#if HAS_TOUCH_SLEEP

bool lcd_sleep_task() {
Expand All @@ -56,7 +99,7 @@ static xy_uint_t cursor;
return false;
}

#endif
#endif // HAS_TOUCH_SLEEP

void text_line(const uint16_t y, uint16_t color) {
tft.canvas(0, y, TFT_WIDTH, MENU_ITEM_HEIGHT);
Expand Down
19 changes: 16 additions & 3 deletions Marlin/src/lcd/tft/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
#include "tft_font.h"
#include "tft_color.h"

// Common Implementation
void quick_feedback();
#if ENABLED(TOUCH_SCREEN)
void do_home();
#endif
#if HAS_TOUCH_SLEEP
bool lcd_sleep_task();
#endif

void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);

Expand Down Expand Up @@ -75,9 +84,13 @@ inline void add_control(
}
#endif

#if HAS_TOUCH_SLEEP
bool lcd_sleep_task();
#endif
// Custom Implementation
void drawMessage_P(PGM_P const msg);
inline void drawMessage(FSTR_P const fmsg) { drawMessage_P(FTOP(fmsg)); }

void drawAxisValue(const AxisEnum axis);
void drawCurESelection();
void drawCurStepValue();

#define ABSOLUTE_ZERO -273.15

Expand Down
41 changes: 8 additions & 33 deletions Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,8 @@ struct {
#define X_MARGIN 20
#define Y_MARGIN 15

static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if ALL(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);
#endif
#endif
}

#define CUR_STEP_VALUE_WIDTH 104
static void drawCurStepValue() {
void drawCurStepValue() {
tft_string.set(ftostr52sp(motionAxisState.currentStepSize));
tft_string.add(F("mm"));
tft.canvas(motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT);
Expand Down Expand Up @@ -115,7 +104,7 @@ static void drawCurStepValue() {
#endif

#if HAS_EXTRUDERS
static void drawCurESelection() {
void drawCurESelection() {
tft.canvas(motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set('E');
Expand All @@ -124,15 +113,13 @@ static void drawCurStepValue() {
}
#endif

static void drawMessage_P(PGM_P const msg) {
void drawMessage_P(PGM_P const msg) {
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - 34, TFT_HEIGHT / 2, 34);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, COLOR_STATUS_MESSAGE, msg);
}

static void drawMessage(FSTR_P const fmsg) { drawMessage_P(FTOP(fmsg)); }

static void drawAxisValue(const AxisEnum axis) {
void drawAxisValue(const AxisEnum axis) {
const float value = (
TERN_(HAS_BED_PROBE, axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE ? probe.offset.z :)
ui.manual_move.axis_value(axis)
Expand Down Expand Up @@ -273,18 +260,6 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
}
#endif

static void do_home() {
quick_feedback();
drawMessage(GET_TEXT_F(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
touch.disable();
TERN_(HAS_EXTRUDERS, drawAxisValue(E_AXIS));
TERN_(HAS_X_AXIS, drawAxisValue(X_AXIS));
TERN_(HAS_Y_AXIS, drawAxisValue(Y_AXIS));
TERN_(HAS_Z_AXIS, drawAxisValue(Z_AXIS));
}

static void step_size() {
motionAxisState.currentStepSize = motionAxisState.currentStepSize / 10.0;
if (motionAxisState.currentStepSize < 0.0015) motionAxisState.currentStepSize = 10.0;
Expand Down Expand Up @@ -383,7 +358,7 @@ void MarlinUI::move_axis_screen() {
#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(x, y);
drawCurESelection();
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, e_select));
#endif

x += BTN_WIDTH + spacing;
Expand All @@ -393,7 +368,7 @@ void MarlinUI::move_axis_screen() {
x += BTN_WIDTH + spacing;

#if ALL(HAS_X_AXIS, TOUCH_SCREEN)
add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy);
add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, do_home, imgHome, !busy);
#endif

x += BTN_WIDTH + spacing;
Expand All @@ -407,7 +382,7 @@ void MarlinUI::move_axis_screen() {
motionAxisState.zTypePos.set(x, y);
drawCurZSelection();
#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, (intptr_t)z_select);
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, z_select);
#endif
#endif

Expand Down Expand Up @@ -454,7 +429,7 @@ void MarlinUI::move_axis_screen() {
motionAxisState.stepValuePos.set(x, y);
if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, x, y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, x, y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, step_size));
}

// Aligned with x+
Expand Down
51 changes: 13 additions & 38 deletions Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,8 @@ struct {
#define X_MARGIN 15
#define Y_MARGIN 11

static void quick_feedback() {
#if HAS_CHIRP
ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if ALL(HAS_MARLINUI_MENU, HAS_BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
delay(10);
#endif
#endif
}

#define CUR_STEP_VALUE_WIDTH 38
static void drawCurStepValue() {
void drawCurStepValue() {
tft_string.set(ftostr52sp(motionAxisState.currentStepSize));
tft.canvas(motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, 20);
tft.set_background(COLOR_BACKGROUND);
Expand Down Expand Up @@ -121,7 +110,7 @@ static void drawCurStepValue() {
#endif

#if HAS_EXTRUDERS
static void drawCurESelection() {
void drawCurESelection() {
tft.canvas(motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set('E');
Expand All @@ -130,7 +119,7 @@ static void drawCurStepValue() {
}
#endif

static void drawMessage_P(PGM_P const msg) {
void drawMessage_P(PGM_P const msg) {
tft.canvas(X_MARGIN,
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
TFT_HEIGHT - 2 * BTN_HEIGHT, TFT_WIDTH - X_MARGIN
Expand All @@ -143,9 +132,7 @@ static void drawMessage_P(PGM_P const msg) {
tft.add_text(0, 0, COLOR_STATUS_MESSAGE, msg);
}

static void drawMessage(FSTR_P const fmsg) { drawMessage_P(FTOP(fmsg)); }

static void drawAxisValue(const AxisEnum axis) {
void drawAxisValue(const AxisEnum axis) {
const float value = (
TERN_(HAS_BED_PROBE, axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE ? probe.offset.z :)
ui.manual_move.axis_value(axis)
Expand Down Expand Up @@ -248,7 +235,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
#if IS_KINEMATIC
UNUSED(limited);
#else
PGM_P const msg = limited ? GET_TEXT(MSG_LCD_SOFT_ENDSTOPS) : NUL_STR;
FSTR_P const msg = limited ? GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS) : FPSTR(NUL_STR);
drawMessage(msg);
#endif

Expand Down Expand Up @@ -286,18 +273,6 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
}
#endif

static void do_home() {
quick_feedback();
drawMessage(GET_TEXT_F(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
touch.disable();
TERN_(HAS_EXTRUDERS, drawAxisValue(E_AXIS));
TERN_(HAS_X_AXIS, drawAxisValue(X_AXIS));
TERN_(HAS_Y_AXIS, drawAxisValue(Y_AXIS));
TERN_(HAS_Z_AXIS, drawAxisValue(Z_AXIS));
}

static void step_size() {
motionAxisState.currentStepSize = motionAxisState.currentStepSize / 10.0;
if (motionAxisState.currentStepSize < 0.0015) motionAxisState.currentStepSize = 10.0;
Expand Down Expand Up @@ -393,7 +368,7 @@ void MarlinUI::move_axis_screen() {
#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(x, y);
drawCurESelection();
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, e_select));
#endif

#if HAS_Y_AXIS
Expand All @@ -415,12 +390,12 @@ void MarlinUI::move_axis_screen() {

#if HAS_X_AXIS
drawBtn(x, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy);
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, do_home, imgHome, !busy));
drawBtn(zplus_x, y, "X+", (intptr_t)x_plus, imgRight, X_BTN_COLOR, !busy);
#endif

#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, (intptr_t)z_select);
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, z_select);
#endif

/**************************************************************************
Expand Down Expand Up @@ -469,7 +444,7 @@ void MarlinUI::move_axis_screen() {

if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, step_size));
}

// Aligned with x+
Expand Down Expand Up @@ -516,7 +491,7 @@ void MarlinUI::move_axis_screen() {
#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(x, y);
drawCurESelection();
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, e_select));
#endif

x += BTN_WIDTH + spacing;
Expand All @@ -526,7 +501,7 @@ void MarlinUI::move_axis_screen() {
x += BTN_WIDTH + spacing;

#if ALL(HAS_X_AXIS, TOUCH_SCREEN)
add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy);
add_control(TFT_WIDTH / 2 - images[imgHome].width / 2, y - (images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, do_home, imgHome, !busy);
#endif

x += BTN_WIDTH + spacing;
Expand All @@ -540,7 +515,7 @@ void MarlinUI::move_axis_screen() {
motionAxisState.zTypePos.set(x, y);
drawCurZSelection();
#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, (intptr_t)z_select);
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, 34 * 2, z_select);
#endif
#endif

Expand Down Expand Up @@ -587,7 +562,7 @@ void MarlinUI::move_axis_screen() {
motionAxisState.stepValuePos.set(yplus_x + BTN_WIDTH - CUR_STEP_VALUE_WIDTH, y);
if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, step_size));
}

// Aligned with x+
Expand Down
Loading

0 comments on commit 6568edd

Please sign in to comment.