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

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