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.

ultralcd_implementation_hitachi_HD44780.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. #ifndef ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H
  2. #define ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H
  3. /**
  4. * Implementation of the LCD display routines for a hitachi HD44780 display. These are common LCD character displays.
  5. * When selecting the rusian language, a slightly different LCD implementation is used to handle UTF8 characters.
  6. **/
  7. #if LANGUAGE_CHOICE == 6
  8. #include "LiquidCrystalRus.h"
  9. #define LCD_CLASS LiquidCrystalRus
  10. #else
  11. #ifdef LCD_I2C
  12. #include <Wire.h>
  13. #include <LiquidCrystal_I2C.h>
  14. #define LCD_CLASS LiquidCrystal_I2C
  15. #else
  16. #include <LiquidCrystal.h>
  17. #define LCD_CLASS LiquidCrystal
  18. #endif
  19. #endif
  20. /* Custom characters defined in the first 8 characters of the LCD */
  21. #define LCD_STR_BEDTEMP "\x00"
  22. #define LCD_STR_DEGREE "\x01"
  23. #define LCD_STR_THERMOMETER "\x02"
  24. #define LCD_STR_UPLEVEL "\x03"
  25. #define LCD_STR_REFRESH "\x04"
  26. #define LCD_STR_FOLDER "\x05"
  27. #define LCD_STR_FEEDRATE "\x06"
  28. #define LCD_STR_CLOCK "\x07"
  29. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  30. #ifdef LCD_I2C
  31. LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_TYPE); //address, columns, rows, type
  32. #else
  33. LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7
  34. #endif
  35. static void lcd_implementation_init()
  36. {
  37. byte bedTemp[8] =
  38. {
  39. B00000,
  40. B11111,
  41. B10101,
  42. B10001,
  43. B10101,
  44. B11111,
  45. B00000,
  46. B00000
  47. }; //thanks Sonny Mounicou
  48. byte degree[8] =
  49. {
  50. B01100,
  51. B10010,
  52. B10010,
  53. B01100,
  54. B00000,
  55. B00000,
  56. B00000,
  57. B00000
  58. };
  59. byte thermometer[8] =
  60. {
  61. B00100,
  62. B01010,
  63. B01010,
  64. B01010,
  65. B01010,
  66. B10001,
  67. B10001,
  68. B01110
  69. };
  70. byte uplevel[8]={
  71. B00100,
  72. B01110,
  73. B11111,
  74. B00100,
  75. B11100,
  76. B00000,
  77. B00000,
  78. B00000
  79. }; //thanks joris
  80. byte refresh[8]={
  81. B00000,
  82. B00110,
  83. B11001,
  84. B11000,
  85. B00011,
  86. B10011,
  87. B01100,
  88. B00000,
  89. }; //thanks joris
  90. byte folder [8]={
  91. B00000,
  92. B11100,
  93. B11111,
  94. B10001,
  95. B10001,
  96. B11111,
  97. B00000,
  98. B00000
  99. }; //thanks joris
  100. byte feedrate [8]={
  101. B11100,
  102. B10000,
  103. B11000,
  104. B10111,
  105. B00101,
  106. B00110,
  107. B00101,
  108. B00000
  109. }; //thanks Sonny Mounicou
  110. byte clock [8]={
  111. B00000,
  112. B01110,
  113. B10011,
  114. B10101,
  115. B10001,
  116. B01110,
  117. B00000,
  118. B00000
  119. }; //thanks Sonny Mounicou
  120. #ifdef LCD_I2C
  121. lcd.init();
  122. #else
  123. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  124. #endif
  125. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  126. lcd.createChar(LCD_STR_DEGREE[0], degree);
  127. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  128. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  129. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  130. lcd.createChar(LCD_STR_FOLDER[0], folder);
  131. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  132. lcd.createChar(LCD_STR_CLOCK[0], clock);
  133. lcd.clear();
  134. }
  135. static void lcd_implementation_clear()
  136. {
  137. lcd.clear();
  138. }
  139. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  140. static void lcd_printPGM(const char* str)
  141. {
  142. char c;
  143. while((c = pgm_read_byte(str++)) != '\0')
  144. {
  145. lcd.write(c);
  146. }
  147. }
  148. /*
  149. Possible status screens:
  150. 16x2 |0123456789012345|
  151. |000/000 B000/000|
  152. |Status line.....|
  153. 16x4 |0123456789012345|
  154. |000/000 B000/000|
  155. |SD100% Z000.0|
  156. |F100% T--:--|
  157. |Status line.....|
  158. 20x2 |01234567890123456789|
  159. |T000/000D B000/000D |
  160. |Status line.........|
  161. 20x4 |01234567890123456789|
  162. |T000/000D B000/000D |
  163. |X+000.0 Y+000.0 Z+000.0|
  164. |F100% SD100% T--:--|
  165. |Status line.........|
  166. 20x4 |01234567890123456789|
  167. |T000/000D B000/000D |
  168. |T000/000D Z000.0|
  169. |F100% SD100% T--:--|
  170. |Status line.........|
  171. */
  172. static void lcd_implementation_status_screen()
  173. {
  174. int tHotend=int(degHotend(0) + 0.5);
  175. int tTarget=int(degTargetHotend(0) + 0.5);
  176. #if LCD_WIDTH < 20
  177. lcd.setCursor(0, 0);
  178. lcd.print(itostr3(tHotend));
  179. lcd.print('/');
  180. lcd.print(itostr3left(tTarget));
  181. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  182. //If we have an 2nd extruder or heated bed, show that in the top right corner
  183. lcd.setCursor(8, 0);
  184. # if EXTRUDERS > 1
  185. tHotend = int(degHotend(1) + 0.5);
  186. tTarget = int(degTargetHotend(1) + 0.5);
  187. lcd.print(LCD_STR_THERMOMETER[0]);
  188. # else//Heated bed
  189. tHotend=int(degBed() + 0.5);
  190. tTarget=int(degTargetBed() + 0.5);
  191. lcd.print(LCD_STR_BEDTEMP[0]);
  192. # endif
  193. lcd.print(itostr3(tHotend));
  194. lcd.print('/');
  195. lcd.print(itostr3left(tTarget));
  196. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  197. #else//LCD_WIDTH > 19
  198. lcd.setCursor(0, 0);
  199. lcd.print(LCD_STR_THERMOMETER[0]);
  200. lcd.print(itostr3(tHotend));
  201. lcd.print('/');
  202. lcd.print(itostr3left(tTarget));
  203. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  204. if (tTarget < 10)
  205. lcd.print(' ');
  206. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  207. //If we have an 2nd extruder or heated bed, show that in the top right corner
  208. lcd.setCursor(10, 0);
  209. # if EXTRUDERS > 1
  210. tHotend = int(degHotend(1) + 0.5);
  211. tTarget = int(degTargetHotend(1) + 0.5);
  212. lcd.print(LCD_STR_THERMOMETER[0]);
  213. # else//Heated bed
  214. tHotend=int(degBed() + 0.5);
  215. tTarget=int(degTargetBed() + 0.5);
  216. lcd.print(LCD_STR_BEDTEMP[0]);
  217. # endif
  218. lcd.print(itostr3(tHotend));
  219. lcd.print('/');
  220. lcd.print(itostr3left(tTarget));
  221. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  222. if (tTarget < 10)
  223. lcd.print(' ');
  224. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  225. #endif//LCD_WIDTH > 19
  226. #if LCD_HEIGHT > 2
  227. //Lines 2 for 4 line LCD
  228. # if LCD_WIDTH < 20
  229. # ifdef SDSUPPORT
  230. lcd.setCursor(0, 2);
  231. lcd_printPGM(PSTR("SD"));
  232. if (IS_SD_PRINTING)
  233. lcd.print(itostr3(card.percentDone()));
  234. else
  235. lcd_printPGM(PSTR("---"));
  236. lcd.print('%');
  237. # endif//SDSUPPORT
  238. # else//LCD_WIDTH > 19
  239. # if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  240. //If we both have a 2nd extruder and a heated bed, show the heated bed temp on the 2nd line on the left, as the first line is filled with extruder temps
  241. tHotend=int(degBed() + 0.5);
  242. tTarget=int(degTargetBed() + 0.5);
  243. lcd.setCursor(0, 1);
  244. lcd.print(LCD_STR_BEDTEMP[0]);
  245. lcd.print(itostr3(tHotend));
  246. lcd.print('/');
  247. lcd.print(itostr3left(tTarget));
  248. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  249. if (tTarget < 10)
  250. lcd.print(' ');
  251. # else
  252. lcd.setCursor(0,1);
  253. lcd.print('X');
  254. lcd.print(ftostr3(current_position[X_AXIS]));
  255. lcd_printPGM(PSTR(" Y"));
  256. lcd.print(ftostr3(current_position[Y_AXIS]));
  257. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  258. # endif//LCD_WIDTH > 19
  259. lcd.setCursor(LCD_WIDTH - 8, 1);
  260. lcd.print('Z');
  261. lcd.print(ftostr32(current_position[Z_AXIS]));
  262. #endif//LCD_HEIGHT > 2
  263. #if LCD_HEIGHT > 3
  264. lcd.setCursor(0, 2);
  265. lcd.print(LCD_STR_FEEDRATE[0]);
  266. lcd.print(itostr3(feedmultiply));
  267. lcd.print('%');
  268. # if LCD_WIDTH > 19
  269. # ifdef SDSUPPORT
  270. lcd.setCursor(7, 2);
  271. lcd_printPGM(PSTR("SD"));
  272. if (IS_SD_PRINTING)
  273. lcd.print(itostr3(card.percentDone()));
  274. else
  275. lcd_printPGM(PSTR("---"));
  276. lcd.print('%');
  277. # endif//SDSUPPORT
  278. # endif//LCD_WIDTH > 19
  279. lcd.setCursor(LCD_WIDTH - 6, 2);
  280. lcd.print(LCD_STR_CLOCK[0]);
  281. if(starttime != 0)
  282. {
  283. uint16_t time = millis()/60000 - starttime/60000;
  284. lcd.print(itostr2(time/60));
  285. lcd.print(':');
  286. lcd.print(itostr2(time%60));
  287. }else{
  288. lcd_printPGM(PSTR("--:--"));
  289. }
  290. #endif
  291. //Status message line on the last line
  292. lcd.setCursor(0, LCD_HEIGHT - 1);
  293. lcd.print(lcd_status_message);
  294. }
  295. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  296. {
  297. char c;
  298. //Use all characters in narrow LCDs
  299. #if LCD_WIDTH < 20
  300. uint8_t n = LCD_WIDTH - 1 - 1;
  301. #else
  302. uint8_t n = LCD_WIDTH - 1 - 2;
  303. #endif
  304. lcd.setCursor(0, row);
  305. lcd.print(pre_char);
  306. while((c = pgm_read_byte(pstr)) != '\0')
  307. {
  308. lcd.print(c);
  309. pstr++;
  310. n--;
  311. }
  312. while(n--)
  313. lcd.print(' ');
  314. lcd.print(post_char);
  315. lcd.print(' ');
  316. }
  317. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  318. {
  319. char c;
  320. //Use all characters in narrow LCDs
  321. #if LCD_WIDTH < 20
  322. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  323. #else
  324. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  325. #endif
  326. lcd.setCursor(0, row);
  327. lcd.print(pre_char);
  328. while((c = pgm_read_byte(pstr)) != '\0')
  329. {
  330. lcd.print(c);
  331. pstr++;
  332. n--;
  333. }
  334. lcd.print(':');
  335. while(n--)
  336. lcd.print(' ');
  337. lcd.print(data);
  338. }
  339. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  340. {
  341. char c;
  342. //Use all characters in narrow LCDs
  343. #if LCD_WIDTH < 20
  344. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  345. #else
  346. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  347. #endif
  348. lcd.setCursor(0, row);
  349. lcd.print(pre_char);
  350. while((c = pgm_read_byte(pstr)) != '\0')
  351. {
  352. lcd.print(c);
  353. pstr++;
  354. n--;
  355. }
  356. lcd.print(':');
  357. while(n--)
  358. lcd.print(' ');
  359. lcd_printPGM(data);
  360. }
  361. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  362. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  363. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  364. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  365. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  366. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  367. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  368. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  369. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  370. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  371. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  372. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  373. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  374. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  375. #define lcd_implementation_drawmenu_setting_edit_bool_selected(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  376. #define lcd_implementation_drawmenu_setting_edit_bool(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  377. void lcd_implementation_drawedit(const char* pstr, char* value)
  378. {
  379. lcd.setCursor(1, 1);
  380. lcd_printPGM(pstr);
  381. lcd.print(':');
  382. #if LCD_WIDTH < 20
  383. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  384. #else
  385. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  386. #endif
  387. lcd.print(value);
  388. }
  389. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  390. {
  391. char c;
  392. uint8_t n = LCD_WIDTH - 1;
  393. lcd.setCursor(0, row);
  394. lcd.print('>');
  395. if (longFilename[0] != '\0')
  396. {
  397. filename = longFilename;
  398. longFilename[LCD_WIDTH-1] = '\0';
  399. }
  400. while((c = *filename) != '\0')
  401. {
  402. lcd.print(c);
  403. filename++;
  404. n--;
  405. }
  406. while(n--)
  407. lcd.print(' ');
  408. }
  409. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  410. {
  411. char c;
  412. uint8_t n = LCD_WIDTH - 1;
  413. lcd.setCursor(0, row);
  414. lcd.print(' ');
  415. if (longFilename[0] != '\0')
  416. {
  417. filename = longFilename;
  418. longFilename[LCD_WIDTH-1] = '\0';
  419. }
  420. while((c = *filename) != '\0')
  421. {
  422. lcd.print(c);
  423. filename++;
  424. n--;
  425. }
  426. while(n--)
  427. lcd.print(' ');
  428. }
  429. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  430. {
  431. char c;
  432. uint8_t n = LCD_WIDTH - 2;
  433. lcd.setCursor(0, row);
  434. lcd.print('>');
  435. lcd.print(LCD_STR_FOLDER[0]);
  436. if (longFilename[0] != '\0')
  437. {
  438. filename = longFilename;
  439. longFilename[LCD_WIDTH-2] = '\0';
  440. }
  441. while((c = *filename) != '\0')
  442. {
  443. lcd.print(c);
  444. filename++;
  445. n--;
  446. }
  447. while(n--)
  448. lcd.print(' ');
  449. }
  450. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  451. {
  452. char c;
  453. uint8_t n = LCD_WIDTH - 2;
  454. lcd.setCursor(0, row);
  455. lcd.print(' ');
  456. lcd.print(LCD_STR_FOLDER[0]);
  457. if (longFilename[0] != '\0')
  458. {
  459. filename = longFilename;
  460. longFilename[LCD_WIDTH-2] = '\0';
  461. }
  462. while((c = *filename) != '\0')
  463. {
  464. lcd.print(c);
  465. filename++;
  466. n--;
  467. }
  468. while(n--)
  469. lcd.print(' ');
  470. }
  471. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  472. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  473. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  474. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  475. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  476. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  477. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  478. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  479. static void lcd_implementation_quick_feedback()
  480. {
  481. #if BEEPER > -1
  482. SET_OUTPUT(BEEPER);
  483. for(int8_t i=0;i<10;i++)
  484. {
  485. WRITE(BEEPER,HIGH);
  486. delay(3);
  487. WRITE(BEEPER,LOW);
  488. delay(3);
  489. }
  490. #endif
  491. }
  492. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H