My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd_implementation_hitachi_HD44780.h 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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 == ru
  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. //Display both Status message line and Filament display on the last line
  457. #ifdef FILAMENT_LCD_DISPLAY
  458. if(message_millis+5000>millis()){ //display any status for the first 5 sec after screen is initiated
  459. lcd.setCursor(0, LCD_HEIGHT - 1);
  460. lcd.print(lcd_status_message);
  461. } else {
  462. lcd.setCursor(0,LCD_HEIGHT - 1);
  463. lcd_printPGM(PSTR("Dia "));
  464. lcd.print(ftostr12ns(filament_width_meas));
  465. lcd_printPGM(PSTR(" V"));
  466. lcd.print(itostr3(100.0*volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  467. lcd.print('%');
  468. }
  469. #else
  470. lcd.setCursor(0, LCD_HEIGHT - 1);
  471. lcd.print(lcd_status_message);
  472. #endif
  473. }
  474. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  475. {
  476. char c;
  477. //Use all characters in narrow LCDs
  478. #if LCD_WIDTH < 20
  479. uint8_t n = LCD_WIDTH - 1 - 1;
  480. #else
  481. uint8_t n = LCD_WIDTH - 1 - 2;
  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. while(n--)
  492. lcd.print(' ');
  493. lcd.print(post_char);
  494. lcd.print(' ');
  495. }
  496. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, 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(data);
  502. #else
  503. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(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.print(data);
  517. }
  518. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  519. {
  520. char c;
  521. //Use all characters in narrow LCDs
  522. #if LCD_WIDTH < 20
  523. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  524. #else
  525. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  526. #endif
  527. lcd.setCursor(0, row);
  528. lcd.print(pre_char);
  529. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  530. {
  531. lcd.print(c);
  532. pstr++;
  533. n--;
  534. }
  535. lcd.print(':');
  536. while(n--)
  537. lcd.print(' ');
  538. lcd_printPGM(data);
  539. }
  540. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  541. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  542. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  543. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  544. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  545. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  546. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  547. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  548. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  549. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  550. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  551. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  552. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  553. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  554. #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))
  555. #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))
  556. //Add version for callback functions
  557. #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)))
  558. #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)))
  559. #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)))
  560. #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)))
  561. #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)))
  562. #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)))
  563. #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)))
  564. #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)))
  565. #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)))
  566. #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)))
  567. #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)))
  568. #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)))
  569. #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)))
  570. #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)))
  571. #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))
  572. #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))
  573. void lcd_implementation_drawedit(const char* pstr, char* value)
  574. {
  575. lcd.setCursor(1, 1);
  576. lcd_printPGM(pstr);
  577. lcd.print(':');
  578. #if LCD_WIDTH < 20
  579. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  580. #else
  581. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  582. #endif
  583. lcd.print(value);
  584. }
  585. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  586. {
  587. char c;
  588. uint8_t n = LCD_WIDTH - 1;
  589. lcd.setCursor(0, row);
  590. lcd.print('>');
  591. if (longFilename[0] != '\0')
  592. {
  593. filename = longFilename;
  594. longFilename[LCD_WIDTH-1] = '\0';
  595. }
  596. while( ((c = *filename) != '\0') && (n>0) )
  597. {
  598. lcd.print(c);
  599. filename++;
  600. n--;
  601. }
  602. while(n--)
  603. lcd.print(' ');
  604. }
  605. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  606. {
  607. char c;
  608. uint8_t n = LCD_WIDTH - 1;
  609. lcd.setCursor(0, row);
  610. lcd.print(' ');
  611. if (longFilename[0] != '\0')
  612. {
  613. filename = longFilename;
  614. longFilename[LCD_WIDTH-1] = '\0';
  615. }
  616. while( ((c = *filename) != '\0') && (n>0) )
  617. {
  618. lcd.print(c);
  619. filename++;
  620. n--;
  621. }
  622. while(n--)
  623. lcd.print(' ');
  624. }
  625. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  626. {
  627. char c;
  628. uint8_t n = LCD_WIDTH - 2;
  629. lcd.setCursor(0, row);
  630. lcd.print('>');
  631. lcd.print(LCD_STR_FOLDER[0]);
  632. if (longFilename[0] != '\0')
  633. {
  634. filename = longFilename;
  635. longFilename[LCD_WIDTH-2] = '\0';
  636. }
  637. while( ((c = *filename) != '\0') && (n>0) )
  638. {
  639. lcd.print(c);
  640. filename++;
  641. n--;
  642. }
  643. while(n--)
  644. lcd.print(' ');
  645. }
  646. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  647. {
  648. char c;
  649. uint8_t n = LCD_WIDTH - 2;
  650. lcd.setCursor(0, row);
  651. lcd.print(' ');
  652. lcd.print(LCD_STR_FOLDER[0]);
  653. if (longFilename[0] != '\0')
  654. {
  655. filename = longFilename;
  656. longFilename[LCD_WIDTH-2] = '\0';
  657. }
  658. while( ((c = *filename) != '\0') && (n>0) )
  659. {
  660. lcd.print(c);
  661. filename++;
  662. n--;
  663. }
  664. while(n--)
  665. lcd.print(' ');
  666. }
  667. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  668. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  669. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  670. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  671. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  672. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  673. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  674. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  675. static void lcd_implementation_quick_feedback()
  676. {
  677. #ifdef LCD_USE_I2C_BUZZER
  678. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  679. lcd_buzz(1000/6,100);
  680. #else
  681. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  682. #endif
  683. #elif defined(BEEPER) && BEEPER > -1
  684. SET_OUTPUT(BEEPER);
  685. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  686. for(int8_t i=0;i<10;i++)
  687. {
  688. WRITE(BEEPER,HIGH);
  689. delayMicroseconds(100);
  690. WRITE(BEEPER,LOW);
  691. delayMicroseconds(100);
  692. }
  693. #else
  694. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  695. {
  696. WRITE(BEEPER,HIGH);
  697. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  698. WRITE(BEEPER,LOW);
  699. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  700. }
  701. #endif
  702. #endif
  703. }
  704. #ifdef LCD_HAS_STATUS_INDICATORS
  705. static void lcd_implementation_update_indicators()
  706. {
  707. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  708. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  709. static uint8_t ledsprev = 0;
  710. uint8_t leds = 0;
  711. if (target_temperature_bed > 0) leds |= LED_A;
  712. if (target_temperature[0] > 0) leds |= LED_B;
  713. if (fanSpeed) leds |= LED_C;
  714. #if EXTRUDERS > 1
  715. if (target_temperature[1] > 0) leds |= LED_C;
  716. #endif
  717. if (leds != ledsprev) {
  718. lcd.setBacklight(leds);
  719. ledsprev = leds;
  720. }
  721. #endif
  722. }
  723. #endif
  724. #ifdef LCD_HAS_SLOW_BUTTONS
  725. extern uint32_t blocking_enc;
  726. static uint8_t lcd_implementation_read_slow_buttons()
  727. {
  728. #ifdef LCD_I2C_TYPE_MCP23017
  729. uint8_t slow_buttons;
  730. // Reading these buttons this is likely to be too slow to call inside interrupt context
  731. // so they are called during normal lcd_update
  732. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  733. #if defined(LCD_I2C_VIKI)
  734. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  735. if(blocking_enc > millis()) {
  736. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  737. }
  738. }
  739. #endif
  740. return slow_buttons;
  741. #endif
  742. }
  743. #endif
  744. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H