ultralcd.cpp 243 KB

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