ultralcd.cpp 246 KB

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