From f0b87e7952d06473d3c53bf0c92ca1e934c9c58b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 16 Jul 2023 16:50:47 -0500 Subject: [PATCH] common code --- Marlin/src/lcd/tft/touch.h | 7 +- Marlin/src/lcd/tft/ui_1024x600.h | 1 - Marlin/src/lcd/tft/ui_240x320.h | 2 - Marlin/src/lcd/tft/ui_320x240.h | 1 - Marlin/src/lcd/tft/ui_320x480.h | 1 - Marlin/src/lcd/tft/ui_480x272.h | 1 - Marlin/src/lcd/tft/ui_480x320.h | 1 - Marlin/src/lcd/tft/ui_common.cpp | 180 +++++++++++++- Marlin/src/lcd/tft/ui_common.h | 80 +++++- .../src/lcd/tft/ui_move_axis_screen_1024.cpp | 222 +---------------- .../src/lcd/tft/ui_move_axis_screen_320.cpp | 231 ++---------------- .../src/lcd/tft/ui_move_axis_screen_480.cpp | 230 ++--------------- 12 files changed, 297 insertions(+), 660 deletions(-) diff --git a/Marlin/src/lcd/tft/touch.h b/Marlin/src/lcd/tft/touch.h index aef23c2f65bdf..16f51bfaaa312 100644 --- a/Marlin/src/lcd/tft/touch.h +++ b/Marlin/src/lcd/tft/touch.h @@ -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(); @@ -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; diff --git a/Marlin/src/lcd/tft/ui_1024x600.h b/Marlin/src/lcd/tft/ui_1024x600.h index fc7eba73084dd..f6726273d1357 100644 --- a/Marlin/src/lcd/tft/ui_1024x600.h +++ b/Marlin/src/lcd/tft/ui_1024x600.h @@ -92,7 +92,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 80 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 94 diff --git a/Marlin/src/lcd/tft/ui_240x320.h b/Marlin/src/lcd/tft/ui_240x320.h index 4fc8da57e77ab..b7d8a03c2877b 100644 --- a/Marlin/src/lcd/tft/ui_240x320.h +++ b/Marlin/src/lcd/tft/ui_240x320.h @@ -92,7 +92,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 64 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 104 @@ -140,7 +139,6 @@ #define COORDINATES_Y 104 #endif - #if !defined(E_MARK_X) && !defined(E_MARK_Y) && !defined(E_VALUE_X) && !defined(E_VALUE_Y) #define E_MARK_X 10 #define E_MARK_Y VCENTER + FONT_LINE_HEIGHT diff --git a/Marlin/src/lcd/tft/ui_320x240.h b/Marlin/src/lcd/tft/ui_320x240.h index 904ba9c0c38a2..178194e723f49 100644 --- a/Marlin/src/lcd/tft/ui_320x240.h +++ b/Marlin/src/lcd/tft/ui_320x240.h @@ -92,7 +92,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 64 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 60 diff --git a/Marlin/src/lcd/tft/ui_320x480.h b/Marlin/src/lcd/tft/ui_320x480.h index ffedc951af7fe..24223c46fef1d 100644 --- a/Marlin/src/lcd/tft/ui_320x480.h +++ b/Marlin/src/lcd/tft/ui_320x480.h @@ -92,7 +92,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 64 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 139 diff --git a/Marlin/src/lcd/tft/ui_480x272.h b/Marlin/src/lcd/tft/ui_480x272.h index 220b09b3b7c87..83f9e5c21aa42 100644 --- a/Marlin/src/lcd/tft/ui_480x272.h +++ b/Marlin/src/lcd/tft/ui_480x272.h @@ -95,7 +95,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 64 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 62 diff --git a/Marlin/src/lcd/tft/ui_480x320.h b/Marlin/src/lcd/tft/ui_480x320.h index 174abbc98dd21..ef669afcc6620 100644 --- a/Marlin/src/lcd/tft/ui_480x320.h +++ b/Marlin/src/lcd/tft/ui_480x320.h @@ -92,7 +92,6 @@ #define BUTTON_CONFIRM_Y TFT_HEIGHT - 64 #endif - // MarlinUI::draw_kill_screen() #if !defined(KILL_SCREEN_STATUS_Y) && !defined(KILL_SCREEN_HALTED_Y) && !defined(KILL_SCREEN_RESET_Y) #define KILL_SCREEN_STATUS_Y 94 diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index 14e0c81c2a946..09364d846ba6d 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -28,15 +28,166 @@ #include "../lcdprint.h" #include "../../libs/numtostr.h" #include "../menu/menu.h" +#include "../../gcode/queue.h" +#include "../../module/temperature.h" +#include "../../module/planner.h" +#include "../../module/probe.h" -void menu_pause_option(); +#if ENABLED(BABYSTEP_ZPROBE_OFFSET) + #include "../../feature/babystep.h" +#endif +motionAxisState_t motionAxisState; static xy_uint_t cursor; - #if ENABLED(TOUCH_SCREEN) bool draw_menu_navigation = false; #endif +void menu_pause_option(); + +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 +} + +void disable_steppers() { + quick_feedback(); + queue.inject(F("M84")); +} + +void moveAxis(const AxisEnum axis, const int8_t direction) { + quick_feedback(); + + #if HAS_EXTRUDERS + if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) { + drawMessage(F("Too cold")); + return; + } + #endif + + const float diff = motionAxisState.currentStepSize * direction; + + #if HAS_BED_PROBE + + if (axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE) { + #if ENABLED(BABYSTEP_ZPROBE_OFFSET) + const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z; + const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; + const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment, + new_probe_offset = probe.offset.z + bsDiff, + new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET + , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff + , new_probe_offset + ); + if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { + babystep.add_steps(Z_AXIS, babystep_increment); + if (do_probe) + probe.offset.z = new_offs; + else + TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); + drawMessage_P(NUL_STR); // Clear the error + drawAxisValue(axis); + } + else + drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); + + #else + // Only change probe.offset.z + probe.offset.z += diff; + if (direction < 0 && current_position.z < Z_PROBE_OFFSET_RANGE_MIN) { + current_position.z = Z_PROBE_OFFSET_RANGE_MIN; + drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); + } + else if (direction > 0 && current_position.z > Z_PROBE_OFFSET_RANGE_MAX) { + current_position.z = Z_PROBE_OFFSET_RANGE_MAX; + drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); + } + else + drawMessage_P(NUL_STR); // Clear the error + + drawAxisValue(axis); + #endif + } + + #endif // HAS_BED_PROBE + + if (!ui.manual_move.processing) { + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits(axis, min, max); + + // Delta limits XY based on the current offset from center + // This assumes the center is 0,0 + #if ENABLED(DELTA) + if (axis != Z_AXIS && TERN1(HAS_EXTRUDERS, axis != E_AXIS)) { + max = SQRT(sq(float(PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis + min = -max; + } + #endif + + // Get the new position + const bool limited = ui.manual_move.apply_diff(axis, diff, min, max); + #if IS_KINEMATIC + UNUSED(limited); + #else + FSTR_P const msg = limited ? GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS) : FPSTR(NUL_STR); + drawMessage(msg); + #endif + + ui.manual_move.soon(axis OPTARG(MULTI_E_MANUAL, motionAxisState.e_selection)); + } + + drawAxisValue(axis); +} + +#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)); + } + + void step_size() { + motionAxisState.currentStepSize = motionAxisState.currentStepSize / 10.0; + if (motionAxisState.currentStepSize < 0.0015) motionAxisState.currentStepSize = 10.0; + quick_feedback(); + drawCurStepValue(); + } + + #if HAS_EXTRUDERS + void e_select() { + if (++motionAxisState.e_selection >= EXTRUDERS) + motionAxisState.e_selection = 0; + quick_feedback(); + drawCurESelection(); + drawAxisValue(E_AXIS); + } + #endif + + #if HAS_BED_PROBE + void z_select() { + motionAxisState.z_selection *= -1; + quick_feedback(); + drawCurZSelection(); + drawAxisValue(Z_AXIS); + } + #endif + +#endif + #if HAS_TOUCH_SLEEP bool lcd_sleep_task() { @@ -56,7 +207,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); @@ -92,6 +243,29 @@ void add_control(uint16_t x, uint16_t y, TouchControlType control_type, intptr_t #endif } +void drawBtn(const int x, const int y, const char *label, intptr_t data, const MarlinImage btnimg, const MarlinImage img, uint16_t bgColor, const bool enabled) { + const uint16_t width = images[btnimg].width, + height = images[btnimg].height; + + if (!enabled) bgColor = COLOR_CONTROL_DISABLED; + + tft.canvas(x, y, width, height); + tft.set_background(COLOR_BACKGROUND); + tft.add_image(0, 0, btnimg, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); + + // TODO: Make an add_text() taking a font arg + if (label) { + tft_string.set(label); + tft_string.trim(); + tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); + } + else + tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); + + TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data)); +} + + // // lcdprint.h functions // diff --git a/Marlin/src/lcd/tft/ui_common.h b/Marlin/src/lcd/tft/ui_common.h index 8f8c24d170f52..c23a6e2e800f8 100644 --- a/Marlin/src/lcd/tft/ui_common.h +++ b/Marlin/src/lcd/tft/ui_common.h @@ -48,6 +48,67 @@ #include "tft_font.h" #include "tft_color.h" +// Common Implementation +#define Z_SELECTION_Z 1 +#define Z_SELECTION_Z_PROBE -1 + +typedef struct { + #if HAS_X_AXIS + xy_int_t xValuePos; + #endif + #if HAS_Y_AXIS + xy_int_t yValuePos; + #endif + #if HAS_Z_AXIS + xy_int_t zValuePos, zTypePos; + int z_selection = Z_SELECTION_Z; + #endif + #if HAS_EXTRUDERS + xy_int_t eValuePos, eNamePos; + uint8_t e_selection = 0; + #endif + xy_int_t stepValuePos; + float currentStepSize = 10.0; + bool blocked = false; + char message[32]; +} motionAxisState_t; + +extern motionAxisState_t motionAxisState; + +void moveAxis(const AxisEnum axis, const int8_t direction); + +#if HAS_EXTRUDERS + inline void e_plus() { moveAxis(E_AXIS, +1); } + inline void e_minus() { moveAxis(E_AXIS, -1); } +#endif +#if HAS_X_AXIS + inline void x_minus() { moveAxis(X_AXIS, -1); } + inline void x_plus() { moveAxis(X_AXIS, +1); } +#endif +#if HAS_Y_AXIS + inline void y_plus() { moveAxis(Y_AXIS, +1); } + inline void y_minus() { moveAxis(Y_AXIS, -1); } +#endif +#if HAS_Z_AXIS + inline void z_plus() { moveAxis(Z_AXIS, +1); } + inline void z_minus() { moveAxis(Z_AXIS, -1); } +#endif +void quick_feedback(); +void disable_steppers(); +#if ENABLED(TOUCH_SCREEN) + void do_home(); + void step_size(); + #if HAS_BED_PROBE + void z_select(); + #endif + #if HAS_EXTRUDERS + void e_select(); + #endif +#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); @@ -67,6 +128,12 @@ inline void add_control( add_control(x, y, control_type, 0, image, is_enabled, color_enabled, color_disabled); } #if ENABLED(TOUCH_SCREEN) + inline void add_control( + uint16_t x, uint16_t y, TouchControlType control_type, screenFunc_t action, MarlinImage image, bool is_enabled=true, + uint16_t color_enabled=COLOR_CONTROL_ENABLED, uint16_t color_disabled=COLOR_CONTROL_DISABLED + ) { + add_control(x, y, control_type, (intptr_t)action, image, is_enabled, color_enabled, color_disabled); + } inline void add_control( uint16_t x, uint16_t y, screenFunc_t screen, MarlinImage image, bool is_enabled=true, uint16_t color_enabled=COLOR_CONTROL_ENABLED, uint16_t color_disabled=COLOR_CONTROL_DISABLED @@ -75,9 +142,16 @@ inline void add_control( } #endif -#if HAS_TOUCH_SLEEP - bool lcd_sleep_task(); -#endif +void drawBtn(const int x, const int y, const char *label, intptr_t data, const MarlinImage btnimg, const MarlinImage img, uint16_t bgColor, const bool enabled=true); + +// 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 drawCurZSelection(); +void drawCurESelection(); +void drawCurStepValue(); #define ABSOLUTE_ZERO -273.15 diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp index d50493d86cae7..5969f068a9a9b 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp @@ -46,48 +46,13 @@ #include "../../module/probe.h" #endif -#define Z_SELECTION_Z 1 -#define Z_SELECTION_Z_PROBE -1 - -struct { - #if HAS_X_AXIS - xy_int_t xValuePos; - #endif - #if HAS_Y_AXIS - xy_int_t yValuePos; - #endif - #if HAS_Z_AXIS - xy_int_t zValuePos, zTypePos; - int z_selection = Z_SELECTION_Z; - #endif - #if HAS_EXTRUDERS - xy_int_t eValuePos, eNamePos; - uint8_t e_selection = 0; - #endif - xy_int_t stepValuePos; - float currentStepSize = 10.0; - bool blocked = false; - char message[32]; -} motionAxisState; - #define BTN_WIDTH 64 #define BTN_HEIGHT 52 #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); @@ -96,7 +61,7 @@ static void drawCurStepValue() { } #if HAS_Z_AXIS - static void drawCurZSelection() { + void drawCurZSelection() { tft_string.set('Z'); tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), 34); tft.set_background(COLOR_BACKGROUND); @@ -115,7 +80,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'); @@ -124,15 +89,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) @@ -160,173 +123,8 @@ static void drawAxisValue(const AxisEnum axis) { tft.add_text(0, 0, color, tft_string); } -static void moveAxis(const AxisEnum axis, const int8_t direction) { - quick_feedback(); - - #if HAS_EXTRUDERS - if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) { - drawMessage(F("Too cold")); - return; - } - #endif - - const float diff = motionAxisState.currentStepSize * direction; - - #if HAS_BED_PROBE - - if (axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE) { - #if ENABLED(BABYSTEP_ZPROBE_OFFSET) - const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z; - const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; - const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment, - new_probe_offset = probe.offset.z + bsDiff, - new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET - , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff - , new_probe_offset - ); - if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - babystep.add_steps(Z_AXIS, babystep_increment); - if (do_probe) - probe.offset.z = new_offs; - else - TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); - drawMessage(F("")); // Clear the error - drawAxisValue(axis); - } - else - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - - #else - // Only change probe.offset.z - probe.offset.z += diff; - if (direction < 0 && current_position.z < Z_PROBE_OFFSET_RANGE_MIN) { - current_position.z = Z_PROBE_OFFSET_RANGE_MIN; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else if (direction > 0 && current_position.z > Z_PROBE_OFFSET_RANGE_MAX) { - current_position.z = Z_PROBE_OFFSET_RANGE_MAX; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else - drawMessage(F("")); // Clear the error - - drawAxisValue(axis); - #endif - } - - #endif // HAS_BED_PROBE - - if (!ui.manual_move.processing) { - // Get motion limit from software endstops, if any - float min, max; - soft_endstop.get_manual_axis_limits(axis, min, max); - - // Delta limits XY based on the current offset from center - // This assumes the center is 0,0 - #if ENABLED(DELTA) - if (axis != Z_AXIS && TERN1(HAS_EXTRUDERS, axis != E_AXIS)) { - max = SQRT(sq(float(PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis - min = -max; - } - #endif - - // Get the new position - const bool limited = ui.manual_move.apply_diff(axis, diff, min, max); - #if IS_KINEMATIC - UNUSED(limited); - #else - FSTR_P const msg = limited ? GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS) : FPSTR(NUL_STR); - drawMessage(msg); - #endif - - ui.manual_move.soon(axis OPTARG(MULTI_E_MANUAL, motionAxisState.e_selection)); - } - - drawAxisValue(axis); -} - -#if HAS_EXTRUDERS - static void e_plus() { moveAxis(E_AXIS, +1); } - static void e_minus() { moveAxis(E_AXIS, -1); } -#endif -#if HAS_X_AXIS - static void x_minus() { moveAxis(X_AXIS, -1); } - static void x_plus() { moveAxis(X_AXIS, +1); } -#endif -#if HAS_Y_AXIS - static void y_plus() { moveAxis(Y_AXIS, +1); } - static void y_minus() { moveAxis(Y_AXIS, -1); } -#endif -#if HAS_Z_AXIS - static void z_plus() { moveAxis(Z_AXIS, +1); } - static void z_minus() { moveAxis(Z_AXIS, -1); } -#endif - -#if ENABLED(TOUCH_SCREEN) - #if HAS_EXTRUDERS - static void e_select() { - if (++motionAxisState.e_selection >= EXTRUDERS) - motionAxisState.e_selection = 0; - quick_feedback(); - drawCurESelection(); - drawAxisValue(E_AXIS); - } - #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; - quick_feedback(); - drawCurStepValue(); - } -#endif - -#if ALL(HAS_BED_PROBE, TOUCH_SCREEN) - static void z_select() { - motionAxisState.z_selection *= -1; - quick_feedback(); - drawCurZSelection(); - drawAxisValue(Z_AXIS); - } -#endif - -static void disable_steppers() { - quick_feedback(); - queue.inject(F("M84")); -} - static void drawBtn(const int x, const int y, const char *label, intptr_t data, const MarlinImage img, uint16_t bgColor, const bool enabled=true) { - const uint16_t width = images[imgBtn52Rounded].width, - height = images[imgBtn52Rounded].height; - - if (!enabled) bgColor = COLOR_CONTROL_DISABLED; - - tft.canvas(x, y, width, height); - tft.set_background(COLOR_BACKGROUND); - tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - // TODO: Make an add_text() taking a font arg - if (label) { - tft_string.set(label); - tft_string.trim(); - tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); - } - else - tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data)); + drawBtn(x, y, label, data, imgBtn52Rounded, img, bgColor, enabled); } void MarlinUI::move_axis_screen() { @@ -383,7 +181,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; @@ -393,7 +191,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; @@ -407,7 +205,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 @@ -454,7 +252,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+ diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp index 857f0fc0b7d48..5845005ded8f2 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp @@ -46,48 +46,13 @@ #include "../../module/probe.h" #endif -#define Z_SELECTION_Z 1 -#define Z_SELECTION_Z_PROBE -1 - -struct { - #if HAS_X_AXIS - xy_int_t xValuePos; - #endif - #if HAS_Y_AXIS - xy_int_t yValuePos; - #endif - #if HAS_Z_AXIS - xy_int_t zValuePos, zTypePos; - int z_selection = Z_SELECTION_Z; - #endif - #if HAS_EXTRUDERS - xy_int_t eValuePos, eNamePos; - uint8_t e_selection = 0; - #endif - xy_int_t stepValuePos; - float currentStepSize = 10.0; - bool blocked = false; - char message[32]; -} motionAxisState; - #define BTN_WIDTH 48 #define BTN_HEIGHT 39 #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); @@ -102,7 +67,7 @@ static void drawCurStepValue() { } #if HAS_Z_AXIS - static void drawCurZSelection() { + void drawCurZSelection() { tft_string.set('Z'); tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), 20); tft.set_background(COLOR_BACKGROUND); @@ -121,7 +86,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'); @@ -130,7 +95,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 @@ -143,9 +108,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) @@ -173,174 +136,8 @@ static void drawAxisValue(const AxisEnum axis) { tft.add_text(0, 0, color, tft_string); } -static void moveAxis(const AxisEnum axis, const int8_t direction) { - quick_feedback(); - - #if HAS_EXTRUDERS - if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) { - drawMessage(F("Too cold")); - return; - } - #endif - - const float diff = motionAxisState.currentStepSize * direction; - - #if HAS_BED_PROBE - - if (axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE) { - #if ENABLED(BABYSTEP_ZPROBE_OFFSET) - const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z; - const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; - const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment, - new_probe_offset = probe.offset.z + bsDiff, - new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET - , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff - , new_probe_offset - ); - if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - babystep.add_steps(Z_AXIS, babystep_increment); - if (do_probe) - probe.offset.z = new_offs; - else - TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); - drawMessage(NUL_STR); // Clear the error - drawAxisValue(axis); - } - else - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - - #else - // Only change probe.offset.z - probe.offset.z += diff; - if (direction < 0 && current_position.z < Z_PROBE_OFFSET_RANGE_MIN) { - current_position.z = Z_PROBE_OFFSET_RANGE_MIN; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else if (direction > 0 && current_position.z > Z_PROBE_OFFSET_RANGE_MAX) { - current_position.z = Z_PROBE_OFFSET_RANGE_MAX; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else - drawMessage(NUL_STR); // Clear the error - - drawAxisValue(axis); - #endif - } - - #endif // HAS_BED_PROBE - - if (!ui.manual_move.processing) { - // Get motion limit from software endstops, if any - float min, max; - soft_endstop.get_manual_axis_limits(axis, min, max); - - // Delta limits XY based on the current offset from center - // This assumes the center is 0,0 - #if ENABLED(DELTA) - if (axis != Z_AXIS && TERN1(HAS_EXTRUDERS, axis != E_AXIS)) { - max = SQRT(sq(float(PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis - min = -max; - } - #endif - - // Get the new position - const bool limited = ui.manual_move.apply_diff(axis, diff, min, max); - #if IS_KINEMATIC - UNUSED(limited); - #else - PGM_P const msg = limited ? GET_TEXT(MSG_LCD_SOFT_ENDSTOPS) : NUL_STR; - drawMessage(msg); - #endif - - ui.manual_move.soon(axis OPTARG(MULTI_E_MANUAL, motionAxisState.e_selection)); - } - - drawAxisValue(axis); -} - -#if HAS_EXTRUDERS - static void e_plus() { moveAxis(E_AXIS, +1); } - static void e_minus() { moveAxis(E_AXIS, -1); } -#endif -#if HAS_X_AXIS - static void x_minus() { moveAxis(X_AXIS, -1); } - static void x_plus() { moveAxis(X_AXIS, +1); } -#endif -#if HAS_Y_AXIS - static void y_plus() { moveAxis(Y_AXIS, +1); } - static void y_minus() { moveAxis(Y_AXIS, -1); } -#endif -#if HAS_Z_AXIS - static void z_plus() { moveAxis(Z_AXIS, +1); } - static void z_minus() { moveAxis(Z_AXIS, -1); } -#endif - -#if ENABLED(TOUCH_SCREEN) - #if HAS_EXTRUDERS - static void e_select() { - if (++motionAxisState.e_selection >= EXTRUDERS) - motionAxisState.e_selection = 0; - quick_feedback(); - drawCurESelection(); - drawAxisValue(E_AXIS); - } - #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; - quick_feedback(); - drawCurStepValue(); - } - - #if HAS_BED_PROBE - static void z_select() { - motionAxisState.z_selection *= -1; - quick_feedback(); - drawCurZSelection(); - drawAxisValue(Z_AXIS); - } - #endif - -#endif // TOUCH_SCREEN - -static void disable_steppers() { - quick_feedback(); - queue.inject(F("M84")); -} - static void drawBtn(const int x, const int y, const char *label, intptr_t data, const MarlinImage img, uint16_t bgColor, const bool enabled=true) { - const uint16_t width = images[imgBtn39Rounded].width, - height = images[imgBtn39Rounded].height; - - if (!enabled) bgColor = COLOR_CONTROL_DISABLED; - - tft.canvas(x, y, width, height); - tft.set_background(COLOR_BACKGROUND); - tft.add_image(0, 0, imgBtn39Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - // TODO: Make an add_text() taking a font arg - if (label) { - tft_string.set(label); - tft_string.trim(); - tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); - } - else - tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data)); + drawBtn(x, y, label, data, imgBtn39Rounded, img, bgColor, enabled); } void MarlinUI::move_axis_screen() { @@ -393,7 +190,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 @@ -415,12 +212,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 /************************************************************************** @@ -469,7 +266,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+ @@ -516,7 +313,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; @@ -526,7 +323,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; @@ -540,7 +337,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 @@ -587,7 +384,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+ diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp index 1411ce3f92fbb..4ab0ce7b00fa8 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp @@ -52,49 +52,14 @@ #define MOVE_AXIS_MARGIN_SIZE ((TFT_HEIGHT - MOVE_AXIS_TOTAL_ROWS_HEIGHT) / MOVE_AXIS_MARGIN_REGIONS) #endif -#define Z_SELECTION_Z 1 -#define Z_SELECTION_Z_PROBE -1 - -struct { - #if HAS_X_AXIS - xy_int_t xValuePos; - #endif - #if HAS_Y_AXIS - xy_int_t yValuePos; - #endif - #if HAS_Z_AXIS - xy_int_t zValuePos, zTypePos; - int z_selection = Z_SELECTION_Z; - #endif - #if HAS_EXTRUDERS - xy_int_t eValuePos, eNamePos; - uint8_t e_selection = 0; - #endif - xy_int_t stepValuePos; - float currentStepSize = 10.0; - bool blocked = false; - char message[32]; -} motionAxisState; - #define BTN_WIDTH 64 #define BTN_HEIGHT 52 #define X_MARGIN 20 #define Y_MARGIN 15 #define Y_OFFSET TERN(HAS_UI_480x272, 28, 34) -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.trim(); tft_string.add(F("mm")); @@ -104,7 +69,7 @@ static void drawCurStepValue() { } #if HAS_Z_AXIS - static void drawCurZSelection() { + void drawCurZSelection() { tft_string.set('Z'); tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), FONT_LINE_HEIGHT); tft.set_background(COLOR_BACKGROUND); @@ -123,7 +88,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'); @@ -132,7 +97,7 @@ static void drawCurStepValue() { } #endif -static void drawMessage_P(PGM_P const msg) { +void drawMessage_P(PGM_P const msg) { #if ENABLED(TFT_COLOR_UI_PORTRAIT) tft.canvas(X_MARGIN, TFT_HEIGHT - 2 * MOVE_AXIS_MARGIN_SIZE - BTN_HEIGHT - FONT_LINE_HEIGHT, TFT_WIDTH - X_MARGIN * 2, FONT_LINE_HEIGHT); #else @@ -142,9 +107,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) @@ -173,173 +136,8 @@ static void drawAxisValue(const AxisEnum axis) { tft.add_text(tft_string.center(BTN_WIDTH + X_MARGIN), 0, color, tft_string); } -static void moveAxis(const AxisEnum axis, const int8_t direction) { - quick_feedback(); - - #if HAS_EXTRUDERS - if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) { - drawMessage(F("Too cold")); - return; - } - #endif - - const float diff = motionAxisState.currentStepSize * direction; - - #if HAS_BED_PROBE - - if (axis == Z_AXIS && motionAxisState.z_selection == Z_SELECTION_Z_PROBE) { - #if ENABLED(BABYSTEP_ZPROBE_OFFSET) - const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z; - const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; - const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment, - new_probe_offset = probe.offset.z + bsDiff, - new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET - , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff - , new_probe_offset - ); - if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - babystep.add_steps(Z_AXIS, babystep_increment); - if (do_probe) - probe.offset.z = new_offs; - else - TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); - drawMessage(NUL_STR); // Clear the error - drawAxisValue(axis); - } - else - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - - #else - // Only change probe.offset.z - probe.offset.z += diff; - if (direction < 0 && current_position.z < Z_PROBE_OFFSET_RANGE_MIN) { - current_position.z = Z_PROBE_OFFSET_RANGE_MIN; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else if (direction > 0 && current_position.z > Z_PROBE_OFFSET_RANGE_MAX) { - current_position.z = Z_PROBE_OFFSET_RANGE_MAX; - drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); - } - else - drawMessage(NUL_STR); // Clear the error - - drawAxisValue(axis); - #endif - } - - #endif // HAS_BED_PROBE - - if (!ui.manual_move.processing) { - // Get motion limit from software endstops, if any - float min, max; - soft_endstop.get_manual_axis_limits(axis, min, max); - - // Delta limits XY based on the current offset from center - // This assumes the center is 0,0 - #if ENABLED(DELTA) - if (axis != Z_AXIS && TERN1(HAS_EXTRUDERS, axis != E_AXIS)) { - max = SQRT(sq(float(PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis - min = -max; - } - #endif - - // Get the new position - const bool limited = ui.manual_move.apply_diff(axis, diff, min, max); - #if IS_KINEMATIC - UNUSED(limited); - #else - PGM_P const msg = limited ? GET_TEXT(MSG_LCD_SOFT_ENDSTOPS) : NUL_STR; - drawMessage(msg); - #endif - - ui.manual_move.soon(axis OPTARG(MULTI_E_MANUAL, motionAxisState.e_selection)); - } - - drawAxisValue(axis); -} - -#if HAS_EXTRUDERS - static void e_plus() { moveAxis(E_AXIS, +1); } - static void e_minus() { moveAxis(E_AXIS, -1); } -#endif -#if HAS_X_AXIS - static void x_minus() { moveAxis(X_AXIS, -1); } - static void x_plus() { moveAxis(X_AXIS, +1); } -#endif -#if HAS_Y_AXIS - static void y_plus() { moveAxis(Y_AXIS, +1); } - static void y_minus() { moveAxis(Y_AXIS, -1); } -#endif -#if HAS_Z_AXIS - static void z_plus() { moveAxis(Z_AXIS, +1); } - static void z_minus() { moveAxis(Z_AXIS, -1); } -#endif - -#if ENABLED(TOUCH_SCREEN) - #if HAS_EXTRUDERS - static void e_select() { - if (++motionAxisState.e_selection >= EXTRUDERS) - motionAxisState.e_selection = 0; - quick_feedback(); - drawCurESelection(); - drawAxisValue(E_AXIS); - } - #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; - quick_feedback(); - drawCurStepValue(); - } -#endif // TOUCH_SCREEN - -#if ALL(HAS_BED_PROBE, TOUCH_SCREEN) - static void z_select() { - motionAxisState.z_selection *= -1; - quick_feedback(); - drawCurZSelection(); - drawAxisValue(Z_AXIS); - } -#endif - -static void disable_steppers() { - quick_feedback(); - queue.inject(F("M84")); -} - static void drawBtn(const int x, const int y, const char *label, intptr_t data, const MarlinImage img, uint16_t bgColor, const bool enabled=true) { - const uint16_t width = images[imgBtn52Rounded].width, - height = images[imgBtn52Rounded].height; - - if (!enabled) bgColor = COLOR_CONTROL_DISABLED; - - tft.canvas(x, y, width, height); - tft.set_background(COLOR_BACKGROUND); - tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - // TODO: Make an add_text() taking a font arg - if (label) { - tft_string.set(label); - tft_string.trim(); - tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); - } - else - tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); - - TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data)); + drawBtn(x, y, label, data, imgBtn52Rounded, img, bgColor, enabled); } void MarlinUI::move_axis_screen() { @@ -382,7 +180,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.eNamePos.set(TFT_WIDTH / 6 - BTN_WIDTH / 2, y); drawCurESelection(); #if ENABLED(TOUCH_SCREEN) - if (!busy) touch.add_control(BUTTON, motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select); + if (!busy) touch.add_control(BUTTON, motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT, e_select); #endif #endif @@ -397,7 +195,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.zTypePos.set(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y); drawCurZSelection(); #if ALL(HAS_BED_PROBE, TOUCH_SCREEN) - if (!busy) touch.add_control(BUTTON, motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, BTN_WIDTH, FONT_LINE_HEIGHT * 2, (intptr_t)z_select); + if (!busy) touch.add_control(BUTTON, motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, BTN_WIDTH, FONT_LINE_HEIGHT * 2, z_select); #endif #endif @@ -409,7 +207,7 @@ void MarlinUI::move_axis_screen() { #if HAS_X_AXIS drawBtn(TFT_WIDTH / 6 - BTN_WIDTH / 2, 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(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y, "X+", (intptr_t)x_plus, imgRight, X_BTN_COLOR, !busy); #endif @@ -467,7 +265,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.stepValuePos.set(X_MARGIN, y + 12); if (!busy) { drawCurStepValue(); - TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y + 12, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size)); + TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y + 12, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, step_size)); } // Button "Disable steppers" @@ -516,7 +314,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; @@ -526,7 +324,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; @@ -540,7 +338,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, Y_OFFSET * 2, (intptr_t)z_select); + if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, Y_OFFSET * 2, z_select); #endif #endif @@ -587,7 +385,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.stepValuePos.set(x, 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+