ultralcd.cpp 200 KB

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