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.

ui_320x240.cpp 23KB

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