My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

draw_print_file.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "draw_ui.h"
  25. #include <lv_conf.h>
  26. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  27. //#include "../lvgl/src/lv_objx/lv_img.h"
  28. //#include "../lvgl/src/lv_core/lv_disp.h"
  29. //#include "../lvgl/src/lv_core/lv_refr.h"
  30. #include "../../../sd/cardreader.h"
  31. #include "../../../inc/MarlinConfig.h"
  32. static lv_obj_t *scr;
  33. extern lv_group_t* g;
  34. static lv_obj_t *buttonPageUp, *buttonPageDown, *buttonBack,
  35. *buttonGcode[FILE_BTN_CNT], *labelPageUp[FILE_BTN_CNT], *buttonText[FILE_BTN_CNT];
  36. enum {
  37. ID_P_UP = 7,
  38. ID_P_DOWN,
  39. ID_P_RETURN
  40. };
  41. int8_t curDirLever = 0;
  42. LIST_FILE list_file;
  43. DIR_OFFSET dir_offset[10];
  44. extern uint8_t public_buf[513];
  45. extern char public_buf_m[100];
  46. uint8_t sel_id = 0;
  47. #if ENABLED(SDSUPPORT)
  48. static uint8_t search_file() {
  49. int valid_name_cnt = 0;
  50. //char tmp[SHORT_NEME_LEN*MAX_DIR_LEVEL+1];
  51. list_file.Sd_file_cnt = 0;
  52. //list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
  53. //root2.rewind();
  54. //SERIAL_ECHOLN(list_file.curDirPath);
  55. if (curDirLever != 0)
  56. card.cd(list_file.curDirPath);
  57. else
  58. card.cdroot();
  59. const uint16_t fileCnt = card.get_num_Files();
  60. for (uint16_t i = 0; i < fileCnt; i++) {
  61. if (list_file.Sd_file_cnt == list_file.Sd_file_offset) {
  62. card.getfilename_sorted(SD_ORDER(i, fileCnt));
  63. list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir;
  64. strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath);
  65. strcat_P(list_file.file_name[valid_name_cnt], PSTR("/"));
  66. strcat(list_file.file_name[valid_name_cnt], card.filename);
  67. strcpy(list_file.long_name[valid_name_cnt], card.longest_filename());
  68. valid_name_cnt++;
  69. if (valid_name_cnt == 1)
  70. dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset;
  71. if (valid_name_cnt >= FILE_NUM) {
  72. dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset;
  73. list_file.Sd_file_offset++;
  74. break;
  75. }
  76. list_file.Sd_file_offset++;
  77. }
  78. list_file.Sd_file_cnt++;
  79. }
  80. //card.closefile(false);
  81. return valid_name_cnt;
  82. }
  83. #endif // SDSUPPORT
  84. bool have_pre_pic(char *path) {
  85. #if ENABLED(SDSUPPORT)
  86. char *ps1, *ps2, *cur_name = strrchr(path, '/');
  87. card.openFileRead(cur_name);
  88. card.read(public_buf, 512);
  89. ps1 = strstr((char *)public_buf, ";simage:");
  90. card.read(public_buf, 512);
  91. ps2 = strstr((char *)public_buf, ";simage:");
  92. card.closefile();
  93. if (ps1 || ps2) return true;
  94. #endif
  95. return false;
  96. }
  97. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  98. if (event != LV_EVENT_RELEASED) return;
  99. uint8_t i, file_count = 0;
  100. //switch (obj->mks_obj_id)
  101. //{
  102. if (obj->mks_obj_id == ID_P_UP) {
  103. if (dir_offset[curDirLever].curPage > 0) {
  104. // 2015.05.19
  105. list_file.Sd_file_cnt = 0;
  106. if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM)
  107. list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM;
  108. #if ENABLED(SDSUPPORT)
  109. file_count = search_file();
  110. #endif
  111. if (file_count != 0) {
  112. dir_offset[curDirLever].curPage--;
  113. lv_clear_print_file();
  114. disp_gcode_icon(file_count);
  115. }
  116. }
  117. }
  118. else if (obj->mks_obj_id == ID_P_DOWN) {
  119. if (dir_offset[curDirLever].cur_page_last_offset > 0) {
  120. list_file.Sd_file_cnt = 0;
  121. list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1;
  122. #if ENABLED(SDSUPPORT)
  123. file_count = search_file();
  124. #endif
  125. if (file_count != 0) {
  126. dir_offset[curDirLever].curPage++;
  127. lv_clear_print_file();
  128. disp_gcode_icon(file_count);
  129. }
  130. if (file_count < FILE_NUM)
  131. dir_offset[curDirLever].cur_page_last_offset = 0;
  132. }
  133. }
  134. else if (obj->mks_obj_id == ID_P_RETURN) {
  135. if (curDirLever > 0) {
  136. int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/');
  137. if (ch) {
  138. *ch = 0;
  139. #if ENABLED(SDSUPPORT)
  140. card.cdup();
  141. #endif
  142. dir_offset[curDirLever].curPage = 0;
  143. dir_offset[curDirLever].cur_page_first_offset = 0;
  144. dir_offset[curDirLever].cur_page_last_offset = 0;
  145. curDirLever--;
  146. list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
  147. #if ENABLED(SDSUPPORT)
  148. file_count = search_file();
  149. #endif
  150. lv_clear_print_file();
  151. disp_gcode_icon(file_count);
  152. }
  153. }
  154. else {
  155. lv_clear_print_file();
  156. TERN(MULTI_VOLUME, lv_draw_media_select(), lv_draw_ready_print());
  157. }
  158. }
  159. else {
  160. for (i = 0; i < FILE_BTN_CNT; i++) {
  161. if (obj->mks_obj_id == (i + 1)) {
  162. if (list_file.file_name[i][0] != 0) {
  163. if (list_file.IsFolder[i]) {
  164. strcpy(list_file.curDirPath, list_file.file_name[i]);
  165. curDirLever++;
  166. list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
  167. #if ENABLED(SDSUPPORT)
  168. file_count = search_file();
  169. #endif
  170. lv_clear_print_file();
  171. disp_gcode_icon(file_count);
  172. }
  173. else {
  174. sel_id = i;
  175. lv_clear_print_file();
  176. lv_draw_dialog(DIALOG_TYPE_PRINT_FILE);
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. void lv_draw_print_file() {
  185. //uint8_t i;
  186. uint8_t file_count;
  187. curDirLever = 0;
  188. dir_offset[curDirLever].curPage = 0;
  189. list_file.Sd_file_offset = 0;
  190. list_file.Sd_file_cnt = 0;
  191. ZERO(dir_offset);
  192. ZERO(list_file.IsFolder);
  193. ZERO(list_file.curDirPath);
  194. list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
  195. #if ENABLED(SDSUPPORT)
  196. card.mount();
  197. file_count = search_file();
  198. #endif
  199. disp_gcode_icon(file_count);
  200. //lv_obj_t *labelPageUp = lv_label_create_empty(buttonPageUp);
  201. //lv_obj_t *labelPageDown = lv_label_create_empty(buttonPageDown);
  202. //lv_obj_t *label_Back = lv_label_create_empty(buttonBack);
  203. /*
  204. if (gCfgItems.multiple_language) {
  205. lv_label_set_text(labelPageUp, tool_menu.preheat);
  206. lv_obj_align(labelPageUp, buttonPageUp, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  207. lv_label_set_text(labelPageDown, tool_menu.extrude);
  208. lv_obj_align(labelPageDown, buttonPageDown, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  209. lv_label_set_text(label_Back, common_menu.text_back);
  210. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  211. }
  212. */
  213. }
  214. static char test_public_buf_l[40];
  215. void disp_gcode_icon(uint8_t file_num) {
  216. uint8_t i;
  217. // TODO: set current media title?!
  218. scr = lv_screen_create(PRINT_FILE_UI, "");
  219. // Create image buttons
  220. buttonPageUp = lv_imgbtn_create(scr, "F:/bmp_pageUp.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_UP);
  221. 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);
  222. 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);
  223. // Create labels on the image buttons
  224. for (i = 0; i < FILE_BTN_CNT; i++) {
  225. /*
  226. if (seq) {
  227. j = (FILE_BTN_CNT-1) - i;
  228. back_flg = 1;
  229. }
  230. else {
  231. j = i;
  232. back_flg = 0;
  233. }
  234. */
  235. if (i >= file_num) break;
  236. #ifdef TFT35
  237. buttonGcode[i] = lv_imgbtn_create(scr, nullptr);
  238. lv_imgbtn_use_label_style(buttonGcode[i]);
  239. lv_obj_clear_protect(buttonGcode[i], LV_PROTECT_FOLLOW);
  240. lv_btn_set_layout(buttonGcode[i], LV_LAYOUT_OFF);
  241. ZERO(public_buf_m);
  242. cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m);
  243. if (list_file.IsFolder[i]) {
  244. lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), "", 0);
  245. lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_dir.bin");
  246. if (i < 3)
  247. lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight);
  248. else
  249. lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  250. labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m);
  251. lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5);
  252. }
  253. else {
  254. if (have_pre_pic((char *)list_file.file_name[i])) {
  255. //lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), list_file.file_name[i], 1);
  256. strcpy(test_public_buf_l, "S:");
  257. strcat(test_public_buf_l, list_file.file_name[i]);
  258. char *temp = strstr(test_public_buf_l, ".GCO");
  259. if (temp) strcpy(temp, ".bin");
  260. lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), test_public_buf_l, 0);
  261. lv_imgbtn_set_src_both(buttonGcode[i], buttonGcode[i]->mks_pic_name);
  262. if (i < 3) {
  263. 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);
  264. buttonText[i] = lv_btn_create(scr, nullptr);
  265. //lv_obj_set_event_cb(buttonText[i], event_handler);
  266. lv_btn_use_label_style(buttonText[i]);
  267. lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW);
  268. lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF);
  269. //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),"", 0);
  270. 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);
  271. lv_obj_set_size(buttonText[i], 100, 40);
  272. }
  273. else {
  274. 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);
  275. buttonText[i] = lv_btn_create(scr, nullptr);
  276. //lv_obj_set_event_cb(buttonText[i], event_handler);
  277. lv_btn_use_label_style(buttonText[i]);
  278. lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW);
  279. lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF);
  280. //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),"", 0);
  281. 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);
  282. lv_obj_set_size(buttonText[i], 100, 40);
  283. }
  284. labelPageUp[i] = lv_label_create(buttonText[i], public_buf_m);
  285. lv_obj_align(labelPageUp[i], buttonText[i], LV_ALIGN_IN_BOTTOM_MID, 0, 0);
  286. }
  287. else {
  288. lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), "", 0);
  289. lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_file.bin");
  290. if (i < 3)
  291. lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight);
  292. else
  293. lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  294. labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m);
  295. lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5);
  296. }
  297. }
  298. #if HAS_ROTARY_ENCODER
  299. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonGcode[i]);
  300. #endif
  301. #else // !TFT35
  302. #endif // !TFT35
  303. }
  304. #if HAS_ROTARY_ENCODER
  305. if (gCfgItems.encoder_enable) {
  306. lv_group_add_obj(g, buttonPageUp);
  307. lv_group_add_obj(g, buttonPageDown);
  308. lv_group_add_obj(g, buttonBack);
  309. }
  310. #endif
  311. }
  312. uint32_t lv_open_gcode_file(char *path) {
  313. #if ENABLED(SDSUPPORT)
  314. uint32_t *ps4;
  315. uintptr_t pre_sread_cnt = UINTPTR_MAX;
  316. char *cur_name;
  317. cur_name = strrchr(path, '/');
  318. card.openFileRead(cur_name);
  319. card.read(public_buf, 512);
  320. ps4 = (uint32_t *)strstr((char *)public_buf, ";simage:");
  321. // Ignore the beginning message of G-code file
  322. if (ps4) {
  323. pre_sread_cnt = (uintptr_t)ps4 - (uintptr_t)((uint32_t *)(&public_buf[0]));
  324. card.setIndex(pre_sread_cnt);
  325. }
  326. return pre_sread_cnt;
  327. #endif // SDSUPPORT
  328. }
  329. int ascii2dec_test(char *ascii) {
  330. int result = 0;
  331. if (ascii == 0) return 0;
  332. if (*(ascii) >= '0' && *(ascii) <= '9')
  333. result = *(ascii) - '0';
  334. else if (*(ascii) >= 'a' && *(ascii) <= 'f')
  335. result = *(ascii) - 'a' + 0x0A;
  336. else if (*(ascii) >= 'A' && *(ascii) <= 'F')
  337. result = *(ascii) - 'A' + 0x0A;
  338. else
  339. return 0;
  340. return result;
  341. }
  342. void lv_gcode_file_read(uint8_t *data_buf) {
  343. #if ENABLED(SDSUPPORT)
  344. uint16_t i = 0, j = 0, k = 0;
  345. uint16_t row_1 = 0;
  346. bool ignore_start = true;
  347. char temp_test[200];
  348. volatile uint16_t *p_index;
  349. hal.watchdog_refresh();
  350. memset(public_buf, 0, 200);
  351. while (card.isFileOpen()) {
  352. if (ignore_start) card.read(temp_test, 8); // line start -> ignore
  353. card.read(temp_test, 200); // data
  354. // \r;;gimage: we got the bit img, so stop here
  355. if (temp_test[1] == ';') {
  356. card.closefile();
  357. break;
  358. }
  359. for (i = 0; i < 200;) {
  360. public_buf[row_1 * 200 + 100 * k + j] = (char)(ascii2dec_test(&temp_test[i]) << 4 | ascii2dec_test(&temp_test[i + 1]));
  361. j++;
  362. i += 2;
  363. }
  364. uint16_t c = card.get();
  365. // check for more data or end of line (CR or LF)
  366. if (ISEOL(c)) {
  367. c = card.get(); // more eol?
  368. if (!ISEOL(c)) card.setIndex(card.getIndex() - 1);
  369. break;
  370. }
  371. card.setIndex(card.getIndex() - 1);
  372. k++;
  373. j = 0;
  374. ignore_start = false;
  375. if (k > 1) {
  376. card.closefile();
  377. break;
  378. }
  379. }
  380. #if HAS_TFT_LVGL_UI_SPI
  381. for (i = 0; i < 200;) {
  382. p_index = (uint16_t *)(&public_buf[i]);
  383. //Color = (*p_index >> 8);
  384. //*p_index = Color | ((*p_index & 0xFF) << 8);
  385. i += 2;
  386. if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
  387. }
  388. #else // !HAS_TFT_LVGL_UI_SPI
  389. for (i = 0; i < 200;) {
  390. p_index = (uint16_t *)(&public_buf[i]);
  391. //Color = (*p_index >> 8);
  392. //*p_index = Color | ((*p_index & 0xFF) << 8);
  393. i += 2;
  394. if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3;
  395. }
  396. #endif // !HAS_TFT_LVGL_UI_SPI
  397. memcpy(data_buf, public_buf, 200);
  398. #endif // SDSUPPORT
  399. }
  400. void lv_close_gcode_file() {TERN_(SDSUPPORT, card.closefile());}
  401. void lv_gcode_file_seek(uint32_t pos) {
  402. card.setIndex(pos);
  403. }
  404. void cutFileName(char *path, int len, int bytePerLine, char *outStr) {
  405. #if _LFN_UNICODE
  406. TCHAR *tmpFile;
  407. TCHAR *strIndex1 = 0, *strIndex2 = 0, *beginIndex;
  408. TCHAR secSeg[10] = {0};
  409. TCHAR gFileTail[4] = {'~', '.', 'g', '\0'};
  410. #else
  411. char *tmpFile;
  412. char *strIndex1 = 0, *strIndex2 = 0, *beginIndex;
  413. char secSeg[10] = {0};
  414. #endif
  415. if (path == 0 || len <= 3 || outStr == 0) return;
  416. tmpFile = path;
  417. #if _LFN_UNICODE
  418. strIndex1 = (WCHAR *)wcsstr((const WCHAR *)tmpFile, (const WCHAR *)'/');
  419. strIndex2 = (WCHAR *)wcsstr((const WCHAR *)tmpFile, (const WCHAR *)'.');
  420. #else
  421. strIndex1 = (char *)strrchr(tmpFile, '/');
  422. strIndex2 = (char *)strrchr(tmpFile, '.');
  423. #endif
  424. beginIndex = (strIndex1 != 0
  425. //&& (strIndex2 != 0) && (strIndex1 < strIndex2)
  426. ) ? strIndex1 + 1 : tmpFile;
  427. if (strIndex2 == 0 || (strIndex1 > strIndex2)) { // not G-code file
  428. #if _LFN_UNICODE
  429. if (wcslen(beginIndex) > len)
  430. wcsncpy(outStr, beginIndex, len);
  431. else
  432. wcscpy(outStr, beginIndex);
  433. #else
  434. if ((int)strlen(beginIndex) > len)
  435. strncpy(outStr, beginIndex, len);
  436. else
  437. strcpy(outStr, beginIndex);
  438. #endif
  439. }
  440. else { // G-code file
  441. if (strIndex2 - beginIndex > (len - 2)) {
  442. #if _LFN_UNICODE
  443. wcsncpy(outStr, (const WCHAR *)beginIndex, len - 3);
  444. wcscat(outStr, (const WCHAR *)gFileTail);
  445. #else
  446. //strncpy(outStr, beginIndex, len - 3);
  447. strncpy(outStr, beginIndex, len - 4);
  448. strcat_P(outStr, PSTR("~.g"));
  449. #endif
  450. }
  451. else {
  452. #if _LFN_UNICODE
  453. wcsncpy(outStr, (const WCHAR *)beginIndex, strIndex2 - beginIndex + 1);
  454. wcscat(outStr, (const WCHAR *)&gFileTail[3]);
  455. #else
  456. strncpy(outStr, beginIndex, strIndex2 - beginIndex + 1);
  457. strcat_P(outStr, PSTR("g"));
  458. #endif
  459. }
  460. }
  461. #if _LFN_UNICODE
  462. if (wcslen(outStr) > bytePerLine) {
  463. wcscpy(secSeg, (const WCHAR *)&outStr[bytePerLine]);
  464. outStr[bytePerLine] = '\n';
  465. outStr[bytePerLine + 1] = '\0';
  466. wcscat(outStr, (const WCHAR *)secSeg);
  467. }
  468. #else
  469. if ((int)strlen(outStr) > bytePerLine) {
  470. strcpy(secSeg, &outStr[bytePerLine]);
  471. outStr[bytePerLine] = '\n';
  472. outStr[bytePerLine + 1] = '\0';
  473. strcat(outStr, secSeg);
  474. }
  475. else {
  476. strcat_P(outStr, PSTR("\n"));
  477. }
  478. #endif
  479. }
  480. void lv_clear_print_file() {
  481. #if HAS_ROTARY_ENCODER
  482. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  483. #endif
  484. lv_obj_del(scr);
  485. }
  486. #endif // HAS_TFT_LVGL_UI