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

ultralcd.cpp 192KB

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