ultralcd_implementation_hitachi_HD44780.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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. /**
  7. * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
  8. * When selecting the Russian language, a slightly different LCD implementation is used to handle UTF8 characters.
  9. **/
  10. #ifndef REPRAPWORLD_KEYPAD
  11. extern volatile uint8_t buttons; //the last checked buttons in a bit array.
  12. #else
  13. extern volatile uint16_t buttons; //an extended version of the last checked buttons in a bit array.
  14. #endif
  15. ////////////////////////////////////
  16. // Setup button and encode mappings for each panel (into 'buttons' variable
  17. //
  18. // This is just to map common functions (across different panels) onto the same
  19. // macro name. The mapping is independent of whether the button is directly connected or
  20. // via a shift/i2c register.
  21. #ifdef ULTIPANEL
  22. // All UltiPanels might have an encoder - so this is always be mapped onto first two bits
  23. #define BLEN_B 1
  24. #define BLEN_A 0
  25. #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
  26. #define EN_A (1<<BLEN_A)
  27. #if defined(BTN_ENC) && BTN_ENC > -1
  28. // encoder click is directly connected
  29. #define BLEN_C 2
  30. #define EN_C (1<<BLEN_C)
  31. #endif
  32. //
  33. // Setup other button mappings of each panel
  34. //
  35. #if defined(LCD_I2C_VIKI)
  36. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  37. // button and encoder bit positions within 'buttons'
  38. #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  39. #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
  40. #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
  41. #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
  42. #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
  43. #if defined(BTN_ENC) && BTN_ENC > -1
  44. // the pause/stop/restart button is connected to BTN_ENC when used
  45. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  46. #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
  47. #else
  48. #define LCD_CLICKED (buttons&(B_MI|B_RI))
  49. #endif
  50. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  51. #define LCD_HAS_SLOW_BUTTONS
  52. #elif defined(LCD_I2C_PANELOLU2)
  53. // encoder click can be read through I2C if not directly connected
  54. #if BTN_ENC <= 0
  55. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  56. #define B_MI (PANELOLU2_ENCODER_C<<B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  57. #define LCD_CLICKED (buttons&B_MI)
  58. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  59. #define LCD_HAS_SLOW_BUTTONS
  60. #else
  61. #define LCD_CLICKED (buttons&EN_C)
  62. #endif
  63. #elif defined(REPRAPWORLD_KEYPAD)
  64. // define register bit values, don't change it
  65. #define BLEN_REPRAPWORLD_KEYPAD_F3 0
  66. #define BLEN_REPRAPWORLD_KEYPAD_F2 1
  67. #define BLEN_REPRAPWORLD_KEYPAD_F1 2
  68. #define BLEN_REPRAPWORLD_KEYPAD_UP 3
  69. #define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4
  70. #define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5
  71. #define BLEN_REPRAPWORLD_KEYPAD_DOWN 6
  72. #define BLEN_REPRAPWORLD_KEYPAD_LEFT 7
  73. #define REPRAPWORLD_BTN_OFFSET 3 // bit offset into buttons for shift register values
  74. #define EN_REPRAPWORLD_KEYPAD_F3 (1<<(BLEN_REPRAPWORLD_KEYPAD_F3+REPRAPWORLD_BTN_OFFSET))
  75. #define EN_REPRAPWORLD_KEYPAD_F2 (1<<(BLEN_REPRAPWORLD_KEYPAD_F2+REPRAPWORLD_BTN_OFFSET))
  76. #define EN_REPRAPWORLD_KEYPAD_F1 (1<<(BLEN_REPRAPWORLD_KEYPAD_F1+REPRAPWORLD_BTN_OFFSET))
  77. #define EN_REPRAPWORLD_KEYPAD_UP (1<<(BLEN_REPRAPWORLD_KEYPAD_UP+REPRAPWORLD_BTN_OFFSET))
  78. #define EN_REPRAPWORLD_KEYPAD_RIGHT (1<<(BLEN_REPRAPWORLD_KEYPAD_RIGHT+REPRAPWORLD_BTN_OFFSET))
  79. #define EN_REPRAPWORLD_KEYPAD_MIDDLE (1<<(BLEN_REPRAPWORLD_KEYPAD_MIDDLE+REPRAPWORLD_BTN_OFFSET))
  80. #define EN_REPRAPWORLD_KEYPAD_DOWN (1<<(BLEN_REPRAPWORLD_KEYPAD_DOWN+REPRAPWORLD_BTN_OFFSET))
  81. #define EN_REPRAPWORLD_KEYPAD_LEFT (1<<(BLEN_REPRAPWORLD_KEYPAD_LEFT+REPRAPWORLD_BTN_OFFSET))
  82. #define LCD_CLICKED ((buttons&EN_C) || (buttons&EN_REPRAPWORLD_KEYPAD_F1))
  83. #define REPRAPWORLD_KEYPAD_MOVE_Y_DOWN (buttons&EN_REPRAPWORLD_KEYPAD_DOWN)
  84. #define REPRAPWORLD_KEYPAD_MOVE_Y_UP (buttons&EN_REPRAPWORLD_KEYPAD_UP)
  85. #define REPRAPWORLD_KEYPAD_MOVE_HOME (buttons&EN_REPRAPWORLD_KEYPAD_MIDDLE)
  86. #elif defined(NEWPANEL)
  87. #define LCD_CLICKED (buttons&EN_C)
  88. #else // old style ULTIPANEL
  89. //bits in the shift register that carry the buttons for:
  90. // left up center down right red(stop)
  91. #define BL_LE 7
  92. #define BL_UP 6
  93. #define BL_MI 5
  94. #define BL_DW 4
  95. #define BL_RI 3
  96. #define BL_ST 2
  97. //automatic, do not change
  98. #define B_LE (1<<BL_LE)
  99. #define B_UP (1<<BL_UP)
  100. #define B_MI (1<<BL_MI)
  101. #define B_DW (1<<BL_DW)
  102. #define B_RI (1<<BL_RI)
  103. #define B_ST (1<<BL_ST)
  104. #define LCD_CLICKED (buttons&(B_MI|B_ST))
  105. #endif
  106. ////////////////////////
  107. // Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  108. // These values are independent of which pins are used for EN_A and EN_B indications
  109. // The rotary encoder part is also independent to the chipset used for the LCD
  110. #if defined(EN_A) && defined(EN_B)
  111. #define encrot0 0
  112. #define encrot1 2
  113. #define encrot2 3
  114. #define encrot3 1
  115. #endif
  116. #endif //ULTIPANEL
  117. ////////////////////////////////////
  118. // Create LCD class instance and chipset-specific information
  119. #if defined(LCD_I2C_TYPE_PCF8575)
  120. // note: these are register mapped pins on the PCF8575 controller not Arduino pins
  121. #define LCD_I2C_PIN_BL 3
  122. #define LCD_I2C_PIN_EN 2
  123. #define LCD_I2C_PIN_RW 1
  124. #define LCD_I2C_PIN_RS 0
  125. #define LCD_I2C_PIN_D4 4
  126. #define LCD_I2C_PIN_D5 5
  127. #define LCD_I2C_PIN_D6 6
  128. #define LCD_I2C_PIN_D7 7
  129. #include <Wire.h>
  130. #include <LCD.h>
  131. #include <LiquidCrystal_I2C.h>
  132. #define LCD_CLASS LiquidCrystal_I2C
  133. 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);
  134. #elif defined(LCD_I2C_TYPE_MCP23017)
  135. //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
  136. #define LED_A 0x04 //100
  137. #define LED_B 0x02 //010
  138. #define LED_C 0x01 //001
  139. #define LCD_HAS_STATUS_INDICATORS
  140. #include <Wire.h>
  141. #include <LiquidTWI2.h>
  142. #define LCD_CLASS LiquidTWI2
  143. #if defined(DETECT_DEVICE)
  144. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  145. #else
  146. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  147. #endif
  148. #elif defined(LCD_I2C_TYPE_MCP23008)
  149. #include <Wire.h>
  150. #include <LiquidTWI2.h>
  151. #define LCD_CLASS LiquidTWI2
  152. #if defined(DETECT_DEVICE)
  153. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  154. #else
  155. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  156. #endif
  157. #elif defined(LCD_I2C_TYPE_PCA8574)
  158. #include <LiquidCrystal_I2C.h>
  159. #define LCD_CLASS LiquidCrystal_I2C
  160. LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
  161. // 2 wire Non-latching LCD SR from:
  162. // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
  163. #elif defined(SR_LCD_2W_NL)
  164. extern "C" void __cxa_pure_virtual() { while (1); }
  165. #include <LCD.h>
  166. #include <LiquidCrystal_SR.h>
  167. #define LCD_CLASS LiquidCrystal_SR
  168. LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN);
  169. #else
  170. // Standard directly connected LCD implementations
  171. #ifdef LANGUAGE_RU
  172. #include "LiquidCrystalRus.h"
  173. #define LCD_CLASS LiquidCrystalRus
  174. #else
  175. #include "LiquidCrystal.h"
  176. #define LCD_CLASS LiquidCrystal
  177. #endif
  178. 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
  179. #endif
  180. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  181. static uint16_t progressBarTick = 0;
  182. #if PROGRESS_MSG_EXPIRE > 0
  183. static uint16_t messageTick = 0;
  184. #endif
  185. #define LCD_STR_PROGRESS "\x03\x04\x05"
  186. #endif
  187. /* Custom characters defined in the first 8 characters of the LCD */
  188. #define LCD_STR_BEDTEMP "\x00"
  189. #define LCD_STR_DEGREE "\x01"
  190. #define LCD_STR_THERMOMETER "\x02"
  191. #define LCD_STR_UPLEVEL "\x03"
  192. #define LCD_STR_REFRESH "\x04"
  193. #define LCD_STR_FOLDER "\x05"
  194. #define LCD_STR_FEEDRATE "\x06"
  195. #define LCD_STR_CLOCK "\x07"
  196. #define LCD_STR_ARROW_UP "\x0B"
  197. #define LCD_STR_ARROW_DOWN "\x01"
  198. #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */
  199. static void lcd_set_custom_characters(
  200. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  201. bool progress_bar_set=true
  202. #endif
  203. ) {
  204. byte bedTemp[8] = {
  205. B00000,
  206. B11111,
  207. B10101,
  208. B10001,
  209. B10101,
  210. B11111,
  211. B00000,
  212. B00000
  213. }; //thanks Sonny Mounicou
  214. byte degree[8] = {
  215. B01100,
  216. B10010,
  217. B10010,
  218. B01100,
  219. B00000,
  220. B00000,
  221. B00000,
  222. B00000
  223. };
  224. byte thermometer[8] = {
  225. B00100,
  226. B01010,
  227. B01010,
  228. B01010,
  229. B01010,
  230. B10001,
  231. B10001,
  232. B01110
  233. };
  234. byte uplevel[8] = {
  235. B00100,
  236. B01110,
  237. B11111,
  238. B00100,
  239. B11100,
  240. B00000,
  241. B00000,
  242. B00000
  243. }; //thanks joris
  244. byte refresh[8] = {
  245. B00000,
  246. B00110,
  247. B11001,
  248. B11000,
  249. B00011,
  250. B10011,
  251. B01100,
  252. B00000,
  253. }; //thanks joris
  254. byte folder[8] = {
  255. B00000,
  256. B11100,
  257. B11111,
  258. B10001,
  259. B10001,
  260. B11111,
  261. B00000,
  262. B00000
  263. }; //thanks joris
  264. #ifdef LANGUAGE_EN_H
  265. byte feedrate[8] = {
  266. B11100,
  267. B10000,
  268. B11000,
  269. B10111,
  270. B00101,
  271. B00110,
  272. B00101,
  273. B00000
  274. }; //thanks Sonny Mounicou
  275. #else
  276. /*
  277. byte feedrate[8] = {
  278. B11100,
  279. B10100,
  280. B11000,
  281. B10100,
  282. B00000,
  283. B00111,
  284. B00010,
  285. B00010
  286. };
  287. */
  288. /*
  289. byte feedrate[8] = {
  290. B01100,
  291. B10011,
  292. B00000,
  293. B01100,
  294. B10011,
  295. B00000,
  296. B01100,
  297. B10011
  298. };
  299. */
  300. byte feedrate[8] = {
  301. B00000,
  302. B00100,
  303. B10010,
  304. B01001,
  305. B10010,
  306. B00100,
  307. B00000,
  308. B00000
  309. };
  310. #endif
  311. byte clock[8] = {
  312. B00000,
  313. B01110,
  314. B10011,
  315. B10101,
  316. B10001,
  317. B01110,
  318. B00000,
  319. B00000
  320. }; //thanks Sonny Mounicou
  321. byte arrup[8] = {
  322. B00100,
  323. B01110,
  324. B11111,
  325. B00000,
  326. B00000,
  327. B00000,
  328. B00000,
  329. B00000
  330. };
  331. byte arrdown[8] = {
  332. B00000,
  333. B00000,
  334. B00000,
  335. B00000,
  336. B00000,
  337. B10001,
  338. B01010,
  339. B00100
  340. };
  341. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  342. static bool char_mode = false;
  343. byte progress[3][8] = { {
  344. B00000,
  345. B10000,
  346. B10000,
  347. B10000,
  348. B10000,
  349. B10000,
  350. B10000,
  351. B00000
  352. }, {
  353. B00000,
  354. B10100,
  355. B10100,
  356. B10100,
  357. B10100,
  358. B10100,
  359. B10100,
  360. B00000
  361. }, {
  362. B00000,
  363. B10101,
  364. B10101,
  365. B10101,
  366. B10101,
  367. B10101,
  368. B10101,
  369. B00000
  370. } };
  371. if (progress_bar_set != char_mode) {
  372. char_mode = progress_bar_set;
  373. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  374. lcd.createChar(LCD_STR_DEGREE[0], degree);
  375. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  376. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  377. lcd.createChar(LCD_STR_CLOCK[0], clock);
  378. if (progress_bar_set) {
  379. // Progress bar characters for info screen
  380. for (int i=3; i--;) lcd.createChar(LCD_STR_PROGRESS[i], progress[i]);
  381. }
  382. else {
  383. // Custom characters for submenus
  384. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  385. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  386. lcd.createChar(LCD_STR_FOLDER[0], folder);
  387. }
  388. }
  389. #else
  390. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  391. lcd.createChar(LCD_STR_DEGREE[0], degree);
  392. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  393. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  394. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  395. lcd.createChar(LCD_STR_FOLDER[0], folder);
  396. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  397. lcd.createChar(LCD_STR_CLOCK[0], clock);
  398. //lcd.createChar(LCD_STR_ARROW_UP[0], arrup);
  399. //lcd.createChar(LCD_STR_ARROW_DOWN[0], arrdown);
  400. #endif
  401. }
  402. void lcd_set_custom_characters_arrows()
  403. {
  404. byte arrdown[8] = {
  405. B00000,
  406. B00000,
  407. B00000,
  408. B00000,
  409. B00000,
  410. B10001,
  411. B01010,
  412. B00100
  413. };
  414. lcd.createChar(1, arrdown);
  415. }
  416. void lcd_set_custom_characters_degree()
  417. {
  418. byte degree[8] = {
  419. B01100,
  420. B10010,
  421. B10010,
  422. B01100,
  423. B00000,
  424. B00000,
  425. B00000,
  426. B00000
  427. };
  428. lcd.createChar(1, degree);
  429. }
  430. static void lcd_implementation_init(
  431. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  432. bool progress_bar_set=true
  433. #endif
  434. ) {
  435. #if defined(LCD_I2C_TYPE_PCF8575)
  436. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  437. #ifdef LCD_I2C_PIN_BL
  438. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  439. lcd.setBacklight(HIGH);
  440. #endif
  441. #elif defined(LCD_I2C_TYPE_MCP23017)
  442. lcd.setMCPType(LTI_TYPE_MCP23017);
  443. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  444. lcd.setBacklight(0); //set all the LEDs off to begin with
  445. #elif defined(LCD_I2C_TYPE_MCP23008)
  446. lcd.setMCPType(LTI_TYPE_MCP23008);
  447. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  448. #elif defined(LCD_I2C_TYPE_PCA8574)
  449. lcd.init();
  450. lcd.backlight();
  451. #else
  452. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  453. #endif
  454. lcd_set_custom_characters(
  455. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  456. progress_bar_set
  457. #endif
  458. );
  459. lcd.clear();
  460. }
  461. static void lcd_implementation_init_noclear(
  462. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  463. bool progress_bar_set=true
  464. #endif
  465. ) {
  466. #if defined(LCD_I2C_TYPE_PCF8575)
  467. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  468. #ifdef LCD_I2C_PIN_BL
  469. lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
  470. lcd.setBacklight(HIGH);
  471. #endif
  472. #elif defined(LCD_I2C_TYPE_MCP23017)
  473. lcd.setMCPType(LTI_TYPE_MCP23017);
  474. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  475. lcd.setBacklight(0); //set all the LEDs off to begin with
  476. #elif defined(LCD_I2C_TYPE_MCP23008)
  477. lcd.setMCPType(LTI_TYPE_MCP23008);
  478. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  479. #elif defined(LCD_I2C_TYPE_PCA8574)
  480. lcd.init();
  481. lcd.backlight();
  482. #else
  483. lcd.begin_noclear(LCD_WIDTH, LCD_HEIGHT);
  484. #endif
  485. lcd_set_custom_characters(
  486. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  487. progress_bar_set
  488. #endif
  489. );
  490. }
  491. static void lcd_implementation_nodisplay()
  492. {
  493. lcd.noDisplay();
  494. }
  495. static void lcd_implementation_display()
  496. {
  497. lcd.display();
  498. }
  499. static void lcd_implementation_clear()
  500. {
  501. lcd.clear();
  502. }
  503. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  504. static void lcd_printPGM(const char* str)
  505. {
  506. char c;
  507. while((c = pgm_read_byte(str++)) != '\0')
  508. {
  509. lcd.write(c);
  510. }
  511. }
  512. /*
  513. 20x4 |01234567890123456789|
  514. |T 000/000D Z000.0 |
  515. |B 000/000D F100% |
  516. |SD100% T--:-- |
  517. |Status line.........|
  518. */
  519. static void lcd_implementation_status_screen()
  520. {
  521. int tHotend=int(degHotend(0) + 0.5);
  522. int tTarget=int(degTargetHotend(0) + 0.5);
  523. //Print the hotend temperature
  524. lcd.setCursor(0, 0);
  525. lcd.print(LCD_STR_THERMOMETER[0]);
  526. lcd.print(itostr3(tHotend));
  527. lcd.print('/');
  528. lcd.print(itostr3left(tTarget));
  529. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  530. lcd.print(" ");
  531. //Print the Z coordinates
  532. lcd.setCursor(LCD_WIDTH - 8-2, 0);
  533. lcd.print(" Z");
  534. lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
  535. lcd.print(' ');
  536. //Print the Bedtemperature
  537. lcd.setCursor(0, 1);
  538. tHotend=int(degBed() + 0.5);
  539. tTarget=int(degTargetBed() + 0.5);
  540. lcd.print(LCD_STR_BEDTEMP[0]);
  541. lcd.print(itostr3(tHotend));
  542. lcd.print('/');
  543. lcd.print(itostr3left(tTarget));
  544. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  545. lcd.print(" ");
  546. //Print Feedrate
  547. lcd.setCursor(LCD_WIDTH - 8-2, 1);
  548. lcd.print(" ");
  549. lcd.print(LCD_STR_FEEDRATE[0]);
  550. lcd.print(itostr3(feedmultiply));
  551. lcd.print('%');
  552. lcd.print(" ");
  553. //Print SD status
  554. lcd.setCursor(0, 2);
  555. lcd_printPGM(PSTR("SD"));
  556. if (IS_SD_PRINTING)
  557. lcd.print(itostr3(card.percentDone()));
  558. else
  559. lcd_printPGM(PSTR("---"));
  560. lcd.print('%');
  561. lcd.print(" ");
  562. //Print time elapsed
  563. lcd.setCursor(LCD_WIDTH - 8 -2, 2);
  564. lcd.print(" ");
  565. lcd.print(LCD_STR_CLOCK[0]);
  566. if(starttime != 0)
  567. {
  568. uint16_t time = millis()/60000 - starttime/60000;
  569. lcd.print(itostr2(time/60));
  570. lcd.print(':');
  571. lcd.print(itostr2(time%60));
  572. }else{
  573. lcd_printPGM(PSTR("--:--"));
  574. }
  575. lcd.print(" ");
  576. //Print status line
  577. lcd.setCursor(0, 3);
  578. if(strcmp(lcd_status_message, "SD-PRINTING ") == 0){
  579. if(strcmp(longFilenameOLD, card.longFilename) != 0){
  580. memset(longFilenameOLD,'\0',strlen(longFilenameOLD));
  581. sprintf(longFilenameOLD, "%s", card.longFilename);
  582. scrollstuff = 0;
  583. }
  584. if(strlen(card.longFilename) > LCD_WIDTH){
  585. int inters = 0;
  586. int gh = scrollstuff;
  587. while( ((gh-scrollstuff)<LCD_WIDTH) && (inters == 0) ){
  588. if(card.longFilename[gh] == '\0'){
  589. lcd.setCursor(gh-scrollstuff, 3);
  590. lcd.print(card.longFilename[gh-1]);
  591. scrollstuff = 0;
  592. gh = scrollstuff;
  593. inters = 1;
  594. }else{
  595. lcd.setCursor(gh-scrollstuff, 3);
  596. lcd.print(card.longFilename[gh-1]);
  597. gh++;
  598. }
  599. }
  600. scrollstuff++;
  601. }else{
  602. lcd.print(longFilenameOLD);
  603. }
  604. }else{
  605. lcd.print(lcd_status_message);
  606. }
  607. for(int fillspace = 0; fillspace<20;fillspace++){
  608. if((lcd_status_message[fillspace] > 31 )){
  609. }else{
  610. lcd.print(' ');
  611. }
  612. }
  613. }
  614. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  615. {
  616. char c;
  617. //Use all characters in narrow LCDs
  618. #if LCD_WIDTH < 20
  619. uint8_t n = LCD_WIDTH - 1 - 1;
  620. #else
  621. uint8_t n = LCD_WIDTH - 1 - 2;
  622. #endif
  623. lcd.setCursor(0, row);
  624. lcd.print(pre_char);
  625. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  626. {
  627. lcd.print(c);
  628. pstr++;
  629. n--;
  630. }
  631. while(n--)
  632. lcd.print(' ');
  633. lcd.print(post_char);
  634. lcd.print(' ');
  635. }
  636. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  637. {
  638. char c;
  639. //Use all characters in narrow LCDs
  640. #if LCD_WIDTH < 20
  641. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  642. #else
  643. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  644. #endif
  645. lcd.setCursor(0, row);
  646. lcd.print(pre_char);
  647. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  648. {
  649. lcd.print(c);
  650. pstr++;
  651. n--;
  652. }
  653. lcd.print(':');
  654. while(n--)
  655. lcd.print(' ');
  656. lcd.print(data);
  657. }
  658. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  659. {
  660. char c;
  661. //Use all characters in narrow LCDs
  662. #if LCD_WIDTH < 20
  663. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  664. #else
  665. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  666. #endif
  667. lcd.setCursor(0, row);
  668. lcd.print(pre_char);
  669. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  670. {
  671. lcd.print(c);
  672. pstr++;
  673. n--;
  674. }
  675. lcd.print(':');
  676. while(n--)
  677. lcd.print(' ');
  678. lcd_printPGM(data);
  679. }
  680. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  681. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  682. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  683. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  684. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  685. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  686. #define lcd_implementation_drawmenu_setting_edit_float43_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr43(*(data)))
  687. #define lcd_implementation_drawmenu_setting_edit_float43(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr43(*(data)))
  688. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  689. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  690. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  691. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  692. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  693. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  694. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  695. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  696. #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))
  697. #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))
  698. //Add version for callback functions
  699. #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)))
  700. #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)))
  701. #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)))
  702. #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)))
  703. #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)))
  704. #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)))
  705. #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)))
  706. #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)))
  707. #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)))
  708. #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)))
  709. #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)))
  710. #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)))
  711. #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)))
  712. #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)))
  713. #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)))
  714. #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)))
  715. #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))
  716. #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))
  717. void lcd_implementation_drawedit(const char* pstr, char* value)
  718. {
  719. lcd.setCursor(1, 1);
  720. lcd_printPGM(pstr);
  721. lcd.print(':');
  722. #if LCD_WIDTH < 20
  723. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  724. #else
  725. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  726. #endif
  727. lcd.print(value);
  728. }
  729. void lcd_implementation_drawedit_2(const char* pstr, char* value)
  730. {
  731. lcd.setCursor(0, 1);
  732. lcd_printPGM(pstr);
  733. lcd.print(':');
  734. lcd.setCursor((LCD_WIDTH - strlen(value))/2, 3);
  735. lcd.print(value);
  736. lcd.print(" mm");
  737. }
  738. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  739. {
  740. char c;
  741. int enc_dif = encoderDiff;
  742. uint8_t n = LCD_WIDTH - 1;
  743. for(int g = 0; g<4;g++){
  744. lcd.setCursor(0, g);
  745. lcd.print(' ');
  746. }
  747. lcd.setCursor(0, row);
  748. lcd.print('>');
  749. if (longFilename[0] != '\0')
  750. {
  751. filename = longFilename;
  752. //longFilename[LCD_WIDTH-1] = '\0';
  753. }
  754. int i = 1;
  755. int j = 0;
  756. int inter = 0;
  757. char* longFilenameTMP = longFilename;
  758. while( ((c = *longFilenameTMP) != '\0') && (inter == 0) )
  759. {
  760. lcd.setCursor(i, row);
  761. lcd.print(c);
  762. i++;
  763. longFilenameTMP++;
  764. if(i==LCD_WIDTH){
  765. i=1;
  766. j++;
  767. longFilenameTMP = longFilename;
  768. longFilenameTMP = longFilenameTMP+j;
  769. n = LCD_WIDTH - 1;
  770. for(int g = 0; ((g<300)&&(inter == 0)) ;g++){
  771. if(LCD_CLICKED || ( enc_dif != encoderDiff )){
  772. // inter = 1;
  773. }else{
  774. delay(1);
  775. }
  776. }
  777. }
  778. }
  779. if(c!='\0'){
  780. lcd.setCursor(i, row);
  781. lcd.print(c);
  782. i++;
  783. }
  784. n=n-i+1;
  785. while(n--)
  786. lcd.print(' ');
  787. }
  788. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  789. {
  790. char c;
  791. uint8_t n = LCD_WIDTH - 1;
  792. lcd.setCursor(0, row);
  793. lcd.print(' ');
  794. if (longFilename[0] != '\0')
  795. {
  796. filename = longFilename;
  797. longFilename[LCD_WIDTH-1] = '\0';
  798. }
  799. while( ((c = *filename) != '\0') && (n>0) )
  800. {
  801. lcd.print(c);
  802. filename++;
  803. n--;
  804. }
  805. while(n--)
  806. lcd.print(' ');
  807. }
  808. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  809. {
  810. char c;
  811. uint8_t n = LCD_WIDTH - 2;
  812. lcd.setCursor(0, row);
  813. lcd.print('>');
  814. lcd.print(LCD_STR_FOLDER[0]);
  815. if (longFilename[0] != '\0')
  816. {
  817. filename = longFilename;
  818. longFilename[LCD_WIDTH-2] = '\0';
  819. }
  820. while( ((c = *filename) != '\0') && (n>0) )
  821. {
  822. lcd.print(c);
  823. filename++;
  824. n--;
  825. }
  826. while(n--)
  827. lcd.print(' ');
  828. }
  829. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  830. {
  831. char c;
  832. uint8_t n = LCD_WIDTH - 2;
  833. lcd.setCursor(0, row);
  834. lcd.print(' ');
  835. lcd.print(LCD_STR_FOLDER[0]);
  836. if (longFilename[0] != '\0')
  837. {
  838. filename = longFilename;
  839. longFilename[LCD_WIDTH-2] = '\0';
  840. }
  841. while( ((c = *filename) != '\0') && (n>0) )
  842. {
  843. lcd.print(c);
  844. filename++;
  845. n--;
  846. }
  847. while(n--)
  848. lcd.print(' ');
  849. }
  850. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  851. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  852. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  853. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  854. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  855. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  856. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  857. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  858. #define lcd_implementation_drawmenu_setlang_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  859. #define lcd_implementation_drawmenu_setlang(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  860. static void lcd_implementation_quick_feedback()
  861. {
  862. #ifdef LCD_USE_I2C_BUZZER
  863. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  864. lcd_buzz(1000/6,100);
  865. #else
  866. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  867. #endif
  868. #elif defined(BEEPER) && BEEPER > -1
  869. SET_OUTPUT(BEEPER);
  870. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  871. for(int8_t i=0;i<10;i++)
  872. {
  873. WRITE(BEEPER,HIGH);
  874. delayMicroseconds(100);
  875. WRITE(BEEPER,LOW);
  876. delayMicroseconds(100);
  877. }
  878. #else
  879. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  880. {
  881. WRITE(BEEPER,HIGH);
  882. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  883. WRITE(BEEPER,LOW);
  884. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  885. }
  886. #endif
  887. #endif
  888. }
  889. #ifdef LCD_HAS_STATUS_INDICATORS
  890. static void lcd_implementation_update_indicators()
  891. {
  892. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  893. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  894. static uint8_t ledsprev = 0;
  895. uint8_t leds = 0;
  896. if (target_temperature_bed > 0) leds |= LED_A;
  897. if (target_temperature[0] > 0) leds |= LED_B;
  898. if (fanSpeed) leds |= LED_C;
  899. #if EXTRUDERS > 1
  900. if (target_temperature[1] > 0) leds |= LED_C;
  901. #endif
  902. if (leds != ledsprev) {
  903. lcd.setBacklight(leds);
  904. ledsprev = leds;
  905. }
  906. #endif
  907. }
  908. #endif
  909. #ifdef LCD_HAS_SLOW_BUTTONS
  910. extern uint32_t blocking_enc;
  911. static uint8_t lcd_implementation_read_slow_buttons()
  912. {
  913. #ifdef LCD_I2C_TYPE_MCP23017
  914. uint8_t slow_buttons;
  915. // Reading these buttons this is likely to be too slow to call inside interrupt context
  916. // so they are called during normal lcd_update
  917. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  918. #if defined(LCD_I2C_VIKI)
  919. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  920. if(blocking_enc > millis()) {
  921. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  922. }
  923. }
  924. #endif
  925. return slow_buttons;
  926. #endif
  927. }
  928. #endif
  929. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H