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

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