My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd_implementation_hitachi_HD44780.h 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. #ifndef ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H
  2. #define ULTRALCD_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. extern "C" void __cxa_pure_virtual() { while (1); }
  162. #include <LCD.h>
  163. #include <LiquidCrystal_SR.h>
  164. #define LCD_CLASS LiquidCrystal_SR
  165. LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN);
  166. #else
  167. // Standard directly connected LCD implementations
  168. #ifdef LANGUAGE_RU
  169. #include "LiquidCrystalRus.h"
  170. #define LCD_CLASS LiquidCrystalRus
  171. #else
  172. #include <LiquidCrystal.h>
  173. #define LCD_CLASS LiquidCrystal
  174. #endif
  175. 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
  176. #endif
  177. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  178. static uint16_t progressBarTick = 0;
  179. #if PROGRESS_MSG_EXPIRE > 0
  180. static uint16_t messageTick = 0;
  181. #endif
  182. #define LCD_STR_PROGRESS "\x03\x04\x05"
  183. #endif
  184. /* Custom characters defined in the first 8 characters of the LCD */
  185. #define LCD_STR_BEDTEMP "\x00"
  186. #define LCD_STR_DEGREE "\x01"
  187. #define LCD_STR_THERMOMETER "\x02"
  188. #define LCD_STR_UPLEVEL "\x03"
  189. #define LCD_STR_REFRESH "\x04"
  190. #define LCD_STR_FOLDER "\x05"
  191. #define LCD_STR_FEEDRATE "\x06"
  192. #define LCD_STR_CLOCK "\x07"
  193. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  194. static void lcd_set_custom_characters(
  195. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  196. bool progress_bar_set=true
  197. #endif
  198. ) {
  199. byte bedTemp[8] = {
  200. B00000,
  201. B11111,
  202. B10101,
  203. B10001,
  204. B10101,
  205. B11111,
  206. B00000,
  207. B00000
  208. }; //thanks Sonny Mounicou
  209. byte degree[8] = {
  210. B01100,
  211. B10010,
  212. B10010,
  213. B01100,
  214. B00000,
  215. B00000,
  216. B00000,
  217. B00000
  218. };
  219. byte thermometer[8] = {
  220. B00100,
  221. B01010,
  222. B01010,
  223. B01010,
  224. B01010,
  225. B10001,
  226. B10001,
  227. B01110
  228. };
  229. byte uplevel[8] = {
  230. B00100,
  231. B01110,
  232. B11111,
  233. B00100,
  234. B11100,
  235. B00000,
  236. B00000,
  237. B00000
  238. }; //thanks joris
  239. byte refresh[8] = {
  240. B00000,
  241. B00110,
  242. B11001,
  243. B11000,
  244. B00011,
  245. B10011,
  246. B01100,
  247. B00000,
  248. }; //thanks joris
  249. byte folder[8] = {
  250. B00000,
  251. B11100,
  252. B11111,
  253. B10001,
  254. B10001,
  255. B11111,
  256. B00000,
  257. B00000
  258. }; //thanks joris
  259. byte feedrate[8] = {
  260. B11100,
  261. B10000,
  262. B11000,
  263. B10111,
  264. B00101,
  265. B00110,
  266. B00101,
  267. B00000
  268. }; //thanks Sonny Mounicou
  269. byte clock[8] = {
  270. B00000,
  271. B01110,
  272. B10011,
  273. B10101,
  274. B10001,
  275. B01110,
  276. B00000,
  277. B00000
  278. }; //thanks Sonny Mounicou
  279. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  280. static bool char_mode = false;
  281. byte progress[3][8] = { {
  282. B00000,
  283. B10000,
  284. B10000,
  285. B10000,
  286. B10000,
  287. B10000,
  288. B10000,
  289. B00000
  290. }, {
  291. B00000,
  292. B10100,
  293. B10100,
  294. B10100,
  295. B10100,
  296. B10100,
  297. B10100,
  298. B00000
  299. }, {
  300. B00000,
  301. B10101,
  302. B10101,
  303. B10101,
  304. B10101,
  305. B10101,
  306. B10101,
  307. B00000
  308. } };
  309. if (progress_bar_set != char_mode) {
  310. char_mode = progress_bar_set;
  311. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  312. lcd.createChar(LCD_STR_DEGREE[0], degree);
  313. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  314. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  315. lcd.createChar(LCD_STR_CLOCK[0], clock);
  316. if (progress_bar_set) {
  317. // Progress bar characters for info screen
  318. for (int i=3; i--;) lcd.createChar(LCD_STR_PROGRESS[i], progress[i]);
  319. }
  320. else {
  321. // Custom characters for submenus
  322. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  323. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  324. lcd.createChar(LCD_STR_FOLDER[0], folder);
  325. }
  326. }
  327. #else
  328. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  329. lcd.createChar(LCD_STR_DEGREE[0], degree);
  330. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  331. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  332. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  333. lcd.createChar(LCD_STR_FOLDER[0], folder);
  334. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  335. lcd.createChar(LCD_STR_CLOCK[0], clock);
  336. #endif
  337. }
  338. static void lcd_implementation_init(
  339. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  340. bool progress_bar_set=true
  341. #endif
  342. ) {
  343. #if defined(LCD_I2C_TYPE_PCF8575)
  344. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  345. #ifdef LCD_I2C_PIN_BL
  346. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  347. lcd.setBacklight(HIGH);
  348. #endif
  349. #elif defined(LCD_I2C_TYPE_MCP23017)
  350. lcd.setMCPType(LTI_TYPE_MCP23017);
  351. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  352. lcd.setBacklight(0); //set all the LEDs off to begin with
  353. #elif defined(LCD_I2C_TYPE_MCP23008)
  354. lcd.setMCPType(LTI_TYPE_MCP23008);
  355. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  356. #elif defined(LCD_I2C_TYPE_PCA8574)
  357. lcd.init();
  358. lcd.backlight();
  359. #else
  360. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  361. #endif
  362. lcd_set_custom_characters(
  363. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  364. progress_bar_set
  365. #endif
  366. );
  367. lcd.clear();
  368. }
  369. static void lcd_implementation_clear()
  370. {
  371. lcd.clear();
  372. }
  373. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  374. static void lcd_printPGM(const char* str)
  375. {
  376. char c;
  377. while((c = pgm_read_byte(str++)) != '\0')
  378. {
  379. lcd.write(c);
  380. }
  381. }
  382. /*
  383. Possible status screens:
  384. 16x2 |0123456789012345|
  385. |000/000 B000/000|
  386. |Status line.....|
  387. 16x4 |0123456789012345|
  388. |000/000 B000/000|
  389. |SD100% Z000.0|
  390. |F100% T--:--|
  391. |Status line.....|
  392. 20x2 |01234567890123456789|
  393. |T000/000D B000/000D |
  394. |Status line.........|
  395. 20x4 |01234567890123456789|
  396. |T000/000D B000/000D |
  397. |X+000.0 Y+000.0 Z+000.0|
  398. |F100% SD100% T--:--|
  399. |Status line.........|
  400. 20x4 |01234567890123456789|
  401. |T000/000D B000/000D |
  402. |T000/000D Z000.0|
  403. |F100% SD100% T--:--|
  404. |Status line.........|
  405. */
  406. static void lcd_implementation_status_screen()
  407. {
  408. int tHotend=int(degHotend(0) + 0.5);
  409. int tTarget=int(degTargetHotend(0) + 0.5);
  410. #if LCD_WIDTH < 20
  411. lcd.setCursor(0, 0);
  412. lcd.print(itostr3(tHotend));
  413. lcd.print('/');
  414. lcd.print(itostr3left(tTarget));
  415. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  416. //If we have an 2nd extruder or heated bed, show that in the top right corner
  417. lcd.setCursor(8, 0);
  418. # if EXTRUDERS > 1
  419. tHotend = int(degHotend(1) + 0.5);
  420. tTarget = int(degTargetHotend(1) + 0.5);
  421. lcd.print(LCD_STR_THERMOMETER[0]);
  422. # else//Heated bed
  423. tHotend=int(degBed() + 0.5);
  424. tTarget=int(degTargetBed() + 0.5);
  425. lcd.print(LCD_STR_BEDTEMP[0]);
  426. # endif
  427. lcd.print(itostr3(tHotend));
  428. lcd.print('/');
  429. lcd.print(itostr3left(tTarget));
  430. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  431. #else//LCD_WIDTH > 19
  432. lcd.setCursor(0, 0);
  433. lcd.print(LCD_STR_THERMOMETER[0]);
  434. lcd.print(itostr3(tHotend));
  435. lcd.print('/');
  436. lcd.print(itostr3left(tTarget));
  437. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  438. if (tTarget < 10)
  439. lcd.print(' ');
  440. # if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  441. //If we have an 2nd extruder or heated bed, show that in the top right corner
  442. lcd.setCursor(10, 0);
  443. # if EXTRUDERS > 1
  444. tHotend = int(degHotend(1) + 0.5);
  445. tTarget = int(degTargetHotend(1) + 0.5);
  446. lcd.print(LCD_STR_THERMOMETER[0]);
  447. # else//Heated bed
  448. tHotend=int(degBed() + 0.5);
  449. tTarget=int(degTargetBed() + 0.5);
  450. lcd.print(LCD_STR_BEDTEMP[0]);
  451. # endif
  452. lcd.print(itostr3(tHotend));
  453. lcd.print('/');
  454. lcd.print(itostr3left(tTarget));
  455. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  456. if (tTarget < 10)
  457. lcd.print(' ');
  458. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  459. #endif//LCD_WIDTH > 19
  460. #if LCD_HEIGHT > 2
  461. //Lines 2 for 4 line LCD
  462. # if LCD_WIDTH < 20
  463. # ifdef SDSUPPORT
  464. lcd.setCursor(0, 2);
  465. lcd_printPGM(PSTR("SD"));
  466. if (IS_SD_PRINTING)
  467. lcd.print(itostr3(card.percentDone()));
  468. else
  469. lcd_printPGM(PSTR("---"));
  470. lcd.print('%');
  471. # endif//SDSUPPORT
  472. # else//LCD_WIDTH > 19
  473. # if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  474. //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
  475. tHotend=int(degBed() + 0.5);
  476. tTarget=int(degTargetBed() + 0.5);
  477. lcd.setCursor(0, 1);
  478. lcd.print(LCD_STR_BEDTEMP[0]);
  479. lcd.print(itostr3(tHotend));
  480. lcd.print('/');
  481. lcd.print(itostr3left(tTarget));
  482. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  483. if (tTarget < 10)
  484. lcd.print(' ');
  485. # else
  486. lcd.setCursor(0,1);
  487. lcd.print('X');
  488. lcd.print(ftostr3(current_position[X_AXIS]));
  489. lcd_printPGM(PSTR(" Y"));
  490. lcd.print(ftostr3(current_position[Y_AXIS]));
  491. # endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  492. # endif//LCD_WIDTH > 19
  493. lcd.setCursor(LCD_WIDTH - 8, 1);
  494. lcd.print('Z');
  495. lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
  496. #endif//LCD_HEIGHT > 2
  497. #if LCD_HEIGHT > 3
  498. lcd.setCursor(0, 2);
  499. lcd.print(LCD_STR_FEEDRATE[0]);
  500. lcd.print(itostr3(feedmultiply));
  501. lcd.print('%');
  502. # if LCD_WIDTH > 19
  503. # ifdef SDSUPPORT
  504. lcd.setCursor(7, 2);
  505. lcd_printPGM(PSTR("SD"));
  506. if (IS_SD_PRINTING)
  507. lcd.print(itostr3(card.percentDone()));
  508. else
  509. lcd_printPGM(PSTR("---"));
  510. lcd.print('%');
  511. # endif//SDSUPPORT
  512. # endif//LCD_WIDTH > 19
  513. lcd.setCursor(LCD_WIDTH - 6, 2);
  514. lcd.print(LCD_STR_CLOCK[0]);
  515. if(starttime != 0)
  516. {
  517. uint16_t time = millis()/60000 - starttime/60000;
  518. lcd.print(itostr2(time/60));
  519. lcd.print(':');
  520. lcd.print(itostr2(time%60));
  521. }else{
  522. lcd_printPGM(PSTR("--:--"));
  523. }
  524. #endif
  525. // Status message line at the bottom
  526. lcd.setCursor(0, LCD_HEIGHT - 1);
  527. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  528. if (card.isFileOpen()) {
  529. uint16_t mil = millis(), diff = mil - progressBarTick;
  530. if (diff >= PROGRESS_BAR_MSG_TIME || !lcd_status_message[0]) {
  531. // draw the progress bar
  532. int tix = (int)(card.percentDone() * LCD_WIDTH * 3) / 100,
  533. cel = tix / 3, rem = tix % 3, i = LCD_WIDTH;
  534. char msg[LCD_WIDTH+1], b = ' ';
  535. msg[i] = '\0';
  536. while (i--) {
  537. if (i == cel - 1)
  538. b = LCD_STR_PROGRESS[2];
  539. else if (i == cel && rem != 0)
  540. b = LCD_STR_PROGRESS[rem-1];
  541. msg[i] = b;
  542. }
  543. lcd.print(msg);
  544. return;
  545. }
  546. } //card.isFileOpen
  547. #endif //LCD_PROGRESS_BAR
  548. //Display both Status message line and Filament display on the last line
  549. #ifdef FILAMENT_LCD_DISPLAY
  550. if (message_millis + 5000 <= millis()) { //display any status for the first 5 sec after screen is initiated
  551. lcd_printPGM(PSTR("Dia "));
  552. lcd.print(ftostr12ns(filament_width_meas));
  553. lcd_printPGM(PSTR(" V"));
  554. lcd.print(itostr3(100.0*volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  555. lcd.print('%');
  556. return;
  557. }
  558. #endif //FILAMENT_LCD_DISPLAY
  559. lcd.print(lcd_status_message);
  560. }
  561. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  562. {
  563. char c;
  564. //Use all characters in narrow LCDs
  565. #if LCD_WIDTH < 20
  566. uint8_t n = LCD_WIDTH - 1 - 1;
  567. #else
  568. uint8_t n = LCD_WIDTH - 1 - 2;
  569. #endif
  570. lcd.setCursor(0, row);
  571. lcd.print(pre_char);
  572. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  573. {
  574. lcd.print(c);
  575. pstr++;
  576. n--;
  577. }
  578. while(n--)
  579. lcd.print(' ');
  580. lcd.print(post_char);
  581. lcd.print(' ');
  582. }
  583. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  584. {
  585. char c;
  586. //Use all characters in narrow LCDs
  587. #if LCD_WIDTH < 20
  588. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  589. #else
  590. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  591. #endif
  592. lcd.setCursor(0, row);
  593. lcd.print(pre_char);
  594. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  595. {
  596. lcd.print(c);
  597. pstr++;
  598. n--;
  599. }
  600. lcd.print(':');
  601. while(n--)
  602. lcd.print(' ');
  603. lcd.print(data);
  604. }
  605. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  606. {
  607. char c;
  608. //Use all characters in narrow LCDs
  609. #if LCD_WIDTH < 20
  610. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  611. #else
  612. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  613. #endif
  614. lcd.setCursor(0, row);
  615. lcd.print(pre_char);
  616. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  617. {
  618. lcd.print(c);
  619. pstr++;
  620. n--;
  621. }
  622. lcd.print(':');
  623. while(n--)
  624. lcd.print(' ');
  625. lcd_printPGM(data);
  626. }
  627. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  628. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  629. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  630. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  631. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  632. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  633. #define lcd_implementation_drawmenu_setting_edit_float43_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr43(*(data)))
  634. #define lcd_implementation_drawmenu_setting_edit_float43(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr43(*(data)))
  635. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  636. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  637. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  638. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  639. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  640. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  641. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  642. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  643. #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))
  644. #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))
  645. //Add version for callback functions
  646. #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)))
  647. #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)))
  648. #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)))
  649. #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)))
  650. #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)))
  651. #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)))
  652. #define lcd_implementation_drawmenu_setting_edit_callback_float43_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr43(*(data)))
  653. #define lcd_implementation_drawmenu_setting_edit_callback_float43(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr43(*(data)))
  654. #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)))
  655. #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)))
  656. #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)))
  657. #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)))
  658. #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)))
  659. #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)))
  660. #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)))
  661. #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)))
  662. #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))
  663. #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))
  664. void lcd_implementation_drawedit(const char* pstr, char* value)
  665. {
  666. lcd.setCursor(1, 1);
  667. lcd_printPGM(pstr);
  668. lcd.print(':');
  669. #if LCD_WIDTH < 20
  670. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  671. #else
  672. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  673. #endif
  674. lcd.print(value);
  675. }
  676. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  677. {
  678. char c;
  679. uint8_t n = LCD_WIDTH - 1;
  680. lcd.setCursor(0, row);
  681. lcd.print('>');
  682. if (longFilename[0] != '\0')
  683. {
  684. filename = longFilename;
  685. longFilename[LCD_WIDTH-1] = '\0';
  686. }
  687. while( ((c = *filename) != '\0') && (n>0) )
  688. {
  689. lcd.print(c);
  690. filename++;
  691. n--;
  692. }
  693. while(n--)
  694. lcd.print(' ');
  695. }
  696. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  697. {
  698. char c;
  699. uint8_t n = LCD_WIDTH - 1;
  700. lcd.setCursor(0, row);
  701. lcd.print(' ');
  702. if (longFilename[0] != '\0')
  703. {
  704. filename = longFilename;
  705. longFilename[LCD_WIDTH-1] = '\0';
  706. }
  707. while( ((c = *filename) != '\0') && (n>0) )
  708. {
  709. lcd.print(c);
  710. filename++;
  711. n--;
  712. }
  713. while(n--)
  714. lcd.print(' ');
  715. }
  716. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  717. {
  718. char c;
  719. uint8_t n = LCD_WIDTH - 2;
  720. lcd.setCursor(0, row);
  721. lcd.print('>');
  722. lcd.print(LCD_STR_FOLDER[0]);
  723. if (longFilename[0] != '\0')
  724. {
  725. filename = longFilename;
  726. longFilename[LCD_WIDTH-2] = '\0';
  727. }
  728. while( ((c = *filename) != '\0') && (n>0) )
  729. {
  730. lcd.print(c);
  731. filename++;
  732. n--;
  733. }
  734. while(n--)
  735. lcd.print(' ');
  736. }
  737. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  738. {
  739. char c;
  740. uint8_t n = LCD_WIDTH - 2;
  741. lcd.setCursor(0, row);
  742. lcd.print(' ');
  743. lcd.print(LCD_STR_FOLDER[0]);
  744. if (longFilename[0] != '\0')
  745. {
  746. filename = longFilename;
  747. longFilename[LCD_WIDTH-2] = '\0';
  748. }
  749. while( ((c = *filename) != '\0') && (n>0) )
  750. {
  751. lcd.print(c);
  752. filename++;
  753. n--;
  754. }
  755. while(n--)
  756. lcd.print(' ');
  757. }
  758. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  759. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  760. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  761. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  762. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  763. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  764. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  765. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  766. static void lcd_implementation_quick_feedback()
  767. {
  768. #ifdef LCD_USE_I2C_BUZZER
  769. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  770. lcd_buzz(1000/6,100);
  771. #else
  772. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  773. #endif
  774. #elif defined(BEEPER) && BEEPER > -1
  775. SET_OUTPUT(BEEPER);
  776. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  777. for(int8_t i=0;i<10;i++)
  778. {
  779. WRITE(BEEPER,HIGH);
  780. delayMicroseconds(100);
  781. WRITE(BEEPER,LOW);
  782. delayMicroseconds(100);
  783. }
  784. #else
  785. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  786. {
  787. WRITE(BEEPER,HIGH);
  788. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  789. WRITE(BEEPER,LOW);
  790. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  791. }
  792. #endif
  793. #endif
  794. }
  795. #ifdef LCD_HAS_STATUS_INDICATORS
  796. static void lcd_implementation_update_indicators()
  797. {
  798. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  799. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  800. static uint8_t ledsprev = 0;
  801. uint8_t leds = 0;
  802. if (target_temperature_bed > 0) leds |= LED_A;
  803. if (target_temperature[0] > 0) leds |= LED_B;
  804. if (fanSpeed) leds |= LED_C;
  805. #if EXTRUDERS > 1
  806. if (target_temperature[1] > 0) leds |= LED_C;
  807. #endif
  808. if (leds != ledsprev) {
  809. lcd.setBacklight(leds);
  810. ledsprev = leds;
  811. }
  812. #endif
  813. }
  814. #endif
  815. #ifdef LCD_HAS_SLOW_BUTTONS
  816. extern uint32_t blocking_enc;
  817. static uint8_t lcd_implementation_read_slow_buttons()
  818. {
  819. #ifdef LCD_I2C_TYPE_MCP23017
  820. uint8_t slow_buttons;
  821. // Reading these buttons this is likely to be too slow to call inside interrupt context
  822. // so they are called during normal lcd_update
  823. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  824. #if defined(LCD_I2C_VIKI)
  825. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  826. if(blocking_enc > millis()) {
  827. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  828. }
  829. }
  830. #endif
  831. return slow_buttons;
  832. #endif
  833. }
  834. #endif
  835. #endif //__ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H