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 199KB

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