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

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