Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#33 from X-Ryl669/AddStatusInMoveMenu
Browse files Browse the repository at this point in the history
Add status in move menu
  • Loading branch information
MKS-Sean authored Dec 28, 2020
2 parents 7f69306 + 83377d3 commit 282167a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
queue.inject_P(PSTR("M84 X Y"));
break;
case ID_H_RETURN:
lv_clear_home();
lv_draw_tool();
clear_cur_ui();
draw_return_ui();
break;
}
}
Expand Down
45 changes: 43 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
#include <lv_conf.h>

#include "../../../../gcode/queue.h"
#include "../../../../module/motion.h"
#include "../../../../inc/MarlinConfig.h"

extern lv_group_t *g;
static lv_obj_t *scr;

static lv_obj_t *labelV, *buttonV;
static lv_obj_t *labelV, *buttonV, *labelP;
static lv_task_t *updatePosTask;
static char cur_label = 'Z';
static float cur_pos = 0;

void disp_cur_pos();

enum {
ID_M_X_P = 1,
Expand All @@ -54,6 +60,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 X%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_one_P(PSTR("G90"));
cur_label = 'X';
}
break;
case ID_M_X_N:
Expand All @@ -62,6 +69,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 X-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_now_P(PSTR("G90"));
cur_label = 'X';
}
break;
case ID_M_Y_P:
Expand All @@ -70,6 +78,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 Y%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_now_P(PSTR("G90"));
cur_label = 'Y';
}
break;
case ID_M_Y_N:
Expand All @@ -78,6 +87,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 Y-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_now_P(PSTR("G90"));
cur_label = 'Y';
}
break;
case ID_M_Z_P:
Expand All @@ -86,6 +96,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 Z%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_now_P(PSTR("G90"));
cur_label = 'Z';
}
break;
case ID_M_Z_N:
Expand All @@ -94,6 +105,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
sprintf_P(public_buf_l, PSTR("G1 Z-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed);
queue.enqueue_one_now(public_buf_l);
queue.enqueue_now_P(PSTR("G90"));
cur_label = 'Z';
}
break;
case ID_M_STEP:
Expand All @@ -106,10 +118,21 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_M_RETURN:
clear_cur_ui();
draw_return_ui();
break;
return;
}
disp_cur_pos();
}

void refresh_pos(lv_task_t *)
{
switch(cur_label) {
case 'X': cur_pos = current_position.x; break;
case 'Y': cur_pos = current_position.y; break;
case 'Z': cur_pos = current_position.z; break;
default: return;
}
disp_cur_pos();
}
void lv_draw_move_motor(void) {
scr = lv_screen_create(MOVE_MOTOR_UI);
lv_obj_t *buttonXI = lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_M_X_P);
Expand All @@ -129,9 +152,26 @@ void lv_draw_move_motor(void) {
}
#endif


lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_RETURN);

// We need to patch the title to leave some space on the right for displaying the status
lv_obj_t * title = lv_obj_get_child_back(scr, NULL);
if (title != NULL) lv_obj_set_width(title, TFT_WIDTH - 101);
labelP = lv_label_create(scr, TFT_WIDTH - 100, TITLE_YPOS, "Z:0.0mm");
if (labelP != NULL) {
updatePosTask = lv_task_create(refresh_pos, 300, LV_TASK_PRIO_LOWEST, 0);
}


disp_move_dist();
disp_cur_pos();
}


void disp_cur_pos() {
sprintf_P(public_buf_l, PSTR("%c:%3.1fmm"), cur_label, cur_pos);
if (labelP) lv_label_set_text(labelP, public_buf_l);
}

void disp_move_dist() {
Expand Down Expand Up @@ -162,6 +202,7 @@ void lv_clear_move_motor() {
#if HAS_ROTARY_ENCODER
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
#endif
lv_task_del(updatePosTask);
lv_obj_del(scr);
}

Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ enum {

static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
lv_clear_tool();
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bool clear = (obj->mks_obj_id != ID_T_LEVELING);
#else
constexpr bool clear = true;
#endif
if (clear) lv_clear_tool();
switch (obj->mks_obj_id) {
case ID_T_PRE_HEAT:
lv_draw_preHeat();
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,16 @@ char *creat_title_text() {
index++;
}

if (disp_state_stack._disp_state[disp_state_stack._disp_index] == PRINTING_UI
) {
if (disp_state_stack._disp_state[disp_state_stack._disp_index] == PRINTING_UI) {
titleText_cat(public_buf_m, sizeof(public_buf_m), (char *)":");
titleText_cat(public_buf_m, sizeof(public_buf_m), tmpCurFileStr);
}

if (strlen(public_buf_m) > MAX_TITLE_LEN) {
ZERO(public_buf_m);
tmpText = getDispText(0);
tmpText = 0;
for (index = 0; index <= disp_state_stack._disp_index && (!tmpText || *tmpText == 0); index++)
tmpText = getDispText(index);
if (*tmpText != 0) {
titleText_cat(public_buf_m, sizeof(public_buf_m), tmpText);
titleText_cat(public_buf_m, sizeof(public_buf_m), (char *)">...>");
Expand Down

0 comments on commit 282167a

Please sign in to comment.