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

ultralcd.cpp 202KB

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