My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ultralcd_implementation_hitachi_HD44780.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. //Use all characters in narrow LCDs
  285. #if LCD_WIDTH < 20
  286. uint8_t n = LCD_WIDTH - 1 - 1;
  287. #else
  288. uint8_t n = LCD_WIDTH - 1 - 2;
  289. #endif
  290. lcd.setCursor(0, row);
  291. lcd.print(pre_char);
  292. while((c = pgm_read_byte(pstr)) != '\0')
  293. {
  294. lcd.print(c);
  295. pstr++;
  296. n--;
  297. }
  298. while(n--)
  299. lcd.print(' ');
  300. lcd.print(post_char);
  301. lcd.print(' ');
  302. }
  303. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  304. {
  305. char c;
  306. //Use all characters in narrow LCDs
  307. #if LCD_WIDTH < 20
  308. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  309. #else
  310. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  311. #endif
  312. lcd.setCursor(0, row);
  313. lcd.print(pre_char);
  314. while((c = pgm_read_byte(pstr)) != '\0')
  315. {
  316. lcd.print(c);
  317. pstr++;
  318. n--;
  319. }
  320. lcd.print(':');
  321. while(n--)
  322. lcd.print(' ');
  323. lcd.print(data);
  324. }
  325. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  326. {
  327. char c;
  328. //Use all characters in narrow LCDs
  329. #if LCD_WIDTH < 20
  330. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  331. #else
  332. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  333. #endif
  334. lcd.setCursor(0, row);
  335. lcd.print(pre_char);
  336. while((c = pgm_read_byte(pstr)) != '\0')
  337. {
  338. lcd.print(c);
  339. pstr++;
  340. n--;
  341. }
  342. lcd.print(':');
  343. while(n--)
  344. lcd.print(' ');
  345. lcd_printPGM(data);
  346. }
  347. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  348. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  349. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  350. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  351. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  352. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  353. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  354. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  355. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  356. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  357. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  358. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  359. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  360. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  361. #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))
  362. #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))
  363. void lcd_implementation_drawedit(const char* pstr, char* value)
  364. {
  365. lcd.setCursor(1, 1);
  366. lcd_printPGM(pstr);
  367. lcd.print(':');
  368. #if LCD_WIDTH < 20
  369. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  370. #else
  371. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  372. #endif
  373. lcd.print(value);
  374. }
  375. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  376. {
  377. char c;
  378. uint8_t n = LCD_WIDTH - 1;
  379. lcd.setCursor(0, row);
  380. lcd.print('>');
  381. if (longFilename[0] != '\0')
  382. {
  383. filename = longFilename;
  384. longFilename[LCD_WIDTH-1] = '\0';
  385. }
  386. while((c = *filename) != '\0')
  387. {
  388. lcd.print(c);
  389. filename++;
  390. n--;
  391. }
  392. while(n--)
  393. lcd.print(' ');
  394. }
  395. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  396. {
  397. char c;
  398. uint8_t n = LCD_WIDTH - 1;
  399. lcd.setCursor(0, row);
  400. lcd.print(' ');
  401. if (longFilename[0] != '\0')
  402. {
  403. filename = longFilename;
  404. longFilename[LCD_WIDTH-1] = '\0';
  405. }
  406. while((c = *filename) != '\0')
  407. {
  408. lcd.print(c);
  409. filename++;
  410. n--;
  411. }
  412. while(n--)
  413. lcd.print(' ');
  414. }
  415. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  416. {
  417. char c;
  418. uint8_t n = LCD_WIDTH - 2;
  419. lcd.setCursor(0, row);
  420. lcd.print('>');
  421. lcd.print(LCD_STR_FOLDER[0]);
  422. if (longFilename[0] != '\0')
  423. {
  424. filename = longFilename;
  425. longFilename[LCD_WIDTH-2] = '\0';
  426. }
  427. while((c = *filename) != '\0')
  428. {
  429. lcd.print(c);
  430. filename++;
  431. n--;
  432. }
  433. while(n--)
  434. lcd.print(' ');
  435. }
  436. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  437. {
  438. char c;
  439. uint8_t n = LCD_WIDTH - 2;
  440. lcd.setCursor(0, row);
  441. lcd.print(' ');
  442. lcd.print(LCD_STR_FOLDER[0]);
  443. if (longFilename[0] != '\0')
  444. {
  445. filename = longFilename;
  446. longFilename[LCD_WIDTH-2] = '\0';
  447. }
  448. while((c = *filename) != '\0')
  449. {
  450. lcd.print(c);
  451. filename++;
  452. n--;
  453. }
  454. while(n--)
  455. lcd.print(' ');
  456. }
  457. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  458. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  459. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  460. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  461. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  462. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  463. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  464. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  465. static void lcd_implementation_quick_feedback()
  466. {
  467. #if BEEPER > -1
  468. SET_OUTPUT(BEEPER);
  469. for(int8_t i=0;i<10;i++)
  470. {
  471. WRITE(BEEPER,HIGH);
  472. delay(3);
  473. WRITE(BEEPER,LOW);
  474. delay(3);
  475. }
  476. #endif
  477. }
  478. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H