mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-01-28 11:50:41 -07:00
🚸 Fix MKS UI G-code result display (#27825)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
4096beaf52
commit
e16885c558
7 changed files with 70 additions and 63 deletions
|
|
@ -34,6 +34,7 @@ static lv_obj_t *scr, *outL, *outV = 0;
|
|||
static int currentWritePos = 0;
|
||||
extern uint8_t public_buf[513];
|
||||
extern "C" { extern char public_buf_m[100]; }
|
||||
extern bool gcode_output_update_flag;
|
||||
|
||||
enum {
|
||||
ID_GCODE_RETURN = 1,
|
||||
|
|
@ -43,6 +44,8 @@ enum {
|
|||
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||
if (event != LV_EVENT_RELEASED) return;
|
||||
lv_clear_gcode();
|
||||
public_buf[0] = public_buf_m[0] = 0; // Clear output buffer
|
||||
MYSERIAL1.setHook();
|
||||
switch (obj->mks_obj_id) {
|
||||
case ID_GCODE_RETURN:
|
||||
lv_draw_more();
|
||||
|
|
@ -56,20 +59,22 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
|||
|
||||
void lv_show_gcode_output(void * that, const char * txt) {
|
||||
// Ignore echo of command
|
||||
if (!memcmp(txt, "echo:", 5)) {
|
||||
public_buf[0] = 0; // Clear output buffer
|
||||
if (txt[0] == 'e' && txt[4] == ':') { // !memcmp_P(txt, PSTR("echo:"), 5)
|
||||
public_buf[0] = public_buf_m[0] = 0; // Clear output buffer
|
||||
return;
|
||||
}
|
||||
|
||||
// Avoid overflow if the answer is too large
|
||||
size_t len = strlen((const char*)public_buf), tlen = strlen(txt);
|
||||
if (len + tlen + 1 < sizeof(public_buf)) {
|
||||
if (len + tlen + 2 <= sizeof(public_buf)) {
|
||||
memcpy(public_buf + len, txt, tlen);
|
||||
public_buf[len + tlen] = '\n';
|
||||
public_buf[len + tlen + 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void lv_serial_capt_hook(void * userPointer, uint8_t c) {
|
||||
gcode_output_update_flag = false;
|
||||
if (c == '\n' || currentWritePos == sizeof(public_buf_m) - 1) { // End of line, probably end of command anyway
|
||||
public_buf_m[currentWritePos] = 0;
|
||||
lv_show_gcode_output(userPointer, public_buf_m);
|
||||
|
|
@ -82,17 +87,21 @@ void lv_serial_capt_hook(void * userPointer, uint8_t c) {
|
|||
void lv_eom_hook(void *) {
|
||||
// Message is done, let's remove the hook now
|
||||
MYSERIAL1.setHook();
|
||||
// Update message display
|
||||
gcode_output_update_flag = true;
|
||||
}
|
||||
|
||||
void lv_draw_gcode(bool clear) {
|
||||
if (clear) {
|
||||
currentWritePos = 0;
|
||||
public_buf[0] = 0;
|
||||
public_buf[0] = public_buf_m[0] = 0;
|
||||
MYSERIAL1.setHook();
|
||||
gcode_output_update_flag = false;
|
||||
}
|
||||
scr = lv_screen_create(GCODE_UI, more_menu.gcode);
|
||||
lv_screen_menu_item(scr, more_menu.entergcode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_GCODE_COMMAND, 1);
|
||||
lv_screen_menu_item(scr, more_menu.entergcode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_GCODE_COMMAND, 0);
|
||||
outL = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2, "Result:");
|
||||
outV = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3, (const char*)public_buf);
|
||||
outV = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 20, (const char*)public_buf);
|
||||
|
||||
lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACK_POS_X + 10, PARA_UI_BACK_POS_Y, event_handler, ID_GCODE_RETURN, true);
|
||||
}
|
||||
|
|
@ -105,4 +114,8 @@ void lv_clear_gcode() {
|
|||
outV = 0;
|
||||
}
|
||||
|
||||
void disp_gcode_output() {
|
||||
lv_label_set_text(outV, (const char*)public_buf);
|
||||
}
|
||||
|
||||
#endif // HAS_TFT_LVGL_UI
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
void lv_draw_gcode(bool clear = false);
|
||||
void lv_clear_gcode();
|
||||
void disp_gcode_output();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* C-declarations for C++ */
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
|
|||
goto_previous_ui();
|
||||
break;
|
||||
case GCodeCommand:
|
||||
if (ret_ta_txt[0] && !queue.ring_buffer.full(3)) {
|
||||
if (ret_ta_txt[0]) {
|
||||
// Hook for the next bytes to arrive from the serial port
|
||||
MYSERIAL1.setHook(lv_serial_capt_hook, lv_eom_hook, 0);
|
||||
// Run the command as soon as possible
|
||||
|
|
|
|||
|
|
@ -59,19 +59,17 @@ void disp_cur_pos() {
|
|||
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||
char str_1[16];
|
||||
if (event != LV_EVENT_RELEASED) return;
|
||||
if (!queue.ring_buffer.full(3)) {
|
||||
bool do_inject = true;
|
||||
float dist = uiCfg.move_dist;
|
||||
switch (obj->mks_obj_id) {
|
||||
case ID_M_X_N: dist *= -1; case ID_M_X_P: cur_label = 'X'; break;
|
||||
case ID_M_Y_N: dist *= -1; case ID_M_Y_P: cur_label = 'Y'; break;
|
||||
case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
|
||||
default: do_inject = false;
|
||||
}
|
||||
if (do_inject) {
|
||||
sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
|
||||
queue.inject(public_buf_l);
|
||||
}
|
||||
bool do_inject = true;
|
||||
float dist = uiCfg.move_dist;
|
||||
switch (obj->mks_obj_id) {
|
||||
case ID_M_X_N: dist *= -1; case ID_M_X_P: cur_label = 'X'; break;
|
||||
case ID_M_Y_N: dist *= -1; case ID_M_Y_P: cur_label = 'Y'; break;
|
||||
case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
|
||||
default: do_inject = false;
|
||||
}
|
||||
if (do_inject) {
|
||||
sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
|
||||
queue.inject(public_buf_l);
|
||||
}
|
||||
|
||||
switch (obj->mks_obj_id) {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ uint32_t size = 809;
|
|||
uint16_t row;
|
||||
bool temps_update_flag;
|
||||
uint8_t printing_rate_update_flag;
|
||||
bool gcode_output_update_flag;
|
||||
|
||||
extern bool once_flag;
|
||||
extern uint8_t sel_id;
|
||||
|
|
@ -864,6 +865,13 @@ void GUI_RefreshPage() {
|
|||
}
|
||||
break;
|
||||
|
||||
case GCODE_UI:
|
||||
if (gcode_output_update_flag) {
|
||||
gcode_output_update_flag = false;
|
||||
disp_gcode_output();
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,19 +73,17 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
|||
char str_1[16];
|
||||
if (event != LV_EVENT_RELEASED) return;
|
||||
//lv_clear_z_offset_wizard();
|
||||
if (!queue.ring_buffer.full(3)) {
|
||||
bool do_inject = true;
|
||||
float dist = uiCfg.move_dist;
|
||||
switch (obj->mks_obj_id) {
|
||||
case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
|
||||
default: do_inject = false;
|
||||
}
|
||||
if (do_inject) {
|
||||
sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
|
||||
queue.inject(public_buf_l);
|
||||
//calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
|
||||
disp_cur_wizard_pos();
|
||||
}
|
||||
bool do_inject = true;
|
||||
float dist = uiCfg.move_dist;
|
||||
switch (obj->mks_obj_id) {
|
||||
case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
|
||||
default: do_inject = false;
|
||||
}
|
||||
if (do_inject) {
|
||||
sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
|
||||
queue.inject(public_buf_l);
|
||||
//calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
|
||||
disp_cur_wizard_pos();
|
||||
}
|
||||
|
||||
switch (obj->mks_obj_id) {
|
||||
|
|
|
|||
|
|
@ -770,8 +770,9 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
|
|||
}
|
||||
|
||||
int send_to_wifi(uint8_t * const buf, const int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
|
||||
int print_to_wifi(const char * const buf) { return package_to_wifi(WIFI_TRANS_INF, (uint8_t*)buf, strlen(buf)); }
|
||||
|
||||
inline void send_ok_to_wifi() { send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n")); }
|
||||
inline void send_ok_to_wifi() { print_to_wifi("ok\r\n"); }
|
||||
|
||||
void set_cur_file_sys(int fileType) { gCfgItems.fileSysType = fileType; }
|
||||
|
||||
|
|
@ -905,7 +906,7 @@ uint8_t exploreDisk(const char * const path, const uint8_t recu_level, const boo
|
|||
}
|
||||
|
||||
strcat_P(Fstream, PSTR("\r\n"));
|
||||
send_to_wifi((uint8_t*)Fstream, strlen(Fstream));
|
||||
print_to_wifi(Fstream);
|
||||
}
|
||||
|
||||
return fileCnt;
|
||||
|
|
@ -950,9 +951,9 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
int index = 0;
|
||||
if (spStr == nullptr) {
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
send_to_wifi((uint8_t *)(STR_BEGIN_FILE_LIST "\r\n"), strlen(STR_BEGIN_FILE_LIST "\r\n"));
|
||||
print_to_wifi(STR_BEGIN_FILE_LIST "\r\n");
|
||||
get_file_list("0:/", false);
|
||||
send_to_wifi((uint8_t *)(STR_END_FILE_LIST "\r\n"), strlen(STR_END_FILE_LIST "\r\n"));
|
||||
print_to_wifi(STR_END_FILE_LIST "\r\n");
|
||||
send_ok_to_wifi();
|
||||
break;
|
||||
}
|
||||
|
|
@ -962,7 +963,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
if (gCfgItems.wifi_type == ESP_WIFI) {
|
||||
char * const path = (char *)tempBuf;
|
||||
if (strlen(&mStr[index]) < 80) {
|
||||
send_to_wifi((uint8_t *)(STR_BEGIN_FILE_LIST "\r\n"), strlen(STR_BEGIN_FILE_LIST "\r\n"));
|
||||
print_to_wifi(STR_BEGIN_FILE_LIST "\r\n");
|
||||
|
||||
if (strncmp(&mStr[index], "1:", 2) == 0)
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
|
|
@ -972,7 +973,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
strcpy(path, &mStr[index]);
|
||||
const bool with_longnames = strchr(mStr, 'L') != nullptr;
|
||||
get_file_list(path, with_longnames);
|
||||
send_to_wifi((uint8_t *)(STR_END_FILE_LIST "\r\n"), strlen(STR_END_FILE_LIST "\r\n"));
|
||||
print_to_wifi(STR_END_FILE_LIST "\r\n");
|
||||
}
|
||||
send_ok_to_wifi();
|
||||
}
|
||||
|
|
@ -1033,9 +1034,9 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
card.openFileRead(cur_name);
|
||||
|
||||
if (card.isFileOpen())
|
||||
send_to_wifi((uint8_t *)"File selected\r\n", strlen("File selected\r\n"));
|
||||
print_to_wifi("File selected\r\n");
|
||||
else {
|
||||
send_to_wifi((uint8_t *)"file.open failed\r\n", strlen("file.open failed\r\n"));
|
||||
print_to_wifi("file.open failed\r\n");
|
||||
strcpy_P(list_file.file_name[sel_id], PSTR("notValid"));
|
||||
}
|
||||
send_ok_to_wifi();
|
||||
|
|
@ -1149,7 +1150,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
print_rate = uiCfg.totalSend;
|
||||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("M27 %d\r\n"), print_rate);
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
print_to_wifi(tempBuf);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1182,7 +1183,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("Writing to file: %s\r\n"), (char *)file_writer.saveFileName);
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
print_to_wifi(tempBuf);
|
||||
wifi_link_state = WIFI_WAIT_TRANS_START;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1246,7 +1247,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
);
|
||||
}
|
||||
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
print_to_wifi(tempBuf);
|
||||
queue.enqueue_one(F("M105"));
|
||||
break;
|
||||
|
||||
|
|
@ -1255,7 +1256,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
ZERO(tempBuf);
|
||||
sprintf_P((char *)tempBuf, PSTR("M992 %d%d:%d%d:%d%d\r\n"), print_time.hours/10, print_time.hours%10, print_time.minutes/10, print_time.minutes%10, print_time.seconds/10, print_time.seconds%10);
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
print_to_wifi(tempBuf);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1265,7 +1266,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
if (strlen((char *)list_file.file_name[sel_id]) > (100 - 1)) return;
|
||||
sprintf_P((char *)tempBuf, PSTR("M994 %s;%d\n"), list_file.file_name[sel_id], (int)gCfgItems.curFilesize);
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
print_to_wifi(tempBuf);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1275,22 +1276,10 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
#define SENDPAUSE "M997 PAUSE\r\n"
|
||||
switch (uiCfg.print_state) {
|
||||
default: break;
|
||||
case IDLE:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)SENDIDLE, strlen(SENDIDLE));
|
||||
break;
|
||||
case WORKING:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)SENDPRINTING, strlen(SENDPRINTING));
|
||||
break;
|
||||
case PAUSED:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)SENDPAUSE, strlen(SENDPAUSE));
|
||||
break;
|
||||
case REPRINTING:
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((uint8_t *)SENDPAUSE, strlen(SENDPAUSE));
|
||||
break;
|
||||
case IDLE: wifi_ret_ack(); print_to_wifi(SENDIDLE); break;
|
||||
case WORKING: wifi_ret_ack(); print_to_wifi(SENDPRINTING); break;
|
||||
case PAUSED: wifi_ret_ack(); print_to_wifi(SENDPAUSE); break;
|
||||
case REPRINTING: wifi_ret_ack(); print_to_wifi(SENDPAUSE); break;
|
||||
}
|
||||
if (!uiCfg.command_send) get_wifi_list_command_send();
|
||||
break;
|
||||
|
|
@ -1307,7 +1296,7 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) {
|
|||
ZERO(tempBuf);
|
||||
send_ok_to_wifi();
|
||||
#define SENDFW "FIRMWARE_NAME:Robin_nano\r\n"
|
||||
send_to_wifi((uint8_t *)SENDFW, strlen(SENDFW));
|
||||
print_to_wifi(SENDFW);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue