My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 199KB

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