ultralcd.cpp 246 KB

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