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

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