My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 212KB

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