ultralcd.cpp 241 KB

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