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.

marlinui_TFTGLCD.cpp 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 IS_TFTGLCD_PANEL
  24. /**
  25. * marlinui_TFTGLCD.cpp
  26. *
  27. * Implementation of the LCD display routines for a TFT GLCD displays with external controller.
  28. * This display looks like a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER but has good text font
  29. * and supports color output.
  30. */
  31. #if NONE(__AVR__, TARGET_LPC1768, STM32F1, STM32F4xx)
  32. #warning "Selected platform not yet tested. Please contribute your good pin mappings."
  33. #endif
  34. #if ENABLED(TFTGLCD_PANEL_SPI)
  35. #include <SPI.h>
  36. #else
  37. #include <Wire.h>
  38. #endif
  39. #include "marlinui_TFTGLCD.h"
  40. #include "../marlinui.h"
  41. #include "../../libs/numtostr.h"
  42. #include "../../sd/cardreader.h"
  43. #include "../../module/temperature.h"
  44. #include "../../module/printcounter.h"
  45. #include "../../module/planner.h"
  46. #include "../../module/motion.h"
  47. #if DISABLED(LCD_PROGRESS_BAR) && BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  48. #include "../../feature/filwidth.h"
  49. #include "../../gcode/parser.h"
  50. #endif
  51. #if ENABLED(AUTO_BED_LEVELING_UBL)
  52. #include "../../feature/bedlevel/bedlevel.h"
  53. #endif
  54. TFTGLCD lcd;
  55. #define ICON_LOGO B00000001
  56. #define ICON_TEMP1 B00000010 //hotend 1
  57. #define ICON_TEMP2 B00000100 //hotend 2
  58. #define ICON_TEMP3 B00001000 //hotend 3
  59. #define ICON_BED B00010000
  60. #define ICON_FAN B00100000
  61. #define ICON_HOT B01000000 //when any T > 50deg
  62. #define PIC_MASK 0x7F
  63. // LEDs not used, for compatibility with Smoothieware
  64. #define LED_HOTEND_ON B00000001
  65. #define LED_BED_ON B00000010
  66. #define LED_FAN_ON B00000100
  67. #define LED_HOT B00001000
  68. #define LED_MASK 0x0F
  69. #define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2)
  70. #define MIDDLE_Y ((LCD_HEIGHT - 1) / 2)
  71. // Markers for change line colors
  72. #define COLOR_EDIT '#'
  73. #define COLOR_ERROR '!'
  74. #ifdef CONVERT_TO_EXT_ASCII //use standart pseudographic symbols in ASCII table
  75. #define LR 179 //vertical line
  76. #define TRC 191 //top right corner
  77. #define BLC 192 //bottom left corner
  78. #define GL 196 //horizontal line
  79. #define BRC 217 //bottom right corner, should be replaced to 12 for some languages
  80. #define TLC 218 //top left corner, should be replaced to 13 for some languages
  81. #else //next symbols must be present in panel font
  82. #define LR 8 //equal to 179
  83. #define TRC 9 //equal to 191
  84. #define BLC 10 //equal to 192
  85. #define GL 11 //equal to 196
  86. #define BRC 12 //equal to 217
  87. #define TLC 13 //equal to 218
  88. #endif
  89. #define Marlin 0x01
  90. enum Commands { // based on Smoothieware commands
  91. GET_SPI_DATA = 0,
  92. READ_BUTTONS, // read buttons
  93. READ_ENCODER, // read encoder
  94. LCD_WRITE, // write all screen to LCD
  95. BUZZER, // beep buzzer
  96. CONTRAST, // set contrast (brightnes)
  97. // Other commands... 0xE0 thru 0xFF
  98. GET_LCD_ROW = 0xE0, // for detect panel
  99. GET_LCD_COL, // reserved for compatibility with Smoothieware, not used
  100. LCD_PUT, // write one line to LCD
  101. CLR_SCREEN,
  102. INIT_SCREEN = 0xFE // clear panel buffer
  103. };
  104. static unsigned char framebuffer[FBSIZE];
  105. static unsigned char *fb;
  106. static uint8_t cour_line;
  107. static uint8_t picBits, ledBits, hotBits;
  108. static uint8_t PanelDetected = 0;
  109. // Different platforms use different SPI methods
  110. #if ANY(__AVR__, TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
  111. #define SPI_SEND_ONE(V) SPI.transfer(V);
  112. #define SPI_SEND_TWO(V) SPI.transfer16(V);
  113. #elif EITHER(STM32F4xx, STM32F1xx)
  114. #define SPI_SEND_ONE(V) SPI.transfer(V, SPI_CONTINUE);
  115. #define SPI_SEND_TWO(V) SPI.transfer16(V, SPI_CONTINUE);
  116. #elif defined(ARDUINO_ARCH_ESP32)
  117. #define SPI_SEND_ONE(V) SPI.write(V);
  118. #define SPI_SEND_TWO(V) SPI.write16(V);
  119. #endif
  120. #if ANY(__AVR__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
  121. #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L);
  122. #elif EITHER(STM32F4xx, STM32F1xx)
  123. #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L, SPI_CONTINUE);
  124. #elif ANY(TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_ESP32)
  125. #define SPI_SEND_SOME(V,L,Z) do{ for (uint16_t i = 0; i < L; i++) SPI_SEND_ONE(V[(Z)+i]); }while(0)
  126. #endif
  127. // Constructor
  128. TFTGLCD::TFTGLCD() {}
  129. // Clear local buffer
  130. void TFTGLCD::clear_buffer() {
  131. memset(&framebuffer[0], ' ', FBSIZE - 2);
  132. framebuffer[FBSIZE - 1] = framebuffer[FBSIZE - 2] = 0;
  133. picBits = ledBits = 0;
  134. }
  135. // Clear panel's screen
  136. void TFTGLCD::clr_screen() {
  137. if (!PanelDetected) return;
  138. #if ENABLED(TFTGLCD_PANEL_SPI)
  139. WRITE(TFTGLCD_CS, LOW);
  140. SPI_SEND_ONE(CLR_SCREEN);
  141. WRITE(TFTGLCD_CS, HIGH);
  142. #else
  143. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
  144. Wire.write(CLR_SCREEN);
  145. Wire.endTransmission(); //transmit data
  146. #endif
  147. }
  148. // Set new text cursor position
  149. void TFTGLCD::setCursor(uint8_t col, uint8_t row) {
  150. fb = &framebuffer[0] + col + row * LCD_WIDTH;
  151. cour_line = row;
  152. }
  153. // Send char to buffer
  154. void TFTGLCD::write(char c) {
  155. *fb++ = c;
  156. }
  157. // Send text line to buffer
  158. void TFTGLCD::print(const char *line) {
  159. while (*line) *fb++ = *line++;
  160. }
  161. // For menu
  162. void TFTGLCD::print_line() {
  163. if (!PanelDetected) return;
  164. #if ENABLED(TFTGLCD_PANEL_SPI)
  165. WRITE(TFTGLCD_CS, LOW);
  166. SPI_SEND_ONE(LCD_PUT);
  167. SPI_SEND_ONE(cour_line);
  168. SPI_SEND_SOME(framebuffer, LCD_WIDTH, cour_line * LCD_WIDTH);
  169. WRITE(TFTGLCD_CS, HIGH);
  170. #else
  171. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
  172. Wire.write(LCD_PUT);
  173. Wire.write(cour_line);
  174. Wire.write(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); //transfer 1 line to txBuffer
  175. Wire.endTransmission(); //transmit data
  176. safe_delay(1);
  177. #endif
  178. }
  179. void TFTGLCD::print_screen() {
  180. if (!PanelDetected) return;
  181. framebuffer[FBSIZE - 2] = picBits & PIC_MASK;
  182. framebuffer[FBSIZE - 1] = ledBits;
  183. #if ENABLED(TFTGLCD_PANEL_SPI)
  184. // Send all framebuffer to panel
  185. WRITE(TFTGLCD_CS, LOW);
  186. SPI_SEND_ONE(LCD_WRITE);
  187. SPI_SEND_SOME(framebuffer, FBSIZE, 0);
  188. WRITE(TFTGLCD_CS, HIGH);
  189. #else
  190. uint8_t r;
  191. // Send framebuffer to panel by line
  192. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  193. // First line
  194. Wire.write(LCD_WRITE);
  195. Wire.write(&framebuffer[0], LCD_WIDTH);
  196. Wire.endTransmission();
  197. for (r = 1; r < (LCD_HEIGHT - 1); r++) {
  198. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  199. Wire.write(&framebuffer[r * LCD_WIDTH], LCD_WIDTH);
  200. Wire.endTransmission();
  201. }
  202. // Last line
  203. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  204. Wire.write(&framebuffer[r * LCD_WIDTH], LCD_WIDTH);
  205. Wire.write(&framebuffer[FBSIZE - 2], 2);
  206. Wire.endTransmission();
  207. #endif
  208. }
  209. void TFTGLCD::setContrast(uint16_t contrast) {
  210. if (!PanelDetected) return;
  211. #if ENABLED(TFTGLCD_PANEL_SPI)
  212. WRITE(TFTGLCD_CS, LOW);
  213. SPI_SEND_ONE(CONTRAST);
  214. SPI_SEND_ONE((uint8_t)contrast);
  215. WRITE(TFTGLCD_CS, HIGH);
  216. #else
  217. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  218. Wire.write(CONTRAST);
  219. Wire.write((uint8_t)contrast);
  220. Wire.endTransmission();
  221. #endif
  222. }
  223. extern volatile int8_t encoderDiff;
  224. // Read buttons and encoder states
  225. uint8_t MarlinUI::read_slow_buttons(void) {
  226. if (!PanelDetected) return 0;
  227. #if ENABLED(TFTGLCD_PANEL_SPI)
  228. uint8_t b = 0;
  229. WRITE(TFTGLCD_CS, LOW);
  230. SPI_SEND_ONE(READ_ENCODER);
  231. #ifndef STM32F4xx
  232. WRITE(TFTGLCD_CS, LOW); // for delay
  233. #endif
  234. encoderDiff += SPI_SEND_ONE(READ_BUTTONS);
  235. #ifndef STM32F4xx
  236. WRITE(TFTGLCD_CS, LOW); // for delay
  237. WRITE(TFTGLCD_CS, LOW);
  238. #endif
  239. b = SPI_SEND_ONE(GET_SPI_DATA);
  240. WRITE(TFTGLCD_CS, HIGH);
  241. return b;
  242. #else
  243. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  244. Wire.write(READ_ENCODER);
  245. Wire.endTransmission();
  246. #ifdef __AVR__
  247. Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1);
  248. #elif defined(STM32F1)
  249. Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2);
  250. #elif EITHER(STM32F4xx, TARGET_LPC1768)
  251. Wire.requestFrom(LCD_I2C_ADDRESS, 2);
  252. #endif
  253. encoderDiff += Wire.read();
  254. return Wire.read(); //buttons
  255. #endif
  256. }
  257. // Duration in ms, freq in Hz
  258. void MarlinUI::buzz(const long duration, const uint16_t freq) {
  259. if (!PanelDetected) return;
  260. if (!buzzer_enabled) return;
  261. #if ENABLED(TFTGLCD_PANEL_SPI)
  262. WRITE(TFTGLCD_CS, LOW);
  263. SPI_SEND_ONE(BUZZER);
  264. SPI_SEND_TWO((uint16_t)duration);
  265. SPI_SEND_TWO(freq);
  266. WRITE(TFTGLCD_CS, HIGH);
  267. #else
  268. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  269. Wire.write(BUZZER);
  270. Wire.write((uint8_t)(duration >> 8));
  271. Wire.write((uint8_t)duration);
  272. Wire.write((uint8_t)(freq >> 8));
  273. Wire.write((uint8_t)freq);
  274. Wire.endTransmission();
  275. #endif
  276. }
  277. void MarlinUI::init_lcd() {
  278. uint8_t t;
  279. lcd.clear_buffer();
  280. t = 0;
  281. #if ENABLED(TFTGLCD_PANEL_SPI)
  282. // SPI speed must be less 10MHz
  283. SET_OUTPUT(TFTGLCD_CS);
  284. WRITE(TFTGLCD_CS, HIGH);
  285. spiInit(TERN(__STM32F1__, SPI_QUARTER_SPEED, SPI_FULL_SPEED));
  286. WRITE(TFTGLCD_CS, LOW);
  287. SPI_SEND_ONE(GET_LCD_ROW);
  288. t = SPI_SEND_ONE(GET_SPI_DATA);
  289. #else
  290. #ifdef TARGET_LPC1768
  291. Wire.begin(); //init twi/I2C
  292. #else
  293. Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C
  294. #endif
  295. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  296. Wire.write((uint8_t)GET_LCD_ROW); // put command to buffer
  297. Wire.endTransmission(); // send buffer
  298. #ifdef __AVR__
  299. Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1);
  300. #elif ANY(STM32F1, STM32F4xx, TARGET_LPC1768)
  301. Wire.requestFrom(LCD_I2C_ADDRESS, 1);
  302. #endif
  303. t = (uint8_t)Wire.read();
  304. #endif
  305. if (t == LCD_HEIGHT) {
  306. PanelDetected = 1;
  307. #if ENABLED(TFTGLCD_PANEL_SPI)
  308. SPI_SEND_ONE(INIT_SCREEN);
  309. SPI_SEND_ONE(Marlin);
  310. WRITE(TFTGLCD_CS, HIGH);
  311. #else
  312. Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
  313. Wire.write((uint8_t)INIT_SCREEN);
  314. Wire.write(Marlin);
  315. Wire.endTransmission();
  316. #endif
  317. }
  318. else
  319. PanelDetected = 0;
  320. safe_delay(100);
  321. }
  322. bool MarlinUI::detected() {
  323. return PanelDetected;
  324. }
  325. void MarlinUI::clear_lcd() {
  326. if (!PanelDetected) return;
  327. lcd.clr_screen();
  328. lcd.clear_buffer();
  329. }
  330. int16_t MarlinUI::contrast; // Initialized by settings.load()
  331. void MarlinUI::set_contrast(const int16_t value) {
  332. contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  333. lcd.setContrast(contrast);
  334. }
  335. static void center_text_P(PGM_P pstart, uint8_t y) {
  336. uint8_t len = utf8_strlen_P(pstart);
  337. if (len < LCD_WIDTH)
  338. lcd.setCursor((LCD_WIDTH - len) / 2, y);
  339. else
  340. lcd.setCursor(0, y);
  341. lcd_put_u8str_P(pstart);
  342. }
  343. #if ENABLED(SHOW_BOOTSCREEN)
  344. void MarlinUI::show_bootscreen() {
  345. if (!PanelDetected) return;
  346. //
  347. // Show the Marlin logo, splash line1, and splash line 2
  348. //
  349. uint8_t indent = (LCD_WIDTH - 8) / 2;
  350. // symbols 217 (bottom right corner) and 218 (top left corner) are using for letters in some languages
  351. // and they should be moved to begining ASCII table as spetial symbols
  352. lcd.setCursor(indent, 0); lcd.write(TLC); lcd_put_u8str_P(PSTR("------")); lcd.write(TRC);
  353. lcd.setCursor(indent, 1); lcd.write(LR); lcd_put_u8str_P(PSTR("Marlin")); lcd.write(LR);
  354. lcd.setCursor(indent, 2); lcd.write(BLC); lcd_put_u8str_P(PSTR("------")); lcd.write(BRC);
  355. center_text_P(PSTR(SHORT_BUILD_VERSION), 3);
  356. center_text_P(PSTR(MARLIN_WEBSITE_URL), 4);
  357. picBits = ICON_LOGO;
  358. lcd.print_screen();
  359. safe_delay(1500);
  360. }
  361. #endif // SHOW_BOOTSCREEN
  362. void MarlinUI::draw_kill_screen() {
  363. if (!PanelDetected) return;
  364. lcd.clear_buffer();
  365. lcd.setCursor(0, 3); lcd.write(COLOR_ERROR);
  366. lcd.setCursor((LCD_WIDTH - utf8_strlen(status_message)) / 2 + 1, 3);
  367. lcd_put_u8str(status_message);
  368. center_text_P(GET_TEXT(MSG_HALTED), 5);
  369. center_text_P(GET_TEXT(MSG_PLEASE_RESET), 6);
  370. lcd.print_screen();
  371. }
  372. //
  373. // Before homing, blink '123' <-> '???'.
  374. // Homed but unknown... '123' <-> ' '.
  375. // Homed and known, display constantly.
  376. //
  377. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  378. lcd.write('X' + uint8_t(axis));
  379. if (blink)
  380. lcd.print(value);
  381. else if (axis_should_home(axis))
  382. while (const char c = *value++) lcd.write(c <= '.' ? c : '?');
  383. else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
  384. lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
  385. else
  386. lcd_put_u8str(value);
  387. }
  388. FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *prefix, const bool blink) {
  389. uint8_t pic_hot_bits;
  390. #if HAS_HEATED_BED
  391. const bool isBed = heater_id < 0;
  392. const celsius_t t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater_id)),
  393. t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
  394. #else
  395. const celsius_t t1 = thermalManager.degHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id);
  396. #endif
  397. #if HOTENDS < 2
  398. if (heater_id == H_E0) {
  399. lcd.setCursor(2, 5); lcd.print(prefix); //HE
  400. lcd.setCursor(1, 6); lcd.print(i16tostr3rj(t1));
  401. lcd.setCursor(1, 7);
  402. }
  403. else {
  404. lcd.setCursor(6, 5); lcd.print(prefix); //BED
  405. lcd.setCursor(6, 6); lcd.print(i16tostr3rj(t1));
  406. lcd.setCursor(6, 7);
  407. }
  408. #else
  409. if (heater_id > H_BED) {
  410. lcd.setCursor(heater_id * 4, 5); lcd.print(prefix); // HE1 or HE2 or HE3
  411. lcd.setCursor(heater_id * 4, 6); lcd.print(i16tostr3rj(t1));
  412. lcd.setCursor(heater_id * 4, 7);
  413. }
  414. else {
  415. lcd.setCursor(13, 5); lcd.print(prefix); //BED
  416. lcd.setCursor(13, 6); lcd.print(i16tostr3rj(t1));
  417. lcd.setCursor(13, 7);
  418. }
  419. #endif // HOTENDS <= 1
  420. #if !HEATER_IDLE_HANDLER
  421. UNUSED(blink);
  422. #else
  423. if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
  424. lcd.write(' ');
  425. if (t2 >= 10) lcd.write(' ');
  426. if (t2 >= 100) lcd.write(' ');
  427. }
  428. else
  429. #endif // !HEATER_IDLE_HANDLER
  430. lcd.print(i16tostr3rj(t2));
  431. switch (heater_id) {
  432. case H_BED: pic_hot_bits = ICON_BED; break;
  433. case H_E0: pic_hot_bits = ICON_TEMP1; break;
  434. case H_E1: pic_hot_bits = ICON_TEMP2; break;
  435. case H_E2: pic_hot_bits = ICON_TEMP3;
  436. default: break;
  437. }
  438. if (t2) picBits |= pic_hot_bits;
  439. else picBits &= ~pic_hot_bits;
  440. if (t1 > 50) hotBits |= pic_hot_bits;
  441. else hotBits &= ~pic_hot_bits;
  442. if (hotBits) picBits |= ICON_HOT;
  443. else picBits &= ~ICON_HOT;
  444. }
  445. #if HAS_PRINT_PROGRESS
  446. FORCE_INLINE void _draw_print_progress() {
  447. if (!PanelDetected) return;
  448. const uint8_t progress = ui._get_progress();
  449. #if ENABLED(SDSUPPORT)
  450. lcd_put_u8str_P(PSTR("SD"));
  451. #elif ENABLED(LCD_SET_PROGRESS_MANUALLY)
  452. lcd_put_u8str_P(PSTR("P:"));
  453. #endif
  454. if (progress)
  455. lcd.print(ui8tostr3rj(progress));
  456. else
  457. lcd_put_u8str_P(PSTR("---"));
  458. lcd.write('%');
  459. }
  460. #endif // HAS_PRINT_PROGRESS
  461. #if ENABLED(LCD_PROGRESS_BAR)
  462. void MarlinUI::draw_progress_bar(const uint8_t percent) {
  463. if (!PanelDetected) return;
  464. if (fb == &framebuffer[0] + LCD_WIDTH * 2) { // For status screen
  465. lcd.write('%'); lcd.write(percent);
  466. }
  467. else { // For progress bar test
  468. lcd.setCursor(LCD_WIDTH / 2 - 2, MIDDLE_Y);
  469. lcd.print(i16tostr3rj(percent)); lcd.write('%');
  470. lcd.print_line();
  471. lcd.setCursor(0, MIDDLE_Y + 1);
  472. lcd.write('%'); lcd.write(percent);
  473. lcd.print_line();
  474. }
  475. }
  476. #endif
  477. void MarlinUI::draw_status_message(const bool blink) {
  478. if (!PanelDetected) return;
  479. lcd.setCursor(0, 3);
  480. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  481. // Alternate Status message and Filament display
  482. if (ELAPSED(millis(), next_filament_display)) {
  483. lcd_put_u8str_P(PSTR("Dia "));
  484. lcd.print(ftostr12ns(filament_width_meas));
  485. lcd_put_u8str_P(PSTR(" V"));
  486. lcd.print(i16tostr3rj(100.0 * (
  487. parser.volumetric_enabled
  488. ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  489. : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  490. )
  491. ));
  492. lcd.write('%');
  493. return;
  494. }
  495. #endif // FILAMENT_LCD_DISPLAY && SDSUPPORT
  496. // Get the UTF8 character count of the string
  497. uint8_t slen = utf8_strlen(status_message);
  498. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  499. static bool last_blink = false;
  500. // If the string fits into the LCD, just print it and do not scroll it
  501. if (slen <= LCD_WIDTH) {
  502. // The string isn't scrolling and may not fill the screen
  503. lcd_put_u8str(status_message);
  504. // Fill the rest with spaces
  505. while (slen < LCD_WIDTH) { lcd.write(' '); ++slen; }
  506. }
  507. else {
  508. // String is larger than the available space in screen.
  509. // Get a pointer to the next valid UTF8 character
  510. // and the string remaining length
  511. uint8_t rlen;
  512. const char *stat = status_and_len(rlen);
  513. lcd_put_u8str_max(stat, LCD_WIDTH); // The string leaves space
  514. // If the remaining string doesn't completely fill the screen
  515. if (rlen < LCD_WIDTH) {
  516. uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
  517. lcd.write(' '); // Always at 1+ spaces left, draw a space
  518. if (--chars) { // Draw a second space if there's room
  519. lcd.write(' ');
  520. if (--chars) { // Draw a third space if there's room
  521. lcd.write(' ');
  522. if (--chars)
  523. lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
  524. }
  525. }
  526. }
  527. if (last_blink != blink) {
  528. last_blink = blink;
  529. advance_status_scroll();
  530. }
  531. }
  532. #else
  533. UNUSED(blink);
  534. // Just print the string to the LCD
  535. lcd_put_u8str_max(status_message, LCD_WIDTH);
  536. // Fill the rest with spaces if there are missing spaces
  537. while (slen < LCD_WIDTH) {
  538. lcd.write(' ');
  539. ++slen;
  540. }
  541. #endif
  542. }
  543. /**
  544. Possible status screens:
  545. Equal to 20x10 text LCD
  546. |X 000 Y 000 Z 000.00|
  547. |FR100% SD100% C--:--|
  548. | Progress bar line |
  549. |Status message |
  550. | |
  551. | HE BED FAN |
  552. | ttc ttc % | ttc - current temperature
  553. | tts tts %%% | tts - setted temperature, %%% - percent for FAN
  554. | ICO ICO ICO ICO | ICO - icon 48x48, placed in 2 text lines
  555. | ICO ICO ICO ICO | ICO
  556. or
  557. |X 000 Y 000 Z 000.00|
  558. |FR100% SD100% C--:--|
  559. | Progress bar line |
  560. |Status message |
  561. | |
  562. |HE1 HE2 HE3 BED ICO|
  563. |ttc ttc ttc ttc ICO|
  564. |tts tts tts tts %%%|
  565. |ICO ICO ICO ICO ICO|
  566. |ICO ICO ICO ICO ICO|
  567. or
  568. Equal to 24x10 text LCD
  569. |X 000 Y 000 Z 000.00 |
  570. |FR100% SD100% C--:--|
  571. | Progress bar line |
  572. |Status message |
  573. | |
  574. |HE1 HE2 HE3 BED FAN |
  575. |ttc ttc ttc ttc % |
  576. |tts tts tts tts %%% |
  577. |ICO ICO ICO ICO ICO ICO|
  578. |ICO ICO ICO ICO ICO ICO|
  579. */
  580. void MarlinUI::draw_status_screen() {
  581. if (!PanelDetected) return;
  582. const bool blink = get_blink();
  583. lcd.clear_buffer();
  584. //
  585. // Line 1 - XYZ coordinates
  586. //
  587. lcd.setCursor(0, 0);
  588. _draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position.x)), blink); lcd.write(' ');
  589. _draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position.y)), blink); lcd.write(' ');
  590. _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink);
  591. #if HAS_LEVELING && !HAS_HEATED_BED
  592. lcd.write(planner.leveling_active || blink ? '_' : ' ');
  593. #endif
  594. //
  595. // Line 2 - feedrate, , time
  596. //
  597. lcd.setCursor(0, 1);
  598. lcd_put_u8str_P(PSTR("FR")); lcd.print(i16tostr3rj(feedrate_percentage)); lcd.write('%');
  599. #if BOTH(SDSUPPORT, HAS_PRINT_PROGRESS)
  600. lcd.setCursor(LCD_WIDTH / 2 - 3, 1);
  601. _draw_print_progress();
  602. #endif
  603. char buffer[10];
  604. duration_t elapsed = print_job_timer.duration();
  605. uint8_t len = elapsed.toDigital(buffer);
  606. lcd.setCursor((LCD_WIDTH - 1) - len, 1);
  607. lcd.write(LCD_STR_CLOCK[0]); lcd.print(buffer);
  608. //
  609. // Line 3 - progressbar
  610. //
  611. lcd.setCursor(0, 2);
  612. #if ENABLED(LCD_PROGRESS_BAR)
  613. draw_progress_bar(_get_progress());
  614. #else
  615. lcd.write('%'); lcd.write(0);
  616. #endif
  617. //
  618. // Line 4 - Status Message (which may be a Filament display)
  619. //
  620. draw_status_message(blink);
  621. //
  622. // Line 5
  623. //
  624. #if HOTENDS <= 1 || (HOTENDS <= 2 && !HAS_HEATED_BED)
  625. #if DUAL_MIXING_EXTRUDER
  626. lcd.setCursor(0, 4);
  627. // Two-component mix / gradient instead of XY
  628. char mixer_messages[12];
  629. const char *mix_label;
  630. #if ENABLED(GRADIENT_MIX)
  631. if (mixer.gradient.enabled) {
  632. mixer.update_mix_from_gradient();
  633. mix_label = "Gr";
  634. }
  635. else
  636. #endif
  637. {
  638. mixer.update_mix_from_vtool();
  639. mix_label = "Mx";
  640. }
  641. sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
  642. lcd_put_u8str(mixer_messages);
  643. #endif
  644. #endif
  645. //
  646. // Line 6..8 Temperatures, FAN
  647. //
  648. #if HOTENDS < 2
  649. _draw_heater_status(H_E0, "HE", blink); // Hotend Temperature
  650. #else
  651. _draw_heater_status(H_E0, "HE1", blink); // Hotend 1 Temperature
  652. _draw_heater_status(H_E1, "HE2", blink); // Hotend 2 Temperature
  653. #if HOTENDS > 2
  654. _draw_heater_status(H_E2, "HE3", blink); // Hotend 3 Temperature
  655. #endif
  656. #endif
  657. #if HAS_HEATED_BED
  658. #if HAS_LEVELING
  659. _draw_heater_status(H_BED, (planner.leveling_active && blink ? "___" : "BED"), blink);
  660. #else
  661. _draw_heater_status(H_BED, "BED", blink);
  662. #endif
  663. #endif
  664. #if HAS_FAN
  665. uint16_t spd = thermalManager.fan_speed[0];
  666. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  667. if (!blink) spd = thermalManager.scaledFanSpeed(0, spd);
  668. #endif
  669. uint16_t per = thermalManager.pwmToPercent(spd);
  670. #if HOTENDS < 2
  671. #define FANX 11
  672. #else
  673. #define FANX 17
  674. #endif
  675. lcd.setCursor(FANX, 5); lcd_put_u8str_P(PSTR("FAN"));
  676. lcd.setCursor(FANX + 1, 6); lcd.write('%');
  677. lcd.setCursor(FANX, 7);
  678. lcd.print(i16tostr3rj(per));
  679. if (TERN0(HAS_FAN0, thermalManager.fan_speed[0]) || TERN0(HAS_FAN1, thermalManager.fan_speed[1]) || TERN0(HAS_FAN2, thermalManager.fan_speed[2]))
  680. picBits |= ICON_FAN;
  681. else
  682. picBits &= ~ICON_FAN;
  683. #endif // HAS_FAN
  684. //
  685. // Line 9, 10 - icons
  686. //
  687. lcd.print_screen();
  688. }
  689. #if HAS_LCD_MENU
  690. #include "../menu/menu.h"
  691. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  692. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  693. if (!PanelDetected) return;
  694. lcd.setCursor((LCD_WIDTH - 14) / 2, row + 1);
  695. lcd.write(LCD_STR_THERMOMETER[0]); lcd_put_u8str_P(PSTR(" E")); lcd.write('1' + extruder); lcd.write(' ');
  696. lcd.print(i16tostr3rj(thermalManager.degHotend(extruder))); lcd.write(LCD_STR_DEGREE[0]); lcd.write('/');
  697. lcd.print(i16tostr3rj(thermalManager.degTargetHotend(extruder))); lcd.write(LCD_STR_DEGREE[0]);
  698. lcd.print_line();
  699. }
  700. #endif
  701. // Draw a static item with no left-right margin required. Centered by default.
  702. void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) {
  703. if (!PanelDetected) return;
  704. uint8_t n = LCD_WIDTH;
  705. lcd.setCursor(0, row);
  706. if ((style & SS_CENTER) && !valstr) {
  707. int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
  708. while (--pad >= 0) { lcd.write(' '); n--; }
  709. }
  710. n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n);
  711. if (valstr) n -= lcd_put_u8str_max(valstr, n);
  712. for (; n; --n) lcd.write(' ');
  713. lcd.print_line();
  714. }
  715. // Draw a generic menu item with pre_char (if selected) and post_char
  716. void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
  717. if (!PanelDetected) return;
  718. lcd.setCursor(0, row);
  719. lcd.write(sel ? pre_char : ' ');
  720. uint8_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2);
  721. for (; n; --n) lcd.write(' ');
  722. lcd.write(post_char);
  723. lcd.print_line();
  724. }
  725. // Draw a menu item with a (potentially) editable value
  726. void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char * const data, const bool pgm) {
  727. if (!PanelDetected) return;
  728. const uint8_t vlen = data ? (pgm ? utf8_strlen_P(data) : utf8_strlen(data)) : 0;
  729. lcd.setCursor(0, row);
  730. lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
  731. uint8_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vlen);
  732. if (vlen) {
  733. lcd.write(':');
  734. for (; n; --n) lcd.write(' ');
  735. if (pgm) lcd_put_u8str_P(data); else lcd_put_u8str(data);
  736. }
  737. lcd.print_line();
  738. }
  739. // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
  740. // This line moves to the last line of the screen for UBL plot screen on the panel side
  741. void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
  742. if (!PanelDetected) return;
  743. ui.encoder_direction_normal();
  744. const uint8_t y = TERN0(AUTO_BED_LEVELING_UBL, ui.external_control) ? LCD_HEIGHT - 1 : MIDDLE_Y;
  745. lcd.setCursor(0, y);
  746. lcd.write(COLOR_EDIT);
  747. lcd_put_u8str_P(pstr);
  748. if (value) {
  749. lcd.write(':');
  750. lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), y); // Right-justified, padded by spaces
  751. lcd.write(' '); // Overwrite char if value gets shorter
  752. lcd.print(value);
  753. lcd.write(' ');
  754. lcd.print_line();
  755. }
  756. }
  757. // The Select Screen presents a prompt and two "buttons"
  758. 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, PGM_P const suff) {
  759. if (!PanelDetected) return;
  760. ui.draw_select_screen_prompt(pref, string, suff);
  761. lcd.setCursor(0, MIDDLE_Y);
  762. lcd.write(COLOR_EDIT);
  763. lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']');
  764. lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, MIDDLE_Y);
  765. lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' ');
  766. lcd.print_line();
  767. }
  768. #if ENABLED(SDSUPPORT)
  769. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
  770. if (!PanelDetected) return;
  771. lcd.setCursor(0, row);
  772. lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
  773. constexpr uint8_t maxlen = LCD_WIDTH - 2;
  774. uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
  775. for (; n; --n) lcd.write(' ');
  776. lcd.write(isDir ? LCD_STR_FOLDER[0] : ' ');
  777. lcd.print_line();
  778. }
  779. #endif // SDSUPPORT
  780. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  781. void MarlinUI::update_indicators() {}
  782. #endif // LCD_HAS_STATUS_INDICATORS
  783. #if ENABLED(AUTO_BED_LEVELING_UBL)
  784. /**
  785. * Map screen:
  786. * |/---------\ (00,00) |
  787. * || . . . . | X:000.00|
  788. * || . . . . | Y:000.00|
  789. * || . . . . | Z:00.000|
  790. * || . . . . | |
  791. * || . . . . | |
  792. * || . . . . | |
  793. * |+---------/ |
  794. * | |
  795. * |____________________|
  796. */
  797. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  798. if (!PanelDetected) return;
  799. #define _LCD_W_POS 12
  800. lcd.clear_buffer();
  801. //print only top left corner. All frame with grid points will be printed by panel
  802. lcd.setCursor(0, 0);
  803. *fb++ = TLC; //top left corner - marker for plot parameters
  804. *fb = (GRID_MAX_POINTS_X << 4) + GRID_MAX_POINTS_Y; //set mesh size
  805. // Print plot position
  806. lcd.setCursor(_LCD_W_POS, 0);
  807. *fb++ = '('; lcd.print(i16tostr3left(x_plot));
  808. *fb++ = ','; lcd.print(i16tostr3left(y_plot)); *fb = ')';
  809. // Show all values
  810. lcd.setCursor(_LCD_W_POS, 1); lcd_put_u8str_P(PSTR("X:"));
  811. lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  812. lcd.setCursor(_LCD_W_POS, 2); lcd_put_u8str_P(PSTR("Y:"));
  813. lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  814. // Show the location value
  815. lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str_P(PSTR("Z:"));
  816. if (!ISNAN(ubl.z_values[x_plot][y_plot]))
  817. lcd.print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  818. else
  819. lcd_put_u8str_P(PSTR(" -----"));
  820. center_text_P(GET_TEXT(MSG_UBL_FINE_TUNE_MESH), 8);
  821. lcd.print_screen();
  822. }
  823. #endif // AUTO_BED_LEVELING_UBL
  824. #endif // HAS_LCD_MENU
  825. #endif // IS_TFTGLCD_PANEL