My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

draw_tmc_current_settings.cpp 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 BOTH(HAS_TFT_LVGL_UI, HAS_TRINAMIC_CONFIG)
  24. #include "lv_conf.h"
  25. #include "draw_ui.h"
  26. #include "../../../../MarlinCore.h"
  27. #include "../../../../module/planner.h"
  28. #include "../../../../module/stepper/indirection.h"
  29. #include "../../../../feature/tmc_util.h"
  30. extern lv_group_t * g;
  31. static lv_obj_t * scr;
  32. #define ID_TMC_CURRENT_RETURN 1
  33. #define ID_TMC_CURRENT_X 2
  34. #define ID_TMC_CURRENT_Y 3
  35. #define ID_TMC_CURRENT_Z 4
  36. #define ID_TMC_CURRENT_E0 5
  37. #define ID_TMC_CURRENT_E1 6
  38. #define ID_TMC_CURRENT_DOWN 7
  39. #define ID_TMC_CURRENT_UP 8
  40. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  41. switch (obj->mks_obj_id) {
  42. case ID_TMC_CURRENT_RETURN:
  43. if (event == LV_EVENT_CLICKED) {
  44. }
  45. else if (event == LV_EVENT_RELEASED) {
  46. uiCfg.para_ui_page = 0;
  47. lv_clear_tmc_current_settings();
  48. draw_return_ui();
  49. }
  50. break;
  51. #if AXIS_IS_TMC(X)
  52. case ID_TMC_CURRENT_X:
  53. if (event == LV_EVENT_CLICKED) {
  54. }
  55. else if (event == LV_EVENT_RELEASED) {
  56. value = Xcurrent;
  57. lv_clear_tmc_current_settings();
  58. lv_draw_number_key();
  59. }
  60. break;
  61. #endif
  62. #if AXIS_IS_TMC(Y)
  63. case ID_TMC_CURRENT_Y:
  64. if (event == LV_EVENT_CLICKED) {
  65. }
  66. else if (event == LV_EVENT_RELEASED) {
  67. value = Ycurrent;
  68. lv_clear_tmc_current_settings();
  69. lv_draw_number_key();
  70. }
  71. break;
  72. #endif
  73. #if AXIS_IS_TMC(Z)
  74. case ID_TMC_CURRENT_Z:
  75. if (event == LV_EVENT_CLICKED) {
  76. }
  77. else if (event == LV_EVENT_RELEASED) {
  78. value = Zcurrent;
  79. lv_clear_tmc_current_settings();
  80. lv_draw_number_key();
  81. }
  82. break;
  83. #endif
  84. #if AXIS_IS_TMC(E0)
  85. case ID_TMC_CURRENT_E0:
  86. if (event == LV_EVENT_CLICKED) {
  87. }
  88. else if (event == LV_EVENT_RELEASED) {
  89. value = E0current;
  90. lv_clear_tmc_current_settings();
  91. lv_draw_number_key();
  92. }
  93. break;
  94. #endif
  95. #if AXIS_IS_TMC(E1)
  96. case ID_TMC_CURRENT_E1:
  97. if (event == LV_EVENT_CLICKED) {
  98. }
  99. else if (event == LV_EVENT_RELEASED) {
  100. value = E1current;
  101. lv_clear_tmc_current_settings();
  102. lv_draw_number_key();
  103. }
  104. break;
  105. #endif
  106. case ID_TMC_CURRENT_UP:
  107. if (event == LV_EVENT_CLICKED) {
  108. }
  109. else if (event == LV_EVENT_RELEASED) {
  110. uiCfg.para_ui_page = 0;
  111. lv_clear_tmc_current_settings();
  112. lv_draw_tmc_current_settings();
  113. }
  114. break;
  115. case ID_TMC_CURRENT_DOWN:
  116. if (event == LV_EVENT_CLICKED) {
  117. }
  118. else if (event == LV_EVENT_RELEASED) {
  119. uiCfg.para_ui_page = 1;
  120. lv_clear_tmc_current_settings();
  121. lv_draw_tmc_current_settings();
  122. }
  123. break;
  124. }
  125. }
  126. void lv_draw_tmc_current_settings(void) {
  127. lv_obj_t *buttonBack = NULL, *label_Back = NULL;
  128. lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL;
  129. lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL;
  130. lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL;
  131. lv_obj_t *labelE0Text = NULL, *buttonE0Value = NULL, *labelE0Value = NULL;
  132. lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL;
  133. //#if AXIS_IS_TMC(E1)
  134. lv_obj_t *buttonTurnPage = NULL, *labelTurnPage = NULL;
  135. lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL;
  136. //#endif
  137. float milliamps;
  138. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TMC_CURRENT_UI) {
  139. disp_state_stack._disp_index++;
  140. disp_state_stack._disp_state[disp_state_stack._disp_index] = TMC_CURRENT_UI;
  141. }
  142. disp_state = TMC_CURRENT_UI;
  143. scr = lv_obj_create(NULL, NULL);
  144. lv_obj_set_style(scr, &tft_style_scr);
  145. lv_scr_load(scr);
  146. lv_obj_clean(scr);
  147. lv_obj_t * title = lv_label_create(scr, NULL);
  148. lv_obj_set_style(title, &tft_style_label_rel);
  149. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  150. lv_label_set_text(title, machine_menu.TmcCurrentConfTitle);
  151. lv_refr_now(lv_refr_get_disp_refreshing());
  152. if (uiCfg.para_ui_page != 1) {
  153. labelXText = lv_label_create(scr, NULL);
  154. lv_obj_set_style(labelXText, &tft_style_label_rel);
  155. lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10);
  156. lv_label_set_text(labelXText, machine_menu.X_Current);
  157. buttonXValue = lv_btn_create(scr, NULL);
  158. lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V);
  159. lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  160. lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_TMC_CURRENT_X, NULL, 0);
  161. lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value);
  162. lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value);
  163. labelXValue = lv_label_create(buttonXValue, NULL);
  164. line1 = lv_line_create(scr, NULL);
  165. lv_ex_line(line1, line_points[0]);
  166. labelYText = lv_label_create(scr, NULL);
  167. lv_obj_set_style(labelYText, &tft_style_label_rel);
  168. lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10);
  169. lv_label_set_text(labelYText, machine_menu.Y_Current);
  170. buttonYValue = lv_btn_create(scr, NULL);
  171. lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V);
  172. lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  173. lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_TMC_CURRENT_Y, NULL, 0);
  174. lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value);
  175. lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value);
  176. labelYValue = lv_label_create(buttonYValue, NULL);
  177. line2 = lv_line_create(scr, NULL);
  178. lv_ex_line(line2, line_points[1]);
  179. labelZText = lv_label_create(scr, NULL);
  180. lv_obj_set_style(labelZText, &tft_style_label_rel);
  181. lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10);
  182. lv_label_set_text(labelZText, machine_menu.Z_Current);
  183. buttonZValue = lv_btn_create(scr, NULL);
  184. lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V);
  185. lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  186. lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_TMC_CURRENT_Z, NULL, 0);
  187. lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value);
  188. lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value);
  189. labelZValue = lv_label_create(buttonZValue, NULL);
  190. line3 = lv_line_create(scr, NULL);
  191. lv_ex_line(line3, line_points[2]);
  192. labelE0Text = lv_label_create(scr, NULL);
  193. lv_obj_set_style(labelE0Text, &tft_style_label_rel);
  194. lv_obj_set_pos(labelE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10);
  195. lv_label_set_text(labelE0Text, machine_menu.E0_Current);
  196. buttonE0Value = lv_btn_create(scr, NULL);
  197. lv_obj_set_pos(buttonE0Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V);
  198. lv_obj_set_size(buttonE0Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  199. lv_obj_set_event_cb_mks(buttonE0Value, event_handler, ID_TMC_CURRENT_E0, NULL, 0);
  200. lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_REL, &style_para_value);
  201. lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_PR, &style_para_value);
  202. labelE0Value = lv_label_create(buttonE0Value, NULL);
  203. #if HAS_ROTARY_ENCODER
  204. if (gCfgItems.encoder_enable) {
  205. lv_group_add_obj(g, buttonXValue);
  206. lv_group_add_obj(g, buttonYValue);
  207. lv_group_add_obj(g, buttonZValue);
  208. lv_group_add_obj(g, buttonE0Value);
  209. }
  210. #endif
  211. line4 = lv_line_create(scr, NULL);
  212. lv_ex_line(line4, line_points[3]);
  213. //#if AXIS_IS_TMC(E1)
  214. buttonTurnPage = lv_btn_create(scr, NULL);
  215. lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_DOWN, NULL, 0);
  216. lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back);
  217. lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back);
  218. #if HAS_ROTARY_ENCODER
  219. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTurnPage);
  220. #endif
  221. //#endif
  222. }
  223. else {
  224. //#if AXIS_IS_TMC(E1)
  225. labelE1Text = lv_label_create(scr, NULL);
  226. lv_obj_set_style(labelE1Text, &tft_style_label_rel);
  227. lv_obj_set_pos(labelE1Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10);
  228. lv_label_set_text(labelE1Text, machine_menu.E1_Current);
  229. buttonE1Value = lv_btn_create(scr, NULL);
  230. lv_obj_set_pos(buttonE1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V);
  231. lv_obj_set_size(buttonE1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  232. lv_obj_set_event_cb_mks(buttonE1Value, event_handler, ID_TMC_CURRENT_E1, NULL, 0);
  233. lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_REL, &style_para_value);
  234. lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_PR, &style_para_value);
  235. labelE1Value = lv_label_create(buttonE1Value, NULL);
  236. line1 = lv_line_create(scr, NULL);
  237. lv_ex_line(line1, line_points[0]);
  238. buttonTurnPage = lv_btn_create(scr, NULL);
  239. lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_UP, NULL, 0);
  240. lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back);
  241. lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back);
  242. #if HAS_ROTARY_ENCODER
  243. if (gCfgItems.encoder_enable) {
  244. lv_group_add_obj(g, buttonE1Value);
  245. lv_group_add_obj(g, buttonTurnPage);
  246. }
  247. #endif
  248. //#endif
  249. }
  250. //#if AXIS_IS_TMC(E1)
  251. lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y);
  252. lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE);
  253. labelTurnPage = lv_label_create(buttonTurnPage, NULL);
  254. //#endif
  255. buttonBack = lv_btn_create(scr, NULL);
  256. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_TMC_CURRENT_RETURN, NULL, 0);
  257. lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back);
  258. lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back);
  259. #if HAS_ROTARY_ENCODER
  260. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  261. #endif
  262. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  263. lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE);
  264. label_Back = lv_label_create(buttonBack, NULL);
  265. if (gCfgItems.multiple_language != 0) {
  266. if (uiCfg.para_ui_page != 1) {
  267. //#if AXIS_IS_TMC(E1)
  268. lv_label_set_text(labelTurnPage, machine_menu.next);
  269. lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0);
  270. //#endif
  271. #if AXIS_IS_TMC(X)
  272. milliamps = stepperX.getMilliamps();
  273. #else
  274. milliamps = -1;
  275. #endif
  276. ZERO(public_buf_l);
  277. sprintf_P(public_buf_l, PSTR("%.1f"), milliamps);
  278. lv_label_set_text(labelXValue, public_buf_l);
  279. lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0);
  280. #if AXIS_IS_TMC(Y)
  281. milliamps = stepperY.getMilliamps();
  282. #else
  283. milliamps = -1;
  284. #endif
  285. ZERO(public_buf_l);
  286. sprintf_P(public_buf_l, PSTR("%.1f"), milliamps);
  287. lv_label_set_text(labelYValue, public_buf_l);
  288. lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0);
  289. #if AXIS_IS_TMC(Z)
  290. milliamps = stepperZ.getMilliamps();
  291. #else
  292. milliamps = -1;
  293. #endif
  294. ZERO(public_buf_l);
  295. sprintf_P(public_buf_l, PSTR("%.1f"), milliamps);
  296. lv_label_set_text(labelZValue, public_buf_l);
  297. lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0);
  298. #if AXIS_IS_TMC(E0)
  299. milliamps = stepperE0.getMilliamps();
  300. #else
  301. milliamps = -1;
  302. #endif
  303. ZERO(public_buf_l);
  304. sprintf_P(public_buf_l, PSTR("%.1f"), milliamps);
  305. lv_label_set_text(labelE0Value, public_buf_l);
  306. lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0);
  307. }
  308. else {
  309. //#if AXIS_IS_TMC(E1)
  310. lv_label_set_text(labelTurnPage, machine_menu.previous);
  311. lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0);
  312. #if AXIS_IS_TMC(E1)
  313. milliamps = stepperE1.getMilliamps();
  314. #else
  315. milliamps = -1;
  316. #endif
  317. ZERO(public_buf_l);
  318. sprintf_P(public_buf_l, PSTR("%.1f"), milliamps);
  319. lv_label_set_text(labelE1Value, public_buf_l);
  320. lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0);
  321. //#endif
  322. }
  323. lv_label_set_text(label_Back, common_menu.text_back);
  324. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  325. }
  326. }
  327. void lv_clear_tmc_current_settings() {
  328. #if HAS_ROTARY_ENCODER
  329. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  330. #endif
  331. lv_obj_del(scr);
  332. }
  333. #endif // HAS_TFT_LVGL_UI && HAS_TRINAMIC_CONFIG