Skip to content

Commit

Permalink
Fix the problem of abnormal picture preview
Browse files Browse the repository at this point in the history
  • Loading branch information
solawc committed Sep 29, 2021
1 parent 79d6d5d commit fd7d8df
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
58 changes: 39 additions & 19 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
95 changes: 59 additions & 36 deletions Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd7d8df

Please sign in to comment.