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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. uint16_t color;
  216. uint16_t offset;
  217. bool is_homed;
  218. tft.add_text( 10, 3, COLOR_AXIS_HOMED , "X");
  219. tft.add_text(127, 3, COLOR_AXIS_HOMED , "Y");
  220. tft.add_text(219, 3, COLOR_AXIS_HOMED , "Z");
  221. is_homed = TEST(axis_homed, X_AXIS);
  222. tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x)));
  223. tft.add_text( 68 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
  224. is_homed = TEST(axis_homed, Y_AXIS);
  225. tft_string.set(blink & !is_homed ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y)));
  226. tft.add_text(185 - tft_string.width(), 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
  227. is_homed = TEST(axis_homed, Z_AXIS);
  228. if (blink & !is_homed) {
  229. tft_string.set("?");
  230. offset = 25; // ".00"
  231. }
  232. else {
  233. const float z = LOGICAL_Z_POSITION(current_position.z);
  234. tft_string.set(ftostr52sp((int16_t)z));
  235. tft_string.rtrim();
  236. offset = tft_string.width();
  237. tft_string.set(ftostr52sp(z));
  238. offset += 25 - tft_string.width();
  239. }
  240. tft.add_text(301 - tft_string.width() - offset, 3, is_homed ? COLOR_AXIS_HOMED : COLOR_AXIS_NOT_HOMED, tft_string);
  241. // feed rate
  242. tft.canvas(70, 136, 80, 32);
  243. tft.set_background(COLOR_BACKGROUND);
  244. color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
  245. tft.add_image(0, 0, imgFeedRate, color);
  246. tft_string.set(i16tostr3rj(feedrate_percentage));
  247. tft_string.add('%');
  248. tft.add_text(32, 6, color , tft_string);
  249. TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 70, 136, 80, 32));
  250. // flow rate
  251. tft.canvas(170, 136, 80, 32);
  252. tft.set_background(COLOR_BACKGROUND);
  253. color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
  254. tft.add_image(0, 0, imgFlowRate, color);
  255. tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
  256. tft_string.add('%');
  257. tft.add_text(32, 6, color , tft_string);
  258. TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 170, 136, 80, 32, active_extruder));
  259. // print duration
  260. char buffer[14];
  261. duration_t elapsed = print_job_timer.duration();
  262. elapsed.toDigital(buffer);
  263. tft.canvas(96, 176, 128, 20);
  264. tft.set_background(COLOR_BACKGROUND);
  265. tft_string.set(buffer);
  266. tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
  267. // progress bar
  268. const uint8_t progress = ui.get_progress_percent();
  269. tft.canvas(4, 198, 312, 9);
  270. tft.set_background(COLOR_PROGRESS_BG);
  271. tft.add_rectangle(0, 0, 312, 9, COLOR_PROGRESS_FRAME);
  272. if (progress)
  273. tft.add_bar(1, 1, (310 * progress) / 100, 7, COLOR_PROGRESS_BAR);
  274. // status message
  275. tft.canvas(0, 216, 320, 20);
  276. tft.set_background(COLOR_BACKGROUND);
  277. tft_string.set(status_message);
  278. tft_string.trim();
  279. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
  280. #if ENABLED(TOUCH_SCREEN)
  281. add_control(256, 130, menu_main, imgSettings);
  282. TERN_(SDSUPPORT, add_control(0, 130, menu_media, imgSD, card.isMounted() && !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
  283. #endif
  284. }
  285. // Draw a static item with no left-right margin required. Centered by default.
  286. void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  287. menu_item(row);
  288. tft_string.set(pstr, itemIndex, itemString);
  289. if (vstr)
  290. tft_string.add(vstr);
  291. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
  292. }
  293. // Draw a generic menu item with pre_char (if selected) and post_char
  294. void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
  295. menu_item(row, sel);
  296. uint8_t *string = (uint8_t *)pstr;
  297. MarlinImage image = noImage;
  298. switch (*string) {
  299. case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
  300. case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
  301. }
  302. uint8_t offset = MENU_TEXT_X_OFFSET;
  303. if (image != noImage) {
  304. string++;
  305. offset = 32;
  306. tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  307. }
  308. tft_string.set(string, itemIndex, itemString);
  309. tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  310. }
  311. // Draw a menu item with a (potentially) editable value
  312. void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
  313. menu_item(row, sel);
  314. tft_string.set(pstr, itemIndex, itemString);
  315. tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  316. if (data) {
  317. tft_string.set(data);
  318. tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  319. }
  320. }
  321. // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
  322. void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
  323. ui.encoder_direction_normal();
  324. TERN_(TOUCH_SCREEN, touch.clear());
  325. uint16_t line = 1;
  326. menu_line(line++);
  327. tft_string.set(pstr, itemIndex, itemString);
  328. tft_string.trim();
  329. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  330. TERN_(AUTO_BED_LEVELING_UBL, if (ui.external_control) line++); // ftostr52() will overwrite *value so *value has to be displayed first
  331. menu_line(line);
  332. tft_string.set(value);
  333. tft_string.trim();
  334. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  335. #if ENABLED(AUTO_BED_LEVELING_UBL)
  336. if (ui.external_control) {
  337. menu_line(line - 1);
  338. tft_string.set(X_LBL);
  339. tft.add_text(52, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  340. tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.x)));
  341. tft_string.trim();
  342. tft.add_text(144 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  343. tft_string.set(Y_LBL);
  344. tft.add_text(176, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  345. tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.y)));
  346. tft_string.trim();
  347. tft.add_text(268 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  348. }
  349. #endif
  350. extern screenFunc_t _manual_move_func_ptr;
  351. if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
  352. #define SLIDER_LENGHT 224
  353. #define SLIDER_Y_POSITION 140
  354. tft.canvas((TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION, SLIDER_LENGHT, 16);
  355. tft.set_background(COLOR_BACKGROUND);
  356. int16_t position = (SLIDER_LENGHT - 2) * ui.encoderPosition / maxEditValue;
  357. tft.add_bar(0, 7, 1, 2, ui.encoderPosition == 0 ? COLOR_SLIDER_INACTIVE : COLOR_SLIDER);
  358. tft.add_bar(1, 6, position, 4, COLOR_SLIDER);
  359. tft.add_bar(position + 1, 6, SLIDER_LENGHT - 2 - position, 4, COLOR_SLIDER_INACTIVE);
  360. tft.add_bar(SLIDER_LENGHT - 1, 7, 1, 2, int32_t(ui.encoderPosition) == maxEditValue ? COLOR_SLIDER : COLOR_SLIDER_INACTIVE);
  361. #if ENABLED(TOUCH_SCREEN)
  362. tft.add_image((SLIDER_LENGHT - 8) * ui.encoderPosition / maxEditValue, 0, imgSlider, COLOR_SLIDER);
  363. touch.add_control(SLIDER, (TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION - 8, SLIDER_LENGHT, 32, maxEditValue);
  364. #endif
  365. }
  366. #if ENABLED(TOUCH_SCREEN)
  367. add_control(32, 176, DECREASE, imgDecrease);
  368. add_control(224, 176, INCREASE, imgIncrease);
  369. add_control(128, 176, CLICK, imgConfirm);
  370. #endif
  371. }
  372. // The Select Screen presents a prompt and two "buttons"
  373. 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*/) {
  374. uint16_t line = 1;
  375. if (string == NULL) line++;
  376. menu_line(line++);
  377. tft_string.set(pref);
  378. tft_string.trim();
  379. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  380. if (string) {
  381. menu_line(line++);
  382. tft_string.set(string);
  383. tft_string.trim();
  384. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  385. }
  386. if (suff) {
  387. menu_line(line);
  388. tft_string.set(suff);
  389. tft_string.trim();
  390. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  391. }
  392. #if ENABLED(TOUCH_SCREEN)
  393. add_control(48, 176, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
  394. add_control(208, 176, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
  395. #endif
  396. }
  397. #if ENABLED(SDSUPPORT)
  398. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
  399. menu_item(row, sel);
  400. if (isDir)
  401. tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  402. tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
  403. }
  404. #endif
  405. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  406. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  407. #if ENABLED(TOUCH_SCREEN)
  408. touch.clear();
  409. draw_menu_navigation = false;
  410. touch.add_control(RESUME_CONTINUE , 0, 0, 320, 240);
  411. #endif
  412. menu_line(row);
  413. tft_string.set(GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE));
  414. tft_string.add('E');
  415. tft_string.add((char)('1' + extruder));
  416. tft_string.add(' ');
  417. tft_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
  418. tft_string.add(LCD_STR_DEGREE);
  419. tft_string.add(" / ");
  420. tft_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
  421. tft_string.add(LCD_STR_DEGREE);
  422. tft_string.trim();
  423. tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  424. }
  425. #endif // ADVANCED_PAUSE_FEATURE
  426. #if ENABLED(AUTO_BED_LEVELING_UBL)
  427. #define GRID_OFFSET_X 8
  428. #define GRID_OFFSET_Y 8
  429. #define GRID_WIDTH 144
  430. #define GRID_HEIGHT 144
  431. #define CONTROL_OFFSET 8
  432. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  433. tft.canvas(GRID_OFFSET_X, GRID_OFFSET_Y, GRID_WIDTH, GRID_HEIGHT);
  434. tft.set_background(COLOR_BACKGROUND);
  435. tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE);
  436. for (uint16_t x = 0; x < GRID_MAX_POINTS_X ; x++)
  437. for (uint16_t y = 0; y < GRID_MAX_POINTS_Y ; y++)
  438. if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
  439. 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);
  440. 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);
  441. const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
  442. lpos = pos.asLogical();
  443. tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - 32) / 2 - 32, 96, 32);
  444. tft.set_background(COLOR_BACKGROUND);
  445. tft_string.set(X_LBL);
  446. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  447. tft_string.set(ftostr52(lpos.x));
  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, 96, 32);
  451. tft.set_background(COLOR_BACKGROUND);
  452. tft_string.set(Y_LBL);
  453. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  454. tft_string.set(ftostr52(lpos.y));
  455. tft_string.trim();
  456. tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  457. tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - 32) / 2 + 32, 96, 32);
  458. tft.set_background(COLOR_BACKGROUND);
  459. tft_string.set(Z_LBL);
  460. tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
  461. tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
  462. tft_string.trim();
  463. tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  464. tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32);
  465. tft.set_background(COLOR_BACKGROUND);
  466. tft_string.set(ui8tostr3rj(x_plot));
  467. tft_string.trim();
  468. tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  469. tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32);
  470. tft.set_background(COLOR_BACKGROUND);
  471. tft_string.set(ui8tostr3rj(y_plot));
  472. tft_string.trim();
  473. tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
  474. #if ENABLED(TOUCH_SCREEN)
  475. touch.clear();
  476. draw_menu_navigation = false;
  477. 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);
  478. 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);
  479. add_control(GRID_OFFSET_X + CONTROL_OFFSET, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, - ENCODER_STEPS_PER_MENU_ITEM, imgLeft);
  480. add_control(GRID_OFFSET_X + GRID_WIDTH - CONTROL_OFFSET - 32, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, ENCODER_STEPS_PER_MENU_ITEM, imgRight);
  481. add_control(224, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, CLICK, imgLeveling);
  482. add_control(144, 206, BACK, imgBack);
  483. #endif
  484. }
  485. #endif // AUTO_BED_LEVELING_UBL
  486. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  487. void MarlinUI::touch_calibration() {
  488. static uint16_t x, y;
  489. calibrationState calibration_stage = touch.get_calibration_state();
  490. if (calibration_stage == CALIBRATION_NONE) {
  491. defer_status_screen(true);
  492. clear_lcd();
  493. calibration_stage = touch.calibration_start();
  494. }
  495. else {
  496. tft.canvas(x - 15, y - 15, 31, 31);
  497. tft.set_background(COLOR_BACKGROUND);
  498. }
  499. x = 20; y = 20;
  500. touch.clear();
  501. if (calibration_stage < CALIBRATION_SUCCESS) {
  502. switch (calibration_stage) {
  503. case CALIBRATION_POINT_1: tft_string.set("Top Left"); break;
  504. case CALIBRATION_POINT_2: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break;
  505. case CALIBRATION_POINT_3: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break;
  506. case CALIBRATION_POINT_4: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break;
  507. default: break;
  508. }
  509. tft.canvas(x - 15, y - 15, 31, 31);
  510. tft.set_background(COLOR_BACKGROUND);
  511. tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
  512. tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
  513. touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
  514. }
  515. else {
  516. tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed");
  517. defer_status_screen(false);
  518. touch.calibration_end();
  519. touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
  520. }
  521. tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
  522. tft.set_background(COLOR_BACKGROUND);
  523. tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
  524. }
  525. #endif // TOUCH_SCREEN_CALIBRATION
  526. void menu_line(const uint8_t row, uint16_t color) {
  527. tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32);
  528. tft.set_background(color);
  529. }
  530. void menu_pause_option();
  531. void menu_item(const uint8_t row, bool sel ) {
  532. #if ENABLED(TOUCH_SCREEN)
  533. if (row == 0) {
  534. touch.clear();
  535. draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
  536. }
  537. #endif
  538. menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
  539. TERN_(TOUCH_SCREEN, touch.add_control(sel ? CLICK : MENU_ITEM, 0, 2 + 34 * row, 320, 32, encoderTopLine + row));
  540. }
  541. void MarlinUI::move_axis_screen() {
  542. }
  543. #endif // HAS_UI_320x240