My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd.cpp 163KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../inc/MarlinConfig.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "ultralcd.h"
  25. #include "../sd/cardreader.h"
  26. #include "../module/temperature.h"
  27. #include "../module/planner.h"
  28. #include "../module/stepper.h"
  29. #include "../module/configuration_store.h"
  30. #include "../Marlin.h"
  31. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  32. #include "../libs/buzzer.h"
  33. #endif
  34. #if ENABLED(PRINTCOUNTER)
  35. #include "../module/printcounter.h"
  36. #include "../libs/duration_t.h"
  37. #endif
  38. #if ENABLED(FILAMENT_LCD_DISPLAY)
  39. #include "../feature/filwidth.h"
  40. #endif
  41. #if HAS_BED_PROBE
  42. #include "../module/probe.h"
  43. #endif
  44. #if ENABLED(BLTOUCH)
  45. #include "../module/endstops.h"
  46. #endif
  47. #if HAS_LEVELING
  48. #include "../feature/bedlevel/bedlevel.h"
  49. #endif
  50. // Initialized by settings.load()
  51. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  52. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  53. millis_t previous_lcd_status_ms = 0;
  54. #endif
  55. #if ENABLED(BABYSTEPPING)
  56. long babysteps_done = 0;
  57. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  58. static void lcd_babystep_zoffset();
  59. #else
  60. static void lcd_babystep_z();
  61. #endif
  62. #endif
  63. uint8_t lcd_status_message_level;
  64. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  65. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  66. uint8_t status_scroll_pos = 0;
  67. #endif
  68. #if ENABLED(DOGLCD)
  69. #include "ultralcd_impl_DOGM.h"
  70. #include <U8glib.h>
  71. #else
  72. #include "ultralcd_impl_HD44780.h"
  73. #endif
  74. // The main status screen
  75. void lcd_status_screen();
  76. millis_t next_lcd_update_ms;
  77. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  78. uint16_t max_display_update_time = 0;
  79. #if ENABLED(DOGLCD)
  80. bool drawing_screen = false;
  81. #endif
  82. #if ENABLED(DAC_STEPPER_CURRENT)
  83. #include "../feature/dac/stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  84. uint8_t driverPercent[XYZE];
  85. #endif
  86. #if ENABLED(ULTIPANEL)
  87. #ifndef TALL_FONT_CORRECTION
  88. #define TALL_FONT_CORRECTION 0
  89. #endif
  90. #if HAS_POWER_SWITCH
  91. extern bool powersupply_on;
  92. #endif
  93. ////////////////////////////////////////////
  94. ///////////////// Menu Tree ////////////////
  95. ////////////////////////////////////////////
  96. void lcd_main_menu();
  97. void lcd_tune_menu();
  98. void lcd_prepare_menu();
  99. void lcd_move_menu();
  100. void lcd_control_menu();
  101. void lcd_control_temperature_menu();
  102. void lcd_control_temperature_preheat_material1_settings_menu();
  103. void lcd_control_temperature_preheat_material2_settings_menu();
  104. void lcd_control_motion_menu();
  105. void lcd_control_filament_menu();
  106. #if ENABLED(LCD_INFO_MENU)
  107. #if ENABLED(PRINTCOUNTER)
  108. void lcd_info_stats_menu();
  109. #endif
  110. void lcd_info_thermistors_menu();
  111. void lcd_info_board_menu();
  112. void lcd_info_menu();
  113. #endif // LCD_INFO_MENU
  114. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  115. void lcd_advanced_pause_toocold_menu();
  116. void lcd_advanced_pause_option_menu();
  117. void lcd_advanced_pause_init_message();
  118. void lcd_advanced_pause_unload_message();
  119. void lcd_advanced_pause_insert_message();
  120. void lcd_advanced_pause_load_message();
  121. void lcd_advanced_pause_heat_nozzle();
  122. void lcd_advanced_pause_extrude_message();
  123. void lcd_advanced_pause_resume_message();
  124. #endif
  125. #if ENABLED(DAC_STEPPER_CURRENT)
  126. void dac_driver_commit();
  127. void dac_driver_getValues();
  128. void lcd_dac_menu();
  129. void lcd_dac_write_eeprom();
  130. #endif
  131. #if ENABLED(FWRETRACT)
  132. void lcd_control_retract_menu();
  133. #endif
  134. #if ENABLED(DELTA_CALIBRATION_MENU)
  135. void lcd_delta_calibrate_menu();
  136. #endif
  137. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  138. #include "../feature/mbl/mesh_bed_leveling.h"
  139. extern void mesh_probing_done();
  140. #endif
  141. ////////////////////////////////////////////
  142. //////////// Menu System Actions ///////////
  143. ////////////////////////////////////////////
  144. #define menu_action_back(dummy) _menu_action_back()
  145. void _menu_action_back();
  146. void menu_action_submenu(screenFunc_t data);
  147. void menu_action_gcode(const char* pgcode);
  148. void menu_action_function(screenFunc_t data);
  149. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  150. bool _menu_edit_ ## _name(); \
  151. void menu_edit_ ## _name(); \
  152. void menu_edit_callback_ ## _name(); \
  153. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  154. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  155. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
  156. typedef void _name##_void
  157. DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
  158. DECLARE_MENU_EDIT_TYPE(int16_t, int3);
  159. DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
  160. DECLARE_MENU_EDIT_TYPE(float, float3);
  161. DECLARE_MENU_EDIT_TYPE(float, float32);
  162. DECLARE_MENU_EDIT_TYPE(float, float43);
  163. DECLARE_MENU_EDIT_TYPE(float, float5);
  164. DECLARE_MENU_EDIT_TYPE(float, float51);
  165. DECLARE_MENU_EDIT_TYPE(float, float52);
  166. DECLARE_MENU_EDIT_TYPE(float, float62);
  167. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  168. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  169. #if ENABLED(SDSUPPORT)
  170. void lcd_sdcard_menu();
  171. void menu_action_sdfile(const char* filename, char* longFilename);
  172. void menu_action_sddirectory(const char* filename, char* longFilename);
  173. #endif
  174. ////////////////////////////////////////////
  175. //////////// Menu System Macros ////////////
  176. ////////////////////////////////////////////
  177. #ifndef ENCODER_FEEDRATE_DEADZONE
  178. #define ENCODER_FEEDRATE_DEADZONE 10
  179. #endif
  180. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  181. #define ENCODER_STEPS_PER_MENU_ITEM 5
  182. #endif
  183. #ifndef ENCODER_PULSES_PER_STEP
  184. #define ENCODER_PULSES_PER_STEP 1
  185. #endif
  186. /**
  187. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  188. *
  189. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  190. * menu_action_[type](arg3...)
  191. *
  192. * Examples:
  193. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  194. * or
  195. * MENU_BACK(MSG_WATCH)
  196. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  197. * menu_action_back()
  198. *
  199. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  200. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  201. * menu_action_function(lcd_sdcard_pause)
  202. *
  203. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  204. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  205. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  206. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  207. *
  208. */
  209. #define _MENU_ITEM_PART_1(TYPE, ...) \
  210. if (_menuLineNr == _thisItemNr) { \
  211. if (lcd_clicked && encoderLine == _thisItemNr) {
  212. #define _MENU_ITEM_PART_2(TYPE, LABEL, ...) \
  213. menu_action_ ## TYPE(__VA_ARGS__); \
  214. if (screen_changed) return; \
  215. } \
  216. if (lcdDrawUpdate) \
  217. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  218. } \
  219. ++_thisItemNr
  220. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  221. _skipStatic = false; \
  222. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  223. _MENU_ITEM_PART_2(TYPE, LABEL, ## __VA_ARGS__); \
  224. }while(0)
  225. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  226. // Used to print static text with no visible cursor.
  227. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  228. #define STATIC_ITEM(LABEL, ...) \
  229. if (_menuLineNr == _thisItemNr) { \
  230. if (_skipStatic && encoderLine <= _thisItemNr) { \
  231. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  232. ++encoderLine; \
  233. } \
  234. if (lcdDrawUpdate) \
  235. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  236. } \
  237. ++_thisItemNr
  238. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  239. bool encoderRateMultiplierEnabled;
  240. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  241. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  242. /**
  243. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  244. */
  245. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  246. _MENU_ITEM_PART_1(type, ## __VA_ARGS__); \
  247. encoderRateMultiplierEnabled = true; \
  248. lastEncoderMovementMillis = 0; \
  249. _MENU_ITEM_PART_2(type, label, ## __VA_ARGS__); \
  250. }while(0)
  251. #else // !ENCODER_RATE_MULTIPLIER
  252. #define ENCODER_RATE_MULTIPLY(F) NOOP
  253. #endif // !ENCODER_RATE_MULTIPLIER
  254. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  255. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  256. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  257. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  258. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  259. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  260. #else // !ENCODER_RATE_MULTIPLIER
  261. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  262. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  263. #endif // !ENCODER_RATE_MULTIPLIER
  264. /**
  265. * START_SCREEN_OR_MENU generates init code for a screen or menu
  266. *
  267. * encoderLine is the position based on the encoder
  268. * encoderTopLine is the top menu line to display
  269. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  270. * _menuLineNr is the menu item to draw and process
  271. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  272. * _countedItems is the total number of items in the menu (after one call)
  273. */
  274. #define START_SCREEN_OR_MENU(LIMIT) \
  275. ENCODER_DIRECTION_MENUS(); \
  276. ENCODER_RATE_MULTIPLY(false); \
  277. if (encoderPosition > 0x8000) encoderPosition = 0; \
  278. static int8_t _countedItems = 0; \
  279. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  280. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  281. encoderLine = max(0, _countedItems - (LIMIT)); \
  282. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  283. }
  284. #define SCREEN_OR_MENU_LOOP() \
  285. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  286. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  287. _thisItemNr = 0
  288. /**
  289. * START_SCREEN Opening code for a screen having only static items.
  290. * Do simplified scrolling of the entire screen.
  291. *
  292. * START_MENU Opening code for a screen with menu items.
  293. * Scroll as-needed to keep the selected line in view.
  294. */
  295. #define START_SCREEN() \
  296. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  297. encoderTopLine = encoderLine; \
  298. bool _skipStatic = false; \
  299. SCREEN_OR_MENU_LOOP()
  300. #define START_MENU() \
  301. START_SCREEN_OR_MENU(1); \
  302. screen_changed = false; \
  303. NOMORE(encoderTopLine, encoderLine); \
  304. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  305. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  306. } \
  307. bool _skipStatic = true; \
  308. SCREEN_OR_MENU_LOOP()
  309. #define END_SCREEN() \
  310. } \
  311. _countedItems = _thisItemNr
  312. #define END_MENU() \
  313. } \
  314. _countedItems = _thisItemNr; \
  315. UNUSED(_skipStatic)
  316. ////////////////////////////////////////////
  317. ///////////// Global Variables /////////////
  318. ////////////////////////////////////////////
  319. /**
  320. * REVERSE_MENU_DIRECTION
  321. *
  322. * To reverse the menu direction we need a general way to reverse
  323. * the direction of the encoder everywhere. So encoderDirection is
  324. * added to allow the encoder to go the other way.
  325. *
  326. * This behavior is limited to scrolling Menus and SD card listings,
  327. * and is disabled in other contexts.
  328. */
  329. #if ENABLED(REVERSE_MENU_DIRECTION)
  330. int8_t encoderDirection = 1;
  331. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  332. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  333. #else
  334. #define ENCODER_DIRECTION_NORMAL() ;
  335. #define ENCODER_DIRECTION_MENUS() ;
  336. #endif
  337. // Encoder Movement
  338. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  339. uint32_t encoderPosition;
  340. millis_t lastEncoderMovementMillis = 0;
  341. // Button States
  342. bool lcd_clicked, wait_for_unclick;
  343. volatile uint8_t buttons;
  344. millis_t next_button_update_ms;
  345. #if ENABLED(REPRAPWORLD_KEYPAD)
  346. volatile uint8_t buttons_reprapworld_keypad;
  347. #endif
  348. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  349. volatile uint8_t slow_buttons;
  350. #endif
  351. // Menu System Navigation
  352. screenFunc_t currentScreen = lcd_status_screen;
  353. int8_t encoderTopLine;
  354. typedef struct {
  355. screenFunc_t menu_function;
  356. uint32_t encoder_position;
  357. } menuPosition;
  358. menuPosition screen_history[6];
  359. uint8_t screen_history_depth = 0;
  360. bool screen_changed, defer_return_to_status;
  361. // Value Editing
  362. const char *editLabel;
  363. void *editValue;
  364. int32_t minEditValue, maxEditValue;
  365. screenFunc_t callbackFunc;
  366. bool liveEdit;
  367. // Manual Moves
  368. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  369. millis_t manual_move_start_time = 0;
  370. int8_t manual_move_axis = (int8_t)NO_AXIS;
  371. #if EXTRUDERS > 1
  372. int8_t manual_move_e_index = 0;
  373. #else
  374. #define manual_move_e_index 0
  375. #endif
  376. #if PIN_EXISTS(SD_DETECT)
  377. uint8_t lcd_sd_status;
  378. #endif
  379. #if ENABLED(PIDTEMP)
  380. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  381. #endif
  382. /**
  383. * General function to go directly to a screen
  384. */
  385. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
  386. if (currentScreen != screen) {
  387. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  388. static millis_t doubleclick_expire_ms = 0;
  389. // Going to lcd_main_menu from status screen? Remember first click time.
  390. // Going back to status screen within a very short time? Go to Z babystepping.
  391. if (screen == lcd_main_menu) {
  392. if (currentScreen == lcd_status_screen)
  393. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  394. }
  395. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  396. screen =
  397. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  398. lcd_babystep_zoffset
  399. #else
  400. lcd_babystep_z
  401. #endif
  402. ;
  403. #endif
  404. currentScreen = screen;
  405. encoderPosition = encoder;
  406. if (screen == lcd_status_screen) {
  407. defer_return_to_status = false;
  408. #if ENABLED(AUTO_BED_LEVELING_UBL)
  409. ubl.lcd_map_control = false;
  410. #endif
  411. screen_history_depth = 0;
  412. }
  413. lcd_implementation_clear();
  414. // Re-initialize custom characters that may be re-used
  415. #if DISABLED(DOGLCD) && ENABLED(AUTO_BED_LEVELING_UBL)
  416. if (!ubl.lcd_map_control) lcd_set_custom_characters(
  417. #if ENABLED(LCD_PROGRESS_BAR)
  418. screen == lcd_status_screen
  419. #endif
  420. );
  421. #elif ENABLED(LCD_PROGRESS_BAR)
  422. lcd_set_custom_characters(screen == lcd_status_screen);
  423. #endif
  424. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  425. screen_changed = true;
  426. #if ENABLED(DOGLCD)
  427. drawing_screen = false;
  428. #endif
  429. }
  430. }
  431. /**
  432. * Show "Moving..." till moves are done, then revert to previous display.
  433. */
  434. static const char moving[] PROGMEM = MSG_MOVING;
  435. static const char *sync_message = moving;
  436. //
  437. // Display the synchronize screen until moves are
  438. // finished, and don't return to the caller until
  439. // done. ** This blocks the command queue! **
  440. //
  441. void _lcd_synchronize() {
  442. static bool no_reentry = false;
  443. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  444. if (no_reentry) return;
  445. // Make this the current handler till all moves are done
  446. no_reentry = true;
  447. screenFunc_t old_screen = currentScreen;
  448. lcd_goto_screen(_lcd_synchronize);
  449. stepper.synchronize();
  450. no_reentry = false;
  451. lcd_goto_screen(old_screen);
  452. }
  453. // Display the synchronize screen with a custom message
  454. // ** This blocks the command queue! **
  455. void lcd_synchronize(const char * const msg=NULL) {
  456. sync_message = msg ? msg : moving;
  457. _lcd_synchronize();
  458. }
  459. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  460. void lcd_save_previous_screen() {
  461. if (screen_history_depth < COUNT(screen_history)) {
  462. screen_history[screen_history_depth].menu_function = currentScreen;
  463. screen_history[screen_history_depth].encoder_position = encoderPosition;
  464. ++screen_history_depth;
  465. }
  466. }
  467. void lcd_goto_previous_menu() {
  468. if (screen_history_depth > 0) {
  469. --screen_history_depth;
  470. lcd_goto_screen(
  471. screen_history[screen_history_depth].menu_function,
  472. screen_history[screen_history_depth].encoder_position
  473. );
  474. }
  475. else
  476. lcd_return_to_status();
  477. }
  478. void lcd_goto_previous_menu_no_defer() {
  479. defer_return_to_status = false;
  480. lcd_goto_previous_menu();
  481. }
  482. #endif // ULTIPANEL
  483. /**
  484. *
  485. * "Info Screen"
  486. *
  487. * This is very display-dependent, so the lcd implementation draws this.
  488. */
  489. void lcd_status_screen() {
  490. #if ENABLED(ULTIPANEL)
  491. ENCODER_DIRECTION_NORMAL();
  492. ENCODER_RATE_MULTIPLY(false);
  493. #endif
  494. #if ENABLED(LCD_PROGRESS_BAR)
  495. millis_t ms = millis();
  496. #if DISABLED(PROGRESS_MSG_ONCE)
  497. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  498. progress_bar_ms = ms;
  499. }
  500. #endif
  501. #if PROGRESS_MSG_EXPIRE > 0
  502. // Handle message expire
  503. if (expire_status_ms > 0) {
  504. #if ENABLED(SDSUPPORT)
  505. if (card.isFileOpen()) {
  506. // Expire the message when printing is active
  507. if (IS_SD_PRINTING) {
  508. if (ELAPSED(ms, expire_status_ms)) {
  509. lcd_status_message[0] = '\0';
  510. expire_status_ms = 0;
  511. }
  512. }
  513. else {
  514. expire_status_ms += LCD_UPDATE_INTERVAL;
  515. }
  516. }
  517. else {
  518. expire_status_ms = 0;
  519. }
  520. #else
  521. expire_status_ms = 0;
  522. #endif // SDSUPPORT
  523. }
  524. #endif
  525. #endif // LCD_PROGRESS_BAR
  526. #if ENABLED(ULTIPANEL)
  527. if (lcd_clicked) {
  528. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  529. previous_lcd_status_ms = millis(); // get status message to show up for a while
  530. #endif
  531. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  532. #if ENABLED(LCD_PROGRESS_BAR)
  533. false
  534. #endif
  535. );
  536. lcd_goto_screen(lcd_main_menu);
  537. return;
  538. }
  539. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  540. const int16_t new_frm = feedrate_percentage + (int32_t)encoderPosition;
  541. // Dead zone at 100% feedrate
  542. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  543. feedrate_percentage = 100;
  544. encoderPosition = 0;
  545. }
  546. else if (feedrate_percentage == 100) {
  547. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  548. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  549. encoderPosition = 0;
  550. }
  551. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  552. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  553. encoderPosition = 0;
  554. }
  555. }
  556. else {
  557. feedrate_percentage = new_frm;
  558. encoderPosition = 0;
  559. }
  560. #endif // ULTIPANEL_FEEDMULTIPLY
  561. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  562. #endif // ULTIPANEL
  563. lcd_implementation_status_screen();
  564. }
  565. void lcd_reset_status() { lcd_setstatusPGM(PSTR(""), -1); }
  566. /**
  567. *
  568. * draw the kill screen
  569. *
  570. */
  571. void kill_screen(const char* lcd_msg) {
  572. lcd_init();
  573. lcd_setalertstatusPGM(lcd_msg);
  574. #if ENABLED(DOGLCD)
  575. u8g.firstPage();
  576. do {
  577. lcd_kill_screen();
  578. } while (u8g.nextPage());
  579. #else
  580. lcd_kill_screen();
  581. #endif
  582. }
  583. #if ENABLED(ULTIPANEL)
  584. /**
  585. *
  586. * Audio feedback for controller clicks
  587. *
  588. */
  589. void lcd_buzz(long duration, uint16_t freq) {
  590. #if ENABLED(LCD_USE_I2C_BUZZER)
  591. lcd.buzz(duration, freq);
  592. #elif PIN_EXISTS(BEEPER)
  593. buzzer.tone(duration, freq);
  594. #else
  595. UNUSED(duration); UNUSED(freq);
  596. #endif
  597. }
  598. void lcd_quick_feedback() {
  599. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  600. buttons = 0;
  601. next_button_update_ms = millis() + 500;
  602. // Buzz and wait. The delay is needed for buttons to settle!
  603. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  604. #if ENABLED(LCD_USE_I2C_BUZZER)
  605. delay(10);
  606. #elif PIN_EXISTS(BEEPER)
  607. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  608. #endif
  609. }
  610. void lcd_completion_feedback(const bool good/*=true*/) {
  611. if (good) {
  612. lcd_buzz(100, 659);
  613. lcd_buzz(100, 698);
  614. }
  615. else lcd_buzz(20, 440);
  616. }
  617. inline void line_to_current_z() {
  618. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  619. }
  620. inline void line_to_z(const float &z) {
  621. current_position[Z_AXIS] = z;
  622. line_to_current_z();
  623. }
  624. #if ENABLED(SDSUPPORT)
  625. void lcd_sdcard_pause() {
  626. card.pauseSDPrint();
  627. print_job_timer.pause();
  628. #if ENABLED(PARK_HEAD_ON_PAUSE)
  629. enqueue_and_echo_commands_P(PSTR("M125"));
  630. #endif
  631. lcd_setstatusPGM(PSTR(MSG_PRINT_PAUSED), -1);
  632. }
  633. void lcd_sdcard_resume() {
  634. #if ENABLED(PARK_HEAD_ON_PAUSE)
  635. enqueue_and_echo_commands_P(PSTR("M24"));
  636. #else
  637. card.startFileprint();
  638. print_job_timer.start();
  639. #endif
  640. lcd_reset_status();
  641. }
  642. void lcd_sdcard_stop() {
  643. card.stopSDPrint();
  644. clear_command_queue();
  645. quickstop_stepper();
  646. print_job_timer.stop();
  647. thermalManager.disable_all_heaters();
  648. #if FAN_COUNT > 0
  649. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  650. #endif
  651. wait_for_heatup = false;
  652. lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
  653. lcd_return_to_status();
  654. }
  655. #endif // SDSUPPORT
  656. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  657. extern int case_light_brightness;
  658. extern bool case_light_on;
  659. extern void update_case_light();
  660. void case_light_menu() {
  661. START_MENU();
  662. //
  663. // ^ Main
  664. //
  665. MENU_BACK(MSG_MAIN);
  666. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true);
  667. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  668. END_MENU();
  669. }
  670. #endif // MENU_ITEM_CASE_LIGHT
  671. #if ENABLED(BLTOUCH)
  672. /**
  673. *
  674. * "BLTouch" submenu
  675. *
  676. */
  677. static void bltouch_menu() {
  678. START_MENU();
  679. //
  680. // ^ Main
  681. //
  682. MENU_BACK(MSG_MAIN);
  683. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  684. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  685. MENU_ITEM(gcode, MSG_BLTOUCH_DEPLOY, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_DEPLOY)));
  686. MENU_ITEM(gcode, MSG_BLTOUCH_STOW, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_STOW)));
  687. END_MENU();
  688. }
  689. #endif // BLTOUCH
  690. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  691. static void progress_bar_test() {
  692. static int8_t bar_percent = 0;
  693. if (lcd_clicked) {
  694. lcd_goto_previous_menu();
  695. lcd_set_custom_characters(false);
  696. return;
  697. }
  698. bar_percent += (int8_t)encoderPosition;
  699. bar_percent = constrain(bar_percent, 0, 100);
  700. encoderPosition = 0;
  701. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  702. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  703. lcd.print(itostr3(bar_percent)); lcd.write('%');
  704. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  705. }
  706. void _progress_bar_test() {
  707. lcd_goto_screen(progress_bar_test);
  708. lcd_set_custom_characters();
  709. }
  710. #endif // LCD_PROGRESS_BAR_TEST
  711. #if HAS_DEBUG_MENU
  712. void lcd_debug_menu() {
  713. START_MENU();
  714. MENU_BACK(MSG_MAIN); // ^ Main
  715. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  716. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  717. #endif
  718. END_MENU();
  719. }
  720. #endif // HAS_DEBUG_MENU
  721. #if ENABLED(CUSTOM_USER_MENUS)
  722. #ifdef USER_SCRIPT_DONE
  723. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  724. #else
  725. #define _DONE_SCRIPT ""
  726. #endif
  727. void _lcd_user_gcode(const char * const cmd) {
  728. enqueue_and_echo_commands_P(cmd);
  729. #if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK)
  730. lcd_completion_feedback();
  731. #endif
  732. }
  733. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  734. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  735. #endif
  736. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  737. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  738. #endif
  739. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  740. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  741. #endif
  742. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  743. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  744. #endif
  745. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  746. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  747. #endif
  748. void _lcd_user_menu() {
  749. START_MENU();
  750. MENU_BACK(MSG_MAIN);
  751. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  752. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  753. #endif
  754. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  755. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  756. #endif
  757. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  758. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  759. #endif
  760. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  761. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  762. #endif
  763. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  764. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  765. #endif
  766. END_MENU();
  767. }
  768. #endif
  769. /**
  770. *
  771. * "Main" menu
  772. *
  773. */
  774. void lcd_main_menu() {
  775. START_MENU();
  776. MENU_BACK(MSG_WATCH);
  777. #if ENABLED(CUSTOM_USER_MENUS)
  778. MENU_ITEM(submenu, MSG_USER_MENU, _lcd_user_menu);
  779. #endif
  780. //
  781. // Debug Menu when certain options are enabled
  782. //
  783. #if HAS_DEBUG_MENU
  784. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  785. #endif
  786. //
  787. // Set Case light on/off/brightness
  788. //
  789. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  790. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  791. MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu);
  792. }
  793. else
  794. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  795. #endif
  796. if (planner.movesplanned() || IS_SD_PRINTING) {
  797. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  798. }
  799. else {
  800. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  801. }
  802. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  803. #if ENABLED(SDSUPPORT)
  804. if (card.cardOK) {
  805. if (card.isFileOpen()) {
  806. if (IS_SD_PRINTING)
  807. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  808. else
  809. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  810. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  811. }
  812. else {
  813. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  814. #if !PIN_EXISTS(SD_DETECT)
  815. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  816. #endif
  817. }
  818. }
  819. else {
  820. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  821. #if !PIN_EXISTS(SD_DETECT)
  822. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  823. #endif
  824. }
  825. #endif // SDSUPPORT
  826. #if ENABLED(LCD_INFO_MENU)
  827. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  828. #endif
  829. END_MENU();
  830. }
  831. /**
  832. *
  833. * "Tune" submenu items
  834. *
  835. */
  836. #if HAS_M206_COMMAND
  837. /**
  838. * Set the home offset based on the current_position
  839. */
  840. void lcd_set_home_offsets() {
  841. // M428 Command
  842. enqueue_and_echo_commands_P(PSTR("M428"));
  843. lcd_return_to_status();
  844. }
  845. #endif
  846. #if ENABLED(BABYSTEPPING)
  847. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  848. if (lcd_clicked) { return lcd_goto_previous_menu_no_defer(); }
  849. ENCODER_DIRECTION_NORMAL();
  850. if (encoderPosition) {
  851. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  852. encoderPosition = 0;
  853. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  854. thermalManager.babystep_axis(axis, babystep_increment);
  855. babysteps_done += babystep_increment;
  856. }
  857. if (lcdDrawUpdate)
  858. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  859. }
  860. #if ENABLED(BABYSTEP_XY)
  861. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  862. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  863. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  864. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  865. #endif
  866. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  867. void lcd_babystep_zoffset() {
  868. if (lcd_clicked) { return lcd_goto_previous_menu_no_defer(); }
  869. defer_return_to_status = true;
  870. ENCODER_DIRECTION_NORMAL();
  871. if (encoderPosition) {
  872. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  873. encoderPosition = 0;
  874. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  875. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  876. if (planner.abl_enabled)
  877. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  878. zprobe_zoffset = new_zoffset;
  879. refresh_zprobe_zoffset(true);
  880. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  881. }
  882. }
  883. if (lcdDrawUpdate)
  884. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  885. }
  886. #else // !BABYSTEP_ZPROBE_OFFSET
  887. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  888. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  889. #endif // !BABYSTEP_ZPROBE_OFFSET
  890. #endif // BABYSTEPPING
  891. #if ENABLED(AUTO_BED_LEVELING_UBL)
  892. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  893. // separate value that doesn't lose precision.
  894. static int16_t ubl_encoderPosition = 0;
  895. static void _lcd_mesh_fine_tune(const char* msg) {
  896. defer_return_to_status = true;
  897. if (ubl.encoder_diff) {
  898. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  899. ubl.encoder_diff = 0;
  900. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  901. mesh_edit_value = mesh_edit_accumulator;
  902. encoderPosition = 0;
  903. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  904. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  905. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  906. }
  907. if (lcdDrawUpdate)
  908. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  909. }
  910. void _lcd_mesh_edit_NOP() {
  911. defer_return_to_status = true;
  912. }
  913. float lcd_mesh_edit() {
  914. lcd_goto_screen(_lcd_mesh_edit_NOP);
  915. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  916. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  917. return mesh_edit_value;
  918. }
  919. void lcd_mesh_edit_setup(float initial) {
  920. mesh_edit_value = mesh_edit_accumulator = initial;
  921. lcd_goto_screen(_lcd_mesh_edit_NOP);
  922. }
  923. void _lcd_z_offset_edit() {
  924. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  925. }
  926. float lcd_z_offset_edit() {
  927. lcd_goto_screen(_lcd_z_offset_edit);
  928. return mesh_edit_value;
  929. }
  930. void lcd_z_offset_edit_setup(float initial) {
  931. mesh_edit_value = mesh_edit_accumulator = initial;
  932. lcd_goto_screen(_lcd_z_offset_edit);
  933. }
  934. #endif // AUTO_BED_LEVELING_UBL
  935. /**
  936. * Watch temperature callbacks
  937. */
  938. #if HAS_TEMP_HOTEND
  939. #if WATCH_HOTENDS
  940. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  941. #else
  942. #define _WATCH_FUNC(N) NOOP
  943. #endif
  944. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  945. #if HOTENDS > 1
  946. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  947. #if HOTENDS > 2
  948. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  949. #if HOTENDS > 3
  950. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  951. #if HOTENDS > 4
  952. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  953. #endif // HOTENDS > 4
  954. #endif // HOTENDS > 3
  955. #endif // HOTENDS > 2
  956. #endif // HOTENDS > 1
  957. #endif // HAS_TEMP_HOTEND
  958. void watch_temp_callback_bed() {
  959. #if WATCH_THE_BED
  960. thermalManager.start_watching_bed();
  961. #endif
  962. }
  963. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  964. void lcd_enqueue_filament_change() {
  965. #if ENABLED(PREVENT_COLD_EXTRUSION)
  966. if (!DEBUGGING(DRYRUN) && !thermalManager.allow_cold_extrude &&
  967. thermalManager.degTargetHotend(active_extruder) < thermalManager.extrude_min_temp) {
  968. lcd_save_previous_screen();
  969. lcd_goto_screen(lcd_advanced_pause_toocold_menu);
  970. return;
  971. }
  972. #endif
  973. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  974. enqueue_and_echo_commands_P(PSTR("M600 B0"));
  975. }
  976. #endif // ADVANCED_PAUSE_FEATURE
  977. /**
  978. *
  979. * "Tune" submenu
  980. *
  981. */
  982. void lcd_tune_menu() {
  983. START_MENU();
  984. //
  985. // ^ Main
  986. //
  987. MENU_BACK(MSG_MAIN);
  988. //
  989. // Speed:
  990. //
  991. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  992. // Manual bed leveling, Bed Z:
  993. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  994. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  995. #endif
  996. //
  997. // Nozzle:
  998. // Nozzle [1-4]:
  999. //
  1000. #if HOTENDS == 1
  1001. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1002. #else // HOTENDS > 1
  1003. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1004. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1005. #if HOTENDS > 2
  1006. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1007. #if HOTENDS > 3
  1008. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1009. #if HOTENDS > 4
  1010. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1011. #endif // HOTENDS > 4
  1012. #endif // HOTENDS > 3
  1013. #endif // HOTENDS > 2
  1014. #endif // HOTENDS > 1
  1015. //
  1016. // Bed:
  1017. //
  1018. #if HAS_TEMP_BED
  1019. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1020. #endif
  1021. //
  1022. // Fan Speed:
  1023. //
  1024. #if FAN_COUNT > 0
  1025. #if HAS_FAN0
  1026. #if FAN_COUNT > 1
  1027. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1028. #else
  1029. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1030. #endif
  1031. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1032. #endif
  1033. #if HAS_FAN1
  1034. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1035. #endif
  1036. #if HAS_FAN2
  1037. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1038. #endif
  1039. #endif // FAN_COUNT > 0
  1040. //
  1041. // Flow:
  1042. // Flow [1-5]:
  1043. //
  1044. #if EXTRUDERS == 1
  1045. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  1046. #else // EXTRUDERS > 1
  1047. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  1048. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  1049. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  1050. #if EXTRUDERS > 2
  1051. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  1052. #if EXTRUDERS > 3
  1053. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  1054. #if EXTRUDERS > 4
  1055. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  1056. #endif // EXTRUDERS > 4
  1057. #endif // EXTRUDERS > 3
  1058. #endif // EXTRUDERS > 2
  1059. #endif // EXTRUDERS > 1
  1060. //
  1061. // Babystep X:
  1062. // Babystep Y:
  1063. // Babystep Z:
  1064. //
  1065. #if ENABLED(BABYSTEPPING)
  1066. #if ENABLED(BABYSTEP_XY)
  1067. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  1068. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  1069. #endif
  1070. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1071. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1072. #else
  1073. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  1074. #endif
  1075. #endif
  1076. //
  1077. // Change filament
  1078. //
  1079. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1080. if (!thermalManager.tooColdToExtrude(active_extruder))
  1081. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1082. #endif
  1083. END_MENU();
  1084. }
  1085. /**
  1086. *
  1087. * "Driver current control" submenu items
  1088. *
  1089. */
  1090. #if ENABLED(DAC_STEPPER_CURRENT)
  1091. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  1092. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  1093. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  1094. void lcd_dac_menu() {
  1095. dac_driver_getValues();
  1096. START_MENU();
  1097. MENU_BACK(MSG_CONTROL);
  1098. MENU_ITEM_EDIT_CALLBACK(int8, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  1099. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  1100. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  1101. MENU_ITEM_EDIT_CALLBACK(int8, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  1102. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1103. END_MENU();
  1104. }
  1105. #endif // DAC_STEPPER_CURRENT
  1106. #if HAS_MOTOR_CURRENT_PWM
  1107. void lcd_pwm_menu() {
  1108. START_MENU();
  1109. MENU_BACK(MSG_CONTROL);
  1110. #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
  1111. MENU_ITEM_EDIT_CALLBACK(long5, MSG_X MSG_Y, &stepper.motor_current_setting[0], 100, 2000, Stepper::refresh_motor_power);
  1112. #endif
  1113. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  1114. MENU_ITEM_EDIT_CALLBACK(long5, MSG_Z, &stepper.motor_current_setting[1], 100, 2000, Stepper::refresh_motor_power);
  1115. #endif
  1116. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  1117. MENU_ITEM_EDIT_CALLBACK(long5, MSG_E, &stepper.motor_current_setting[2], 100, 2000, Stepper::refresh_motor_power);
  1118. #endif
  1119. END_MENU();
  1120. }
  1121. #endif // HAS_MOTOR_CURRENT_PWM
  1122. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1123. /**
  1124. *
  1125. * "Prepare" submenu items
  1126. *
  1127. */
  1128. void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1129. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1130. #if TEMP_SENSOR_BED != 0
  1131. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1132. #else
  1133. UNUSED(tempb);
  1134. #endif
  1135. #if FAN_COUNT > 0
  1136. #if FAN_COUNT > 1
  1137. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1138. #else
  1139. fanSpeeds[0] = fan;
  1140. #endif
  1141. #else
  1142. UNUSED(fan);
  1143. #endif
  1144. lcd_return_to_status();
  1145. }
  1146. #if TEMP_SENSOR_0 != 0
  1147. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1148. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1149. #if TEMP_SENSOR_BED != 0
  1150. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1151. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1152. #endif
  1153. #endif
  1154. #if HOTENDS > 1
  1155. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1156. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1157. #if TEMP_SENSOR_BED != 0
  1158. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1159. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1160. #endif
  1161. #if HOTENDS > 2
  1162. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1163. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1164. #if TEMP_SENSOR_BED != 0
  1165. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1166. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1167. #endif
  1168. #if HOTENDS > 3
  1169. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1170. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1171. #if TEMP_SENSOR_BED != 0
  1172. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1173. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1174. #endif
  1175. #if HOTENDS > 4
  1176. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1177. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1178. #if TEMP_SENSOR_BED != 0
  1179. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1180. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1181. #endif
  1182. #endif // HOTENDS > 4
  1183. #endif // HOTENDS > 3
  1184. #endif // HOTENDS > 2
  1185. void lcd_preheat_m1_all() {
  1186. #if HOTENDS > 1
  1187. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1188. #if HOTENDS > 2
  1189. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1190. #if HOTENDS > 3
  1191. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1192. #if HOTENDS > 4
  1193. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1194. #endif // HOTENDS > 4
  1195. #endif // HOTENDS > 3
  1196. #endif // HOTENDS > 2
  1197. #endif // HOTENDS > 1
  1198. #if TEMP_SENSOR_BED != 0
  1199. lcd_preheat_m1_e0();
  1200. #else
  1201. lcd_preheat_m1_e0_only();
  1202. #endif
  1203. }
  1204. void lcd_preheat_m2_all() {
  1205. #if HOTENDS > 1
  1206. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1207. #if HOTENDS > 2
  1208. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1209. #if HOTENDS > 3
  1210. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1211. #if HOTENDS > 4
  1212. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1213. #endif // HOTENDS > 4
  1214. #endif // HOTENDS > 3
  1215. #endif // HOTENDS > 2
  1216. #endif // HOTENDS > 1
  1217. #if TEMP_SENSOR_BED != 0
  1218. lcd_preheat_m2_e0();
  1219. #else
  1220. lcd_preheat_m2_e0_only();
  1221. #endif
  1222. }
  1223. #endif // HOTENDS > 1
  1224. #if TEMP_SENSOR_BED != 0
  1225. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1226. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1227. #endif
  1228. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
  1229. void lcd_preheat_m1_menu() {
  1230. START_MENU();
  1231. MENU_BACK(MSG_PREPARE);
  1232. #if HOTENDS == 1
  1233. #if TEMP_SENSOR_BED != 0
  1234. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1235. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1236. #else
  1237. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1238. #endif
  1239. #else
  1240. #if TEMP_SENSOR_BED != 0
  1241. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1242. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1243. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1244. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1245. #else
  1246. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1247. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1248. #endif
  1249. #if HOTENDS > 2
  1250. #if TEMP_SENSOR_BED != 0
  1251. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1252. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1253. #else
  1254. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1255. #endif
  1256. #if HOTENDS > 3
  1257. #if TEMP_SENSOR_BED != 0
  1258. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1259. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1260. #else
  1261. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1262. #endif
  1263. #if HOTENDS > 4
  1264. #if TEMP_SENSOR_BED != 0
  1265. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1266. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1267. #else
  1268. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1269. #endif
  1270. #endif // HOTENDS > 4
  1271. #endif // HOTENDS > 3
  1272. #endif // HOTENDS > 2
  1273. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1274. #endif // HOTENDS > 1
  1275. #if TEMP_SENSOR_BED != 0
  1276. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1277. #endif
  1278. END_MENU();
  1279. }
  1280. void lcd_preheat_m2_menu() {
  1281. START_MENU();
  1282. MENU_BACK(MSG_PREPARE);
  1283. #if HOTENDS == 1
  1284. #if TEMP_SENSOR_BED != 0
  1285. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1286. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1287. #else
  1288. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1289. #endif
  1290. #else
  1291. #if TEMP_SENSOR_BED != 0
  1292. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1293. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1294. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1295. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1296. #else
  1297. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1298. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1299. #endif
  1300. #if HOTENDS > 2
  1301. #if TEMP_SENSOR_BED != 0
  1302. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1303. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1304. #else
  1305. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1306. #endif
  1307. #if HOTENDS > 3
  1308. #if TEMP_SENSOR_BED != 0
  1309. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1310. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1311. #else
  1312. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1313. #endif
  1314. #if HOTENDS > 4
  1315. #if TEMP_SENSOR_BED != 0
  1316. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1317. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1318. #else
  1319. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1320. #endif
  1321. #endif // HOTENDS > 4
  1322. #endif // HOTENDS > 3
  1323. #endif // HOTENDS > 2
  1324. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1325. #endif // HOTENDS > 1
  1326. #if TEMP_SENSOR_BED != 0
  1327. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1328. #endif
  1329. END_MENU();
  1330. }
  1331. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
  1332. void lcd_cooldown() {
  1333. #if FAN_COUNT > 0
  1334. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1335. #endif
  1336. thermalManager.disable_all_heaters();
  1337. lcd_return_to_status();
  1338. }
  1339. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1340. void lcd_autostart_sd() {
  1341. card.autostart_index = 0;
  1342. card.setroot();
  1343. card.checkautostart(true);
  1344. }
  1345. #endif
  1346. #if ENABLED(EEPROM_SETTINGS)
  1347. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1348. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1349. #endif
  1350. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  1351. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  1352. #endif
  1353. #if ENABLED(LEVEL_BED_CORNERS)
  1354. /**
  1355. * Level corners, starting in the front-left corner.
  1356. */
  1357. static int8_t bed_corner;
  1358. void _lcd_goto_next_corner() {
  1359. line_to_z(LOGICAL_Z_POSITION(4.0));
  1360. switch (bed_corner) {
  1361. case 0:
  1362. current_position[X_AXIS] = X_MIN_BED + 10;
  1363. current_position[Y_AXIS] = Y_MIN_BED + 10;
  1364. break;
  1365. case 1:
  1366. current_position[X_AXIS] = X_MAX_BED - 10;
  1367. break;
  1368. case 2:
  1369. current_position[Y_AXIS] = Y_MAX_BED - 10;
  1370. break;
  1371. case 3:
  1372. current_position[X_AXIS] = X_MIN_BED + 10;
  1373. break;
  1374. }
  1375. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[X_AXIS]), active_extruder);
  1376. line_to_z(LOGICAL_Z_POSITION(0.0));
  1377. if (++bed_corner > 3) bed_corner = 0;
  1378. }
  1379. void _lcd_corner_submenu() {
  1380. START_MENU();
  1381. MENU_ITEM(function, MSG_NEXT_CORNER, _lcd_goto_next_corner);
  1382. MENU_ITEM(function, MSG_BACK, lcd_goto_previous_menu_no_defer);
  1383. END_MENU();
  1384. }
  1385. void _lcd_level_bed_corners() {
  1386. defer_return_to_status = true;
  1387. lcd_goto_screen(_lcd_corner_submenu);
  1388. bed_corner = 0;
  1389. _lcd_goto_next_corner();
  1390. }
  1391. #endif // LEVEL_BED_CORNERS
  1392. #if ENABLED(LCD_BED_LEVELING)
  1393. /**
  1394. *
  1395. * "Prepare" > "Level Bed" handlers
  1396. *
  1397. */
  1398. static uint8_t manual_probe_index;
  1399. // LCD probed points are from defaults
  1400. constexpr uint8_t total_probe_points = (
  1401. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1402. 3
  1403. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1404. GRID_MAX_POINTS
  1405. #endif
  1406. );
  1407. //
  1408. // Raise Z to the "manual probe height"
  1409. // Don't return until done.
  1410. // ** This blocks the command queue! **
  1411. //
  1412. void _lcd_after_probing() {
  1413. #if MANUAL_PROBE_HEIGHT > 0
  1414. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1415. #endif
  1416. // Display "Done" screen and wait for moves to complete
  1417. #if MANUAL_PROBE_HEIGHT > 0 || ENABLED(MESH_BED_LEVELING)
  1418. lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
  1419. #endif
  1420. lcd_goto_previous_menu();
  1421. lcd_completion_feedback();
  1422. defer_return_to_status = false;
  1423. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1424. }
  1425. #if ENABLED(MESH_BED_LEVELING)
  1426. // Utility to go to the next mesh point
  1427. inline void _manual_probe_goto_xy(float x, float y) {
  1428. #if MANUAL_PROBE_HEIGHT > 0
  1429. const float prev_z = current_position[Z_AXIS];
  1430. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1431. #endif
  1432. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1433. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1434. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1435. #if MANUAL_PROBE_HEIGHT > 0
  1436. line_to_z(prev_z);
  1437. #endif
  1438. lcd_synchronize();
  1439. }
  1440. #elif ENABLED(PROBE_MANUALLY)
  1441. bool lcd_wait_for_move;
  1442. //
  1443. // Bed leveling is done. Wait for G29 to complete.
  1444. // A flag is used so that this can release control
  1445. // and allow the command queue to be processed.
  1446. //
  1447. void _lcd_level_bed_done() {
  1448. if (!lcd_wait_for_move) _lcd_after_probing();
  1449. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1450. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1451. }
  1452. #endif
  1453. void _lcd_level_goto_next_point();
  1454. /**
  1455. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1456. */
  1457. void _lcd_level_bed_get_z() {
  1458. ENCODER_DIRECTION_NORMAL();
  1459. if (lcd_clicked) {
  1460. //
  1461. // Save the current Z position
  1462. //
  1463. #if ENABLED(MESH_BED_LEVELING)
  1464. //
  1465. // MBL records the position but doesn't move to the next one
  1466. //
  1467. mbl.set_zigzag_z(manual_probe_index, current_position[Z_AXIS]);
  1468. #endif
  1469. // If done...
  1470. if (++manual_probe_index >= total_probe_points) {
  1471. #if ENABLED(PROBE_MANUALLY)
  1472. //
  1473. // The last G29 will record and enable but not move.
  1474. //
  1475. lcd_wait_for_move = true;
  1476. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1477. lcd_goto_screen(_lcd_level_bed_done);
  1478. #elif ENABLED(MESH_BED_LEVELING)
  1479. _lcd_after_probing();
  1480. mbl.set_has_mesh(true);
  1481. mesh_probing_done();
  1482. #endif
  1483. }
  1484. else {
  1485. // MESH_BED_LEVELING: Z already stored, just move
  1486. // PROBE_MANUALLY: Send G29 to record Z, then move
  1487. _lcd_level_goto_next_point();
  1488. }
  1489. return;
  1490. }
  1491. //
  1492. // Encoder knob or keypad buttons adjust the Z position
  1493. //
  1494. if (encoderPosition) {
  1495. refresh_cmd_timeout();
  1496. const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1497. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
  1498. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1499. encoderPosition = 0;
  1500. }
  1501. //
  1502. // Draw on first display, then only on Z change
  1503. //
  1504. if (lcdDrawUpdate) {
  1505. const float v = current_position[Z_AXIS];
  1506. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1507. }
  1508. }
  1509. /**
  1510. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1511. */
  1512. void _lcd_level_bed_moving() {
  1513. if (lcdDrawUpdate) {
  1514. char msg[10];
  1515. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1516. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1517. }
  1518. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1519. #if ENABLED(PROBE_MANUALLY)
  1520. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1521. #endif
  1522. }
  1523. /**
  1524. * Step 5: Initiate a move to the next point
  1525. */
  1526. void _lcd_level_goto_next_point() {
  1527. // Set the menu to display ahead of blocking call
  1528. lcd_goto_screen(_lcd_level_bed_moving);
  1529. #if ENABLED(MESH_BED_LEVELING)
  1530. int8_t px, py;
  1531. mbl.zigzag(manual_probe_index, px, py);
  1532. // Controls the loop until the move is done
  1533. _manual_probe_goto_xy(
  1534. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1535. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1536. );
  1537. // After the blocking function returns, change menus
  1538. lcd_goto_screen(_lcd_level_bed_get_z);
  1539. #elif ENABLED(PROBE_MANUALLY)
  1540. // G29 Records Z, moves, and signals when it pauses
  1541. lcd_wait_for_move = true;
  1542. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1543. #endif
  1544. }
  1545. /**
  1546. * Step 4: Display "Click to Begin", wait for click
  1547. * Move to the first probe position
  1548. */
  1549. void _lcd_level_bed_homing_done() {
  1550. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1551. if (lcd_clicked) {
  1552. manual_probe_index = 0;
  1553. _lcd_level_goto_next_point();
  1554. }
  1555. }
  1556. /**
  1557. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1558. */
  1559. void _lcd_level_bed_homing() {
  1560. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1561. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1562. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1563. lcd_goto_screen(_lcd_level_bed_homing_done);
  1564. }
  1565. #if ENABLED(PROBE_MANUALLY)
  1566. extern bool g29_in_progress;
  1567. #endif
  1568. /**
  1569. * Step 2: Continue Bed Leveling...
  1570. */
  1571. void _lcd_level_bed_continue() {
  1572. defer_return_to_status = true;
  1573. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1574. lcd_goto_screen(_lcd_level_bed_homing);
  1575. enqueue_and_echo_commands_P(PSTR("G28"));
  1576. }
  1577. static bool _level_state;
  1578. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
  1579. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1580. void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
  1581. #endif
  1582. /**
  1583. * Step 1: Bed Level entry-point
  1584. *
  1585. * << Prepare
  1586. * Auto Home (if homing needed)
  1587. * Leveling On/Off (if data exists, and homed)
  1588. * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
  1589. * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
  1590. * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  1591. * Level Bed >
  1592. * Level Corners > (if homed)
  1593. * Load Settings (Req: EEPROM_SETTINGS)
  1594. * Save Settings (Req: EEPROM_SETTINGS)
  1595. */
  1596. void lcd_bed_leveling() {
  1597. START_MENU();
  1598. MENU_BACK(MSG_PREPARE);
  1599. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1600. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1601. else if (leveling_is_valid()) {
  1602. _level_state = leveling_is_active();
  1603. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
  1604. }
  1605. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1606. set_z_fade_height(planner.z_fade_height);
  1607. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
  1608. #endif
  1609. //
  1610. // MBL Z Offset
  1611. //
  1612. #if ENABLED(MESH_BED_LEVELING)
  1613. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1614. #endif
  1615. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1616. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1617. #elif HAS_BED_PROBE
  1618. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  1619. #endif
  1620. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1621. #if ENABLED(LEVEL_BED_CORNERS)
  1622. // Move to the next corner for leveling
  1623. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1624. MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  1625. #endif
  1626. #if ENABLED(EEPROM_SETTINGS)
  1627. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1628. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1629. #endif
  1630. END_MENU();
  1631. }
  1632. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1633. void _lcd_ubl_level_bed();
  1634. static int16_t ubl_storage_slot = 0,
  1635. custom_hotend_temp = 190,
  1636. side_points = 3,
  1637. ubl_fillin_amount = 5,
  1638. ubl_height_amount = 1,
  1639. n_edit_pts = 1,
  1640. x_plot = 0,
  1641. y_plot = 0;
  1642. #if HAS_TEMP_BED
  1643. static int16_t custom_bed_temp = 50;
  1644. #endif
  1645. /**
  1646. * UBL Build Custom Mesh Command
  1647. */
  1648. void _lcd_ubl_build_custom_mesh() {
  1649. char UBL_LCD_GCODE[20];
  1650. enqueue_and_echo_commands_P(PSTR("G28"));
  1651. #if HAS_TEMP_BED
  1652. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1653. enqueue_and_echo_command(UBL_LCD_GCODE);
  1654. #endif
  1655. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1656. enqueue_and_echo_command(UBL_LCD_GCODE);
  1657. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1658. }
  1659. /**
  1660. * UBL Custom Mesh submenu
  1661. *
  1662. * << Build Mesh
  1663. * Hotend Temp: ---
  1664. * Bed Temp: ---
  1665. * Build Custom Mesh
  1666. */
  1667. void _lcd_ubl_custom_mesh() {
  1668. START_MENU();
  1669. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1670. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1671. #if HAS_TEMP_BED
  1672. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 5));
  1673. #endif
  1674. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1675. END_MENU();
  1676. }
  1677. /**
  1678. * UBL Adjust Mesh Height Command
  1679. */
  1680. void _lcd_ubl_adjust_height_cmd() {
  1681. char UBL_LCD_GCODE[16];
  1682. const int ind = ubl_height_amount < 0 ? 6 : 7;
  1683. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
  1684. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
  1685. enqueue_and_echo_command(UBL_LCD_GCODE);
  1686. }
  1687. /**
  1688. * UBL Adjust Mesh Height submenu
  1689. *
  1690. * << Edit Mesh
  1691. * Height Amount: ---
  1692. * Adjust Mesh Height
  1693. * << Info Screen
  1694. */
  1695. void _lcd_ubl_height_adjust_menu() {
  1696. START_MENU();
  1697. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1698. MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
  1699. MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
  1700. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1701. END_MENU();
  1702. }
  1703. /**
  1704. * UBL Edit Mesh submenu
  1705. *
  1706. * << UBL Tools
  1707. * Fine Tune All
  1708. * Fine Tune Closest
  1709. * - Adjust Mesh Height >>
  1710. * << Info Screen
  1711. */
  1712. void _lcd_ubl_edit_mesh() {
  1713. START_MENU();
  1714. MENU_BACK(MSG_UBL_TOOLS);
  1715. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  1716. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1717. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1718. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1719. END_MENU();
  1720. }
  1721. /**
  1722. * UBL Validate Custom Mesh Command
  1723. */
  1724. void _lcd_ubl_validate_custom_mesh() {
  1725. char UBL_LCD_GCODE[24];
  1726. const int temp =
  1727. #if HAS_TEMP_BED
  1728. custom_bed_temp
  1729. #else
  1730. 0
  1731. #endif
  1732. ;
  1733. sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
  1734. enqueue_and_echo_command(UBL_LCD_GCODE);
  1735. }
  1736. /**
  1737. * UBL Validate Mesh submenu
  1738. *
  1739. * << UBL Tools
  1740. * PLA Mesh Validation
  1741. * ABS Mesh Validation
  1742. * Validate Custom Mesh
  1743. * << Info Screen
  1744. */
  1745. void _lcd_ubl_validate_mesh() {
  1746. START_MENU();
  1747. MENU_BACK(MSG_UBL_TOOLS);
  1748. #if HAS_TEMP_BED
  1749. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1750. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1751. #else
  1752. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1753. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1754. #endif
  1755. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1756. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1757. END_MENU();
  1758. }
  1759. /**
  1760. * UBL Grid Leveling Command
  1761. */
  1762. void _lcd_ubl_grid_level_cmd() {
  1763. char UBL_LCD_GCODE[10];
  1764. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1765. enqueue_and_echo_command(UBL_LCD_GCODE);
  1766. }
  1767. /**
  1768. * UBL Grid Leveling submenu
  1769. *
  1770. * << UBL Tools
  1771. * Side points: ---
  1772. * Level Mesh
  1773. */
  1774. void _lcd_ubl_grid_level() {
  1775. START_MENU();
  1776. MENU_BACK(MSG_UBL_TOOLS);
  1777. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1778. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1779. END_MENU();
  1780. }
  1781. /**
  1782. * UBL Mesh Leveling submenu
  1783. *
  1784. * << UBL Tools
  1785. * 3-Point Mesh Leveling
  1786. * - Grid Mesh Leveling >>
  1787. * << Info Screen
  1788. */
  1789. void _lcd_ubl_mesh_leveling() {
  1790. START_MENU();
  1791. MENU_BACK(MSG_UBL_TOOLS);
  1792. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1793. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1794. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1795. END_MENU();
  1796. }
  1797. /**
  1798. * UBL Fill-in Amount Mesh Command
  1799. */
  1800. void _lcd_ubl_fillin_amount_cmd() {
  1801. char UBL_LCD_GCODE[16];
  1802. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1803. enqueue_and_echo_command(UBL_LCD_GCODE);
  1804. }
  1805. /**
  1806. * UBL Smart Fill-in Command
  1807. */
  1808. void _lcd_ubl_smart_fillin_cmd() {
  1809. char UBL_LCD_GCODE[12];
  1810. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T0"));
  1811. enqueue_and_echo_command(UBL_LCD_GCODE);
  1812. }
  1813. /**
  1814. * UBL Fill-in Mesh submenu
  1815. *
  1816. * << Build Mesh
  1817. * Fill-in Amount: ---
  1818. * Fill-in Mesh
  1819. * Smart Fill-in
  1820. * Manual Fill-in
  1821. * << Info Screen
  1822. */
  1823. void _lcd_ubl_fillin_menu() {
  1824. START_MENU();
  1825. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1826. MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
  1827. MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
  1828. MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  1829. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1830. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1831. END_MENU();
  1832. }
  1833. void _lcd_ubl_invalidate() {
  1834. ubl.invalidate();
  1835. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  1836. }
  1837. /**
  1838. * UBL Build Mesh submenu
  1839. *
  1840. * << UBL Tools
  1841. * Build PLA Mesh
  1842. * Build ABS Mesh
  1843. * - Build Custom Mesh >>
  1844. * Build Cold Mesh
  1845. * - Fill-in Mesh >>
  1846. * Continue Bed Mesh
  1847. * Invalidate All
  1848. * Invalidate Closest
  1849. * << Info Screen
  1850. */
  1851. void _lcd_ubl_build_mesh() {
  1852. START_MENU();
  1853. MENU_BACK(MSG_UBL_TOOLS);
  1854. #if HAS_TEMP_BED
  1855. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1856. "G28\n"
  1857. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  1858. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1859. "G29 P1\n"
  1860. "M104 S0\n"
  1861. "M140 S0"
  1862. ));
  1863. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1864. "G28\n"
  1865. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  1866. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1867. "G29 P1\n"
  1868. "M104 S0\n"
  1869. "M140 S0"
  1870. ));
  1871. #else
  1872. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1873. "G28\n"
  1874. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1875. "G29 P1\n"
  1876. "M104 S0"
  1877. ));
  1878. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1879. "G28\n"
  1880. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1881. "G29 P1\n"
  1882. "M104 S0"
  1883. ));
  1884. #endif
  1885. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  1886. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  1887. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  1888. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  1889. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  1890. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  1891. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1892. END_MENU();
  1893. }
  1894. /**
  1895. * UBL Load Mesh Command
  1896. */
  1897. void _lcd_ubl_load_mesh_cmd() {
  1898. char UBL_LCD_GCODE[25];
  1899. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  1900. enqueue_and_echo_command(UBL_LCD_GCODE);
  1901. sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_LOADED "."), ubl_storage_slot);
  1902. enqueue_and_echo_command(UBL_LCD_GCODE);
  1903. }
  1904. /**
  1905. * UBL Save Mesh Command
  1906. */
  1907. void _lcd_ubl_save_mesh_cmd() {
  1908. char UBL_LCD_GCODE[25];
  1909. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  1910. enqueue_and_echo_command(UBL_LCD_GCODE);
  1911. sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_SAVED "."), ubl_storage_slot);
  1912. enqueue_and_echo_command(UBL_LCD_GCODE);
  1913. }
  1914. /**
  1915. * UBL Mesh Storage submenu
  1916. *
  1917. * << Unified Bed Leveling
  1918. * Memory Slot: ---
  1919. * Load Bed Mesh
  1920. * Save Bed Mesh
  1921. */
  1922. void _lcd_ubl_storage_mesh() {
  1923. int16_t a = settings.calc_num_meshes();
  1924. START_MENU();
  1925. MENU_BACK(MSG_UBL_LEVEL_BED);
  1926. if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
  1927. STATIC_ITEM(MSG_NO_STORAGE);
  1928. STATIC_ITEM(MSG_INIT_EEPROM);
  1929. }
  1930. else {
  1931. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  1932. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  1933. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  1934. }
  1935. END_MENU();
  1936. }
  1937. /**
  1938. * UBL LCD "radar" map homing
  1939. */
  1940. void _lcd_ubl_output_map_lcd();
  1941. void _lcd_ubl_map_homing() {
  1942. defer_return_to_status = true;
  1943. ubl.lcd_map_control = true; // Return to the map screen
  1944. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
  1945. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1946. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1947. lcd_goto_screen(_lcd_ubl_output_map_lcd);
  1948. }
  1949. /**
  1950. * UBL LCD "radar" map point editing
  1951. */
  1952. void _lcd_ubl_map_lcd_edit_cmd() {
  1953. char ubl_lcd_gcode [50], str[10], str2[10];
  1954. dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
  1955. dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
  1956. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
  1957. enqueue_and_echo_command(ubl_lcd_gcode);
  1958. }
  1959. /**
  1960. * UBL LCD Map Movement
  1961. */
  1962. void ubl_map_move_to_xy() {
  1963. current_position[X_AXIS] = LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]));
  1964. current_position[Y_AXIS] = LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]));
  1965. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1966. }
  1967. /**
  1968. * UBL LCD "radar" map
  1969. */
  1970. void set_current_from_steppers_for_axis(const AxisEnum axis);
  1971. void sync_plan_position();
  1972. void _lcd_ubl_output_map_lcd() {
  1973. static int16_t step_scaler = 0;
  1974. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1975. return lcd_goto_screen(_lcd_ubl_map_homing);
  1976. if (lcd_clicked) return _lcd_ubl_map_lcd_edit_cmd();
  1977. ENCODER_DIRECTION_NORMAL();
  1978. if (encoderPosition) {
  1979. step_scaler += (int32_t)encoderPosition;
  1980. x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
  1981. if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM)
  1982. step_scaler = 0;
  1983. refresh_cmd_timeout();
  1984. encoderPosition = 0;
  1985. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1986. }
  1987. // Encoder to the right (++)
  1988. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  1989. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  1990. // Encoder to the left (--)
  1991. if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  1992. if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
  1993. // Prevent underrun/overrun of plot numbers
  1994. x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
  1995. y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
  1996. // Determine number of points to edit
  1997. #if IS_KINEMATIC
  1998. n_edit_pts = 9; //TODO: Delta accessible edit points
  1999. #else
  2000. const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
  2001. yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
  2002. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  2003. #endif
  2004. if (lcdDrawUpdate) {
  2005. lcd_implementation_ubl_plot(x_plot, y_plot);
  2006. ubl_map_move_to_xy(); // Move to current location
  2007. if (planner.movesplanned() > 1) { // if the nozzle is moving, cancel the move. There is a new location
  2008. stepper.quick_stop();
  2009. set_current_from_steppers_for_axis(ALL_AXES);
  2010. sync_plan_position();
  2011. ubl_map_move_to_xy(); // Move to new location
  2012. refresh_cmd_timeout();
  2013. }
  2014. }
  2015. }
  2016. /**
  2017. * UBL Homing before LCD map
  2018. */
  2019. void _lcd_ubl_output_map_lcd_cmd() {
  2020. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
  2021. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  2022. enqueue_and_echo_commands_P(PSTR("G28"));
  2023. }
  2024. lcd_goto_screen(_lcd_ubl_map_homing);
  2025. }
  2026. /**
  2027. * UBL Output map submenu
  2028. *
  2029. * << Unified Bed Leveling
  2030. * Output for Host
  2031. * Output for CSV
  2032. * Off Printer Backup
  2033. * Output Mesh Map
  2034. */
  2035. void _lcd_ubl_output_map() {
  2036. START_MENU();
  2037. MENU_BACK(MSG_UBL_LEVEL_BED);
  2038. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  2039. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  2040. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  2041. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  2042. END_MENU();
  2043. }
  2044. /**
  2045. * UBL Tools submenu
  2046. *
  2047. * << Unified Bed Leveling
  2048. * - Build Mesh >>
  2049. * - Validate Mesh >>
  2050. * - Edit Mesh >>
  2051. * - Mesh Leveling >>
  2052. */
  2053. void _lcd_ubl_tools_menu() {
  2054. START_MENU();
  2055. MENU_BACK(MSG_UBL_LEVEL_BED);
  2056. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  2057. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  2058. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2059. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  2060. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  2061. END_MENU();
  2062. }
  2063. /**
  2064. * UBL Step-By-Step submenu
  2065. *
  2066. * << Unified Bed Leveling
  2067. * 1 Build Cold Mesh
  2068. * 2 Smart Fill-in
  2069. * - 3 Validate Mesh >>
  2070. * 4 Fine Tune All
  2071. * - 5 Validate Mesh >>
  2072. * 6 Fine Tune All
  2073. * 7 Save Bed Mesh
  2074. */
  2075. void _lcd_ubl_step_by_step() {
  2076. START_MENU();
  2077. MENU_BACK(MSG_UBL_LEVEL_BED);
  2078. MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  2079. MENU_ITEM(function, "2 " MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  2080. MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2081. MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2082. MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2083. MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2084. MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  2085. END_MENU();
  2086. }
  2087. /**
  2088. * UBL System submenu
  2089. *
  2090. * << Prepare
  2091. * - Manually Build Mesh >>
  2092. * - Activate UBL >>
  2093. * - Deactivate UBL >>
  2094. * - Step-By-Step UBL >>
  2095. * - Mesh Storage >>
  2096. * - Output Map >>
  2097. * - UBL Tools >>
  2098. * - Output UBL Info >>
  2099. */
  2100. void _lcd_ubl_level_bed() {
  2101. START_MENU();
  2102. MENU_BACK(MSG_PREPARE);
  2103. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  2104. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  2105. MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  2106. MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
  2107. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  2108. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  2109. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  2110. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  2111. END_MENU();
  2112. }
  2113. #endif // AUTO_BED_LEVELING_UBL
  2114. /**
  2115. *
  2116. * "Prepare" submenu
  2117. *
  2118. */
  2119. void lcd_prepare_menu() {
  2120. START_MENU();
  2121. //
  2122. // ^ Main
  2123. //
  2124. MENU_BACK(MSG_MAIN);
  2125. //
  2126. // Move Axis
  2127. //
  2128. #if ENABLED(DELTA)
  2129. if (axis_homed[Z_AXIS])
  2130. #endif
  2131. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  2132. //
  2133. // Auto Home
  2134. //
  2135. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2136. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  2137. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  2138. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  2139. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  2140. #endif
  2141. //
  2142. // Level Bed
  2143. //
  2144. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2145. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  2146. #elif ENABLED(LCD_BED_LEVELING)
  2147. #if ENABLED(PROBE_MANUALLY)
  2148. if (!g29_in_progress)
  2149. #endif
  2150. MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
  2151. #else
  2152. #if PLANNER_LEVELING
  2153. MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));
  2154. #endif
  2155. #if ENABLED(LEVEL_BED_CORNERS)
  2156. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2157. MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  2158. #endif
  2159. #endif
  2160. #if HAS_M206_COMMAND
  2161. //
  2162. // Set Home Offsets
  2163. //
  2164. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  2165. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  2166. #endif
  2167. //
  2168. // Disable Steppers
  2169. //
  2170. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2171. //
  2172. // Change filament
  2173. //
  2174. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2175. if (!thermalManager.tooColdToExtrude(active_extruder) && !IS_SD_FILE_OPEN)
  2176. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  2177. #endif
  2178. #if TEMP_SENSOR_0 != 0
  2179. //
  2180. // Cooldown
  2181. //
  2182. bool has_heat = false;
  2183. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  2184. #if HAS_TEMP_BED
  2185. if (thermalManager.target_temperature_bed) has_heat = true;
  2186. #endif
  2187. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  2188. //
  2189. // Preheat for Material 1 and 2
  2190. //
  2191. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
  2192. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  2193. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  2194. #else
  2195. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  2196. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  2197. #endif
  2198. #endif // TEMP_SENSOR_0 != 0
  2199. //
  2200. // BLTouch Self-Test and Reset
  2201. //
  2202. #if ENABLED(BLTOUCH)
  2203. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  2204. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  2205. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  2206. #endif
  2207. //
  2208. // Switch power on/off
  2209. //
  2210. #if HAS_POWER_SWITCH
  2211. if (powersupply_on)
  2212. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  2213. else
  2214. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  2215. #endif
  2216. //
  2217. // Autostart
  2218. //
  2219. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  2220. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  2221. #endif
  2222. //
  2223. // Delta Calibration
  2224. //
  2225. #if ENABLED(DELTA_CALIBRATION_MENU)
  2226. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  2227. #endif
  2228. END_MENU();
  2229. }
  2230. float move_menu_scale;
  2231. #if ENABLED(DELTA_CALIBRATION_MENU)
  2232. void lcd_move_z();
  2233. void lcd_delta_calibrate_menu();
  2234. void _lcd_calibrate_homing() {
  2235. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  2236. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  2237. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2238. lcd_goto_previous_menu();
  2239. }
  2240. void _lcd_delta_calibrate_home() {
  2241. #if HAS_LEVELING
  2242. reset_bed_level(); // After calibration bed-level data is no longer valid
  2243. #endif
  2244. enqueue_and_echo_commands_P(PSTR("G28"));
  2245. lcd_goto_screen(_lcd_calibrate_homing);
  2246. }
  2247. void _man_probe_pt(const float &lx, const float &ly) {
  2248. #if HAS_LEVELING
  2249. reset_bed_level(); // After calibration bed-level data is no longer valid
  2250. #endif
  2251. float z_dest = LOGICAL_Z_POSITION((Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5);
  2252. line_to_z(z_dest);
  2253. current_position[X_AXIS] = LOGICAL_X_POSITION(lx);
  2254. current_position[Y_AXIS] = LOGICAL_Y_POSITION(ly);
  2255. line_to_current_z();
  2256. z_dest = LOGICAL_Z_POSITION(Z_CLEARANCE_BETWEEN_PROBES);
  2257. line_to_z(z_dest);
  2258. lcd_synchronize();
  2259. move_menu_scale = PROBE_MANUALLY_STEP;
  2260. lcd_goto_screen(lcd_move_z);
  2261. }
  2262. float lcd_probe_pt(const float &lx, const float &ly) {
  2263. _man_probe_pt(lx, ly);
  2264. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2265. defer_return_to_status = true;
  2266. wait_for_user = true;
  2267. while (wait_for_user) idle();
  2268. KEEPALIVE_STATE(IN_HANDLER);
  2269. lcd_goto_previous_menu_no_defer();
  2270. return current_position[Z_AXIS];
  2271. }
  2272. void _goto_tower_x() { _man_probe_pt(cos(RADIANS(210)) * delta_calibration_radius, sin(RADIANS(210)) * delta_calibration_radius); }
  2273. void _goto_tower_y() { _man_probe_pt(cos(RADIANS(330)) * delta_calibration_radius, sin(RADIANS(330)) * delta_calibration_radius); }
  2274. void _goto_tower_z() { _man_probe_pt(cos(RADIANS( 90)) * delta_calibration_radius, sin(RADIANS( 90)) * delta_calibration_radius); }
  2275. void _goto_center() { _man_probe_pt(0,0); }
  2276. static float _delta_height = DELTA_HEIGHT;
  2277. void _lcd_set_delta_height() {
  2278. home_offset[Z_AXIS] = _delta_height - DELTA_HEIGHT;
  2279. update_software_endstops(Z_AXIS);
  2280. }
  2281. void lcd_delta_settings() {
  2282. START_MENU();
  2283. MENU_BACK(MSG_DELTA_CALIBRATE);
  2284. float Tz = 0.00;
  2285. MENU_ITEM_EDIT(float52, MSG_DELTA_DIAG_ROG, &delta_diagonal_rod, DELTA_DIAGONAL_ROD - 5.0, DELTA_DIAGONAL_ROD + 5.0);
  2286. _delta_height = DELTA_HEIGHT + home_offset[Z_AXIS];
  2287. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_DELTA_HEIGHT, &_delta_height, _delta_height - 10.0, _delta_height + 10.0, _lcd_set_delta_height);
  2288. MENU_ITEM_EDIT(float43, "Ex", &endstop_adj[A_AXIS], -5.0, 5.0);
  2289. MENU_ITEM_EDIT(float43, "Ey", &endstop_adj[B_AXIS], -5.0, 5.0);
  2290. MENU_ITEM_EDIT(float43, "Ez", &endstop_adj[C_AXIS], -5.0, 5.0);
  2291. MENU_ITEM_EDIT(float52, MSG_DELTA_RADIUS, &delta_radius, DELTA_RADIUS - 5.0, DELTA_RADIUS + 5.0);
  2292. MENU_ITEM_EDIT(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5.0, 5.0);
  2293. MENU_ITEM_EDIT(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5.0, 5.0);
  2294. MENU_ITEM_EDIT(float43, "Tz", &Tz, -5.0, 5.0);
  2295. END_MENU();
  2296. }
  2297. void lcd_delta_calibrate_menu() {
  2298. START_MENU();
  2299. MENU_BACK(MSG_MAIN);
  2300. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2301. MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
  2302. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  2303. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 P1"));
  2304. #if ENABLED(EEPROM_SETTINGS)
  2305. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2306. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2307. #endif
  2308. #endif
  2309. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  2310. if (axis_homed[Z_AXIS]) {
  2311. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  2312. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  2313. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  2314. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  2315. }
  2316. END_MENU();
  2317. }
  2318. #endif // DELTA_CALIBRATION_MENU
  2319. /**
  2320. * If the most recent manual move hasn't been fed to the planner yet,
  2321. * and the planner can accept one, send immediately
  2322. */
  2323. inline void manage_manual_move() {
  2324. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  2325. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  2326. manual_move_axis = (int8_t)NO_AXIS;
  2327. }
  2328. }
  2329. /**
  2330. * Set a flag that lcd_update() should start a move
  2331. * to "current_position" after a short delay.
  2332. */
  2333. inline void manual_move_to_current(AxisEnum axis
  2334. #if E_MANUAL > 1
  2335. , int8_t eindex=-1
  2336. #endif
  2337. ) {
  2338. #if E_MANUAL > 1
  2339. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  2340. #endif
  2341. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  2342. manual_move_axis = (int8_t)axis;
  2343. }
  2344. /**
  2345. *
  2346. * "Prepare" > "Move Axis" submenu
  2347. *
  2348. */
  2349. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  2350. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2351. ENCODER_DIRECTION_NORMAL();
  2352. if (encoderPosition) {
  2353. refresh_cmd_timeout();
  2354. float min = current_position[axis] - 1000,
  2355. max = current_position[axis] + 1000;
  2356. #if HAS_SOFTWARE_ENDSTOPS
  2357. // Limit to software endstops, if enabled
  2358. if (soft_endstops_enabled) {
  2359. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  2360. min = soft_endstop_min[axis];
  2361. #endif
  2362. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  2363. max = soft_endstop_max[axis];
  2364. #endif
  2365. }
  2366. #endif
  2367. // Get the new position
  2368. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  2369. // Delta limits XY based on the current offset from center
  2370. // This assumes the center is 0,0
  2371. #if ENABLED(DELTA)
  2372. if (axis != Z_AXIS) {
  2373. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  2374. min = -max;
  2375. }
  2376. #endif
  2377. // Limit only when trying to move towards the limit
  2378. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  2379. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  2380. manual_move_to_current(axis);
  2381. encoderPosition = 0;
  2382. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2383. }
  2384. if (lcdDrawUpdate)
  2385. lcd_implementation_drawedit(name, move_menu_scale >= 0.1 ? ftostr41sign(current_position[axis]) : ftostr43sign(current_position[axis]));
  2386. }
  2387. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  2388. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  2389. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  2390. void _lcd_move_e(
  2391. #if E_MANUAL > 1
  2392. int8_t eindex=-1
  2393. #endif
  2394. ) {
  2395. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2396. ENCODER_DIRECTION_NORMAL();
  2397. if (encoderPosition) {
  2398. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  2399. encoderPosition = 0;
  2400. manual_move_to_current(E_AXIS
  2401. #if E_MANUAL > 1
  2402. , eindex
  2403. #endif
  2404. );
  2405. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2406. }
  2407. if (lcdDrawUpdate) {
  2408. PGM_P pos_label;
  2409. #if E_MANUAL == 1
  2410. pos_label = PSTR(MSG_MOVE_E);
  2411. #else
  2412. switch (eindex) {
  2413. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  2414. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  2415. #if E_MANUAL > 2
  2416. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  2417. #if E_MANUAL > 3
  2418. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  2419. #if E_MANUAL > 4
  2420. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  2421. #endif // E_MANUAL > 4
  2422. #endif // E_MANUAL > 3
  2423. #endif // E_MANUAL > 2
  2424. }
  2425. #endif // E_MANUAL > 1
  2426. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  2427. }
  2428. }
  2429. void lcd_move_e() { _lcd_move_e(); }
  2430. #if E_MANUAL > 1
  2431. void lcd_move_e0() { _lcd_move_e(0); }
  2432. void lcd_move_e1() { _lcd_move_e(1); }
  2433. #if E_MANUAL > 2
  2434. void lcd_move_e2() { _lcd_move_e(2); }
  2435. #if E_MANUAL > 3
  2436. void lcd_move_e3() { _lcd_move_e(3); }
  2437. #if E_MANUAL > 4
  2438. void lcd_move_e4() { _lcd_move_e(4); }
  2439. #endif // E_MANUAL > 4
  2440. #endif // E_MANUAL > 3
  2441. #endif // E_MANUAL > 2
  2442. #endif // E_MANUAL > 1
  2443. /**
  2444. *
  2445. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2446. *
  2447. */
  2448. screenFunc_t _manual_move_func_ptr;
  2449. void _goto_manual_move(const float scale) {
  2450. defer_return_to_status = true;
  2451. move_menu_scale = scale;
  2452. lcd_goto_screen(_manual_move_func_ptr);
  2453. }
  2454. void lcd_move_menu_10mm() { _goto_manual_move(10.0); }
  2455. void lcd_move_menu_1mm() { _goto_manual_move( 1.0); }
  2456. void lcd_move_menu_01mm() { _goto_manual_move( 0.1); }
  2457. void _lcd_move_distance_menu(const AxisEnum axis, const screenFunc_t func) {
  2458. _manual_move_func_ptr = func;
  2459. START_MENU();
  2460. if (LCD_HEIGHT >= 4) {
  2461. switch(axis) {
  2462. case X_AXIS:
  2463. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2464. case Y_AXIS:
  2465. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2466. case Z_AXIS:
  2467. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2468. default:
  2469. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2470. }
  2471. }
  2472. MENU_BACK(MSG_MOVE_AXIS);
  2473. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2474. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2475. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2476. END_MENU();
  2477. }
  2478. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2479. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2480. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2481. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2482. #if E_MANUAL > 1
  2483. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2484. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2485. #if E_MANUAL > 2
  2486. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2487. #if E_MANUAL > 3
  2488. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2489. #if E_MANUAL > 4
  2490. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2491. #endif // E_MANUAL > 4
  2492. #endif // E_MANUAL > 3
  2493. #endif // E_MANUAL > 2
  2494. #endif // E_MANUAL > 1
  2495. /**
  2496. *
  2497. * "Prepare" > "Move Axis" submenu
  2498. *
  2499. */
  2500. #if IS_KINEMATIC
  2501. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2502. #if ENABLED(DELTA)
  2503. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2504. void lcd_lower_z_to_clip_height() {
  2505. line_to_z(delta_clip_start_height);
  2506. lcd_synchronize();
  2507. }
  2508. #else
  2509. #define _MOVE_XY_ALLOWED true
  2510. #endif
  2511. #else
  2512. #define _MOVE_XYZ_ALLOWED true
  2513. #define _MOVE_XY_ALLOWED true
  2514. #endif
  2515. void lcd_move_menu() {
  2516. START_MENU();
  2517. MENU_BACK(MSG_PREPARE);
  2518. if (_MOVE_XYZ_ALLOWED) {
  2519. if (_MOVE_XY_ALLOWED) {
  2520. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2521. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2522. }
  2523. #if ENABLED(DELTA)
  2524. else
  2525. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2526. #endif
  2527. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2528. }
  2529. else
  2530. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2531. #if ENABLED(SWITCHING_EXTRUDER)
  2532. if (active_extruder)
  2533. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2534. else
  2535. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2536. #endif
  2537. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2538. #if E_MANUAL > 1
  2539. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2540. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2541. #if E_MANUAL > 2
  2542. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2543. #if E_MANUAL > 3
  2544. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2545. #if E_MANUAL > 4
  2546. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2547. #endif // E_MANUAL > 4
  2548. #endif // E_MANUAL > 3
  2549. #endif // E_MANUAL > 2
  2550. #endif // E_MANUAL > 1
  2551. END_MENU();
  2552. }
  2553. /**
  2554. *
  2555. * "Control" submenu
  2556. *
  2557. */
  2558. #if HAS_LCD_CONTRAST
  2559. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2560. #endif
  2561. static void lcd_factory_settings() {
  2562. settings.reset();
  2563. lcd_completion_feedback();
  2564. }
  2565. void lcd_control_menu() {
  2566. START_MENU();
  2567. MENU_BACK(MSG_MAIN);
  2568. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2569. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2570. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2571. #if HAS_LCD_CONTRAST
  2572. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int16_t*)&lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2573. #endif
  2574. #if ENABLED(FWRETRACT)
  2575. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2576. #endif
  2577. #if ENABLED(DAC_STEPPER_CURRENT)
  2578. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2579. #endif
  2580. #if HAS_MOTOR_CURRENT_PWM
  2581. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_pwm_menu);
  2582. #endif
  2583. #if ENABLED(BLTOUCH)
  2584. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2585. #endif
  2586. #if ENABLED(EEPROM_SETTINGS)
  2587. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2588. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2589. #endif
  2590. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2591. #if ENABLED(EEPROM_SETTINGS)
  2592. MENU_ITEM(gcode, MSG_INIT_EEPROM, PSTR("M502\nM500")); // TODO: Add "Are You Sure?" step
  2593. #endif
  2594. END_MENU();
  2595. }
  2596. /**
  2597. *
  2598. * "Temperature" submenu
  2599. *
  2600. */
  2601. #if ENABLED(PID_AUTOTUNE_MENU)
  2602. #if ENABLED(PIDTEMP)
  2603. int16_t autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2604. #endif
  2605. #if ENABLED(PIDTEMPBED)
  2606. int16_t autotune_temp_bed = 70;
  2607. #endif
  2608. void _lcd_autotune(int16_t e) {
  2609. char cmd[30];
  2610. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2611. #if HAS_PID_FOR_BOTH
  2612. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2613. #elif ENABLED(PIDTEMPBED)
  2614. autotune_temp_bed
  2615. #else
  2616. autotune_temp[e]
  2617. #endif
  2618. );
  2619. enqueue_and_echo_command(cmd);
  2620. }
  2621. #endif // PID_AUTOTUNE_MENU
  2622. #if ENABLED(PIDTEMP)
  2623. // Helpers for editing PID Ki & Kd values
  2624. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2625. void copy_and_scalePID_i(int16_t e) {
  2626. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2627. UNUSED(e);
  2628. #endif
  2629. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  2630. thermalManager.updatePID();
  2631. }
  2632. void copy_and_scalePID_d(int16_t e) {
  2633. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2634. UNUSED(e);
  2635. #endif
  2636. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  2637. thermalManager.updatePID();
  2638. }
  2639. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  2640. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  2641. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  2642. #if ENABLED(PID_AUTOTUNE_MENU)
  2643. #define DEFINE_PIDTEMP_FUNCS(N) \
  2644. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  2645. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  2646. #else
  2647. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  2648. #endif
  2649. DEFINE_PIDTEMP_FUNCS(0);
  2650. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2651. #if HOTENDS > 1
  2652. DEFINE_PIDTEMP_FUNCS(1);
  2653. #if HOTENDS > 2
  2654. DEFINE_PIDTEMP_FUNCS(2);
  2655. #if HOTENDS > 3
  2656. DEFINE_PIDTEMP_FUNCS(3);
  2657. #if HOTENDS > 4
  2658. DEFINE_PIDTEMP_FUNCS(4);
  2659. #endif // HOTENDS > 4
  2660. #endif // HOTENDS > 3
  2661. #endif // HOTENDS > 2
  2662. #endif // HOTENDS > 1
  2663. #endif // PID_PARAMS_PER_HOTEND
  2664. #endif // PIDTEMP
  2665. /**
  2666. *
  2667. * "Control" > "Temperature" submenu
  2668. *
  2669. */
  2670. void lcd_control_temperature_menu() {
  2671. START_MENU();
  2672. //
  2673. // ^ Control
  2674. //
  2675. MENU_BACK(MSG_CONTROL);
  2676. //
  2677. // Nozzle:
  2678. // Nozzle [1-5]:
  2679. //
  2680. #if HOTENDS == 1
  2681. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2682. #else // HOTENDS > 1
  2683. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2684. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  2685. #if HOTENDS > 2
  2686. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  2687. #if HOTENDS > 3
  2688. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  2689. #if HOTENDS > 4
  2690. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  2691. #endif // HOTENDS > 4
  2692. #endif // HOTENDS > 3
  2693. #endif // HOTENDS > 2
  2694. #endif // HOTENDS > 1
  2695. //
  2696. // Bed:
  2697. //
  2698. #if HAS_TEMP_BED
  2699. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  2700. #endif
  2701. //
  2702. // Fan Speed:
  2703. //
  2704. #if FAN_COUNT > 0
  2705. #if HAS_FAN0
  2706. #if FAN_COUNT > 1
  2707. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  2708. #else
  2709. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  2710. #endif
  2711. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  2712. #endif
  2713. #if HAS_FAN1
  2714. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  2715. #endif
  2716. #if HAS_FAN2
  2717. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  2718. #endif
  2719. #endif // FAN_COUNT > 0
  2720. //
  2721. // Autotemp, Min, Max, Fact
  2722. //
  2723. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  2724. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  2725. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  2726. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  2727. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  2728. #endif
  2729. //
  2730. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  2731. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  2732. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  2733. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  2734. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  2735. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  2736. //
  2737. #if ENABLED(PIDTEMP)
  2738. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  2739. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  2740. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  2741. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  2742. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  2743. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2744. #if ENABLED(PID_EXTRUSION_SCALING)
  2745. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2746. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2747. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2748. #else
  2749. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2750. #endif
  2751. #if ENABLED(PID_AUTOTUNE_MENU)
  2752. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2753. _PID_MENU_ITEMS(ELABEL, eindex); \
  2754. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2755. #else
  2756. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2757. #endif
  2758. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2759. PID_MENU_ITEMS(" " MSG_E1, 0);
  2760. PID_MENU_ITEMS(" " MSG_E2, 1);
  2761. #if HOTENDS > 2
  2762. PID_MENU_ITEMS(" " MSG_E3, 2);
  2763. #if HOTENDS > 3
  2764. PID_MENU_ITEMS(" " MSG_E4, 3);
  2765. #if HOTENDS > 4
  2766. PID_MENU_ITEMS(" " MSG_E5, 4);
  2767. #endif // HOTENDS > 4
  2768. #endif // HOTENDS > 3
  2769. #endif // HOTENDS > 2
  2770. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2771. PID_MENU_ITEMS("", 0);
  2772. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2773. #endif // PIDTEMP
  2774. //
  2775. // Preheat Material 1 conf
  2776. //
  2777. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2778. //
  2779. // Preheat Material 2 conf
  2780. //
  2781. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2782. END_MENU();
  2783. }
  2784. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2785. #if HOTENDS > 4
  2786. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2787. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2788. #elif HOTENDS > 3
  2789. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2790. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2791. #elif HOTENDS > 2
  2792. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2793. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2794. #elif HOTENDS > 1
  2795. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2796. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2797. #else
  2798. #define MINTEMP_ALL HEATER_0_MINTEMP
  2799. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2800. #endif
  2801. START_MENU();
  2802. MENU_BACK(MSG_TEMPERATURE);
  2803. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2804. #if TEMP_SENSOR_0 != 0
  2805. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2806. #endif
  2807. #if TEMP_SENSOR_BED != 0
  2808. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2809. #endif
  2810. #if ENABLED(EEPROM_SETTINGS)
  2811. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2812. #endif
  2813. END_MENU();
  2814. }
  2815. /**
  2816. *
  2817. * "Temperature" > "Preheat Material 1 conf" submenu
  2818. *
  2819. */
  2820. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2821. /**
  2822. *
  2823. * "Temperature" > "Preheat Material 2 conf" submenu
  2824. *
  2825. */
  2826. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2827. /**
  2828. *
  2829. * "Control" > "Motion" submenu
  2830. *
  2831. */
  2832. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2833. #if ENABLED(DISTINCT_E_FACTORS)
  2834. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2835. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2836. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2837. #if E_STEPPERS > 2
  2838. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2839. #if E_STEPPERS > 3
  2840. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2841. #if E_STEPPERS > 4
  2842. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2843. #endif // E_STEPPERS > 4
  2844. #endif // E_STEPPERS > 3
  2845. #endif // E_STEPPERS > 2
  2846. #endif
  2847. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2848. #if ENABLED(DISTINCT_E_FACTORS)
  2849. void _planner_refresh_e_positioning(const uint8_t e) {
  2850. if (e == active_extruder)
  2851. _planner_refresh_positioning();
  2852. else
  2853. planner.steps_to_mm[E_AXIS + e] = 1.0 / planner.axis_steps_per_mm[E_AXIS + e];
  2854. }
  2855. void _planner_refresh_e0_positioning() { _planner_refresh_e_positioning(0); }
  2856. void _planner_refresh_e1_positioning() { _planner_refresh_e_positioning(1); }
  2857. #if E_STEPPERS > 2
  2858. void _planner_refresh_e2_positioning() { _planner_refresh_e_positioning(2); }
  2859. #if E_STEPPERS > 3
  2860. void _planner_refresh_e3_positioning() { _planner_refresh_e_positioning(3); }
  2861. #if E_STEPPERS > 4
  2862. void _planner_refresh_e4_positioning() { _planner_refresh_e_positioning(4); }
  2863. #endif // E_STEPPERS > 4
  2864. #endif // E_STEPPERS > 3
  2865. #endif // E_STEPPERS > 2
  2866. #endif
  2867. // M203 / M205 Velocity options
  2868. void lcd_control_motion_velocity_menu() {
  2869. START_MENU();
  2870. MENU_BACK(MSG_MOTION);
  2871. // M203 Max Feedrate
  2872. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2873. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2874. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2875. #if ENABLED(DISTINCT_E_FACTORS)
  2876. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2877. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2878. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2879. #if E_STEPPERS > 2
  2880. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2881. #if E_STEPPERS > 3
  2882. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2883. #if E_STEPPERS > 4
  2884. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2885. #endif // E_STEPPERS > 4
  2886. #endif // E_STEPPERS > 3
  2887. #endif // E_STEPPERS > 2
  2888. #else
  2889. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2890. #endif
  2891. // M205 S Min Feedrate
  2892. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2893. // M205 T Min Travel Feedrate
  2894. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2895. END_MENU();
  2896. }
  2897. // M201 / M204 Accelerations
  2898. void lcd_control_motion_acceleration_menu() {
  2899. START_MENU();
  2900. MENU_BACK(MSG_MOTION);
  2901. // M204 P Acceleration
  2902. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2903. // M204 R Retract Acceleration
  2904. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2905. // M204 T Travel Acceleration
  2906. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2907. // M201 settings
  2908. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2909. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2910. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2911. #if ENABLED(DISTINCT_E_FACTORS)
  2912. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2913. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2914. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2915. #if E_STEPPERS > 2
  2916. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2917. #if E_STEPPERS > 3
  2918. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2919. #if E_STEPPERS > 4
  2920. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2921. #endif // E_STEPPERS > 4
  2922. #endif // E_STEPPERS > 3
  2923. #endif // E_STEPPERS > 2
  2924. #else
  2925. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2926. #endif
  2927. END_MENU();
  2928. }
  2929. // M205 Jerk
  2930. void lcd_control_motion_jerk_menu() {
  2931. START_MENU();
  2932. MENU_BACK(MSG_MOTION);
  2933. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2934. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2935. #if ENABLED(DELTA)
  2936. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2937. #else
  2938. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2939. #endif
  2940. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2941. END_MENU();
  2942. }
  2943. // M92 Steps-per-mm
  2944. void lcd_control_motion_steps_per_mm_menu() {
  2945. START_MENU();
  2946. MENU_BACK(MSG_MOTION);
  2947. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2948. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2949. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2950. #if ENABLED(DISTINCT_E_FACTORS)
  2951. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2952. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2953. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2954. #if E_STEPPERS > 2
  2955. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2956. #if E_STEPPERS > 3
  2957. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2958. #if E_STEPPERS > 4
  2959. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2960. #endif // E_STEPPERS > 4
  2961. #endif // E_STEPPERS > 3
  2962. #endif // E_STEPPERS > 2
  2963. #else
  2964. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2965. #endif
  2966. END_MENU();
  2967. }
  2968. void lcd_control_motion_menu() {
  2969. START_MENU();
  2970. MENU_BACK(MSG_CONTROL);
  2971. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2972. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2973. #elif HAS_BED_PROBE
  2974. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2975. #endif
  2976. // M203 / M205 - Feedrate items
  2977. MENU_ITEM(submenu, MSG_VELOCITY, lcd_control_motion_velocity_menu);
  2978. // M201 - Acceleration items
  2979. MENU_ITEM(submenu, MSG_ACCELERATION, lcd_control_motion_acceleration_menu);
  2980. // M205 - Max Jerk
  2981. MENU_ITEM(submenu, MSG_JERK, lcd_control_motion_jerk_menu);
  2982. // M92 - Steps Per mm
  2983. MENU_ITEM(submenu, MSG_STEPS_PER_MM, lcd_control_motion_steps_per_mm_menu);
  2984. // M540 S - Abort on endstop hit when SD printing
  2985. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2986. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2987. #endif
  2988. END_MENU();
  2989. }
  2990. /**
  2991. *
  2992. * "Control" > "Filament" submenu
  2993. *
  2994. */
  2995. void lcd_control_filament_menu() {
  2996. START_MENU();
  2997. MENU_BACK(MSG_CONTROL);
  2998. #if ENABLED(LIN_ADVANCE)
  2999. MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
  3000. #endif
  3001. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  3002. if (volumetric_enabled) {
  3003. #if EXTRUDERS == 1
  3004. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  3005. #else // EXTRUDERS > 1
  3006. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  3007. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  3008. #if EXTRUDERS > 2
  3009. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  3010. #if EXTRUDERS > 3
  3011. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  3012. #if EXTRUDERS > 4
  3013. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  3014. #endif // EXTRUDERS > 4
  3015. #endif // EXTRUDERS > 3
  3016. #endif // EXTRUDERS > 2
  3017. #endif // EXTRUDERS > 1
  3018. }
  3019. END_MENU();
  3020. }
  3021. /**
  3022. *
  3023. * "Control" > "Retract" submenu
  3024. *
  3025. */
  3026. #if ENABLED(FWRETRACT)
  3027. void lcd_control_retract_menu() {
  3028. START_MENU();
  3029. MENU_BACK(MSG_CONTROL);
  3030. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  3031. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  3032. #if EXTRUDERS > 1
  3033. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &swap_retract_length, 0, 100);
  3034. #endif
  3035. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  3036. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  3037. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  3038. #if EXTRUDERS > 1
  3039. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &swap_retract_recover_length, -100, 100);
  3040. #endif
  3041. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  3042. END_MENU();
  3043. }
  3044. #endif // FWRETRACT
  3045. #if ENABLED(SDSUPPORT)
  3046. #if !PIN_EXISTS(SD_DETECT)
  3047. void lcd_sd_refresh() {
  3048. card.initsd();
  3049. encoderTopLine = 0;
  3050. }
  3051. #endif
  3052. void lcd_sd_updir() {
  3053. card.updir();
  3054. encoderTopLine = 0;
  3055. screen_changed = true;
  3056. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3057. }
  3058. /**
  3059. *
  3060. * "Print from SD" submenu
  3061. *
  3062. */
  3063. void lcd_sdcard_menu() {
  3064. ENCODER_DIRECTION_MENUS();
  3065. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  3066. const uint16_t fileCnt = card.get_num_Files();
  3067. START_MENU();
  3068. MENU_BACK(MSG_MAIN);
  3069. card.getWorkDirName();
  3070. if (card.filename[0] == '/') {
  3071. #if !PIN_EXISTS(SD_DETECT)
  3072. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  3073. #endif
  3074. }
  3075. else {
  3076. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  3077. }
  3078. if (fileCnt) {
  3079. for (uint16_t i = 0; i < fileCnt; i++) {
  3080. if (_menuLineNr == _thisItemNr) {
  3081. const uint16_t nr =
  3082. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  3083. fileCnt - 1 -
  3084. #endif
  3085. i;
  3086. #if ENABLED(SDCARD_SORT_ALPHA)
  3087. card.getfilename_sorted(nr);
  3088. #else
  3089. card.getfilename(nr);
  3090. #endif
  3091. if (card.filenameIsDir)
  3092. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3093. else
  3094. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3095. }
  3096. else {
  3097. MENU_ITEM_DUMMY();
  3098. }
  3099. }
  3100. }
  3101. END_MENU();
  3102. }
  3103. #endif // SDSUPPORT
  3104. #if ENABLED(LCD_INFO_MENU)
  3105. #if ENABLED(PRINTCOUNTER)
  3106. /**
  3107. *
  3108. * About Printer > Statistics submenu
  3109. *
  3110. */
  3111. void lcd_info_stats_menu() {
  3112. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3113. char buffer[21];
  3114. printStatistics stats = print_job_timer.getStats();
  3115. START_SCREEN(); // 12345678901234567890
  3116. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  3117. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  3118. duration_t elapsed = stats.printTime;
  3119. elapsed.toString(buffer);
  3120. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  3121. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3122. elapsed = stats.longestPrint;
  3123. elapsed.toString(buffer);
  3124. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  3125. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3126. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
  3127. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  3128. STATIC_ITEM("", false, false, buffer); // 125m
  3129. END_SCREEN();
  3130. }
  3131. #endif // PRINTCOUNTER
  3132. /**
  3133. *
  3134. * About Printer > Thermistors
  3135. *
  3136. */
  3137. void lcd_info_thermistors_menu() {
  3138. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3139. START_SCREEN();
  3140. #define THERMISTOR_ID TEMP_SENSOR_0
  3141. #include "thermistornames.h"
  3142. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  3143. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  3144. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  3145. #if TEMP_SENSOR_1 != 0
  3146. #undef THERMISTOR_ID
  3147. #define THERMISTOR_ID TEMP_SENSOR_1
  3148. #include "thermistornames.h"
  3149. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  3150. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  3151. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  3152. #endif
  3153. #if TEMP_SENSOR_2 != 0
  3154. #undef THERMISTOR_ID
  3155. #define THERMISTOR_ID TEMP_SENSOR_2
  3156. #include "thermistornames.h"
  3157. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  3158. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  3159. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  3160. #endif
  3161. #if TEMP_SENSOR_3 != 0
  3162. #undef THERMISTOR_ID
  3163. #define THERMISTOR_ID TEMP_SENSOR_3
  3164. #include "thermistornames.h"
  3165. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  3166. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  3167. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  3168. #endif
  3169. #if TEMP_SENSOR_4 != 0
  3170. #undef THERMISTOR_ID
  3171. #define THERMISTOR_ID TEMP_SENSOR_4
  3172. #include "thermistornames.h"
  3173. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  3174. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  3175. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  3176. #endif
  3177. #if TEMP_SENSOR_BED != 0
  3178. #undef THERMISTOR_ID
  3179. #define THERMISTOR_ID TEMP_SENSOR_BED
  3180. #include "thermistornames.h"
  3181. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  3182. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  3183. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  3184. #endif
  3185. END_SCREEN();
  3186. }
  3187. /**
  3188. *
  3189. * About Printer > Board Info
  3190. *
  3191. */
  3192. void lcd_info_board_menu() {
  3193. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3194. START_SCREEN();
  3195. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  3196. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  3197. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  3198. #if POWER_SUPPLY == 0
  3199. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  3200. #elif POWER_SUPPLY == 1
  3201. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  3202. #elif POWER_SUPPLY == 2
  3203. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  3204. #endif
  3205. END_SCREEN();
  3206. }
  3207. /**
  3208. *
  3209. * About Printer > Printer Info
  3210. *
  3211. */
  3212. void lcd_info_printer_menu() {
  3213. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3214. START_SCREEN();
  3215. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  3216. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  3217. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  3218. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  3219. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  3220. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  3221. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  3222. STATIC_ITEM(MSG_3POINT_LEVELING, true); // 3-Point Leveling
  3223. #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
  3224. STATIC_ITEM(MSG_LINEAR_LEVELING, true); // Linear Leveling
  3225. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  3226. STATIC_ITEM(MSG_BILINEAR_LEVELING, true); // Bi-linear Leveling
  3227. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  3228. STATIC_ITEM(MSG_UBL_LEVELING, true); // Unified Bed Leveling
  3229. #elif ENABLED(MESH_BED_LEVELING)
  3230. STATIC_ITEM(MSG_MESH_LEVELING, true); // Mesh Leveling
  3231. #endif
  3232. END_SCREEN();
  3233. }
  3234. /**
  3235. *
  3236. * "About Printer" submenu
  3237. *
  3238. */
  3239. void lcd_info_menu() {
  3240. START_MENU();
  3241. MENU_BACK(MSG_MAIN);
  3242. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  3243. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  3244. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  3245. #if ENABLED(PRINTCOUNTER)
  3246. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  3247. #endif
  3248. END_MENU();
  3249. }
  3250. #endif // LCD_INFO_MENU
  3251. /**
  3252. *
  3253. * Filament Change Feature Screens
  3254. *
  3255. */
  3256. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3257. // Portions from STATIC_ITEM...
  3258. #define HOTEND_STATUS_ITEM() do { \
  3259. if (_menuLineNr == _thisItemNr) { \
  3260. if (lcdDrawUpdate) { \
  3261. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  3262. lcd_implementation_hotend_status(_lcdLineNr); \
  3263. } \
  3264. if (_skipStatic && encoderLine <= _thisItemNr) { \
  3265. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  3266. ++encoderLine; \
  3267. } \
  3268. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  3269. } \
  3270. ++_thisItemNr; \
  3271. }while(0)
  3272. void lcd_advanced_pause_toocold_menu() {
  3273. START_MENU();
  3274. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  3275. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  3276. MENU_BACK(MSG_BACK);
  3277. #if LCD_HEIGHT > 4
  3278. STATIC_ITEM(" ");
  3279. #endif
  3280. HOTEND_STATUS_ITEM();
  3281. END_MENU();
  3282. }
  3283. void lcd_advanced_pause_resume_print() {
  3284. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  3285. }
  3286. void lcd_advanced_pause_extrude_more() {
  3287. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  3288. }
  3289. void lcd_advanced_pause_option_menu() {
  3290. START_MENU();
  3291. #if LCD_HEIGHT > 2
  3292. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  3293. #endif
  3294. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  3295. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_advanced_pause_extrude_more);
  3296. END_MENU();
  3297. }
  3298. void lcd_advanced_pause_init_message() {
  3299. START_SCREEN();
  3300. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3301. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  3302. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  3303. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  3304. #define __FC_LINES_A 3
  3305. #else
  3306. #define __FC_LINES_A 2
  3307. #endif
  3308. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  3309. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  3310. #define _FC_LINES_A (__FC_LINES_A + 1)
  3311. #else
  3312. #define _FC_LINES_A __FC_LINES_A
  3313. #endif
  3314. #if LCD_HEIGHT > _FC_LINES_A + 1
  3315. STATIC_ITEM(" ");
  3316. #endif
  3317. HOTEND_STATUS_ITEM();
  3318. END_SCREEN();
  3319. }
  3320. void lcd_advanced_pause_unload_message() {
  3321. START_SCREEN();
  3322. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3323. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  3324. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  3325. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  3326. #define __FC_LINES_B 3
  3327. #else
  3328. #define __FC_LINES_B 2
  3329. #endif
  3330. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  3331. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  3332. #define _FC_LINES_B (__FC_LINES_B + 1)
  3333. #else
  3334. #define _FC_LINES_B __FC_LINES_B
  3335. #endif
  3336. #if LCD_HEIGHT > _FC_LINES_B + 1
  3337. STATIC_ITEM(" ");
  3338. #endif
  3339. HOTEND_STATUS_ITEM();
  3340. END_SCREEN();
  3341. }
  3342. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  3343. START_SCREEN();
  3344. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3345. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  3346. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  3347. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  3348. #define _FC_LINES_C 3
  3349. #else
  3350. #define _FC_LINES_C 2
  3351. #endif
  3352. #if LCD_HEIGHT > _FC_LINES_C + 1
  3353. STATIC_ITEM(" ");
  3354. #endif
  3355. HOTEND_STATUS_ITEM();
  3356. END_SCREEN();
  3357. }
  3358. void lcd_advanced_pause_heat_nozzle() {
  3359. START_SCREEN();
  3360. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3361. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  3362. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3363. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  3364. #define _FC_LINES_D 3
  3365. #else
  3366. #define _FC_LINES_D 2
  3367. #endif
  3368. #if LCD_HEIGHT > _FC_LINES_D + 1
  3369. STATIC_ITEM(" ");
  3370. #endif
  3371. HOTEND_STATUS_ITEM();
  3372. END_SCREEN();
  3373. }
  3374. void lcd_advanced_pause_insert_message() {
  3375. START_SCREEN();
  3376. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3377. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  3378. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3379. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  3380. #define __FC_LINES_E 3
  3381. #else
  3382. #define __FC_LINES_E 2
  3383. #endif
  3384. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  3385. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  3386. #define _FC_LINES_E (__FC_LINES_E + 1)
  3387. #else
  3388. #define _FC_LINES_E __FC_LINES_E
  3389. #endif
  3390. #if LCD_HEIGHT > _FC_LINES_E + 1
  3391. STATIC_ITEM(" ");
  3392. #endif
  3393. HOTEND_STATUS_ITEM();
  3394. END_SCREEN();
  3395. }
  3396. void lcd_advanced_pause_load_message() {
  3397. START_SCREEN();
  3398. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3399. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  3400. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  3401. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  3402. #define __FC_LINES_F 3
  3403. #else
  3404. #define __FC_LINES_F 2
  3405. #endif
  3406. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  3407. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  3408. #define _FC_LINES_F (__FC_LINES_F + 1)
  3409. #else
  3410. #define _FC_LINES_F __FC_LINES_F
  3411. #endif
  3412. #if LCD_HEIGHT > _FC_LINES_F + 1
  3413. STATIC_ITEM(" ");
  3414. #endif
  3415. HOTEND_STATUS_ITEM();
  3416. END_SCREEN();
  3417. }
  3418. void lcd_advanced_pause_extrude_message() {
  3419. START_SCREEN();
  3420. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3421. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  3422. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  3423. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  3424. #define __FC_LINES_G 3
  3425. #else
  3426. #define __FC_LINES_G 2
  3427. #endif
  3428. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  3429. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  3430. #define _FC_LINES_G (__FC_LINES_G + 1)
  3431. #else
  3432. #define _FC_LINES_G __FC_LINES_G
  3433. #endif
  3434. #if LCD_HEIGHT > _FC_LINES_G + 1
  3435. STATIC_ITEM(" ");
  3436. #endif
  3437. HOTEND_STATUS_ITEM();
  3438. END_SCREEN();
  3439. }
  3440. void lcd_advanced_pause_resume_message() {
  3441. START_SCREEN();
  3442. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3443. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  3444. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  3445. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  3446. #endif
  3447. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  3448. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  3449. #endif
  3450. END_SCREEN();
  3451. }
  3452. void lcd_advanced_pause_show_message(const AdvancedPauseMessage message) {
  3453. switch (message) {
  3454. case ADVANCED_PAUSE_MESSAGE_INIT:
  3455. defer_return_to_status = true;
  3456. lcd_goto_screen(lcd_advanced_pause_init_message);
  3457. break;
  3458. case ADVANCED_PAUSE_MESSAGE_UNLOAD:
  3459. defer_return_to_status = true;
  3460. lcd_goto_screen(lcd_advanced_pause_unload_message);
  3461. break;
  3462. case ADVANCED_PAUSE_MESSAGE_INSERT:
  3463. defer_return_to_status = true;
  3464. lcd_goto_screen(lcd_advanced_pause_insert_message);
  3465. break;
  3466. case ADVANCED_PAUSE_MESSAGE_LOAD:
  3467. defer_return_to_status = true;
  3468. lcd_goto_screen(lcd_advanced_pause_load_message);
  3469. break;
  3470. case ADVANCED_PAUSE_MESSAGE_EXTRUDE:
  3471. defer_return_to_status = true;
  3472. lcd_goto_screen(lcd_advanced_pause_extrude_message);
  3473. break;
  3474. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  3475. defer_return_to_status = true;
  3476. lcd_goto_screen(lcd_advanced_pause_heat_nozzle);
  3477. break;
  3478. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  3479. defer_return_to_status = true;
  3480. lcd_goto_screen(lcd_advanced_pause_wait_for_nozzles_to_heat);
  3481. break;
  3482. case ADVANCED_PAUSE_MESSAGE_OPTION:
  3483. defer_return_to_status = true;
  3484. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  3485. lcd_goto_screen(lcd_advanced_pause_option_menu);
  3486. break;
  3487. case ADVANCED_PAUSE_MESSAGE_RESUME:
  3488. defer_return_to_status = true;
  3489. lcd_goto_screen(lcd_advanced_pause_resume_message);
  3490. break;
  3491. case ADVANCED_PAUSE_MESSAGE_STATUS:
  3492. lcd_return_to_status();
  3493. break;
  3494. }
  3495. }
  3496. #endif // ADVANCED_PAUSE_FEATURE
  3497. /**
  3498. *
  3499. * Functions for editing single values
  3500. *
  3501. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  3502. *
  3503. * For example, DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1) expands into these functions:
  3504. *
  3505. * bool _menu_edit_int3();
  3506. * void menu_edit_int3(); // edit int16_t (interactively)
  3507. * void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
  3508. * void _menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  3509. * void menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  3510. * void menu_action_setting_edit_callback_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback, const bool live); // edit int16_t with callback
  3511. *
  3512. * You can then use one of the menu macros to present the edit interface:
  3513. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  3514. *
  3515. * This expands into a more primitive menu item:
  3516. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3517. *
  3518. * ...which calls:
  3519. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3520. */
  3521. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  3522. bool _menu_edit_ ## _name() { \
  3523. ENCODER_DIRECTION_NORMAL(); \
  3524. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3525. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  3526. if (lcdDrawUpdate) \
  3527. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  3528. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  3529. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  3530. if (editValue != NULL) *((_type*)editValue) = value; \
  3531. if (liveEdit) (*callbackFunc)(); \
  3532. if (lcd_clicked) lcd_goto_previous_menu(); \
  3533. } \
  3534. return lcd_clicked; \
  3535. } \
  3536. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  3537. void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
  3538. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  3539. lcd_save_previous_screen(); \
  3540. \
  3541. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  3542. \
  3543. editLabel = pstr; \
  3544. editValue = ptr; \
  3545. minEditValue = minValue * _scale; \
  3546. maxEditValue = maxValue * _scale - minEditValue; \
  3547. encoderPosition = (*ptr) * _scale - minEditValue; \
  3548. } \
  3549. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  3550. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3551. currentScreen = menu_edit_ ## _name; \
  3552. } \
  3553. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  3554. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3555. currentScreen = menu_edit_callback_ ## _name; \
  3556. callbackFunc = callback; \
  3557. liveEdit = live; \
  3558. } \
  3559. typedef void _name
  3560. DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
  3561. DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
  3562. DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
  3563. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  3564. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  3565. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  3566. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  3567. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  3568. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  3569. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  3570. /**
  3571. *
  3572. * Handlers for Keypad input
  3573. *
  3574. */
  3575. #if ENABLED(ADC_KEYPAD)
  3576. inline bool handle_adc_keypad() {
  3577. static uint8_t adc_steps = 0;
  3578. if (buttons_reprapworld_keypad) {
  3579. if (adc_steps < 20) ++adc_steps;
  3580. lcd_quick_feedback();
  3581. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3582. if (encoderDirection == -1) { // side effect which signals we are inside a menu
  3583. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
  3584. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
  3585. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_LEFT) menu_action_back();
  3586. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) lcd_return_to_status();
  3587. }
  3588. else {
  3589. const int8_t step = adc_steps > 19 ? 100 : adc_steps > 10 ? 10 : 1;
  3590. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition += ENCODER_PULSES_PER_STEP * step;
  3591. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition -= ENCODER_PULSES_PER_STEP * step;
  3592. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) encoderPosition = 0;
  3593. }
  3594. #if ENABLED(ADC_KEYPAD_DEBUG)
  3595. SERIAL_PROTOCOLLNPAIR("buttons_reprapworld_keypad = ", (uint32_t)buttons_reprapworld_keypad);
  3596. SERIAL_PROTOCOLLNPAIR("encoderPosition = ", (uint32_t)encoderPosition);
  3597. #endif
  3598. return true;
  3599. }
  3600. else if (!thermalManager.current_ADCKey_raw)
  3601. adc_steps = 0; // reset stepping acceleration
  3602. return false;
  3603. }
  3604. #elif ENABLED(REPRAPWORLD_KEYPAD)
  3605. void _reprapworld_keypad_move(const AxisEnum axis, const int16_t dir) {
  3606. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  3607. encoderPosition = dir;
  3608. switch (axis) {
  3609. case X_AXIS: lcd_move_x(); break;
  3610. case Y_AXIS: lcd_move_y(); break;
  3611. case Z_AXIS: lcd_move_z();
  3612. default: break;
  3613. }
  3614. }
  3615. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  3616. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  3617. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  3618. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  3619. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  3620. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  3621. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  3622. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  3623. inline void handle_reprapworld_keypad() {
  3624. static uint8_t keypad_debounce = 0;
  3625. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  3626. if (keypad_debounce > 0) keypad_debounce--;
  3627. }
  3628. else if (!keypad_debounce) {
  3629. keypad_debounce = 2;
  3630. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  3631. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  3632. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3633. #endif
  3634. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  3635. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  3636. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3637. #endif
  3638. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  3639. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  3640. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  3641. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  3642. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  3643. }
  3644. else {
  3645. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  3646. }
  3647. }
  3648. }
  3649. #endif // REPRAPWORLD_KEYPAD
  3650. /**
  3651. *
  3652. * Menu actions
  3653. *
  3654. */
  3655. void _menu_action_back() { lcd_goto_previous_menu(); }
  3656. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  3657. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  3658. void menu_action_function(screenFunc_t func) { (*func)(); }
  3659. #if ENABLED(SDSUPPORT)
  3660. void menu_action_sdfile(const char* filename, char* longFilename) {
  3661. UNUSED(longFilename);
  3662. card.openAndPrintFile(filename);
  3663. lcd_return_to_status();
  3664. }
  3665. void menu_action_sddirectory(const char* filename, char* longFilename) {
  3666. UNUSED(longFilename);
  3667. card.chdir(filename);
  3668. encoderPosition = 0;
  3669. screen_changed = true;
  3670. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3671. }
  3672. #endif // SDSUPPORT
  3673. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  3674. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  3675. menu_action_setting_edit_bool(pstr, ptr);
  3676. (*callback)();
  3677. }
  3678. #endif // ULTIPANEL
  3679. void lcd_init() {
  3680. lcd_implementation_init(
  3681. #if ENABLED(LCD_PROGRESS_BAR)
  3682. true
  3683. #endif
  3684. );
  3685. #if ENABLED(NEWPANEL)
  3686. #if BUTTON_EXISTS(EN1)
  3687. SET_INPUT_PULLUP(BTN_EN1);
  3688. #endif
  3689. #if BUTTON_EXISTS(EN2)
  3690. SET_INPUT_PULLUP(BTN_EN2);
  3691. #endif
  3692. #if BUTTON_EXISTS(ENC)
  3693. SET_INPUT_PULLUP(BTN_ENC);
  3694. #endif
  3695. #if ENABLED(REPRAPWORLD_KEYPAD) && DISABLED(ADC_KEYPAD)
  3696. SET_OUTPUT(SHIFT_CLK);
  3697. OUT_WRITE(SHIFT_LD, HIGH);
  3698. SET_INPUT_PULLUP(SHIFT_OUT);
  3699. #endif
  3700. #if BUTTON_EXISTS(UP)
  3701. SET_INPUT(BTN_UP);
  3702. #endif
  3703. #if BUTTON_EXISTS(DWN)
  3704. SET_INPUT(BTN_DWN);
  3705. #endif
  3706. #if BUTTON_EXISTS(LFT)
  3707. SET_INPUT(BTN_LFT);
  3708. #endif
  3709. #if BUTTON_EXISTS(RT)
  3710. SET_INPUT(BTN_RT);
  3711. #endif
  3712. #else // !NEWPANEL
  3713. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  3714. SET_OUTPUT(SR_DATA_PIN);
  3715. SET_OUTPUT(SR_CLK_PIN);
  3716. #elif defined(SHIFT_CLK)
  3717. SET_OUTPUT(SHIFT_CLK);
  3718. OUT_WRITE(SHIFT_LD, HIGH);
  3719. OUT_WRITE(SHIFT_EN, LOW);
  3720. SET_INPUT_PULLUP(SHIFT_OUT);
  3721. #endif // SR_LCD_2W_NL
  3722. #endif // !NEWPANEL
  3723. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3724. SET_INPUT_PULLUP(SD_DETECT_PIN);
  3725. lcd_sd_status = 2; // UNKNOWN
  3726. #endif
  3727. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3728. slow_buttons = 0;
  3729. #endif
  3730. lcd_buttons_update();
  3731. #if ENABLED(ULTIPANEL)
  3732. encoderDiff = 0;
  3733. #endif
  3734. }
  3735. int16_t lcd_strlen(const char* s) {
  3736. int16_t i = 0, j = 0;
  3737. while (s[i]) {
  3738. if (PRINTABLE(s[i])) j++;
  3739. i++;
  3740. }
  3741. return j;
  3742. }
  3743. int16_t lcd_strlen_P(const char* s) {
  3744. int16_t j = 0;
  3745. while (pgm_read_byte(s)) {
  3746. if (PRINTABLE(pgm_read_byte(s))) j++;
  3747. s++;
  3748. }
  3749. return j;
  3750. }
  3751. bool lcd_blink() {
  3752. static uint8_t blink = 0;
  3753. static millis_t next_blink_ms = 0;
  3754. millis_t ms = millis();
  3755. if (ELAPSED(ms, next_blink_ms)) {
  3756. blink ^= 0xFF;
  3757. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  3758. }
  3759. return blink != 0;
  3760. }
  3761. /**
  3762. * Update the LCD, read encoder buttons, etc.
  3763. * - Read button states
  3764. * - Check the SD Card slot state
  3765. * - Act on RepRap World keypad input
  3766. * - Update the encoder position
  3767. * - Apply acceleration to the encoder position
  3768. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3769. * - Reset the Info Screen timeout if there's any input
  3770. * - Update status indicators, if any
  3771. *
  3772. * Run the current LCD menu handler callback function:
  3773. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3774. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3775. * - Call the menu handler. Menu handlers should do the following:
  3776. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3777. * (Encoder events automatically set lcdDrawUpdate for you.)
  3778. * - if (lcdDrawUpdate) { redraw }
  3779. * - Before exiting the handler set lcdDrawUpdate to:
  3780. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3781. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  3782. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  3783. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  3784. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3785. * so don't change lcdDrawUpdate without considering this.
  3786. *
  3787. * After the menu handler callback runs (or not):
  3788. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3789. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3790. *
  3791. * No worries. This function is only called from the main thread.
  3792. */
  3793. void lcd_update() {
  3794. #if ENABLED(ULTIPANEL)
  3795. static millis_t return_to_status_ms = 0;
  3796. manage_manual_move();
  3797. lcd_buttons_update();
  3798. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3799. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3800. #else
  3801. constexpr bool UBL_CONDITION = true;
  3802. #endif
  3803. // If the action button is pressed...
  3804. if (UBL_CONDITION && LCD_CLICKED) {
  3805. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3806. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3807. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3808. wait_for_user = false; // Any click clears wait for user
  3809. lcd_quick_feedback(); // Always make a click sound
  3810. }
  3811. }
  3812. else wait_for_unclick = false;
  3813. #endif
  3814. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3815. const bool sd_status = IS_SD_INSERTED;
  3816. if (sd_status != lcd_sd_status && lcd_detected()) {
  3817. if (sd_status) {
  3818. card.initsd();
  3819. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3820. }
  3821. else {
  3822. card.release();
  3823. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3824. }
  3825. lcd_sd_status = sd_status;
  3826. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3827. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3828. #if ENABLED(LCD_PROGRESS_BAR)
  3829. currentScreen == lcd_status_screen
  3830. #endif
  3831. );
  3832. }
  3833. #endif // SDSUPPORT && SD_DETECT_PIN
  3834. const millis_t ms = millis();
  3835. if (ELAPSED(ms, next_lcd_update_ms)
  3836. #if ENABLED(DOGLCD)
  3837. || drawing_screen
  3838. #endif
  3839. ) {
  3840. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3841. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3842. lcd_implementation_update_indicators();
  3843. #endif
  3844. #if ENABLED(ULTIPANEL)
  3845. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3846. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3847. #endif
  3848. #if ENABLED(ADC_KEYPAD)
  3849. if (handle_adc_keypad())
  3850. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3851. #elif ENABLED(REPRAPWORLD_KEYPAD)
  3852. handle_reprapworld_keypad();
  3853. #endif
  3854. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3855. if (encoderPastThreshold || lcd_clicked) {
  3856. if (encoderPastThreshold) {
  3857. int32_t encoderMultiplier = 1;
  3858. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3859. if (encoderRateMultiplierEnabled) {
  3860. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3861. if (lastEncoderMovementMillis) {
  3862. // Note that the rate is always calculated between two passes through the
  3863. // loop and that the abs of the encoderDiff value is tracked.
  3864. float encoderStepRate = float(encoderMovementSteps) / float(ms - lastEncoderMovementMillis) * 1000.0;
  3865. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3866. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3867. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3868. SERIAL_ECHO_START();
  3869. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3870. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3871. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3872. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3873. SERIAL_EOL();
  3874. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  3875. }
  3876. lastEncoderMovementMillis = ms;
  3877. } // encoderRateMultiplierEnabled
  3878. #endif // ENCODER_RATE_MULTIPLIER
  3879. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3880. encoderDiff = 0;
  3881. }
  3882. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3883. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3884. }
  3885. #endif // ULTIPANEL
  3886. // We arrive here every ~100ms when idling often enough.
  3887. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3888. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3889. if (
  3890. #if ENABLED(ULTIPANEL)
  3891. currentScreen == lcd_status_screen &&
  3892. #endif
  3893. !lcd_status_update_delay--
  3894. ) {
  3895. lcd_status_update_delay = 9
  3896. #if ENABLED(DOGLCD)
  3897. + 3
  3898. #endif
  3899. ;
  3900. max_display_update_time--;
  3901. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3902. }
  3903. // then we want to use 1/2 of the time only.
  3904. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3905. #if ENABLED(DOGLCD)
  3906. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3907. #else
  3908. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3909. #endif
  3910. {
  3911. #if ENABLED(DOGLCD)
  3912. if (!drawing_screen)
  3913. #endif
  3914. {
  3915. switch (lcdDrawUpdate) {
  3916. case LCDVIEW_CALL_NO_REDRAW:
  3917. lcdDrawUpdate = LCDVIEW_NONE;
  3918. break;
  3919. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3920. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3921. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3922. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3923. case LCDVIEW_NONE:
  3924. break;
  3925. } // switch
  3926. }
  3927. #if ENABLED(ADC_KEYPAD)
  3928. buttons_reprapworld_keypad = 0;
  3929. #endif
  3930. #if ENABLED(ULTIPANEL)
  3931. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3932. #else
  3933. #define CURRENTSCREEN() lcd_status_screen()
  3934. #endif
  3935. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3936. if (!drawing_screen) {
  3937. u8g.firstPage();
  3938. drawing_screen = 1;
  3939. }
  3940. lcd_setFont(FONT_MENU);
  3941. u8g.setColorIndex(1);
  3942. CURRENTSCREEN();
  3943. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3944. NOLESS(max_display_update_time, millis() - ms);
  3945. return;
  3946. }
  3947. #else
  3948. CURRENTSCREEN();
  3949. #endif
  3950. NOLESS(max_display_update_time, millis() - ms);
  3951. }
  3952. #if ENABLED(ULTIPANEL)
  3953. // Return to Status Screen after a timeout
  3954. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3955. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3956. else if (ELAPSED(ms, return_to_status_ms))
  3957. lcd_return_to_status();
  3958. #endif // ULTIPANEL
  3959. #if ENABLED(DOGLCD)
  3960. if (!drawing_screen)
  3961. #endif
  3962. {
  3963. switch (lcdDrawUpdate) {
  3964. case LCDVIEW_CLEAR_CALL_REDRAW:
  3965. lcd_implementation_clear();
  3966. case LCDVIEW_CALL_REDRAW_NEXT:
  3967. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3968. break;
  3969. case LCDVIEW_REDRAW_NOW:
  3970. lcdDrawUpdate = LCDVIEW_NONE;
  3971. break;
  3972. case LCDVIEW_NONE:
  3973. break;
  3974. } // switch
  3975. }
  3976. } // ELAPSED(ms, next_lcd_update_ms)
  3977. }
  3978. void pad_message_string() {
  3979. uint8_t i = 0, j = 0;
  3980. char c;
  3981. while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
  3982. if (PRINTABLE(c)) j++;
  3983. i++;
  3984. }
  3985. if (true
  3986. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3987. && j < LCD_WIDTH
  3988. #endif
  3989. ) {
  3990. // pad with spaces to fill up the line
  3991. while (j++ < LCD_WIDTH) lcd_status_message[i++] = ' ';
  3992. // chop off at the edge
  3993. lcd_status_message[i] = '\0';
  3994. }
  3995. }
  3996. void lcd_finishstatus(const bool persist=false) {
  3997. pad_message_string();
  3998. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3999. UNUSED(persist);
  4000. #endif
  4001. #if ENABLED(LCD_PROGRESS_BAR)
  4002. progress_bar_ms = millis();
  4003. #if PROGRESS_MSG_EXPIRE > 0
  4004. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  4005. #endif
  4006. #endif
  4007. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  4008. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  4009. previous_lcd_status_ms = millis(); //get status message to show up for a while
  4010. #endif
  4011. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  4012. status_scroll_pos = 0;
  4013. #endif
  4014. }
  4015. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  4016. void dontExpireStatus() { expire_status_ms = 0; }
  4017. #endif
  4018. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  4019. void lcd_setstatus(const char * const message, const bool persist) {
  4020. if (lcd_status_message_level > 0) return;
  4021. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  4022. lcd_finishstatus(persist);
  4023. }
  4024. void lcd_setstatusPGM(const char * const message, int8_t level) {
  4025. if (level < 0) level = lcd_status_message_level = 0;
  4026. if (level < lcd_status_message_level) return;
  4027. lcd_status_message_level = level;
  4028. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  4029. lcd_finishstatus(level > 0);
  4030. }
  4031. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  4032. if (level < lcd_status_message_level) return;
  4033. lcd_status_message_level = level;
  4034. va_list args;
  4035. va_start(args, fmt);
  4036. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  4037. va_end(args);
  4038. lcd_finishstatus(level > 0);
  4039. }
  4040. void lcd_setalertstatusPGM(const char * const message) {
  4041. lcd_setstatusPGM(message, 1);
  4042. #if ENABLED(ULTIPANEL)
  4043. lcd_return_to_status();
  4044. #endif
  4045. }
  4046. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  4047. #if HAS_LCD_CONTRAST
  4048. void set_lcd_contrast(const uint16_t value) {
  4049. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  4050. u8g.setContrast(lcd_contrast);
  4051. }
  4052. #endif
  4053. #if ENABLED(ULTIPANEL)
  4054. /**
  4055. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  4056. * These values are independent of which pins are used for EN_A and EN_B indications
  4057. * The rotary encoder part is also independent to the chipset used for the LCD
  4058. */
  4059. #if defined(EN_A) && defined(EN_B)
  4060. #define encrot0 0
  4061. #define encrot1 2
  4062. #define encrot2 3
  4063. #define encrot3 1
  4064. #endif
  4065. #define GET_BUTTON_STATES(DST) \
  4066. uint8_t new_##DST = 0; \
  4067. WRITE(SHIFT_LD, LOW); \
  4068. WRITE(SHIFT_LD, HIGH); \
  4069. for (int8_t i = 0; i < 8; i++) { \
  4070. new_##DST >>= 1; \
  4071. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  4072. WRITE(SHIFT_CLK, HIGH); \
  4073. WRITE(SHIFT_CLK, LOW); \
  4074. } \
  4075. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  4076. /**
  4077. * Read encoder buttons from the hardware registers
  4078. * Warning: This function is called from interrupt context!
  4079. */
  4080. void lcd_buttons_update() {
  4081. static uint8_t lastEncoderBits;
  4082. millis_t now = millis();
  4083. if (ELAPSED(now, next_button_update_ms)) {
  4084. #if ENABLED(NEWPANEL)
  4085. uint8_t newbutton = 0;
  4086. #if BUTTON_EXISTS(EN1)
  4087. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  4088. #endif
  4089. #if BUTTON_EXISTS(EN2)
  4090. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  4091. #endif
  4092. #if BUTTON_EXISTS(ENC)
  4093. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  4094. #endif
  4095. #if LCD_HAS_DIRECTIONAL_BUTTONS
  4096. // Manage directional buttons
  4097. #if ENABLED(REVERSE_MENU_DIRECTION)
  4098. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  4099. #else
  4100. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  4101. #endif
  4102. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  4103. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  4104. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  4105. #else
  4106. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  4107. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  4108. #endif
  4109. if (false) {
  4110. // for the else-ifs below
  4111. }
  4112. #if BUTTON_EXISTS(UP)
  4113. else if (BUTTON_PRESSED(UP)) {
  4114. encoderDiff = -(ENCODER_UD_STEPS);
  4115. next_button_update_ms = now + 300;
  4116. }
  4117. #endif
  4118. #if BUTTON_EXISTS(DWN)
  4119. else if (BUTTON_PRESSED(DWN)) {
  4120. encoderDiff = ENCODER_UD_STEPS;
  4121. next_button_update_ms = now + 300;
  4122. }
  4123. #endif
  4124. #if BUTTON_EXISTS(LFT)
  4125. else if (BUTTON_PRESSED(LFT)) {
  4126. encoderDiff = -(ENCODER_LR_PULSES);
  4127. next_button_update_ms = now + 300;
  4128. }
  4129. #endif
  4130. #if BUTTON_EXISTS(RT)
  4131. else if (BUTTON_PRESSED(RT)) {
  4132. encoderDiff = ENCODER_LR_PULSES;
  4133. next_button_update_ms = now + 300;
  4134. }
  4135. #endif
  4136. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  4137. buttons = newbutton;
  4138. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  4139. buttons |= slow_buttons;
  4140. #endif
  4141. #if ENABLED(ADC_KEYPAD)
  4142. uint8_t newbutton_reprapworld_keypad = 0;
  4143. buttons = 0;
  4144. if (buttons_reprapworld_keypad == 0) {
  4145. newbutton_reprapworld_keypad = get_ADC_keyValue();
  4146. if (WITHIN(newbutton_reprapworld_keypad, 1, 8))
  4147. buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1);
  4148. }
  4149. #elif ENABLED(REPRAPWORLD_KEYPAD)
  4150. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  4151. #endif
  4152. #else
  4153. GET_BUTTON_STATES(buttons);
  4154. #endif // !NEWPANEL
  4155. } // next_button_update_ms
  4156. // Manage encoder rotation
  4157. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  4158. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  4159. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  4160. #elif ENABLED(REVERSE_MENU_DIRECTION)
  4161. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  4162. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  4163. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  4164. #define ENCODER_DIFF_CW (encoderDiff--)
  4165. #define ENCODER_DIFF_CCW (encoderDiff++)
  4166. #else
  4167. #define ENCODER_DIFF_CW (encoderDiff++)
  4168. #define ENCODER_DIFF_CCW (encoderDiff--)
  4169. #endif
  4170. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  4171. uint8_t enc = 0;
  4172. if (buttons & EN_A) enc |= B01;
  4173. if (buttons & EN_B) enc |= B10;
  4174. if (enc != lastEncoderBits) {
  4175. switch (enc) {
  4176. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  4177. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  4178. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  4179. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  4180. }
  4181. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4182. if (ubl.has_control_of_lcd_panel) {
  4183. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  4184. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  4185. // knob has not turned.
  4186. }
  4187. #endif
  4188. lastEncoderBits = enc;
  4189. }
  4190. }
  4191. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  4192. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  4193. #else
  4194. bool lcd_detected() { return true; }
  4195. #endif
  4196. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4197. void chirp_at_user() {
  4198. #if ENABLED(LCD_USE_I2C_BUZZER)
  4199. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4200. #elif PIN_EXISTS(BEEPER)
  4201. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4202. #endif
  4203. }
  4204. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  4205. #endif
  4206. #endif // ULTIPANEL
  4207. #if ENABLED(ADC_KEYPAD)
  4208. typedef struct {
  4209. uint16_t ADCKeyValueMin, ADCKeyValueMax;
  4210. uint8_t ADCKeyNo;
  4211. } _stADCKeypadTable_;
  4212. static const _stADCKeypadTable_ stADCKeyTable[] PROGMEM = {
  4213. // VALUE_MIN, VALUE_MAX, KEY
  4214. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F1 + 1 }, // F1
  4215. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F2 + 1 }, // F2
  4216. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F3 + 1 }, // F3
  4217. { 300, 500, BLEN_REPRAPWORLD_KEYPAD_LEFT + 1 }, // LEFT
  4218. { 1900, 2200, BLEN_REPRAPWORLD_KEYPAD_RIGHT + 1 }, // RIGHT
  4219. { 570, 870, BLEN_REPRAPWORLD_KEYPAD_UP + 1 }, // UP
  4220. { 2670, 2870, BLEN_REPRAPWORLD_KEYPAD_DOWN + 1 }, // DOWN
  4221. { 1150, 1450, BLEN_REPRAPWORLD_KEYPAD_MIDDLE + 1 }, // ENTER
  4222. };
  4223. uint8_t get_ADC_keyValue(void) {
  4224. if (thermalManager.ADCKey_count >= 16) {
  4225. const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2;
  4226. #if ENABLED(ADC_KEYPAD_DEBUG)
  4227. SERIAL_PROTOCOLLN(currentkpADCValue);
  4228. #endif
  4229. thermalManager.current_ADCKey_raw = 0;
  4230. thermalManager.ADCKey_count = 0;
  4231. if (currentkpADCValue < 4000)
  4232. for (uint8_t i = 0; i < ADC_KEY_NUM; i++) {
  4233. const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
  4234. hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
  4235. if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);
  4236. }
  4237. }
  4238. return 0;
  4239. }
  4240. #endif
  4241. #endif // ULTRA_LCD