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

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