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

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