ultralcd_implementation_hitachi_HD44780.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  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. static inline void lcd_print_percent_done() {
  600. if (is_usb_printing)
  601. {
  602. lcd_printPGM(PSTR("USB"));
  603. }
  604. else if(IS_SD_PRINTING)
  605. {
  606. lcd_printPGM(PSTR("SD"));
  607. }
  608. else
  609. {
  610. lcd_printPGM(PSTR(" "));
  611. }
  612. if (IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT)))
  613. {
  614. lcd.print(itostr3(print_percent_done()));
  615. }
  616. else
  617. {
  618. lcd_printPGM(PSTR("---"));
  619. }
  620. lcd.print('%');
  621. }
  622. static inline void lcd_print_time() {
  623. //if remaining print time estimation is available print it else print elapsed time
  624. //uses 8 characters
  625. uint16_t print_t = 0;
  626. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT){
  627. print_t = print_time_remaining();
  628. }
  629. else if(starttime != 0){
  630. print_t = millis() / 60000 - starttime / 60000;
  631. }
  632. uint16_t print_hours = print_t / 60;
  633. uint8_t print_minutes = print_t % 60;
  634. if((PRINTER_ACTIVE) && ((print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)||(starttime != 0)))
  635. {
  636. if (print_hours > 99) {
  637. if (print_hours > 999) print_hours = 999;
  638. lcd.print(itostr3(print_hours));
  639. }
  640. else {
  641. lcd.print(LCD_STR_CLOCK[0]);
  642. lcd.print(itostr2(print_hours));
  643. }
  644. lcd.print(':');
  645. lcd.print(itostr2(print_minutes));
  646. (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT) ? lcd.print('R') : lcd.print(' ');
  647. (feedmultiply == 100) ? lcd.print(' ') : lcd.print('?');
  648. }else{
  649. lcd.print(LCD_STR_CLOCK[0]);
  650. lcd_printPGM(PSTR("--:-- "));
  651. }
  652. }
  653. /*
  654. 20x4 |01234567890123456789|
  655. |T 000/000D Z000.0 |
  656. |B 000/000D F100% |
  657. |SD100% T--:-- |
  658. |Status line.........|
  659. */
  660. static void lcd_implementation_status_screen()
  661. {
  662. int tHotend=int(degHotend(0) + 0.5);
  663. int tTarget=int(degTargetHotend(0) + 0.5);
  664. //Print the hotend temperature
  665. lcd.setCursor(0, 0);
  666. lcd.print(LCD_STR_THERMOMETER[0]);
  667. lcd.print(itostr3(tHotend));
  668. lcd.print('/');
  669. lcd.print(itostr3left(tTarget));
  670. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  671. lcd_printPGM(PSTR(" "));
  672. //Print the Z coordinates
  673. lcd.setCursor(LCD_WIDTH - 8-2, 0);
  674. #if 1
  675. lcd_printPGM(PSTR(" Z"));
  676. if (custom_message_type == 1) {
  677. // In a bed calibration mode.
  678. lcd_printPGM(PSTR(" --- "));
  679. } else {
  680. lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
  681. lcd.print(' ');
  682. }
  683. #else
  684. lcd_printPGM(PSTR(" Queue:"));
  685. lcd.print(int(moves_planned()));
  686. lcd.print(' ');
  687. #endif
  688. //Print the Bedtemperature
  689. lcd.setCursor(0, 1);
  690. tHotend=int(degBed() + 0.5);
  691. tTarget=int(degTargetBed() + 0.5);
  692. lcd.print(LCD_STR_BEDTEMP[0]);
  693. lcd.print(itostr3(tHotend));
  694. lcd.print('/');
  695. lcd.print(itostr3left(tTarget));
  696. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  697. lcd_printPGM(PSTR(" "));
  698. #if 1
  699. //Print Feedrate
  700. lcd.setCursor(LCD_WIDTH - 8-2, 1);
  701. lcd_printPGM(PSTR(" "));
  702. lcd.print(LCD_STR_FEEDRATE[0]);
  703. lcd.print(itostr3(feedmultiply));
  704. lcd_printPGM(PSTR("% "));
  705. #else
  706. //Print Feedrate
  707. lcd.setCursor(LCD_WIDTH - 8-2, 1);
  708. lcd.print(LCD_STR_FEEDRATE[0]);
  709. lcd.print(itostr3(feedmultiply));
  710. lcd_printPGM(PSTR("% Q"));
  711. {
  712. uint8_t queue = planner_queue_min();
  713. if (queue < (BLOCK_BUFFER_SIZE >> 1)) {
  714. lcd.print('!');
  715. } else {
  716. lcd.print((char)(queue / 10) + '0');
  717. queue %= 10;
  718. }
  719. lcd.print((char)queue + '0');
  720. planner_queue_min_reset();
  721. }
  722. #endif
  723. //Print SD status
  724. lcd.setCursor(0, 2);
  725. lcd_print_percent_done();
  726. // Farm number display
  727. if (farm_mode)
  728. {
  729. lcd.setCursor(0, 6);
  730. lcd_printPGM(PSTR(" F"));
  731. lcd.print(farm_no);
  732. lcd_printPGM(PSTR(" "));
  733. // Beat display
  734. lcd.setCursor(LCD_WIDTH - 1, 0);
  735. if ( (millis() - kicktime) < 60000 ) {
  736. lcd_printPGM(PSTR("L"));
  737. }else{
  738. lcd_printPGM(PSTR(" "));
  739. }
  740. }
  741. else {
  742. #ifdef SNMM
  743. lcd_printPGM(PSTR(" E"));
  744. lcd.print(get_ext_nr() + 1);
  745. #else
  746. lcd.setCursor(LCD_WIDTH - 8 - 2, 2);
  747. lcd_printPGM(PSTR(" "));
  748. #endif
  749. }
  750. #ifdef CMD_DIAGNOSTICS
  751. lcd.setCursor(LCD_WIDTH - 8 -1, 2);
  752. lcd_printPGM(PSTR(" C"));
  753. lcd.print(buflen); // number of commands in cmd buffer
  754. if (buflen < 9) lcd_printPGM(" ");
  755. #else
  756. //Print time
  757. lcd.setCursor(LCD_WIDTH - 8, 2);
  758. lcd_print_time();
  759. #endif //CMD_DIAGNOSTICS
  760. #ifdef DEBUG_DISABLE_LCD_STATUS_LINE
  761. return;
  762. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  763. //Print status line
  764. lcd.setCursor(0, 3);
  765. // If heating in progress, set flag
  766. if (heating_status != 0) { custom_message = true; }
  767. if (IS_SD_PRINTING) {
  768. if (strcmp(longFilenameOLD, card.longFilename) != 0)
  769. {
  770. memset(longFilenameOLD, '\0', strlen(longFilenameOLD));
  771. sprintf_P(longFilenameOLD, PSTR("%s"), card.longFilename);
  772. scrollstuff = 0;
  773. }
  774. }
  775. // If printing from SD, show what we are printing
  776. if (IS_SD_PRINTING && !custom_message)
  777. {
  778. if (strlen(card.longFilename) > LCD_WIDTH)
  779. {
  780. int inters = 0;
  781. int gh = scrollstuff;
  782. while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0))
  783. {
  784. if (card.longFilename[gh] == '\0')
  785. {
  786. lcd.setCursor(gh - scrollstuff, 3);
  787. lcd.print(card.longFilename[gh - 1]);
  788. scrollstuff = 0;
  789. gh = scrollstuff;
  790. inters = 1;
  791. }
  792. else
  793. {
  794. lcd.setCursor(gh - scrollstuff, 3);
  795. lcd.print(card.longFilename[gh - 1]);
  796. gh++;
  797. }
  798. }
  799. scrollstuff++;
  800. }
  801. else
  802. {
  803. lcd.print(longFilenameOLD);
  804. }
  805. }
  806. // If not, check for other special events
  807. else
  808. {
  809. if (custom_message)
  810. {
  811. // If heating flag, show progress of heating.
  812. if (heating_status != 0)
  813. {
  814. heating_status_counter++;
  815. if (heating_status_counter > 13)
  816. {
  817. heating_status_counter = 0;
  818. }
  819. lcd.setCursor(7, 3);
  820. lcd_printPGM(PSTR(" "));
  821. for (uint16_t dots = 0; dots < heating_status_counter; dots++)
  822. {
  823. lcd.setCursor(7 + dots, 3);
  824. lcd.print('.');
  825. }
  826. switch (heating_status)
  827. {
  828. case 1:
  829. lcd.setCursor(0, 3);
  830. lcd_printPGM(MSG_HEATING);
  831. break;
  832. case 2:
  833. lcd.setCursor(0, 3);
  834. lcd_printPGM(MSG_HEATING_COMPLETE);
  835. heating_status = 0;
  836. heating_status_counter = 0;
  837. custom_message = false;
  838. break;
  839. case 3:
  840. lcd.setCursor(0, 3);
  841. lcd_printPGM(MSG_BED_HEATING);
  842. break;
  843. case 4:
  844. lcd.setCursor(0, 3);
  845. lcd_printPGM(MSG_BED_DONE);
  846. heating_status = 0;
  847. heating_status_counter = 0;
  848. custom_message = false;
  849. break;
  850. default:
  851. break;
  852. }
  853. }
  854. // If mesh bed leveling in progress, show the status
  855. if (custom_message_type == 1)
  856. {
  857. if (custom_message_state > 10)
  858. {
  859. lcd.setCursor(0, 3);
  860. lcd_printPGM(PSTR(" "));
  861. lcd.setCursor(0, 3);
  862. lcd_printPGM(MSG_HOMEYZ_PROGRESS);
  863. lcd_printPGM(PSTR(" : "));
  864. lcd.print(custom_message_state-10);
  865. }
  866. else
  867. {
  868. if (custom_message_state == 3)
  869. {
  870. lcd_printPGM(WELCOME_MSG);
  871. lcd_setstatuspgm(WELCOME_MSG);
  872. custom_message = false;
  873. custom_message_type = 0;
  874. }
  875. if (custom_message_state > 3 && custom_message_state <= 10 )
  876. {
  877. lcd.setCursor(0, 3);
  878. lcd_printPGM(PSTR(" "));
  879. lcd.setCursor(0, 3);
  880. lcd_printPGM(MSG_HOMEYZ_DONE);
  881. custom_message_state--;
  882. }
  883. }
  884. }
  885. // If loading filament, print status
  886. if (custom_message_type == 2)
  887. {
  888. lcd.print(lcd_status_message);
  889. }
  890. // PID tuning in progress
  891. if (custom_message_type == 3) {
  892. lcd.print(lcd_status_message);
  893. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) {
  894. lcd.setCursor(10, 3);
  895. lcd.print(itostr3(pid_cycle));
  896. lcd.print('/');
  897. lcd.print(itostr3left(pid_number_of_cycles));
  898. }
  899. }
  900. // PINDA temp calibration in progress
  901. if (custom_message_type == 4) {
  902. char progress[4];
  903. lcd.setCursor(0, 3);
  904. lcd_printPGM(MSG_TEMP_CALIBRATION);
  905. lcd.setCursor(12, 3);
  906. sprintf(progress, "%d/6", custom_message_state);
  907. lcd.print(progress);
  908. }
  909. // temp compensation preheat
  910. if (custom_message_type == 5) {
  911. lcd.setCursor(0, 3);
  912. lcd_printPGM(MSG_PINDA_PREHEAT);
  913. if (custom_message_state <= PINDA_HEAT_T) {
  914. lcd_printPGM(PSTR(": "));
  915. lcd.print(custom_message_state); //seconds
  916. lcd.print(' ');
  917. }
  918. }
  919. }
  920. else
  921. {
  922. // Nothing special, print status message normally
  923. lcd.print(lcd_status_message);
  924. }
  925. }
  926. // Fill the rest of line to have nice and clean output
  927. for(int fillspace = 0; fillspace<20;fillspace++)
  928. {
  929. if((lcd_status_message[fillspace] > 31 ))
  930. {
  931. }
  932. else
  933. {
  934. lcd.print(' ');
  935. }
  936. }
  937. }
  938. static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
  939. {
  940. char c;
  941. //Use all characters in narrow LCDs
  942. #if LCD_WIDTH < 20
  943. uint8_t n = LCD_WIDTH - 1 - 1;
  944. #else
  945. uint8_t n = LCD_WIDTH - 1 - 2;
  946. #endif
  947. lcd.setCursor(0, row);
  948. lcd.print(pre_char);
  949. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  950. {
  951. lcd.print(c);
  952. pstr++;
  953. n--;
  954. }
  955. while(n--)
  956. lcd.print(' ');
  957. lcd.print(post_char);
  958. lcd.print(' ');
  959. }
  960. static void lcd_implementation_drawmenu_generic_RAM(uint8_t row, const char* str, char pre_char, char post_char)
  961. {
  962. char c;
  963. //Use all characters in narrow LCDs
  964. #if LCD_WIDTH < 20
  965. uint8_t n = LCD_WIDTH - 1 - 1;
  966. #else
  967. uint8_t n = LCD_WIDTH - 1 - 2;
  968. #endif
  969. lcd.setCursor(0, row);
  970. lcd.print(pre_char);
  971. while( ((c = *str) != '\0') && (n>0) )
  972. {
  973. lcd.print(c);
  974. str++;
  975. n--;
  976. }
  977. while(n--)
  978. lcd.print(' ');
  979. lcd.print(post_char);
  980. lcd.print(' ');
  981. }
  982. static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
  983. {
  984. char c;
  985. //Use all characters in narrow LCDs
  986. #if LCD_WIDTH < 20
  987. uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data);
  988. #else
  989. uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
  990. #endif
  991. lcd.setCursor(0, row);
  992. lcd.print(pre_char);
  993. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  994. {
  995. lcd.print(c);
  996. pstr++;
  997. n--;
  998. }
  999. lcd.print(':');
  1000. while(n--)
  1001. lcd.print(' ');
  1002. lcd.print(data);
  1003. }
  1004. #if 0
  1005. static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
  1006. {
  1007. char c;
  1008. //Use all characters in narrow LCDs
  1009. #if LCD_WIDTH < 20
  1010. uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data);
  1011. #else
  1012. uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data);
  1013. #endif
  1014. lcd.setCursor(0, row);
  1015. lcd.print(pre_char);
  1016. while( ((c = pgm_read_byte(pstr)) != '\0') && (n>0) )
  1017. {
  1018. lcd.print(c);
  1019. pstr++;
  1020. n--;
  1021. }
  1022. lcd.print(':');
  1023. while(n--)
  1024. lcd.print(' ');
  1025. lcd_printPGM(data);
  1026. }
  1027. #endif
  1028. #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
  1029. #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
  1030. #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
  1031. #define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
  1032. #define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
  1033. #define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
  1034. #define lcd_implementation_drawmenu_setting_edit_float43_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr43(*(data)))
  1035. #define lcd_implementation_drawmenu_setting_edit_float43(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr43(*(data)))
  1036. #define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  1037. #define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  1038. #define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
  1039. #define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
  1040. #define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
  1041. #define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
  1042. #define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
  1043. #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
  1044. #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))
  1045. #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))
  1046. //Add version for callback functions
  1047. #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)))
  1048. #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)))
  1049. #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)))
  1050. #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)))
  1051. #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)))
  1052. #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)))
  1053. #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)))
  1054. #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)))
  1055. #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)))
  1056. #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)))
  1057. #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)))
  1058. #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)))
  1059. #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)))
  1060. #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)))
  1061. #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)))
  1062. #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)))
  1063. #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))
  1064. #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))
  1065. void lcd_implementation_drawedit(const char* pstr, char* value)
  1066. {
  1067. lcd.setCursor(1, 1);
  1068. lcd_printPGM(pstr);
  1069. lcd.print(':');
  1070. #if LCD_WIDTH < 20
  1071. lcd.setCursor(LCD_WIDTH - strlen(value), 1);
  1072. #else
  1073. lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1);
  1074. #endif
  1075. lcd.print(value);
  1076. }
  1077. void lcd_implementation_drawedit_2(const char* pstr, char* value)
  1078. {
  1079. lcd.setCursor(0, 1);
  1080. lcd_printPGM(pstr);
  1081. lcd.print(':');
  1082. lcd.setCursor((LCD_WIDTH - strlen(value))/2, 3);
  1083. lcd.print(value);
  1084. lcd.print(" mm");
  1085. }
  1086. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1087. {
  1088. char c;
  1089. int enc_dif = encoderDiff;
  1090. uint8_t n = LCD_WIDTH - 1;
  1091. for(int g = 0; g<4;g++){
  1092. lcd.setCursor(0, g);
  1093. lcd.print(' ');
  1094. }
  1095. lcd.setCursor(0, row);
  1096. lcd.print('>');
  1097. int i = 1;
  1098. int j = 0;
  1099. char* longFilenameTMP = longFilename;
  1100. while((c = *longFilenameTMP) != '\0')
  1101. {
  1102. lcd.setCursor(i, row);
  1103. lcd.print(c);
  1104. i++;
  1105. longFilenameTMP++;
  1106. if(i==LCD_WIDTH) {
  1107. i=1;
  1108. j++;
  1109. longFilenameTMP = longFilename + j;
  1110. n = LCD_WIDTH - 1;
  1111. for(int g = 0; g<300 ;g++){
  1112. if(LCD_CLICKED || ( enc_dif != encoderDiff )){
  1113. longFilenameTMP = longFilename;
  1114. *(longFilenameTMP + LCD_WIDTH - 2) = '\0';
  1115. i = 1;
  1116. j = 0;
  1117. break;
  1118. }else{
  1119. if (j == 1) delay(3); //wait around 1.2 s to start scrolling text
  1120. delay(1); //then scroll with redrawing every 300 ms
  1121. }
  1122. }
  1123. }
  1124. }
  1125. if(c!='\0'){
  1126. lcd.setCursor(i, row);
  1127. lcd.print(c);
  1128. i++;
  1129. }
  1130. n=n-i+1;
  1131. while(n--)
  1132. lcd.print(' ');
  1133. }
  1134. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1135. {
  1136. char c;
  1137. uint8_t n = LCD_WIDTH - 1;
  1138. lcd.setCursor(0, row);
  1139. lcd.print(' ');
  1140. if (longFilename[0] != '\0')
  1141. {
  1142. filename = longFilename;
  1143. longFilename[LCD_WIDTH-1] = '\0';
  1144. }
  1145. while( ((c = *filename) != '\0') && (n>0) )
  1146. {
  1147. lcd.print(c);
  1148. filename++;
  1149. n--;
  1150. }
  1151. while(n--)
  1152. lcd.print(' ');
  1153. }
  1154. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1155. {
  1156. char c;
  1157. uint8_t n = LCD_WIDTH - 2;
  1158. lcd.setCursor(0, row);
  1159. lcd.print('>');
  1160. lcd.print(LCD_STR_FOLDER[0]);
  1161. if (longFilename[0] != '\0')
  1162. {
  1163. filename = longFilename;
  1164. longFilename[LCD_WIDTH-2] = '\0';
  1165. }
  1166. while( ((c = *filename) != '\0') && (n>0) )
  1167. {
  1168. lcd.print(c);
  1169. filename++;
  1170. n--;
  1171. }
  1172. while(n--)
  1173. lcd.print(' ');
  1174. }
  1175. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
  1176. {
  1177. char c;
  1178. uint8_t n = LCD_WIDTH - 2;
  1179. lcd.setCursor(0, row);
  1180. lcd.print(' ');
  1181. lcd.print(LCD_STR_FOLDER[0]);
  1182. if (longFilename[0] != '\0')
  1183. {
  1184. filename = longFilename;
  1185. longFilename[LCD_WIDTH-2] = '\0';
  1186. }
  1187. while( ((c = *filename) != '\0') && (n>0) )
  1188. {
  1189. lcd.print(c);
  1190. filename++;
  1191. n--;
  1192. }
  1193. while(n--)
  1194. lcd.print(' ');
  1195. }
  1196. #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  1197. #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])
  1198. #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])
  1199. #define lcd_implementation_drawmenu_back_RAM(row, str, data) lcd_implementation_drawmenu_generic_RAM(row, str, ' ', LCD_STR_UPLEVEL[0])
  1200. #define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  1201. #define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0])
  1202. #define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1203. #define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1204. #define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1205. #define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1206. #define lcd_implementation_drawmenu_setlang_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ')
  1207. #define lcd_implementation_drawmenu_setlang(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ')
  1208. static void lcd_implementation_quick_feedback()
  1209. {
  1210. #ifdef LCD_USE_I2C_BUZZER
  1211. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  1212. lcd_buzz(1000/6,100);
  1213. #else
  1214. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
  1215. #endif
  1216. #elif defined(BEEPER) && BEEPER > -1
  1217. SET_OUTPUT(BEEPER);
  1218. Sound_MakeSound(e_SOUND_CLASS_Echo,e_SOUND_TYPE_ButtonEcho);
  1219. /*
  1220. #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
  1221. for(int8_t i=0;i<10;i++)
  1222. {
  1223. WRITE(BEEPER,HIGH);
  1224. delayMicroseconds(100);
  1225. WRITE(BEEPER,LOW);
  1226. delayMicroseconds(100);
  1227. }
  1228. #else
  1229. for(int8_t i=0;i<(LCD_FEEDBACK_FREQUENCY_DURATION_MS / (1000 / LCD_FEEDBACK_FREQUENCY_HZ));i++)
  1230. {
  1231. WRITE(BEEPER,HIGH);
  1232. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  1233. WRITE(BEEPER,LOW);
  1234. delayMicroseconds(1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2);
  1235. }
  1236. #endif
  1237. */
  1238. #endif
  1239. }
  1240. #ifdef LCD_HAS_STATUS_INDICATORS
  1241. static void lcd_implementation_update_indicators()
  1242. {
  1243. #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
  1244. //set the LEDS - referred to as backlights by the LiquidTWI2 library
  1245. static uint8_t ledsprev = 0;
  1246. uint8_t leds = 0;
  1247. if (target_temperature_bed > 0) leds |= LED_A;
  1248. if (target_temperature[0] > 0) leds |= LED_B;
  1249. if (fanSpeed) leds |= LED_C;
  1250. #if EXTRUDERS > 1
  1251. if (target_temperature[1] > 0) leds |= LED_C;
  1252. #endif
  1253. if (leds != ledsprev) {
  1254. lcd.setBacklight(leds);
  1255. ledsprev = leds;
  1256. }
  1257. #endif
  1258. }
  1259. #endif
  1260. #ifdef LCD_HAS_SLOW_BUTTONS
  1261. extern uint32_t blocking_enc;
  1262. static uint8_t lcd_implementation_read_slow_buttons()
  1263. {
  1264. #ifdef LCD_I2C_TYPE_MCP23017
  1265. uint8_t slow_buttons;
  1266. // Reading these buttons this is likely to be too slow to call inside interrupt context
  1267. // so they are called during normal lcd_update
  1268. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  1269. #if defined(LCD_I2C_VIKI)
  1270. if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
  1271. if(blocking_enc > millis()) {
  1272. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  1273. }
  1274. }
  1275. #endif
  1276. return slow_buttons;
  1277. #endif
  1278. }
  1279. #endif
  1280. #endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H