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

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