ultralcd_implementation_hitachi_HD44780.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. }
  737. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  738. {
  739. char c;
  740. int enc_dif = encoderDiff;
  741. uint8_t n = LCD_WIDTH - 1;
  742. for(int g = 0; g<4;g++){
  743. lcd.setCursor(0, g);
  744. lcd.print(' ');
  745. }
  746. lcd.setCursor(0, row);
  747. lcd.print('>');
  748. if (longFilename[0] != '\0')
  749. {
  750. filename = longFilename;
  751. //longFilename[LCD_WIDTH-1] = '\0';
  752. }
  753. int i = 1;
  754. int j = 0;
  755. int inter = 0;
  756. char* longFilenameTMP = longFilename;
  757. while( ((c = *longFilenameTMP) != '\0') && (inter == 0) )
  758. {
  759. lcd.setCursor(i, row);
  760. lcd.print(c);
  761. i++;
  762. longFilenameTMP++;
  763. if(i==LCD_WIDTH){
  764. i=1;
  765. j++;
  766. longFilenameTMP = longFilename;
  767. longFilenameTMP = longFilenameTMP+j;
  768. n = LCD_WIDTH - 1;
  769. for(int g = 0; ((g<300)&&(inter == 0)) ;g++){
  770. if(LCD_CLICKED || ( enc_dif != encoderDiff )){
  771. // inter = 1;
  772. }else{
  773. delay(1);
  774. }
  775. }
  776. }
  777. }
  778. if(c!='\0'){
  779. lcd.setCursor(i, row);
  780. lcd.print(c);
  781. i++;
  782. }
  783. n=n-i+1;
  784. while(n--)
  785. lcd.print(' ');
  786. }
  787. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  788. {
  789. char c;
  790. uint8_t n = LCD_WIDTH - 1;
  791. lcd.setCursor(0, row);
  792. lcd.print(' ');
  793. if (longFilename[0] != '\0')
  794. {
  795. filename = longFilename;
  796. longFilename[LCD_WIDTH-1] = '\0';
  797. }
  798. while( ((c = *filename) != '\0') && (n>0) )
  799. {
  800. lcd.print(c);
  801. filename++;
  802. n--;
  803. }
  804. while(n--)
  805. lcd.print(' ');
  806. }
  807. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  808. {
  809. char c;
  810. uint8_t n = LCD_WIDTH - 2;
  811. lcd.setCursor(0, row);
  812. lcd.print('>');
  813. lcd.print(LCD_STR_FOLDER[0]);
  814. if (longFilename[0] != '\0')
  815. {
  816. filename = longFilename;
  817. longFilename[LCD_WIDTH-2] = '\0';
  818. }
  819. while( ((c = *filename) != '\0') && (n>0) )
  820. {
  821. lcd.print(c);
  822. filename++;
  823. n--;
  824. }
  825. while(n--)
  826. lcd.print(' ');
  827. }
  828. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  829. {
  830. char c;
  831. uint8_t n = LCD_WIDTH - 2;
  832. lcd.setCursor(0, row);
  833. lcd.print(' ');
  834. lcd.print(LCD_STR_FOLDER[0]);
  835. if (longFilename[0] != '\0')
  836. {
  837. filename = longFilename;
  838. longFilename[LCD_WIDTH-2] = '\0';
  839. }
  840. while( ((c = *filename) != '\0') && (n>0) )
  841. {
  842. lcd.print(c);
  843. filename++;
  844. n--;
  845. }
  846. while(n--)
  847. lcd.print(' ');
  848. }
  849. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  850. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  851. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  852. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  853. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  854. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  855. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  856. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  857. #define lcd_implementation_drawmenu_setlang_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  858. #define lcd_implementation_drawmenu_setlang(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  859. static void lcd_implementation_quick_feedback()
  860. {
  861. #ifdef LCD_USE_I2C_BUZZER
  862. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  863. lcd_buzz(1000/6,100);
  864. #else
  865. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  866. #endif
  867. #elif defined(BEEPER) && BEEPER > -1
  868. SET_OUTPUT(BEEPER);
  869. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  870. for(int8_t i=0;i<10;i++)
  871. {
  872. WRITE(BEEPER,HIGH);
  873. delayMicroseconds(100);
  874. WRITE(BEEPER,LOW);
  875. delayMicroseconds(100);
  876. }
  877. #else
  878. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  879. {
  880. WRITE(BEEPER,HIGH);
  881. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  882. WRITE(BEEPER,LOW);
  883. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  884. }
  885. #endif
  886. #endif
  887. }
  888. #ifdef LCD_HAS_STATUS_INDICATORS
  889. static void lcd_implementation_update_indicators()
  890. {
  891. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  892. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  893. static uint8_t ledsprev = 0;
  894. uint8_t leds = 0;
  895. if (target_temperature_bed > 0) leds |= LED_A;
  896. if (target_temperature[0] > 0) leds |= LED_B;
  897. if (fanSpeed) leds |= LED_C;
  898. #if EXTRUDERS > 1
  899. if (target_temperature[1] > 0) leds |= LED_C;
  900. #endif
  901. if (leds != ledsprev) {
  902. lcd.setBacklight(leds);
  903. ledsprev = leds;
  904. }
  905. #endif
  906. }
  907. #endif
  908. #ifdef LCD_HAS_SLOW_BUTTONS
  909. extern uint32_t blocking_enc;
  910. static uint8_t lcd_implementation_read_slow_buttons()
  911. {
  912. #ifdef LCD_I2C_TYPE_MCP23017
  913. uint8_t slow_buttons;
  914. // Reading these buttons this is likely to be too slow to call inside interrupt context
  915. // so they are called during normal lcd_update
  916. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  917. #if defined(LCD_I2C_VIKI)
  918. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  919. if(blocking_enc > millis()) {
  920. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  921. }
  922. }
  923. #endif
  924. return slow_buttons;
  925. #endif
  926. }
  927. #endif
  928. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H