From fd7d8df02cc63d96a4c175daea55131853110416 Mon Sep 17 00:00:00 2001 From: solawc <1225093964@qq.com> Date: Wed, 29 Sep 2021 17:35:05 +0800 Subject: [PATCH] Fix the problem of abnormal picture preview --- Marlin/Configuration.h | 2 +- .../src/lcd/extui/lib/mks_ui/draw_dialog.cpp | 6 ++ .../src/lcd/extui/lib/mks_ui/draw_preHeat.cpp | 2 - .../lcd/extui/lib/mks_ui/draw_print_file.cpp | 58 +++++++---- .../lcd/extui/lib/mks_ui/draw_ready_print.cpp | 1 + .../lib/mks_ui/tft_lvgl_configuration.cpp | 95 ++++++++++++------- .../src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h | 6 +- 7 files changed, 109 insertions(+), 61 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 862b734abe..11514c4ba3 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -102,7 +102,7 @@ * * :[-1, 0, 1, 2, 3, 4, 5, 6, 7] */ -#define SERIAL_PORT -1 +#define SERIAL_PORT 3//-1 /** * Select a secondary serial port on the board to use for communication with the host. diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 8adcc39421..8b9082f1a7 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -227,6 +227,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) { if (event != LV_EVENT_RELEASED) return; + if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { // TERN_(ADVANCED_PAUSE_FEATURE, pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT); } @@ -254,6 +255,11 @@ static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) { lv_clear_cur_ui(); lv_draw_return_ui(); } + else if(DIALOG_IS(TYPE_PRINT_FILE)) { + + lv_clear_cur_ui(); + lv_draw_print_file(); + } else { lv_clear_cur_ui(); lv_draw_return_ui(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp index ace8353fa7..e429400efa 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp @@ -141,12 +141,10 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { } lv_obj_del(btn_pla); lv_obj_del(btn_abs); - } else if (uiCfg.curTempType == 1) { uiCfg.curSprayerChoose = 0; uiCfg.curTempType = 0; - lv_obj_del(buttonAdd); lv_obj_del(buttonDec); disp_add_dec(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp index f9598d61c7..bef574f2dc 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp @@ -119,12 +119,20 @@ void unicode_2_utf8(char *des, uint16_t *source, uint8_t Len) { for (uint16_t i = 0; i < fileCnt; i++) { if (list_file.Sd_file_cnt == list_file.Sd_file_offset) { + card.getfilename_sorted(SD_ORDER(i, fileCnt)); + list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir; + // if() + strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath); + strcat_P(list_file.file_name[valid_name_cnt], PSTR("/")); + strcat(list_file.file_name[valid_name_cnt], card.filename); + // strcpy(list_file.long_name[valid_name_cnt], card.longest_filename()); + ZERO(list_file.long_name[valid_name_cnt]); if (lv_longFilename[0] == 0) strncpy(list_file.long_name[valid_name_cnt], card.filename, strlen(card.filename)); @@ -256,7 +264,6 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { }else { lv_draw_dialog(DIALOG_TYPE_PRINT_FILE); } - } break; } @@ -285,25 +292,10 @@ void lv_draw_print_file(void) { file_count = search_file(); #endif disp_gcode_icon(file_count); - - //lv_obj_t *labelPageUp = lv_label_create_empty(buttonPageUp); - //lv_obj_t *labelPageDown = lv_label_create_empty(buttonPageDown); - //lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - - /* - if (gCfgItems.multiple_language) { - lv_label_set_text(labelPageUp, tool_menu.preheat); - lv_obj_align(labelPageUp, buttonPageUp, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelPageDown, tool_menu.extrude); - lv_obj_align(labelPageDown, buttonPageDown, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - } - */ } + static char test_public_buf_l[(SHORT_NAME_LEN + 1) * MAX_DIR_LEVEL + strlen("S:/") + 1]; + void disp_gcode_icon(uint8_t file_num) { uint8_t i; @@ -352,15 +344,23 @@ void disp_gcode_icon(uint8_t file_num) { } else { if (have_pre_pic((char *)list_file.file_name[i])) { - //lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), list_file.file_name[i], 1); + memset(test_public_buf_l, 0, sizeof(test_public_buf_l)); + memset(buttonGcode[i]->mks_pic_name, 0, sizeof(buttonGcode[i]->mks_pic_name)); + strcpy(test_public_buf_l, "S:"); + strcat(test_public_buf_l, list_file.file_name[i]); + char *temp = strstr(test_public_buf_l, ".GCO"); + if (temp) strcpy(temp, ".bin"); + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), test_public_buf_l, 0); + lv_imgbtn_set_src_both(buttonGcode[i], buttonGcode[i]->mks_pic_name); + if (i < 3) { lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET); buttonText[i] = lv_btn_create(scr, nullptr); @@ -385,8 +385,10 @@ void disp_gcode_icon(uint8_t file_num) { lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1) + FILE_PRE_PIC_X_OFFSET, BTN_Y_PIXEL + INTERVAL_H + titleHeight + FILE_PRE_PIC_Y_OFFSET + 100); lv_obj_set_size(buttonText[i], 100, 40); } + labelPageUp[i] = lv_label_create(buttonText[i], public_buf_m); lv_obj_align(labelPageUp[i], buttonText[i], LV_ALIGN_IN_BOTTOM_MID, 0, 0); + // lv_refr_now(lv_refr_get_disp_refreshing()); } else { lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), "", 0); @@ -398,6 +400,7 @@ void disp_gcode_icon(uint8_t file_num) { labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m); lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5); + // lv_refr_now(lv_refr_get_disp_refreshing()); } } #if HAS_ROTARY_ENCODER @@ -407,6 +410,23 @@ void disp_gcode_icon(uint8_t file_num) { #else // !TFT35 #endif // !TFT35 } + + if(file_num != 0) { + if (have_pre_pic((char *)list_file.file_name[0])) { + // memset(test_public_buf_l, 0, sizeof(test_public_buf_l)); + // memset(buttonGcode[0]->mks_pic_name, 0, sizeof(buttonGcode[0]->mks_pic_name)); + strcpy(test_public_buf_l, "S:"); + + strcat(test_public_buf_l, list_file.file_name[0]); + + char *temp = strstr(test_public_buf_l, ".GCO"); + + if (temp) strcpy(temp, ".bin"); + + lv_imgbtn_set_src_both(buttonGcode[0], buttonGcode[0]->mks_pic_name); + } + } + #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { lv_group_add_obj(g, buttonPageUp); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp index 1937e11ad1..1e5f48f738 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp @@ -138,6 +138,7 @@ void lv_draw_ready_print(void) { lv_obj_t *buttonTool; disp_state_stack._disp_index = 0; + ZERO(disp_state_stack._disp_state); if (mks_test_flag == 0x1E) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index bae0d162d9..6deb6f3192 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -267,9 +267,9 @@ void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * co SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height); - for (uint16_t i = 0; i < height; i++) - SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); - // SPI_TFT.tftio.WriteSequence((uint16_t*)color_p, width * height); + // for (uint16_t i = 0; i < height; i++) + // SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); + SPI_TFT.tftio.WriteSequence((uint16_t*)color_p, width * height); lv_disp_flush_ready(disp); // Indicate you are ready with the flushing @@ -326,40 +326,62 @@ static bool get_point(int16_t *x, int16_t *y) { } bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { + // static int16_t last_x = 0, last_y = 0; + // static uint8_t last_touch_state = LV_INDEV_STATE_REL; + // static int32_t touch_time1 = 0; + // uint32_t tmpTime, diffTime = 0; + + // tmpTime = millis(); + // diffTime = getTickDiff(tmpTime, touch_time1); + // if (diffTime > 20) { + // if (get_point(&last_x, &last_y)) { + + // if (last_touch_state == LV_INDEV_STATE_PR) return false; + // data->state = LV_INDEV_STATE_PR; + + // // Set the coordinates (if released use the last-pressed coordinates) + // #if TFT_ROTATION == TFT_ROTATE_180 + // data->point.x = TFT_WIDTH - last_x; + // data->point.y = TFT_HEIGHT -last_y; + // #else + // data->point.x = last_x; + // data->point.y = last_y; + // #endif + + // last_x = last_y = 0; + // last_touch_state = LV_INDEV_STATE_PR; + // } + // else { + // if (last_touch_state == LV_INDEV_STATE_PR) + // data->state = LV_INDEV_STATE_REL; + // last_touch_state = LV_INDEV_STATE_REL; + // } + + // touch_time1 = tmpTime; + // } + + // return false; // Return `false` since no data is buffering or left to read static int16_t last_x = 0, last_y = 0; - static uint8_t last_touch_state = LV_INDEV_STATE_REL; - static int32_t touch_time1 = 0; - uint32_t tmpTime, diffTime = 0; - - tmpTime = millis(); - diffTime = getTickDiff(tmpTime, touch_time1); - if (diffTime > 20) { - if (get_point(&last_x, &last_y)) { - - if (last_touch_state == LV_INDEV_STATE_PR) return false; - data->state = LV_INDEV_STATE_PR; - - // Set the coordinates (if released use the last-pressed coordinates) - #if TFT_ROTATION == TFT_ROTATE_180 - data->point.x = TFT_WIDTH - last_x; - data->point.y = TFT_HEIGHT -last_y; - #else - data->point.x = last_x; - data->point.y = last_y; - #endif - - last_x = last_y = 0; - last_touch_state = LV_INDEV_STATE_PR; - } - else { - if (last_touch_state == LV_INDEV_STATE_PR) - data->state = LV_INDEV_STATE_REL; - last_touch_state = LV_INDEV_STATE_REL; - } - - touch_time1 = tmpTime; + if (get_point(&last_x, &last_y)) { + #if TFT_ROTATION == TFT_ROTATE_180 + data->point.x = TFT_WIDTH - last_x; + data->point.y = TFT_HEIGHT - last_y; + #else + data->point.x = last_x; + data->point.y = last_y; + #endif + data->state = LV_INDEV_STATE_PR; + } + else { + #if TFT_ROTATION == TFT_ROTATE_180 + data->point.x = TFT_WIDTH - last_x; + data->point.y = TFT_HEIGHT - last_y; + #else + data->point.x = last_x; + data->point.y = last_y; + #endif + data->state = LV_INDEV_STATE_REL; } - return false; // Return `false` since no data is buffering or left to read } @@ -432,10 +454,11 @@ char *cur_namefff; uint32_t sd_read_base_addr = 0, sd_read_addr_offset = 0, small_image_size = 409; char last_path[(SHORT_NAME_LEN + 1) * MAX_DIR_LEVEL + strlen("S:/") + 1]; lv_fs_res_t sd_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) { + if (path != nullptr && card.isFileOpen() && strcmp((const char*)path, (const char*)last_path) == 0) return LV_FS_RES_OK; strcpy(last_path, path); lv_close_gcode_file(); - char name_buf[100]; + char name_buf[100] = {0}; *name_buf = '/'; strcpy(name_buf + 1, path); char *temp = strstr(name_buf, ".bin"); diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h index 0f803894d2..7625fa7b4c 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h @@ -330,10 +330,10 @@ #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - #define BTN_EN1 PE8 - #define BTN_EN2 PE11 + // #define BTN_EN1 PE8 + // #define BTN_EN2 PE11 #define BEEPER_PIN PC5 - #define BTN_ENC PE13 + // #define BTN_ENC PE13 #define LCD_READ_ID 0xD3 #define LCD_USE_DMA_SPI