ultralcd.cpp 246 KB

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