ultralcd_implementation_hitachi_HD44780.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. #ifndef ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H
  2. #define ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H
  3. int scrollstuff = 0;
  4. char longFilenameOLD[LONG_FILENAME_LENGTH];
  5. #include "Configuration_prusa.h"
  6. #include "Marlin.h"
  7. #include "sound.h"
  8. /**
  9. * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
  10. * When selecting the Russian language, a slightly different LCD implementation is used to handle UTF8 characters.
  11. **/
  12. #ifndef REPRAPWORLD_KEYPAD
  13. extern volatile uint8_t buttons; //the last checked buttons in a bit array.
  14. #else
  15. extern volatile uint16_t buttons; //an extended version of the last checked buttons in a bit array.
  16. #endif
  17. ////////////////////////////////////
  18. // Setup button and encode mappings for each panel (into 'buttons' variable
  19. //
  20. // This is just to map common functions (across different panels) onto the same
  21. // macro name. The mapping is independent of whether the button is directly connected or
  22. // via a shift/i2c register.
  23. #ifdef ULTIPANEL
  24. // All UltiPanels might have an encoder - so this is always be mapped onto first two bits
  25. #define BLEN_B 1
  26. #define BLEN_A 0
  27. #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
  28. #define EN_A (1<<BLEN_A)
  29. #if defined(BTN_ENC) && BTN_ENC > -1
  30. // encoder click is directly connected
  31. #define BLEN_C 2
  32. #define EN_C (1<<BLEN_C)
  33. #endif
  34. //
  35. // Setup other button mappings of each panel
  36. //
  37. #if defined(LCD_I2C_VIKI)
  38. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  39. // button and encoder bit positions within 'buttons'
  40. #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  41. #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
  42. #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
  43. #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
  44. #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
  45. #if defined(BTN_ENC) && BTN_ENC > -1
  46. // the pause/stop/restart button is connected to BTN_ENC when used
  47. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  48. #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
  49. #else
  50. #define LCD_CLICKED (buttons&(B_MI|B_RI))
  51. #endif
  52. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  53. #define LCD_HAS_SLOW_BUTTONS
  54. #elif defined(LCD_I2C_PANELOLU2)
  55. // encoder click can be read through I2C if not directly connected
  56. #if BTN_ENC <= 0
  57. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  58. #define B_MI (PANELOLU2_ENCODER_C<<B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  59. #define LCD_CLICKED (buttons&B_MI)
  60. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  61. #define LCD_HAS_SLOW_BUTTONS
  62. #else
  63. #define LCD_CLICKED (buttons&EN_C)
  64. #endif
  65. #elif defined(REPRAPWORLD_KEYPAD)
  66. // define register bit values, don't change it
  67. #define BLEN_REPRAPWORLD_KEYPAD_F3 0
  68. #define BLEN_REPRAPWORLD_KEYPAD_F2 1
  69. #define BLEN_REPRAPWORLD_KEYPAD_F1 2
  70. #define BLEN_REPRAPWORLD_KEYPAD_UP 3
  71. #define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4
  72. #define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5
  73. #define BLEN_REPRAPWORLD_KEYPAD_DOWN 6
  74. #define BLEN_REPRAPWORLD_KEYPAD_LEFT 7
  75. #define REPRAPWORLD_BTN_OFFSET 3 // bit offset into buttons for shift register values
  76. #define EN_REPRAPWORLD_KEYPAD_F3 (1<<(BLEN_REPRAPWORLD_KEYPAD_F3+REPRAPWORLD_BTN_OFFSET))
  77. #define EN_REPRAPWORLD_KEYPAD_F2 (1<<(BLEN_REPRAPWORLD_KEYPAD_F2+REPRAPWORLD_BTN_OFFSET))
  78. #define EN_REPRAPWORLD_KEYPAD_F1 (1<<(BLEN_REPRAPWORLD_KEYPAD_F1+REPRAPWORLD_BTN_OFFSET))
  79. #define EN_REPRAPWORLD_KEYPAD_UP (1<<(BLEN_REPRAPWORLD_KEYPAD_UP+REPRAPWORLD_BTN_OFFSET))
  80. #define EN_REPRAPWORLD_KEYPAD_RIGHT (1<<(BLEN_REPRAPWORLD_KEYPAD_RIGHT+REPRAPWORLD_BTN_OFFSET))
  81. #define EN_REPRAPWORLD_KEYPAD_MIDDLE (1<<(BLEN_REPRAPWORLD_KEYPAD_MIDDLE+REPRAPWORLD_BTN_OFFSET))
  82. #define EN_REPRAPWORLD_KEYPAD_DOWN (1<<(BLEN_REPRAPWORLD_KEYPAD_DOWN+REPRAPWORLD_BTN_OFFSET))
  83. #define EN_REPRAPWORLD_KEYPAD_LEFT (1<<(BLEN_REPRAPWORLD_KEYPAD_LEFT+REPRAPWORLD_BTN_OFFSET))
  84. #define LCD_CLICKED ((buttons&EN_C) || (buttons&EN_REPRAPWORLD_KEYPAD_F1))
  85. #define REPRAPWORLD_KEYPAD_MOVE_Y_DOWN (buttons&EN_REPRAPWORLD_KEYPAD_DOWN)
  86. #define REPRAPWORLD_KEYPAD_MOVE_Y_UP (buttons&EN_REPRAPWORLD_KEYPAD_UP)
  87. #define REPRAPWORLD_KEYPAD_MOVE_HOME (buttons&EN_REPRAPWORLD_KEYPAD_MIDDLE)
  88. #elif defined(NEWPANEL)
  89. #define LCD_CLICKED (buttons&EN_C)
  90. #else // old style ULTIPANEL
  91. //bits in the shift register that carry the buttons for:
  92. // left up center down right red(stop)
  93. #define BL_LE 7
  94. #define BL_UP 6
  95. #define BL_MI 5
  96. #define BL_DW 4
  97. #define BL_RI 3
  98. #define BL_ST 2
  99. //automatic, do not change
  100. #define B_LE (1<<BL_LE)
  101. #define B_UP (1<<BL_UP)
  102. #define B_MI (1<<BL_MI)
  103. #define B_DW (1<<BL_DW)
  104. #define B_RI (1<<BL_RI)
  105. #define B_ST (1<<BL_ST)
  106. #define LCD_CLICKED (buttons&(B_MI|B_ST))
  107. #endif
  108. ////////////////////////
  109. // Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  110. // These values are independent of which pins are used for EN_A and EN_B indications
  111. // The rotary encoder part is also independent to the chipset used for the LCD
  112. #if defined(EN_A) && defined(EN_B)
  113. #define encrot0 0
  114. #define encrot1 2
  115. #define encrot2 3
  116. #define encrot3 1
  117. #endif
  118. #endif //ULTIPANEL
  119. ////////////////////////////////////
  120. // Create LCD class instance and chipset-specific information
  121. #if defined(LCD_I2C_TYPE_PCF8575)
  122. // note: these are register mapped pins on the PCF8575 controller not Arduino pins
  123. #define LCD_I2C_PIN_BL 3
  124. #define LCD_I2C_PIN_EN 2
  125. #define LCD_I2C_PIN_RW 1
  126. #define LCD_I2C_PIN_RS 0
  127. #define LCD_I2C_PIN_D4 4
  128. #define LCD_I2C_PIN_D5 5
  129. #define LCD_I2C_PIN_D6 6
  130. #define LCD_I2C_PIN_D7 7
  131. #include <Wire.h>
  132. #include <LCD.h>
  133. #include <LiquidCrystal_I2C.h>
  134. #define LCD_CLASS LiquidCrystal_I2C
  135. 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);
  136. #elif defined(LCD_I2C_TYPE_MCP23017)
  137. //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
  138. #define LED_A 0x04 //100
  139. #define LED_B 0x02 //010
  140. #define LED_C 0x01 //001
  141. #define LCD_HAS_STATUS_INDICATORS
  142. #include <Wire.h>
  143. #include <LiquidTWI2.h>
  144. #define LCD_CLASS LiquidTWI2
  145. #if defined(DETECT_DEVICE)
  146. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  147. #else
  148. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  149. #endif
  150. #elif defined(LCD_I2C_TYPE_MCP23008)
  151. #include <Wire.h>
  152. #include <LiquidTWI2.h>
  153. #define LCD_CLASS LiquidTWI2
  154. #if defined(DETECT_DEVICE)
  155. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  156. #else
  157. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  158. #endif
  159. #elif defined(LCD_I2C_TYPE_PCA8574)
  160. #include <LiquidCrystal_I2C.h>
  161. #define LCD_CLASS LiquidCrystal_I2C
  162. LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
  163. // 2 wire Non-latching LCD SR from:
  164. // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
  165. #elif defined(SR_LCD_2W_NL)
  166. extern "C" void __cxa_pure_virtual() { while (1); }
  167. #include <LCD.h>
  168. #include <LiquidCrystal_SR.h>
  169. #define LCD_CLASS LiquidCrystal_SR
  170. LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN);
  171. #else
  172. // Standard directly connected LCD implementations
  173. #ifdef LANGUAGE_RU
  174. #include "LiquidCrystalRus.h"
  175. #define LCD_CLASS LiquidCrystalRus
  176. #else
  177. #include "LiquidCrystal.h"
  178. #define LCD_CLASS LiquidCrystal
  179. #endif
  180. 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
  181. #endif
  182. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  183. static uint16_t progressBarTick = 0;
  184. #if PROGRESS_MSG_EXPIRE > 0
  185. static uint16_t messageTick = 0;
  186. #endif
  187. #define LCD_STR_PROGRESS "\x03\x04\x05"
  188. #endif
  189. /* Custom characters defined in the first 8 characters of the LCD */
  190. #define LCD_STR_BEDTEMP "\x00"
  191. #define LCD_STR_DEGREE "\x01"
  192. #define LCD_STR_THERMOMETER "\x02"
  193. #define LCD_STR_UPLEVEL "\x03"
  194. #define LCD_STR_REFRESH "\x04"
  195. #define LCD_STR_FOLDER "\x05"
  196. #define LCD_STR_FEEDRATE "\x06"
  197. #define LCD_STR_CLOCK "\x07"
  198. #define LCD_STR_ARROW_UP "\x0B"
  199. #define LCD_STR_ARROW_DOWN "\x01"
  200. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  201. static void lcd_set_custom_characters(
  202. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  203. bool progress_bar_set=true
  204. #endif
  205. ) {
  206. byte bedTemp[8] = {
  207. B00000,
  208. B11111,
  209. B10101,
  210. B10001,
  211. B10101,
  212. B11111,
  213. B00000,
  214. B00000
  215. }; //thanks Sonny Mounicou
  216. byte degree[8] = {
  217. B01100,
  218. B10010,
  219. B10010,
  220. B01100,
  221. B00000,
  222. B00000,
  223. B00000,
  224. B00000
  225. };
  226. byte thermometer[8] = {
  227. B00100,
  228. B01010,
  229. B01010,
  230. B01010,
  231. B01010,
  232. B10001,
  233. B10001,
  234. B01110
  235. };
  236. byte uplevel[8] = {
  237. B00100,
  238. B01110,
  239. B11111,
  240. B00100,
  241. B11100,
  242. B00000,
  243. B00000,
  244. B00000
  245. }; //thanks joris
  246. byte refresh[8] = {
  247. B00000,
  248. B00110,
  249. B11001,
  250. B11000,
  251. B00011,
  252. B10011,
  253. B01100,
  254. B00000,
  255. }; //thanks joris
  256. byte folder[8] = {
  257. B00000,
  258. B11100,
  259. B11111,
  260. B10001,
  261. B10001,
  262. B11111,
  263. B00000,
  264. B00000
  265. }; //thanks joris
  266. #ifdef LANGUAGE_EN_H
  267. byte feedrate[8] = {
  268. B11100,
  269. B10000,
  270. B11000,
  271. B10111,
  272. B00101,
  273. B00110,
  274. B00101,
  275. B00000
  276. }; //thanks Sonny Mounicou
  277. #else
  278. /*
  279. byte feedrate[8] = {
  280. B11100,
  281. B10100,
  282. B11000,
  283. B10100,
  284. B00000,
  285. B00111,
  286. B00010,
  287. B00010
  288. };
  289. */
  290. /*
  291. byte feedrate[8] = {
  292. B01100,
  293. B10011,
  294. B00000,
  295. B01100,
  296. B10011,
  297. B00000,
  298. B01100,
  299. B10011
  300. };
  301. */
  302. byte feedrate[8] = {
  303. B00000,
  304. B00100,
  305. B10010,
  306. B01001,
  307. B10010,
  308. B00100,
  309. B00000,
  310. B00000
  311. };
  312. #endif
  313. byte clock[8] = {
  314. B00000,
  315. B01110,
  316. B10011,
  317. B10101,
  318. B10001,
  319. B01110,
  320. B00000,
  321. B00000
  322. }; //thanks Sonny Mounicou
  323. #if 0 // Unused
  324. byte arrup[8] = {
  325. B00100,
  326. B01110,
  327. B11111,
  328. B00000,
  329. B00000,
  330. B00000,
  331. B00000,
  332. B00000
  333. };
  334. byte arrdown[8] = {
  335. B00000,
  336. B00000,
  337. B00000,
  338. B00000,
  339. B00000,
  340. B10001,
  341. B01010,
  342. B00100
  343. };
  344. #endif
  345. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  346. static bool char_mode = false;
  347. byte progress[3][8] = { {
  348. B00000,
  349. B10000,
  350. B10000,
  351. B10000,
  352. B10000,
  353. B10000,
  354. B10000,
  355. B00000
  356. }, {
  357. B00000,
  358. B10100,
  359. B10100,
  360. B10100,
  361. B10100,
  362. B10100,
  363. B10100,
  364. B00000
  365. }, {
  366. B00000,
  367. B10101,
  368. B10101,
  369. B10101,
  370. B10101,
  371. B10101,
  372. B10101,
  373. B00000
  374. } };
  375. if (progress_bar_set != char_mode) {
  376. char_mode = progress_bar_set;
  377. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  378. lcd.createChar(LCD_STR_DEGREE[0], degree);
  379. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  380. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  381. lcd.createChar(LCD_STR_CLOCK[0], clock);
  382. if (progress_bar_set) {
  383. // Progress bar characters for info screen
  384. for (int i=3; i--;) lcd.createChar(LCD_STR_PROGRESS[i], progress[i]);
  385. }
  386. else {
  387. // Custom characters for submenus
  388. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  389. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  390. lcd.createChar(LCD_STR_FOLDER[0], folder);
  391. }
  392. }
  393. #else
  394. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  395. lcd.createChar(LCD_STR_DEGREE[0], degree);
  396. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  397. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  398. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  399. lcd.createChar(LCD_STR_FOLDER[0], folder);
  400. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  401. lcd.createChar(LCD_STR_CLOCK[0], clock);
  402. //lcd.createChar(LCD_STR_ARROW_UP[0], arrup);
  403. //lcd.createChar(LCD_STR_ARROW_DOWN[0], arrdown);
  404. #endif
  405. }
  406. void lcd_set_custom_characters_arrows()
  407. {
  408. byte arrdown[8] = {
  409. B00000,
  410. B00000,
  411. B00000,
  412. B00000,
  413. B00000,
  414. B10001,
  415. B01010,
  416. B00100
  417. };
  418. lcd.createChar(1, arrdown);
  419. }
  420. void lcd_set_custom_characters_progress()
  421. {
  422. byte progress[8] = {
  423. B11111,
  424. B11111,
  425. B11111,
  426. B11111,
  427. B11111,
  428. B11111,
  429. B11111,
  430. B11111,
  431. };
  432. lcd.createChar(1, progress);
  433. }
  434. void lcd_set_custom_characters_nextpage()
  435. {
  436. byte arrdown[8] = {
  437. B00000,
  438. B00000,
  439. B10001,
  440. B01010,
  441. B00100,
  442. B10001,
  443. B01010,
  444. B00100
  445. };
  446. byte confirm[8] = {
  447. B00000,
  448. B00001,
  449. B00011,
  450. B10110,
  451. B11100,
  452. B01000,
  453. B00000,
  454. B00000
  455. };
  456. lcd.createChar(1, arrdown);
  457. lcd.createChar(2, confirm);
  458. }
  459. void lcd_set_custom_characters_degree()
  460. {
  461. byte degree[8] = {
  462. B01100,
  463. B10010,
  464. B10010,
  465. B01100,
  466. B00000,
  467. B00000,
  468. B00000,
  469. B00000
  470. };
  471. lcd.createChar(1, degree);
  472. }
  473. static void lcd_implementation_init(
  474. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  475. bool progress_bar_set=true
  476. #endif
  477. ) {
  478. #if defined(LCD_I2C_TYPE_PCF8575)
  479. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  480. #ifdef LCD_I2C_PIN_BL
  481. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  482. lcd.setBacklight(HIGH);
  483. #endif
  484. #elif defined(LCD_I2C_TYPE_MCP23017)
  485. lcd.setMCPType(LTI_TYPE_MCP23017);
  486. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  487. lcd.setBacklight(0); //set all the LEDs off to begin with
  488. #elif defined(LCD_I2C_TYPE_MCP23008)
  489. lcd.setMCPType(LTI_TYPE_MCP23008);
  490. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  491. #elif defined(LCD_I2C_TYPE_PCA8574)
  492. lcd.init();
  493. lcd.backlight();
  494. #else
  495. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  496. #endif
  497. lcd_set_custom_characters(
  498. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  499. progress_bar_set
  500. #endif
  501. );
  502. lcd.clear();
  503. }
  504. static void lcd_implementation_init_noclear(
  505. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  506. bool progress_bar_set=true
  507. #endif
  508. ) {
  509. #if defined(LCD_I2C_TYPE_PCF8575)
  510. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  511. #ifdef LCD_I2C_PIN_BL
  512. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  513. lcd.setBacklight(HIGH);
  514. #endif
  515. #elif defined(LCD_I2C_TYPE_MCP23017)
  516. lcd.setMCPType(LTI_TYPE_MCP23017);
  517. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  518. lcd.setBacklight(0); //set all the LEDs off to begin with
  519. #elif defined(LCD_I2C_TYPE_MCP23008)
  520. lcd.setMCPType(LTI_TYPE_MCP23008);
  521. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  522. #elif defined(LCD_I2C_TYPE_PCA8574)
  523. lcd.init();
  524. lcd.backlight();
  525. #else
  526. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  527. #endif
  528. lcd_set_custom_characters(
  529. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  530. progress_bar_set
  531. #endif
  532. );
  533. }
  534. inline void lcd_implementation_nodisplay()
  535. {
  536. lcd.noDisplay();
  537. }
  538. inline void lcd_implementation_display()
  539. {
  540. lcd.display();
  541. }
  542. inline void lcd_implementation_clear()
  543. {
  544. lcd.clear();
  545. }
  546. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  547. void lcd_printPGM(const char* str)
  548. {
  549. char c;
  550. while((c = pgm_read_byte(str++)) != '\0')
  551. {
  552. lcd.write(c);
  553. }
  554. }
  555. void lcd_print_at_PGM(uint8_t x, uint8_t y, const char* str)
  556. {
  557. lcd.setCursor(x, y);
  558. char c;
  559. while((c = pgm_read_byte(str++)) != '\0')
  560. {
  561. lcd.write(c);
  562. }
  563. }
  564. void lcd_implementation_write(char c)
  565. {
  566. lcd.write(c);
  567. }
  568. void lcd_implementation_print(int8_t i)
  569. {
  570. lcd.print(i);
  571. }
  572. void lcd_implementation_print_at(uint8_t x, uint8_t y, int8_t i)
  573. {
  574. lcd.setCursor(x, y);
  575. lcd.print(i);
  576. }
  577. void lcd_implementation_print(int i)
  578. {
  579. lcd.print(i);
  580. }
  581. void lcd_implementation_print_at(uint8_t x, uint8_t y, int i)
  582. {
  583. lcd.setCursor(x, y);
  584. lcd.print(i);
  585. }
  586. void lcd_implementation_print(float f)
  587. {
  588. lcd.print(f);
  589. }
  590. void lcd_implementation_print(const char *str)
  591. {
  592. lcd.print(str);
  593. }
  594. void lcd_implementation_print_at(uint8_t x, uint8_t y, const char *str)
  595. {
  596. lcd.setCursor(x, y);
  597. lcd.print(str);
  598. }
  599. /*
  600. 20x4 |01234567890123456789|
  601. |T 000/000D Z000.0 |
  602. |B 000/000D F100% |
  603. |SD100% T--:-- |
  604. |Status line.........|
  605. */
  606. static void lcd_implementation_status_screen()
  607. {
  608. int tHotend=int(degHotend(0) + 0.5);
  609. int tTarget=int(degTargetHotend(0) + 0.5);
  610. //Print the hotend temperature
  611. lcd.setCursor(0, 0);
  612. lcd.print(LCD_STR_THERMOMETER[0]);
  613. lcd.print(itostr3(tHotend));
  614. lcd.print('/');
  615. lcd.print(itostr3left(tTarget));
  616. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  617. lcd_printPGM(PSTR(" "));
  618. //Print the Z coordinates
  619. lcd.setCursor(LCD_WIDTH - 8-2, 0);
  620. #if 1
  621. lcd_printPGM(PSTR(" Z"));
  622. if (custom_message_type == 1) {
  623. // In a bed calibration mode.
  624. lcd_printPGM(PSTR(" --- "));
  625. } else {
  626. lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
  627. lcd.print(' ');
  628. }
  629. #else
  630. lcd_printPGM(PSTR(" Queue:"));
  631. lcd.print(int(moves_planned()));
  632. lcd.print(' ');
  633. #endif
  634. //Print the Bedtemperature
  635. lcd.setCursor(0, 1);
  636. tHotend=int(degBed() + 0.5);
  637. tTarget=int(degTargetBed() + 0.5);
  638. lcd.print(LCD_STR_BEDTEMP[0]);
  639. lcd.print(itostr3(tHotend));
  640. lcd.print('/');
  641. lcd.print(itostr3left(tTarget));
  642. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  643. lcd_printPGM(PSTR(" "));
  644. #if 1
  645. //Print Feedrate
  646. lcd.setCursor(LCD_WIDTH - 8-2, 1);
  647. lcd_printPGM(PSTR(" "));
  648. lcd.print(LCD_STR_FEEDRATE[0]);
  649. lcd.print(itostr3(feedmultiply));
  650. lcd_printPGM(PSTR("% "));
  651. #else
  652. //Print Feedrate
  653. lcd.setCursor(LCD_WIDTH - 8-2, 1);
  654. lcd.print(LCD_STR_FEEDRATE[0]);
  655. lcd.print(itostr3(feedmultiply));
  656. lcd_printPGM(PSTR("% Q"));
  657. {
  658. uint8_t queue = planner_queue_min();
  659. if (queue < (BLOCK_BUFFER_SIZE >> 1)) {
  660. lcd.print('!');
  661. } else {
  662. lcd.print((char)(queue / 10) + '0');
  663. queue %= 10;
  664. }
  665. lcd.print((char)queue + '0');
  666. planner_queue_min_reset();
  667. }
  668. #endif
  669. //Print SD status
  670. lcd.setCursor(0, 2);
  671. if (is_usb_printing)
  672. {
  673. lcd_printPGM(PSTR("--"));
  674. }
  675. else
  676. {
  677. lcd_printPGM(PSTR("SD"));
  678. }
  679. if (IS_SD_PRINTING)
  680. {
  681. lcd.print(itostr3(card.percentDone()));
  682. lcd.print('%');
  683. }
  684. else
  685. {
  686. if (is_usb_printing)
  687. {
  688. lcd_printPGM(PSTR(">USB"));
  689. }
  690. else
  691. {
  692. lcd_printPGM(PSTR("---"));
  693. lcd.print('%');
  694. }
  695. }
  696. // Farm number display
  697. if (farm_mode)
  698. {
  699. lcd_printPGM(PSTR(" F"));
  700. lcd.print(farm_no);
  701. lcd_printPGM(PSTR(" "));
  702. // Beat display
  703. lcd.setCursor(LCD_WIDTH - 1, 0);
  704. if ( (millis() - kicktime) < 60000 ) {
  705. lcd_printPGM(PSTR("L"));
  706. }else{
  707. lcd_printPGM(PSTR(" "));
  708. }
  709. }
  710. else {
  711. #ifdef SNMM
  712. lcd_printPGM(PSTR(" E"));
  713. lcd.print(get_ext_nr() + 1);
  714. #else
  715. lcd.setCursor(LCD_WIDTH - 8 - 2, 2);
  716. lcd_printPGM(PSTR(" "));
  717. #endif
  718. }
  719. //Print time elapsed
  720. lcd.setCursor(LCD_WIDTH - 8 -1, 2);
  721. lcd_printPGM(PSTR(" "));
  722. lcd.print(LCD_STR_CLOCK[0]);
  723. if(starttime != 0)
  724. {
  725. uint16_t time = millis() / 60000 - starttime / 60000;
  726. lcd.print(itostr2(time/60));
  727. lcd.print(':');
  728. lcd.print(itostr2(time%60));
  729. }else{
  730. lcd_printPGM(PSTR("--:--"));
  731. }
  732. lcd_printPGM(PSTR(" "));
  733. #ifdef DEBUG_DISABLE_LCD_STATUS_LINE
  734. return;
  735. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  736. //Print status line
  737. lcd.setCursor(0, 3);
  738. // If heating in progress, set flag
  739. if (heating_status != 0) { custom_message = true; }
  740. if (IS_SD_PRINTING) {
  741. if (strcmp(longFilenameOLD, card.longFilename) != 0)
  742. {
  743. memset(longFilenameOLD, '\0', strlen(longFilenameOLD));
  744. sprintf_P(longFilenameOLD, PSTR("%s"), card.longFilename);
  745. scrollstuff = 0;
  746. }
  747. }
  748. // If printing from SD, show what we are printing
  749. if (IS_SD_PRINTING && !custom_message)
  750. {
  751. if (strlen(card.longFilename) > LCD_WIDTH)
  752. {
  753. int inters = 0;
  754. int gh = scrollstuff;
  755. while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0))
  756. {
  757. if (card.longFilename[gh] == '\0')
  758. {
  759. lcd.setCursor(gh - scrollstuff, 3);
  760. lcd.print(card.longFilename[gh - 1]);
  761. scrollstuff = 0;
  762. gh = scrollstuff;
  763. inters = 1;
  764. }
  765. else
  766. {
  767. lcd.setCursor(gh - scrollstuff, 3);
  768. lcd.print(card.longFilename[gh - 1]);
  769. gh++;
  770. }
  771. }
  772. scrollstuff++;
  773. }
  774. else
  775. {
  776. lcd.print(longFilenameOLD);
  777. }
  778. }
  779. // If not, check for other special events
  780. else
  781. {
  782. if (custom_message)
  783. {
  784. // If heating flag, show progress of heating.
  785. if (heating_status != 0)
  786. {
  787. heating_status_counter++;
  788. if (heating_status_counter > 13)
  789. {
  790. heating_status_counter = 0;
  791. }
  792. lcd.setCursor(7, 3);
  793. lcd_printPGM(PSTR(" "));
  794. for (uint16_t dots = 0; dots < heating_status_counter; dots++)
  795. {
  796. lcd.setCursor(7 + dots, 3);
  797. lcd.print('.');
  798. }
  799. switch (heating_status)
  800. {
  801. case 1:
  802. lcd.setCursor(0, 3);
  803. lcd_printPGM(MSG_HEATING);
  804. break;
  805. case 2:
  806. lcd.setCursor(0, 3);
  807. lcd_printPGM(MSG_HEATING_COMPLETE);
  808. heating_status = 0;
  809. heating_status_counter = 0;
  810. custom_message = false;
  811. break;
  812. case 3:
  813. lcd.setCursor(0, 3);
  814. lcd_printPGM(MSG_BED_HEATING);
  815. break;
  816. case 4:
  817. lcd.setCursor(0, 3);
  818. lcd_printPGM(MSG_BED_DONE);
  819. heating_status = 0;
  820. heating_status_counter = 0;
  821. custom_message = false;
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. // If mesh bed leveling in progress, show the status
  828. if (custom_message_type == 1)
  829. {
  830. if (custom_message_state > 10)
  831. {
  832. lcd.setCursor(0, 3);
  833. lcd_printPGM(PSTR(" "));
  834. lcd.setCursor(0, 3);
  835. lcd_printPGM(MSG_HOMEYZ_PROGRESS);
  836. lcd_printPGM(PSTR(" : "));
  837. lcd.print(custom_message_state-10);
  838. }
  839. else
  840. {
  841. if (custom_message_state == 3)
  842. {
  843. lcd_printPGM(WELCOME_MSG);
  844. lcd_setstatuspgm(WELCOME_MSG);
  845. custom_message = false;
  846. custom_message_type = 0;
  847. }
  848. if (custom_message_state > 3 && custom_message_state <= 10 )
  849. {
  850. lcd.setCursor(0, 3);
  851. lcd_printPGM(PSTR(" "));
  852. lcd.setCursor(0, 3);
  853. lcd_printPGM(MSG_HOMEYZ_DONE);
  854. custom_message_state--;
  855. }
  856. }
  857. }
  858. // If loading filament, print status
  859. if (custom_message_type == 2)
  860. {
  861. lcd.print(lcd_status_message);
  862. }
  863. // PID tuning in progress
  864. if (custom_message_type == 3) {
  865. lcd.print(lcd_status_message);
  866. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) {
  867. lcd.setCursor(10, 3);
  868. lcd.print(itostr3(pid_cycle));
  869. lcd.print('/');
  870. lcd.print(itostr3left(pid_number_of_cycles));
  871. }
  872. }
  873. // PINDA temp calibration in progress
  874. if (custom_message_type == 4) {
  875. char progress[4];
  876. lcd.setCursor(0, 3);
  877. lcd_printPGM(MSG_TEMP_CALIBRATION);
  878. lcd.setCursor(12, 3);
  879. sprintf(progress, "%d/6", custom_message_state);
  880. lcd.print(progress);
  881. }
  882. // temp compensation preheat
  883. if (custom_message_type == 5) {
  884. lcd.setCursor(0, 3);
  885. lcd_printPGM(MSG_PINDA_PREHEAT);
  886. if (custom_message_state <= PINDA_HEAT_T) {
  887. lcd_printPGM(PSTR(": "));
  888. lcd.print(custom_message_state); //seconds
  889. lcd.print(' ');
  890. }
  891. }
  892. }
  893. else
  894. {
  895. // Nothing special, print status message normally
  896. lcd.print(lcd_status_message);
  897. }
  898. }
  899. // Fill the rest of line to have nice and clean output
  900. for(int fillspace = 0; fillspace<20;fillspace++)
  901. {
  902. if((lcd_status_message[fillspace] > 31 ))
  903. {
  904. }
  905. else
  906. {
  907. lcd.print(' ');
  908. }
  909. }
  910. }
  911. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  912. {
  913. char c;
  914. //Use all characters in narrow LCDs
  915. #if LCD_WIDTH < 20
  916. uint8_t n = LCD_WIDTH - 1 - 1;
  917. #else
  918. uint8_t n = LCD_WIDTH - 1 - 2;
  919. #endif
  920. lcd.setCursor(0, row);
  921. lcd.print(pre_char);
  922. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  923. {
  924. lcd.print(c);
  925. pstr++;
  926. n--;
  927. }
  928. while(n--)
  929. lcd.print(' ');
  930. lcd.print(post_char);
  931. lcd.print(' ');
  932. }
  933. static void lcd_implementation_drawmenu_generic_RAM(uint8_t row, const char* str, char pre_char, char post_char)
  934. {
  935. char c;
  936. //Use all characters in narrow LCDs
  937. #if LCD_WIDTH < 20
  938. uint8_t n = LCD_WIDTH - 1 - 1;
  939. #else
  940. uint8_t n = LCD_WIDTH - 1 - 2;
  941. #endif
  942. lcd.setCursor(0, row);
  943. lcd.print(pre_char);
  944. while( ((c = *str) != '\0') && (n>0) )
  945. {
  946. lcd.print(c);
  947. str++;
  948. n--;
  949. }
  950. while(n--)
  951. lcd.print(' ');
  952. lcd.print(post_char);
  953. lcd.print(' ');
  954. }
  955. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  956. {
  957. char c;
  958. //Use all characters in narrow LCDs
  959. #if LCD_WIDTH < 20
  960. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  961. #else
  962. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  963. #endif
  964. lcd.setCursor(0, row);
  965. lcd.print(pre_char);
  966. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  967. {
  968. lcd.print(c);
  969. pstr++;
  970. n--;
  971. }
  972. lcd.print(':');
  973. while(n--)
  974. lcd.print(' ');
  975. lcd.print(data);
  976. }
  977. #if 0
  978. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  979. {
  980. char c;
  981. //Use all characters in narrow LCDs
  982. #if LCD_WIDTH < 20
  983. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  984. #else
  985. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  986. #endif
  987. lcd.setCursor(0, row);
  988. lcd.print(pre_char);
  989. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  990. {
  991. lcd.print(c);
  992. pstr++;
  993. n--;
  994. }
  995. lcd.print(':');
  996. while(n--)
  997. lcd.print(' ');
  998. lcd_printPGM(data);
  999. }
  1000. #endif
  1001. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  1002. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  1003. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  1004. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  1005. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  1006. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  1007. #define lcd_implementation_drawmenu_setting_edit_float43_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr43(*(data)))
  1008. #define lcd_implementation_drawmenu_setting_edit_float43(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr43(*(data)))
  1009. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  1010. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  1011. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  1012. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  1013. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  1014. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  1015. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  1016. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  1017. #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))
  1018. #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))
  1019. //Add version for callback functions
  1020. #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)))
  1021. #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)))
  1022. #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)))
  1023. #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)))
  1024. #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)))
  1025. #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)))
  1026. #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)))
  1027. #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)))
  1028. #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)))
  1029. #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)))
  1030. #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)))
  1031. #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)))
  1032. #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)))
  1033. #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)))
  1034. #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)))
  1035. #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)))
  1036. #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))
  1037. #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))
  1038. void lcd_implementation_drawedit(const char* pstr, char* value)
  1039. {
  1040. lcd.setCursor(1, 1);
  1041. lcd_printPGM(pstr);
  1042. lcd.print(':');
  1043. #if LCD_WIDTH < 20
  1044. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  1045. #else
  1046. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  1047. #endif
  1048. lcd.print(value);
  1049. }
  1050. void lcd_implementation_drawedit_2(const char* pstr, char* value)
  1051. {
  1052. lcd.setCursor(0, 1);
  1053. lcd_printPGM(pstr);
  1054. lcd.print(':');
  1055. lcd.setCursor((LCD_WIDTH - strlen(value))/2, 3);
  1056. lcd.print(value);
  1057. lcd.print(" mm");
  1058. }
  1059. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1060. {
  1061. char c;
  1062. int enc_dif = encoderDiff;
  1063. uint8_t n = LCD_WIDTH - 1;
  1064. for(int g = 0; g<4;g++){
  1065. lcd.setCursor(0, g);
  1066. lcd.print(' ');
  1067. }
  1068. lcd.setCursor(0, row);
  1069. lcd.print('>');
  1070. int i = 1;
  1071. int j = 0;
  1072. char* longFilenameTMP = longFilename;
  1073. while((c = *longFilenameTMP) != '\0')
  1074. {
  1075. lcd.setCursor(i, row);
  1076. lcd.print(c);
  1077. i++;
  1078. longFilenameTMP++;
  1079. if(i==LCD_WIDTH) {
  1080. i=1;
  1081. j++;
  1082. longFilenameTMP = longFilename + j;
  1083. n = LCD_WIDTH - 1;
  1084. for(int g = 0; g<300 ;g++){
  1085. if(LCD_CLICKED || ( enc_dif != encoderDiff )){
  1086. longFilenameTMP = longFilename;
  1087. *(longFilenameTMP + LCD_WIDTH - 2) = '\0';
  1088. i = 1;
  1089. j = 0;
  1090. break;
  1091. }else{
  1092. if (j == 1) delay(3); //wait around 1.2 s to start scrolling text
  1093. delay(1); //then scroll with redrawing every 300 ms
  1094. }
  1095. }
  1096. }
  1097. }
  1098. if(c!='\0'){
  1099. lcd.setCursor(i, row);
  1100. lcd.print(c);
  1101. i++;
  1102. }
  1103. n=n-i+1;
  1104. while(n--)
  1105. lcd.print(' ');
  1106. }
  1107. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1108. {
  1109. char c;
  1110. uint8_t n = LCD_WIDTH - 1;
  1111. lcd.setCursor(0, row);
  1112. lcd.print(' ');
  1113. if (longFilename[0] != '\0')
  1114. {
  1115. filename = longFilename;
  1116. longFilename[LCD_WIDTH-1] = '\0';
  1117. }
  1118. while( ((c = *filename) != '\0') && (n>0) )
  1119. {
  1120. lcd.print(c);
  1121. filename++;
  1122. n--;
  1123. }
  1124. while(n--)
  1125. lcd.print(' ');
  1126. }
  1127. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1128. {
  1129. char c;
  1130. uint8_t n = LCD_WIDTH - 2;
  1131. lcd.setCursor(0, row);
  1132. lcd.print('>');
  1133. lcd.print(LCD_STR_FOLDER[0]);
  1134. if (longFilename[0] != '\0')
  1135. {
  1136. filename = longFilename;
  1137. longFilename[LCD_WIDTH-2] = '\0';
  1138. }
  1139. while( ((c = *filename) != '\0') && (n>0) )
  1140. {
  1141. lcd.print(c);
  1142. filename++;
  1143. n--;
  1144. }
  1145. while(n--)
  1146. lcd.print(' ');
  1147. }
  1148. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1149. {
  1150. char c;
  1151. uint8_t n = LCD_WIDTH - 2;
  1152. lcd.setCursor(0, row);
  1153. lcd.print(' ');
  1154. lcd.print(LCD_STR_FOLDER[0]);
  1155. if (longFilename[0] != '\0')
  1156. {
  1157. filename = longFilename;
  1158. longFilename[LCD_WIDTH-2] = '\0';
  1159. }
  1160. while( ((c = *filename) != '\0') && (n>0) )
  1161. {
  1162. lcd.print(c);
  1163. filename++;
  1164. n--;
  1165. }
  1166. while(n--)
  1167. lcd.print(' ');
  1168. }
  1169. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  1170. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  1171. #define lcd_implementation_drawmenu_back_RAM_selected(row, str, data) lcd_implementation_drawmenu_generic_RAM(row, str, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  1172. #define lcd_implementation_drawmenu_back_RAM(row, str, data) lcd_implementation_drawmenu_generic_RAM(row, str, ' ', LCD_STR_UPLEVEL[0])
  1173. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  1174. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  1175. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1176. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1177. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1178. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1179. #define lcd_implementation_drawmenu_setlang_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1180. #define lcd_implementation_drawmenu_setlang(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1181. static void lcd_implementation_quick_feedback()
  1182. {
  1183. #ifdef LCD_USE_I2C_BUZZER
  1184. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  1185. lcd_buzz(1000/6,100);
  1186. #else
  1187. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  1188. #endif
  1189. #elif defined(BEEPER) && BEEPER > -1
  1190. SET_OUTPUT(BEEPER);
  1191. Sound_MakeSound(e_SOUND_CLASS_Echo,e_SOUND_TYPE_ButtonEcho);
  1192. /*
  1193. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  1194. for(int8_t i=0;i<10;i++)
  1195. {
  1196. WRITE(BEEPER,HIGH);
  1197. delayMicroseconds(100);
  1198. WRITE(BEEPER,LOW);
  1199. delayMicroseconds(100);
  1200. }
  1201. #else
  1202. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  1203. {
  1204. WRITE(BEEPER,HIGH);
  1205. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  1206. WRITE(BEEPER,LOW);
  1207. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  1208. }
  1209. #endif
  1210. */
  1211. #endif
  1212. }
  1213. #ifdef LCD_HAS_STATUS_INDICATORS
  1214. static void lcd_implementation_update_indicators()
  1215. {
  1216. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  1217. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  1218. static uint8_t ledsprev = 0;
  1219. uint8_t leds = 0;
  1220. if (target_temperature_bed > 0) leds |= LED_A;
  1221. if (target_temperature[0] > 0) leds |= LED_B;
  1222. if (fanSpeed) leds |= LED_C;
  1223. #if EXTRUDERS > 1
  1224. if (target_temperature[1] > 0) leds |= LED_C;
  1225. #endif
  1226. if (leds != ledsprev) {
  1227. lcd.setBacklight(leds);
  1228. ledsprev = leds;
  1229. }
  1230. #endif
  1231. }
  1232. #endif
  1233. #ifdef LCD_HAS_SLOW_BUTTONS
  1234. extern uint32_t blocking_enc;
  1235. static uint8_t lcd_implementation_read_slow_buttons()
  1236. {
  1237. #ifdef LCD_I2C_TYPE_MCP23017
  1238. uint8_t slow_buttons;
  1239. // Reading these buttons this is likely to be too slow to call inside interrupt context
  1240. // so they are called during normal lcd_update
  1241. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  1242. #if defined(LCD_I2C_VIKI)
  1243. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  1244. if(blocking_enc > millis()) {
  1245. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  1246. }
  1247. }
  1248. #endif
  1249. return slow_buttons;
  1250. #endif
  1251. }
  1252. #endif
  1253. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H