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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  191. //If we have an 2nd extruder or heated bed, show that in the top right corner
  192. lcd.setCursor(10, 0);
  193. # if EXTRUDERS > 1
  194. tHotend = int(degHotend(1) + 0.5);
  195. tTarget = int(degTargetHotend(1) + 0.5);
  196. lcd.print(LCD_STR_THERMOMETER[0]);
  197. # else//Heated bed
  198. tHotend=int(degBed() + 0.5);
  199. tTarget=int(degTargetBed() + 0.5);
  200. lcd.print(LCD_STR_BEDTEMP[0]);
  201. # endif
  202. lcd.print(itostr3(tHotend));
  203. lcd.print('/');
  204. lcd.print(itostr3left(tTarget));
  205. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  206. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  207. #endif//LCD_WIDTH > 19
  208. #if LCD_HEIGHT > 2
  209. //Lines 2 for 4 line LCD
  210. # if LCD_WIDTH < 20
  211. # ifdef SDSUPPORT
  212. lcd.setCursor(0, 2);
  213. lcd_printPGM(PSTR("SD"));
  214. if (IS_SD_PRINTING)
  215. lcd.print(itostr3(card.percentDone()));
  216. else
  217. lcd_printPGM(PSTR("---"));
  218. lcd.print('%');
  219. # endif//SDSUPPORT
  220. # else//LCD_WIDTH > 19
  221. # if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  222. //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
  223. tHotend=int(degBed() + 0.5);
  224. tTarget=int(degTargetBed() + 0.5);
  225. lcd.setCursor(0, 1);
  226. lcd.print(LCD_STR_BEDTEMP[0]);
  227. lcd.print(itostr3(tHotend));
  228. lcd.print('/');
  229. lcd.print(itostr3left(tTarget));
  230. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  231. # else
  232. lcd.setCursor(0,1);
  233. lcd.print('X');
  234. lcd.print(ftostr3(current_position[X_AXIS]));
  235. lcd_printPGM(PSTR(" Y"));
  236. lcd.print(ftostr3(current_position[Y_AXIS]));
  237. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  238. # endif//LCD_WIDTH > 19
  239. lcd.setCursor(LCD_WIDTH - 7, 1);
  240. lcd.print('Z');
  241. lcd.print(ftostr31(current_position[Z_AXIS]));
  242. #endif//LCD_HEIGHT > 2
  243. #if LCD_HEIGHT > 3
  244. lcd.setCursor(0, 2);
  245. lcd.print(LCD_STR_FEEDRATE[0]);
  246. lcd.print(itostr3(feedmultiply));
  247. lcd.print('%');
  248. # if LCD_WIDTH > 19
  249. # ifdef SDSUPPORT
  250. lcd.setCursor(7, 2);
  251. lcd_printPGM(PSTR("SD"));
  252. if (IS_SD_PRINTING)
  253. lcd.print(itostr3(card.percentDone()));
  254. else
  255. lcd_printPGM(PSTR("---"));
  256. lcd.print('%');
  257. # endif//SDSUPPORT
  258. # endif//LCD_WIDTH > 19
  259. lcd.setCursor(LCD_WIDTH - 6, 2);
  260. lcd.print(LCD_STR_CLOCK[0]);
  261. if(starttime != 0)
  262. {
  263. uint16_t time = millis()/60000 - starttime/60000;
  264. lcd.print(itostr2(time/60));
  265. lcd.print(':');
  266. lcd.print(itostr2(time%60));
  267. }else{
  268. lcd_printPGM(PSTR("--:--"));
  269. }
  270. #endif
  271. //Status message line on the last line
  272. lcd.setCursor(0, LCD_HEIGHT - 1);
  273. lcd.print(lcd_status_message);
  274. }
  275. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  276. {
  277. char c;
  278. uint8_t n = LCD_WIDTH - 1 - 2;
  279. lcd.setCursor(0, row);
  280. lcd.print(pre_char);
  281. while((c = pgm_read_byte(pstr)) != '\0')
  282. {
  283. lcd.print(c);
  284. pstr++;
  285. n--;
  286. }
  287. while(n--)
  288. lcd.print(' ');
  289. lcd.print(post_char);
  290. lcd.print(' ');
  291. }
  292. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  293. {
  294. char c;
  295. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  296. lcd.setCursor(0, row);
  297. lcd.print(pre_char);
  298. while((c = pgm_read_byte(pstr)) != '\0')
  299. {
  300. lcd.print(c);
  301. pstr++;
  302. n--;
  303. }
  304. lcd.print(':');
  305. while(n--)
  306. lcd.print(' ');
  307. lcd.print(data);
  308. }
  309. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  310. {
  311. char c;
  312. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  313. lcd.setCursor(0, row);
  314. lcd.print(pre_char);
  315. while((c = pgm_read_byte(pstr)) != '\0')
  316. {
  317. lcd.print(c);
  318. pstr++;
  319. n--;
  320. }
  321. lcd.print(':');
  322. while(n--)
  323. lcd.print(' ');
  324. lcd_printPGM(data);
  325. }
  326. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  327. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  328. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  329. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  330. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  331. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  332. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  333. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  334. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  335. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  336. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  337. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  338. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  339. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  340. #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))
  341. #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))
  342. void lcd_implementation_drawedit(const char* pstr, char* value)
  343. {
  344. lcd.setCursor(0, 1);
  345. lcd_printPGM(pstr);
  346. lcd.print(':');
  347. lcd.setCursor(19 - strlen(value), 1);
  348. lcd.print(value);
  349. }
  350. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  351. {
  352. char c;
  353. uint8_t n = LCD_WIDTH - 1;
  354. lcd.setCursor(0, row);
  355. lcd.print('>');
  356. if (longFilename[0] != '\0')
  357. {
  358. filename = longFilename;
  359. longFilename[LCD_WIDTH-1] = '\0';
  360. }
  361. while((c = *filename) != '\0')
  362. {
  363. lcd.print(c);
  364. filename++;
  365. n--;
  366. }
  367. while(n--)
  368. lcd.print(' ');
  369. }
  370. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  371. {
  372. char c;
  373. uint8_t n = LCD_WIDTH - 1;
  374. lcd.setCursor(0, row);
  375. lcd.print(' ');
  376. if (longFilename[0] != '\0')
  377. {
  378. filename = longFilename;
  379. longFilename[LCD_WIDTH-1] = '\0';
  380. }
  381. while((c = *filename) != '\0')
  382. {
  383. lcd.print(c);
  384. filename++;
  385. n--;
  386. }
  387. while(n--)
  388. lcd.print(' ');
  389. }
  390. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  391. {
  392. char c;
  393. uint8_t n = LCD_WIDTH - 2;
  394. lcd.setCursor(0, row);
  395. lcd.print('>');
  396. lcd.print(LCD_STR_FOLDER[0]);
  397. if (longFilename[0] != '\0')
  398. {
  399. filename = longFilename;
  400. longFilename[LCD_WIDTH-2] = '\0';
  401. }
  402. while((c = *filename) != '\0')
  403. {
  404. lcd.print(c);
  405. filename++;
  406. n--;
  407. }
  408. while(n--)
  409. lcd.print(' ');
  410. }
  411. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  412. {
  413. char c;
  414. uint8_t n = LCD_WIDTH - 2;
  415. lcd.setCursor(0, row);
  416. lcd.print(' ');
  417. lcd.print(LCD_STR_FOLDER[0]);
  418. if (longFilename[0] != '\0')
  419. {
  420. filename = longFilename;
  421. longFilename[LCD_WIDTH-2] = '\0';
  422. }
  423. while((c = *filename) != '\0')
  424. {
  425. lcd.print(c);
  426. filename++;
  427. n--;
  428. }
  429. while(n--)
  430. lcd.print(' ');
  431. }
  432. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  433. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  434. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  435. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  436. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  437. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  438. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  439. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  440. static void lcd_implementation_quick_feedback()
  441. {
  442. #if BEEPER > -1
  443. SET_OUTPUT(BEEPER);
  444. for(int8_t i=0;i<10;i++)
  445. {
  446. WRITE(BEEPER,HIGH);
  447. delay(3);
  448. WRITE(BEEPER,LOW);
  449. delay(3);
  450. }
  451. #endif
  452. }
  453. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H