My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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_UI_320x240
  24. #include "ui_320x240.h"
  25. #include "../marlinui.h"
  26. #include "../menu/menu.h"
  27. #include "../../libs/numtostr.h"
  28. #include "../../sd/cardreader.h"
  29. #include "../../module/temperature.h"
  30. #include "../../module/printcounter.h"
  31. #include "../../module/planner.h"
  32. #include "../../module/motion.h"
  33. #if DISABLED(LCD_PROGRESS_BAR) && BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  34. #include "../../feature/filwidth.h"
  35. #include "../../gcode/parser.h"
  36. #endif
  37. #if ENABLED(AUTO_BED_LEVELING_UBL)
  38. #include "../../feature/bedlevel/bedlevel.h"
  39. #endif
  40. #if !HAS_LCD_MENU
  41. #error "Seriously? High resolution TFT screen without menu?"
  42. #endif
  43. static bool draw_menu_navigation = false;
  44. void MarlinUI::tft_idle() {
  45. #if ENABLED(TOUCH_SCREEN)
  46. if (draw_menu_navigation) {
  47. add_control(48, 206, PAGE_UP, imgPageUp, encoderTopLine > 0);
  48. add_control(240, 206, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
  49. add_control(144, 206, BACK, imgBack);
  50. draw_menu_navigation = false;
  51. }
  52. #endif
  53. tft.queue.async();
  54. TERN_(TOUCH_SCREEN, touch.idle());
  55. }
  56. void MarlinUI::init_lcd() {
  57. tft.init();
  58. tft.set_font(MENU_FONT_NAME);
  59. #ifdef SYMBOLS_FONT_NAME
  60. tft.add_glyphs(SYMBOLS_FONT_NAME);
  61. #endif
  62. TERN_(TOUCH_SCREEN, touch.init());
  63. clear_lcd();
  64. }
  65. bool MarlinUI::detected() { return true; }
  66. void MarlinUI::clear_lcd() {
  67. #if ENABLED(TOUCH_SCREEN)
  68. touch.reset();
  69. draw_menu_navigation = false;
  70. #endif
  71. tft.queue.reset();
  72. tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
  73. }
  74. #if ENABLED(SHOW_BOOTSCREEN)
  75. #ifndef BOOTSCREEN_TIMEOUT
  76. #define BOOTSCREEN_TIMEOUT 1500
  77. #endif
  78. void MarlinUI::show_bootscreen() {
  79. tft.queue.reset();
  80. tft.canvas(0, 0, TFT_WIDTH, TFT_HEIGHT);
  81. tft.add_image(0, 0, imgBootScreen); // MarlinLogo320x240x16
  82. #ifdef WEBSITE_URL
  83. tft.add_text(4, 188, COLOR_WEBSITE_URL, WEBSITE_URL);
  84. #endif
  85. tft.queue.sync();
  86. safe_delay(BOOTSCREEN_TIMEOUT);
  87. clear_lcd();
  88. }
  89. #endif // SHOW_BOOTSCREEN
  90. void MarlinUI::draw_kill_screen() {
  91. tft.queue.reset();
  92. tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_KILL_SCREEN_BG);
  93. tft.canvas(0, 60, TFT_WIDTH, 20);
  94. tft.set_background(COLOR_KILL_SCREEN_BG);
  95. tft_string.set(status_message);
  96. tft_string.trim();
  97. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_KILL_SCREEN_TEXT, tft_string);
  98. tft.canvas(0, 120, TFT_WIDTH, 20);
  99. tft.set_background(COLOR_KILL_SCREEN_BG);
  100. tft_string.set(GET_TEXT(MSG_HALTED));
  101. tft_string.trim();
  102. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_KILL_SCREEN_TEXT, tft_string);
  103. tft.canvas(0, 160, TFT_WIDTH, 20);
  104. tft.set_background(COLOR_KILL_SCREEN_BG);
  105. tft_string.set(GET_TEXT(MSG_PLEASE_RESET));
  106. tft_string.trim();
  107. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_KILL_SCREEN_TEXT, tft_string);
  108. tft.queue.sync();
  109. }
  110. void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
  111. MarlinImage image = imgHotEnd;
  112. uint16_t Color;
  113. float currentTemperature, targetTemperature;
  114. if (Heater >= 0) { // HotEnd
  115. currentTemperature = thermalManager.degHotend(Heater);
  116. targetTemperature = thermalManager.degTargetHotend(Heater);
  117. }
  118. #if HAS_HEATED_BED
  119. else if (Heater == H_BED) {
  120. currentTemperature = thermalManager.degBed();
  121. targetTemperature = thermalManager.degTargetBed();
  122. }
  123. #endif // HAS_HEATED_BED
  124. #if HAS_TEMP_CHAMBER
  125. else if (Heater == H_CHAMBER) {
  126. currentTemperature = thermalManager.degChamber();
  127. #if HAS_HEATED_CHAMBER
  128. targetTemperature = thermalManager.degTargetChamber();
  129. #else
  130. targetTemperature = ABSOLUTE_ZERO;
  131. #endif
  132. }
  133. #endif // HAS_TEMP_CHAMBER
  134. else return;
  135. TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 64, 100, Heater));
  136. tft.canvas(x, y, 64, 100);
  137. tft.set_background(COLOR_BACKGROUND);
  138. Color = currentTemperature < 0 ? COLOR_INACTIVE : COLOR_COLD;
  139. if (Heater >= 0) { // HotEnd
  140. if (currentTemperature >= 50) Color = COLOR_HOTEND;
  141. }
  142. #if HAS_HEATED_BED
  143. else if (Heater == H_BED) {
  144. if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
  145. image = targetTemperature > 0 ? imgBedHeated : imgBed;
  146. }
  147. #endif // HAS_HEATED_BED
  148. #if HAS_TEMP_CHAMBER
  149. else if (Heater == H_CHAMBER) {
  150. if (currentTemperature >= 50) Color = COLOR_CHAMBER;
  151. image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
  152. }
  153. #endif // HAS_TEMP_CHAMBER
  154. tft.add_image(0, 18, image, Color);
  155. tft_string.set((uint8_t *)i16tostr3rj(currentTemperature + 0.5));
  156. tft_string.add(LCD_STR_DEGREE);
  157. tft_string.trim();
  158. tft.add_text(tft_string.center(64) + 2, 72, Color, tft_string);
  159. if (targetTemperature >= 0) {
  160. tft_string.set((uint8_t *)i16tostr3rj(targetTemperature + 0.5));
  161. tft_string.add(LCD_STR_DEGREE);
  162. tft_string.trim();
  163. tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string);
  164. }
  165. }
  166. void draw_fan_status(uint16_t x, uint16_t y, const bool blink) {
  167. TERN_(TOUCH_SCREEN, touch.add_control(FAN, x, y, 64, 100));
  168. tft.canvas(x, y, 64, 100);
  169. tft.set_background(COLOR_BACKGROUND);
  170. uint8_t fanSpeed = thermalManager.fan_speed[0];
  171. MarlinImage image;
  172. if (fanSpeed >= 127)
  173. image = blink ? imgFanFast1 : imgFanFast0;
  174. else if (fanSpeed > 0)
  175. image = blink ? imgFanSlow1 : imgFanSlow0;
  176. else
  177. image = imgFanIdle;
  178. tft.add_image(0, 10, image, COLOR_FAN);
  179. tft_string.set((uint8_t *)ui8tostr4pctrj(thermalManager.fan_speed[0]));
  180. tft_string.trim();
  181. tft.add_text(tft_string.center(64) + 6, 72, COLOR_FAN, tft_string);
  182. }
  183. void MarlinUI::draw_status_screen() {
  184. const bool blink = get_blink();
  185. TERN_(TOUCH_SCREEN, touch.clear());
  186. // heaters and fan
  187. uint16_t i, x, y = POS_Y;
  188. for (i = 0 ; i < ITEMS_COUNT; i++) {
  189. x = (320 / ITEMS_COUNT - 64) / 2 + (320 * i / ITEMS_COUNT);
  190. switch (i) {
  191. #ifdef ITEM_E0
  192. case ITEM_E0: draw_heater_status(x, y, H_E0); break;
  193. #endif
  194. #ifdef ITEM_E1
  195. case ITEM_E1: draw_heater_status(x, y, H_E1); break;
  196. #endif
  197. #ifdef ITEM_E2
  198. case ITEM_E2: draw_heater_status(x, y, H_E2); break;
  199. #endif
  200. #ifdef ITEM_BED
  201. case ITEM_BED: draw_heater_status(x, y, H_BED); break;
  202. #endif
  203. #ifdef ITEM_CHAMBER
  204. case ITEM_CHAMBER: draw_heater_status(x, y, H_CHAMBER); break;
  205. #endif
  206. #ifdef ITEM_FAN
  207. case ITEM_FAN: draw_fan_status(x, y, blink); break;
  208. #endif
  209. }
  210. }
  211. // coordinates
  212. tft.canvas(4, 103, 312, 24);
  213. tft.set_background(COLOR_BACKGROUND);
  214. tft.add_rectangle(0, 0, 312, 24, COLOR_AXIS_HOMED);
  215. tft.add_text( 10, 3, COLOR_AXIS_HOMED , "X");
  216. tft.add_text(127, 3, COLOR_AXIS_HOMED , "Y");
  217. tft.add_text(219, 3, COLOR_AXIS_HOMED , "Z");
  218. bool not_homed = axis_should_home(X_AXIS);
  219. tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
  220. tft.add_text( 68 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
  221. not_homed = axis_should_home(Y_AXIS);
  222. tft_string.set(blink && not_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
  223. tft.add_text(185 - tft_string.width(), 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
  224. not_homed = axis_should_home(Z_AXIS);
  225. uint16_t offset = 25;
  226. if (blink && not_homed)
  227. tft_string.set("?");
  228. else {
  229. const float z = LOGICAL_Z_POSITION(current_position.z);
  230. tft_string.set(ftostr52sp((int16_t)z));
  231. tft_string.rtrim();
  232. offset += tft_string.width();
  233. tft_string.set(ftostr52sp(z));
  234. offset -= tft_string.width();
  235. }
  236. tft.add_text(301 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
  237. // feed rate
  238. tft.canvas(70, 136, 80, 32);
  239. tft.set_background(COLOR_BACKGROUND);
  240. uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
  241. tft.add_image(0, 0, imgFeedRate, color);
  242. tft_string.set(i16tostr3rj(feedrate_percentage));
  243. tft_string.add('%');
  244. tft.add_text(32, 6, color , tft_string);
  245. TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 70, 136, 80, 32));
  246. // flow rate
  247. tft.canvas(170, 136, 80, 32);
  248. tft.set_background(COLOR_BACKGROUND);
  249. color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
  250. tft.add_image(0, 0, imgFlowRate, color);
  251. tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
  252. tft_string.add('%');
  253. tft.add_text(32, 6, color , tft_string);
  254. TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 170, 136, 80, 32, active_extruder));
  255. // print duration
  256. char buffer[14];
  257. duration_t elapsed = print_job_timer.duration();
  258. elapsed.toDigital(buffer);
  259. tft.canvas(96, 176, 128, 20);
  260. tft.set_background(COLOR_BACKGROUND);
  261. tft_string.set(buffer);
  262. tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
  263. // progress bar
  264. const uint8_t progress = ui.get_progress_percent();
  265. tft.canvas(4, 198, 312, 9);
  266. tft.set_background(COLOR_PROGRESS_BG);
  267. tft.add_rectangle(0, 0, 312, 9, COLOR_PROGRESS_FRAME);
  268. if (progress)
  269. tft.add_bar(1, 1, (310 * progress) / 100, 7, COLOR_PROGRESS_BAR);
  270. // status message
  271. tft.canvas(0, 216, 320, 20);
  272. tft.set_background(COLOR_BACKGROUND);
  273. tft_string.set(status_message);
  274. tft_string.trim();
  275. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
  276. #if ENABLED(TOUCH_SCREEN)
  277. add_control(256, 130, menu_main, imgSettings);
  278. TERN_(SDSUPPORT, add_control(0, 130, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
  279. #endif
  280. }
  281. // Draw a static item with no left-right margin required. Centered by default.
  282. void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  283. menu_item(row);
  284. tft_string.set(pstr, itemIndex, itemString);
  285. if (vstr)
  286. tft_string.add(vstr);
  287. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
  288. }
  289. // Draw a generic menu item with pre_char (if selected) and post_char
  290. void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
  291. menu_item(row, sel);
  292. uint8_t *string = (uint8_t *)pstr;
  293. MarlinImage image = noImage;
  294. switch (*string) {
  295. case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
  296. case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
  297. }
  298. uint8_t offset = MENU_TEXT_X_OFFSET;
  299. if (image != noImage) {
  300. string++;
  301. offset = 32;
  302. tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  303. }
  304. tft_string.set(string, itemIndex, itemString);
  305. tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  306. }
  307. // Draw a menu item with a (potentially) editable value
  308. void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
  309. menu_item(row, sel);
  310. tft_string.set(pstr, itemIndex, itemString);
  311. tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  312. if (data) {
  313. tft_string.set(data);
  314. tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  315. }
  316. }
  317. // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
  318. void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
  319. ui.encoder_direction_normal();
  320. TERN_(TOUCH_SCREEN, touch.clear());
  321. uint16_t line = 1;
  322. menu_line(line++);
  323. tft_string.set(pstr, itemIndex, itemString);
  324. tft_string.trim();
  325. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  326. TERN_(AUTO_BED_LEVELING_UBL, if (ui.external_control) line++); // ftostr52() will overwrite *value so *value has to be displayed first
  327. menu_line(line);
  328. tft_string.set(value);
  329. tft_string.trim();
  330. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  331. #if ENABLED(AUTO_BED_LEVELING_UBL)
  332. if (ui.external_control) {
  333. menu_line(line - 1);
  334. tft_string.set(X_LBL);
  335. tft.add_text(52, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  336. tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.x)));
  337. tft_string.trim();
  338. tft.add_text(144 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  339. tft_string.set(Y_LBL);
  340. tft.add_text(176, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  341. tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.y)));
  342. tft_string.trim();
  343. tft.add_text(268 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  344. }
  345. #endif
  346. extern screenFunc_t _manual_move_func_ptr;
  347. if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
  348. #define SLIDER_LENGHT 224
  349. #define SLIDER_Y_POSITION 140
  350. tft.canvas((TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION, SLIDER_LENGHT, 16);
  351. tft.set_background(COLOR_BACKGROUND);
  352. int16_t position = (SLIDER_LENGHT - 2) * ui.encoderPosition / maxEditValue;
  353. tft.add_bar(0, 7, 1, 2, ui.encoderPosition == 0 ? COLOR_SLIDER_INACTIVE : COLOR_SLIDER);
  354. tft.add_bar(1, 6, position, 4, COLOR_SLIDER);
  355. tft.add_bar(position + 1, 6, SLIDER_LENGHT - 2 - position, 4, COLOR_SLIDER_INACTIVE);
  356. tft.add_bar(SLIDER_LENGHT - 1, 7, 1, 2, int32_t(ui.encoderPosition) == maxEditValue ? COLOR_SLIDER : COLOR_SLIDER_INACTIVE);
  357. #if ENABLED(TOUCH_SCREEN)
  358. tft.add_image((SLIDER_LENGHT - 8) * ui.encoderPosition / maxEditValue, 0, imgSlider, COLOR_SLIDER);
  359. touch.add_control(SLIDER, (TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION - 8, SLIDER_LENGHT, 32, maxEditValue);
  360. #endif
  361. }
  362. #if ENABLED(TOUCH_SCREEN)
  363. add_control(32, 176, DECREASE, imgDecrease);
  364. add_control(224, 176, INCREASE, imgIncrease);
  365. add_control(128, 176, CLICK, imgConfirm);
  366. #endif
  367. }
  368. // The Select Screen presents a prompt and two "buttons"
  369. void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
  370. uint16_t line = 1;
  371. if (!string) line++;
  372. menu_line(line++);
  373. tft_string.set(pref);
  374. tft_string.trim();
  375. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  376. if (string) {
  377. menu_line(line++);
  378. tft_string.set(string);
  379. tft_string.trim();
  380. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  381. }
  382. if (suff) {
  383. menu_line(line);
  384. tft_string.set(suff);
  385. tft_string.trim();
  386. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  387. }
  388. #if ENABLED(TOUCH_SCREEN)
  389. add_control(48, 176, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
  390. add_control(208, 176, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
  391. #endif
  392. }
  393. #if ENABLED(SDSUPPORT)
  394. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
  395. menu_item(row, sel);
  396. if (isDir)
  397. tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  398. tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
  399. }
  400. #endif
  401. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  402. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  403. #if ENABLED(TOUCH_SCREEN)
  404. touch.clear();
  405. draw_menu_navigation = false;
  406. touch.add_control(RESUME_CONTINUE , 0, 0, 320, 240);
  407. #endif
  408. menu_line(row);
  409. tft_string.set(GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE));
  410. tft_string.add('E');
  411. tft_string.add((char)('1' + extruder));
  412. tft_string.add(' ');
  413. tft_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
  414. tft_string.add(LCD_STR_DEGREE);
  415. tft_string.add(" / ");
  416. tft_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
  417. tft_string.add(LCD_STR_DEGREE);
  418. tft_string.trim();
  419. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  420. }
  421. #endif // ADVANCED_PAUSE_FEATURE
  422. #if ENABLED(AUTO_BED_LEVELING_UBL)
  423. #define GRID_OFFSET_X 8
  424. #define GRID_OFFSET_Y 8
  425. #define GRID_WIDTH 144
  426. #define GRID_HEIGHT 144
  427. #define CONTROL_OFFSET 8
  428. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  429. tft.canvas(GRID_OFFSET_X, GRID_OFFSET_Y, GRID_WIDTH, GRID_HEIGHT);
  430. tft.set_background(COLOR_BACKGROUND);
  431. tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE);
  432. for (uint16_t x = 0; x < GRID_MAX_POINTS_X ; x++)
  433. for (uint16_t y = 0; y < GRID_MAX_POINTS_Y ; y++)
  434. if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
  435. tft.add_bar(1 + (x * 2 + 1) * (GRID_WIDTH - 4) / GRID_MAX_POINTS_X / 2, GRID_HEIGHT - 3 - ((y * 2 + 1) * (GRID_HEIGHT - 4) / GRID_MAX_POINTS_Y / 2), 2, 2, COLOR_UBL);
  436. tft.add_rectangle((x_plot * 2 + 1) * (GRID_WIDTH - 4) / GRID_MAX_POINTS_X / 2 - 1, GRID_HEIGHT - 5 - ((y_plot * 2 + 1) * (GRID_HEIGHT - 4) / GRID_MAX_POINTS_Y / 2), 6, 6, COLOR_UBL);
  437. const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
  438. lpos = pos.asLogical();
  439. tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - 32) / 2 - 32, 96, 32);
  440. tft.set_background(COLOR_BACKGROUND);
  441. tft_string.set(X_LBL);
  442. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  443. tft_string.set(ftostr52(lpos.x));
  444. tft_string.trim();
  445. tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  446. tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - 32) / 2, 96, 32);
  447. tft.set_background(COLOR_BACKGROUND);
  448. tft_string.set(Y_LBL);
  449. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  450. tft_string.set(ftostr52(lpos.y));
  451. tft_string.trim();
  452. tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  453. tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - 32) / 2 + 32, 96, 32);
  454. tft.set_background(COLOR_BACKGROUND);
  455. tft_string.set(Z_LBL);
  456. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  457. tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
  458. tft_string.trim();
  459. tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  460. tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32);
  461. tft.set_background(COLOR_BACKGROUND);
  462. tft_string.set(ui8tostr3rj(x_plot));
  463. tft_string.trim();
  464. tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  465. tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32);
  466. tft.set_background(COLOR_BACKGROUND);
  467. tft_string.set(ui8tostr3rj(y_plot));
  468. tft_string.trim();
  469. tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  470. #if ENABLED(TOUCH_SCREEN)
  471. touch.clear();
  472. draw_menu_navigation = false;
  473. add_control(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + CONTROL_OFFSET, UBL, ENCODER_STEPS_PER_MENU_ITEM * GRID_MAX_POINTS_X, imgUp);
  474. add_control(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + GRID_HEIGHT - CONTROL_OFFSET - 32, UBL, - ENCODER_STEPS_PER_MENU_ITEM * GRID_MAX_POINTS_X, imgDown);
  475. add_control(GRID_OFFSET_X + CONTROL_OFFSET, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, - ENCODER_STEPS_PER_MENU_ITEM, imgLeft);
  476. add_control(GRID_OFFSET_X + GRID_WIDTH - CONTROL_OFFSET - 32, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, ENCODER_STEPS_PER_MENU_ITEM, imgRight);
  477. add_control(224, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, CLICK, imgLeveling);
  478. add_control(144, 206, BACK, imgBack);
  479. #endif
  480. }
  481. #endif // AUTO_BED_LEVELING_UBL
  482. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  483. void MarlinUI::touch_calibration_screen() {
  484. uint16_t x, y;
  485. calibrationState calibration_stage = touch_calibration.get_calibration_state();
  486. if (calibration_stage == CALIBRATION_NONE) {
  487. defer_status_screen(true);
  488. clear_lcd();
  489. calibration_stage = touch_calibration.calibration_start();
  490. }
  491. else {
  492. x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
  493. y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
  494. tft.canvas(x - 15, y - 15, 31, 31);
  495. tft.set_background(COLOR_BACKGROUND);
  496. }
  497. touch.clear();
  498. if (calibration_stage < CALIBRATION_SUCCESS) {
  499. switch (calibration_stage) {
  500. case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
  501. case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
  502. case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
  503. case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
  504. default: break;
  505. }
  506. x = touch_calibration.calibration_points[calibration_stage].x;
  507. y = touch_calibration.calibration_points[calibration_stage].y;
  508. tft.canvas(x - 15, y - 15, 31, 31);
  509. tft.set_background(COLOR_BACKGROUND);
  510. tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
  511. tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
  512. touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
  513. }
  514. else {
  515. tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
  516. defer_status_screen(false);
  517. touch_calibration.calibration_end();
  518. touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
  519. }
  520. tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
  521. tft.set_background(COLOR_BACKGROUND);
  522. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
  523. }
  524. #endif // TOUCH_SCREEN_CALIBRATION
  525. void menu_line(const uint8_t row, uint16_t color) {
  526. tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32);
  527. tft.set_background(color);
  528. }
  529. void menu_pause_option();
  530. void menu_item(const uint8_t row, bool sel ) {
  531. #if ENABLED(TOUCH_SCREEN)
  532. if (row == 0) {
  533. touch.clear();
  534. draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
  535. }
  536. #endif
  537. menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  538. #if ENABLED(TOUCH_SCREEN)
  539. const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
  540. touch.add_control(tct, 0, 2 + 34 * row, TFT_WIDTH, 32, encoderTopLine + row);
  541. #endif
  542. }
  543. void MarlinUI::move_axis_screen() {
  544. }
  545. #endif // HAS_UI_320x240