ultralcd_implementation_hitachi_HD44780.h 41 KB

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