ultralcd.cpp 245 KB

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