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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. #else
  154. // Standard directly connected LCD implementations
  155. #if LANGUAGE_CHOICE == 6
  156. #include "LiquidCrystalRus.h"
  157. #define LCD_CLASS LiquidCrystalRus
  158. #else
  159. #include <LiquidCrystal.h>
  160. #define LCD_CLASS LiquidCrystal
  161. #endif
  162. 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
  163. #endif
  164. /* Custom characters defined in the first 8 characters of the LCD */
  165. #define LCD_STR_BEDTEMP "\x00"
  166. #define LCD_STR_DEGREE "\x01"
  167. #define LCD_STR_THERMOMETER "\x02"
  168. #define LCD_STR_UPLEVEL "\x03"
  169. #define LCD_STR_REFRESH "\x04"
  170. #define LCD_STR_FOLDER "\x05"
  171. #define LCD_STR_FEEDRATE "\x06"
  172. #define LCD_STR_CLOCK "\x07"
  173. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  174. static void lcd_implementation_init()
  175. {
  176. byte bedTemp[8] =
  177. {
  178. B00000,
  179. B11111,
  180. B10101,
  181. B10001,
  182. B10101,
  183. B11111,
  184. B00000,
  185. B00000
  186. }; //thanks Sonny Mounicou
  187. byte degree[8] =
  188. {
  189. B01100,
  190. B10010,
  191. B10010,
  192. B01100,
  193. B00000,
  194. B00000,
  195. B00000,
  196. B00000
  197. };
  198. byte thermometer[8] =
  199. {
  200. B00100,
  201. B01010,
  202. B01010,
  203. B01010,
  204. B01010,
  205. B10001,
  206. B10001,
  207. B01110
  208. };
  209. byte uplevel[8]={
  210. B00100,
  211. B01110,
  212. B11111,
  213. B00100,
  214. B11100,
  215. B00000,
  216. B00000,
  217. B00000
  218. }; //thanks joris
  219. byte refresh[8]={
  220. B00000,
  221. B00110,
  222. B11001,
  223. B11000,
  224. B00011,
  225. B10011,
  226. B01100,
  227. B00000,
  228. }; //thanks joris
  229. byte folder [8]={
  230. B00000,
  231. B11100,
  232. B11111,
  233. B10001,
  234. B10001,
  235. B11111,
  236. B00000,
  237. B00000
  238. }; //thanks joris
  239. byte feedrate [8]={
  240. B11100,
  241. B10000,
  242. B11000,
  243. B10111,
  244. B00101,
  245. B00110,
  246. B00101,
  247. B00000
  248. }; //thanks Sonny Mounicou
  249. byte clock [8]={
  250. B00000,
  251. B01110,
  252. B10011,
  253. B10101,
  254. B10001,
  255. B01110,
  256. B00000,
  257. B00000
  258. }; //thanks Sonny Mounicou
  259. #if defined(LCDI2C_TYPE_PCF8575)
  260. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  261. #ifdef LCD_I2C_PIN_BL
  262. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  263. lcd.setBacklight(HIGH);
  264. #endif
  265. #elif defined(LCD_I2C_TYPE_MCP23017)
  266. lcd.setMCPType(LTI_TYPE_MCP23017);
  267. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  268. lcd.setBacklight(0); //set all the LEDs off to begin with
  269. #elif defined(LCD_I2C_TYPE_MCP23008)
  270. lcd.setMCPType(LTI_TYPE_MCP23008);
  271. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  272. #else
  273. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  274. #endif
  275. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  276. lcd.createChar(LCD_STR_DEGREE[0], degree);
  277. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  278. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  279. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  280. lcd.createChar(LCD_STR_FOLDER[0], folder);
  281. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  282. lcd.createChar(LCD_STR_CLOCK[0], clock);
  283. lcd.clear();
  284. }
  285. static void lcd_implementation_clear()
  286. {
  287. lcd.clear();
  288. }
  289. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  290. static void lcd_printPGM(const char* str)
  291. {
  292. char c;
  293. while((c = pgm_read_byte(str++)) != '\0')
  294. {
  295. lcd.write(c);
  296. }
  297. }
  298. /*
  299. Possible status screens:
  300. 16x2 |0123456789012345|
  301. |000/000 B000/000|
  302. |Status line.....|
  303. 16x4 |0123456789012345|
  304. |000/000 B000/000|
  305. |SD100% Z000.0|
  306. |F100% T--:--|
  307. |Status line.....|
  308. 20x2 |01234567890123456789|
  309. |T000/000D B000/000D |
  310. |Status line.........|
  311. 20x4 |01234567890123456789|
  312. |T000/000D B000/000D |
  313. |X+000.0 Y+000.0 Z+000.0|
  314. |F100% SD100% T--:--|
  315. |Status line.........|
  316. 20x4 |01234567890123456789|
  317. |T000/000D B000/000D |
  318. |T000/000D Z000.0|
  319. |F100% SD100% T--:--|
  320. |Status line.........|
  321. */
  322. static void lcd_implementation_status_screen()
  323. {
  324. int tHotend=int(degHotend(0) + 0.5);
  325. int tTarget=int(degTargetHotend(0) + 0.5);
  326. #if LCD_WIDTH < 20
  327. lcd.setCursor(0, 0);
  328. lcd.print(itostr3(tHotend));
  329. lcd.print('/');
  330. lcd.print(itostr3left(tTarget));
  331. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  332. //If we have an 2nd extruder or heated bed, show that in the top right corner
  333. lcd.setCursor(8, 0);
  334. # if EXTRUDERS > 1
  335. tHotend = int(degHotend(1) + 0.5);
  336. tTarget = int(degTargetHotend(1) + 0.5);
  337. lcd.print(LCD_STR_THERMOMETER[0]);
  338. # else//Heated bed
  339. tHotend=int(degBed() + 0.5);
  340. tTarget=int(degTargetBed() + 0.5);
  341. lcd.print(LCD_STR_BEDTEMP[0]);
  342. # endif
  343. lcd.print(itostr3(tHotend));
  344. lcd.print('/');
  345. lcd.print(itostr3left(tTarget));
  346. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  347. #else//LCD_WIDTH > 19
  348. lcd.setCursor(0, 0);
  349. lcd.print(LCD_STR_THERMOMETER[0]);
  350. lcd.print(itostr3(tHotend));
  351. lcd.print('/');
  352. lcd.print(itostr3left(tTarget));
  353. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  354. if (tTarget < 10)
  355. lcd.print(' ');
  356. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  357. //If we have an 2nd extruder or heated bed, show that in the top right corner
  358. lcd.setCursor(10, 0);
  359. # if EXTRUDERS > 1
  360. tHotend = int(degHotend(1) + 0.5);
  361. tTarget = int(degTargetHotend(1) + 0.5);
  362. lcd.print(LCD_STR_THERMOMETER[0]);
  363. # else//Heated bed
  364. tHotend=int(degBed() + 0.5);
  365. tTarget=int(degTargetBed() + 0.5);
  366. lcd.print(LCD_STR_BEDTEMP[0]);
  367. # endif
  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. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  375. #endif//LCD_WIDTH > 19
  376. #if LCD_HEIGHT > 2
  377. //Lines 2 for 4 line LCD
  378. # if LCD_WIDTH < 20
  379. # ifdef SDSUPPORT
  380. lcd.setCursor(0, 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. # else//LCD_WIDTH > 19
  389. # if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  390. //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
  391. tHotend=int(degBed() + 0.5);
  392. tTarget=int(degTargetBed() + 0.5);
  393. lcd.setCursor(0, 1);
  394. lcd.print(LCD_STR_BEDTEMP[0]);
  395. lcd.print(itostr3(tHotend));
  396. lcd.print('/');
  397. lcd.print(itostr3left(tTarget));
  398. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  399. if (tTarget < 10)
  400. lcd.print(' ');
  401. # else
  402. lcd.setCursor(0,1);
  403. lcd.print('X');
  404. lcd.print(ftostr3(current_position[X_AXIS]));
  405. lcd_printPGM(PSTR(" Y"));
  406. lcd.print(ftostr3(current_position[Y_AXIS]));
  407. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  408. # endif//LCD_WIDTH > 19
  409. lcd.setCursor(LCD_WIDTH - 8, 1);
  410. lcd.print('Z');
  411. lcd.print(ftostr32(current_position[Z_AXIS]));
  412. #endif//LCD_HEIGHT > 2
  413. #if LCD_HEIGHT > 3
  414. lcd.setCursor(0, 2);
  415. lcd.print(LCD_STR_FEEDRATE[0]);
  416. lcd.print(itostr3(feedmultiply));
  417. lcd.print('%');
  418. # if LCD_WIDTH > 19
  419. # ifdef SDSUPPORT
  420. lcd.setCursor(7, 2);
  421. lcd_printPGM(PSTR("SD"));
  422. if (IS_SD_PRINTING)
  423. lcd.print(itostr3(card.percentDone()));
  424. else
  425. lcd_printPGM(PSTR("---"));
  426. lcd.print('%');
  427. # endif//SDSUPPORT
  428. # endif//LCD_WIDTH > 19
  429. lcd.setCursor(LCD_WIDTH - 6, 2);
  430. lcd.print(LCD_STR_CLOCK[0]);
  431. if(starttime != 0)
  432. {
  433. uint16_t time = millis()/60000 - starttime/60000;
  434. lcd.print(itostr2(time/60));
  435. lcd.print(':');
  436. lcd.print(itostr2(time%60));
  437. }else{
  438. lcd_printPGM(PSTR("--:--"));
  439. }
  440. #endif
  441. //Status message line on the last line
  442. lcd.setCursor(0, LCD_HEIGHT - 1);
  443. lcd.print(lcd_status_message);
  444. }
  445. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  446. {
  447. char c;
  448. //Use all characters in narrow LCDs
  449. #if LCD_WIDTH < 20
  450. uint8_t n = LCD_WIDTH - 1 - 1;
  451. #else
  452. uint8_t n = LCD_WIDTH - 1 - 2;
  453. #endif
  454. lcd.setCursor(0, row);
  455. lcd.print(pre_char);
  456. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  457. {
  458. lcd.print(c);
  459. pstr++;
  460. n--;
  461. }
  462. while(n--)
  463. lcd.print(' ');
  464. lcd.print(post_char);
  465. lcd.print(' ');
  466. }
  467. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  468. {
  469. char c;
  470. //Use all characters in narrow LCDs
  471. #if LCD_WIDTH < 20
  472. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  473. #else
  474. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  475. #endif
  476. lcd.setCursor(0, row);
  477. lcd.print(pre_char);
  478. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  479. {
  480. lcd.print(c);
  481. pstr++;
  482. n--;
  483. }
  484. lcd.print(':');
  485. while(n--)
  486. lcd.print(' ');
  487. lcd.print(data);
  488. }
  489. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  490. {
  491. char c;
  492. //Use all characters in narrow LCDs
  493. #if LCD_WIDTH < 20
  494. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  495. #else
  496. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  497. #endif
  498. lcd.setCursor(0, row);
  499. lcd.print(pre_char);
  500. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  501. {
  502. lcd.print(c);
  503. pstr++;
  504. n--;
  505. }
  506. lcd.print(':');
  507. while(n--)
  508. lcd.print(' ');
  509. lcd_printPGM(data);
  510. }
  511. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  512. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  513. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  514. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  515. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  516. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  517. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  518. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  519. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  520. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  521. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  522. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  523. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  524. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  525. #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))
  526. #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))
  527. //Add version for callback functions
  528. #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)))
  529. #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)))
  530. #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)))
  531. #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)))
  532. #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)))
  533. #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)))
  534. #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)))
  535. #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)))
  536. #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)))
  537. #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)))
  538. #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)))
  539. #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)))
  540. #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)))
  541. #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)))
  542. #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))
  543. #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))
  544. void lcd_implementation_drawedit(const char* pstr, char* value)
  545. {
  546. lcd.setCursor(1, 1);
  547. lcd_printPGM(pstr);
  548. lcd.print(':');
  549. #if LCD_WIDTH < 20
  550. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  551. #else
  552. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  553. #endif
  554. lcd.print(value);
  555. }
  556. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  557. {
  558. char c;
  559. uint8_t n = LCD_WIDTH - 1;
  560. lcd.setCursor(0, row);
  561. lcd.print('>');
  562. if (longFilename[0] != '\0')
  563. {
  564. filename = longFilename;
  565. longFilename[LCD_WIDTH-1] = '\0';
  566. }
  567. while( ((c = *filename) != '\0') && (n>0) )
  568. {
  569. lcd.print(c);
  570. filename++;
  571. n--;
  572. }
  573. while(n--)
  574. lcd.print(' ');
  575. }
  576. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  577. {
  578. char c;
  579. uint8_t n = LCD_WIDTH - 1;
  580. lcd.setCursor(0, row);
  581. lcd.print(' ');
  582. if (longFilename[0] != '\0')
  583. {
  584. filename = longFilename;
  585. longFilename[LCD_WIDTH-1] = '\0';
  586. }
  587. while( ((c = *filename) != '\0') && (n>0) )
  588. {
  589. lcd.print(c);
  590. filename++;
  591. n--;
  592. }
  593. while(n--)
  594. lcd.print(' ');
  595. }
  596. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  597. {
  598. char c;
  599. uint8_t n = LCD_WIDTH - 2;
  600. lcd.setCursor(0, row);
  601. lcd.print('>');
  602. lcd.print(LCD_STR_FOLDER[0]);
  603. if (longFilename[0] != '\0')
  604. {
  605. filename = longFilename;
  606. longFilename[LCD_WIDTH-2] = '\0';
  607. }
  608. while( ((c = *filename) != '\0') && (n>0) )
  609. {
  610. lcd.print(c);
  611. filename++;
  612. n--;
  613. }
  614. while(n--)
  615. lcd.print(' ');
  616. }
  617. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  618. {
  619. char c;
  620. uint8_t n = LCD_WIDTH - 2;
  621. lcd.setCursor(0, row);
  622. lcd.print(' ');
  623. lcd.print(LCD_STR_FOLDER[0]);
  624. if (longFilename[0] != '\0')
  625. {
  626. filename = longFilename;
  627. longFilename[LCD_WIDTH-2] = '\0';
  628. }
  629. while( ((c = *filename) != '\0') && (n>0) )
  630. {
  631. lcd.print(c);
  632. filename++;
  633. n--;
  634. }
  635. while(n--)
  636. lcd.print(' ');
  637. }
  638. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  639. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  640. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  641. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  642. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  643. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  644. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  645. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  646. static void lcd_implementation_quick_feedback()
  647. {
  648. #ifdef LCD_USE_I2C_BUZZER
  649. lcd.buzz(60,1000/6);
  650. #elif defined(BEEPER) && BEEPER > -1
  651. SET_OUTPUT(BEEPER);
  652. for(int8_t i=0;i<10;i++)
  653. {
  654. WRITE(BEEPER,HIGH);
  655. delay(3);
  656. WRITE(BEEPER,LOW);
  657. delay(3);
  658. }
  659. #endif
  660. }
  661. #ifdef LCD_HAS_STATUS_INDICATORS
  662. static void lcd_implementation_update_indicators()
  663. {
  664. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  665. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  666. static uint8_t ledsprev = 0;
  667. uint8_t leds = 0;
  668. if (target_temperature_bed > 0) leds |= LED_A;
  669. if (target_temperature[0] > 0) leds |= LED_B;
  670. if (fanSpeed) leds |= LED_C;
  671. #if EXTRUDERS > 1
  672. if (target_temperature[1] > 0) leds |= LED_C;
  673. #endif
  674. if (leds != ledsprev) {
  675. lcd.setBacklight(leds);
  676. ledsprev = leds;
  677. }
  678. #endif
  679. }
  680. #endif
  681. #ifdef LCD_HAS_SLOW_BUTTONS
  682. static uint8_t lcd_implementation_read_slow_buttons()
  683. {
  684. #ifdef LCD_I2C_TYPE_MCP23017
  685. // Reading these buttons this is likely to be too slow to call inside interrupt context
  686. // so they are called during normal lcd_update
  687. return lcd.readButtons() << B_I2C_BTN_OFFSET;
  688. #endif
  689. }
  690. #endif
  691. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H