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

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