ultralcd.cpp 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803
  1. //! @file
  2. //! @date Aug 28, 2019
  3. //! @author mkbel
  4. //! @brief LCD
  5. #include "temperature.h"
  6. #include "ultralcd.h"
  7. #include "conv2str.h"
  8. #include "Marlin.h"
  9. #include "language.h"
  10. #include "cardreader.h"
  11. #include "fancheck.h"
  12. #include "stepper.h"
  13. #include "ConfigurationStore.h"
  14. #include "printers.h"
  15. #include <string.h>
  16. #include "lcd.h"
  17. #include "menu.h"
  18. #include "backlight.h"
  19. #include "util.h"
  20. #include "mesh_bed_leveling.h"
  21. #include "mesh_bed_calibration.h"
  22. //#include "Configuration.h"
  23. #include "cmdqueue.h"
  24. #include "Filament_sensor.h"
  25. #ifdef TMC2130
  26. #include "tmc2130.h"
  27. #endif //TMC2130
  28. #include "sound.h"
  29. #include "mmu2.h"
  30. #include "SpoolJoin.h"
  31. #include "static_assert.h"
  32. #include "first_lay_cal.h"
  33. #include "adc.h"
  34. #include "config.h"
  35. #ifndef LA_NOCOMPAT
  36. #include "la10compat.h"
  37. #endif
  38. #include "Prusa_farm.h"
  39. int clock_interval = 0;
  40. static void lcd_sd_updir();
  41. static void lcd_mesh_bed_leveling_settings();
  42. #ifdef LCD_BL_PIN
  43. static void lcd_backlight_menu();
  44. #endif
  45. int8_t ReInitLCD = 0;
  46. uint8_t scrollstuff = 0;
  47. int8_t SilentModeMenu = SILENT_MODE_OFF;
  48. uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode
  49. int8_t FSensorStateMenu = 1;
  50. LcdCommands lcd_commands_type = LcdCommands::Idle;
  51. static uint8_t lcd_commands_step = 0;
  52. CustomMsg custom_message_type = CustomMsg::Status;
  53. uint8_t custom_message_state = 0;
  54. bool isPrintPaused = false;
  55. static ShortTimer display_time; //just timer for showing pid finished message on lcd;
  56. static uint16_t pid_temp = DEFAULT_PID_TEMP;
  57. static float manual_feedrate[] = MANUAL_FEEDRATE;
  58. /* LCD message status */
  59. static LongTimer lcd_status_message_timeout;
  60. static uint8_t lcd_status_message_level;
  61. static char lcd_status_message[LCD_WIDTH + 1];
  62. /* !Configuration settings */
  63. static uint8_t lay1cal_filament = 0;
  64. static const char separator[] PROGMEM = "--------------------";
  65. /** forward declarations **/
  66. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg);
  67. // void copy_and_scalePID_i();
  68. // void copy_and_scalePID_d();
  69. /* Different menus */
  70. //static void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  71. #if (LANG_MODE != 0)
  72. static void lcd_language_menu();
  73. #endif
  74. static void lcd_main_menu();
  75. static void lcd_tune_menu();
  76. //static void lcd_move_menu();
  77. static void lcd_settings_menu();
  78. static void lcd_calibration_menu();
  79. static void lcd_control_temperature_menu();
  80. #ifdef TMC2130
  81. static void lcd_settings_linearity_correction_menu_save();
  82. #endif
  83. static void lcd_menu_xyz_y_min();
  84. static void lcd_menu_xyz_skew();
  85. static void lcd_menu_xyz_offset();
  86. static void lcd_menu_fails_stats_mmu();
  87. static void lcd_menu_fails_stats_mmu_print();
  88. static void lcd_menu_fails_stats_mmu_total();
  89. static void lcd_menu_toolchange_stats_mmu_total();
  90. static void mmu_unload_filament();
  91. static void lcd_v2_calibration();
  92. //static void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  93. static void mmu_fil_eject_menu();
  94. static void mmu_load_to_nozzle_menu();
  95. static void mmu_loading_test_menu();
  96. static void preheat_or_continue();
  97. #ifdef MMU_HAS_CUTTER
  98. static void mmu_cut_filament_menu();
  99. #endif //MMU_HAS_CUTTER
  100. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  101. static void lcd_menu_fails_stats();
  102. #endif //TMC2130 or FILAMENT_SENSOR
  103. #ifdef TMC2130
  104. static void lcd_belttest_v();
  105. #endif //TMC2130
  106. static void lcd_selftest_v();
  107. #ifdef TMC2130
  108. static void reset_crash_det(uint8_t axis);
  109. static bool lcd_selfcheck_axis_sg(uint8_t axis);
  110. #else
  111. static bool lcd_selfcheck_axis(int _axis, int _travel);
  112. static bool lcd_selfcheck_pulleys(int axis);
  113. #endif //TMC2130
  114. static bool lcd_selfcheck_endstops();
  115. static bool lcd_selfcheck_check_heater(bool _isbed);
  116. enum class TestScreen : uint_least8_t
  117. {
  118. ExtruderFan,
  119. PrintFan,
  120. FansOk,
  121. EndStops,
  122. AxisX,
  123. AxisY,
  124. AxisZ,
  125. Bed,
  126. Hotend,
  127. HotendOk,
  128. Fsensor,
  129. FsensorOk,
  130. AllCorrect,
  131. Failed,
  132. Home,
  133. };
  134. enum class TestError : uint_least8_t
  135. {
  136. Heater,
  137. Bed,
  138. Endstops,
  139. Motor,
  140. Endstop,
  141. PrintFan,
  142. ExtruderFan,
  143. Pulley,
  144. Axis,
  145. SwappedFan,
  146. WiringFsensor,
  147. TriggeringFsensor,
  148. FsensorLevel
  149. };
  150. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay);
  151. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name, const char *_indicator);
  152. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  153. bool _default=false);
  154. #ifdef FANCHECK
  155. /** Enumerate for lcd_selftest_fan_auto function.
  156. */
  157. enum class FanCheck : uint_least8_t {
  158. Success,
  159. PrintFan,
  160. ExtruderFan,
  161. SwappedFan,
  162. };
  163. /**
  164. * Try to check fan working and wiring.
  165. *
  166. * @param _fan i fan number 0 means hotend fan, 1 means print fan.
  167. *
  168. * @returns a TestError noerror, extruderFan, printFan or swappedFan.
  169. */
  170. static FanCheck lcd_selftest_fan_auto(uint8_t _fan);
  171. #endif //FANCHECK
  172. #ifdef FILAMENT_SENSOR
  173. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  174. static bool lcd_selftest_fsensor();
  175. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR
  176. static bool selftest_irsensor();
  177. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
  178. static bool selftest_irsensor();
  179. static bool lcd_selftest_IRsensor(bool bStandalone=false);
  180. static void lcd_detect_IRsensor();
  181. #endif
  182. #endif //FILAMENT_SENSOR
  183. static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2);
  184. static void lcd_colorprint_change();
  185. static void lcd_disable_farm_mode();
  186. static void lcd_set_fan_check();
  187. #ifdef MMU_HAS_CUTTER
  188. static void lcd_cutter_enabled();
  189. #endif
  190. #ifdef SDCARD_SORT_ALPHA
  191. static void lcd_sort_type_set();
  192. #endif
  193. static void lcd_babystep_z();
  194. static void lcd_sdcard_menu();
  195. static void lcd_sheet_menu();
  196. #ifdef DELTA_CALIBRATION_MENU
  197. static void lcd_delta_calibrate_menu();
  198. #endif // DELTA_CALIBRATION_MENU
  199. /* Different types of actions that can be used in menu items. */
  200. static void menu_action_sdfile(const char* filename);
  201. static void menu_action_sddirectory(const char* filename);
  202. #define ENCODER_FEEDRATE_DEADZONE 10
  203. #define STATE_NA 255
  204. #define STATE_OFF 0
  205. #define STATE_ON 1
  206. /*
  207. #define MENU_ITEM(type, label, args...) do { \
  208. if (menu_item == menu_line) { \
  209. if (lcd_draw_update) { \
  210. const char* _label_pstr = (label); \
  211. if (lcd_encoder == menu_item) { \
  212. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  213. }else{\
  214. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  215. }\
  216. }\
  217. if (menu_clicked && (lcd_encoder == menu_item)) {\
  218. lcd_quick_feedback(); \
  219. menu_action_ ## type ( args ); \
  220. return;\
  221. }\
  222. }\
  223. menu_item++;\
  224. } while(0)
  225. */
  226. #if (SDCARDDETECT > 0)
  227. bool lcd_oldcardstatus;
  228. #endif
  229. uint8_t selected_sheet = 0;
  230. bool ignore_click = false;
  231. bool wait_for_unclick;
  232. // place-holders for Ki and Kd edits
  233. #ifdef PIDTEMP
  234. // float raw_Ki, raw_Kd;
  235. #endif
  236. bool bMain; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  237. bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function
  238. const char STR_SEPARATOR[] PROGMEM = "------------";
  239. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename)
  240. {
  241. uint8_t len = LCD_WIDTH - 1;
  242. lcd_set_cursor(0, row);
  243. lcd_print((lcd_encoder == menu_item)?'>':' ');
  244. lcd_print_pad(longFilename, len);
  245. }
  246. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* longFilename)
  247. {
  248. uint8_t len = LCD_WIDTH - 2;
  249. lcd_set_cursor(0, row);
  250. lcd_print((lcd_encoder == menu_item)?'>':' ');
  251. lcd_print(LCD_STR_FOLDER[0]);
  252. lcd_print_pad(longFilename, len);
  253. }
  254. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  255. #define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0)
  256. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  257. {
  258. if (menu_item == menu_line)
  259. {
  260. if (lcd_draw_update)
  261. {
  262. lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  263. }
  264. if (menu_clicked && (lcd_encoder == menu_item))
  265. {
  266. menu_clicked = false;
  267. lcd_consume_click();
  268. lcd_update_enabled = false;
  269. menu_action_sddirectory(str_fn);
  270. lcd_update_enabled = true;
  271. return menu_item_ret();
  272. }
  273. }
  274. menu_item++;
  275. return 0;
  276. }
  277. static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
  278. {
  279. if (menu_item == menu_line)
  280. {
  281. if (lcd_draw_update)
  282. {
  283. lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  284. }
  285. if (menu_clicked && (lcd_encoder == menu_item))
  286. {
  287. menu_clicked = false;
  288. lcd_consume_click();
  289. lcd_update_enabled = false;
  290. menu_action_sdfile(str_fn);
  291. lcd_update_enabled = true;
  292. return menu_item_ret();
  293. }
  294. }
  295. menu_item++;
  296. return 0;
  297. }
  298. // Print temperature (nozzle/bed) (9 chars total)
  299. void lcdui_print_temp(char type, int val_current, int val_target)
  300. {
  301. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  302. lcd_space(9 - chars);
  303. }
  304. // Print Z-coordinate (8 chars total)
  305. void lcdui_print_Z_coord(void)
  306. {
  307. if (custom_message_type == CustomMsg::MeshBedLeveling)
  308. lcd_puts_P(_N("Z --- "));
  309. else
  310. lcd_printf_P(_N("Z%6.2f%c"), current_position[Z_AXIS], axis_known_position[Z_AXIS]?' ':'?');
  311. }
  312. #ifdef PLANNER_DIAGNOSTICS
  313. // Print planner diagnostics (8 chars total)
  314. void lcdui_print_planner_diag(void)
  315. {
  316. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  317. lcd_print(LCD_STR_FEEDRATE[0]);
  318. lcd_print(itostr3(feedmultiply));
  319. lcd_puts_P(PSTR("% Q"));
  320. {
  321. uint8_t queue = planner_queue_min();
  322. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  323. lcd_putc('!');
  324. else
  325. {
  326. lcd_putc((char)(queue / 10) + '0');
  327. queue %= 10;
  328. }
  329. lcd_putc((char)queue + '0');
  330. planner_queue_min_reset();
  331. }
  332. }
  333. #endif // PLANNER_DIAGNOSTICS
  334. // Print feedrate (8 chars total)
  335. void lcdui_print_feedrate(void)
  336. {
  337. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  338. lcd_space(8 - chars);
  339. }
  340. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  341. void lcdui_print_percent_done(void)
  342. {
  343. const char* src = usb_timer.running()?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  344. char per[4];
  345. bool num = IS_SD_PRINTING || (printer_active() && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  346. if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating
  347. {
  348. const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  349. const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
  350. if ((nextSheet >= 0) && (sheetNR != nextSheet))
  351. {
  352. char sheet[8];
  353. eeprom_read_block(sheet, EEPROM_Sheets_base->s[sheetNR].name, 7);
  354. sheet[7] = '\0';
  355. lcd_printf_P(PSTR("%-7s"),sheet);
  356. return; //do not also print the percentage
  357. }
  358. }
  359. sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done());
  360. lcd_printf_P(_N("%3S%3s%%"), src, per);
  361. }
  362. // Print extruder status (5 chars total)
  363. // Scenario 1: "F?"
  364. // There is no filament loaded and no tool change is in progress
  365. // Scenario 2: "F[nr.]"
  366. // [nr.] ranges from 1 to 5.
  367. // Shows which filament is loaded. No tool change is in progress
  368. // Scenario 3: "?>[nr.]"
  369. // [nr.] ranges from 1 to 5.
  370. // There is no filament currently loaded, but [nr.] is currently being loaded via tool change
  371. // Scenario 4: "[nr.]>?"
  372. // [nr.] ranges from 1 to 5.
  373. // This scenario indicates a bug in the firmware if ? is on the right side
  374. // Scenario 5: "[nr1.]>[nr2.]"
  375. // [nr1.] ranges from 1 to 5.
  376. // [nr2.] ranges from 1 to 5.
  377. // Filament [nr1.] was loaded, but [nr2.] is currently being loaded via tool change
  378. // Scenario 6: "?>?"
  379. // This scenario should not be possible and indicates a bug in the firmware
  380. uint8_t lcdui_print_extruder(void) {
  381. uint8_t chars = 1;
  382. lcd_space(1);
  383. if (MMU2::mmu2.get_current_tool() == MMU2::mmu2.get_tool_change_tool()) {
  384. lcd_putc('F');
  385. lcd_putc(MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_current_tool() + '1');
  386. chars += 2;
  387. } else {
  388. lcd_putc(MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_current_tool() + '1');
  389. lcd_putc('>');
  390. lcd_putc(MMU2::mmu2.get_tool_change_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_tool_change_tool() + '1');
  391. chars += 3;
  392. }
  393. return chars;
  394. }
  395. // Print farm number (5 chars total)
  396. static void lcdui_print_farm(void)
  397. {
  398. lcd_printf_P(_N(" FRM "));
  399. }
  400. #ifdef CMD_DIAGNOSTICS
  401. // Print CMD queue diagnostic (8 chars total)
  402. void lcdui_print_cmd_diag(void)
  403. {
  404. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  405. lcd_puts_P(PSTR(" C"));
  406. lcd_print(buflen); // number of commands in cmd buffer
  407. if (buflen < 9) lcd_print(' ');
  408. }
  409. #endif //CMD_DIAGNOSTICS
  410. // Print time (8 chars total)
  411. void lcdui_print_time(void)
  412. {
  413. //if remaining print time estimation is available print it else print elapsed time
  414. int chars = 0;
  415. if (printer_active()) {
  416. uint16_t print_t = PRINT_TIME_REMAINING_INIT;
  417. uint16_t print_tr = PRINT_TIME_REMAINING_INIT;
  418. uint16_t print_tc = PRINT_TIME_REMAINING_INIT;
  419. char suff = ' ';
  420. char suff_doubt = ' ';
  421. #ifdef TMC2130
  422. if (SilentModeMenu != SILENT_MODE_OFF) {
  423. if (print_time_remaining_silent != PRINT_TIME_REMAINING_INIT)
  424. print_tr = print_time_remaining_silent;
  425. //#ifdef CLOCK_INTERVAL_TIME
  426. if (print_time_to_change_silent != PRINT_TIME_REMAINING_INIT)
  427. print_tc = print_time_to_change_silent;
  428. //#endif //CLOCK_INTERVAL_TIME
  429. } else {
  430. #endif //TMC2130
  431. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  432. print_tr = print_time_remaining_normal;
  433. //#ifdef CLOCK_INTERVAL_TIME
  434. if (print_time_to_change_normal != PRINT_TIME_REMAINING_INIT)
  435. print_tc = print_time_to_change_normal;
  436. //#endif //CLOCK_INTERVAL_TIME
  437. #ifdef TMC2130
  438. }
  439. #endif //TMC2130
  440. //#ifdef CLOCK_INTERVAL_TIME
  441. if (clock_interval == CLOCK_INTERVAL_TIME*2)
  442. clock_interval = 0;
  443. clock_interval++;
  444. if (print_tc != PRINT_TIME_REMAINING_INIT && clock_interval > CLOCK_INTERVAL_TIME) {
  445. print_t = print_tc;
  446. suff = 'C';
  447. } else
  448. //#endif //CLOCK_INTERVAL_TIME
  449. if (print_tr != PRINT_TIME_REMAINING_INIT) {
  450. print_t = print_tr;
  451. suff = 'R';
  452. } else
  453. print_t = _millis() / 60000 - starttime / 60000;
  454. if (feedmultiply != 100 && (print_t == print_tr || print_t == print_tc)) {
  455. suff_doubt = '?';
  456. print_t = 100ul * print_t / feedmultiply;
  457. }
  458. if (print_t < 6000) //time<100h
  459. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  460. else //time>=100h
  461. chars = lcd_printf_P(_N("%c%3uh %c%c"), LCD_STR_CLOCK[0], print_t / 60, suff, suff_doubt);
  462. }
  463. else
  464. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  465. lcd_space(8 - chars);
  466. }
  467. //! @Brief Print status line on status screen
  468. void lcdui_print_status_line(void) {
  469. if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating
  470. heating_status_counter++;
  471. if (heating_status_counter > 13) {
  472. heating_status_counter = 0;
  473. }
  474. lcd_set_cursor(7, 3);
  475. lcd_space(13);
  476. for (uint8_t dots = 0; dots < heating_status_counter; dots++) {
  477. lcd_putc_at(7 + dots, 3, '.');
  478. }
  479. switch (heating_status) {
  480. case HeatingStatus::EXTRUDER_HEATING:
  481. lcd_puts_at_P(0, 3, _T(MSG_HEATING));
  482. break;
  483. case HeatingStatus::EXTRUDER_HEATING_COMPLETE:
  484. lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
  485. heating_status = HeatingStatus::NO_HEATING;
  486. heating_status_counter = 0;
  487. break;
  488. case HeatingStatus::BED_HEATING:
  489. lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
  490. break;
  491. case HeatingStatus::BED_HEATING_COMPLETE:
  492. lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
  493. heating_status = HeatingStatus::NO_HEATING;
  494. heating_status_counter = 0;
  495. break;
  496. default:
  497. break;
  498. }
  499. }
  500. else if ((IS_SD_PRINTING) &&
  501. (custom_message_type == CustomMsg::Status) &&
  502. (lcd_status_message_level <= LCD_STATUS_INFO) &&
  503. lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT))
  504. {
  505. // If printing from SD, show what we are printing
  506. const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename);
  507. if( lcd_print_pad(&longFilenameOLD[scrollstuff], LCD_WIDTH) )
  508. {
  509. scrollstuff++;
  510. } else {
  511. scrollstuff = 0;
  512. }
  513. } else { // Otherwise check for other special events
  514. switch (custom_message_type) {
  515. case CustomMsg::M117: // M117 Set the status line message on the LCD
  516. case CustomMsg::Status: // Nothing special, print status message normally
  517. case CustomMsg::M0Wait: // M0/M1 Wait command working even from SD
  518. case CustomMsg::FilamentLoading: // If loading filament, print status
  519. case CustomMsg::MMUProgress: // MMU Progress Codes
  520. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  521. break;
  522. case CustomMsg::MeshBedLeveling: // If mesh bed leveling in progress, show the status
  523. if (custom_message_state > 10) {
  524. lcd_set_cursor(0, 3);
  525. lcd_space(LCD_WIDTH);
  526. lcd_puts_at_P(0, 3, _T(MSG_CALIBRATE_Z_AUTO));
  527. lcd_puts_P(PSTR(" : "));
  528. lcd_print(custom_message_state - 10);
  529. } else {
  530. if (custom_message_state == 3) {
  531. lcd_setstatuspgm(MSG_WELCOME);
  532. custom_message_type = CustomMsg::Status;
  533. }
  534. if (custom_message_state > 3 && custom_message_state <= 10) {
  535. lcd_set_cursor(0, 3);
  536. lcd_space(19);
  537. lcd_puts_at_P(0, 3, _i("Calibration done")); ////MSG_HOMEYZ_DONE c=20
  538. custom_message_state--;
  539. }
  540. }
  541. break;
  542. case CustomMsg::PidCal: // PID tuning in progress
  543. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  544. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) {
  545. lcd_set_cursor(10, 3);
  546. lcd_print(itostr3(pid_cycle));
  547. lcd_print('/');
  548. lcd_print(itostr3left(pid_number_of_cycles));
  549. }
  550. break;
  551. case CustomMsg::TempCal: // PINDA temp calibration in progress
  552. lcd_set_cursor(0, 3);
  553. lcd_printf_P(PSTR("%-12.12S%-d/6"), _T(MSG_PINDA_CALIBRATION), custom_message_state);
  554. break;
  555. case CustomMsg::TempCompPreheat: // temp compensation preheat
  556. lcd_puts_at_P(0, 3, _i("PINDA Heating")); ////MSG_PINDA_PREHEAT c=20
  557. if (custom_message_state <= PINDA_HEAT_T) {
  558. lcd_puts_P(PSTR(": "));
  559. lcd_print(custom_message_state); // seconds
  560. lcd_print(' ');
  561. }
  562. break;
  563. case CustomMsg::Resuming: // Resuming
  564. lcd_puts_at_P(0, 3, _T(MSG_RESUMING_PRINT));
  565. break;
  566. }
  567. }
  568. }
  569. //! @brief Show Status Screen
  570. //!
  571. //! @code{.unparsed}
  572. //! |01234567890123456789|
  573. //! |N 000/000D Z000.0 |
  574. //! |B 000/000D F100% |
  575. //! |USB100% T0 t--:-- |
  576. //! |Status line.........|
  577. //! ----------------------
  578. //! N - nozzle temp symbol LCD_STR_THERMOMETER
  579. //! D - Degree sysmbol LCD_STR_DEGREE
  580. //! B - bed temp symbol LCD_STR_BEDTEMP
  581. //! F - feedrate symbol LCD_STR_FEEDRATE
  582. //! t - clock symbol LCD_STR_THERMOMETER
  583. //! @endcode
  584. void lcdui_print_status_screen(void)
  585. {
  586. lcd_set_cursor(0, 0); //line 0
  587. //Print the hotend temperature (9 chars total)
  588. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  589. lcd_space(3); //3 spaces
  590. //Print Z-coordinate (8 chars total)
  591. lcdui_print_Z_coord();
  592. lcd_set_cursor(0, 1); //line 1
  593. //Print the Bed temperature (9 chars total)
  594. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  595. lcd_space(3); //3 spaces
  596. #ifdef PLANNER_DIAGNOSTICS
  597. //Print planner diagnostics (8 chars)
  598. lcdui_print_planner_diag();
  599. #else // PLANNER_DIAGNOSTICS
  600. //Print Feedrate (8 chars)
  601. lcdui_print_feedrate();
  602. #endif // PLANNER_DIAGNOSTICS
  603. lcd_set_cursor(0, 2); //line 2
  604. //Print SD status (7 chars)
  605. lcdui_print_percent_done();
  606. if (MMU2::mmu2.Enabled()) {
  607. // Print extruder status (5 chars)
  608. lcd_space(5 - lcdui_print_extruder());
  609. } else if (farm_mode) {
  610. // Print farm number (5 chars)
  611. lcdui_print_farm();
  612. } else {
  613. lcd_space(5); // 5 spaces
  614. }
  615. #ifdef CMD_DIAGNOSTICS
  616. //Print cmd queue diagnostics (8chars)
  617. lcdui_print_cmd_diag();
  618. #else
  619. //Print time (8chars)
  620. lcdui_print_time();
  621. #endif //CMD_DIAGNOSTICS
  622. lcd_set_cursor(0, 3); //line 3
  623. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  624. lcdui_print_status_line();
  625. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  626. }
  627. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  628. void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  629. {
  630. static uint8_t lcd_status_update_delay = 0;
  631. #ifdef ULTIPANEL_FEEDMULTIPLY
  632. // Dead zone at 100% feedrate
  633. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  634. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  635. {
  636. lcd_encoder = 0;
  637. feedmultiply = 100;
  638. }
  639. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  640. {
  641. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  642. lcd_encoder = 0;
  643. }
  644. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  645. {
  646. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  647. lcd_encoder = 0;
  648. }
  649. else if (feedmultiply != 100)
  650. {
  651. feedmultiply += int(lcd_encoder);
  652. lcd_encoder = 0;
  653. }
  654. #endif //ULTIPANEL_FEEDMULTIPLY
  655. if (feedmultiply < 10)
  656. feedmultiply = 10;
  657. else if (feedmultiply > 999)
  658. feedmultiply = 999;
  659. if (lcd_draw_update) {
  660. // Update the status screen immediately
  661. lcd_status_update_delay = 0;
  662. }
  663. if (lcd_status_update_delay)
  664. lcd_status_update_delay--;
  665. else
  666. { // Redraw the main screen every second (see LCD_UPDATE_INTERVAL).
  667. // This is easier then trying keep track of all things that change on the screen
  668. lcd_status_update_delay = 10;
  669. ReInitLCD++;
  670. if (ReInitLCD == 30)
  671. {
  672. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  673. ReInitLCD = 0 ;
  674. }
  675. else
  676. {
  677. if ((ReInitLCD % 10) == 0)
  678. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  679. }
  680. lcdui_print_status_screen();
  681. prusa_statistics_update_from_status_screen();
  682. if (lcd_commands_type != LcdCommands::Idle)
  683. lcd_commands();
  684. }
  685. bool current_click = LCD_CLICKED;
  686. if (ignore_click)
  687. {
  688. if (wait_for_unclick)
  689. {
  690. if (!current_click)
  691. ignore_click = wait_for_unclick = false;
  692. else
  693. current_click = false;
  694. }
  695. else if (current_click)
  696. {
  697. lcd_quick_feedback();
  698. wait_for_unclick = true;
  699. current_click = false;
  700. }
  701. }
  702. if (current_click
  703. && ( menu_block_mask == MENU_BLOCK_NONE ) // or a serious error blocks entering the menu
  704. )
  705. {
  706. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  707. menu_submenu(lcd_main_menu);
  708. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  709. }
  710. }
  711. void lcd_print_stop_finish();
  712. void lcd_commands()
  713. {
  714. // printf_P(PSTR("lcd_commands begin, lcd_commands_type=%u, lcd_commands_step=%u\n"), (uint8_t)lcd_commands_type, lcd_commands_step);
  715. if (planner_aborted) {
  716. // we are still within an aborted command. do not process any LCD command until we return
  717. return;
  718. }
  719. if (lcd_commands_type == LcdCommands::StopPrint)
  720. {
  721. if (!blocks_queued() && !homing_flag)
  722. {
  723. custom_message_type = CustomMsg::Status;
  724. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  725. lcd_commands_type = LcdCommands::Idle;
  726. lcd_commands_step = 0;
  727. lcd_print_stop_finish();
  728. }
  729. }
  730. if (lcd_commands_type == LcdCommands::LongPause)
  731. {
  732. if (!blocks_queued() && !homing_flag)
  733. {
  734. if (custom_message_type != CustomMsg::M117)
  735. {
  736. custom_message_type = CustomMsg::Status;
  737. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20
  738. }
  739. lcd_commands_type = LcdCommands::Idle;
  740. lcd_commands_step = 0;
  741. long_pause();
  742. }
  743. }
  744. if (lcd_commands_type == LcdCommands::Layer1Cal)
  745. {
  746. char cmd1[30];
  747. if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  748. if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
  749. {
  750. switch(lcd_commands_step)
  751. {
  752. case 0:
  753. lcd_commands_step = 11;
  754. break;
  755. case 11:
  756. lay1cal_wait_preheat();
  757. lcd_commands_step = 10;
  758. break;
  759. case 10:
  760. lay1cal_load_filament(cmd1, lay1cal_filament);
  761. lcd_commands_step = 9;
  762. break;
  763. case 9:
  764. lcd_clear();
  765. menu_depth = 0;
  766. menu_submenu(lcd_babystep_z);
  767. lay1cal_intro_line();
  768. lcd_commands_step = 8;
  769. break;
  770. case 8:
  771. lay1cal_before_meander();
  772. lcd_commands_step = 7;
  773. break;
  774. case 7:
  775. lay1cal_meander(cmd1);
  776. lcd_commands_step = 6;
  777. break;
  778. case 6:
  779. for (uint8_t i = 0; i < 4; i++)
  780. {
  781. lay1cal_square(cmd1, i);
  782. }
  783. lcd_commands_step = 5;
  784. break;
  785. case 5:
  786. for (uint8_t i = 4; i < 8; i++)
  787. {
  788. lay1cal_square(cmd1, i);
  789. }
  790. lcd_commands_step = 4;
  791. break;
  792. case 4:
  793. for (uint8_t i = 8; i < 12; i++)
  794. {
  795. lay1cal_square(cmd1, i);
  796. }
  797. lcd_commands_step = 3;
  798. break;
  799. case 3:
  800. for (uint8_t i = 12; i < 16; i++)
  801. {
  802. lay1cal_square(cmd1, i);
  803. }
  804. lcd_commands_step = 2;
  805. break;
  806. case 2:
  807. enquecommand_P(PSTR("M107")); //turn off printer fan
  808. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  809. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  810. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  811. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  812. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  813. if (MMU2::mmu2.Enabled()) enquecommand_P(PSTR("M702")); //unload from nozzle
  814. enquecommand_P(PSTR("M84"));// disable motors
  815. lcd_return_to_status(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  816. lcd_commands_step = 1;
  817. break;
  818. case 1:
  819. lcd_setstatuspgm(MSG_WELCOME);
  820. lcd_commands_step = 0;
  821. lcd_commands_type = LcdCommands::Idle;
  822. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  823. lcd_wizard(WizState::RepeatLay1Cal);
  824. break;
  825. }
  826. }
  827. }
  828. if (lcd_commands_type == LcdCommands::PidExtruder) {
  829. char cmd1[30];
  830. if (lcd_commands_step == 0) {
  831. custom_message_type = CustomMsg::PidCal;
  832. custom_message_state = 1;
  833. lcd_draw_update = 3;
  834. lcd_commands_step = 3;
  835. }
  836. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  837. preparePidTuning(); // ensure we don't move to the next step early
  838. sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp);
  839. // setting the correct target temperature (for visualization) is done in PID_autotune
  840. enquecommand(cmd1);
  841. lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20
  842. lcd_commands_step = 2;
  843. }
  844. if (lcd_commands_step == 2 && !pidTuningRunning()) { //saving to eeprom
  845. custom_message_state = 0;
  846. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20
  847. setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
  848. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  849. sprintf_P(cmd1, PSTR("M301 P%.2f I%.2f D%.2f"), _Kp, _Ki, _Kd);
  850. enquecommand(cmd1);
  851. enquecommand_P(PSTR("M500"));
  852. }
  853. else {
  854. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  855. }
  856. display_time.start();
  857. lcd_commands_step = 1;
  858. }
  859. if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message
  860. lcd_setstatuspgm(MSG_WELCOME);
  861. custom_message_type = CustomMsg::Status;
  862. pid_temp = DEFAULT_PID_TEMP;
  863. lcd_commands_step = 0;
  864. lcd_commands_type = LcdCommands::Idle;
  865. }
  866. }
  867. #ifdef TEMP_MODEL
  868. if (lcd_commands_type == LcdCommands::TempModel && cmd_buffer_empty())
  869. {
  870. switch (lcd_commands_step)
  871. {
  872. case 0:
  873. lcd_commands_step = 3;
  874. [[fallthrough]];
  875. case 3:
  876. enquecommand_P(PSTR("M310 A F1"));
  877. lcd_commands_step = 2;
  878. break;
  879. case 2:
  880. if (temp_model_autotune_result())
  881. enquecommand_P(PSTR("M500"));
  882. lcd_commands_step = 1;
  883. break;
  884. case 1:
  885. lcd_commands_step = 0;
  886. lcd_commands_type = LcdCommands::Idle;
  887. bool res = temp_model_autotune_result();
  888. if (res) calibration_status_set(CALIBRATION_STATUS_TEMP_MODEL);
  889. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) {
  890. // resume the wizard
  891. lcd_wizard(res ? WizState::Restore : WizState::Failed);
  892. }
  893. break;
  894. }
  895. }
  896. #endif //TEMP_MODEL
  897. if (lcd_commands_type == LcdCommands::NozzleCNG)
  898. {
  899. if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
  900. {
  901. #ifdef TEMP_MODEL
  902. static bool was_enabled;
  903. #endif //TEMP_MODEL
  904. switch(lcd_commands_step)
  905. {
  906. case 0:
  907. lcd_commands_step = 3;
  908. break;
  909. case 3:
  910. lcd_update_enabled = false; //hack to avoid lcd_update recursion.
  911. lcd_show_fullscreen_message_and_wait_P(_T(MSG_NOZZLE_CNG_READ_HELP));
  912. lcd_update_enabled = true;
  913. lcd_draw_update = 2; //force lcd clear and update after the stack unwinds.
  914. enquecommand_P(PSTR("G28 W"));
  915. enquecommand_P(PSTR("G1 X125 Y10 Z150 F1000"));
  916. enquecommand_P(PSTR("M109 S280"));
  917. #ifdef TEMP_MODEL
  918. was_enabled = temp_model_enabled();
  919. temp_model_set_enabled(false);
  920. #endif //TEMP_MODEL
  921. lcd_commands_step = 2;
  922. break;
  923. case 2:
  924. //|0123456789012456789|
  925. //|Hotend at 280C!
  926. //|Nozzle changed and
  927. //|tightend to specs?
  928. //| Yes No
  929. enquecommand_P(PSTR("M84 XY"));
  930. lcd_update_enabled = false; //hack to avoid lcd_update recursion.
  931. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_NOZZLE_CNG_CHANGED), false) == LCD_LEFT_BUTTON_CHOICE) {
  932. setAllTargetHotends(0);
  933. #ifdef TEMP_MODEL
  934. temp_model_set_enabled(was_enabled);
  935. #endif //TEMP_MODEL
  936. lcd_commands_step = 1;
  937. }
  938. lcd_update_enabled = true;
  939. break;
  940. case 1:
  941. lcd_setstatuspgm(MSG_WELCOME);
  942. lcd_commands_step = 0;
  943. lcd_commands_type = LcdCommands::Idle;
  944. break;
  945. }
  946. }
  947. }
  948. }
  949. void lcd_return_to_status()
  950. {
  951. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  952. menu_goto(lcd_status_screen, 0, false, true);
  953. menu_depth = 0;
  954. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  955. }
  956. //! @brief Pause print, disable nozzle heater, move to park position, send host action "paused"
  957. void lcd_pause_print()
  958. {
  959. stop_and_save_print_to_ram(0.0, -default_retraction);
  960. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_PAUSED);
  961. isPrintPaused = true;
  962. // return to status is required to continue processing in the main loop!
  963. lcd_commands_type = LcdCommands::LongPause;
  964. lcd_return_to_status();
  965. }
  966. //! @brief Send host action "pause"
  967. void lcd_pause_usb_print()
  968. {
  969. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_PAUSE);
  970. }
  971. static void lcd_move_menu_axis();
  972. /* Menu implementation */
  973. static void lcd_cooldown()
  974. {
  975. setAllTargetHotends(0);
  976. setTargetBed(0);
  977. fanSpeed = 0;
  978. lcd_return_to_status();
  979. }
  980. //! @brief append text label with a colon and format it into a fixed size output buffer
  981. //! It would have been much easier if there was a ':' in the labels.
  982. //! But since the texts like Bed, Nozzle and PINDA are used in other places
  983. //! it is better to reuse these texts even though it requires some extra formatting code.
  984. //! @param [in] ipgmLabel pointer to string in PROGMEM
  985. //! @param [out] pointer to string in RAM which will receive the formatted text. Must be allocated to appropriate size
  986. //! @param [in] dstSize allocated length of dst
  987. static void pgmtext_with_colon(const char *ipgmLabel, char *dst, uint8_t dstSize){
  988. uint8_t i = 0;
  989. for(; i < dstSize - 2; ++i){ // 2 byte less than buffer, we'd be adding a ':' to the end
  990. uint8_t b = pgm_read_byte(ipgmLabel + i);
  991. if( ! b )
  992. break;
  993. dst[i] = b;
  994. }
  995. dst[i] = ':'; // append the colon
  996. ++i;
  997. for(; i < dstSize - 1; ++i) // fill the rest with spaces
  998. dst[i] = ' ';
  999. dst[dstSize-1] = '\0'; // terminate the string properly
  1000. }
  1001. //! @brief Show Extruder Info
  1002. //!
  1003. //! @code{.unparsed}
  1004. //! |01234567890123456789|
  1005. //! |Hotend fan: 0000| MSG_HOTEND_FAN_SPEED c=15
  1006. //! |Print fan: 0000| MSG_PRINT_FAN_SPEED c=15
  1007. //! | |
  1008. //! | |
  1009. //! ----------------------
  1010. //! @endcode
  1011. void lcd_menu_extruder_info() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  1012. {
  1013. lcd_timeoutToStatus.stop(); //infinite timeout
  1014. lcd_home();
  1015. lcd_printf_P(PSTR("%-15.15S%-5d\n" "%-15.15S%-5d\n"), _T(MSG_HOTEND_FAN_SPEED), 60*fan_speed[0], _T(MSG_PRINT_FAN_SPEED), 60*fan_speed[1] );
  1016. menu_back_if_clicked();
  1017. }
  1018. static uint16_t __attribute__((noinline)) clamp999(uint16_t v){
  1019. return v > 999 ? 999 : v;
  1020. }
  1021. //! @brief Show Fails Statistics MMU
  1022. //!
  1023. //! @code{.unparsed}
  1024. //! |01234567890123456789|
  1025. //! | Main | MSG_MAIN c=18
  1026. //! | Last print | MSG_LAST_PRINT c=18
  1027. //! | Total | MSG_TOTAL c=6
  1028. //! | |
  1029. //! ----------------------
  1030. //! @endcode
  1031. static void lcd_menu_fails_stats_mmu()
  1032. {
  1033. MENU_BEGIN();
  1034. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1035. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_mmu_print);
  1036. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_mmu_total);
  1037. MENU_ITEM_SUBMENU_P(_O(PSTR("Toolchange count")), lcd_menu_toolchange_stats_mmu_total);
  1038. MENU_END();
  1039. }
  1040. //! @brief Show Last Print Failures Statistics MMU
  1041. //!
  1042. //! @code{.unparsed}
  1043. //! |01234567890123456789|
  1044. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1045. //! | MMU fails 000| MSG_MMU_FAILS c=15
  1046. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  1047. //! | |
  1048. //! ----------------------
  1049. //! @endcode
  1050. static void lcd_menu_fails_stats_mmu_print() {
  1051. lcd_timeoutToStatus.stop(); //infinite timeout
  1052. lcd_home();
  1053. lcd_printf_P(
  1054. PSTR("%S\n"
  1055. " %-16.16S%-3d\n"
  1056. " %-16.16S%-3d"
  1057. ),
  1058. _T(MSG_LAST_PRINT_FAILURES),
  1059. _T(MSG_MMU_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) ),
  1060. _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) ));
  1061. menu_back_if_clicked_fb();
  1062. }
  1063. //! @brief Show Total Failures Statistics MMU
  1064. //!
  1065. //! @code{.unparsed}
  1066. //! |01234567890123456789|
  1067. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1068. //! | MMU fails 000| MSG_MMU_FAILS c=15
  1069. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  1070. //! | MMU power fails 000| MSG_MMU_POWER_FAILS c=15
  1071. //! ----------------------
  1072. //! @endcode
  1073. static void lcd_menu_fails_stats_mmu_total() {
  1074. lcd_timeoutToStatus.stop(); //infinite timeout
  1075. lcd_home();
  1076. lcd_printf_P(
  1077. PSTR("%S\n"
  1078. " %-16.16S%-3d\n"
  1079. " %-16.16S%-3d\n"
  1080. " %-16.16S%-3d"
  1081. ),
  1082. _T(MSG_TOTAL_FAILURES),
  1083. _T(MSG_MMU_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) ),
  1084. _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) ),
  1085. _T(MSG_MMU_POWER_FAILS), clamp999( MMU2::mmu2.TMCFailures() ));
  1086. menu_back_if_clicked_fb();
  1087. }
  1088. //! @brief Show Total Failures Statistics MMU
  1089. //!
  1090. //! @code{.unparsed}
  1091. //! |01234567890123456789|
  1092. //! |Toolchange count: |
  1093. //! | 4294967295|
  1094. //! | |
  1095. //! | |
  1096. //! ----------------------
  1097. //! @endcode
  1098. static void lcd_menu_toolchange_stats_mmu_total()
  1099. {
  1100. typedef struct
  1101. {
  1102. bool initialized; // 1byte
  1103. } _menu_data_t;
  1104. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1105. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1106. if(!_md->initialized) {
  1107. lcd_set_cursor(0, 0);
  1108. lcd_puts_P(PSTR("Toolchange count:"));
  1109. lcd_set_cursor(10, 1);
  1110. lcd_print(eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT));
  1111. _md->initialized = true;
  1112. }
  1113. menu_back_if_clicked_fb();
  1114. }
  1115. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1116. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-7.7SX %-3d Y %-3d";
  1117. //! @brief Show Total Failures Statistics MMU
  1118. //!
  1119. //! @code{.unparsed}
  1120. //! |01234567890123456789|
  1121. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1122. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1123. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1124. //! | Crash X:000 Y:000| MSG_CRASH c=7
  1125. //! ----------------------
  1126. //! @endcode
  1127. static void lcd_menu_fails_stats_total()
  1128. {
  1129. lcd_timeoutToStatus.stop(); //infinite timeout
  1130. lcd_home();
  1131. lcd_printf_P(failStatsFmt,
  1132. _T(MSG_TOTAL_FAILURES),
  1133. _T(MSG_POWER_FAILURES), clamp999( eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) ),
  1134. _T(MSG_FIL_RUNOUTS), clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) ),
  1135. _T(MSG_CRASH),
  1136. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) ),
  1137. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) ));
  1138. menu_back_if_clicked_fb();
  1139. }
  1140. //! @brief Show Last Print Failures Statistics
  1141. //!
  1142. //! @code{.unparsed}
  1143. //! |01234567890123456789|
  1144. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1145. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1146. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1147. //! | Crash X 000 Y 000| MSG_CRASH c=7
  1148. //! ----------------------
  1149. //! @endcode
  1150. //! @todo leptun refactor this piece of code please
  1151. static void lcd_menu_fails_stats_print()
  1152. {
  1153. lcd_timeoutToStatus.stop(); //infinite timeout
  1154. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1155. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1156. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1157. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1158. lcd_home();
  1159. lcd_printf_P(failStatsFmt,
  1160. _T(MSG_LAST_PRINT_FAILURES),
  1161. _T(MSG_POWER_FAILURES), power,
  1162. _T(MSG_FIL_RUNOUTS), filam,
  1163. _T(MSG_CRASH), crashX, crashY);
  1164. menu_back_if_clicked_fb();
  1165. }
  1166. //! @brief Open fail statistics menu
  1167. //!
  1168. //! This version of function is used, when there is filament sensor,
  1169. //! power failure and crash detection.
  1170. //! There are Last print and Total menu items.
  1171. //!
  1172. //! @code{.unparsed}
  1173. //! |01234567890123456789|
  1174. //! | Main | MSG_MAIN c=18
  1175. //! | Last print | MSG_LAST_PRINT c=18
  1176. //! | Total | MSG_TOTAL c=6
  1177. //! | |
  1178. //! ----------------------
  1179. //! @endcode
  1180. static void lcd_menu_fails_stats()
  1181. {
  1182. MENU_BEGIN();
  1183. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1184. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_print);
  1185. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_total);
  1186. MENU_END();
  1187. }
  1188. #elif defined(FILAMENT_SENSOR)
  1189. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" "%S\n" " %-16.16S%-3d\n";
  1190. //!
  1191. //! @brief Print last print and total filament run outs
  1192. //!
  1193. //! This version of function is used, when there is filament sensor,
  1194. //! but no other sensors (e.g. power failure, crash detection).
  1195. //!
  1196. //! Example screen:
  1197. //! @code{.unparsed}
  1198. //! |01234567890123456789|
  1199. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1200. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1201. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1202. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1203. //! ----------------------
  1204. //! @endcode
  1205. static void lcd_menu_fails_stats()
  1206. {
  1207. lcd_timeoutToStatus.stop(); //infinite timeout
  1208. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1209. uint16_t filamentTotal = clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) );
  1210. lcd_home();
  1211. lcd_printf_P(failStatsFmt,
  1212. _T(MSG_LAST_PRINT_FAILURES),
  1213. _T(MSG_FIL_RUNOUTS), filamentLast,
  1214. _T(MSG_TOTAL_FAILURES),
  1215. _T(MSG_FIL_RUNOUTS), filamentTotal);
  1216. menu_back_if_clicked();
  1217. }
  1218. #else
  1219. static void lcd_menu_fails_stats()
  1220. {
  1221. lcd_timeoutToStatus.stop(); //infinite timeout
  1222. MENU_BEGIN();
  1223. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1224. MENU_END();
  1225. }
  1226. #endif //TMC2130
  1227. #ifdef DEBUG_BUILD
  1228. #ifdef DEBUG_STACK_MONITOR
  1229. extern uint16_t SP_min;
  1230. extern char* __malloc_heap_start;
  1231. extern char* __malloc_heap_end;
  1232. #endif //DEBUG_STACK_MONITOR
  1233. //! @brief Show Debug Information
  1234. //!
  1235. //! @code{.unparsed}
  1236. //! |01234567890123456789|
  1237. //! |RAM statistics | c=20
  1238. //! | SP_min: 0000| c=14
  1239. //! | heap_start: 0000| c=14
  1240. //! | heap_end: 0000| c=14
  1241. //! ----------------------
  1242. //! @endcode
  1243. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1244. static void lcd_menu_debug()
  1245. {
  1246. #ifdef DEBUG_STACK_MONITOR
  1247. lcd_home();
  1248. lcd_printf_P(PSTR("RAM statistics\n" ////c=20
  1249. " SP_min: 0x%04x\n" ////c=14
  1250. " heap_start: 0x%04x\n" ////c=14
  1251. " heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); ////c=14
  1252. #endif //DEBUG_STACK_MONITOR
  1253. menu_back_if_clicked_fb();
  1254. }
  1255. #endif /* DEBUG_BUILD */
  1256. //! @brief common line print for lcd_menu_temperatures
  1257. //! @param [in] ipgmLabel pointer to string in PROGMEM
  1258. //! @param [in] value to be printed behind the label
  1259. static void lcd_menu_temperatures_line(const char *ipgmLabel, int value){
  1260. static const size_t maxChars = 15;
  1261. char tmp[maxChars];
  1262. pgmtext_with_colon(ipgmLabel, tmp, maxChars);
  1263. lcd_printf_P(PSTR(" %s%3d\x01 \n"), tmp, value); // no need to add -14.14 to string alignment
  1264. }
  1265. //! @brief Show Temperatures
  1266. //!
  1267. //! @code{.unparsed}
  1268. //! |01234567890123456789|
  1269. //! | Nozzle: 000D| MSG_NOZZLE c=10
  1270. //! | Bed: 000D| MSG_BED c=13
  1271. //! | Ambient: 000D| MSG_AMBIENTc=14
  1272. //! | PINDA: 000D| MSG_PINDA c=14
  1273. //! ----------------------
  1274. //! D - Degree sysmbol LCD_STR_DEGREE
  1275. //! @endcode
  1276. static void lcd_menu_temperatures()
  1277. {
  1278. lcd_timeoutToStatus.stop(); //infinite timeout
  1279. lcd_home();
  1280. lcd_menu_temperatures_line( _T(MSG_NOZZLE), (int)current_temperature[0] );
  1281. lcd_menu_temperatures_line( _T(MSG_BED), (int)current_temperature_bed );
  1282. #ifdef AMBIENT_THERMISTOR
  1283. lcd_menu_temperatures_line( _i("Ambient"), (int)current_temperature_ambient ); ////MSG_AMBIENT c=14
  1284. #endif //AMBIENT_THERMISTOR
  1285. #ifdef PINDA_THERMISTOR
  1286. lcd_menu_temperatures_line(MSG_PINDA, (int)current_temperature_pinda ); ////MSG_PINDA
  1287. #endif //PINDA_THERMISTOR
  1288. menu_back_if_clicked();
  1289. }
  1290. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || (defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG))
  1291. #define VOLT_DIV_R1 10000
  1292. #define VOLT_DIV_R2 2370
  1293. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1294. //! @brief Show Voltages
  1295. //!
  1296. //! @code{.unparsed}
  1297. //! |01234567890123456789|
  1298. //! | |
  1299. //! | PWR: 00.0V | c=12
  1300. //! | Bed: 00.0V | c=12
  1301. //! | IR : 00.0V | c=12 optional
  1302. //! ----------------------
  1303. //! @endcode
  1304. static void lcd_menu_voltages()
  1305. {
  1306. lcd_timeoutToStatus.stop(); //infinite timeout
  1307. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1308. float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1309. lcd_home();
  1310. lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed);
  1311. #ifdef IR_SENSOR_ANALOG
  1312. lcd_printf_P(PSTR("\n IR : %3.1fV"), fsensor.Raw2Voltage(fsensor.getVoltRaw()));
  1313. #endif //IR_SENSOR_ANALOG
  1314. menu_back_if_clicked();
  1315. }
  1316. #endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG)
  1317. #ifdef TMC2130
  1318. //! @brief Show Belt Status
  1319. //!
  1320. //! @code{.unparsed}
  1321. //! |01234567890123456789|
  1322. //! | Belt status | c=18
  1323. //! | X: 000 |
  1324. //! | Y: 000 |
  1325. //! | |
  1326. //! ----------------------
  1327. //! @endcode
  1328. static void lcd_menu_belt_status()
  1329. {
  1330. lcd_home();
  1331. lcd_printf_P(PSTR("%S\n" " X %d\n" " Y %d"), _T(MSG_BELT_STATUS), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1332. menu_back_if_clicked();
  1333. }
  1334. #endif //TMC2130
  1335. #ifdef RESUME_DEBUG
  1336. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1337. extern void restore_print_from_ram_and_continue(float e_move);
  1338. static void lcd_menu_test_save()
  1339. {
  1340. stop_and_save_print_to_ram(10, -0.8);
  1341. }
  1342. static void lcd_menu_test_restore()
  1343. {
  1344. restore_print_from_ram_and_continue(0.8);
  1345. }
  1346. #endif //RESUME_DEBUG
  1347. //! @brief Show Preheat Menu
  1348. static void lcd_preheat_menu()
  1349. {
  1350. eFilamentAction = FilamentAction::Preheat;
  1351. lcd_generic_preheat_menu();
  1352. }
  1353. #ifdef MENU_DUMP
  1354. #include "xflash_dump.h"
  1355. static void lcd_dump_memory()
  1356. {
  1357. lcd_beeper_quick_feedback();
  1358. xfdump_dump();
  1359. lcd_return_to_status();
  1360. }
  1361. #endif //MENU_DUMP
  1362. #ifdef MENU_SERIAL_DUMP
  1363. #include "Dcodes.h"
  1364. static void lcd_serial_dump()
  1365. {
  1366. serial_dump_and_reset(dump_crash_reason::manual);
  1367. }
  1368. #endif //MENU_SERIAL_DUMP
  1369. #if defined(DEBUG_BUILD) && defined(EMERGENCY_HANDLERS)
  1370. #include <avr/wdt.h>
  1371. #ifdef WATCHDOG
  1372. static void lcd_wdr_crash()
  1373. {
  1374. while (1);
  1375. }
  1376. #endif
  1377. static uint8_t lcd_stack_crash_(uint8_t arg, uint32_t sp = 0)
  1378. {
  1379. // populate the stack with an increasing value for ease of testing
  1380. volatile uint16_t tmp __attribute__((unused)) = sp;
  1381. _delay(arg);
  1382. uint8_t ret = lcd_stack_crash_(arg, SP);
  1383. // required to avoid tail call elimination and to slow down the stack growth
  1384. _delay(ret);
  1385. return ret;
  1386. }
  1387. static void lcd_stack_crash()
  1388. {
  1389. #ifdef WATCHDOG
  1390. wdt_disable();
  1391. #endif
  1392. // delay choosen in order to hit the stack-check in the temperature isr reliably
  1393. lcd_stack_crash_(10);
  1394. }
  1395. #endif
  1396. #ifdef DEBUG_PULLUP_CRASH
  1397. void TestPullupCrash() {
  1398. PORTF |= 0x01;
  1399. }
  1400. #endif // DEBUG_PULLUP_CRASH
  1401. //! @brief Show Support Menu
  1402. //!
  1403. //! @code{.unparsed}
  1404. //! |01234567890123456789|
  1405. //! | Main | MSG_MAIN c=18
  1406. //! | Firmware: | c=18
  1407. //! | 3.7.2.-2363 | c=16
  1408. //! | prusa3d.com | MSG_PRUSA3D
  1409. //! | forum.prusa3d.com | MSG_PRUSA3D_FORUM
  1410. //! | help.prusa3d.com | MSG_PRUSA3D_HELP
  1411. //! | -------------- | STR_SEPARATOR
  1412. //! | 1_75mm_MK3 | FILAMENT_SIZE
  1413. //! | help.prusa3d.com | ELECTRONICS
  1414. //! | help.prusa3d.com | NOZZLE_TYPE
  1415. //! | -------------- | STR_SEPARATOR
  1416. //! | Date: | c=17
  1417. //! | MMM DD YYYY | __DATE__
  1418. //! | -------------- | STR_SEPARATOR
  1419. //! @endcode
  1420. //!
  1421. //! If MMU is connected
  1422. //!
  1423. //! @code{.unparsed}
  1424. //! | MMU2 connected | c=18
  1425. //! | FW: 1.0.6-7064523 |
  1426. //! @endcode
  1427. //!
  1428. //! If MMU is not connected
  1429. //!
  1430. //! @code{.unparsed}
  1431. //! | MMU2 N/A | c=18
  1432. //! @endcode
  1433. //!
  1434. //! If Flash Air is connected
  1435. //!
  1436. //! @code{.unparsed}
  1437. //! | -------------- | STR_SEPARATOR
  1438. //! | FlashAir IP Addr: | c=18
  1439. //! | 192.168.1.100 |
  1440. //! @endcode
  1441. //!
  1442. //! @code{.unparsed}
  1443. //! | -------------- | STR_SEPARATOR
  1444. //! | XYZ cal. details | MSG_XYZ_DETAILS c=18
  1445. //! | Extruder info | MSG_INFO_EXTRUDER
  1446. //! | XYZ cal. details | MSG_INFO_SENSORS
  1447. //! @endcode
  1448. //!
  1449. //! If TMC2130 defined
  1450. //!
  1451. //! @code{.unparsed}
  1452. //! | Belt status | MSG_BELT_STATUS
  1453. //! @endcode
  1454. //!
  1455. //! @code{.unparsed}
  1456. //! | Temperatures | MSG_MENU_TEMPERATURES
  1457. //! @endcode
  1458. //!
  1459. //! If Voltage Bed and PWR Pin are defined
  1460. //!
  1461. //! @code{.unparsed}
  1462. //! | Voltages | MSG_MENU_VOLTAGES
  1463. //! @endcode
  1464. //!
  1465. //!
  1466. //! If DEBUG_BUILD is defined
  1467. //!
  1468. //! @code{.unparsed}
  1469. //! | Debug | c=18
  1470. //! @endcode
  1471. //! ----------------------
  1472. //! @endcode
  1473. static void lcd_support_menu()
  1474. {
  1475. typedef struct
  1476. { // 22bytes total
  1477. int8_t status; // 1byte
  1478. bool is_flash_air; // 1byte
  1479. uint32_t ip; // 4bytes
  1480. char ip_str[IP4_STR_SIZE]; // 16bytes
  1481. } _menu_data_t;
  1482. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1483. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1484. if (_md->status == 0 || lcd_draw_update == 2)
  1485. {
  1486. // Menu was entered or SD card status has changed (plugged in or removed).
  1487. // Initialize its status.
  1488. _md->status = 1;
  1489. _md->is_flash_air = card.ToshibaFlashAir_isEnabled();
  1490. if (_md->is_flash_air) {
  1491. card.ToshibaFlashAir_GetIP((uint8_t*)(&_md->ip)); // ip == 0 if it failed
  1492. }
  1493. } else if (_md->is_flash_air && _md->ip == 0 && ++ _md->status == 16)
  1494. {
  1495. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1496. _md->status = 0;
  1497. }
  1498. MENU_BEGIN();
  1499. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1500. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1501. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1502. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1503. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1504. #endif
  1505. // Ideally this block would be optimized out by the compiler.
  1506. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1507. if (fw_string_len < 6) {
  1508. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1509. } else {
  1510. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1511. }*/
  1512. MENU_ITEM_BACK_P(_n("prusa3d.com"));////MSG_PRUSA3D c=18
  1513. MENU_ITEM_BACK_P(_n("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=18
  1514. MENU_ITEM_BACK_P(_n("help.prusa3d.com"));////MSG_PRUSA3D_HELP c=18
  1515. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1516. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1517. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1518. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1519. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1520. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17
  1521. MENU_ITEM_BACK_P(PSTR(SOURCE_DATE_EPOCH));
  1522. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  1523. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1524. MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:"));
  1525. MENU_ITEM_BACK_P(fsensor.getIRVersionText());
  1526. #endif // IR_SENSOR_ANALOG
  1527. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1528. if (MMU2::mmu2.Enabled())
  1529. {
  1530. MENU_ITEM_BACK_P(_i("MMU2 connected")); ////MSG_MMU_CONNECTED c=18
  1531. MENU_ITEM_BACK_P(PSTR(" FW:")); ////c=17
  1532. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1533. {
  1534. lcd_set_cursor(6, menu_row);
  1535. MMU2::Version mmu_version = MMU2::mmu2.GetMMUFWVersion();
  1536. if (mmu_version.major > 0)
  1537. lcd_printf_P(PSTR("%d.%d.%d"), mmu_version.major, mmu_version.minor, mmu_version.build);
  1538. else
  1539. lcd_puts_P(_i("unknown")); ////MSG_UNKNOWN c=13
  1540. }
  1541. }
  1542. else
  1543. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1544. // Show the FlashAir IP address, if the card is available.
  1545. if (_md->is_flash_air) {
  1546. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1547. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); ////MSG_FLASHAIR c=18
  1548. MENU_ITEM_BACK_P(PSTR(" "));
  1549. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1550. lcd_set_cursor(2, menu_row);
  1551. ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip));
  1552. lcd_print(_md->ip_str);
  1553. }
  1554. }
  1555. // Show the printer IP address, if it is available.
  1556. if (IP_address) {
  1557. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1558. MENU_ITEM_BACK_P(_i("Printer IP Addr:")); ////MSG_PRINTER_IP c=18
  1559. MENU_ITEM_BACK_P(PSTR(" "));
  1560. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1561. lcd_set_cursor(2, menu_row);
  1562. ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address));
  1563. lcd_print(_md->ip_str);
  1564. }
  1565. }
  1566. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1567. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1568. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1569. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1570. #ifdef TMC2130
  1571. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);
  1572. #endif //TMC2130
  1573. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1574. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1575. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1576. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1577. #ifdef MENU_DUMP
  1578. MENU_ITEM_FUNCTION_P(_n("Dump memory"), lcd_dump_memory);
  1579. #endif //MENU_DUMP
  1580. #ifdef MENU_SERIAL_DUMP
  1581. if (emergency_serial_dump)
  1582. MENU_ITEM_FUNCTION_P(_n("Dump to serial"), lcd_serial_dump);
  1583. #endif
  1584. #ifdef DEBUG_BUILD
  1585. #ifdef EMERGENCY_HANDLERS
  1586. #ifdef WATCHDOG
  1587. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1588. #endif //WATCHDOG
  1589. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1590. #endif //EMERGENCY_HANDLERS
  1591. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1592. #endif /* DEBUG_BUILD */
  1593. MENU_END();
  1594. }
  1595. void lcd_set_fan_check() {
  1596. fans_check_enabled = !fans_check_enabled;
  1597. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1598. #ifdef FANCHECK
  1599. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1600. #endif //FANCHECK
  1601. }
  1602. #ifdef MMU_HAS_CUTTER
  1603. void lcd_cutter_enabled()
  1604. {
  1605. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1606. {
  1607. #ifndef MMU_ALWAYS_CUT
  1608. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1609. }
  1610. #else //MMU_ALWAYS_CUT
  1611. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1612. }
  1613. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1614. {
  1615. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1616. }
  1617. #endif //MMU_ALWAYS_CUT
  1618. else
  1619. {
  1620. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1621. }
  1622. }
  1623. #endif //MMU_HAS_CUTTER
  1624. void lcd_set_filament_autoload() {
  1625. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled());
  1626. }
  1627. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1628. void lcd_set_filament_oq_meass()
  1629. {
  1630. fsensor_oq_measure_set(!fsensor_oq_measure_enabled);
  1631. }
  1632. #endif
  1633. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1634. bool bFilamentPreheatState;
  1635. bool bFilamentAction=false;
  1636. static bool bFilamentWaitingFlag=false;
  1637. bool shouldPreheatOnlyNozzle() {
  1638. uint8_t eeprom_setting = eeprom_read_byte((uint8_t*)EEPROM_HEAT_BED_ON_LOAD_FILAMENT);
  1639. if (eeprom_setting != 0)
  1640. return false;
  1641. switch(eFilamentAction) {
  1642. case FilamentAction::Load:
  1643. case FilamentAction::AutoLoad:
  1644. case FilamentAction::UnLoad:
  1645. case FilamentAction::MmuLoad:
  1646. case FilamentAction::MmuUnLoad:
  1647. case FilamentAction::MmuEject:
  1648. case FilamentAction::MmuCut:
  1649. return true;
  1650. default:
  1651. return false;
  1652. }
  1653. }
  1654. void lcd_print_target_temps_first_line(){
  1655. lcd_set_cursor(0, 0);
  1656. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  1657. lcd_set_cursor(10, 0);
  1658. int targetBedTemp = (int) degTargetBed();
  1659. if (targetBedTemp) {
  1660. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int) degBed(), targetBedTemp);
  1661. } else {
  1662. lcd_space(10);
  1663. }
  1664. }
  1665. static void mFilamentPrompt()
  1666. {
  1667. uint8_t nLevel;
  1668. lcd_print_target_temps_first_line();
  1669. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1670. lcd_set_cursor(0,2);
  1671. switch(eFilamentAction)
  1672. {
  1673. case FilamentAction::Load:
  1674. case FilamentAction::AutoLoad:
  1675. case FilamentAction::MmuLoad:
  1676. case FilamentAction::MmuLoadingTest:
  1677. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1678. break;
  1679. case FilamentAction::UnLoad:
  1680. case FilamentAction::MmuUnLoad:
  1681. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1682. break;
  1683. case FilamentAction::MmuEject:
  1684. case FilamentAction::MmuCut:
  1685. case FilamentAction::None:
  1686. case FilamentAction::Preheat:
  1687. case FilamentAction::Lay1Cal:
  1688. break;
  1689. }
  1690. if(lcd_clicked()
  1691. #ifdef FILAMENT_SENSOR
  1692. /// @todo leptun - add this as a specific retest item
  1693. || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent())
  1694. #endif //FILAMENT_SENSOR
  1695. ) {
  1696. nLevel=2;
  1697. if(!bFilamentPreheatState)
  1698. {
  1699. nLevel++;
  1700. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1701. }
  1702. menu_back(nLevel);
  1703. switch(eFilamentAction)
  1704. {
  1705. case FilamentAction::AutoLoad:
  1706. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1707. // FALLTHRU
  1708. case FilamentAction::Load:
  1709. loading_flag=true;
  1710. enquecommand_P(PSTR("M701")); // load filament
  1711. break;
  1712. case FilamentAction::UnLoad:
  1713. enquecommand_P(PSTR("M702")); // unload filament
  1714. break;
  1715. case FilamentAction::MmuLoad:
  1716. case FilamentAction::MmuLoadingTest:
  1717. case FilamentAction::MmuUnLoad:
  1718. case FilamentAction::MmuEject:
  1719. case FilamentAction::MmuCut:
  1720. case FilamentAction::None:
  1721. case FilamentAction::Preheat:
  1722. case FilamentAction::Lay1Cal:
  1723. break;
  1724. }
  1725. }
  1726. }
  1727. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1728. {
  1729. uint8_t nLevel;
  1730. setTargetHotend0((float)nTemp);
  1731. if (!shouldPreheatOnlyNozzle()) setTargetBed((float)nTempBed);
  1732. {
  1733. const FilamentAction action = eFilamentAction;
  1734. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1735. {
  1736. lcd_return_to_status();
  1737. if (action == FilamentAction::Lay1Cal)
  1738. {
  1739. lcd_commands_type = LcdCommands::Layer1Cal;
  1740. }
  1741. else
  1742. {
  1743. raise_z_above(MIN_Z_FOR_PREHEAT);
  1744. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1745. lcd_wizard(WizState::LoadFilHot);
  1746. }
  1747. return;
  1748. }
  1749. }
  1750. lcd_timeoutToStatus.stop();
  1751. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1752. {
  1753. switch (eFilamentAction)
  1754. {
  1755. case FilamentAction::Load:
  1756. case FilamentAction::AutoLoad:
  1757. case FilamentAction::UnLoad:
  1758. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1759. else
  1760. {
  1761. nLevel = bFilamentPreheatState ? 1 : 2;
  1762. menu_back(nLevel);
  1763. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1764. {
  1765. loading_flag = true;
  1766. enquecommand_P(PSTR("M701")); // load filament
  1767. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1768. }
  1769. if (eFilamentAction == FilamentAction::UnLoad)
  1770. enquecommand_P(PSTR("M702")); // unload filament
  1771. }
  1772. break;
  1773. case FilamentAction::MmuLoad:
  1774. nLevel = bFilamentPreheatState ? 1 : 2;
  1775. bFilamentAction = true;
  1776. menu_back(nLevel);
  1777. menu_submenu(mmu_load_to_nozzle_menu);
  1778. break;
  1779. case FilamentAction::MmuLoadingTest:
  1780. nLevel = bFilamentPreheatState ? 1 : 2;
  1781. bFilamentAction = true;
  1782. menu_back(nLevel);
  1783. menu_submenu(mmu_loading_test_menu);
  1784. break;
  1785. case FilamentAction::MmuUnLoad:
  1786. nLevel = bFilamentPreheatState ? 1 : 2;
  1787. bFilamentAction = true;
  1788. menu_back(nLevel);
  1789. MMU2::mmu2.unload();
  1790. break;
  1791. case FilamentAction::MmuEject:
  1792. nLevel = bFilamentPreheatState ? 1 : 2;
  1793. bFilamentAction = true;
  1794. menu_back(nLevel);
  1795. menu_submenu(mmu_fil_eject_menu);
  1796. break;
  1797. case FilamentAction::MmuCut:
  1798. #ifdef MMU_HAS_CUTTER
  1799. nLevel=bFilamentPreheatState?1:2;
  1800. bFilamentAction=true;
  1801. menu_back(nLevel);
  1802. menu_submenu(mmu_cut_filament_menu);
  1803. #endif //MMU_HAS_CUTTER
  1804. break;
  1805. case FilamentAction::None:
  1806. case FilamentAction::Preheat:
  1807. case FilamentAction::Lay1Cal:
  1808. // handled earlier
  1809. break;
  1810. }
  1811. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  1812. bFilamentWaitingFlag = false;
  1813. }
  1814. else
  1815. {
  1816. if (!bFilamentWaitingFlag || lcd_draw_update)
  1817. {
  1818. // First entry from another menu OR first run after the filament preheat selection. Use
  1819. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  1820. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  1821. // modified elsewhere and needs to be redrawn in full.
  1822. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  1823. bool once = !bFilamentWaitingFlag;
  1824. bFilamentWaitingFlag = true;
  1825. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  1826. lcd_draw_update = 1;
  1827. lcd_clear();
  1828. lcd_puts_at_P(0, 3, _T(MSG_CANCEL));
  1829. lcd_set_cursor(0, 1);
  1830. switch (eFilamentAction)
  1831. {
  1832. case FilamentAction::Load:
  1833. case FilamentAction::AutoLoad:
  1834. case FilamentAction::MmuLoad:
  1835. case FilamentAction::MmuLoadingTest:
  1836. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  1837. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  1838. break;
  1839. case FilamentAction::UnLoad:
  1840. case FilamentAction::MmuUnLoad:
  1841. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  1842. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  1843. break;
  1844. case FilamentAction::MmuEject:
  1845. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  1846. break;
  1847. case FilamentAction::MmuCut:
  1848. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  1849. break;
  1850. case FilamentAction::None:
  1851. case FilamentAction::Preheat:
  1852. case FilamentAction::Lay1Cal:
  1853. // handled earlier
  1854. break;
  1855. }
  1856. }
  1857. if (bFilamentWaitingFlag) {
  1858. lcd_print_target_temps_first_line();
  1859. }
  1860. if (lcd_clicked())
  1861. {
  1862. bFilamentWaitingFlag = false;
  1863. if (!bFilamentPreheatState)
  1864. {
  1865. setTargetHotend0(0.0);
  1866. if (!isPrintPaused) setTargetBed(0.0);
  1867. menu_back();
  1868. }
  1869. menu_back();
  1870. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1871. }
  1872. }
  1873. }
  1874. static void mFilamentItem_farm()
  1875. {
  1876. bFilamentPreheatState = false;
  1877. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  1878. }
  1879. static void mFilamentItem_farm_nozzle()
  1880. {
  1881. bFilamentPreheatState = false;
  1882. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  1883. }
  1884. static void mFilamentItem_PLA()
  1885. {
  1886. bFilamentPreheatState = false;
  1887. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  1888. }
  1889. static void mFilamentItem_PET()
  1890. {
  1891. bFilamentPreheatState = false;
  1892. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  1893. }
  1894. static void mFilamentItem_ASA()
  1895. {
  1896. bFilamentPreheatState = false;
  1897. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  1898. }
  1899. static void mFilamentItem_PC()
  1900. {
  1901. bFilamentPreheatState = false;
  1902. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  1903. }
  1904. static void mFilamentItem_ABS()
  1905. {
  1906. bFilamentPreheatState = false;
  1907. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  1908. }
  1909. static void mFilamentItem_PA()
  1910. {
  1911. bFilamentPreheatState = false;
  1912. mFilamentItem(PA_PREHEAT_HOTEND_TEMP, PA_PREHEAT_HPB_TEMP);
  1913. }
  1914. static void mFilamentItem_HIPS()
  1915. {
  1916. bFilamentPreheatState = false;
  1917. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  1918. }
  1919. static void mFilamentItem_PP()
  1920. {
  1921. bFilamentPreheatState = false;
  1922. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  1923. }
  1924. static void mFilamentItem_FLEX()
  1925. {
  1926. bFilamentPreheatState = false;
  1927. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  1928. }
  1929. static void mFilamentItem_PVB()
  1930. {
  1931. bFilamentPreheatState = false;
  1932. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  1933. }
  1934. void mFilamentBack()
  1935. {
  1936. if (eFilamentAction == FilamentAction::AutoLoad ||
  1937. eFilamentAction == FilamentAction::Preheat ||
  1938. eFilamentAction == FilamentAction::Lay1Cal)
  1939. {
  1940. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1941. }
  1942. }
  1943. void lcd_generic_preheat_menu()
  1944. {
  1945. MENU_BEGIN();
  1946. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1947. {
  1948. ON_MENU_LEAVE(
  1949. mFilamentBack();
  1950. );
  1951. MENU_ITEM_BACK_P(_T(eFilamentAction == FilamentAction::Lay1Cal ? MSG_BACK : MSG_MAIN));
  1952. }
  1953. if (farm_mode)
  1954. {
  1955. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  1956. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  1957. }
  1958. else
  1959. {
  1960. bool bPreheatOnlyNozzle = shouldPreheatOnlyNozzle();
  1961. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)) : PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)) , mFilamentItem_PLA);
  1962. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP)) : PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)) , mFilamentItem_PET);
  1963. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP)) : PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)) , mFilamentItem_ASA);
  1964. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP)) : PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)) , mFilamentItem_PC);
  1965. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP)) : PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)) , mFilamentItem_PVB);
  1966. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PA - " STRINGIFY(PA_PREHEAT_HOTEND_TEMP)) : PSTR("PA - " STRINGIFY(PA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PA_PREHEAT_HPB_TEMP)) , mFilamentItem_PA);
  1967. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP)) : PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)) , mFilamentItem_ABS);
  1968. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP)): PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), mFilamentItem_HIPS);
  1969. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP)) : PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)) , mFilamentItem_PP);
  1970. MENU_ITEM_SUBMENU_P(bPreheatOnlyNozzle ? PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP)): PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), mFilamentItem_FLEX);
  1971. }
  1972. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1973. MENU_END();
  1974. }
  1975. void mFilamentItemForce()
  1976. {
  1977. mFilamentItem(target_temperature[0],target_temperature_bed);
  1978. }
  1979. void lcd_unLoadFilament()
  1980. {
  1981. eFilamentAction=FilamentAction::UnLoad;
  1982. preheat_or_continue();
  1983. }
  1984. static void mmu_unload_filament()
  1985. {
  1986. eFilamentAction = FilamentAction::MmuUnLoad;
  1987. preheat_or_continue();
  1988. }
  1989. void lcd_wait_interact() {
  1990. lcd_clear();
  1991. lcd_puts_at_P(0, 1, _i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  1992. #ifdef FILAMENT_SENSOR
  1993. if (!fsensor.getAutoLoadEnabled())
  1994. #endif //FILAMENT_SENSOR
  1995. {
  1996. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  1997. }
  1998. }
  1999. void lcd_change_success() {
  2000. lcd_clear();
  2001. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  2002. }
  2003. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  2004. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  2005. lcd_putc_at(i, 3, '.');
  2006. //loading_time_ms/20 delay
  2007. for (uint_least8_t j = 0; j < 5; j++) {
  2008. delay_keep_alive(loading_time_ms / 100);
  2009. }
  2010. }
  2011. }
  2012. void lcd_loading_color() {
  2013. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  2014. lcd_clear();
  2015. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  2016. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2017. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  2018. }
  2019. void lcd_loading_filament() {
  2020. lcd_clear();
  2021. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  2022. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2023. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  2024. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  2025. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  2026. }
  2027. uint8_t lcd_alright() {
  2028. int8_t enc_dif = 0;
  2029. uint8_t cursor_pos = 1;
  2030. lcd_clear();
  2031. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  2032. lcd_puts_at_P(1, 1, _T(MSG_YES));
  2033. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  2034. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  2035. lcd_putc_at(0, 1, '>');
  2036. enc_dif = lcd_encoder_diff;
  2037. lcd_consume_click();
  2038. while (1)
  2039. {
  2040. manage_heater();
  2041. manage_inactivity(true);
  2042. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  2043. {
  2044. if (enc_dif > lcd_encoder_diff ) {
  2045. // Rotating knob counter clockwise
  2046. cursor_pos--;
  2047. } else if (enc_dif < lcd_encoder_diff) {
  2048. // Rotating knob clockwise
  2049. cursor_pos++;
  2050. }
  2051. if (cursor_pos > 3) {
  2052. cursor_pos = 3;
  2053. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2054. } else if (cursor_pos < 1) {
  2055. cursor_pos = 1;
  2056. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2057. }
  2058. // Update '>' render only
  2059. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  2060. lcd_putc_at(0, cursor_pos, '>');
  2061. // Consume rotation event and make feedback sound
  2062. enc_dif = lcd_encoder_diff;
  2063. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2064. _delay(100);
  2065. }
  2066. if (lcd_clicked())
  2067. {
  2068. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2069. lcd_clear();
  2070. lcd_return_to_status();
  2071. return cursor_pos;
  2072. }
  2073. };
  2074. }
  2075. void show_preheat_nozzle_warning()
  2076. {
  2077. lcd_clear();
  2078. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2079. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2080. _delay(2000);
  2081. lcd_clear();
  2082. }
  2083. void lcd_load_filament_color_check()
  2084. {
  2085. uint8_t clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2086. while (clean == LCD_MIDDLE_BUTTON_CHOICE) {
  2087. load_filament_final_feed();
  2088. st_synchronize();
  2089. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2090. }
  2091. }
  2092. #ifdef FILAMENT_SENSOR
  2093. static void lcd_menu_AutoLoadFilament()
  2094. {
  2095. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament is active, just press the knob and insert filament..."));////MSG_AUTOLOADING_ENABLED c=20 r=4
  2096. menu_back_if_clicked();
  2097. }
  2098. #endif //FILAMENT_SENSOR
  2099. static void preheat_or_continue() {
  2100. if (target_temperature[0] >= extrude_min_temp) {
  2101. bFilamentPreheatState = true;
  2102. mFilamentItem(target_temperature[0], target_temperature_bed);
  2103. } else {
  2104. lcd_generic_preheat_menu();
  2105. }
  2106. }
  2107. static void lcd_LoadFilament()
  2108. {
  2109. eFilamentAction = FilamentAction::Load;
  2110. preheat_or_continue();
  2111. }
  2112. //! @brief Show filament used a print time
  2113. //!
  2114. //! If printing current print statistics are shown
  2115. //!
  2116. //! @code{.unparsed}
  2117. //! |01234567890123456789|
  2118. //! |Filament used: | MSG_FILAMENT_USED c=19
  2119. //! | 0000.00m |
  2120. //! |Print time: | MSG_PRINT_TIME c=19
  2121. //! | 00h 00m 00s |
  2122. //! ----------------------
  2123. //! @endcode
  2124. //!
  2125. //! If not printing, total statistics are shown
  2126. //!
  2127. //! @code{.unparsed}
  2128. //! |01234567890123456789|
  2129. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2130. //! | 0000.00m |
  2131. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2132. //! | 00d 00h 00m |
  2133. //! ----------------------
  2134. //! @endcode
  2135. void lcd_menu_statistics()
  2136. {
  2137. lcd_timeoutToStatus.stop(); //infinite timeout
  2138. if (IS_SD_PRINTING)
  2139. {
  2140. const float _met = ((float)total_filament_used) / (100000.f);
  2141. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2142. const uint32_t _h = _t / 3600;
  2143. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2144. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2145. lcd_home();
  2146. lcd_printf_P(_N(
  2147. "%S:\n"
  2148. "%18.2fm \n"
  2149. "%S:\n"
  2150. "%10ldh %02dm %02ds"
  2151. ),
  2152. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2153. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2154. menu_back_if_clicked_fb();
  2155. }
  2156. else
  2157. {
  2158. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2159. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2160. uint8_t _hours, _minutes;
  2161. uint32_t _days;
  2162. float _filament_m = (float)_filament/100;
  2163. _days = _time / 1440;
  2164. _hours = (_time - (_days * 1440)) / 60;
  2165. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2166. lcd_home();
  2167. lcd_printf_P(_N(
  2168. "%S:\n"
  2169. "%18.2fm \n"
  2170. "%S:\n"
  2171. "%10ldd %02dh %02dm"
  2172. ),
  2173. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2174. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2175. menu_back_if_clicked_fb();
  2176. }
  2177. }
  2178. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2179. {
  2180. if (homing_flag || mesh_bed_leveling_flag)
  2181. {
  2182. // printer entered a new state where axis move is forbidden
  2183. menu_back();
  2184. return;
  2185. }
  2186. typedef struct
  2187. { // 2bytes total
  2188. bool initialized; // 1byte
  2189. bool endstopsEnabledPrevious; // 1byte
  2190. } _menu_data_t;
  2191. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2192. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2193. if (!_md->initialized)
  2194. {
  2195. _md->endstopsEnabledPrevious = enable_endstops(false);
  2196. _md->initialized = true;
  2197. }
  2198. if (lcd_encoder != 0)
  2199. {
  2200. refresh_cmd_timeout();
  2201. if (! planner_queue_full())
  2202. {
  2203. current_position[axis] += float((int)lcd_encoder);
  2204. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2205. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2206. lcd_encoder = 0;
  2207. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2208. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2209. lcd_draw_update = 1;
  2210. }
  2211. }
  2212. if (lcd_draw_update)
  2213. {
  2214. lcd_set_cursor(0, 1);
  2215. menu_draw_float31(name, current_position[axis]);
  2216. }
  2217. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2218. if (LCD_CLICKED) menu_back();
  2219. }
  2220. void lcd_move_e()
  2221. {
  2222. if ((int)degHotend0() > extrude_min_temp)
  2223. {
  2224. if (lcd_encoder != 0)
  2225. {
  2226. refresh_cmd_timeout();
  2227. if (! planner_queue_full())
  2228. {
  2229. current_position[E_AXIS] += float((int)lcd_encoder);
  2230. lcd_encoder = 0;
  2231. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2232. lcd_draw_update = 1;
  2233. }
  2234. }
  2235. if (lcd_draw_update)
  2236. {
  2237. lcd_set_cursor(0, 1);
  2238. // Note: the colon behind the text is necessary to greatly shorten
  2239. // the implementation of menu_draw_float31
  2240. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2241. }
  2242. if (LCD_CLICKED) menu_back();
  2243. }
  2244. else
  2245. {
  2246. show_preheat_nozzle_warning();
  2247. lcd_return_to_status();
  2248. }
  2249. }
  2250. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2251. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2252. //! This functionality is applied more often for MK2 printers.
  2253. //! @code{.unparsed}
  2254. //! |01234567890123456789|
  2255. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2256. //! | -------------- | STR_SEPARATOR
  2257. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2258. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2259. //! ----------------------
  2260. //! @endcode
  2261. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2262. static void lcd_menu_xyz_y_min()
  2263. {
  2264. float distanceMin[2];
  2265. count_xyz_details(distanceMin);
  2266. lcd_home();
  2267. lcd_printf_P(_N(
  2268. "%S\n"
  2269. "%S\n"
  2270. "%S:\n"
  2271. "%S:"
  2272. ),
  2273. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2274. separator,
  2275. _i("Left"), ////MSG_LEFT c=10
  2276. _i("Right") ////MSG_RIGHT c=10
  2277. );
  2278. for (uint8_t i = 0; i < 2; i++)
  2279. {
  2280. lcd_set_cursor(11,2+i);
  2281. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2282. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2283. }
  2284. if (lcd_clicked())
  2285. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2286. }
  2287. //@brief Show measured axis skewness
  2288. float _deg(float rad)
  2289. {
  2290. return rad * 180 / M_PI;
  2291. }
  2292. //! @brief Show Measured XYZ Skew
  2293. //!
  2294. //! @code{.unparsed}
  2295. //! |01234567890123456789|
  2296. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14
  2297. //! | -------------- | STR_SEPARATOR
  2298. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14
  2299. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14
  2300. //! ----------------------
  2301. //! D - Degree sysmbol LCD_STR_DEGREE
  2302. //! @endcode
  2303. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2304. static void lcd_menu_xyz_skew()
  2305. {
  2306. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2307. lcd_home();
  2308. lcd_printf_P(_N(
  2309. "%-14.14S:\n"
  2310. "%S\n"
  2311. "%-14.14S:%3.2f\x01\n"
  2312. "%-14.14S:%3.2f\x01"
  2313. ),
  2314. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2315. separator,
  2316. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14
  2317. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14
  2318. );
  2319. if (angleDiff < 100){
  2320. lcd_set_cursor(15,0);
  2321. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2322. }
  2323. else{
  2324. lcd_puts_at_P(15,0, _T(MSG_NA));
  2325. }
  2326. if (lcd_clicked())
  2327. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2328. }
  2329. //! @brief Show measured bed offset from expected position
  2330. //!
  2331. //! @code{.unparsed}
  2332. //! |01234567890123456789|
  2333. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2334. //! | -------------- | STR_SEPARATOR
  2335. //! |X 00.00mm| c=10
  2336. //! |Y 00.00mm| c=10
  2337. //! ----------------------
  2338. //! @endcode
  2339. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2340. static void lcd_menu_xyz_offset()
  2341. {
  2342. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2343. lcd_puts_at_P(0, 1, separator);
  2344. lcd_puts_at_P(0, 2, PSTR("X"));
  2345. lcd_puts_at_P(0, 3, PSTR("Y"));
  2346. float vec_x[2];
  2347. float vec_y[2];
  2348. float cntr[2];
  2349. world2machine_read_valid(vec_x, vec_y, cntr);
  2350. for (uint_least8_t i = 0; i < 2; i++)
  2351. {
  2352. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2353. lcd_print(cntr[i]);
  2354. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2355. }
  2356. menu_back_if_clicked();
  2357. }
  2358. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2359. // the implementation of menu_draw_float31
  2360. static void lcd_move_x() {
  2361. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2362. }
  2363. static void lcd_move_y() {
  2364. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2365. }
  2366. static void lcd_move_z() {
  2367. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2368. }
  2369. /**
  2370. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2371. *
  2372. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2373. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2374. * Purpose of this function for other axis then Z is unknown.
  2375. *
  2376. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2377. * other value leads to storing Z_AXIS
  2378. * @param msg text to be displayed
  2379. */
  2380. static void lcd_babystep_z()
  2381. {
  2382. if (homing_flag || mesh_bed_leveling_flag)
  2383. {
  2384. // printer changed to a new state where live Z is forbidden
  2385. menu_back();
  2386. return;
  2387. }
  2388. typedef struct
  2389. {
  2390. int8_t status;
  2391. int16_t babystepMemZ;
  2392. float babystepMemMMZ;
  2393. } _menu_data_t;
  2394. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2395. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2396. if (_md->status == 0)
  2397. {
  2398. // Menu was entered.
  2399. // Initialize its status.
  2400. _md->status = 1;
  2401. check_babystep();
  2402. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2403. _md->babystepMemZ = 0;
  2404. }
  2405. else{
  2406. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2407. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2408. }
  2409. // same logic as in babystep_load
  2410. if (!calibration_status_get(CALIBRATION_STATUS_LIVE_ADJUST))
  2411. _md->babystepMemZ = 0;
  2412. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2413. lcd_draw_update = 1;
  2414. //SERIAL_ECHO("Z baby step: ");
  2415. //SERIAL_ECHO(_md->babystepMem[2]);
  2416. }
  2417. if (lcd_encoder != 0)
  2418. {
  2419. _md->babystepMemZ += (int)lcd_encoder;
  2420. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2421. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2422. else babystepsTodoZadd(lcd_encoder);
  2423. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2424. _delay(50);
  2425. lcd_encoder = 0;
  2426. lcd_draw_update = 1;
  2427. }
  2428. if (lcd_draw_update)
  2429. {
  2430. SheetFormatBuffer buffer;
  2431. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2432. lcd_set_cursor(0, 0);
  2433. lcd_print(buffer.c);
  2434. lcd_set_cursor(0, 1);
  2435. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 // Beware: must include the ':' as its last character
  2436. }
  2437. if (LCD_CLICKED || menu_leaving)
  2438. {
  2439. // Only update the EEPROM when leaving the menu.
  2440. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2441. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2442. // NOTE: bed_temp and pinda_temp are not currently read/used anywhere.
  2443. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2444. #ifdef PINDA_THERMISTOR
  2445. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2446. #endif //PINDA_THERMISTOR
  2447. calibration_status_set(CALIBRATION_STATUS_LIVE_ADJUST);
  2448. }
  2449. if (LCD_CLICKED) menu_back();
  2450. }
  2451. typedef struct
  2452. { // 12bytes + 9bytes = 21bytes total
  2453. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2454. int8_t status; // 1byte
  2455. int16_t left; // 2byte
  2456. int16_t right; // 2byte
  2457. int16_t front; // 2byte
  2458. int16_t rear; // 2byte
  2459. } _menu_data_adjust_bed_t;
  2460. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2461. void lcd_adjust_bed_reset(void)
  2462. {
  2463. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2464. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2465. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2466. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2467. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2468. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2469. _md->status = 0;
  2470. }
  2471. //! @brief Show Bed level correct
  2472. //!
  2473. //! @code{.unparsed}
  2474. //! |01234567890123456789|
  2475. //! |Settings: | MSG_SETTINGS
  2476. //! |Left side [µm]: | MSG_BED_CORRECTION_LEFT
  2477. //! |Right side[µm]: | MSG_BED_CORRECTION_RIGHT
  2478. //! |Front side[µm]: | MSG_BED_CORRECTION_FRONT
  2479. //! |Rear side [µm]: | MSG_BED_CORRECTION_REAR
  2480. //! |Reset | MSG_BED_CORRECTION_RESET
  2481. //! ----------------------
  2482. //! @endcode
  2483. void lcd_adjust_bed(void)
  2484. {
  2485. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2486. if (_md->status == 0)
  2487. {
  2488. // Menu was entered.
  2489. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2490. {
  2491. _md->left = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT);
  2492. _md->right = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT);
  2493. _md->front = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT);
  2494. _md->rear = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR);
  2495. }
  2496. _md->status = 1;
  2497. }
  2498. MENU_BEGIN();
  2499. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2500. ON_MENU_LEAVE(
  2501. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT, (uint8_t)_md->left);
  2502. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT, (uint8_t)_md->front);
  2503. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR, (uint8_t)_md->rear);
  2504. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT, (uint8_t)_md->right);
  2505. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_VALID, 1);
  2506. );
  2507. MENU_ITEM_BACK_P(_T(MSG_BACK));
  2508. MENU_ITEM_EDIT_int3_P(_i("Left side [\xe4m]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14
  2509. MENU_ITEM_EDIT_int3_P(_i("Right side[\xe4m]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14
  2510. MENU_ITEM_EDIT_int3_P(_i("Front side[\xe4m]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14
  2511. MENU_ITEM_EDIT_int3_P(_i("Rear side [\xe4m]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14
  2512. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);
  2513. MENU_END();
  2514. }
  2515. //! @brief Show PID Extruder
  2516. //!
  2517. //! @code{.unparsed}
  2518. //! |01234567890123456789|
  2519. //! |Set temperature: |
  2520. //! | |
  2521. //! | 210 |
  2522. //! | |
  2523. //! ----------------------
  2524. //! @endcode
  2525. void pid_extruder()
  2526. {
  2527. lcd_clear();
  2528. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE c=20
  2529. pid_temp += int(lcd_encoder);
  2530. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2531. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2532. lcd_encoder = 0;
  2533. lcd_set_cursor(1, 2);
  2534. lcd_printf_P(PSTR("%3u"), pid_temp);
  2535. if (lcd_clicked()) {
  2536. lcd_commands_type = LcdCommands::PidExtruder;
  2537. lcd_return_to_status();
  2538. lcd_update(2);
  2539. }
  2540. }
  2541. #ifdef PINDA_THERMISTOR
  2542. bool lcd_wait_for_pinda(float temp) {
  2543. setAllTargetHotends(0);
  2544. setTargetBed(0);
  2545. LongTimer pinda_timeout;
  2546. pinda_timeout.start();
  2547. bool target_temp_reached = true;
  2548. while (current_temperature_pinda > temp){
  2549. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2550. lcd_set_cursor(0, 4);
  2551. lcd_print(LCD_STR_THERMOMETER[0]);
  2552. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)current_temperature_pinda, (int16_t) temp);
  2553. lcd_print(LCD_STR_DEGREE[0]);
  2554. delay_keep_alive(1000);
  2555. serialecho_temperatures();
  2556. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2557. target_temp_reached = false;
  2558. break;
  2559. }
  2560. }
  2561. lcd_update_enable(true);
  2562. return target_temp_reached;
  2563. }
  2564. #endif //PINDA_THERMISTOR
  2565. void lcd_wait_for_heater() {
  2566. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2567. lcd_set_cursor(0, 4);
  2568. lcd_print(LCD_STR_THERMOMETER[0]);
  2569. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)degHotend(active_extruder), (int16_t) degTargetHotend(active_extruder));
  2570. lcd_print(LCD_STR_DEGREE[0]);
  2571. }
  2572. void lcd_wait_for_cool_down() {
  2573. setAllTargetHotends(0);
  2574. setTargetBed(0);
  2575. int fanSpeedBckp = fanSpeed;
  2576. fanSpeed = 255;
  2577. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2578. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2579. lcd_set_cursor(0, 4);
  2580. lcd_print(LCD_STR_THERMOMETER[0]);
  2581. lcd_printf_P(PSTR("%3d/0"), (int16_t)degHotend(0));
  2582. lcd_print(LCD_STR_DEGREE[0]);
  2583. lcd_set_cursor(9, 4);
  2584. lcd_print(LCD_STR_BEDTEMP[0]);
  2585. lcd_printf_P(PSTR("%3d/0"), (int16_t)degBed());
  2586. lcd_print(LCD_STR_DEGREE[0]);
  2587. delay_keep_alive(1000);
  2588. serialecho_temperatures();
  2589. }
  2590. fanSpeed = fanSpeedBckp;
  2591. lcd_update_enable(true);
  2592. }
  2593. // Lets the user move the Z carriage up to the end stoppers.
  2594. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2595. // Otherwise the Z calibration is not changed and false is returned.
  2596. #ifndef TMC2130
  2597. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2598. {
  2599. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  2600. current_position[Z_AXIS] = 0;
  2601. plan_set_position_curposXYZE();
  2602. // Until confirmed by the confirmation dialog.
  2603. for (;;) {
  2604. const char *msg = only_z
  2605. ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.")////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2606. : _i("Calibrating XYZ. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.");////MSG_MOVE_CARRIAGE_TO_THE_TOP c=20 r=8
  2607. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2608. const bool multi_screen = msg_next != NULL;
  2609. unsigned long previous_millis_msg = _millis();
  2610. // Until the user finishes the z up movement.
  2611. lcd_encoder_diff = 0;
  2612. lcd_encoder = 0;
  2613. for (;;) {
  2614. manage_heater();
  2615. manage_inactivity(true);
  2616. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2617. _delay(50);
  2618. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2619. lcd_encoder_diff = 0;
  2620. if (! planner_queue_full()) {
  2621. // Only move up, whatever direction the user rotates the encoder.
  2622. current_position[Z_AXIS] += fabs(lcd_encoder);
  2623. lcd_encoder = 0;
  2624. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2625. }
  2626. }
  2627. if (lcd_clicked()) {
  2628. // Abort a move if in progress.
  2629. planner_abort_hard();
  2630. planner_aborted = false;
  2631. while (lcd_clicked()) ;
  2632. _delay(10);
  2633. while (lcd_clicked()) ;
  2634. break;
  2635. }
  2636. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2637. if (msg_next == NULL)
  2638. msg_next = msg;
  2639. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2640. previous_millis_msg = _millis();
  2641. }
  2642. }
  2643. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2644. uint8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Are left and right Z~carriages all up?"), false);////MSG_CONFIRM_CARRIAGE_AT_THE_TOP c=20 r=2
  2645. if (result == LCD_BUTTON_TIMEOUT)
  2646. goto canceled;
  2647. else if (result == LCD_LEFT_BUTTON_CHOICE)
  2648. goto calibrated;
  2649. // otherwise perform another round of the Z up dialog.
  2650. }
  2651. calibrated:
  2652. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2653. // during the search for the induction points.
  2654. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2655. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2656. }
  2657. else {
  2658. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2659. }
  2660. plan_set_position_curposXYZE();
  2661. return true;
  2662. canceled:
  2663. return false;
  2664. }
  2665. #endif // TMC2130
  2666. static inline bool pgm_is_whitespace(const char *c_addr)
  2667. {
  2668. const char c = pgm_read_byte(c_addr);
  2669. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2670. }
  2671. static inline bool pgm_is_interpunction(const char *c_addr)
  2672. {
  2673. const char c = pgm_read_byte(c_addr);
  2674. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2675. }
  2676. /**
  2677. * @brief show full screen message
  2678. *
  2679. * This function is non-blocking
  2680. * @param msg message to be displayed from PROGMEM
  2681. * @return rest of the text (to be displayed on next page)
  2682. */
  2683. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg)
  2684. {
  2685. const char *msgend = msg;
  2686. bool multi_screen = false;
  2687. for (uint8_t row = 0; row < LCD_HEIGHT; ++ row) {
  2688. lcd_set_cursor(0, row);
  2689. // Previous row ended with a complete word, so the first character in the
  2690. // next row is a whitespace. We can skip the whitespace on a new line.
  2691. if (pgm_is_whitespace(msg) && ++msg == nullptr)
  2692. {
  2693. // End of the message.
  2694. break;
  2695. }
  2696. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  2697. const char *msgend2 = msg + linelen;
  2698. msgend = msgend2;
  2699. if (row == 3 && linelen == LCD_WIDTH) {
  2700. // Last line of the display, full line shall be displayed.
  2701. // Find out, whether this message will be split into multiple screens.
  2702. multi_screen = pgm_read_byte(msgend) != 0;
  2703. if (multi_screen)
  2704. msgend = (msgend2 -= 2);
  2705. }
  2706. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2707. // Splitting a word. Find the start of the current word.
  2708. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2709. -- msgend;
  2710. if (msgend == msg)
  2711. // Found a single long word, which cannot be split. Just cut it.
  2712. msgend = msgend2;
  2713. }
  2714. for (; msg < msgend; ++ msg) {
  2715. char c = char(pgm_read_byte(msg));
  2716. if (c == '~')
  2717. c = ' ';
  2718. else if (c == '\n') {
  2719. // Abort early if '\n' is encontered.
  2720. // This character is used to force the following words to be printed on the next line.
  2721. break;
  2722. }
  2723. lcd_print(c);
  2724. }
  2725. }
  2726. if (multi_screen) {
  2727. // Display the "next screen" indicator character.
  2728. lcd_set_custom_characters_nextpage();
  2729. lcd_set_cursor(19, 3);
  2730. // Display the double down arrow.
  2731. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  2732. }
  2733. return multi_screen ? msgend : NULL;
  2734. }
  2735. const char* lcd_display_message_fullscreen_P(const char *msg)
  2736. {
  2737. // Disable update of the screen by the usual lcd_update(0) routine.
  2738. lcd_update_enable(false);
  2739. lcd_clear();
  2740. return lcd_display_message_fullscreen_nonBlocking_P(msg);
  2741. }
  2742. /**
  2743. * @brief show full screen message and wait
  2744. *
  2745. * This function is blocking.
  2746. * @param msg message to be displayed from PROGMEM
  2747. */
  2748. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2749. {
  2750. LcdUpdateDisabler lcdUpdateDisabler;
  2751. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2752. bool multi_screen = msg_next != NULL;
  2753. lcd_set_custom_characters_nextpage();
  2754. lcd_consume_click();
  2755. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2756. // Until confirmed by a button click.
  2757. for (;;) {
  2758. if (msg_next == NULL) {
  2759. lcd_set_cursor(19, 3);
  2760. // Display the confirm char.
  2761. lcd_print(LCD_STR_CONFIRM[0]);
  2762. }
  2763. // Wait for 5 seconds before displaying the next text.
  2764. for (uint8_t i = 0; i < 100; ++ i) {
  2765. delay_keep_alive(50);
  2766. if (lcd_clicked()) {
  2767. if (msg_next == NULL) {
  2768. KEEPALIVE_STATE(IN_HANDLER);
  2769. lcd_set_custom_characters();
  2770. return;
  2771. }
  2772. else {
  2773. break;
  2774. }
  2775. }
  2776. }
  2777. if (multi_screen) {
  2778. if (msg_next == NULL)
  2779. msg_next = msg;
  2780. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2781. }
  2782. }
  2783. }
  2784. bool lcd_wait_for_click_delay(uint16_t nDelay)
  2785. // nDelay :: timeout [s] (0 ~ no timeout)
  2786. // true ~ clicked, false ~ delayed
  2787. {
  2788. bool bDelayed;
  2789. long nTime0 = _millis()/1000;
  2790. lcd_consume_click();
  2791. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2792. for (;;) {
  2793. manage_heater();
  2794. manage_inactivity(true);
  2795. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  2796. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  2797. if (lcd_clicked() || bDelayed) {
  2798. KEEPALIVE_STATE(IN_HANDLER);
  2799. return(!bDelayed);
  2800. }
  2801. }
  2802. }
  2803. void lcd_wait_for_click()
  2804. {
  2805. lcd_wait_for_click_delay(0);
  2806. }
  2807. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  2808. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2809. //! @param allow_timeouting if true, allows time outing of the screen
  2810. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2811. //! @retval 0 yes choice selected by user
  2812. //! @retval 1 no choice selected by user
  2813. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2814. uint8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection) //currently just max. n*4 + 3 lines supported (set in language header files)
  2815. {
  2816. return lcd_show_multiscreen_message_with_choices_and_wait_P(msg, allow_timeouting, default_selection, _T(MSG_YES), _T(MSG_NO), nullptr, 10);
  2817. }
  2818. //! @brief Show a two-choice prompt on the last line of the LCD
  2819. //! @param selected Show first choice as selected if true, the second otherwise
  2820. //! @param first_choice text caption of first possible choice
  2821. //! @param second_choice text caption of second possible choice
  2822. //! @param second_col column on LCD where second choice is rendered.
  2823. //! @param third_choice text caption of third, optional, choice.
  2824. void lcd_show_choices_prompt_P(uint8_t selected, const char *first_choice, const char *second_choice, uint8_t second_col, const char *third_choice)
  2825. {
  2826. lcd_set_cursor(0, 3);
  2827. lcd_print(selected == LCD_LEFT_BUTTON_CHOICE ? '>': ' ');
  2828. lcd_puts_P(first_choice);
  2829. lcd_set_cursor(second_col, 3);
  2830. lcd_print(selected == LCD_MIDDLE_BUTTON_CHOICE ? '>': ' ');
  2831. lcd_puts_P(second_choice);
  2832. if (third_choice)
  2833. {
  2834. lcd_set_cursor(18, 3);
  2835. lcd_print(selected == LCD_RIGHT_BUTTON_CHOICE ? '>': ' ');
  2836. lcd_puts_P(third_choice);
  2837. }
  2838. }
  2839. //! @brief Show single or multiple screen message with two possible choices and wait with possible timeout
  2840. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2841. //! @param allow_timeouting bool, if true, allows time outing of the screen
  2842. //! @param default_selection uint8_t, Control which choice is selected first. 0: left most, 1: middle, 2: right most choice. The left most choice is selected by default
  2843. //! @param first_choice text caption of first possible choice. Must be in PROGMEM
  2844. //! @param second_choice text caption of second possible choice. Must be in PROGMEM
  2845. //! @param third_choice text caption of second possible choice. Must be in PROGMEM. When not set to nullptr first_choice and second_choice may not be more than 5 characters long.
  2846. //! @param second_col column on LCD where second_choice starts
  2847. //! @retval 0 first choice selected by user
  2848. //! @retval 1 first choice selected by user
  2849. //! @retval 2 third choice selected by user
  2850. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2851. uint8_t lcd_show_multiscreen_message_with_choices_and_wait_P(
  2852. const char *const msg, bool allow_timeouting, uint8_t default_selection,
  2853. const char *const first_choice, const char *const second_choice, const char *const third_choice,
  2854. uint8_t second_col
  2855. ) {
  2856. const char *msg_next = msg ? lcd_display_message_fullscreen_P(msg) : NULL;
  2857. bool multi_screen = msg_next != NULL;
  2858. lcd_set_custom_characters_nextpage();
  2859. // Initial status/prompt on single-screen messages
  2860. uint8_t current_selection = default_selection;
  2861. if (!msg_next) {
  2862. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2863. }
  2864. // Wait for user confirmation or a timeout.
  2865. unsigned long previous_millis_cmd = _millis();
  2866. int8_t enc_dif = lcd_encoder_diff;
  2867. lcd_consume_click();
  2868. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2869. for (;;) {
  2870. for (uint8_t i = 0; i < 100; ++i) {
  2871. delay_keep_alive(50);
  2872. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS) {
  2873. current_selection = LCD_BUTTON_TIMEOUT;
  2874. goto exit;
  2875. }
  2876. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2877. if (msg_next == NULL) {
  2878. if (third_choice) { // third_choice is not nullptr, safe to dereference
  2879. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2880. // Rotating knob counter clockwise
  2881. current_selection--;
  2882. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_RIGHT_BUTTON_CHOICE) {
  2883. // Rotating knob clockwise
  2884. current_selection++;
  2885. }
  2886. } else {
  2887. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2888. // Rotating knob counter clockwise
  2889. current_selection = LCD_LEFT_BUTTON_CHOICE;
  2890. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_MIDDLE_BUTTON_CHOICE) {
  2891. // Rotating knob clockwise
  2892. current_selection = LCD_MIDDLE_BUTTON_CHOICE;
  2893. }
  2894. }
  2895. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2896. enc_dif = lcd_encoder_diff;
  2897. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2898. } else {
  2899. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2900. break; // turning knob skips waiting loop
  2901. }
  2902. }
  2903. if (lcd_clicked()) {
  2904. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2905. if (msg_next == NULL) {
  2906. goto exit;
  2907. } else
  2908. break;
  2909. }
  2910. }
  2911. if (multi_screen) {
  2912. if (msg_next == NULL) {
  2913. msg_next = msg;
  2914. }
  2915. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2916. }
  2917. if (msg_next == NULL) {
  2918. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2919. }
  2920. }
  2921. exit:
  2922. KEEPALIVE_STATE(IN_HANDLER);
  2923. lcd_set_custom_characters();
  2924. lcd_update_enable(true);
  2925. return current_selection;
  2926. }
  2927. //! @brief Display and wait for a Yes/No choice using the last line of the LCD
  2928. //! @param allow_timeouting if true, allows time outing of the screen
  2929. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2930. //! @retval 0 yes choice selected by user
  2931. //! @retval 1 no choice selected by user
  2932. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2933. uint8_t lcd_show_yes_no_and_wait(bool allow_timeouting, uint8_t default_selection)
  2934. {
  2935. return lcd_show_multiscreen_message_yes_no_and_wait_P(NULL, allow_timeouting, default_selection);
  2936. }
  2937. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  2938. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2939. //! @param allow_timeouting if true, allows time outing of the screen
  2940. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2941. //! @retval 0 yes choice selected by user
  2942. //! @retval 1 no choice selected by user
  2943. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2944. //! @relates lcd_show_yes_no_and_wait
  2945. uint8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection)
  2946. {
  2947. return lcd_show_multiscreen_message_yes_no_and_wait_P(msg, allow_timeouting, default_selection);
  2948. }
  2949. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2950. {
  2951. const char *msg = NULL;
  2952. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2953. lcd_show_fullscreen_message_and_wait_P(_i("XYZ calibration failed. Bed calibration point was not found."));////MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND c=20 r=6
  2954. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2955. if (point_too_far_mask == 0)
  2956. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2957. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2958. // Only the center point or all the three front points.
  2959. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  2960. else if ((point_too_far_mask & 1) == 0)
  2961. // The right and maybe the center point out of reach.
  2962. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  2963. else
  2964. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2965. msg = _n("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  2966. lcd_show_fullscreen_message_and_wait_P(msg);
  2967. } else {
  2968. if (point_too_far_mask != 0) {
  2969. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2970. // Only the center point or all the three front points.
  2971. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  2972. else if ((point_too_far_mask & 1) == 0)
  2973. // The right and maybe the center point out of reach.
  2974. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  2975. else
  2976. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2977. msg = _n("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  2978. lcd_show_fullscreen_message_and_wait_P(msg);
  2979. }
  2980. if (point_too_far_mask == 0 || result > 0) {
  2981. switch (result) {
  2982. default:
  2983. // should not happen
  2984. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2985. break;
  2986. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2987. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  2988. break;
  2989. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2990. msg = _i("XYZ calibration all right. X/Y axes are slightly skewed. Good job!");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD c=20 r=8
  2991. break;
  2992. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2993. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  2994. break;
  2995. }
  2996. lcd_show_fullscreen_message_and_wait_P(msg);
  2997. }
  2998. }
  2999. }
  3000. void lcd_temp_cal_show_result(bool result) {
  3001. custom_message_type = CustomMsg::Status;
  3002. disable_x();
  3003. disable_y();
  3004. disable_z();
  3005. disable_e0();
  3006. disable_e1();
  3007. disable_e2();
  3008. setTargetBed(0); //set bed target temperature back to 0
  3009. if (result == true) {
  3010. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3011. SERIAL_ECHOLNPGM("PINDA calibration done. Continue with pressing the knob.");
  3012. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PINDA_CALIBRATION_DONE));
  3013. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3014. }
  3015. else {
  3016. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3017. SERIAL_ECHOLNPGM("PINDA calibration failed. Continue with pressing the knob.");
  3018. lcd_show_fullscreen_message_and_wait_P(_i("PINDA calibration failed"));////MSG_PINDA_CAL_FAILED c=20 r=4
  3019. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3020. }
  3021. lcd_update_enable(true);
  3022. lcd_update(2);
  3023. }
  3024. static void lcd_show_end_stops() {
  3025. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3026. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3027. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3028. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3029. }
  3030. #ifndef TMC2130
  3031. static void menu_show_end_stops() {
  3032. lcd_show_end_stops();
  3033. if (LCD_CLICKED) menu_back();
  3034. }
  3035. #endif // not defined TMC2130
  3036. // Lets the user move the Z carriage up to the end stoppers.
  3037. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3038. // Otherwise the Z calibration is not changed and false is returned.
  3039. void lcd_diag_show_end_stops()
  3040. {
  3041. lcd_clear();
  3042. lcd_consume_click();
  3043. for (;;) {
  3044. manage_heater();
  3045. manage_inactivity(true);
  3046. lcd_show_end_stops();
  3047. if (lcd_clicked()) {
  3048. break;
  3049. }
  3050. }
  3051. lcd_clear();
  3052. lcd_return_to_status();
  3053. }
  3054. static void lcd_print_state(uint8_t state)
  3055. {
  3056. switch (state) {
  3057. case STATE_ON:
  3058. lcd_puts_P(_N(" 1"));
  3059. break;
  3060. case STATE_OFF:
  3061. lcd_puts_P(_N(" 0"));
  3062. break;
  3063. default:
  3064. lcd_puts_P(_T(MSG_NA));
  3065. break;
  3066. }
  3067. }
  3068. //! @brief Show sensor state
  3069. //!
  3070. //! @code{.unparsed}
  3071. //! |01234567890123456789|
  3072. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  3073. //! |Fil. sensor N/A| MSG_FSENSOR
  3074. //! | Int: 000 Xd:+00000|
  3075. //! |Shut: 000 Yd:+00000|
  3076. //! ----------------------
  3077. //! @endcode
  3078. static void lcd_show_sensors_state()
  3079. {
  3080. //0: N/A; 1: OFF; 2: ON
  3081. uint8_t pinda_state = STATE_NA;
  3082. uint8_t finda_state = STATE_NA;
  3083. uint8_t idler_state = STATE_NA;
  3084. pinda_state = READ(Z_MIN_PIN);
  3085. if (MMU2::mmu2.Enabled())
  3086. {
  3087. finda_state = MMU2::mmu2.FindaDetectsFilament();
  3088. }
  3089. lcd_puts_at_P(0, 0, MSG_PINDA);
  3090. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3091. lcd_print_state(pinda_state);
  3092. if (MMU2::mmu2.Enabled())
  3093. {
  3094. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3095. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3096. lcd_print_state(finda_state);
  3097. }
  3098. #ifdef FILAMENT_SENSOR
  3099. idler_state = fsensor.getFilamentPresent();
  3100. lcd_puts_at_P(0, 1, _T(MSG_FSENSOR));
  3101. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3102. lcd_print_state(idler_state);
  3103. #endif //FILAMENT_SENSOR
  3104. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3105. // Display X and Y difference from Filament sensor
  3106. // Display Light intensity from Filament sensor
  3107. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3108. // value ranges from 0(darkest) to 255(brightest).
  3109. // Display LASER shutter time from Filament sensor
  3110. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3111. // auto-exposure algorithm. When the chip is tracking on a reflective surface, the Shutter is small.
  3112. // When the chip is tracking on a surface that absorbs IR (or doesn't reflect it), the Shutter is large.
  3113. // The maximum value of the shutter is 17. The value of 16 seems to be reported as 17 even though the
  3114. // Brightness value changes correctly as if the shutter changed to 16 (probably some bug with the sensor).
  3115. // The shutter algorithm tries to keep the B value in the 70-110 range.
  3116. lcd_set_cursor(0, 2);
  3117. lcd_printf_P(_N("B: %3d Xd:%6d\n"
  3118. "S: %3d Yd:%6d"),
  3119. pat9125_b, pat9125_x,
  3120. pat9125_s, pat9125_y);
  3121. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3122. }
  3123. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3124. {
  3125. lcd_timeoutToStatus.stop();
  3126. lcd_show_sensors_state();
  3127. menu_back_if_clicked();
  3128. }
  3129. void lcd_move_menu_axis()
  3130. {
  3131. MENU_BEGIN();
  3132. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3133. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=18
  3134. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=18
  3135. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=18
  3136. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);
  3137. MENU_END();
  3138. }
  3139. #ifdef SDCARD_SORT_ALPHA
  3140. static void lcd_sort_type_set() {
  3141. uint8_t sdSort;
  3142. sdSort = eeprom_read_byte((uint8_t*) EEPROM_SD_SORT);
  3143. switch (sdSort) {
  3144. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3145. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3146. default: sdSort = SD_SORT_TIME;
  3147. }
  3148. eeprom_update_byte((uint8_t*)EEPROM_SD_SORT, sdSort);
  3149. card.presort_flag = true;
  3150. }
  3151. #endif //SDCARD_SORT_ALPHA
  3152. #ifdef TMC2130
  3153. static void lcd_crash_mode_info()
  3154. {
  3155. lcd_update_enable(true);
  3156. static uint32_t tim = 0;
  3157. if ((tim + 1000) < _millis())
  3158. {
  3159. lcd_clear();
  3160. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3161. tim = _millis();
  3162. }
  3163. menu_back_if_clicked();
  3164. }
  3165. static void lcd_crash_mode_info2()
  3166. {
  3167. lcd_update_enable(true);
  3168. static uint32_t tim = 0;
  3169. if ((tim + 1000) < _millis())
  3170. {
  3171. lcd_clear();
  3172. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3173. tim = _millis();
  3174. }
  3175. menu_back_if_clicked();
  3176. }
  3177. #endif //TMC2130
  3178. //-//
  3179. static void lcd_sound_state_set(void)
  3180. {
  3181. Sound_CycleState();
  3182. }
  3183. #ifndef MMU_FORCE_STEALTH_MODE
  3184. static void lcd_silent_mode_mmu_set() {
  3185. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3186. else SilentModeMenu_MMU = 1;
  3187. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3188. }
  3189. #endif //MMU_FORCE_STEALTH_MODE
  3190. static void lcd_silent_mode_set() {
  3191. switch (SilentModeMenu) {
  3192. #ifdef TMC2130
  3193. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3194. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3195. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3196. #else
  3197. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3198. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3199. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3200. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3201. #endif //TMC2130
  3202. }
  3203. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3204. #ifdef TMC2130
  3205. lcd_display_message_fullscreen_P(_i("Mode change in progress..."));////MSG_MODE_CHANGE_IN_PROGRESS c=20 r=3
  3206. // Wait until the planner queue is drained and the stepper routine achieves
  3207. // an idle state.
  3208. st_synchronize();
  3209. if (tmc2130_wait_standstill_xy(1000)) {}
  3210. // MYSERIAL.print("standstill OK");
  3211. // else
  3212. // MYSERIAL.print("standstill NG!");
  3213. cli();
  3214. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3215. update_mode_profile();
  3216. tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  3217. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3218. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3219. st_reset_timer();
  3220. sei();
  3221. #endif //TMC2130
  3222. st_current_init();
  3223. #ifdef TMC2130
  3224. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3225. menu_submenu(lcd_crash_mode_info2);
  3226. lcd_encoder_diff=0; // reset 'encoder buffer'
  3227. #endif //TMC2130
  3228. }
  3229. #ifdef TMC2130
  3230. static void crash_mode_switch()
  3231. {
  3232. if (lcd_crash_detect_enabled())
  3233. {
  3234. lcd_crash_detect_disable();
  3235. }
  3236. else
  3237. {
  3238. lcd_crash_detect_enable();
  3239. }
  3240. if (IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3241. else menu_goto(lcd_settings_menu, 9, true, true);
  3242. }
  3243. #endif //TMC2130
  3244. #if (LANG_MODE != 0)
  3245. void menu_setlang(unsigned char lang)
  3246. {
  3247. if (!lang_select(lang))
  3248. {
  3249. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, LCD_LEFT_BUTTON_CHOICE) == LCD_LEFT_BUTTON_CHOICE)////MSG_COPY_SEL_LANG c=20 r=3
  3250. lang_boot_update_start(lang);
  3251. lcd_update_enable(true);
  3252. lcd_clear();
  3253. menu_goto(lcd_language_menu, 0, true, true);
  3254. lcd_timeoutToStatus.stop(); //infinite timeout
  3255. lcd_draw_update = 2;
  3256. }
  3257. }
  3258. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3259. #ifdef XFLASH
  3260. static void lcd_community_language_menu()
  3261. {
  3262. MENU_BEGIN();
  3263. uint8_t cnt = lang_get_count();
  3264. MENU_ITEM_BACK_P(_T(MSG_SELECT_LANGUAGE)); //Back to previous Menu
  3265. for (int i = 8; i < cnt; i++) //all community languages
  3266. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3267. {
  3268. menu_setlang(i);
  3269. return;
  3270. }
  3271. MENU_END();
  3272. }
  3273. #endif //XFLASH
  3274. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3275. static void lcd_language_menu()
  3276. {
  3277. MENU_BEGIN();
  3278. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3279. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3280. {
  3281. menu_setlang(0);
  3282. return;
  3283. }
  3284. uint8_t cnt = lang_get_count();
  3285. #ifdef XFLASH
  3286. if (cnt == 2) //display secondary language in case of clear xflash
  3287. {
  3288. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3289. {
  3290. menu_setlang(1);
  3291. return;
  3292. }
  3293. }
  3294. else
  3295. for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
  3296. #else //XFLASH
  3297. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3298. #endif //XFLASH
  3299. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3300. {
  3301. menu_setlang(i);
  3302. return;
  3303. }
  3304. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3305. #ifdef XFLASH
  3306. MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu);
  3307. #endif //XFLASH
  3308. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3309. MENU_END();
  3310. }
  3311. #endif //(LANG_MODE != 0)
  3312. void lcd_mesh_bedleveling()
  3313. {
  3314. enquecommand_P(PSTR("G80"));
  3315. lcd_return_to_status();
  3316. }
  3317. void lcd_mesh_calibration()
  3318. {
  3319. enquecommand_P(PSTR("M45"));
  3320. lcd_return_to_status();
  3321. }
  3322. void lcd_mesh_calibration_z()
  3323. {
  3324. enquecommand_P(PSTR("M45 Z"));
  3325. lcd_return_to_status();
  3326. }
  3327. void lcd_temp_calibration_set() {
  3328. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3329. temp_cal_active = !temp_cal_active;
  3330. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3331. }
  3332. #ifdef HAS_SECOND_SERIAL_PORT
  3333. void lcd_second_serial_set() {
  3334. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3335. else selectedSerialPort = 1;
  3336. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3337. MYSERIAL.begin(BAUDRATE);
  3338. }
  3339. #endif //HAS_SECOND_SERIAL_PORT
  3340. void lcd_calibrate_pinda() {
  3341. enquecommand_P(PSTR("G76"));
  3342. lcd_return_to_status();
  3343. }
  3344. void lcd_toshiba_flash_air_compatibility_toggle()
  3345. {
  3346. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3347. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3348. }
  3349. //! @brief Continue first layer calibration with previous value or start from zero?
  3350. //!
  3351. //! @code{.unparsed}
  3352. //! |01234567890123456789|
  3353. //! |Sheet Smooth1| MSG_SHEET c=12, MSG_SHEET_NAME c=7
  3354. //! |Z offset: -1.480mm| MSG_Z_OFFSET c=11
  3355. //! |>Continue | MSG_CONTINUE
  3356. //! | Reset | MSG_RESET
  3357. //! ----------------------
  3358. //! @endcode
  3359. void lcd_first_layer_calibration_reset()
  3360. {
  3361. typedef struct
  3362. {
  3363. bool reset;
  3364. } MenuData;
  3365. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  3366. MenuData* menuData = (MenuData*)&(menu_data[0]);
  3367. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  3368. (!calibration_status_get(CALIBRATION_STATUS_LIVE_ADJUST)) ||
  3369. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  3370. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  3371. {
  3372. if (menuData->reset)
  3373. {
  3374. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  3375. }
  3376. menu_goto(lcd_v2_calibration,0,true,true);
  3377. }
  3378. if (lcd_encoder > 0)
  3379. {
  3380. menuData->reset = true;
  3381. lcd_encoder = 1;
  3382. }
  3383. else if (lcd_encoder < 1)
  3384. {
  3385. menuData->reset = false;
  3386. lcd_encoder = 0;
  3387. }
  3388. char sheet_name[sizeof(Sheet::name)];
  3389. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  3390. lcd_set_cursor(0, 0);
  3391. float offset = static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))/cs.axis_steps_per_unit[Z_AXIS];
  3392. lcd_printf_P(_i("Sheet %.7s\nZ offset: %+1.3fmm\n%cContinue\n%cReset"),////MSG_SHEET_OFFSET c=20 r=4
  3393. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');// \n denotes line break, %.7s is replaced by 7 character long sheet name, %+1.3f is replaced by 6 character long floating point number, %c is replaced by > or white space (one character) based on whether first or second option is selected. % denoted place holders can not be reordered.
  3394. }
  3395. void lcd_v2_calibration()
  3396. {
  3397. if (MMU2::mmu2.Enabled())
  3398. {
  3399. const uint8_t filament = choose_menu_P(
  3400. _T(MSG_SELECT_FILAMENT),
  3401. _T(MSG_FILAMENT),(_T(MSG_CANCEL)+1)); //Hack to reuse MSG but strip 1st char off
  3402. if (filament < 5)
  3403. {
  3404. lay1cal_filament = filament;
  3405. }
  3406. else
  3407. {
  3408. menu_back();
  3409. return;
  3410. }
  3411. }
  3412. #ifdef FILAMENT_SENSOR
  3413. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  3414. {
  3415. bool loaded = false;
  3416. if (fsensor.isReady())
  3417. {
  3418. loaded = fsensor.getFilamentPresent();
  3419. }
  3420. else
  3421. {
  3422. loaded = !lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, LCD_LEFT_BUTTON_CHOICE);
  3423. lcd_update_enabled = true;
  3424. }
  3425. if (!loaded)
  3426. {
  3427. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3428. lcd_consume_click();
  3429. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  3430. delay_keep_alive(100);
  3431. if (lcd_clicked()) {
  3432. break;
  3433. }
  3434. }
  3435. lcd_update_enabled = true;
  3436. menu_back();
  3437. return;
  3438. }
  3439. }
  3440. #endif //FILAMENT_SENSOR
  3441. eFilamentAction = FilamentAction::Lay1Cal;
  3442. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  3443. }
  3444. void lcd_wizard() {
  3445. bool result = true;
  3446. if (calibration_status_get(CALIBRATION_WIZARD_STEPS)) {
  3447. // calibration already performed: ask before clearing the previous status
  3448. result = !lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Running Wizard will delete current calibration results and start from the beginning. Continue?"), false);////MSG_WIZARD_RERUN c=20 r=7
  3449. }
  3450. if (result) {
  3451. lcd_wizard(WizState::Run);
  3452. } else {
  3453. lcd_return_to_status();
  3454. lcd_update_enable(true);
  3455. lcd_update(2);
  3456. }
  3457. }
  3458. #if (LANG_MODE != 0)
  3459. void lcd_language()
  3460. {
  3461. lcd_update_enable(true);
  3462. lcd_clear();
  3463. menu_goto(lcd_language_menu, 0, true, true);
  3464. lcd_timeoutToStatus.stop(); //infinite timeout
  3465. lcd_draw_update = 2;
  3466. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3467. {
  3468. _delay(50);
  3469. lcd_update(0);
  3470. manage_heater();
  3471. manage_inactivity(true);
  3472. }
  3473. if (lang_is_selected())
  3474. lcd_return_to_status();
  3475. else
  3476. lang_select(LANG_ID_PRI);
  3477. }
  3478. #endif
  3479. static void wait_preheat()
  3480. {
  3481. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3482. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  3483. delay_keep_alive(2000);
  3484. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3485. while (fabs(degHotend(0) - degTargetHotend(0)) > 3) {
  3486. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3487. lcd_set_cursor(0, 4);
  3488. //Print the hotend temperature (9 chars total)
  3489. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  3490. delay_keep_alive(1000);
  3491. }
  3492. }
  3493. static void lcd_wizard_load() {
  3494. if (MMU2::mmu2.Enabled()) {
  3495. lcd_show_fullscreen_message_and_wait_P(
  3496. _i("Please insert filament into the first tube of the MMU, then press the knob to load it.")); ////MSG_MMU_INSERT_FILAMENT_FIRST_TUBE c=20 r=6
  3497. // NOTE: a full screen message showing which filament is being inserted
  3498. // is performed by M701. For this reason MSG_LOADING_FILAMENT is not
  3499. // used here when a MMU is used.
  3500. } else {
  3501. lcd_show_fullscreen_message_and_wait_P(
  3502. _i("Please insert filament into the extruder, then press the knob to load it.")); ////MSG_WIZARD_LOAD_FILAMENT c=20 r=6
  3503. lcd_update_enable(false);
  3504. lcd_clear();
  3505. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3506. loading_flag = true;
  3507. }
  3508. gcode_M701(FILAMENTCHANGE_FIRSTFEED, 0);
  3509. //enquecommand_P(PSTR("M701"));
  3510. }
  3511. static void wizard_lay1cal_message(bool cold)
  3512. {
  3513. lcd_show_fullscreen_message_and_wait_P(
  3514. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  3515. if (MMU2::mmu2.Enabled())
  3516. {
  3517. lcd_show_fullscreen_message_and_wait_P(
  3518. _i("Select a filament for the First Layer Calibration and select it in the on-screen menu."));////MSG_SELECT_FIL_1ST_LAYERCAL c=20 r=7
  3519. }
  3520. else if (cold)
  3521. {
  3522. lcd_show_fullscreen_message_and_wait_P(
  3523. _i("Select temperature which matches your material."));////MSG_SELECT_TEMP_MATCHES_MATERIAL c=20 r=4
  3524. }
  3525. lcd_show_fullscreen_message_and_wait_P(
  3526. _i("The printer will start printing a zig-zag line. Rotate the knob until you reach the optimal height. Check the pictures in the handbook (Calibration chapter).")); ////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3527. }
  3528. //! @brief Printer first run wizard (Selftest and calibration)
  3529. //!
  3530. //!
  3531. //! First layer calibration with MMU state diagram
  3532. //!
  3533. //! @startuml
  3534. //! [*] --> IsFil
  3535. //! IsFil : Is any filament loaded?
  3536. //! LoadFilCold : Push the button to start loading Filament 1
  3537. //!
  3538. //! IsFil --> Lay1CalCold : yes
  3539. //! IsFil --> LoadFilCold : no
  3540. //! LoadFilCold --> Lay1CalCold : click
  3541. //! @enduml
  3542. //!
  3543. //! First layer calibration without MMU state diagram
  3544. //!
  3545. //! @startuml
  3546. //! [*] --> IsFil
  3547. //! IsFil : Is filament loaded?
  3548. //! Preheat : Select nozle temperature which matches your material.
  3549. //! LoadFilHot : Insert filament to extruder and press the knob.
  3550. //!
  3551. //! IsFil --> Lay1CalCold : yes
  3552. //! IsFil --> Preheat : no
  3553. //! Preheat --> LoadFilHot : select
  3554. //! LoadFilHot --> Lay1CalHot : click
  3555. //! @enduml
  3556. //!
  3557. //! @param state Entry point of the wizard
  3558. //!
  3559. //! state | description
  3560. //! ---------------------- | ----------------
  3561. //! WizState::Run | Main entry point
  3562. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  3563. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  3564. void lcd_wizard(WizState state)
  3565. {
  3566. using S = WizState;
  3567. bool end = false;
  3568. uint8_t wizard_event;
  3569. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  3570. // other than WizState::Run - it is useful for debugging wizard.
  3571. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3572. FORCE_BL_ON_START;
  3573. while (!end) {
  3574. printf_P(PSTR("Wizard state: %d\n"), (uint8_t)state);
  3575. switch (state) {
  3576. case S::Run: //Run wizard?
  3577. // 2019-08-07 brutal hack - solving the "viper" situation.
  3578. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  3579. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  3580. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  3581. // which results in distorted print.
  3582. // This primarily happens when the printer is new and parked in 0,0
  3583. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  3584. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  3585. // Btw. the flag may even trigger the viper situation on normal start this way and the user won't be able to find out why.
  3586. saved_printing = false;
  3587. if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){
  3588. // printer pre-assembled: finish remaining steps
  3589. lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING));
  3590. state = S::Restore;
  3591. } else {
  3592. // new printer, factory reset or manual invocation
  3593. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, LCD_LEFT_BUTTON_CHOICE);
  3594. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3595. state = S::Restore;
  3596. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3597. calibration_status_clear(CALIBRATION_WIZARD_STEPS);
  3598. } else {
  3599. // user interrupted
  3600. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3601. end = true;
  3602. }
  3603. }
  3604. break;
  3605. case S::Restore:
  3606. // clear any previous error for make _new_ errors visible
  3607. lcd_reset_alert_level();
  3608. // determine the next step in the required order
  3609. if (!calibration_status_get(CALIBRATION_STATUS_SELFTEST)) {
  3610. state = S::Selftest;
  3611. } else if (!calibration_status_get(CALIBRATION_STATUS_XYZ)) {
  3612. // S::Xyz *includes* S::Z so it needs to come before
  3613. // to avoid repeating Z alignment
  3614. state = S::Xyz;
  3615. } else if (!calibration_status_get(CALIBRATION_STATUS_Z)) {
  3616. state = S::Z;
  3617. #ifdef TEMP_MODEL
  3618. } else if (!calibration_status_get(CALIBRATION_STATUS_TEMP_MODEL)) {
  3619. state = S::TempModel;
  3620. #endif //TEMP_MODEL
  3621. } else if (!calibration_status_get(CALIBRATION_STATUS_LIVE_ADJUST)) {
  3622. state = S::IsFil;
  3623. } else {
  3624. // all required steps completed, finish successfully
  3625. state = S::Finish;
  3626. }
  3627. break;
  3628. case S::Selftest:
  3629. lcd_show_fullscreen_message_and_wait_P(_i("First, I will run the selftest to check most common assembly problems."));////MSG_WIZARD_SELFTEST c=20 r=8
  3630. wizard_event = lcd_selftest();
  3631. state = (wizard_event ? S::Restore : S::Failed);
  3632. break;
  3633. case S::Xyz:
  3634. lcd_show_fullscreen_message_and_wait_P(_i("I will run xyz calibration now. It will take up to 24 mins."));////MSG_WIZARD_XYZ_CAL c=20 r=8
  3635. wizard_event = gcode_M45(false, 0);
  3636. state = (wizard_event ? S::Restore : S::Failed);
  3637. break;
  3638. case S::Z:
  3639. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));////MSG_REMOVE_SHIPPING_HELPERS c=20 r=3
  3640. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));////MSG_REMOVE_TEST_PRINT c=20 r=4
  3641. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3642. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false);
  3643. if (wizard_event == LCD_MIDDLE_BUTTON_CHOICE) {
  3644. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3645. }
  3646. wizard_event = gcode_M45(true, 0);
  3647. if (!wizard_event) {
  3648. state = S::Failed;
  3649. } else {
  3650. raise_z_above(MIN_Z_FOR_SWAP);
  3651. //current filament needs to be unloaded and then new filament should be loaded
  3652. //start to preheat nozzle for unloading remaining PLA filament
  3653. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3654. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA.")); ////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3655. wait_preheat();
  3656. //unload current filament
  3657. unload_filament(FILAMENTCHANGE_FINALRETRACT);
  3658. //load filament
  3659. lcd_wizard_load();
  3660. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  3661. state = S::Restore;
  3662. }
  3663. break;
  3664. #ifdef TEMP_MODEL
  3665. case S::TempModel:
  3666. lcd_show_fullscreen_message_and_wait_P(_i("Temp model cal. takes approx. 12 mins."));////MSG_TM_CAL c=20 r=4
  3667. lcd_commands_type = LcdCommands::TempModel;
  3668. end = true; // Leave wizard temporarily for Temp model cal.
  3669. break;
  3670. #endif //TEMP_MODEL
  3671. case S::IsFil:
  3672. //start to preheat nozzle and bed to save some time later
  3673. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3674. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3675. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  3676. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3677. state = S::Lay1CalCold;
  3678. } else { // MIDDLE_BUTTON_CHOICE
  3679. if(MMU2::mmu2.Enabled()) state = S::LoadFilCold;
  3680. else state = S::Preheat;
  3681. }
  3682. break;
  3683. case S::Preheat:
  3684. menu_goto(lcd_preheat_menu,0,false,true);
  3685. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));////MSG_SEL_PREHEAT_TEMP c=20 r=6
  3686. end = true; // Leave wizard temporarily for lcd_preheat_menu
  3687. break;
  3688. case S::LoadFilHot:
  3689. wait_preheat();
  3690. lcd_wizard_load();
  3691. state = S::Lay1CalHot;
  3692. break;
  3693. case S::LoadFilCold:
  3694. lcd_wizard_load();
  3695. state = S::Lay1CalCold;
  3696. break;
  3697. case S::Lay1CalCold:
  3698. wizard_lay1cal_message(true);
  3699. menu_goto(lcd_v2_calibration,0,false,true);
  3700. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3701. break;
  3702. case S::Lay1CalHot:
  3703. wizard_lay1cal_message(false);
  3704. lcd_commands_type = LcdCommands::Layer1Cal;
  3705. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3706. break;
  3707. case S::RepeatLay1Cal:
  3708. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Do you want to repeat last step to readjust distance between nozzle and heatbed?"), false);////MSG_WIZARD_REPEAT_V2_CAL c=20 r=7
  3709. if (wizard_event == LCD_LEFT_BUTTON_CHOICE)
  3710. {
  3711. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3712. state = S::Lay1CalCold;
  3713. }
  3714. else
  3715. {
  3716. lcd_show_fullscreen_message_and_wait_P(_i("If you have additional steel sheets, calibrate their presets in Settings - HW Setup - Steel sheets."));////MSG_ADDITIONAL_SHEETS c=20 r=9
  3717. state = S::Restore;
  3718. }
  3719. break;
  3720. case S::Finish:
  3721. case S::Failed:
  3722. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3723. end = true;
  3724. break;
  3725. }
  3726. }
  3727. FORCE_BL_ON_END;
  3728. const char *msg = NULL;
  3729. printf_P(_N("Wizard end state: %d\n"), (uint8_t)state);
  3730. switch (state) {
  3731. case S::Run:
  3732. // user interrupted
  3733. msg = _T(MSG_WIZARD_QUIT);
  3734. break;
  3735. case S::Finish:
  3736. // we are successfully finished
  3737. msg = _T(MSG_WIZARD_DONE);
  3738. lcd_reset_alert_level();
  3739. lcd_setstatuspgm(MSG_WELCOME);
  3740. lcd_return_to_status();
  3741. break;
  3742. case S::Failed:
  3743. // aborted due to failure
  3744. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3745. break;
  3746. default:
  3747. // exiting for later re-entry
  3748. break;
  3749. }
  3750. if (msg) {
  3751. lcd_show_fullscreen_message_and_wait_P(msg);
  3752. }
  3753. lcd_update_enable(true);
  3754. lcd_update(2);
  3755. }
  3756. #ifdef TMC2130
  3757. void lcd_settings_linearity_correction_menu(void)
  3758. {
  3759. MENU_BEGIN();
  3760. ON_MENU_LEAVE(
  3761. lcd_settings_linearity_correction_menu_save();
  3762. );
  3763. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3764. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3765. //tmc2130_wave_fac[X_AXIS]
  3766. MENU_ITEM_EDIT_int3_P(_i("X-correct:"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_X_CORRECTION c=13
  3767. MENU_ITEM_EDIT_int3_P(_i("Y-correct:"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Y_CORRECTION c=13
  3768. MENU_ITEM_EDIT_int3_P(_i("Z-correct:"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Z_CORRECTION c=13
  3769. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3770. MENU_ITEM_EDIT_int3_P(_i("E-correct:"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=13
  3771. MENU_END();
  3772. }
  3773. #endif // TMC2130
  3774. #ifdef FILAMENT_SENSOR
  3775. static void fsensor_reinit() {
  3776. fsensor.init();
  3777. }
  3778. static void lcd_fsensor_enabled_set(void) {
  3779. fsensor.setEnabled(!fsensor.isEnabled());
  3780. }
  3781. static void lcd_fsensor_runout_set() {
  3782. fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true);
  3783. }
  3784. static void lcd_fsensor_autoload_set() {
  3785. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true);
  3786. }
  3787. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3788. static void lcd_fsensor_jam_detection_set() {
  3789. fsensor.setJamDetectionEnabled(!fsensor.getJamDetectionEnabled(), true);
  3790. }
  3791. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3792. static void lcd_fsensor_actionNA_set(void)
  3793. {
  3794. Filament_sensor::SensorActionOnError act = fsensor.getActionOnError();
  3795. switch(act) {
  3796. case Filament_sensor::SensorActionOnError::_Continue:
  3797. act = Filament_sensor::SensorActionOnError::_Pause;
  3798. break;
  3799. case Filament_sensor::SensorActionOnError::_Pause:
  3800. act = Filament_sensor::SensorActionOnError::_Continue;
  3801. break;
  3802. default:
  3803. act = Filament_sensor::SensorActionOnError::_Continue;
  3804. }
  3805. fsensor.setActionOnError(act, true);
  3806. }
  3807. static void lcd_fsensor_settings_menu() {
  3808. MENU_BEGIN();
  3809. MENU_ITEM_BACK_P(_T(MSG_BACK));
  3810. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), fsensor.isEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_enabled_set);
  3811. if (fsensor.isEnabled()) {
  3812. if (fsensor.isError()) {
  3813. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), _T(MSG_NA), fsensor_reinit);
  3814. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_NA), fsensor_reinit);
  3815. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3816. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), _T(MSG_NA), fsensor_reinit);
  3817. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3818. }
  3819. else {
  3820. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set);
  3821. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set);
  3822. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3823. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), fsensor.getJamDetectionEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_jam_detection_set);
  3824. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3825. }
  3826. switch(fsensor.getActionOnError()) {
  3827. case Filament_sensor::SensorActionOnError::_Continue:
  3828. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_CONTINUE_SHORT), lcd_fsensor_actionNA_set);
  3829. break;
  3830. case Filament_sensor::SensorActionOnError::_Pause:
  3831. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_PAUSE), lcd_fsensor_actionNA_set);
  3832. break;
  3833. default:
  3834. lcd_fsensor_actionNA_set();
  3835. }
  3836. }
  3837. MENU_END();
  3838. }
  3839. #endif //FILAMENT_SENSOR
  3840. static void settingsSpoolJoin()
  3841. {
  3842. MENU_ITEM_TOGGLE_P(MSG_SPOOL_JOIN, SpoolJoin::spooljoin.isSpoolJoinEnabled() ? _T(MSG_ON) : _T(MSG_OFF), SpoolJoin::spooljoin.toggleSpoolJoin);
  3843. }
  3844. #define SETTINGS_SPOOLJOIN \
  3845. do\
  3846. {\
  3847. settingsSpoolJoin();\
  3848. }\
  3849. while(0)\
  3850. #ifdef MMU_HAS_CUTTER
  3851. static void settingsCutter()
  3852. {
  3853. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3854. {
  3855. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  3856. }
  3857. #ifdef MMU_ALWAYS_CUT
  3858. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3859. {
  3860. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ALWAYS), lcd_cutter_enabled);
  3861. }
  3862. #endif
  3863. else
  3864. {
  3865. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  3866. }
  3867. }
  3868. #define SETTINGS_CUTTER \
  3869. do\
  3870. {\
  3871. settingsCutter();\
  3872. }\
  3873. while(0)
  3874. #else
  3875. #define SETTINGS_CUTTER
  3876. #endif //MMU_HAS_CUTTER
  3877. static void mmu_enable_switch()
  3878. {
  3879. uint8_t current_state = eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED);
  3880. // EEPROM update is handled by the stop and start functions.
  3881. if (current_state)
  3882. {
  3883. MMU2::mmu2.Stop();
  3884. }
  3885. else
  3886. {
  3887. MMU2::mmu2.Start();
  3888. }
  3889. }
  3890. static void mmu_reset()
  3891. {
  3892. MMU2::mmu2.Reset(MMU2::MMU2::ResetForm::Software);
  3893. }
  3894. #ifdef TMC2130
  3895. #define SETTINGS_SILENT_MODE \
  3896. do\
  3897. {\
  3898. if(!farm_mode)\
  3899. {\
  3900. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3901. {\
  3902. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  3903. }\
  3904. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  3905. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3906. {\
  3907. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  3908. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  3909. }\
  3910. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  3911. }\
  3912. }\
  3913. while (0)
  3914. #else //TMC2130
  3915. #define SETTINGS_SILENT_MODE \
  3916. do\
  3917. {\
  3918. if(!farm_mode)\
  3919. {\
  3920. switch (SilentModeMenu)\
  3921. {\
  3922. case SILENT_MODE_POWER:\
  3923. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3924. break;\
  3925. case SILENT_MODE_SILENT:\
  3926. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  3927. break;\
  3928. case SILENT_MODE_AUTO:\
  3929. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  3930. break;\
  3931. default:\
  3932. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3933. break; /* (probably) not needed*/\
  3934. }\
  3935. }\
  3936. }\
  3937. while (0)
  3938. #endif //TMC2130
  3939. #ifndef MMU_FORCE_STEALTH_MODE
  3940. #define SETTINGS_MMU_MODE \
  3941. do\
  3942. {\
  3943. if (MMU2::mmu2.Enabled())\
  3944. {\
  3945. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  3946. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  3947. }\
  3948. }\
  3949. while (0)
  3950. #else //MMU_FORCE_STEALTH_MODE
  3951. #define SETTINGS_MMU_MODE
  3952. #endif //MMU_FORCE_STEALTH_MODE
  3953. /*
  3954. #define SETTINGS_MBL_MODE \
  3955. do\
  3956. {\
  3957. switch(e_mbl_type)\
  3958. {\
  3959. case e_MBL_FAST:\
  3960. MENU_ITEM_FUNCTION_P(_n("Mode [Fast]"),mbl_mode_set);\
  3961. break; \
  3962. case e_MBL_OPTIMAL:\
  3963. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3964. break; \
  3965. case e_MBL_PREC:\
  3966. MENU_ITEM_FUNCTION_P(_n("Mode [Precise]"), mbl_mode_set); \
  3967. break; \
  3968. default:\
  3969. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3970. break; \
  3971. }\
  3972. }\
  3973. while (0)
  3974. */
  3975. #define SETTINGS_MMU_LOADING_TEST \
  3976. do\
  3977. {\
  3978. MENU_ITEM_SUBMENU_P(_T(MSG_LOADING_TEST), mmu_loading_test_menu); \
  3979. }\
  3980. while (0)
  3981. #define SETTINGS_SOUND \
  3982. do\
  3983. {\
  3984. switch(eSoundMode)\
  3985. {\
  3986. case e_SOUND_MODE_LOUD:\
  3987. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  3988. break;\
  3989. case e_SOUND_MODE_ONCE:\
  3990. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  3991. break;\
  3992. case e_SOUND_MODE_SILENT:\
  3993. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  3994. break;\
  3995. case e_SOUND_MODE_BLIND:\
  3996. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  3997. break;\
  3998. default:\
  3999. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4000. }\
  4001. }\
  4002. while (0)
  4003. //-//
  4004. static void lcd_check_mode_set(void)
  4005. {
  4006. switch(oCheckMode)
  4007. {
  4008. case ClCheckMode::_None:
  4009. oCheckMode=ClCheckMode::_Warn;
  4010. break;
  4011. case ClCheckMode::_Warn:
  4012. oCheckMode=ClCheckMode::_Strict;
  4013. break;
  4014. case ClCheckMode::_Strict:
  4015. oCheckMode=ClCheckMode::_None;
  4016. break;
  4017. default:
  4018. oCheckMode=ClCheckMode::_None;
  4019. }
  4020. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  4021. }
  4022. #define SETTINGS_MODE \
  4023. do\
  4024. {\
  4025. switch(oCheckMode)\
  4026. {\
  4027. case ClCheckMode::_None:\
  4028. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4029. break;\
  4030. case ClCheckMode::_Warn:\
  4031. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  4032. break;\
  4033. case ClCheckMode::_Strict:\
  4034. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  4035. break;\
  4036. default:\
  4037. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4038. }\
  4039. }\
  4040. while (0)
  4041. static void lcd_nozzle_diameter_cycle(void) {
  4042. uint16_t nDiameter;
  4043. switch(oNozzleDiameter){
  4044. case ClNozzleDiameter::_Diameter_250:
  4045. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4046. nDiameter=400;
  4047. break;
  4048. case ClNozzleDiameter::_Diameter_400:
  4049. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  4050. nDiameter=600;
  4051. break;
  4052. case ClNozzleDiameter::_Diameter_600:
  4053. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  4054. nDiameter=800;
  4055. break;
  4056. case ClNozzleDiameter::_Diameter_800:
  4057. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  4058. nDiameter=250;
  4059. break;
  4060. default:
  4061. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4062. nDiameter=400;
  4063. }
  4064. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  4065. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  4066. }
  4067. #define SETTINGS_NOZZLE \
  4068. do\
  4069. {\
  4070. float fNozzleDiam;\
  4071. switch(oNozzleDiameter)\
  4072. {\
  4073. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  4074. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  4075. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  4076. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  4077. default: fNozzleDiam = 0.4f; break;\
  4078. }\
  4079. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  4080. }\
  4081. while (0)
  4082. static void lcd_check_model_set(void)
  4083. {
  4084. switch(oCheckModel)
  4085. {
  4086. case ClCheckModel::_None:
  4087. oCheckModel=ClCheckModel::_Warn;
  4088. break;
  4089. case ClCheckModel::_Warn:
  4090. oCheckModel=ClCheckModel::_Strict;
  4091. break;
  4092. case ClCheckModel::_Strict:
  4093. oCheckModel=ClCheckModel::_None;
  4094. break;
  4095. default:
  4096. oCheckModel=ClCheckModel::_None;
  4097. }
  4098. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4099. }
  4100. #define SETTINGS_MODEL \
  4101. do\
  4102. {\
  4103. switch(oCheckModel)\
  4104. {\
  4105. case ClCheckModel::_None:\
  4106. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4107. break;\
  4108. case ClCheckModel::_Warn:\
  4109. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4110. break;\
  4111. case ClCheckModel::_Strict:\
  4112. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4113. break;\
  4114. default:\
  4115. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4116. }\
  4117. }\
  4118. while (0)
  4119. static void lcd_check_version_set(void)
  4120. {
  4121. switch(oCheckVersion)
  4122. {
  4123. case ClCheckVersion::_None:
  4124. oCheckVersion=ClCheckVersion::_Warn;
  4125. break;
  4126. case ClCheckVersion::_Warn:
  4127. oCheckVersion=ClCheckVersion::_Strict;
  4128. break;
  4129. case ClCheckVersion::_Strict:
  4130. oCheckVersion=ClCheckVersion::_None;
  4131. break;
  4132. default:
  4133. oCheckVersion=ClCheckVersion::_None;
  4134. }
  4135. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4136. }
  4137. #define SETTINGS_VERSION \
  4138. do\
  4139. {\
  4140. switch(oCheckVersion)\
  4141. {\
  4142. case ClCheckVersion::_None:\
  4143. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4144. break;\
  4145. case ClCheckVersion::_Warn:\
  4146. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_WARN), lcd_check_version_set);\
  4147. break;\
  4148. case ClCheckVersion::_Strict:\
  4149. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_STRICT), lcd_check_version_set);\
  4150. break;\
  4151. default:\
  4152. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4153. }\
  4154. }\
  4155. while (0)
  4156. static void lcd_checking_menu(void)
  4157. {
  4158. MENU_BEGIN();
  4159. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4160. SETTINGS_MODE;
  4161. SETTINGS_MODEL;
  4162. SETTINGS_VERSION;
  4163. MENU_END();
  4164. }
  4165. template <uint8_t number>
  4166. static void select_sheet_menu()
  4167. {
  4168. selected_sheet = number;
  4169. lcd_sheet_menu();
  4170. }
  4171. static void sheets_menu()
  4172. {
  4173. MENU_BEGIN();
  4174. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4175. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4176. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4177. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4178. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4179. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4180. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4181. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4182. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4183. MENU_END();
  4184. }
  4185. static void nozzle_change()
  4186. {
  4187. lcd_commands_type = LcdCommands::NozzleCNG;
  4188. lcd_return_to_status();
  4189. }
  4190. void lcd_hw_setup_menu(void) // can not be "static"
  4191. {
  4192. typedef struct
  4193. {// 2bytes total
  4194. int8_t status;
  4195. uint8_t experimental_menu_visibility;
  4196. } _menu_data_t;
  4197. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4198. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4199. if (_md->status == 0 || lcd_draw_update)
  4200. {
  4201. _md->status = 1;
  4202. _md->experimental_menu_visibility = eeprom_init_default_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, 0);
  4203. }
  4204. MENU_BEGIN();
  4205. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  4206. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  4207. SETTINGS_NOZZLE;
  4208. MENU_ITEM_FUNCTION_P(_T(MSG_NOZZLE_CNG_MENU),nozzle_change);
  4209. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); ////MSG_CHECKS c=18
  4210. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  4211. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  4212. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  4213. if(!MMU2::mmu2.Enabled()) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  4214. #endif //IR_SENSOR_ANALOG
  4215. if (_md->experimental_menu_visibility)
  4216. {
  4217. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  4218. }
  4219. #ifdef PINDA_TEMP_COMP
  4220. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  4221. //! This works well on the EINSY board but not on the miniRAMBo board as
  4222. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  4223. //!
  4224. //! This menu allows the user to en-/disable the SuperPINDA manualy
  4225. MENU_ITEM_TOGGLE_P(_N("SuperPINDA"), eeprom_read_byte((uint8_t *)EEPROM_PINDA_TEMP_COMPENSATION) ? _T(MSG_YES) : _T(MSG_NO), lcd_pinda_temp_compensation_toggle);
  4226. #endif //PINDA_TEMP_COMP
  4227. MENU_END();
  4228. }
  4229. static void lcd_settings_menu()
  4230. {
  4231. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  4232. MENU_BEGIN();
  4233. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4234. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=18
  4235. if (!printer_active() || isPrintPaused)
  4236. {
  4237. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
  4238. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
  4239. }
  4240. #ifdef FILAMENT_SENSOR
  4241. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  4242. #endif //FILAMENT_SENSOR
  4243. MENU_ITEM_TOGGLE_P(PSTR("MMU"), eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED) ? _T(MSG_ON) : _T(MSG_OFF), mmu_enable_switch);
  4244. if (MMU2::mmu2.Enabled())
  4245. { // Only show menus when communicating with MMU
  4246. SETTINGS_SPOOLJOIN;
  4247. SETTINGS_CUTTER;
  4248. SETTINGS_MMU_MODE;
  4249. SETTINGS_MMU_LOADING_TEST;
  4250. }
  4251. if (eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED))
  4252. { // Communication with MMU not required to reset MMU
  4253. MENU_ITEM_FUNCTION_P(PSTR("Reset MMU"), mmu_reset);
  4254. }
  4255. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  4256. SETTINGS_SILENT_MODE;
  4257. if(!farm_mode)
  4258. {
  4259. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  4260. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  4261. } else MENU_ITEM_FUNCTION_P(_T(MSG_NOZZLE_CNG_MENU),nozzle_change);
  4262. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  4263. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4264. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);////MSG_LIN_CORRECTION c=18
  4265. #endif //LINEARITY_CORRECTION && TMC2130
  4266. if(has_temperature_compensation())
  4267. {
  4268. MENU_ITEM_TOGGLE_P(_T(MSG_PINDA_CALIBRATION), eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE) ? _T(MSG_ON) : _T(MSG_OFF), lcd_temp_calibration_set);
  4269. }
  4270. #ifdef HAS_SECOND_SERIAL_PORT
  4271. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  4272. #endif //HAS_SECOND_SERIAL
  4273. if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag)
  4274. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4275. #if (LANG_MODE != 0)
  4276. MENU_ITEM_SUBMENU_P(_T(MSG_SELECT_LANGUAGE), lcd_language_menu);
  4277. #endif //(LANG_MODE != 0)
  4278. if (!farm_mode) { //SD related settings are not available in farm mode
  4279. if (card.ToshibaFlashAir_isEnabled())
  4280. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY, lcd_toshiba_flash_air_compatibility_toggle);
  4281. else
  4282. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);
  4283. #ifdef SDCARD_SORT_ALPHA
  4284. switch (eeprom_read_byte((uint8_t*) EEPROM_SD_SORT)) {
  4285. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;
  4286. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;
  4287. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);
  4288. }
  4289. }
  4290. #endif //SDCARD_SORT_ALPHA
  4291. SETTINGS_SOUND;
  4292. #ifdef LCD_BL_PIN
  4293. if (backlightSupport)
  4294. {
  4295. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  4296. }
  4297. #endif //LCD_BL_PIN
  4298. //! Enables/disables the bed heating while heating the nozzle for loading/unloading filament
  4299. MENU_ITEM_TOGGLE_P(_N("HBed on load"), eeprom_read_byte((uint8_t *)EEPROM_HEAT_BED_ON_LOAD_FILAMENT) ? _T(MSG_YES) : _T(MSG_NO), lcd_heat_bed_on_load_toggle); ////MSG_HEAT_BED_ON_LOAD c=12
  4300. if (farm_mode)
  4301. {
  4302. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4303. }
  4304. MENU_END();
  4305. }
  4306. #ifdef TMC2130
  4307. static void lcd_ustep_linearity_menu_save()
  4308. {
  4309. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4310. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4311. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4312. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4313. }
  4314. #endif //TMC2130
  4315. #ifdef TMC2130
  4316. static void lcd_settings_linearity_correction_menu_save()
  4317. {
  4318. bool changed = false;
  4319. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4320. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4321. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4322. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4323. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4324. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4325. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4326. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4327. lcd_ustep_linearity_menu_save();
  4328. if (changed) tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  4329. }
  4330. #endif //TMC2130
  4331. static void lcd_calibration_menu()
  4332. {
  4333. MENU_BEGIN();
  4334. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4335. if (!isPrintPaused)
  4336. {
  4337. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17
  4338. if (lcd_commands_type == LcdCommands::Idle)
  4339. {
  4340. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);
  4341. }
  4342. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4343. #ifdef TMC2130
  4344. MENU_ITEM_FUNCTION_P(_i("Belt test"), lcd_belttest_v);////MSG_BELTTEST c=18
  4345. #endif //TMC2130
  4346. MENU_ITEM_FUNCTION_P(_i("Selftest"), lcd_selftest_v);////MSG_SELFTEST c=18
  4347. // MK2
  4348. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  4349. // "Calibrate Z" with storing the reference values to EEPROM.
  4350. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4351. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling); ////MSG_MESH_BED_LEVELING c=18
  4352. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  4353. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  4354. #ifndef TMC2130
  4355. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  4356. #endif
  4357. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  4358. if(has_temperature_compensation())
  4359. {
  4360. MENU_ITEM_FUNCTION_P(_T(MSG_PINDA_CALIBRATION), lcd_calibrate_pinda);
  4361. }
  4362. }
  4363. #ifdef TEMP_MODEL
  4364. MENU_ITEM_SUBMENU_P(_n("Temp Model cal."), lcd_temp_model_cal);
  4365. #endif //TEMP_MODEL
  4366. MENU_END();
  4367. }
  4368. //! @brief Select one of numbered items
  4369. //!
  4370. //! Create list of items with header. Header can not be selected.
  4371. //! Each item has text description passed by function parameter and
  4372. //! number. There are 5 numbered items, if MMU2::mmu2.Enabled(), 4 otherwise.
  4373. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  4374. //! There can be last item with different text and no number.
  4375. //!
  4376. //! @param header Header text
  4377. //! @param item Item text
  4378. //! @param last_item Last item text, or nullptr if there is no Last item
  4379. //! @return selected item index, first item index is 0
  4380. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  4381. {
  4382. //following code should handle 3 to 127 number of items well
  4383. const int8_t items_no = last_item?(MMU2::mmu2.Enabled()?6:5):(MMU2::mmu2.Enabled()?5:4);
  4384. const uint8_t item_len = item?strlen_P(item):0;
  4385. int8_t first = 0;
  4386. int8_t enc_dif = lcd_encoder_diff;
  4387. int8_t cursor_pos = 1;
  4388. lcd_clear();
  4389. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4390. while (1)
  4391. {
  4392. manage_heater();
  4393. manage_inactivity(true);
  4394. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  4395. {
  4396. if (enc_dif > lcd_encoder_diff)
  4397. {
  4398. cursor_pos--;
  4399. }
  4400. if (enc_dif < lcd_encoder_diff)
  4401. {
  4402. cursor_pos++;
  4403. }
  4404. enc_dif = lcd_encoder_diff;
  4405. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4406. }
  4407. if (cursor_pos > 3)
  4408. {
  4409. cursor_pos = 3;
  4410. if (first < items_no - 3)
  4411. {
  4412. first++;
  4413. lcd_clear();
  4414. } else { // here we are at the very end of the list
  4415. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4416. }
  4417. }
  4418. if (cursor_pos < 1)
  4419. {
  4420. cursor_pos = 1;
  4421. if (first > 0)
  4422. {
  4423. first--;
  4424. lcd_clear();
  4425. } else { // here we are at the very end of the list
  4426. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4427. }
  4428. }
  4429. if (header) lcd_puts_at_P(0,0,header);
  4430. const bool last_visible = (first == items_no - 3);
  4431. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  4432. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4433. {
  4434. if (item) lcd_puts_at_P(1, i + 1, item);
  4435. }
  4436. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4437. {
  4438. lcd_set_cursor(2 + item_len, i+1);
  4439. lcd_print(first + i + 1);
  4440. }
  4441. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  4442. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  4443. lcd_putc_at(0, cursor_pos, '>');
  4444. _delay(100);
  4445. if (lcd_clicked())
  4446. {
  4447. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4448. KEEPALIVE_STATE(IN_HANDLER);
  4449. lcd_encoder_diff = 0;
  4450. return(cursor_pos + first - 1);
  4451. }
  4452. }
  4453. }
  4454. char reset_menu() {
  4455. static int8_t first = 0;
  4456. int8_t enc_dif = 0;
  4457. char cursor_pos = 0;
  4458. const char *const item[] = {
  4459. PSTR("Language"),
  4460. PSTR("Statistics"),
  4461. PSTR("Shipping prep"),
  4462. PSTR("Service prep"),
  4463. PSTR("All Data"),
  4464. };
  4465. enc_dif = lcd_encoder_diff;
  4466. lcd_clear();
  4467. lcd_set_cursor(0, 0);
  4468. lcd_putc('>');
  4469. lcd_consume_click();
  4470. while (1) {
  4471. for (uint_least8_t i = 0; i < 4; i++) {
  4472. lcd_puts_at_P(1, i, item[first + i]);
  4473. }
  4474. manage_heater();
  4475. manage_inactivity(true);
  4476. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4477. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4478. if (enc_dif > lcd_encoder_diff) {
  4479. cursor_pos--;
  4480. }
  4481. if (enc_dif < lcd_encoder_diff) {
  4482. cursor_pos++;
  4483. }
  4484. if (cursor_pos > 3) {
  4485. cursor_pos = 3;
  4486. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4487. if (first < (uint8_t)(sizeof(item) / sizeof(item[0])) - 4) {
  4488. first++;
  4489. lcd_clear();
  4490. }
  4491. }
  4492. if (cursor_pos < 0) {
  4493. cursor_pos = 0;
  4494. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4495. if (first > 0) {
  4496. first--;
  4497. lcd_clear();
  4498. }
  4499. }
  4500. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  4501. lcd_set_cursor(0, cursor_pos);
  4502. lcd_putc('>');
  4503. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4504. enc_dif = lcd_encoder_diff;
  4505. _delay(100);
  4506. }
  4507. }
  4508. if (lcd_clicked()) {
  4509. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4510. return(cursor_pos + first);
  4511. }
  4512. }
  4513. }
  4514. static void lcd_disable_farm_mode()
  4515. {
  4516. uint8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true); //allow timeouting, default no
  4517. if (disable == LCD_LEFT_BUTTON_CHOICE)
  4518. {
  4519. enquecommand_P(PSTR("G99"));
  4520. lcd_return_to_status();
  4521. }
  4522. lcd_update_enable(true);
  4523. lcd_draw_update = 2;
  4524. }
  4525. static inline void load_all_wrapper(){
  4526. for(uint8_t i = 0; i < 5; ++i){
  4527. MMU2::mmu2.load_filament(i);
  4528. }
  4529. }
  4530. static inline void load_filament_wrapper(uint8_t i){
  4531. MMU2::mmu2.load_filament(i);
  4532. }
  4533. static void mmu_load_filament_menu() {
  4534. MENU_BEGIN();
  4535. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4536. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), load_all_wrapper);
  4537. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4538. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', load_filament_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4539. MENU_END();
  4540. }
  4541. static inline void lcd_mmu_load_to_nozzle_wrapper(uint8_t index){
  4542. MMU2::mmu2.load_filament_to_nozzle(index);
  4543. // Ask user if the extruded color is correct:
  4544. lcd_return_to_status();
  4545. lcd_load_filament_color_check();
  4546. lcd_setstatuspgm(MSG_WELCOME);
  4547. custom_message_type = CustomMsg::Status;
  4548. }
  4549. static void mmu_load_to_nozzle_menu() {
  4550. if (bFilamentAction) {
  4551. MENU_BEGIN();
  4552. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4553. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4554. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', lcd_mmu_load_to_nozzle_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4555. MENU_END();
  4556. } else {
  4557. eFilamentAction = FilamentAction::MmuLoad;
  4558. preheat_or_continue();
  4559. }
  4560. }
  4561. static void mmu_eject_filament(uint8_t filament) {
  4562. menu_back();
  4563. MMU2::mmu2.eject_filament(filament, true);
  4564. }
  4565. static void mmu_fil_eject_menu() {
  4566. if (bFilamentAction) {
  4567. MENU_BEGIN();
  4568. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4569. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4570. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), i + '1', mmu_eject_filament, i); ////MSG_EJECT_FILAMENT c=16
  4571. MENU_END();
  4572. } else {
  4573. eFilamentAction = FilamentAction::MmuEject;
  4574. preheat_or_continue();
  4575. }
  4576. }
  4577. #ifdef MMU_HAS_CUTTER
  4578. static inline void mmu_cut_filament_wrapper(uint8_t index){
  4579. MMU2::mmu2.cut_filament(index);
  4580. }
  4581. static void mmu_cut_filament_menu() {
  4582. if (bFilamentAction) {
  4583. MENU_BEGIN();
  4584. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4585. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4586. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), i + '1', mmu_cut_filament_wrapper, i); ////MSG_CUT_FILAMENT c=16
  4587. MENU_END();
  4588. } else {
  4589. eFilamentAction=FilamentAction::MmuCut;
  4590. preheat_or_continue();
  4591. }
  4592. }
  4593. #endif //MMU_HAS_CUTTER
  4594. static inline void loading_test_all_wrapper(){
  4595. for(uint8_t i = 0; i < 5; ++i){
  4596. MMU2::mmu2.loading_test(i);
  4597. }
  4598. }
  4599. static inline void loading_test_wrapper(uint8_t i){
  4600. MMU2::mmu2.loading_test(i);
  4601. }
  4602. static void mmu_loading_test_menu() {
  4603. if (bFilamentAction) {
  4604. MENU_BEGIN();
  4605. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4606. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), loading_test_all_wrapper);
  4607. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4608. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', loading_test_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4609. MENU_END();
  4610. } else {
  4611. eFilamentAction = FilamentAction::MmuLoadingTest;
  4612. preheat_or_continue();
  4613. }
  4614. }
  4615. /// @brief unload filament for single material printer (used in M600 and M702)
  4616. /// @param unloadLength Retract distance for removal (manual reload)
  4617. void unload_filament(float unloadLength)
  4618. {
  4619. custom_message_type = CustomMsg::FilamentLoading;
  4620. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4621. FSensorBlockRunout fsBlockRunout;
  4622. // Retract filament
  4623. current_position[E_AXIS] += -FILAMENT_UNLOAD_PURGE_RETRACT;
  4624. plan_buffer_line_curposXYZE(PAUSE_PARK_RETRACT_FEEDRATE);
  4625. st_synchronize();
  4626. // Wait for filament to cool
  4627. delay_keep_alive(FILAMENT_UNLOAD_PURGE_DELAY);
  4628. // Quickly purge
  4629. current_position[E_AXIS] += (FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH);
  4630. plan_buffer_line_curposXYZE(FILAMENT_UNLOAD_PURGE_FEEDRATE);
  4631. st_synchronize();
  4632. // Configurable length
  4633. current_position[E_AXIS] += unloadLength;
  4634. plan_buffer_line_curposXYZE(FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  4635. st_synchronize();
  4636. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4637. //disable extruder steppers so filament can be removed
  4638. disable_e0();
  4639. disable_e1();
  4640. disable_e2();
  4641. _delay(100);
  4642. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  4643. uint8_t counterBeep = 0;
  4644. while (!lcd_clicked() && (counterBeep < 50)) {
  4645. delay_keep_alive(100);
  4646. counterBeep++;
  4647. }
  4648. st_synchronize();
  4649. while (lcd_clicked()) delay_keep_alive(100);
  4650. lcd_update_enable(true);
  4651. lcd_setstatuspgm(MSG_WELCOME);
  4652. custom_message_type = CustomMsg::Status;
  4653. eFilamentAction = FilamentAction::None;
  4654. }
  4655. #include "xflash.h"
  4656. #ifdef LCD_TEST
  4657. static void lcd_test_menu()
  4658. {
  4659. XFLASH_SPI_ENTER();
  4660. xflash_enable_wr();
  4661. xflash_chip_erase();
  4662. xflash_disable_wr();
  4663. }
  4664. #endif //LCD_TEST
  4665. static bool fan_error_selftest()
  4666. {
  4667. #ifdef FANCHECK
  4668. if (!fans_check_enabled) return 0;
  4669. fanSpeed = 255;
  4670. #ifdef FAN_SOFT_PWM
  4671. fanSpeedSoftPwm = 255;
  4672. #endif //FAN_SOFT_PWM
  4673. manage_heater(); //enables print fan
  4674. setExtruderAutoFanState(3); //force enables the hotend fan
  4675. #ifdef FAN_SOFT_PWM
  4676. extruder_autofan_last_check = _millis();
  4677. fan_measuring = true;
  4678. #endif //FAN_SOFT_PWM
  4679. _delay(1000); //delay_keep_alive would turn off hotend fan, because temerature is too low (maybe)
  4680. manage_heater();
  4681. fanSpeed = 0;
  4682. setExtruderAutoFanState(1); //releases lock on the hotend fan
  4683. #ifdef FAN_SOFT_PWM
  4684. fanSpeedSoftPwm = 0;
  4685. #endif //FAN_SOFT_PWM
  4686. manage_heater();
  4687. #ifdef TACH_0
  4688. if (fan_speed[0] <= 20) { //hotend fan error
  4689. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_HOTEND);
  4690. return 1;
  4691. }
  4692. #endif
  4693. #ifdef TACH_1
  4694. if (fan_speed[1] <= 20) { //print fan error
  4695. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  4696. return 1;
  4697. }
  4698. #endif
  4699. #endif //FANCHECK
  4700. return 0;
  4701. }
  4702. bool resume_print_checks() {
  4703. // reset the lcd status so that a newer error will be shown
  4704. lcd_return_to_status();
  4705. lcd_reset_alert_level();
  4706. // ensure thermal issues (temp or fan) are resolved before we allow to resume
  4707. if (get_temp_error()
  4708. #ifdef FANCHECK
  4709. || fan_error_selftest()
  4710. #endif
  4711. ) {
  4712. return false; // abort if error persists
  4713. }
  4714. return true;
  4715. }
  4716. //! @brief Resume paused print, send host action "resumed"
  4717. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  4718. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  4719. void lcd_resume_print()
  4720. {
  4721. // reset lcd and ensure we can resume first
  4722. if (!resume_print_checks()) return;
  4723. cmdqueue_serial_disabled = false;
  4724. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4725. st_synchronize();
  4726. custom_message_type = CustomMsg::Resuming;
  4727. isPrintPaused = false;
  4728. Stopped = false; // resume processing USB commands again
  4729. restore_print_from_ram_and_continue(default_retraction);
  4730. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  4731. refresh_cmd_timeout();
  4732. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  4733. custom_message_type = CustomMsg::Status;
  4734. }
  4735. //! @brief Resume paused USB/host print, send host action "resume"
  4736. void lcd_resume_usb_print()
  4737. {
  4738. // reset lcd and ensure we can resume first
  4739. if (!resume_print_checks()) return;
  4740. // resume the usb host
  4741. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_RESUME);
  4742. }
  4743. static void change_sheet()
  4744. {
  4745. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4746. menu_back(3);
  4747. }
  4748. static void lcd_rename_sheet_menu()
  4749. {
  4750. struct MenuData
  4751. {
  4752. bool initialized;
  4753. uint8_t selected;
  4754. char name[sizeof(Sheet::name)];
  4755. };
  4756. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  4757. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4758. if (!menuData->initialized)
  4759. {
  4760. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  4761. lcd_encoder = menuData->name[0];
  4762. menuData->initialized = true;
  4763. }
  4764. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  4765. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  4766. menuData->name[menuData->selected] = lcd_encoder;
  4767. lcd_set_cursor(0,0);
  4768. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  4769. {
  4770. lcd_putc(menuData->name[i]);
  4771. }
  4772. lcd_set_cursor(menuData->selected, 1);
  4773. lcd_putc('^');
  4774. if (lcd_clicked())
  4775. {
  4776. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  4777. {
  4778. lcd_encoder = menuData->name[++(menuData->selected)];
  4779. }
  4780. else
  4781. {
  4782. eeprom_update_block(menuData->name,
  4783. EEPROM_Sheets_base->s[selected_sheet].name,
  4784. sizeof(Sheet::name));
  4785. menu_back();
  4786. }
  4787. }
  4788. }
  4789. static void lcd_reset_sheet()
  4790. {
  4791. SheetName sheetName;
  4792. eeprom_default_sheet_name(selected_sheet, sheetName);
  4793. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  4794. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  4795. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  4796. {
  4797. eeprom_switch_to_next_sheet();
  4798. if (-1 == eeprom_next_initialized_sheet(0))
  4799. calibration_status_clear(CALIBRATION_STATUS_LIVE_ADJUST);
  4800. }
  4801. menu_back();
  4802. }
  4803. //! @brief Activate selected_sheet and run first layer calibration
  4804. static void activate_calibrate_sheet()
  4805. {
  4806. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4807. lcd_first_layer_calibration_reset();
  4808. }
  4809. static void lcd_sheet_menu()
  4810. {
  4811. MENU_BEGIN();
  4812. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  4813. if(eeprom_is_sheet_initialized(selected_sheet)){
  4814. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  4815. }
  4816. if (lcd_commands_type == LcdCommands::Idle)
  4817. {
  4818. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);
  4819. }
  4820. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  4821. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet);
  4822. MENU_END();
  4823. }
  4824. //! @brief Show Main Menu
  4825. //!
  4826. //! @code{.unparsed}
  4827. //! |01234567890123456789|
  4828. //! | Info screen | allways
  4829. //!
  4830. //! | tst - Save | ifdef RESUME_DEBUG
  4831. //! | tst - Restore | ifdef RESUME_DEBUG
  4832. //!
  4833. //! | recover print | ifdef TMC2130_DEBUG
  4834. //! | power panic | ifdef TMC2130_DEBUG
  4835. //!
  4836. //! | Live adjust Z | printing + Z low
  4837. //!
  4838. //! | Change filament | farm mode
  4839. //!
  4840. //! | Tune | printing + paused
  4841. //! | Pause print | printing + not paused
  4842. //! | Resume print | printing + paused
  4843. //! | Stop print | printing or paused + NOT MBL
  4844. //! | Preheat | not printing + not paused
  4845. //! | Print from SD | not printing or paused
  4846. //!
  4847. //! | Switch sheet | farm mode
  4848. //!
  4849. //! | AutoLoad filament | not printing + not mmu or paused
  4850. //! | Load filament | not printing + mmu or paused
  4851. //! | Load to nozzle | not printing + mmu or paused
  4852. //! | Unload filament | not printing or paused
  4853. //! | Eject filament | not printing + mmu or paused
  4854. //! | Cut filament | not printing + mmu or paused + cut atctive
  4855. //! | Settings | not printing or paused
  4856. //! | Calibration | not printing
  4857. //! | Statistics | not printing
  4858. //! | Fail stats | allways
  4859. //! | Fail stats MMU | mmu
  4860. //! | Support | allways
  4861. //! @endcode
  4862. static void lcd_main_menu()
  4863. {
  4864. MENU_BEGIN();
  4865. // Majkl superawesome menu
  4866. MENU_ITEM_BACK_P(_T(MSG_INFO_SCREEN));
  4867. #ifdef RESUME_DEBUG
  4868. if (!saved_printing)
  4869. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4870. else
  4871. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4872. #endif //RESUME_DEBUG
  4873. #ifdef TMC2130_DEBUG
  4874. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4875. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4876. #endif //TMC2130_DEBUG
  4877. if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
  4878. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4879. }
  4880. if (farm_mode)
  4881. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  4882. if ( moves_planned() || printer_active() ) {
  4883. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  4884. } else if (!Stopped) {
  4885. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  4886. }
  4887. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  4888. if (usb_timer.running()) {
  4889. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);
  4890. } else if (IS_SD_PRINTING) {
  4891. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);
  4892. }
  4893. }
  4894. if(isPrintPaused)
  4895. {
  4896. // only allow resuming if hardware errors (temperature or fan) are cleared
  4897. if(!get_temp_error()
  4898. #ifdef FANCHECK
  4899. && ((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  4900. #endif //FANCHECK
  4901. ) {
  4902. if (saved_printing) {
  4903. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);
  4904. } else {
  4905. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);
  4906. }
  4907. }
  4908. }
  4909. if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  4910. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4911. }
  4912. #ifdef TEMP_MODEL
  4913. else if(Stopped) {
  4914. MENU_ITEM_SUBMENU_P(_T(MSG_TM_ACK_ERROR), lcd_print_stop);
  4915. }
  4916. #endif
  4917. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  4918. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  4919. if (!card.isFileOpen()) {
  4920. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4921. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  4922. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4923. }
  4924. #if SDCARDDETECT < 1
  4925. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user ////MSG_CNG_SDCARD c=18
  4926. #endif //SDCARDDETECT
  4927. }
  4928. } else {
  4929. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  4930. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu); ////MSG_NO_CARD c=18
  4931. #if SDCARDDETECT < 1
  4932. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface ////MSG_INIT_SDCARD c=18
  4933. #endif //SDCARDDETECT
  4934. }
  4935. #endif //SDSUPPORT
  4936. if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4937. if (!farm_mode) {
  4938. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  4939. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  4940. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  4941. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  4942. }
  4943. }
  4944. }
  4945. if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal || Stopped) ) ) {
  4946. if (MMU2::mmu2.Enabled()) {
  4947. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), mmu_load_filament_menu);
  4948. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  4949. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  4950. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  4951. #ifdef MMU_HAS_CUTTER
  4952. if (eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) != 0) {
  4953. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  4954. }
  4955. #endif //MMU_HAS_CUTTER
  4956. } else {
  4957. #ifdef FILAMENT_SENSOR
  4958. if (fsensor.getAutoLoadEnabled()) {
  4959. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  4960. }
  4961. else
  4962. #endif //FILAMENT_SENSOR
  4963. {
  4964. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4965. }
  4966. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4967. }
  4968. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4969. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu);
  4970. }
  4971. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4972. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  4973. }
  4974. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  4975. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  4976. #endif
  4977. if (MMU2::mmu2.Enabled()) {
  4978. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  4979. }
  4980. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  4981. #ifdef LCD_TEST
  4982. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_XFLASH c=18
  4983. #endif //LCD_TEST
  4984. MENU_END();
  4985. }
  4986. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4987. bool stepper_timer_overflow_state = false;
  4988. uint16_t stepper_timer_overflow_max = 0;
  4989. uint16_t stepper_timer_overflow_last = 0;
  4990. uint16_t stepper_timer_overflow_cnt = 0;
  4991. void stepper_timer_overflow() {
  4992. char msg[28];
  4993. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4994. lcd_setstatus(msg);
  4995. stepper_timer_overflow_state = false;
  4996. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4997. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4998. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4999. MYSERIAL.print(msg);
  5000. SERIAL_ECHOLNPGM("");
  5001. WRITE(BEEPER, LOW);
  5002. }
  5003. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5004. static void lcd_colorprint_change() {
  5005. enquecommand_P(PSTR("M600"));
  5006. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  5007. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5008. lcd_return_to_status();
  5009. lcd_draw_update = 3;
  5010. }
  5011. #ifdef LA_LIVE_K
  5012. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  5013. // redefine our custom handling functions to mimick other tunables
  5014. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  5015. static void lcd_advance_draw_K(char chr, float val)
  5016. {
  5017. if (val <= 0)
  5018. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  5019. else
  5020. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  5021. }
  5022. static void lcd_advance_edit_K(void)
  5023. {
  5024. if (lcd_draw_update)
  5025. {
  5026. if (lcd_encoder < 0) lcd_encoder = 0;
  5027. if (lcd_encoder > 999) lcd_encoder = 999;
  5028. lcd_set_cursor(0, 1);
  5029. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  5030. }
  5031. if (LCD_CLICKED)
  5032. {
  5033. extruder_advance_K = 0.01 * lcd_encoder;
  5034. menu_back_no_reset();
  5035. }
  5036. }
  5037. static uint8_t lcd_advance_K()
  5038. {
  5039. if (menu_item == menu_line)
  5040. {
  5041. if (lcd_draw_update)
  5042. {
  5043. lcd_set_cursor(0, menu_row);
  5044. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5045. }
  5046. if (menu_clicked && (lcd_encoder == menu_item))
  5047. {
  5048. menu_submenu_no_reset(lcd_advance_edit_K);
  5049. lcd_encoder = 100. * extruder_advance_K;
  5050. return menu_item_ret();
  5051. }
  5052. }
  5053. menu_item++;
  5054. return 0;
  5055. }
  5056. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5057. #endif
  5058. static void lcd_tune_menu()
  5059. {
  5060. typedef struct
  5061. {
  5062. menu_data_edit_t reserved; //!< reserved for number editing functions
  5063. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5064. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5065. //! it needs to be applied.
  5066. int16_t extrudemultiply;
  5067. } _menu_data_t;
  5068. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5069. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5070. if (_md->status == 0)
  5071. {
  5072. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5073. _md->status = 1;
  5074. _md->extrudemultiply = extrudemultiply;
  5075. }
  5076. else if (_md->extrudemultiply != extrudemultiply)
  5077. {
  5078. // extrudemultiply has been changed from the child menu. Apply the new value.
  5079. _md->extrudemultiply = extrudemultiply;
  5080. calculate_extruder_multipliers();
  5081. }
  5082. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  5083. MENU_BEGIN();
  5084. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5085. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  5086. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5087. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);
  5088. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5089. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  5090. #ifdef LA_LIVE_K
  5091. MENU_ITEM_EDIT_advance_K();//7
  5092. #endif
  5093. #ifdef FILAMENTCHANGEENABLE
  5094. if (!farm_mode)
  5095. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5096. #endif
  5097. #ifdef FILAMENT_SENSOR
  5098. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  5099. #endif //FILAMENT_SENSOR
  5100. if (MMU2::mmu2.Enabled())
  5101. {
  5102. SETTINGS_SPOOLJOIN;
  5103. SETTINGS_CUTTER;
  5104. }
  5105. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  5106. #ifdef TMC2130
  5107. if(!farm_mode)
  5108. {
  5109. if (SilentModeMenu == SILENT_MODE_NORMAL) {
  5110. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  5111. if (lcd_crash_detect_enabled()) {
  5112. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  5113. } else {
  5114. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  5115. }
  5116. } else {
  5117. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  5118. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  5119. }
  5120. }
  5121. #else //TMC2130
  5122. if (!farm_mode) { //dont show in menu if we are in farm mode
  5123. switch (SilentModeMenu) {
  5124. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  5125. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  5126. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  5127. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  5128. }
  5129. }
  5130. #endif //TMC2130
  5131. SETTINGS_MMU_MODE;
  5132. SETTINGS_SOUND;
  5133. #ifdef LCD_BL_PIN
  5134. if (backlightSupport)
  5135. {
  5136. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  5137. }
  5138. #endif //LCD_BL_PIN
  5139. MENU_END();
  5140. }
  5141. static void mbl_magnets_elimination_toggle() {
  5142. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5143. magnet_elimination = !magnet_elimination;
  5144. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  5145. }
  5146. static void mbl_mesh_toggle() {
  5147. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5148. if(mesh_nr == 3) mesh_nr = 7;
  5149. else mesh_nr = 3;
  5150. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  5151. }
  5152. static void mbl_probe_nr_toggle() {
  5153. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  5154. switch (mbl_z_probe_nr) {
  5155. case 1: mbl_z_probe_nr = 3; break;
  5156. case 3: mbl_z_probe_nr = 5; break;
  5157. case 5: mbl_z_probe_nr = 1; break;
  5158. default: mbl_z_probe_nr = 3; break;
  5159. }
  5160. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  5161. }
  5162. static void lcd_mesh_bed_leveling_settings()
  5163. {
  5164. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5165. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5166. char sToggle[4]; //enough for nxn format
  5167. MENU_BEGIN();
  5168. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5169. sToggle[0] = points_nr + '0';
  5170. sToggle[1] = 'x';
  5171. sToggle[2] = points_nr + '0';
  5172. sToggle[3] = 0;
  5173. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  5174. sToggle[0] = mbl_z_probe_nr + '0';
  5175. sToggle[1] = 0;
  5176. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  5177. MENU_ITEM_TOGGLE_P(_T(MSG_MAGNETS_COMP), (points_nr == 7) ? (magnet_elimination ? _T(MSG_ON): _T(MSG_OFF)) : _T(MSG_NA), mbl_magnets_elimination_toggle);
  5178. MENU_END();
  5179. //SETTINGS_MBL_MODE;
  5180. }
  5181. #ifdef LCD_BL_PIN
  5182. static void backlight_mode_toggle()
  5183. {
  5184. switch (backlightMode)
  5185. {
  5186. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  5187. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  5188. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5189. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5190. }
  5191. backlight_save();
  5192. }
  5193. static void lcd_backlight_menu()
  5194. {
  5195. MENU_BEGIN();
  5196. ON_MENU_LEAVE(
  5197. backlight_save();
  5198. );
  5199. MENU_ITEM_BACK_P(_T(MSG_BACK));
  5200. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  5201. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  5202. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), ((backlightMode==BACKLIGHT_MODE_BRIGHT) ? _T(MSG_BRIGHT) : ((backlightMode==BACKLIGHT_MODE_DIM) ? _T(MSG_DIM) : _T(MSG_AUTO))), backlight_mode_toggle);
  5203. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  5204. MENU_END();
  5205. }
  5206. #endif //LCD_BL_PIN
  5207. static void lcd_control_temperature_menu()
  5208. {
  5209. #ifdef PIDTEMP
  5210. // set up temp variables - undo the default scaling
  5211. // raw_Ki = unscalePID_i(Ki);
  5212. // raw_Kd = unscalePID_d(Kd);
  5213. #endif
  5214. MENU_BEGIN();
  5215. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5216. #if TEMP_SENSOR_0 != 0
  5217. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5218. #endif
  5219. #if TEMP_SENSOR_1 != 0
  5220. MENU_ITEM_EDIT_int3_P(_n("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  5221. #endif
  5222. #if TEMP_SENSOR_2 != 0
  5223. MENU_ITEM_EDIT_int3_P(_n("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  5224. #endif
  5225. #if TEMP_SENSOR_BED != 0
  5226. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5227. #endif
  5228. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5229. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5230. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5231. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5232. MENU_ITEM_EDIT(float3, _n(" \xdf Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  5233. MENU_ITEM_EDIT(float3, _n(" \xdf Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  5234. MENU_ITEM_EDIT(float32, _n(" \xdf Fact"), &autotemp_factor, 0.0, 1.0);
  5235. #endif
  5236. MENU_END();
  5237. }
  5238. static void lcd_sd_refresh()
  5239. {
  5240. #if SDCARDDETECT == -1
  5241. card.initsd();
  5242. #else
  5243. card.presort();
  5244. #endif
  5245. menu_top = 0;
  5246. lcd_encoder = 0;
  5247. menu_data_reset(); //Forces reloading of cached variables.
  5248. }
  5249. static void lcd_sd_updir()
  5250. {
  5251. card.updir();
  5252. menu_top = 0;
  5253. lcd_encoder = 0;
  5254. menu_data_reset(); //Forces reloading of cached variables.
  5255. }
  5256. // continue stopping the print from the main loop after lcd_print_stop() is called
  5257. void lcd_print_stop_finish()
  5258. {
  5259. // save printing time
  5260. stoptime = _millis();
  5261. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5262. save_statistics(total_filament_used, t);
  5263. // lift Z
  5264. raise_z(10);
  5265. // if axis are homed, move to parking position.
  5266. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
  5267. current_position[X_AXIS] = X_CANCEL_POS;
  5268. current_position[Y_AXIS] = Y_CANCEL_POS;
  5269. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5270. }
  5271. st_synchronize();
  5272. // did we come here from a thermal error?
  5273. if(get_temp_error()) {
  5274. // time to stop the error beep
  5275. WRITE(BEEPER, LOW);
  5276. } else {
  5277. // Turn off the print fan
  5278. fanSpeed = 0;
  5279. }
  5280. if (MMU2::mmu2.Enabled() && MMU2::mmu2.FindaDetectsFilament())
  5281. {
  5282. if (isPrintPaused)
  5283. {
  5284. // Restore temperature saved in ram after pausing print
  5285. restore_extruder_temperature_from_ram();
  5286. }
  5287. MMU2::mmu2.unload(); // M702
  5288. }
  5289. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  5290. finishAndDisableSteppers(); //M84
  5291. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  5292. }
  5293. void print_stop(bool interactive)
  5294. {
  5295. // UnconditionalStop() will internally cause planner_abort_hard(), meaning we _cannot_ plan any
  5296. // more move in this call! Any further move must happen inside lcd_print_stop_finish(), which is
  5297. // called by the main loop one iteration later.
  5298. UnconditionalStop();
  5299. if (!card.sdprinting) {
  5300. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  5301. }
  5302. #ifdef MESH_BED_LEVELING
  5303. mbl.active = false;
  5304. #endif
  5305. // clear any pending paused state immediately
  5306. pause_time = 0;
  5307. isPrintPaused = false;
  5308. if (interactive) {
  5309. // acknowledged by the user from the LCD: resume processing USB commands again
  5310. Stopped = false;
  5311. }
  5312. // return to status is required to continue processing in the main loop!
  5313. lcd_commands_type = LcdCommands::StopPrint;
  5314. lcd_return_to_status();
  5315. }
  5316. void lcd_print_stop()
  5317. {
  5318. print_stop(true);
  5319. }
  5320. #ifdef TEMP_MODEL
  5321. void lcd_temp_model_cal()
  5322. {
  5323. lcd_commands_type = LcdCommands::TempModel;
  5324. lcd_return_to_status();
  5325. }
  5326. #endif //TEMP_MODEL
  5327. void lcd_sdcard_stop()
  5328. {
  5329. // Show static message
  5330. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  5331. lcd_putc_at(0, 1, '\n');
  5332. MENU_BEGIN();
  5333. // Skip first two LCD rows used by static message
  5334. if(menu_row == 0) menu_row = 2;
  5335. // Show No options first, the default selection
  5336. MENU_ITEM_FUNCTION_P(_T(MSG_NO), lcd_return_to_status);
  5337. MENU_ITEM_FUNCTION_P(_T(MSG_YES), lcd_print_stop);
  5338. MENU_END();
  5339. }
  5340. void lcd_sdcard_menu()
  5341. {
  5342. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  5343. typedef struct
  5344. {
  5345. menuState_t menuState = _uninitialized;
  5346. uint8_t offset;
  5347. bool isDir;
  5348. const char* scrollPointer;
  5349. uint16_t selectedFileID;
  5350. uint16_t fileCnt;
  5351. int8_t row;
  5352. uint8_t sdSort;
  5353. ShortTimer lcd_scrollTimer;
  5354. } _menu_data_sdcard_t;
  5355. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  5356. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  5357. switch(_md->menuState)
  5358. {
  5359. case _uninitialized: //Initialize menu data
  5360. {
  5361. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  5362. {
  5363. card.presort_flag = false;
  5364. lcd_update_enabled = false;
  5365. card.presort();
  5366. lcd_update_enabled = true;
  5367. }
  5368. _md->fileCnt = card.getnrfilenames();
  5369. _md->sdSort = farm_mode ? SD_SORT_NONE : eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5370. _md->menuState = _standard;
  5371. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5372. }
  5373. // FALLTHRU
  5374. case _standard: //normal menu structure.
  5375. {
  5376. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  5377. {
  5378. _md->lcd_scrollTimer.start();
  5379. lcd_draw_update = 1;
  5380. }
  5381. if ((lcd_draw_update == 0) && _md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  5382. {
  5383. _md->menuState = _scrolling;
  5384. _md->offset = 0;
  5385. _md->scrollPointer = NULL;
  5386. _md->lcd_scrollTimer.start();
  5387. lcd_draw_update = 1; //forces last load before switching to scrolling.
  5388. }
  5389. if (lcd_draw_update == 0 && !LCD_CLICKED)
  5390. return; // nothing to do (so don't thrash the SD card)
  5391. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5392. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  5393. _md->lcd_scrollTimer.start();
  5394. MENU_BEGIN();
  5395. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  5396. card.getWorkDirName();
  5397. if (card.filename[0] == '/')
  5398. {
  5399. #if SDCARDDETECT == -1
  5400. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5401. #else
  5402. if (card.ToshibaFlashAir_isEnabled())
  5403. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  5404. #endif
  5405. }
  5406. else
  5407. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  5408. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  5409. {
  5410. if (menu_item == menu_line) //If the file is on the screen.
  5411. {
  5412. //load filename to memory.
  5413. #ifdef SDCARD_SORT_ALPHA
  5414. card.getfilename_sorted(i, _md->sdSort);
  5415. #else
  5416. card.getfilename(i);
  5417. #endif
  5418. if (lcd_encoder == menu_item) //If the file is selected.
  5419. {
  5420. _md->selectedFileID = i;
  5421. _md->isDir = card.filenameIsDir;
  5422. _md->row = menu_row;
  5423. }
  5424. if (card.filenameIsDir)
  5425. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  5426. else
  5427. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  5428. }
  5429. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  5430. }
  5431. MENU_END();
  5432. } break;
  5433. case _scrolling: //scrolling filename
  5434. {
  5435. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  5436. if (_md->scrollPointer == NULL)
  5437. {
  5438. //load filename to memory.
  5439. #ifdef SDCARD_SORT_ALPHA
  5440. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  5441. #else
  5442. card.getfilename(_md->selectedFileID);
  5443. #endif
  5444. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  5445. }
  5446. if (rewindFlag == 1)
  5447. _md->offset = 0; //redraw once again from the beginning.
  5448. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  5449. {
  5450. uint8_t len = LCD_WIDTH - ((_md->isDir)? 2 : 1);
  5451. lcd_set_cursor(0, _md->row);
  5452. lcd_print('>');
  5453. if (_md->isDir)
  5454. lcd_print(LCD_STR_FOLDER[0]);
  5455. if( lcd_print_pad(&_md->scrollPointer[_md->offset], len) )
  5456. {
  5457. _md->lcd_scrollTimer.start();
  5458. _md->offset++;
  5459. } else {
  5460. // stop at the end of the string
  5461. _md->lcd_scrollTimer.stop();
  5462. }
  5463. }
  5464. if (rewindFlag) //go back to sd_menu.
  5465. {
  5466. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  5467. _md->menuState = _standard;
  5468. }
  5469. } break;
  5470. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  5471. }
  5472. }
  5473. #ifdef TMC2130
  5474. static void lcd_belttest_v()
  5475. {
  5476. lcd_belttest();
  5477. menu_back_if_clicked();
  5478. }
  5479. void lcd_belttest()
  5480. {
  5481. lcd_clear();
  5482. // Belttest requires high power mode. Enable it.
  5483. FORCE_HIGH_POWER_START;
  5484. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5485. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5486. lcd_printf_P(_T(MSG_CHECKING_X));
  5487. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  5488. KEEPALIVE_STATE(IN_HANDLER);
  5489. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  5490. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  5491. if (lcd_selfcheck_axis_sg(X_AXIS)){
  5492. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5493. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  5494. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  5495. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  5496. if (lcd_selfcheck_axis_sg(Y_AXIS))
  5497. {
  5498. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5499. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  5500. lcd_set_cursor(19, 3);
  5501. lcd_print(LCD_STR_UPLEVEL[0]);
  5502. lcd_wait_for_click_delay(10);
  5503. }
  5504. }
  5505. FORCE_HIGH_POWER_END;
  5506. KEEPALIVE_STATE(NOT_BUSY);
  5507. }
  5508. #endif //TMC2130
  5509. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5510. // called also from marlin_main.cpp
  5511. void printf_IRSensorAnalogBoardChange(){
  5512. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), fsensor.getIRVersionText());
  5513. }
  5514. static bool lcd_selftest_IRsensor(bool bStandalone)
  5515. {
  5516. FSensorBlockRunout fsBlockRunout;
  5517. IR_sensor_analog::SensorRevision oldSensorRevision = fsensor.getSensorRevision();
  5518. IR_sensor_analog::SensorRevision newSensorRevision;
  5519. uint16_t volt_IR_int = fsensor.getVoltRaw();
  5520. newSensorRevision = (volt_IR_int < fsensor.IRsensor_Hopen_TRESHOLD) ? IR_sensor_analog::SensorRevision::_Rev04 : IR_sensor_analog::SensorRevision::_Old;
  5521. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  5522. if(volt_IR_int < fsensor.IRsensor_Hmin_TRESHOLD){
  5523. if(!bStandalone)
  5524. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  5525. return false;
  5526. }
  5527. lcd_show_fullscreen_message_and_wait_P(_i("Insert the filament (do not load it) into the extruder and then press the knob."));////MSG_INSERT_FIL c=20 r=6
  5528. volt_IR_int = fsensor.getVoltRaw();
  5529. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  5530. if(volt_IR_int > (fsensor.IRsensor_Lmax_TRESHOLD)){
  5531. if(!bStandalone)
  5532. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  5533. return false;
  5534. }
  5535. if(newSensorRevision != oldSensorRevision) {
  5536. fsensor.setSensorRevision(newSensorRevision, true);
  5537. printf_IRSensorAnalogBoardChange();
  5538. }
  5539. return true;
  5540. }
  5541. static void lcd_detect_IRsensor(){
  5542. bool bAction;
  5543. bool loaded;
  5544. /// Check if filament is loaded. If it is loaded stop detection.
  5545. /// @todo Add autodetection with MMU2s
  5546. loaded = fsensor.getFilamentPresent();
  5547. if(loaded){
  5548. lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action."));////MSG_UNLOAD_FILAMENT_REPEAT c=20 r=4
  5549. return;
  5550. } else {
  5551. lcd_show_fullscreen_message_and_wait_P(_i("Please check the IR sensor connection, unload filament if present."));////MSG_CHECK_IR_CONNECTION c=20 r=4
  5552. bAction = lcd_selftest_IRsensor(true);
  5553. }
  5554. if(bAction){
  5555. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  5556. fsensor.init();
  5557. } else {
  5558. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  5559. }
  5560. }
  5561. #endif //IR_SENSOR_ANALOG
  5562. static void lcd_selftest_v()
  5563. {
  5564. (void)lcd_selftest();
  5565. }
  5566. bool lcd_selftest()
  5567. {
  5568. uint8_t _progress = 0;
  5569. bool _result = true;
  5570. bool _swapped_fan = false;
  5571. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5572. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  5573. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  5574. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  5575. if(fsensor.getSensorRevision() == IR_sensor_analog::SensorRevision::_Undef) {
  5576. if (!MMU2::mmu2.Enabled()) {
  5577. lcd_detect_IRsensor();
  5578. }
  5579. else {
  5580. fsensor.setSensorRevision(IR_sensor_analog::SensorRevision::_Old, true);
  5581. }
  5582. }
  5583. #endif
  5584. lcd_wait_for_cool_down();
  5585. lcd_clear();
  5586. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  5587. #ifdef TMC2130
  5588. FORCE_HIGH_POWER_START;
  5589. #endif // TMC2130
  5590. FORCE_BL_ON_START;
  5591. _delay(2000);
  5592. KEEPALIVE_STATE(IN_HANDLER);
  5593. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  5594. #if (defined(FANCHECK) && defined(TACH_0))
  5595. switch (lcd_selftest_fan_auto(0)){ // check hotend fan
  5596. case FanCheck::SwappedFan:
  5597. _swapped_fan = true; // swapped is merely a hint (checked later)
  5598. // FALLTHRU
  5599. case FanCheck::Success:
  5600. _result = true;
  5601. break;
  5602. default:
  5603. _result = false;
  5604. break;
  5605. }
  5606. #else //defined(TACH_0)
  5607. _result = lcd_selftest_manual_fan_check(0, false);
  5608. #endif //defined(TACH_0)
  5609. if (!_result)
  5610. {
  5611. lcd_selftest_error(TestError::ExtruderFan, "", "");
  5612. }
  5613. if (_result)
  5614. {
  5615. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  5616. #if (defined(FANCHECK) && defined(TACH_1))
  5617. switch (lcd_selftest_fan_auto(1)){ // check print fan
  5618. case FanCheck::SwappedFan:
  5619. _swapped_fan = true; // swapped is merely a hint (checked later)
  5620. // FALLTHRU
  5621. case FanCheck::Success:
  5622. _result = true;
  5623. break;
  5624. default:
  5625. _result = false;
  5626. break;
  5627. }
  5628. #else //defined(TACH_1)
  5629. _result = lcd_selftest_manual_fan_check(1, false);
  5630. #endif //defined(TACH_1)
  5631. if (!_result)
  5632. {
  5633. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  5634. }
  5635. }
  5636. if (_swapped_fan) {
  5637. //turn on print fan and check that left hotend fan is not spinning
  5638. _result = lcd_selftest_manual_fan_check(1, true);
  5639. if (_result) {
  5640. //print fan is stil turned on; check that it is spinning
  5641. _result = lcd_selftest_manual_fan_check(1, false, true);
  5642. if (!_result){
  5643. lcd_selftest_error(TestError::PrintFan, "", "");
  5644. }
  5645. }
  5646. else {
  5647. // fans are swapped
  5648. lcd_selftest_error(TestError::SwappedFan, "", "");
  5649. }
  5650. }
  5651. if (_result)
  5652. {
  5653. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  5654. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  5655. }
  5656. if (_result)
  5657. {
  5658. //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  5659. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  5660. #ifdef TMC2130
  5661. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5662. #else
  5663. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5664. #endif //TMC2130
  5665. }
  5666. if (_result)
  5667. {
  5668. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  5669. #ifndef TMC2130
  5670. _result = lcd_selfcheck_pulleys(X_AXIS);
  5671. #endif
  5672. }
  5673. if (_result)
  5674. {
  5675. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  5676. #ifdef TMC2130
  5677. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5678. #else
  5679. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5680. #endif // TMC2130
  5681. }
  5682. if (_result)
  5683. {
  5684. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  5685. #ifndef TMC2130
  5686. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5687. #endif // TMC2130
  5688. }
  5689. if (_result)
  5690. {
  5691. #ifdef TMC2130
  5692. tmc2130_home_exit();
  5693. enable_endstops(false);
  5694. #endif
  5695. //homeaxis(X_AXIS);
  5696. //homeaxis(Y_AXIS);
  5697. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  5698. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  5699. #ifdef TMC2130
  5700. //current_position[X_AXIS] += 0;
  5701. current_position[Y_AXIS] += 4;
  5702. #endif //TMC2130
  5703. raise_z(10);
  5704. set_destination_to_current();
  5705. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  5706. #ifdef TMC2130
  5707. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  5708. #else
  5709. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  5710. #endif //TMC2130
  5711. //raise Z to not damage the bed during and hotend testing
  5712. raise_z(20);
  5713. }
  5714. #ifdef TMC2130
  5715. if (_result)
  5716. {
  5717. raise_z(10);
  5718. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  5719. bool bres = tmc2130_home_calibrate(X_AXIS);
  5720. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  5721. bres &= tmc2130_home_calibrate(Y_AXIS);
  5722. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  5723. if (bres)
  5724. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5725. _result = bres;
  5726. }
  5727. #endif //TMC2130
  5728. if (_result)
  5729. {
  5730. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  5731. _result = lcd_selfcheck_check_heater(true);
  5732. }
  5733. if (_result)
  5734. {
  5735. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  5736. _result = lcd_selfcheck_check_heater(false);
  5737. }
  5738. if (_result)
  5739. {
  5740. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  5741. }
  5742. #ifdef FILAMENT_SENSOR
  5743. if (_result)
  5744. {
  5745. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5746. if (MMU2::mmu2.Enabled())
  5747. {
  5748. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5749. _result = selftest_irsensor();
  5750. if (_result)
  5751. {
  5752. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5753. }
  5754. } else
  5755. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5756. {
  5757. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5758. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5759. _result = lcd_selftest_fsensor();
  5760. if (_result)
  5761. {
  5762. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5763. }
  5764. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5765. #if 0
  5766. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  5767. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  5768. //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5769. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  5770. _result = lcd_selftest_IRsensor();
  5771. if (_result)
  5772. {
  5773. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  5774. }
  5775. #endif //IR_SENSOR_ANALOG
  5776. }
  5777. }
  5778. #endif //FILAMENT_SENSOR
  5779. if (_result)
  5780. {
  5781. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  5782. }
  5783. else
  5784. {
  5785. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  5786. }
  5787. lcd_reset_alert_level();
  5788. enquecommand_P(PSTR("M84"));
  5789. lcd_update_enable(true);
  5790. if (_result)
  5791. {
  5792. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  5793. calibration_status_set(CALIBRATION_STATUS_SELFTEST);
  5794. }
  5795. else
  5796. {
  5797. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5798. }
  5799. #ifdef TMC2130
  5800. FORCE_HIGH_POWER_END;
  5801. #endif // TMC2130
  5802. FORCE_BL_ON_END;
  5803. KEEPALIVE_STATE(NOT_BUSY);
  5804. return(_result);
  5805. }
  5806. #ifdef TMC2130
  5807. static void reset_crash_det(uint8_t axis) {
  5808. current_position[axis] += 10;
  5809. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5810. st_synchronize();
  5811. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5812. }
  5813. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  5814. // each axis length is measured twice
  5815. float axis_length, current_position_init, current_position_final;
  5816. float measured_axis_length[2];
  5817. float margin = 60;
  5818. float max_error_mm = 5;
  5819. switch (axis) {
  5820. case 0: axis_length = X_MAX_POS; break;
  5821. case 1: axis_length = Y_MAX_POS + 8; break;
  5822. default: axis_length = 210; break;
  5823. }
  5824. tmc2130_sg_stop_on_crash = false;
  5825. tmc2130_home_exit();
  5826. enable_endstops(true);
  5827. raise_z_above(MESH_HOME_Z_SEARCH);
  5828. tmc2130_home_enter(1 << axis);
  5829. // first axis length measurement begin
  5830. current_position[axis] -= (axis_length + margin);
  5831. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5832. st_synchronize();
  5833. tmc2130_sg_measure_start(axis);
  5834. current_position_init = st_get_position_mm(axis);
  5835. current_position[axis] += 2 * margin;
  5836. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5837. st_synchronize();
  5838. current_position[axis] += axis_length;
  5839. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5840. st_synchronize();
  5841. uint16_t sg1 = tmc2130_sg_measure_stop();
  5842. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5843. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5844. current_position_final = st_get_position_mm(axis);
  5845. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  5846. // first measurement end and second measurement begin
  5847. current_position[axis] -= margin;
  5848. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5849. st_synchronize();
  5850. current_position[axis] -= (axis_length + margin);
  5851. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5852. st_synchronize();
  5853. current_position_init = st_get_position_mm(axis);
  5854. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  5855. tmc2130_home_exit();
  5856. //end of second measurement, now check for possible errors:
  5857. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5858. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5859. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5860. enable_endstops(false);
  5861. const char *_error_1;
  5862. if (axis == X_AXIS) _error_1 = "X";
  5863. if (axis == Y_AXIS) _error_1 = "Y";
  5864. if (axis == Z_AXIS) _error_1 = "Z";
  5865. lcd_selftest_error(TestError::Axis, _error_1, "");
  5866. current_position[axis] = 0;
  5867. plan_set_position_curposXYZE();
  5868. reset_crash_det(axis);
  5869. enable_endstops(true);
  5870. endstops_hit_on_purpose();
  5871. return false;
  5872. }
  5873. }
  5874. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  5875. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5876. //loose pulleys
  5877. const char *_error_1;
  5878. if (axis == X_AXIS) _error_1 = "X";
  5879. if (axis == Y_AXIS) _error_1 = "Y";
  5880. if (axis == Z_AXIS) _error_1 = "Z";
  5881. lcd_selftest_error(TestError::Pulley, _error_1, "");
  5882. current_position[axis] = 0;
  5883. plan_set_position_curposXYZE();
  5884. reset_crash_det(axis);
  5885. endstops_hit_on_purpose();
  5886. return false;
  5887. }
  5888. current_position[axis] = 0;
  5889. plan_set_position_curposXYZE();
  5890. reset_crash_det(axis);
  5891. endstops_hit_on_purpose();
  5892. return true;
  5893. }
  5894. #endif //TMC2130
  5895. #ifndef TMC2130
  5896. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5897. {
  5898. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5899. bool _stepdone = false;
  5900. bool _stepresult = false;
  5901. uint8_t _progress = 0;
  5902. int _travel_done = 0;
  5903. int _err_endstop = 0;
  5904. int _lcd_refresh = 0;
  5905. _travel = _travel + (_travel / 10);
  5906. if (_axis == X_AXIS) {
  5907. current_position[Z_AXIS] += 17;
  5908. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5909. }
  5910. do {
  5911. current_position[_axis] = current_position[_axis] - 1;
  5912. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5913. st_synchronize();
  5914. #ifdef TMC2130
  5915. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5916. #else //TMC2130
  5917. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5918. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5919. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5920. #endif //TMC2130
  5921. {
  5922. if (_axis == 0)
  5923. {
  5924. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5925. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5926. }
  5927. if (_axis == 1)
  5928. {
  5929. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5930. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5931. }
  5932. if (_axis == 2)
  5933. {
  5934. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5935. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5936. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5937. /*disable_x();
  5938. disable_y();
  5939. disable_z();*/
  5940. }
  5941. _stepdone = true;
  5942. }
  5943. if (_lcd_refresh < 6)
  5944. {
  5945. _lcd_refresh++;
  5946. }
  5947. else
  5948. {
  5949. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  5950. _lcd_refresh = 0;
  5951. }
  5952. manage_heater();
  5953. manage_inactivity(true);
  5954. //_delay(100);
  5955. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5956. } while (!_stepdone);
  5957. //current_position[_axis] = current_position[_axis] + 15;
  5958. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  5959. if (!_stepresult)
  5960. {
  5961. const char *_error_1;
  5962. const char *_error_2;
  5963. if (_axis == X_AXIS) _error_1 = "X";
  5964. if (_axis == Y_AXIS) _error_1 = "Y";
  5965. if (_axis == Z_AXIS) _error_1 = "Z";
  5966. if (_err_endstop == 0) _error_2 = "X";
  5967. if (_err_endstop == 1) _error_2 = "Y";
  5968. if (_err_endstop == 2) _error_2 = "Z";
  5969. if (_travel_done >= _travel)
  5970. {
  5971. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  5972. }
  5973. else
  5974. {
  5975. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  5976. }
  5977. }
  5978. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  5979. plan_set_position_curposXYZE();
  5980. return _stepresult;
  5981. }
  5982. static bool lcd_selfcheck_pulleys(int axis)
  5983. {
  5984. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5985. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5986. float current_position_init;
  5987. float move;
  5988. bool endstop_triggered = false;
  5989. int i;
  5990. unsigned long timeout_counter;
  5991. refresh_cmd_timeout();
  5992. manage_inactivity(true);
  5993. if (axis == 0) move = 50; //X_AXIS
  5994. else move = 50; //Y_AXIS
  5995. current_position_init = current_position[axis];
  5996. current_position[axis] += 2;
  5997. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5998. for (i = 0; i < 5; i++) {
  5999. refresh_cmd_timeout();
  6000. current_position[axis] = current_position[axis] + move;
  6001. st_current_set(0, 850); //set motor current higher
  6002. plan_buffer_line_curposXYZE(200);
  6003. st_synchronize();
  6004. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  6005. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  6006. current_position[axis] = current_position[axis] - move;
  6007. plan_buffer_line_curposXYZE(50);
  6008. st_synchronize();
  6009. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6010. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6011. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6012. return(false);
  6013. }
  6014. }
  6015. timeout_counter = _millis() + 2500;
  6016. endstop_triggered = false;
  6017. manage_inactivity(true);
  6018. while (!endstop_triggered) {
  6019. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6020. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6021. endstop_triggered = true;
  6022. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  6023. current_position[axis] += 10;
  6024. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6025. st_synchronize();
  6026. return(true);
  6027. }
  6028. else {
  6029. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6030. return(false);
  6031. }
  6032. }
  6033. else {
  6034. current_position[axis] -= 1;
  6035. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6036. st_synchronize();
  6037. if (_millis() > timeout_counter) {
  6038. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6039. return(false);
  6040. }
  6041. }
  6042. }
  6043. return(true);
  6044. }
  6045. #endif //not defined TMC2130
  6046. static bool lcd_selfcheck_endstops()
  6047. {
  6048. bool _result = true;
  6049. if (
  6050. #ifndef TMC2130
  6051. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6052. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6053. #endif //!TMC2130
  6054. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6055. {
  6056. #ifndef TMC2130
  6057. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6058. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6059. #endif //!TMC2130
  6060. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  6061. }
  6062. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6063. st_synchronize();
  6064. if (
  6065. #ifndef TMC2130
  6066. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6067. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6068. #endif //!TMC2130
  6069. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6070. {
  6071. _result = false;
  6072. char _error[4] = "";
  6073. #ifndef TMC2130
  6074. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  6075. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  6076. #endif //!TMC2130
  6077. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  6078. lcd_selftest_error(TestError::Endstops, _error, "");
  6079. }
  6080. manage_heater();
  6081. manage_inactivity(true);
  6082. return _result;
  6083. }
  6084. static bool lcd_selfcheck_check_heater(bool _isbed)
  6085. {
  6086. uint8_t _progress = 0;
  6087. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  6088. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  6089. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  6090. target_temperature[0] = (_isbed) ? 0 : 200;
  6091. target_temperature_bed = (_isbed) ? 100 : 0;
  6092. manage_heater();
  6093. manage_inactivity(true);
  6094. for(uint8_t _counter = 0; _counter < _cycles && !Stopped; ++_counter)
  6095. {
  6096. manage_heater();
  6097. manage_inactivity(true);
  6098. _progress = (_isbed?
  6099. lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) :
  6100. lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400));
  6101. /*if (_isbed) {
  6102. MYSERIAL.print("Bed temp:");
  6103. MYSERIAL.println(degBed());
  6104. }
  6105. else {
  6106. MYSERIAL.print("Hotend temp:");
  6107. MYSERIAL.println(degHotend(0));
  6108. }*/
  6109. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  6110. }
  6111. target_temperature[0] = 0;
  6112. target_temperature_bed = 0;
  6113. manage_heater();
  6114. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  6115. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  6116. /*
  6117. MYSERIAL.println("");
  6118. MYSERIAL.print("Checked result:");
  6119. MYSERIAL.println(_checked_result);
  6120. MYSERIAL.print("Opposite result:");
  6121. MYSERIAL.println(_opposite_result);
  6122. */
  6123. bool _stepresult = false;
  6124. if (Stopped)
  6125. {
  6126. // thermal error occurred while heating the nozzle
  6127. lcd_selftest_error(TestError::Heater, "", "");
  6128. }
  6129. else
  6130. {
  6131. if (_opposite_result < ((_isbed) ? 30 : 9))
  6132. {
  6133. if (_checked_result >= ((_isbed) ? 9 : 30))
  6134. _stepresult = true;
  6135. else
  6136. lcd_selftest_error(TestError::Heater, "", "");
  6137. }
  6138. else
  6139. {
  6140. lcd_selftest_error(TestError::Bed, "", "");
  6141. }
  6142. }
  6143. manage_heater();
  6144. manage_inactivity(true);
  6145. return _stepresult;
  6146. }
  6147. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  6148. {
  6149. lcd_beeper_quick_feedback();
  6150. FORCE_BL_ON_END;
  6151. target_temperature[0] = 0;
  6152. target_temperature_bed = 0;
  6153. manage_heater();
  6154. manage_inactivity();
  6155. lcd_clear();
  6156. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  6157. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  6158. switch (testError)
  6159. {
  6160. case TestError::Heater:
  6161. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  6162. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  6163. break;
  6164. case TestError::Bed:
  6165. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  6166. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6167. break;
  6168. case TestError::Endstops:
  6169. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  6170. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6171. lcd_set_cursor(18, 3);
  6172. lcd_print(_error_1);
  6173. break;
  6174. case TestError::Motor:
  6175. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  6176. lcd_set_cursor(18, 2);
  6177. lcd_print(_error_1);
  6178. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  6179. lcd_set_cursor(18, 3);
  6180. lcd_print(_error_2);
  6181. break;
  6182. case TestError::Endstop:
  6183. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  6184. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6185. lcd_set_cursor(18, 3);
  6186. lcd_print(_error_1);
  6187. break;
  6188. case TestError::PrintFan:
  6189. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_PART_FAN));
  6190. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6191. lcd_set_cursor(18, 3);
  6192. lcd_print(_error_1);
  6193. break;
  6194. case TestError::ExtruderFan:
  6195. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_HOTEND_FAN));
  6196. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6197. lcd_set_cursor(18, 3);
  6198. lcd_print(_error_1);
  6199. break;
  6200. case TestError::Pulley:
  6201. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  6202. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6203. lcd_set_cursor(18, 3);
  6204. lcd_print(_error_1);
  6205. break;
  6206. case TestError::Axis:
  6207. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  6208. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  6209. lcd_set_cursor(18, 3);
  6210. lcd_print(_error_1);
  6211. break;
  6212. case TestError::SwappedFan:
  6213. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  6214. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  6215. lcd_set_cursor(18, 3);
  6216. lcd_print(_error_1);
  6217. break;
  6218. case TestError::WiringFsensor:
  6219. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6220. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6221. break;
  6222. case TestError::TriggeringFsensor:
  6223. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6224. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  6225. break;
  6226. case TestError::FsensorLevel:
  6227. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6228. lcd_set_cursor(0, 3);
  6229. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  6230. break;
  6231. }
  6232. _delay(1000);
  6233. lcd_beeper_quick_feedback();
  6234. do {
  6235. _delay(100);
  6236. manage_heater();
  6237. manage_inactivity();
  6238. } while (!lcd_clicked());
  6239. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6240. lcd_return_to_status();
  6241. }
  6242. #ifdef FILAMENT_SENSOR
  6243. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6244. static bool lcd_selftest_fsensor(void)
  6245. {
  6246. fsensor.init();
  6247. if (fsensor.isError())
  6248. {
  6249. lcd_selftest_error(TestError::WiringFsensor, "", "");
  6250. }
  6251. return (!fsensor.isError());
  6252. }
  6253. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6254. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6255. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  6256. //!
  6257. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  6258. //!
  6259. //! Steps:
  6260. //! * Backup current active extruder temperature
  6261. //! * Pre-heat to PLA extrude temperature.
  6262. //! * Unload filament possibly present.
  6263. //! * Move extruder idler same way as during filament load
  6264. //! and sample the filament sensor.
  6265. //! * Check that pin doesn't go low.
  6266. //!
  6267. //! @retval true passed
  6268. //! @retval false failed
  6269. static bool selftest_irsensor()
  6270. {
  6271. class TempBackup
  6272. {
  6273. public:
  6274. TempBackup():
  6275. m_temp(degTargetHotend(active_extruder)),
  6276. m_extruder(active_extruder){}
  6277. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  6278. private:
  6279. float m_temp;
  6280. uint8_t m_extruder;
  6281. };
  6282. uint8_t progress;
  6283. {
  6284. TempBackup tempBackup;
  6285. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  6286. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  6287. }
  6288. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6289. MMU2::mmu2.unload();
  6290. for(uint_least8_t i = 0; i < 200; ++i)
  6291. {
  6292. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6293. //@@TODO mmu_load_step(false);
  6294. while (blocks_queued())
  6295. {
  6296. if (fsensor.getFilamentPresent())
  6297. {
  6298. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  6299. return false;
  6300. }
  6301. #ifdef TMC2130
  6302. manage_heater();
  6303. // Vojtech: Don't disable motors inside the planner!
  6304. if (!tmc2130_update_sg())
  6305. {
  6306. manage_inactivity(true);
  6307. }
  6308. #else //TMC2130
  6309. manage_heater();
  6310. // Vojtech: Don't disable motors inside the planner!
  6311. manage_inactivity(true);
  6312. #endif //TMC2130
  6313. }
  6314. }
  6315. return true;
  6316. }
  6317. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6318. #endif //FILAMENT_SENSOR
  6319. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  6320. bool _default)
  6321. {
  6322. bool _result = check_opposite;
  6323. lcd_clear();
  6324. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  6325. switch (_fan)
  6326. {
  6327. case 0:
  6328. // extruder cooling fan
  6329. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_PART_FAN) : _T(MSG_SELFTEST_HOTEND_FAN));
  6330. setExtruderAutoFanState(3);
  6331. break;
  6332. case 1:
  6333. // object cooling fan
  6334. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_HOTEND_FAN) : _T(MSG_SELFTEST_PART_FAN));
  6335. SET_OUTPUT(FAN_PIN);
  6336. #ifdef FAN_SOFT_PWM
  6337. fanSpeedSoftPwm = 255;
  6338. #else //FAN_SOFT_PWM
  6339. analogWrite(FAN_PIN, 255);
  6340. #endif //FAN_SOFT_PWM
  6341. break;
  6342. }
  6343. _delay(500);
  6344. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6345. lcd_putc_at(0, 3, '>');
  6346. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6347. int8_t enc_dif = int(_default)*3;
  6348. KEEPALIVE_STATE(PAUSED_FOR_USER);
  6349. lcd_button_pressed = false;
  6350. do
  6351. {
  6352. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  6353. if (enc_dif > lcd_encoder_diff) {
  6354. _result = !check_opposite;
  6355. lcd_putc_at(0, 2, '>');
  6356. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6357. lcd_putc_at(0, 3, ' ');
  6358. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6359. }
  6360. if (enc_dif < lcd_encoder_diff) {
  6361. _result = check_opposite;
  6362. lcd_putc_at(0, 2, ' ');
  6363. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6364. lcd_putc_at(0, 3, '>');
  6365. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6366. }
  6367. enc_dif = 0;
  6368. lcd_encoder_diff = 0;
  6369. }
  6370. manage_heater();
  6371. _delay(100);
  6372. } while (!lcd_clicked());
  6373. KEEPALIVE_STATE(IN_HANDLER);
  6374. setExtruderAutoFanState(0);
  6375. SET_OUTPUT(FAN_PIN);
  6376. #ifdef FAN_SOFT_PWM
  6377. fanSpeedSoftPwm = 0;
  6378. #else //FAN_SOFT_PWM
  6379. analogWrite(FAN_PIN, 0);
  6380. #endif //FAN_SOFT_PWM
  6381. fanSpeed = 0;
  6382. manage_heater();
  6383. return _result;
  6384. }
  6385. #ifdef FANCHECK
  6386. // Set print fan speed
  6387. static void lcd_selftest_setfan(uint8_t speed) {
  6388. // set the fan speed
  6389. fanSpeed = speed;
  6390. #ifdef FAN_SOFT_PWM
  6391. fanSpeedSoftPwm = speed;
  6392. #endif
  6393. manage_heater();
  6394. }
  6395. // Wait for the specified number of seconds while displaying some single-character indicator on the
  6396. // screen coordinate col/row, then perform fan measurement
  6397. static void lcd_selftest_measure_fans(uint8_t delay, uint8_t col, uint8_t row) {
  6398. // spin-up delay
  6399. static char symbols[] = {'-', '|'};
  6400. static_assert(1000 / sizeof(symbols) * sizeof(symbols) == 1000);
  6401. while(delay--) {
  6402. for(uint8_t i = 0; i != sizeof(symbols); ++i) {
  6403. lcd_putc_at(col, row, symbols[i]);
  6404. delay_keep_alive(1000 / sizeof(symbols));
  6405. }
  6406. }
  6407. #ifdef FANCHECK
  6408. extruder_autofan_last_check = _millis();
  6409. #endif
  6410. fan_measuring = true;
  6411. while(fan_measuring) {
  6412. delay_keep_alive(100);
  6413. }
  6414. gcode_M123();
  6415. }
  6416. static FanCheck lcd_selftest_fan_auto(uint8_t _fan)
  6417. {
  6418. // speed threshold to differentiate between extruder and print fan
  6419. static const int printFanThr = FANCHECK_AUTO_PRINT_FAN_THRS; // >= FANCHECK_AUTO_PRINT_FAN_THRS RPS
  6420. // speed threshold to mark a fan as failed
  6421. static const int failThr = FANCHECK_AUTO_FAIL_THRS; // < FANCHECK_AUTO_FAIL_THRS RPM would mean either a faulty Noctua, Altfan or print fan
  6422. switch (_fan) {
  6423. case 0:
  6424. setExtruderAutoFanState(3); // hotend fan
  6425. lcd_selftest_setfan(0); // print fan off
  6426. lcd_selftest_measure_fans(2, 18, 2);
  6427. setExtruderAutoFanState(0); // hotend fan off
  6428. if (fan_speed[0] < failThr) {
  6429. return FanCheck::ExtruderFan;
  6430. }
  6431. if (fan_speed[0] >= printFanThr ) {
  6432. return FanCheck::SwappedFan;
  6433. }
  6434. break;
  6435. case 1:
  6436. lcd_selftest_setfan(255);
  6437. lcd_selftest_measure_fans(5, 18, 3);
  6438. lcd_selftest_setfan(0);
  6439. if (fan_speed[1] < failThr) {
  6440. return FanCheck::PrintFan;
  6441. }
  6442. if (fan_speed[1] < printFanThr) {
  6443. return FanCheck::SwappedFan;
  6444. }
  6445. }
  6446. return FanCheck::Success;
  6447. }
  6448. #endif //FANCHECK
  6449. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  6450. {
  6451. lcd_update_enable(false);
  6452. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  6453. if (_clear) lcd_clear();
  6454. lcd_set_cursor(0, 0);
  6455. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6456. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6457. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6458. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  6459. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  6460. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  6461. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  6462. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6463. if (screen == TestScreen::Hotend
  6464. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  6465. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6466. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6467. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  6468. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  6469. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  6470. lcd_puts_at_P(0, 1, separator);
  6471. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  6472. {
  6473. //SERIAL_ECHOLNPGM("Fan test");
  6474. lcd_puts_at_P(0, 2, _T(MSG_HOTEND_FAN_SPEED));
  6475. lcd_set_cursor(18, 2);
  6476. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  6477. lcd_puts_at_P(0, 3, _T(MSG_PRINT_FAN_SPEED));
  6478. lcd_set_cursor(18, 3);
  6479. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  6480. }
  6481. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  6482. {
  6483. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6484. lcd_putc(':');
  6485. lcd_set_cursor(18, 2);
  6486. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  6487. }
  6488. else if (screen < TestScreen::Fsensor)
  6489. {
  6490. //SERIAL_ECHOLNPGM("Other tests");
  6491. TestScreen _step_block = TestScreen::AxisX;
  6492. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  6493. _step_block = TestScreen::AxisY;
  6494. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  6495. _step_block = TestScreen::AxisZ;
  6496. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  6497. _step_block = TestScreen::Bed;
  6498. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  6499. _step_block = TestScreen::Hotend;
  6500. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  6501. }
  6502. if (_delay > 0) delay_keep_alive(_delay);
  6503. _progress++;
  6504. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  6505. }
  6506. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  6507. {
  6508. lcd_set_cursor(_col, _row);
  6509. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  6510. switch (_state)
  6511. {
  6512. case 1:
  6513. lcd_puts_P(_name_PROGMEM);
  6514. lcd_putc_at(_col + strlenNameP, _row, ':');
  6515. lcd_set_cursor(_col + strlenNameP + 1, _row);
  6516. lcd_print(_indicator);
  6517. break;
  6518. case 2:
  6519. lcd_puts_P(_name_PROGMEM);
  6520. lcd_putc_at(_col + strlenNameP, _row, ':');
  6521. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  6522. break;
  6523. default:
  6524. lcd_puts_P(_name_PROGMEM);
  6525. }
  6526. }
  6527. /** End of menus **/
  6528. /** Menu action functions **/
  6529. static bool check_file(const char* filename) {
  6530. if (farm_mode) return true;
  6531. card.openFileReadFilteredGcode(filename, true);
  6532. bool result = false;
  6533. const uint32_t filesize = card.getFileSize();
  6534. uint32_t startPos = 0;
  6535. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  6536. if (filesize > END_FILE_SECTION) {
  6537. startPos = filesize - END_FILE_SECTION;
  6538. card.setIndex(startPos);
  6539. }
  6540. cmdqueue_reset();
  6541. cmdqueue_serial_disabled = true;
  6542. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  6543. while (!card.eof() && !result) {
  6544. menu_progressbar_update(card.get_sdpos() - startPos);
  6545. card.sdprinting = true;
  6546. get_command();
  6547. result = check_commands();
  6548. #ifdef CMDBUFFER_DEBUG
  6549. // Kick watchdog because the file check is very slow
  6550. // with the CMDBUFFER_DEBUG enabled
  6551. manage_heater();
  6552. #endif // CMDBUFFER_DEBUG
  6553. }
  6554. menu_progressbar_finish();
  6555. cmdqueue_serial_disabled = false;
  6556. card.printingHasFinished();
  6557. lcd_setstatuspgm(MSG_WELCOME);
  6558. return result;
  6559. }
  6560. static void menu_action_sdfile(const char* filename)
  6561. {
  6562. loading_flag = false;
  6563. char cmd[30];
  6564. char* c;
  6565. bool result = true;
  6566. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6567. for (c = &cmd[4]; *c; c++)
  6568. *c = tolower(*c);
  6569. const char end[5] = ".gco";
  6570. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6571. for (uint_least8_t i = 0; i < 8; i++) {
  6572. if (strcmp((cmd + i + 4), end) == 0) {
  6573. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6574. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6575. break;
  6576. }
  6577. else {
  6578. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6579. }
  6580. }
  6581. uint8_t depth = card.getWorkDirDepth();
  6582. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6583. for (uint_least8_t i = 0; i < depth; i++) {
  6584. for (uint_least8_t j = 0; j < 8; j++) {
  6585. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  6586. }
  6587. }
  6588. //filename is just a pointer to card.filename, which changes everytime you try to open a file by filename. So you can't use filename directly
  6589. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  6590. if (!check_file(cmd + 4)) {
  6591. result = !lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false);////MSG_FILE_INCOMPLETE c=20 r=3
  6592. lcd_update_enable(true);
  6593. }
  6594. if (result) {
  6595. enquecommand(cmd);
  6596. enquecommand_P(PSTR("M24"));
  6597. }
  6598. lcd_return_to_status();
  6599. }
  6600. void menu_action_sddirectory(const char* filename)
  6601. {
  6602. card.chdir(filename, true);
  6603. lcd_encoder = 0;
  6604. menu_data_reset(); //Forces reloading of cached variables.
  6605. }
  6606. /** LCD API **/
  6607. void ultralcd_init()
  6608. {
  6609. backlight_init();
  6610. lcd_init();
  6611. lcd_refresh();
  6612. lcd_longpress_func = menu_lcd_longpress_func;
  6613. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6614. menu_menu = lcd_status_screen;
  6615. SET_INPUT(BTN_EN1);
  6616. SET_INPUT(BTN_EN2);
  6617. WRITE(BTN_EN1, HIGH);
  6618. WRITE(BTN_EN2, HIGH);
  6619. #if BTN_ENC > 0
  6620. SET_INPUT(BTN_ENC);
  6621. WRITE(BTN_ENC, HIGH);
  6622. #endif
  6623. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6624. SET_INPUT(SDCARDDETECT);
  6625. WRITE(SDCARDDETECT, HIGH);
  6626. _delay_ms(1); //wait for the pullups to raise the line
  6627. lcd_oldcardstatus = IS_SD_INSERTED;
  6628. #endif//(SDCARDDETECT > 0)
  6629. lcd_encoder_diff = 0;
  6630. // Initialise status line
  6631. strncpy_P(lcd_status_message, MSG_WELCOME, LCD_WIDTH);
  6632. }
  6633. void lcd_ignore_click(bool b)
  6634. {
  6635. ignore_click = b;
  6636. wait_for_unclick = false;
  6637. }
  6638. static bool lcd_message_check(uint8_t priority)
  6639. {
  6640. // regular priority check
  6641. if (priority >= lcd_status_message_level)
  6642. return true;
  6643. // check if we can override an info message yet
  6644. if (lcd_status_message_level == LCD_STATUS_INFO) {
  6645. return lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT);
  6646. }
  6647. return false;
  6648. }
  6649. static void lcd_updatestatus(const char *message, bool progmem = false)
  6650. {
  6651. if (progmem)
  6652. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6653. else
  6654. strncpy(lcd_status_message, message, LCD_WIDTH);
  6655. lcd_status_message[LCD_WIDTH] = 0;
  6656. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  6657. // hack lcd_draw_update to 1, i.e. without clear
  6658. lcd_draw_update = 1;
  6659. }
  6660. void lcd_setstatus(const char* message)
  6661. {
  6662. if (lcd_message_check(LCD_STATUS_NONE))
  6663. lcd_updatestatus(message);
  6664. }
  6665. void lcd_setstatuspgm(const char* message)
  6666. {
  6667. if (lcd_message_check(LCD_STATUS_NONE))
  6668. lcd_updatestatus(message, true);
  6669. }
  6670. void lcd_setstatus_serial(const char* message)
  6671. {
  6672. if (lcd_message_check(LCD_STATUS_NONE))
  6673. lcd_updatestatus(message);
  6674. SERIAL_ECHOLN(message);
  6675. }
  6676. void lcd_setalertstatus_(const char* message, uint8_t severity, bool progmem)
  6677. {
  6678. if (lcd_message_check(severity)) {
  6679. bool same = !(progmem?
  6680. strcmp_P(lcd_status_message, message):
  6681. strcmp(lcd_status_message, message));
  6682. lcd_status_message_timeout.start();
  6683. lcd_status_message_level = severity;
  6684. custom_message_type = CustomMsg::Status;
  6685. custom_message_state = 0;
  6686. if (!same) {
  6687. // do not kick the user out of the menus if the message is unchanged
  6688. lcd_updatestatus(message, progmem);
  6689. lcd_return_to_status();
  6690. }
  6691. }
  6692. }
  6693. void lcd_setalertstatus(const char* message, uint8_t severity)
  6694. {
  6695. lcd_setalertstatus_(message, severity, false);
  6696. }
  6697. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  6698. {
  6699. lcd_setalertstatus_(message, severity, true);
  6700. }
  6701. void lcd_reset_alert_level()
  6702. {
  6703. lcd_status_message_level = 0;
  6704. }
  6705. uint8_t get_message_level()
  6706. {
  6707. return lcd_status_message_level;
  6708. }
  6709. void menu_lcd_longpress_func(void)
  6710. {
  6711. // Wake up the LCD backlight and,
  6712. // start LCD inactivity timer
  6713. lcd_timeoutToStatus.start();
  6714. backlight_wake();
  6715. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z || menu_block_mask != MENU_BLOCK_NONE || Stopped)
  6716. {
  6717. // disable longpress during re-entry, while homing, calibration or if a serious error
  6718. lcd_quick_feedback();
  6719. return;
  6720. }
  6721. if (menu_menu == lcd_hw_setup_menu)
  6722. {
  6723. // only toggle the experimental menu visibility flag
  6724. lcd_quick_feedback();
  6725. eeprom_toggle((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  6726. return;
  6727. }
  6728. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  6729. // The lists are not the same for both functions, so first decide which function is to be performed
  6730. if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z
  6731. if (( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  6732. && ( menu_menu == lcd_status_screen // and in listed menus...
  6733. || menu_menu == lcd_main_menu
  6734. || menu_menu == lcd_tune_menu
  6735. || menu_menu == lcd_support_menu
  6736. )
  6737. ){
  6738. lcd_clear();
  6739. menu_submenu(lcd_babystep_z);
  6740. } else {
  6741. lcd_quick_feedback();
  6742. }
  6743. } else { // long press as move-z
  6744. if (menu_menu == lcd_status_screen
  6745. || menu_menu == lcd_main_menu
  6746. || menu_menu == lcd_preheat_menu
  6747. || menu_menu == lcd_sdcard_menu
  6748. || menu_menu == lcd_settings_menu
  6749. || menu_menu == lcd_control_temperature_menu
  6750. #if (LANG_MODE != 0)
  6751. || menu_menu == lcd_language
  6752. #endif
  6753. || menu_menu == lcd_support_menu
  6754. ){
  6755. menu_submenu(lcd_move_z);
  6756. } else {
  6757. lcd_quick_feedback();
  6758. }
  6759. }
  6760. }
  6761. static inline bool z_menu_expired()
  6762. {
  6763. return (menu_menu == lcd_babystep_z
  6764. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6765. }
  6766. static inline bool other_menu_expired()
  6767. {
  6768. return (menu_menu != lcd_status_screen
  6769. && menu_menu != lcd_babystep_z
  6770. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6771. }
  6772. void menu_lcd_lcdupdate_func(void)
  6773. {
  6774. #if (SDCARDDETECT > 0)
  6775. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6776. {
  6777. if(menu_menu == lcd_sdcard_menu) {
  6778. // If the user is either inside the submenus
  6779. // 1. 'Print from SD' --> and SD card is removed
  6780. // 2. 'No SD card' --> and SD card is inserted
  6781. //
  6782. // 1. 'Print from SD': We want to back out of this submenu
  6783. // and instead show the submenu title 'No SD card'.
  6784. //
  6785. // 2. 'No SD card': When the user inserts the SD card we want
  6786. // to back out of this submenu. Not only to show
  6787. // 'Print from SD' submenu title but also because the user
  6788. // will be prompted with another menu with the sorted list of files.
  6789. // Without backing out of the menu, the list will appear empty and
  6790. // The user will need to back out of two nested submenus.
  6791. menu_back();
  6792. }
  6793. lcd_draw_update = 2;
  6794. lcd_oldcardstatus = IS_SD_INSERTED;
  6795. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6796. backlight_wake();
  6797. if (lcd_oldcardstatus)
  6798. {
  6799. if (!card.cardOK)
  6800. {
  6801. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  6802. card.presort_flag = true; //force sorting of the SD menu
  6803. }
  6804. LCD_MESSAGERPGM(MSG_WELCOME);
  6805. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  6806. menu_submenu(lcd_sdcard_menu);
  6807. lcd_timeoutToStatus.start();
  6808. }
  6809. else
  6810. {
  6811. card.release();
  6812. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  6813. }
  6814. }
  6815. #endif//CARDINSERTED
  6816. backlight_update();
  6817. if (lcd_next_update_millis < _millis())
  6818. {
  6819. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6820. {
  6821. if (lcd_draw_update == 0)
  6822. lcd_draw_update = 1;
  6823. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6824. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  6825. lcd_encoder_diff = 0;
  6826. lcd_timeoutToStatus.start();
  6827. backlight_wake();
  6828. }
  6829. if (LCD_CLICKED)
  6830. {
  6831. lcd_timeoutToStatus.start();
  6832. backlight_wake();
  6833. }
  6834. (*menu_menu)();
  6835. if (z_menu_expired() || other_menu_expired())
  6836. {
  6837. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  6838. // to give it a chance to save its state.
  6839. // This is useful for example, when the babystep value has to be written into EEPROM.
  6840. if (menu_menu != NULL)
  6841. {
  6842. menu_leaving = 1;
  6843. (*menu_menu)();
  6844. menu_leaving = 0;
  6845. }
  6846. lcd_clear();
  6847. lcd_return_to_status();
  6848. lcd_draw_update = 2;
  6849. }
  6850. if (lcd_draw_update == 2) lcd_clear();
  6851. if (lcd_draw_update) lcd_draw_update--;
  6852. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  6853. }
  6854. prusa_statistics_update_from_lcd_update();
  6855. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  6856. }
  6857. #ifdef TMC2130
  6858. //! @brief Is crash detection enabled?
  6859. //!
  6860. //! @retval true crash detection enabled
  6861. //! @retval false crash detection disabled
  6862. bool lcd_crash_detect_enabled()
  6863. {
  6864. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  6865. }
  6866. void lcd_crash_detect_enable()
  6867. {
  6868. tmc2130_sg_stop_on_crash = true;
  6869. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  6870. }
  6871. void lcd_crash_detect_disable()
  6872. {
  6873. tmc2130_sg_stop_on_crash = false;
  6874. tmc2130_sg_crash = 0;
  6875. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  6876. }
  6877. #endif
  6878. #ifdef TMC2130
  6879. void UserECool_toggle(){
  6880. // this is only called when the experimental menu is visible, thus the first condition for enabling of the ECool mode is met in this place
  6881. // The condition is intentionally inverted as we are toggling the state (i.e. if it was enabled, we are disabling the feature and vice versa)
  6882. bool enable = ! UserECoolEnabled();
  6883. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  6884. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  6885. // and I don't want to add more code for this experimental feature ... ideally do not reinit the TMC here at all and let the user reset the printer.
  6886. tmc2130_init(TMCInitParams(enable));
  6887. }
  6888. #endif
  6889. /// Enable experimental support for cooler operation of the extruder motor
  6890. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  6891. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  6892. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  6893. /// (which would be obviously too late for an improperly sized motor)
  6894. /// For farm printing, the cooler E-motor is enabled by default.
  6895. bool UserECoolEnabled(){
  6896. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  6897. // a value of the universal answer to all problems of the universe
  6898. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  6899. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  6900. }
  6901. bool FarmOrUserECool(){
  6902. return farm_mode || UserECoolEnabled();
  6903. }
  6904. #ifdef PRUSA_SN_SUPPORT
  6905. void WorkaroundPrusaSN() {
  6906. const char *SN = PSTR("CZPXInvalidSerialNr");
  6907. for (uint8_t i = 0; i < 20; i++) {
  6908. eeprom_update_byte((uint8_t*)EEPROM_PRUSA_SN + i, pgm_read_byte(SN++));
  6909. }
  6910. }
  6911. #endif //PRUSA_SN_SUPPORT
  6912. void lcd_experimental_menu()
  6913. {
  6914. MENU_BEGIN();
  6915. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6916. #ifdef EXTRUDER_ALTFAN_DETECT
  6917. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  6918. #endif //EXTRUDER_ALTFAN_DETECT
  6919. #ifdef TMC2130
  6920. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  6921. #endif
  6922. #ifdef DEBUG_PULLUP_CRASH
  6923. MENU_ITEM_FUNCTION_P(_N("Test Pullup Crash"), TestPullupCrash);
  6924. #endif // DEBUG_PULLUP_CRASH
  6925. #ifdef PRUSA_SN_SUPPORT
  6926. MENU_ITEM_FUNCTION_P(_N("Fake serial number"), WorkaroundPrusaSN);////MSG_WORKAROUND_PRUSA_SN c=18
  6927. #endif //PRUSA_SN_SUPPORT
  6928. MENU_END();
  6929. }
  6930. #ifdef PINDA_TEMP_COMP
  6931. void lcd_pinda_temp_compensation_toggle()
  6932. {
  6933. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  6934. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  6935. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  6936. else
  6937. pinda_temp_compensation = !pinda_temp_compensation;
  6938. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  6939. SERIAL_ECHOLNPGM("SuperPINDA:");
  6940. SERIAL_ECHOLN(pinda_temp_compensation);
  6941. }
  6942. #endif //PINDA_TEMP_COMP
  6943. void lcd_heat_bed_on_load_toggle()
  6944. {
  6945. uint8_t value = eeprom_read_byte((uint8_t*)EEPROM_HEAT_BED_ON_LOAD_FILAMENT);
  6946. if (value > 1)
  6947. value = 1;
  6948. else
  6949. value = !value;
  6950. eeprom_update_byte((uint8_t*)EEPROM_HEAT_BED_ON_LOAD_FILAMENT, value);
  6951. }