Skip to content

Commit

Permalink
🐛 Fix Manual Move axis selection (MarlinFirmware#24404)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 26, 2022
1 parent 3af5c32 commit 994b396
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 58 deletions.
18 changes: 9 additions & 9 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ CrealityDWINClass CrealityDWIN;

#endif

void manual_move(bool zmove=false) {
void manual_mesh_move(const bool zmove=false) {
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
Expand Down Expand Up @@ -3035,7 +3035,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
mesh_conf.goto_mesh_value = true;
mesh_conf.mesh_x = mesh_conf.mesh_y = 0;
Popup_Handler(MoveWait);
mesh_conf.manual_move();
mesh_conf.manual_mesh_move();
Draw_Menu(UBLMesh);
#endif
#elif HAS_BED_PROBE
Expand Down Expand Up @@ -3091,7 +3091,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
TERN_(HAS_HEATED_BED, thermalManager.wait_for_bed_heating());
#endif
Popup_Handler(MoveWait);
mesh_conf.manual_move();
mesh_conf.manual_mesh_move();
Draw_Menu(LevelManual);
}
break;
Expand Down Expand Up @@ -3328,7 +3328,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
mesh_conf.mesh_x++;
else
mesh_conf.mesh_x--;
mesh_conf.manual_move();
mesh_conf.manual_mesh_move();
}
}
break;
Expand Down Expand Up @@ -3375,7 +3375,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
else {
mesh_conf.goto_mesh_value = !mesh_conf.goto_mesh_value;
current_position.z = 0;
mesh_conf.manual_move(true);
mesh_conf.manual_mesh_move(true);
Draw_Checkbox(row, mesh_conf.goto_mesh_value);
}
break;
Expand Down Expand Up @@ -3428,7 +3428,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
mesh_conf.mesh_x++;
else
mesh_conf.mesh_x--;
mesh_conf.manual_move();
mesh_conf.manual_mesh_move();
}
else {
gcode.process_subcommands_now(F("G29 S"));
Expand All @@ -3449,7 +3449,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
mesh_conf.mesh_x--;
else
mesh_conf.mesh_x++;
mesh_conf.manual_move();
mesh_conf.manual_mesh_move();
}
}
break;
Expand Down Expand Up @@ -4109,8 +4109,8 @@ void CrealityDWINClass::Value_Control() {
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
break;
case UBLMesh: mesh_conf.manual_move(true); break;
case LevelManual: mesh_conf.manual_move(selection == LEVELING_M_OFFSET); break;
case UBLMesh: mesh_conf.manual_mesh_move(true); break;
case LevelManual: mesh_conf.manual_mesh_move(selection == LEVELING_M_OFFSET); break;
#endif
}
if (valuepointer == &planner.flow_percentage[0])
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ void MarlinUI::draw_status_message(const bool blink) {
const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));

extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
if (ui.can_show_slider()) {

const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
slider_height = 16,
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ namespace Language_en {
LSTR MSG_MOVE_Z = _UxGT("Move Z");
LSTR MSG_MOVE_N = _UxGT("Move @");
LSTR MSG_MOVE_E = _UxGT("Move Extruder");
LSTR MSG_MOVE_EN = _UxGT("Move E*");
LSTR MSG_MOVE_EN = _UxGT("Move *");
LSTR MSG_HOTEND_TOO_COLD = _UxGT("Hotend too cold");
LSTR MSG_MOVE_N_MM = _UxGT("Move $mm");
LSTR MSG_MOVE_01MM = _UxGT("Move 0.1mm");
Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ void MarlinUI::init() {

millis_t ManualMove::start_time = 0;
float ManualMove::menu_scale = 1;
screenFunc_t ManualMove::screen_ptr;
#if IS_KINEMATIC
float ManualMove::offset = 0;
xyze_pos_t ManualMove::all_axes_destination = { 0 };
Expand All @@ -775,6 +776,9 @@ void MarlinUI::init() {
int8_t ManualMove::e_index = 0;
#endif
AxisEnum ManualMove::axis = NO_AXIS_ENUM;
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
float ManualMove::e_origin = 0;
#endif

/**
* If a manual move has been posted and its time has arrived, and if the planner
Expand All @@ -791,9 +795,6 @@ void MarlinUI::init() {
* For kinematic machines:
* - Set manual_move.offset to modify one axis and post the move.
* This is used to achieve more rapid stepping on kinematic machines.
*
* Currently used by the _lcd_move_xyz function in menu_motion.cpp
* and the ubl_map_move_to_xy function in menu_ubl.cpp.
*/
void ManualMove::task() {

Expand Down Expand Up @@ -864,7 +865,7 @@ void MarlinUI::init() {

void MarlinUI::external_encoder() {
if (external_control && encoderDiff) {
bedlevel.encoder_diff += encoderDiff; // Encoder for UBL G29 mesh editing
bedlevel.encoder_diff += encoderDiff; // Encoder for UBL G29 mesh editing
encoderDiff = 0; // Hide encoder events from the screen handler
refresh(LCDVIEW_REDRAW_NOW); // ...but keep the refresh.
}
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ typedef bool (*statusResetFunc_t)();
static xyze_pos_t all_axes_destination;
#endif
public:
static screenFunc_t screen_ptr;
static float menu_scale;
#if IS_KINEMATIC
static float offset;
#endif
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
static float e_origin;
#endif
template <typename T>
void set_destination(const T& dest) {
static void set_destination(const T& dest) {
#if IS_KINEMATIC
// Moves are segmented, so the entire move is not submitted at once.
// Using a separate variable prevents corrupting the in-progress move.
Expand All @@ -153,10 +157,10 @@ typedef bool (*statusResetFunc_t)();
current_position.set(dest);
#endif
}
float axis_value(const AxisEnum axis) {
static float axis_value(const AxisEnum axis) {
return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis);
}
bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
static bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
#if IS_KINEMATIC
float &valref = offset;
const float rmin = min - current_position[axis], rmax = max - current_position[axis];
Expand All @@ -166,12 +170,7 @@ typedef bool (*statusResetFunc_t)();
#endif
valref += diff;
const float pre = valref;
if (min != max) {
if (diff < 0)
NOLESS(valref, rmin);
else
NOMORE(valref, rmax);
}
if (min != max) { if (diff < 0) NOLESS(valref, rmin); else NOMORE(valref, rmax); }
return pre != valref;
}
#if IS_KINEMATIC
Expand Down Expand Up @@ -552,6 +551,7 @@ class MarlinUI {

// Manual Movement
static ManualMove manual_move;
static bool can_show_slider() { return !external_control && currentScreen != manual_move.screen_ptr; }

// Select Screen (modal NO/YES style dialog)
static bool selection;
Expand Down
43 changes: 16 additions & 27 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif

#if ENABLED(MANUAL_E_MOVES_RELATIVE)
float manual_move_e_origin = 0;
#endif

//
// "Motion" > "Move Axis" submenu
//

static void _lcd_move_xyz(const AxisEnum axis) {
void lcd_move_axis(const AxisEnum axis) {
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
if (ui.encoderPosition && !ui.manual_move.processing) {
// Get motion limit from software endstops, if any
Expand Down Expand Up @@ -91,11 +87,6 @@ static void _lcd_move_xyz(const AxisEnum axis) {
}
}

void _lcd_move_axis_n() { _lcd_move_xyz(AxisEnum(MenuItemBase::itemIndex)); }

// Move functions for non-menu code that hasn't set itemIndex (e.g., keypad)
void lcd_move_axis(const AxisEnum axis) { MenuEditItemBase::itemIndex = int8_t(axis); _lcd_move_axis_n(); }

// Move Z easy accessor
void lcd_move_z() { lcd_move_axis(Z_AXIS); }

Expand All @@ -118,7 +109,7 @@ void lcd_move_z() { lcd_move_axis(Z_AXIS); }
GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
ftostr41sign(current_position.e
PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin)
)
);
} // should_draw
Expand All @@ -143,25 +134,23 @@ void lcd_move_z() { lcd_move_axis(Z_AXIS); }
#define FINE_MANUAL_MOVE 0.025
#endif

screenFunc_t _manual_move_func_ptr;

void _goto_manual_move(const_float_t scale) {
ui.defer_status_screen();
ui.manual_move.menu_scale = scale;
ui.goto_screen(_manual_move_func_ptr);
ui.goto_screen(ui.manual_move.screen_ptr);
thermalManager.set_menu_cold_override(true);
}

void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
_manual_move_func_ptr = func;
ui.manual_move.screen_ptr = func;
START_MENU();

if (LCD_HEIGHT >= 4) {
if (axis < LINEAR_AXES)
STATIC_ITEM_N(axis, MSG_MOVE_N, SS_DEFAULT|SS_INVERT);
else {
TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e);
STATIC_ITEM(MSG_MOVE_E, SS_DEFAULT|SS_INVERT);
TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = current_position.e);
STATIC_ITEM_N(eindex, MSG_MOVE_EN, SS_DEFAULT|SS_INVERT);
}
}

Expand All @@ -183,8 +172,6 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
END_MENU();
}

void _menu_move_n_distance() { _menu_move_distance(AxisEnum(MenuItemBase::itemIndex), _lcd_move_axis_n); }

#if E_MANUAL

inline void _goto_menu_move_distance_e() {
Expand Down Expand Up @@ -221,17 +208,19 @@ void menu_move() {
// Move submenu for each axis
if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
for (uint8_t a = X_AXIS; a <= min(int(Y_AXIS), LINEAR_AXES - 1); a++)
SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance);
SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); });
#if HAS_Y_AXIS
SUBMENU_N(Y_AXIS, MSG_MOVE_N, []{ _menu_move_distance(Y_AXIS, []{ lcd_move_axis(Y_AXIS); }); });
#endif
}
else {
#if ENABLED(DELTA)
ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
#endif
}
#if HAS_Z_AXIS
for (uint8_t a = Z_AXIS; a < LINEAR_AXES; a++)
SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance);
#define _AXIS_MOVE(N) SUBMENU_N(N, MSG_MOVE_N, []{ _menu_move_distance(AxisEnum(N), []{ lcd_move_axis(AxisEnum(N)); }); });
REPEAT_S(2, NUM_AXES, _AXIS_MOVE);
#endif
}
else
Expand Down Expand Up @@ -276,9 +265,9 @@ void menu_move() {
#if E_MANUAL

// The current extruder
SUBMENU(MSG_MOVE_E, []{ _menu_move_distance_e_maybe(); });
SUBMENU(MSG_MOVE_E, _menu_move_distance_e_maybe);

#define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(MenuItemBase::itemIndex); }, MenuItemBase::itemIndex); });
#define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(N); }, N); });

#if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)

Expand All @@ -289,8 +278,8 @@ void menu_move() {

#elif MULTI_E_MANUAL

// Independent extruders with one E-stepper per hotend
LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
// Independent extruders with one E stepper per hotend
REPEAT(E_MANUAL, SUBMENU_MOVE_E);

#endif

Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/tft/ui_1024x600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
}
#endif

extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
if (ui.can_show_slider()) {

#define SLIDER_LENGTH 600
#define SLIDER_Y_POSITION 200
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/tft/ui_320x240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
}
#endif

extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
if (ui.can_show_slider()) {

#define SLIDER_LENGTH 224
#define SLIDER_Y_POSITION 140
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/tft/ui_480x320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
}
#endif

extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
if (ui.can_show_slider()) {

#define SLIDER_LENGTH 336
#define SLIDER_Y_POSITION 186
Expand Down

0 comments on commit 994b396

Please sign in to comment.