2020-06-16 02:05:33 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-16 02:05:33 +00:00
|
|
|
*
|
|
|
|
*/
|
2021-05-06 09:17:59 +00:00
|
|
|
#include "../../../inc/MarlinConfigPre.h"
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#if HAS_TFT_LVGL_UI
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-21 17:45:27 +00:00
|
|
|
#include "draw_ui.h"
|
|
|
|
#include <lv_conf.h>
|
2020-06-16 02:05:33 +00:00
|
|
|
//#include "../lvgl/src/lv_objx/lv_imgbtn.h"
|
|
|
|
//#include "../lvgl/src/lv_objx/lv_img.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_disp.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_refr.h"
|
2020-10-21 17:45:27 +00:00
|
|
|
|
2021-05-06 09:17:59 +00:00
|
|
|
#include "../../../sd/cardreader.h"
|
|
|
|
#include "../../../inc/MarlinConfig.h"
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
static lv_obj_t *scr;
|
2020-09-21 01:55:02 +00:00
|
|
|
extern lv_group_t* g;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
static lv_obj_t *buttonPageUp, *buttonPageDown, *buttonBack,
|
|
|
|
*buttonGcode[FILE_BTN_CNT], *labelPageUp[FILE_BTN_CNT], *buttonText[FILE_BTN_CNT];
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
enum {
|
|
|
|
ID_P_UP = 7,
|
|
|
|
ID_P_DOWN,
|
|
|
|
ID_P_RETURN
|
|
|
|
};
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
int8_t curDirLever = 0;
|
|
|
|
LIST_FILE list_file;
|
|
|
|
DIR_OFFSET dir_offset[10];
|
|
|
|
|
2021-01-13 03:02:35 +00:00
|
|
|
extern uint8_t public_buf[513];
|
2020-06-16 02:05:33 +00:00
|
|
|
extern char public_buf_m[100];
|
|
|
|
|
|
|
|
uint8_t sel_id = 0;
|
|
|
|
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
static uint8_t search_file() {
|
|
|
|
int valid_name_cnt = 0;
|
|
|
|
//char tmp[SHORT_NEME_LEN*MAX_DIR_LEVEL+1];
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
list_file.Sd_file_cnt = 0;
|
|
|
|
//list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
//root2.rewind();
|
|
|
|
//SERIAL_ECHOLN(list_file.curDirPath);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2021-03-03 06:11:50 +00:00
|
|
|
if (curDirLever != 0)
|
|
|
|
card.cd(list_file.curDirPath);
|
|
|
|
else
|
|
|
|
card.cdroot();
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
const uint16_t fileCnt = card.get_num_Files();
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
for (uint16_t i = 0; i < fileCnt; i++) {
|
|
|
|
if (list_file.Sd_file_cnt == list_file.Sd_file_offset) {
|
2021-01-14 06:23:56 +00:00
|
|
|
card.getfilename_sorted(SD_ORDER(i, fileCnt));
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir;
|
|
|
|
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());
|
|
|
|
|
|
|
|
valid_name_cnt++;
|
|
|
|
if (valid_name_cnt == 1)
|
|
|
|
dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset;
|
|
|
|
if (valid_name_cnt >= FILE_NUM) {
|
|
|
|
dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset;
|
2020-06-16 02:05:33 +00:00
|
|
|
list_file.Sd_file_offset++;
|
2020-10-24 04:37:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
list_file.Sd_file_offset++;
|
2020-07-25 05:52:07 +00:00
|
|
|
}
|
|
|
|
list_file.Sd_file_cnt++;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-07-25 05:52:07 +00:00
|
|
|
//card.closefile(false);
|
|
|
|
return valid_name_cnt;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SDSUPPORT
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
bool have_pre_pic(char *path) {
|
2020-06-16 02:05:33 +00:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
char *ps1, *ps2, *cur_name = strrchr(path, '/');
|
|
|
|
card.openFileRead(cur_name);
|
|
|
|
card.read(public_buf, 512);
|
|
|
|
ps1 = strstr((char *)public_buf, ";simage:");
|
|
|
|
card.read(public_buf, 512);
|
|
|
|
ps2 = strstr((char *)public_buf, ";simage:");
|
|
|
|
card.closefile();
|
2020-10-24 04:37:45 +00:00
|
|
|
if (ps1 || ps2) return true;
|
2020-06-16 02:05:33 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
return false;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_RELEASED) return;
|
2020-06-16 02:05:33 +00:00
|
|
|
uint8_t i, file_count = 0;
|
|
|
|
//switch (obj->mks_obj_id)
|
|
|
|
//{
|
|
|
|
if (obj->mks_obj_id == ID_P_UP) {
|
2020-10-24 04:37:45 +00:00
|
|
|
if (dir_offset[curDirLever].curPage > 0) {
|
|
|
|
// 2015.05.19
|
|
|
|
list_file.Sd_file_cnt = 0;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM)
|
|
|
|
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
file_count = search_file();
|
|
|
|
#endif
|
|
|
|
if (file_count != 0) {
|
|
|
|
dir_offset[curDirLever].curPage--;
|
|
|
|
lv_clear_print_file();
|
|
|
|
disp_gcode_icon(file_count);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (obj->mks_obj_id == ID_P_DOWN) {
|
2020-10-24 04:37:45 +00:00
|
|
|
if (dir_offset[curDirLever].cur_page_last_offset > 0) {
|
|
|
|
list_file.Sd_file_cnt = 0;
|
|
|
|
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1;
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
file_count = search_file();
|
|
|
|
#endif
|
|
|
|
if (file_count != 0) {
|
|
|
|
dir_offset[curDirLever].curPage++;
|
|
|
|
lv_clear_print_file();
|
|
|
|
disp_gcode_icon(file_count);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-10-24 04:37:45 +00:00
|
|
|
if (file_count < FILE_NUM)
|
|
|
|
dir_offset[curDirLever].cur_page_last_offset = 0;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (obj->mks_obj_id == ID_P_RETURN) {
|
2020-10-24 04:37:45 +00:00
|
|
|
if (curDirLever > 0) {
|
|
|
|
int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/');
|
|
|
|
if (ch) {
|
|
|
|
*ch = 0;
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
card.cdup();
|
|
|
|
#endif
|
|
|
|
dir_offset[curDirLever].curPage = 0;
|
|
|
|
dir_offset[curDirLever].cur_page_first_offset = 0;
|
|
|
|
dir_offset[curDirLever].cur_page_last_offset = 0;
|
|
|
|
curDirLever--;
|
|
|
|
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
file_count = search_file();
|
|
|
|
#endif
|
2020-09-21 01:55:02 +00:00
|
|
|
lv_clear_print_file();
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_gcode_icon(file_count);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-24 04:37:45 +00:00
|
|
|
else {
|
|
|
|
lv_clear_print_file();
|
2021-04-13 22:34:19 +00:00
|
|
|
TERN(MULTI_VOLUME, lv_draw_media_select(), lv_draw_ready_print());
|
2020-10-24 04:37:45 +00:00
|
|
|
}
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; i < FILE_BTN_CNT; i++) {
|
|
|
|
if (obj->mks_obj_id == (i + 1)) {
|
2020-10-24 04:37:45 +00:00
|
|
|
if (list_file.file_name[i][0] != 0) {
|
|
|
|
if (list_file.IsFolder[i]) {
|
|
|
|
strcpy(list_file.curDirPath, list_file.file_name[i]);
|
|
|
|
curDirLever++;
|
|
|
|
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
file_count = search_file();
|
|
|
|
#endif
|
|
|
|
lv_clear_print_file();
|
|
|
|
disp_gcode_icon(file_count);
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-10-24 04:37:45 +00:00
|
|
|
else {
|
|
|
|
sel_id = i;
|
|
|
|
lv_clear_print_file();
|
|
|
|
lv_draw_dialog(DIALOG_TYPE_PRINT_FILE);
|
|
|
|
}
|
|
|
|
break;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 06:23:56 +00:00
|
|
|
void lv_draw_print_file() {
|
2020-06-16 02:05:33 +00:00
|
|
|
//uint8_t i;
|
|
|
|
uint8_t file_count;
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
curDirLever = 0;
|
2020-06-16 02:05:33 +00:00
|
|
|
dir_offset[curDirLever].curPage = 0;
|
|
|
|
|
|
|
|
list_file.Sd_file_offset = 0;
|
2020-10-24 04:37:45 +00:00
|
|
|
list_file.Sd_file_cnt = 0;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
ZERO(dir_offset);
|
|
|
|
ZERO(list_file.IsFolder);
|
|
|
|
ZERO(list_file.curDirPath);
|
|
|
|
|
|
|
|
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
card.mount();
|
|
|
|
file_count = search_file();
|
|
|
|
#endif
|
|
|
|
disp_gcode_icon(file_count);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
//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);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
/*
|
2020-10-21 17:45:27 +00:00
|
|
|
if (gCfgItems.multiple_language) {
|
2020-06-16 02:05:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2020-09-21 01:55:02 +00:00
|
|
|
static char test_public_buf_l[40];
|
2020-06-16 02:05:33 +00:00
|
|
|
void disp_gcode_icon(uint8_t file_num) {
|
|
|
|
uint8_t i;
|
|
|
|
|
2021-04-13 22:34:19 +00:00
|
|
|
// TODO: set current media title?!
|
2020-10-27 20:09:19 +00:00
|
|
|
scr = lv_screen_create(PRINT_FILE_UI, "");
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-09-21 00:07:59 +00:00
|
|
|
// Create image buttons
|
2020-10-23 01:22:17 +00:00
|
|
|
buttonPageUp = lv_imgbtn_create(scr, "F:/bmp_pageUp.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_UP);
|
|
|
|
buttonPageDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_P_DOWN);
|
|
|
|
buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL * 2 + INTERVAL_H * 2, event_handler, ID_P_RETURN);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-09-21 00:07:59 +00:00
|
|
|
// Create labels on the image buttons
|
2020-06-16 02:05:33 +00:00
|
|
|
for (i = 0; i < FILE_BTN_CNT; i++) {
|
|
|
|
/*
|
2020-07-25 05:52:07 +00:00
|
|
|
if (seq) {
|
2020-06-16 02:05:33 +00:00
|
|
|
j = (FILE_BTN_CNT-1) - i;
|
|
|
|
back_flg = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
j = i;
|
|
|
|
back_flg = 0;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (i >= file_num) break;
|
|
|
|
|
|
|
|
#ifdef TFT35
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonGcode[i] = lv_imgbtn_create(scr, nullptr);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_imgbtn_use_label_style(buttonGcode[i]);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_clear_protect(buttonGcode[i], LV_PROTECT_FOLLOW);
|
|
|
|
lv_btn_set_layout(buttonGcode[i], LV_LAYOUT_OFF);
|
|
|
|
|
|
|
|
ZERO(public_buf_m);
|
2020-10-24 04:37:45 +00:00
|
|
|
cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
if (list_file.IsFolder[i]) {
|
2020-11-11 01:39:34 +00:00
|
|
|
lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), "", 0);
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_dir.bin");
|
2020-06-16 02:05:33 +00:00
|
|
|
if (i < 3)
|
|
|
|
lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight);
|
|
|
|
else
|
|
|
|
lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (have_pre_pic((char *)list_file.file_name[i])) {
|
2020-09-21 01:55:02 +00:00
|
|
|
|
|
|
|
//lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), list_file.file_name[i], 1);
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
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");
|
2020-12-28 05:15:01 +00:00
|
|
|
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);
|
2020-06-16 02:05:33 +00:00
|
|
|
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);
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonText[i] = lv_btn_create(scr, nullptr);
|
2020-06-16 02:05:33 +00:00
|
|
|
//lv_obj_set_event_cb(buttonText[i], event_handler);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_btn_use_label_style(buttonText[i]);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW);
|
|
|
|
lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF);
|
2020-11-11 01:39:34 +00:00
|
|
|
//lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),"", 0);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET + 100);
|
|
|
|
lv_obj_set_size(buttonText[i], 100, 40);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lv_obj_set_pos(buttonGcode[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);
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonText[i] = lv_btn_create(scr, nullptr);
|
2020-06-16 02:05:33 +00:00
|
|
|
//lv_obj_set_event_cb(buttonText[i], event_handler);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_btn_use_label_style(buttonText[i]);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW);
|
|
|
|
lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF);
|
2020-11-11 01:39:34 +00:00
|
|
|
//lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),"", 0);
|
2020-06-16 02:05:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-10-23 01:22:17 +00:00
|
|
|
labelPageUp[i] = lv_label_create(buttonText[i], public_buf_m);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_align(labelPageUp[i], buttonText[i], LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
|
|
|
}
|
|
|
|
else {
|
2020-11-11 01:39:34 +00:00
|
|
|
lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), "", 0);
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_file.bin");
|
2020-06-16 02:05:33 +00:00
|
|
|
if (i < 3)
|
|
|
|
lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight);
|
|
|
|
else
|
|
|
|
lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight);
|
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5);
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 01:55:02 +00:00
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonGcode[i]);
|
|
|
|
#endif
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#else // !TFT35
|
|
|
|
#endif // !TFT35
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-09-21 01:55:02 +00:00
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) {
|
|
|
|
lv_group_add_obj(g, buttonPageUp);
|
|
|
|
lv_group_add_obj(g, buttonPageDown);
|
|
|
|
lv_group_add_obj(g, buttonBack);
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
uint32_t lv_open_gcode_file(char *path) {
|
2020-06-16 02:05:33 +00:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2020-07-25 05:52:07 +00:00
|
|
|
uint32_t *ps4;
|
2020-12-28 05:15:01 +00:00
|
|
|
uint32_t pre_sread_cnt = UINT32_MAX;
|
2020-06-16 02:05:33 +00:00
|
|
|
char *cur_name;
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2020-06-16 02:05:33 +00:00
|
|
|
cur_name = strrchr(path, '/');
|
2020-07-25 05:52:07 +00:00
|
|
|
|
2020-06-16 02:05:33 +00:00
|
|
|
card.openFileRead(cur_name);
|
2020-07-25 05:52:07 +00:00
|
|
|
card.read(public_buf, 512);
|
|
|
|
ps4 = (uint32_t *)strstr((char *)public_buf, ";simage:");
|
|
|
|
// Ignore the beginning message of gcode file
|
|
|
|
if (ps4) {
|
|
|
|
pre_sread_cnt = (uint32_t)ps4 - (uint32_t)((uint32_t *)(&public_buf[0]));
|
|
|
|
card.setIndex(pre_sread_cnt);
|
|
|
|
}
|
2020-09-21 01:55:02 +00:00
|
|
|
return pre_sread_cnt;
|
2020-07-25 05:52:07 +00:00
|
|
|
#endif // SDSUPPORT
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ascii2dec_test(char *ascii) {
|
|
|
|
int result = 0;
|
|
|
|
if (ascii == 0) return 0;
|
|
|
|
|
|
|
|
if (*(ascii) >= '0' && *(ascii) <= '9')
|
|
|
|
result = *(ascii) - '0';
|
|
|
|
else if (*(ascii) >= 'a' && *(ascii) <= 'f')
|
2020-10-09 21:50:17 +00:00
|
|
|
result = *(ascii) - 'a' + 0x0A;
|
2020-06-16 02:05:33 +00:00
|
|
|
else if (*(ascii) >= 'A' && *(ascii) <= 'F')
|
2020-10-09 21:50:17 +00:00
|
|
|
result = *(ascii) - 'A' + 0x0A;
|
2020-06-16 02:05:33 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
void lv_gcode_file_read(uint8_t *data_buf) {
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
uint16_t i = 0, j = 0, k = 0;
|
|
|
|
uint16_t row_1 = 0;
|
2020-07-01 06:30:24 +00:00
|
|
|
bool ignore_start = true;
|
2020-06-16 02:05:33 +00:00
|
|
|
char temp_test[200];
|
2020-07-01 06:30:24 +00:00
|
|
|
volatile uint16_t *p_index;
|
|
|
|
|
2020-12-28 05:15:01 +00:00
|
|
|
watchdog_refresh();
|
2020-07-01 06:30:24 +00:00
|
|
|
memset(public_buf, 0, 200);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
while (card.isFileOpen()) {
|
|
|
|
if (ignore_start) card.read(temp_test, 8); // line start -> ignore
|
|
|
|
card.read(temp_test, 200); // data
|
|
|
|
// \r;;gimage: we got the bit img, so stop here
|
2020-07-01 06:30:24 +00:00
|
|
|
if (temp_test[1] == ';') {
|
|
|
|
card.closefile();
|
|
|
|
break;
|
|
|
|
}
|
2020-07-25 05:52:07 +00:00
|
|
|
for (i = 0; i < 200;) {
|
|
|
|
public_buf[row_1 * 200 + 100 * k + j] = (char)(ascii2dec_test(&temp_test[i]) << 4 | ascii2dec_test(&temp_test[i + 1]));
|
2020-06-16 02:05:33 +00:00
|
|
|
j++;
|
2020-07-25 05:52:07 +00:00
|
|
|
i += 2;
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-07-01 06:30:24 +00:00
|
|
|
|
|
|
|
uint16_t c = card.get();
|
2020-12-29 04:07:11 +00:00
|
|
|
// check for more data or end of line (CR or LF)
|
|
|
|
if (ISEOL(c)) {
|
|
|
|
c = card.get(); // more eol?
|
|
|
|
if (!ISEOL(c)) card.setIndex(card.getIndex() - 1);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-28 05:15:01 +00:00
|
|
|
card.setIndex(card.getIndex() - 1);
|
2020-07-01 06:30:24 +00:00
|
|
|
k++;
|
2020-07-25 05:52:07 +00:00
|
|
|
j = 0;
|
2020-07-01 06:30:24 +00:00
|
|
|
ignore_start = false;
|
2020-12-29 04:07:11 +00:00
|
|
|
if (k > 1) {
|
|
|
|
card.closefile();
|
|
|
|
break;
|
|
|
|
}
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
2020-10-15 08:00:27 +00:00
|
|
|
#if HAS_TFT_LVGL_UI_SPI
|
2020-07-25 05:52:07 +00:00
|
|
|
for (i = 0; i < 200;) {
|
2020-07-01 06:30:24 +00:00
|
|
|
p_index = (uint16_t *)(&public_buf[i]);
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
//Color = (*p_index >> 8);
|
2020-10-09 21:50:17 +00:00
|
|
|
//*p_index = Color | ((*p_index & 0xFF) << 8);
|
2020-07-25 05:52:07 +00:00
|
|
|
i += 2;
|
|
|
|
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
|
2020-07-01 06:30:24 +00:00
|
|
|
}
|
2020-10-15 08:00:27 +00:00
|
|
|
#else // !HAS_TFT_LVGL_UI_SPI
|
2020-07-25 05:52:07 +00:00
|
|
|
for (i = 0; i < 200;) {
|
2020-07-01 06:30:24 +00:00
|
|
|
p_index = (uint16_t *)(&public_buf[i]);
|
|
|
|
//Color = (*p_index >> 8);
|
2020-10-09 21:50:17 +00:00
|
|
|
//*p_index = Color | ((*p_index & 0xFF) << 8);
|
2020-07-25 05:52:07 +00:00
|
|
|
i += 2;
|
2020-07-25 06:53:07 +00:00
|
|
|
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3;
|
2020-07-01 06:30:24 +00:00
|
|
|
}
|
2020-10-15 08:00:27 +00:00
|
|
|
#endif // !HAS_TFT_LVGL_UI_SPI
|
2020-07-25 05:52:07 +00:00
|
|
|
memcpy(data_buf, public_buf, 200);
|
|
|
|
#endif // SDSUPPORT
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_close_gcode_file() {TERN_(SDSUPPORT, card.closefile());}
|
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
void lv_gcode_file_seek(uint32_t pos) {
|
|
|
|
card.setIndex(pos);
|
|
|
|
}
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
void cutFileName(char *path, int len, int bytePerLine, char *outStr) {
|
2020-06-16 02:05:33 +00:00
|
|
|
#if _LFN_UNICODE
|
|
|
|
TCHAR *tmpFile;
|
|
|
|
TCHAR *strIndex1 = 0, *strIndex2 = 0, *beginIndex;
|
2020-07-25 05:52:07 +00:00
|
|
|
TCHAR secSeg[10] = {0};
|
2020-06-16 02:05:33 +00:00
|
|
|
TCHAR gFileTail[4] = {'~', '.', 'g', '\0'};
|
|
|
|
#else
|
|
|
|
char *tmpFile;
|
|
|
|
char *strIndex1 = 0, *strIndex2 = 0, *beginIndex;
|
|
|
|
char secSeg[10] = {0};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (path == 0 || len <= 3 || outStr == 0) return;
|
|
|
|
|
|
|
|
tmpFile = path;
|
|
|
|
#if _LFN_UNICODE
|
|
|
|
strIndex1 = (WCHAR *)wcsstr((const WCHAR *)tmpFile, (const WCHAR *)'/');
|
|
|
|
strIndex2 = (WCHAR *)wcsstr((const WCHAR *)tmpFile, (const WCHAR *)'.');
|
|
|
|
#else
|
|
|
|
strIndex1 = (char *)strrchr(tmpFile, '/');
|
|
|
|
strIndex2 = (char *)strrchr(tmpFile, '.');
|
|
|
|
#endif
|
|
|
|
|
|
|
|
beginIndex = (strIndex1 != 0
|
2020-07-25 06:53:07 +00:00
|
|
|
//&& (strIndex2 != 0) && (strIndex1 < strIndex2)
|
2020-06-16 02:05:33 +00:00
|
|
|
) ? strIndex1 + 1 : tmpFile;
|
|
|
|
|
|
|
|
if (strIndex2 == 0 || (strIndex1 > strIndex2)) { // not gcode file
|
|
|
|
#if _LFN_UNICODE
|
|
|
|
if (wcslen(beginIndex) > len)
|
|
|
|
wcsncpy(outStr, beginIndex, len);
|
|
|
|
else
|
|
|
|
wcscpy(outStr, beginIndex);
|
|
|
|
#else
|
|
|
|
if ((int)strlen(beginIndex) > len)
|
|
|
|
strncpy(outStr, beginIndex, len);
|
|
|
|
else
|
|
|
|
strcpy(outStr, beginIndex);
|
|
|
|
#endif
|
|
|
|
}
|
2020-07-25 05:52:07 +00:00
|
|
|
else { // gcode file
|
2020-06-16 02:05:33 +00:00
|
|
|
if (strIndex2 - beginIndex > (len - 2)) {
|
|
|
|
#if _LFN_UNICODE
|
|
|
|
wcsncpy(outStr, (const WCHAR *)beginIndex, len - 3);
|
|
|
|
wcscat(outStr, (const WCHAR *)gFileTail);
|
|
|
|
#else
|
|
|
|
//strncpy(outStr, beginIndex, len - 3);
|
|
|
|
strncpy(outStr, beginIndex, len - 4);
|
2020-07-25 05:52:07 +00:00
|
|
|
strcat_P(outStr, PSTR("~.g"));
|
2020-06-16 02:05:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#if _LFN_UNICODE
|
|
|
|
wcsncpy(outStr, (const WCHAR *)beginIndex, strIndex2 - beginIndex + 1);
|
|
|
|
wcscat(outStr, (const WCHAR *)&gFileTail[3]);
|
|
|
|
#else
|
|
|
|
strncpy(outStr, beginIndex, strIndex2 - beginIndex + 1);
|
2020-07-25 05:52:07 +00:00
|
|
|
strcat_P(outStr, PSTR("g"));
|
2020-06-16 02:05:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if _LFN_UNICODE
|
|
|
|
if (wcslen(outStr) > bytePerLine) {
|
|
|
|
wcscpy(secSeg, (const WCHAR *)&outStr[bytePerLine]);
|
2020-07-25 05:52:07 +00:00
|
|
|
outStr[bytePerLine] = '\n';
|
2020-06-16 02:05:33 +00:00
|
|
|
outStr[bytePerLine + 1] = '\0';
|
|
|
|
wcscat(outStr, (const WCHAR *)secSeg);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((int)strlen(outStr) > bytePerLine) {
|
|
|
|
strcpy(secSeg, &outStr[bytePerLine]);
|
2020-07-25 05:52:07 +00:00
|
|
|
outStr[bytePerLine] = '\n';
|
2020-06-16 02:05:33 +00:00
|
|
|
outStr[bytePerLine + 1] = '\0';
|
|
|
|
strcat(outStr, secSeg);
|
|
|
|
}
|
|
|
|
else {
|
2020-07-25 05:52:07 +00:00
|
|
|
strcat_P(outStr, PSTR("\n"));
|
2020-06-16 02:05:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
void lv_clear_print_file() {
|
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
|
|
|
|
#endif
|
|
|
|
lv_obj_del(scr);
|
|
|
|
}
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#endif // HAS_TFT_LVGL_UI
|