My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd.cpp 210KB

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