My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

draw_ui.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. #pragma once
  23. #include <lvgl.h>
  24. #include <stdint.h>
  25. #include <string.h>
  26. // the colors of the last MKS Ui
  27. #undef LV_COLOR_BACKGROUND
  28. #define LV_COLOR_BACKGROUND LV_COLOR_MAKE(0x1A, 0x1A, 0x1A)
  29. #define TFT_LV_PARA_BACK_BODY_COLOR LV_COLOR_MAKE(0x4A, 0x52, 0xFF)
  30. #include "tft_lvgl_configuration.h"
  31. #include "tft_multi_language.h"
  32. #include "pic_manager.h"
  33. #include "draw_ready_print.h"
  34. #include "draw_language.h"
  35. #include "draw_set.h"
  36. #include "draw_tool.h"
  37. #include "draw_print_file.h"
  38. #include "draw_dialog.h"
  39. #include "draw_printing.h"
  40. #include "draw_operation.h"
  41. #include "draw_preHeat.h"
  42. #include "draw_extrusion.h"
  43. #include "draw_home.h"
  44. #include "draw_gcode.h"
  45. #include "draw_more.h"
  46. #include "draw_move_motor.h"
  47. #include "draw_fan.h"
  48. #include "draw_about.h"
  49. #include "draw_change_speed.h"
  50. #include "draw_manuaLevel.h"
  51. #include "draw_error_message.h"
  52. #include "printer_operation.h"
  53. #include "draw_machine_para.h"
  54. #include "draw_machine_settings.h"
  55. #include "draw_motor_settings.h"
  56. #include "draw_advance_settings.h"
  57. #include "draw_acceleration_settings.h"
  58. #include "draw_number_key.h"
  59. #include "draw_jerk_settings.h"
  60. #include "draw_pause_position.h"
  61. #include "draw_step_settings.h"
  62. #include "draw_tmc_current_settings.h"
  63. #include "draw_eeprom_settings.h"
  64. #include "draw_max_feedrate_settings.h"
  65. #include "draw_tmc_step_mode_settings.h"
  66. #include "draw_level_settings.h"
  67. #include "draw_manual_level_pos_settings.h"
  68. #include "draw_auto_level_offset_settings.h"
  69. #include "draw_filament_change.h"
  70. #include "draw_filament_settings.h"
  71. #include "draw_homing_sensitivity_settings.h"
  72. #include "draw_baby_stepping.h"
  73. #include "draw_keyboard.h"
  74. #include "draw_encoder_settings.h"
  75. #include "../../../../inc/MarlinConfigPre.h"
  76. #if ENABLED(MKS_WIFI_MODULE)
  77. #include "wifiSerial.h"
  78. #include "wifi_module.h"
  79. #include "wifi_upload.h"
  80. #include "draw_wifi_settings.h"
  81. #include "draw_wifi.h"
  82. #include "draw_wifi_list.h"
  83. #include "draw_wifi_tips.h"
  84. #include "draw_cloud_bind.h"
  85. #endif
  86. #define ESP_WIFI 0x02
  87. #define AP_MODEL 0x01
  88. #define STA_MODEL 0x02
  89. #define FILE_SYS_USB 0
  90. #define FILE_SYS_SD 1
  91. #define TICK_CYCLE 1
  92. #define PARA_SEL_ICON_TEXT_COLOR LV_COLOR_MAKE(0x4A, 0x52, 0xFF);
  93. #define TFT35
  94. #ifdef TFT35
  95. #define TFT_WIDTH 480
  96. #define TFT_HEIGHT 320
  97. #define titleHeight 36 // TFT_screen.title_high
  98. #define INTERVAL_H 2 // TFT_screen.gap_h // 2
  99. #define INTERVAL_V 2 // TFT_screen.gap_v // 2
  100. #define BTN_X_PIXEL 117 // TFT_screen.btn_x_pixel
  101. #define BTN_Y_PIXEL 140 // TFT_screen.btn_y_pixel
  102. #define SIMPLE_FIRST_PAGE_GRAP 30
  103. #define BUTTON_TEXT_Y_OFFSET -20
  104. #define TITLE_XPOS 3 // TFT_screen.title_xpos
  105. #define TITLE_YPOS 5 // TFT_screen.title_ypos
  106. #define FILE_BTN_CNT 6
  107. #define OTHER_BTN_XPIEL 117
  108. #define OTHER_BTN_YPIEL 92
  109. #define FILE_PRE_PIC_X_OFFSET 8
  110. #define FILE_PRE_PIC_Y_OFFSET 0
  111. #define PREVIEW_LITTLE_PIC_SIZE 40910 // 400*100+9*101+1
  112. #define PREVIEW_SIZE 202720 // (PREVIEW_LITTLE_PIC_SIZE+800*200+201*9+1)
  113. // machine parameter ui
  114. #define PARA_UI_POS_X 10
  115. #define PARA_UI_POS_Y 50
  116. #define PARA_UI_SIZE_X 450
  117. #define PARA_UI_SIZE_Y 40
  118. #define PARA_UI_ARROW_V 12
  119. #define PARA_UI_BACL_POS_X 400
  120. #define PARA_UI_BACL_POS_Y 270
  121. #define PARA_UI_TURN_PAGE_POS_X 320
  122. #define PARA_UI_TURN_PAGE_POS_Y 270
  123. #define PARA_UI_VALUE_SIZE_X 370
  124. #define PARA_UI_VALUE_POS_X 400
  125. #define PARA_UI_VALUE_V 5
  126. #define PARA_UI_STATE_POS_X 380
  127. #define PARA_UI_STATE_V 2
  128. #define PARA_UI_VALUE_SIZE_X_2 200
  129. #define PARA_UI_VALUE_POS_X_2 320
  130. #define PARA_UI_VALUE_V_2 5
  131. #define PARA_UI_VALUE_BTN_X_SIZE 70
  132. #define PARA_UI_VALUE_BTN_Y_SIZE 28
  133. #define PARA_UI_BACK_BTN_X_SIZE 70
  134. #define PARA_UI_BACK_BTN_Y_SIZE 40
  135. #define QRCODE_X 20
  136. #define QRCODE_Y 40
  137. #define QRCODE_WIDTH 160
  138. #else // ifdef TFT35
  139. #define TFT_WIDTH 320
  140. #define TFT_HEIGHT 240
  141. #endif // ifdef TFT35
  142. #ifdef __cplusplus
  143. extern "C" { /* C-declarations for C++ */
  144. #endif
  145. extern char public_buf_m[100];
  146. extern char public_buf_l[30];
  147. typedef struct {
  148. uint32_t spi_flash_flag;
  149. uint8_t disp_rotation_180;
  150. bool multiple_language;
  151. uint8_t language;
  152. uint8_t leveling_mode;
  153. bool from_flash_pic;
  154. bool finish_power_off;
  155. bool pause_reprint;
  156. uint8_t wifi_mode_sel;
  157. uint8_t fileSysType;
  158. uint8_t wifi_type;
  159. bool cloud_enable,
  160. encoder_enable;
  161. int levelingPos[5][2];
  162. int filamentchange_load_length,
  163. filamentchange_load_speed,
  164. filamentchange_unload_length,
  165. filamentchange_unload_speed;
  166. celsius_t filament_limit_temp;
  167. float pausePosX, pausePosY, pausePosZ;
  168. uint32_t curFilesize;
  169. } CFG_ITMES;
  170. typedef struct {
  171. uint8_t curTempType:1,
  172. extruderIndex:3,
  173. stepHeat:4,
  174. extruderIndexBak:4;
  175. bool leveling_first_time:1,
  176. para_ui_page:1,
  177. configWifi:1,
  178. command_send:1,
  179. filament_load_heat_flg:1,
  180. filament_heat_completed_load:1,
  181. filament_unload_heat_flg:1,
  182. filament_heat_completed_unload:1,
  183. filament_loading_completed:1,
  184. filament_unloading_completed:1,
  185. filament_loading_time_flg:1,
  186. filament_unloading_time_flg:1;
  187. uint8_t wifi_name[32];
  188. uint8_t wifi_key[64];
  189. uint8_t cloud_hostUrl[96];
  190. uint8_t extruStep;
  191. uint8_t extruSpeed;
  192. uint8_t print_state;
  193. uint8_t stepPrintSpeed;
  194. uint8_t waitEndMoves;
  195. uint8_t dialogType;
  196. uint8_t F[4];
  197. uint8_t filament_rate;
  198. uint16_t moveSpeed;
  199. uint16_t cloud_port;
  200. uint16_t moveSpeed_bak;
  201. uint32_t totalSend;
  202. uint32_t filament_loading_time,
  203. filament_unloading_time,
  204. filament_loading_time_cnt,
  205. filament_unloading_time_cnt;
  206. float move_dist;
  207. celsius_t hotendTargetTempBak;
  208. float current_x_position_bak,
  209. current_y_position_bak,
  210. current_z_position_bak,
  211. current_e_position_bak;
  212. } UI_CFG;
  213. typedef enum {
  214. MAIN_UI,
  215. PRINT_READY_UI,
  216. PRINT_FILE_UI,
  217. PRINTING_UI,
  218. MOVE_MOTOR_UI,
  219. OPERATE_UI,
  220. PAUSE_UI,
  221. EXTRUSION_UI,
  222. FAN_UI,
  223. PRE_HEAT_UI,
  224. CHANGE_SPEED_UI,
  225. TEMP_UI,
  226. SET_UI,
  227. ZERO_UI,
  228. SPRAYER_UI,
  229. MACHINE_UI,
  230. LANGUAGE_UI,
  231. ABOUT_UI,
  232. LOG_UI,
  233. DISK_UI,
  234. CALIBRATE_UI,
  235. DIALOG_UI,
  236. WIFI_UI,
  237. MORE_UI,
  238. FILETRANSFER_UI,
  239. FILETRANSFERSTATE_UI,
  240. PRINT_MORE_UI,
  241. FILAMENTCHANGE_UI,
  242. LEVELING_UI,
  243. MESHLEVELING_UI,
  244. BIND_UI,
  245. #if HAS_BED_PROBE
  246. NOZZLE_PROBE_OFFSET_UI,
  247. #endif
  248. TOOL_UI,
  249. HARDWARE_TEST_UI,
  250. WIFI_LIST_UI,
  251. KEY_BOARD_UI,
  252. WIFI_TIPS_UI,
  253. MACHINE_PARA_UI,
  254. MACHINE_SETTINGS_UI,
  255. TEMPERATURE_SETTINGS_UI,
  256. MOTOR_SETTINGS_UI,
  257. MACHINETYPE_UI,
  258. STROKE_UI,
  259. HOME_DIR_UI,
  260. ENDSTOP_TYPE_UI,
  261. FILAMENT_SETTINGS_UI,
  262. LEVELING_SETTIGNS_UI,
  263. LEVELING_PARA_UI,
  264. DELTA_LEVELING_PARA_UI,
  265. MANUAL_LEVELING_POSIGION_UI,
  266. MAXFEEDRATE_UI,
  267. STEPS_UI,
  268. ACCELERATION_UI,
  269. JERK_UI,
  270. MOTORDIR_UI,
  271. HOMESPEED_UI,
  272. NOZZLE_CONFIG_UI,
  273. HOTBED_CONFIG_UI,
  274. ADVANCED_UI,
  275. DOUBLE_Z_UI,
  276. ENABLE_INVERT_UI,
  277. NUMBER_KEY_UI,
  278. BABY_STEP_UI,
  279. ERROR_MESSAGE_UI,
  280. PAUSE_POS_UI,
  281. TMC_CURRENT_UI,
  282. TMC_MODE_UI,
  283. EEPROM_SETTINGS_UI,
  284. WIFI_SETTINGS_UI,
  285. HOMING_SENSITIVITY_UI,
  286. ENCODER_SETTINGS_UI,
  287. TOUCH_CALIBRATION_UI,
  288. GCODE_UI,
  289. } DISP_STATE;
  290. typedef struct {
  291. DISP_STATE _disp_state[100];
  292. int _disp_index;
  293. } DISP_STATE_STACK;
  294. typedef struct {
  295. int16_t days;
  296. uint16_t hours;
  297. uint8_t minutes;
  298. volatile int8_t seconds;
  299. int8_t ms_10;
  300. int8_t start;
  301. } PRINT_TIME;
  302. extern PRINT_TIME print_time;
  303. typedef enum {
  304. PrintAcceleration,
  305. RetractAcceleration,
  306. TravelAcceleration,
  307. XAcceleration,
  308. YAcceleration,
  309. ZAcceleration,
  310. E0Acceleration,
  311. E1Acceleration,
  312. XMaxFeedRate,
  313. YMaxFeedRate,
  314. ZMaxFeedRate,
  315. E0MaxFeedRate,
  316. E1MaxFeedRate,
  317. XJerk,
  318. YJerk,
  319. ZJerk,
  320. EJerk,
  321. Xstep,
  322. Ystep,
  323. Zstep,
  324. E0step,
  325. E1step,
  326. Xcurrent,
  327. Ycurrent,
  328. Zcurrent,
  329. E0current,
  330. E1current,
  331. pause_pos_x,
  332. pause_pos_y,
  333. pause_pos_z,
  334. level_pos_x1,
  335. level_pos_y1,
  336. level_pos_x2,
  337. level_pos_y2,
  338. level_pos_x3,
  339. level_pos_y3,
  340. level_pos_x4,
  341. level_pos_y4,
  342. level_pos_x5,
  343. level_pos_y5,
  344. #if HAS_BED_PROBE
  345. x_offset,
  346. y_offset,
  347. z_offset,
  348. #endif
  349. load_length,
  350. load_speed,
  351. unload_length,
  352. unload_speed,
  353. filament_temp,
  354. x_sensitivity,
  355. y_sensitivity,
  356. z_sensitivity,
  357. z2_sensitivity
  358. } num_key_value_state;
  359. extern num_key_value_state value;
  360. typedef enum {
  361. wifiName,
  362. wifiPassWord,
  363. wifiConfig,
  364. autoLevelGcodeCommand,
  365. GCodeCommand,
  366. } keyboard_value_state;
  367. extern keyboard_value_state keyboard_value;
  368. extern CFG_ITMES gCfgItems;
  369. extern UI_CFG uiCfg;
  370. extern DISP_STATE disp_state;
  371. extern DISP_STATE last_disp_state;
  372. extern DISP_STATE_STACK disp_state_stack;
  373. extern lv_style_t tft_style_scr;
  374. extern lv_style_t tft_style_label_pre;
  375. extern lv_style_t tft_style_label_rel;
  376. extern lv_style_t style_line;
  377. extern lv_style_t style_para_value_pre;
  378. extern lv_style_t style_para_value_rel;
  379. extern lv_style_t style_num_key_pre;
  380. extern lv_style_t style_num_key_rel;
  381. extern lv_style_t style_num_text;
  382. extern lv_style_t style_sel_text;
  383. extern lv_style_t style_para_value;
  384. extern lv_style_t style_para_back;
  385. extern lv_style_t lv_bar_style_indic;
  386. extern lv_style_t style_btn_pr;
  387. extern lv_style_t style_btn_rel;
  388. extern lv_point_t line_points[4][2];
  389. extern void gCfgItems_init();
  390. extern void ui_cfg_init();
  391. extern void tft_style_init();
  392. extern char *creat_title_text();
  393. extern void preview_gcode_prehandle(char *path);
  394. extern void update_spi_flash();
  395. extern void update_gcode_command(int addr,uint8_t *s);
  396. extern void get_gcode_command(int addr,uint8_t *d);
  397. extern void lv_serial_capt_hook(void *, uint8_t);
  398. extern void lv_eom_hook(void *);
  399. #if HAS_GCODE_PREVIEW
  400. extern void disp_pre_gcode(int xpos_pixel, int ypos_pixel);
  401. #endif
  402. extern void GUI_RefreshPage();
  403. extern void clear_cur_ui();
  404. extern void draw_return_ui();
  405. extern void sd_detection();
  406. extern void gCfg_to_spiFlah();
  407. extern void print_time_count();
  408. extern void LV_TASK_HANDLER();
  409. extern void lv_ex_line(lv_obj_t *line, lv_point_t *points);
  410. #ifdef __cplusplus
  411. } /* C-declarations for C++ */
  412. #endif
  413. // Set the same image for both Released and Pressed
  414. void lv_imgbtn_set_src_both(lv_obj_t *imgbtn, const void *src);
  415. // Set label styles for Released and Pressed
  416. void lv_imgbtn_use_label_style(lv_obj_t *imgbtn);
  417. // Set label styles for Released and Pressed
  418. void lv_btn_use_label_style(lv_obj_t *btn);
  419. // Set the same style for both Released and Pressed
  420. void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style);
  421. // Create a screen
  422. lv_obj_t* lv_screen_create(DISP_STATE newScreenType, const char* title = nullptr);
  423. // Create an empty label
  424. lv_obj_t* lv_label_create_empty(lv_obj_t *par);
  425. // Create a label with style and text
  426. lv_obj_t* lv_label_create(lv_obj_t *par, const char *text);
  427. // Create a label with style, position, and text
  428. lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char *text);
  429. // Create a button with callback, ID, and Style.
  430. lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id, lv_style_t *style=&style_para_value);
  431. // Create a button with callback and ID, with label style.
  432. lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0);
  433. // Create a button with callback and ID, with button style.
  434. lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0);
  435. // Create a button with position, size, callback, ID, and style.
  436. lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id, lv_style_t *style);
  437. // Create a button with position, size, callback, and ID. Style set to style_para_value.
  438. lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0);
  439. // Create a button with position, size, callback, and ID, with label style.
  440. lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0);
  441. // Create a button with position, size, callback, and ID, with button style.
  442. lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0);
  443. // Create a button with callback and ID. Style set to style_para_back.
  444. lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id=0);
  445. // Create a button with position, size, callback, and ID. Style set to style_para_back.
  446. lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0);
  447. // Create an image button with image, callback, and ID. Use label style.
  448. lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id=0);
  449. // Create an image button with image, position, callback, and ID. Use label style.
  450. lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id=0);
  451. // Create a big image button with a label, follow the LVGL UI standard.
  452. lv_obj_t* lv_big_button_create(lv_obj_t *par, const char *img, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, bool centerLabel = false);
  453. // Create a menu item, follow the LVGL UI standard.
  454. lv_obj_t* lv_screen_menu_item(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, bool drawArrow = true);
  455. lv_obj_t* lv_screen_menu_item_1_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue);
  456. lv_obj_t* lv_screen_menu_item_2_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue, const int idEdit2, const char *editValue2);
  457. lv_obj_t* lv_screen_menu_item_onoff(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const bool curValue);
  458. void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue);
  459. #define _DIA_1(T) (uiCfg.dialogType == DIALOG_##T)
  460. #define DIALOG_IS(V...) DO(DIA,||,V)