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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. // Declare LCD class to use
  8. #if defined(LCD_I2C_TYPE_PCF8575)
  9. // note: these are virtual pins on the PCF8575 controller not Arduino pins
  10. #define LCD_I2C_PIN_BL 3
  11. #define LCD_I2C_PIN_EN 2
  12. #define LCD_I2C_PIN_RW 1
  13. #define LCD_I2C_PIN_RS 0
  14. #define LCD_I2C_PIN_D4 4
  15. #define LCD_I2C_PIN_D5 5
  16. #define LCD_I2C_PIN_D6 6
  17. #define LCD_I2C_PIN_D7 7
  18. #include <Wire.h>
  19. #include <LCD.h>
  20. #include <LiquidCrystal_I2C.h>
  21. #define LCD_CLASS LiquidCrystal_I2C
  22. LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7);
  23. #elif defined(LCD_I2C_TYPE_MCP23017)
  24. //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
  25. #define LED_A 0x04 //100
  26. #define LED_B 0x02 //010
  27. #define LED_C 0x01 //001
  28. #include <Wire.h>
  29. #include <LiquidTWI2.h>
  30. #define LCD_CLASS LiquidTWI2
  31. LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0"
  32. #elif defined(LCD_I2C_TYPE_MCP23008)
  33. #include <Wire.h>
  34. #include <LiquidTWI2.h>
  35. #define LCD_CLASS LiquidTWI2
  36. LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0"
  37. #else
  38. #if LANGUAGE_CHOICE == 6
  39. #include "LiquidCrystalRus.h"
  40. #define LCD_CLASS LiquidCrystalRus
  41. #else
  42. #include <LiquidCrystal.h>
  43. #define LCD_CLASS LiquidCrystal
  44. #endif
  45. 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
  46. #endif
  47. extern volatile uint8_t buttons; //the last checked buttons in a bit array.
  48. // provide default button bitmask and encoder definitions (note this is not pin or motherboard specific)
  49. #ifdef LCD_I2C_VIKI
  50. //encoder rotation values
  51. #define encrot0 0
  52. #define encrot1 2
  53. #define encrot2 3
  54. #define encrot3 1
  55. #define BLEN_C 2
  56. #define BLEN_B 1
  57. #define BLEN_A 0
  58. #define EN_C (1<<BLEN_C) // The stop/pause/resume button comes through BTN_ENC pin (for consistency with NEWPANEL code)
  59. #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
  60. #define EN_A (1<<BLEN_A)
  61. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  62. // button and encoder bit positions within 'buttons'
  63. #define B_ST (EN_C) // The pause/stop/resume button is mapped to EN_C for consistency with NEWPANEL
  64. #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining buttons are I2C read buttons.
  65. #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
  66. #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
  67. #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
  68. #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
  69. #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
  70. // I2C buttons are likely to take too long to read inside interrupt context and so we read them during lcd_update
  71. #define LCD_HAS_EXTRA_BUTTONS
  72. #elif defined(NEWPANEL)
  73. //from the same bit in the RAMPS Newpanel define
  74. //encoder rotation values
  75. #define encrot0 0
  76. #define encrot1 2
  77. #define encrot2 3
  78. #define encrot3 1
  79. #define BLEN_C 2
  80. #define BLEN_B 1
  81. #define BLEN_A 0
  82. #define EN_C (1<<BLEN_C)
  83. #define EN_B (1<<BLEN_B)
  84. #define EN_A (1<<BLEN_A)
  85. #define LCD_CLICKED (buttons&EN_C)
  86. #else // old style ULTIPANEL
  87. //encoder rotation values
  88. #ifndef ULTIMAKERCONTROLLER
  89. #define encrot0 0
  90. #define encrot1 2
  91. #define encrot2 3
  92. #define encrot3 1
  93. #else
  94. #define encrot0 0
  95. #define encrot1 1
  96. #define encrot2 3
  97. #define encrot3 2
  98. #endif
  99. //bits in the shift register that carry the buttons for:
  100. // left up center down right red(stop)
  101. #define BL_LE 7
  102. #define BL_UP 6
  103. #define BL_MI 5
  104. #define BL_DW 4
  105. #define BL_RI 3
  106. #define BL_ST 2
  107. #define BLEN_B 1
  108. #define BLEN_A 0
  109. //automatic, do not change
  110. #define B_LE (1<<BL_LE)
  111. #define B_UP (1<<BL_UP)
  112. #define B_MI (1<<BL_MI)
  113. #define B_DW (1<<BL_DW)
  114. #define B_RI (1<<BL_RI)
  115. #define B_ST (1<<BL_ST)
  116. #define EN_B (1<<BLEN_B)
  117. #define EN_A (1<<BLEN_A)
  118. #define LCD_CLICKED (buttons&(B_MI|B_ST))
  119. #endif//else NEWPANEL
  120. #ifdef LCD_HAS_STATUS_INDICATORS
  121. //forward declaration
  122. static void lcd_implementation_update_indicators();
  123. #endif
  124. /* Custom characters defined in the first 8 characters of the LCD */
  125. #define LCD_STR_BEDTEMP "\x00"
  126. #define LCD_STR_DEGREE "\x01"
  127. #define LCD_STR_THERMOMETER "\x02"
  128. #define LCD_STR_UPLEVEL "\x03"
  129. #define LCD_STR_REFRESH "\x04"
  130. #define LCD_STR_FOLDER "\x05"
  131. #define LCD_STR_FEEDRATE "\x06"
  132. #define LCD_STR_CLOCK "\x07"
  133. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  134. static void lcd_implementation_init()
  135. {
  136. byte bedTemp[8] =
  137. {
  138. B00000,
  139. B11111,
  140. B10101,
  141. B10001,
  142. B10101,
  143. B11111,
  144. B00000,
  145. B00000
  146. }; //thanks Sonny Mounicou
  147. byte degree[8] =
  148. {
  149. B01100,
  150. B10010,
  151. B10010,
  152. B01100,
  153. B00000,
  154. B00000,
  155. B00000,
  156. B00000
  157. };
  158. byte thermometer[8] =
  159. {
  160. B00100,
  161. B01010,
  162. B01010,
  163. B01010,
  164. B01010,
  165. B10001,
  166. B10001,
  167. B01110
  168. };
  169. byte uplevel[8]={
  170. B00100,
  171. B01110,
  172. B11111,
  173. B00100,
  174. B11100,
  175. B00000,
  176. B00000,
  177. B00000
  178. }; //thanks joris
  179. byte refresh[8]={
  180. B00000,
  181. B00110,
  182. B11001,
  183. B11000,
  184. B00011,
  185. B10011,
  186. B01100,
  187. B00000,
  188. }; //thanks joris
  189. byte folder [8]={
  190. B00000,
  191. B11100,
  192. B11111,
  193. B10001,
  194. B10001,
  195. B11111,
  196. B00000,
  197. B00000
  198. }; //thanks joris
  199. byte feedrate [8]={
  200. B11100,
  201. B10000,
  202. B11000,
  203. B10111,
  204. B00101,
  205. B00110,
  206. B00101,
  207. B00000
  208. }; //thanks Sonny Mounicou
  209. byte clock [8]={
  210. B00000,
  211. B01110,
  212. B10011,
  213. B10101,
  214. B10001,
  215. B01110,
  216. B00000,
  217. B00000
  218. }; //thanks Sonny Mounicou
  219. #if defined(LCDI2C_TYPE_PCF8575)
  220. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  221. #ifdef LCD_I2C_PIN_BL
  222. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  223. lcd.setBacklight(HIGH);
  224. #endif
  225. #elif defined(LCD_I2C_TYPE_MCP23017)
  226. lcd.setMCPType(LTI_TYPE_MCP23017);
  227. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  228. lcd.setBacklight(0); //set all the LEDs off to begin with
  229. #elif defined(LCD_I2C_TYPE_MCP23008)
  230. lcd.setMCPType(LTI_TYPE_MCP23008);
  231. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  232. #else
  233. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  234. #endif
  235. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  236. lcd.createChar(LCD_STR_DEGREE[0], degree);
  237. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  238. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  239. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  240. lcd.createChar(LCD_STR_FOLDER[0], folder);
  241. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  242. lcd.createChar(LCD_STR_CLOCK[0], clock);
  243. lcd.clear();
  244. }
  245. static void lcd_implementation_clear()
  246. {
  247. lcd.clear();
  248. }
  249. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  250. static void lcd_printPGM(const char* str)
  251. {
  252. char c;
  253. while((c = pgm_read_byte(str++)) != '\0')
  254. {
  255. lcd.write(c);
  256. }
  257. }
  258. /*
  259. Possible status screens:
  260. 16x2 |0123456789012345|
  261. |000/000 B000/000|
  262. |Status line.....|
  263. 16x4 |0123456789012345|
  264. |000/000 B000/000|
  265. |SD100% Z000.0|
  266. |F100% T--:--|
  267. |Status line.....|
  268. 20x2 |01234567890123456789|
  269. |T000/000D B000/000D |
  270. |Status line.........|
  271. 20x4 |01234567890123456789|
  272. |T000/000D B000/000D |
  273. |X+000.0 Y+000.0 Z+000.0|
  274. |F100% SD100% T--:--|
  275. |Status line.........|
  276. 20x4 |01234567890123456789|
  277. |T000/000D B000/000D |
  278. |T000/000D Z000.0|
  279. |F100% SD100% T--:--|
  280. |Status line.........|
  281. */
  282. static void lcd_implementation_status_screen()
  283. {
  284. int tHotend=int(degHotend(0) + 0.5);
  285. int tTarget=int(degTargetHotend(0) + 0.5);
  286. #if LCD_WIDTH < 20
  287. lcd.setCursor(0, 0);
  288. lcd.print(itostr3(tHotend));
  289. lcd.print('/');
  290. lcd.print(itostr3left(tTarget));
  291. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  292. //If we have an 2nd extruder or heated bed, show that in the top right corner
  293. lcd.setCursor(8, 0);
  294. # if EXTRUDERS > 1
  295. tHotend = int(degHotend(1) + 0.5);
  296. tTarget = int(degTargetHotend(1) + 0.5);
  297. lcd.print(LCD_STR_THERMOMETER[0]);
  298. # else//Heated bed
  299. tHotend=int(degBed() + 0.5);
  300. tTarget=int(degTargetBed() + 0.5);
  301. lcd.print(LCD_STR_BEDTEMP[0]);
  302. # endif
  303. lcd.print(itostr3(tHotend));
  304. lcd.print('/');
  305. lcd.print(itostr3left(tTarget));
  306. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  307. #else//LCD_WIDTH > 19
  308. lcd.setCursor(0, 0);
  309. lcd.print(LCD_STR_THERMOMETER[0]);
  310. lcd.print(itostr3(tHotend));
  311. lcd.print('/');
  312. lcd.print(itostr3left(tTarget));
  313. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  314. if (tTarget < 10)
  315. lcd.print(' ');
  316. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  317. //If we have an 2nd extruder or heated bed, show that in the top right corner
  318. lcd.setCursor(10, 0);
  319. # if EXTRUDERS > 1
  320. tHotend = int(degHotend(1) + 0.5);
  321. tTarget = int(degTargetHotend(1) + 0.5);
  322. lcd.print(LCD_STR_THERMOMETER[0]);
  323. # else//Heated bed
  324. tHotend=int(degBed() + 0.5);
  325. tTarget=int(degTargetBed() + 0.5);
  326. lcd.print(LCD_STR_BEDTEMP[0]);
  327. # endif
  328. lcd.print(itostr3(tHotend));
  329. lcd.print('/');
  330. lcd.print(itostr3left(tTarget));
  331. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  332. if (tTarget < 10)
  333. lcd.print(' ');
  334. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  335. #endif//LCD_WIDTH > 19
  336. #if LCD_HEIGHT > 2
  337. //Lines 2 for 4 line LCD
  338. # if LCD_WIDTH < 20
  339. # ifdef SDSUPPORT
  340. lcd.setCursor(0, 2);
  341. lcd_printPGM(PSTR("SD"));
  342. if (IS_SD_PRINTING)
  343. lcd.print(itostr3(card.percentDone()));
  344. else
  345. lcd_printPGM(PSTR("---"));
  346. lcd.print('%');
  347. # endif//SDSUPPORT
  348. # else//LCD_WIDTH > 19
  349. # if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  350. //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
  351. tHotend=int(degBed() + 0.5);
  352. tTarget=int(degTargetBed() + 0.5);
  353. lcd.setCursor(0, 1);
  354. lcd.print(LCD_STR_BEDTEMP[0]);
  355. lcd.print(itostr3(tHotend));
  356. lcd.print('/');
  357. lcd.print(itostr3left(tTarget));
  358. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  359. if (tTarget < 10)
  360. lcd.print(' ');
  361. # else
  362. lcd.setCursor(0,1);
  363. lcd.print('X');
  364. lcd.print(ftostr3(current_position[X_AXIS]));
  365. lcd_printPGM(PSTR(" Y"));
  366. lcd.print(ftostr3(current_position[Y_AXIS]));
  367. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  368. # endif//LCD_WIDTH > 19
  369. lcd.setCursor(LCD_WIDTH - 8, 1);
  370. lcd.print('Z');
  371. lcd.print(ftostr32(current_position[Z_AXIS]));
  372. #endif//LCD_HEIGHT > 2
  373. #if LCD_HEIGHT > 3
  374. lcd.setCursor(0, 2);
  375. lcd.print(LCD_STR_FEEDRATE[0]);
  376. lcd.print(itostr3(feedmultiply));
  377. lcd.print('%');
  378. # if LCD_WIDTH > 19
  379. # ifdef SDSUPPORT
  380. lcd.setCursor(7, 2);
  381. lcd_printPGM(PSTR("SD"));
  382. if (IS_SD_PRINTING)
  383. lcd.print(itostr3(card.percentDone()));
  384. else
  385. lcd_printPGM(PSTR("---"));
  386. lcd.print('%');
  387. # endif//SDSUPPORT
  388. # endif//LCD_WIDTH > 19
  389. lcd.setCursor(LCD_WIDTH - 6, 2);
  390. lcd.print(LCD_STR_CLOCK[0]);
  391. if(starttime != 0)
  392. {
  393. uint16_t time = millis()/60000 - starttime/60000;
  394. lcd.print(itostr2(time/60));
  395. lcd.print(':');
  396. lcd.print(itostr2(time%60));
  397. }else{
  398. lcd_printPGM(PSTR("--:--"));
  399. }
  400. #endif
  401. //Status message line on the last line
  402. lcd.setCursor(0, LCD_HEIGHT - 1);
  403. lcd.print(lcd_status_message);
  404. #ifdef LCD_HAS_STATUS_INDICATORS
  405. lcd_implementation_update_indicators();
  406. #endif
  407. }
  408. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  409. {
  410. char c;
  411. //Use all characters in narrow LCDs
  412. #if LCD_WIDTH < 20
  413. uint8_t n = LCD_WIDTH - 1 - 1;
  414. #else
  415. uint8_t n = LCD_WIDTH - 1 - 2;
  416. #endif
  417. lcd.setCursor(0, row);
  418. lcd.print(pre_char);
  419. while((c = pgm_read_byte(pstr)) != '\0')
  420. {
  421. lcd.print(c);
  422. pstr++;
  423. n--;
  424. }
  425. while(n--)
  426. lcd.print(' ');
  427. lcd.print(post_char);
  428. lcd.print(' ');
  429. }
  430. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  431. {
  432. char c;
  433. //Use all characters in narrow LCDs
  434. #if LCD_WIDTH < 20
  435. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  436. #else
  437. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  438. #endif
  439. lcd.setCursor(0, row);
  440. lcd.print(pre_char);
  441. while((c = pgm_read_byte(pstr)) != '\0')
  442. {
  443. lcd.print(c);
  444. pstr++;
  445. n--;
  446. }
  447. lcd.print(':');
  448. while(n--)
  449. lcd.print(' ');
  450. lcd.print(data);
  451. }
  452. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  453. {
  454. char c;
  455. //Use all characters in narrow LCDs
  456. #if LCD_WIDTH < 20
  457. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  458. #else
  459. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  460. #endif
  461. lcd.setCursor(0, row);
  462. lcd.print(pre_char);
  463. while((c = pgm_read_byte(pstr)) != '\0')
  464. {
  465. lcd.print(c);
  466. pstr++;
  467. n--;
  468. }
  469. lcd.print(':');
  470. while(n--)
  471. lcd.print(' ');
  472. lcd_printPGM(data);
  473. }
  474. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  475. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  476. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  477. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  478. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  479. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  480. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  481. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  482. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  483. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  484. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  485. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  486. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  487. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  488. #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))
  489. #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))
  490. void lcd_implementation_drawedit(const char* pstr, char* value)
  491. {
  492. lcd.setCursor(1, 1);
  493. lcd_printPGM(pstr);
  494. lcd.print(':');
  495. #if LCD_WIDTH < 20
  496. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  497. #else
  498. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  499. #endif
  500. lcd.print(value);
  501. }
  502. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  503. {
  504. char c;
  505. uint8_t n = LCD_WIDTH - 1;
  506. lcd.setCursor(0, row);
  507. lcd.print('>');
  508. if (longFilename[0] != '\0')
  509. {
  510. filename = longFilename;
  511. longFilename[LCD_WIDTH-1] = '\0';
  512. }
  513. while((c = *filename) != '\0')
  514. {
  515. lcd.print(c);
  516. filename++;
  517. n--;
  518. }
  519. while(n--)
  520. lcd.print(' ');
  521. }
  522. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  523. {
  524. char c;
  525. uint8_t n = LCD_WIDTH - 1;
  526. lcd.setCursor(0, row);
  527. lcd.print(' ');
  528. if (longFilename[0] != '\0')
  529. {
  530. filename = longFilename;
  531. longFilename[LCD_WIDTH-1] = '\0';
  532. }
  533. while((c = *filename) != '\0')
  534. {
  535. lcd.print(c);
  536. filename++;
  537. n--;
  538. }
  539. while(n--)
  540. lcd.print(' ');
  541. }
  542. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  543. {
  544. char c;
  545. uint8_t n = LCD_WIDTH - 2;
  546. lcd.setCursor(0, row);
  547. lcd.print('>');
  548. lcd.print(LCD_STR_FOLDER[0]);
  549. if (longFilename[0] != '\0')
  550. {
  551. filename = longFilename;
  552. longFilename[LCD_WIDTH-2] = '\0';
  553. }
  554. while((c = *filename) != '\0')
  555. {
  556. lcd.print(c);
  557. filename++;
  558. n--;
  559. }
  560. while(n--)
  561. lcd.print(' ');
  562. }
  563. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  564. {
  565. char c;
  566. uint8_t n = LCD_WIDTH - 2;
  567. lcd.setCursor(0, row);
  568. lcd.print(' ');
  569. lcd.print(LCD_STR_FOLDER[0]);
  570. if (longFilename[0] != '\0')
  571. {
  572. filename = longFilename;
  573. longFilename[LCD_WIDTH-2] = '\0';
  574. }
  575. while((c = *filename) != '\0')
  576. {
  577. lcd.print(c);
  578. filename++;
  579. n--;
  580. }
  581. while(n--)
  582. lcd.print(' ');
  583. }
  584. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  585. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  586. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  587. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  588. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  589. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  590. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  591. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  592. static void lcd_implementation_quick_feedback()
  593. {
  594. #ifdef LCD_HAS_I2C_BUZZ
  595. lcd.buzz(300,4000);
  596. #elif defined(BEEPER) && BEEPER > -1
  597. SET_OUTPUT(BEEPER);
  598. for(int8_t i=0;i<10;i++)
  599. {
  600. WRITE(BEEPER,HIGH);
  601. delay(3);
  602. WRITE(BEEPER,LOW);
  603. delay(3);
  604. }
  605. #endif
  606. }
  607. #ifdef LCD_HAS_STATUS_INDICATORS
  608. static void lcd_implementation_update_indicators()
  609. {
  610. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  611. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  612. static uint8_t ledsprev = 0;
  613. uint8_t leds = 0;
  614. if (isHeatingBed()) leds |= LED_A;
  615. if (isHeatingHotend(0)) leds |= LED_B;
  616. if (fanSpeed) leds |= LED_C;
  617. #if EXTRUDERS > 1
  618. if (isHeatingHotend(1)) leds |= LED_C;
  619. #endif
  620. if (leds != ledsprev) {
  621. lcd.setBacklight(leds);
  622. ledsprev = leds;
  623. }
  624. #endif
  625. }
  626. #endif
  627. #ifdef LCD_HAS_EXTRA_BUTTONS
  628. static uint8_t lcd_read_extra_buttons()
  629. {
  630. #ifdef LCD_I2C_TYPE_MCP23017
  631. // the I2C button bit positions are shifted by three bits from the native LiquidTWI2 position
  632. // this is potentially too slow to call inside interrupt context
  633. return lcd.readButtons() << B_I2C_BTN_OFFSET;
  634. #endif
  635. }
  636. #endif
  637. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H