ultralcd.cpp 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #include "fsensor.h"
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. #include <string.h>
  11. #include "lcd.h"
  12. #include "menu.h"
  13. #include "util.h"
  14. #include "mesh_bed_leveling.h"
  15. #include "mesh_bed_calibration.h"
  16. //#include "Configuration.h"
  17. #include "cmdqueue.h"
  18. #include "SdFatUtil.h"
  19. #ifdef FILAMENT_SENSOR
  20. #include "pat9125.h"
  21. #include "fsensor.h"
  22. #endif //FILAMENT_SENSOR
  23. #ifdef TMC2130
  24. #include "tmc2130.h"
  25. #endif //TMC2130
  26. #include "sound.h"
  27. #include "mmu.h"
  28. extern bool fans_check_enabled;
  29. int scrollstuff = 0;
  30. char longFilenameOLD[LONG_FILENAME_LENGTH];
  31. static void lcd_sd_updir();
  32. int8_t ReInitLCD = 0;
  33. int8_t SilentModeMenu = SILENT_MODE_OFF;
  34. int8_t FSensorStateMenu = 1;
  35. int8_t CrashDetectMenu = 1;
  36. extern bool fsensor_enable();
  37. extern void fsensor_disable();
  38. #ifdef TMC2130
  39. extern void crashdet_enable();
  40. extern void crashdet_disable();
  41. #endif //TMC2130
  42. #ifdef SDCARD_SORT_ALPHA
  43. bool presort_flag = false;
  44. #endif
  45. int lcd_commands_type = LCD_COMMAND_IDLE;
  46. int lcd_commands_step = 0;
  47. unsigned int custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  48. unsigned int custom_message_state = 0;
  49. bool isPrintPaused = false;
  50. uint8_t farm_mode = 0;
  51. int farm_no = 0;
  52. int farm_timer = 8;
  53. int farm_status = 0;
  54. bool printer_connected = true;
  55. unsigned long display_time; //just timer for showing pid finished message on lcd;
  56. float pid_temp = DEFAULT_PID_TEMP;
  57. static bool forceMenuExpire = false;
  58. bool lcd_autoDeplete;
  59. static float manual_feedrate[] = MANUAL_FEEDRATE;
  60. /* !Configuration settings */
  61. uint8_t lcd_status_message_level;
  62. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  63. unsigned char firstrun = 1;
  64. static const char separator[] PROGMEM = "--------------------";
  65. /** forward declarations **/
  66. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines);
  67. // void copy_and_scalePID_i();
  68. // void copy_and_scalePID_d();
  69. /* Different menus */
  70. static void lcd_status_screen();
  71. static void lcd_language_menu();
  72. static void lcd_main_menu();
  73. static void lcd_tune_menu();
  74. //static void lcd_move_menu();
  75. static void lcd_settings_menu();
  76. static void lcd_calibration_menu();
  77. #ifdef LINEARITY_CORRECTION
  78. static void lcd_settings_menu_back();
  79. #endif //LINEARITY_CORRECTION
  80. static void lcd_control_temperature_menu();
  81. static void lcd_control_temperature_preheat_pla_settings_menu();
  82. static void lcd_control_temperature_preheat_abs_settings_menu();
  83. static void lcd_control_motion_menu();
  84. static void lcd_control_volumetric_menu();
  85. static void lcd_settings_linearity_correction_menu_save();
  86. static void prusa_stat_printerstatus(int _status);
  87. static void prusa_stat_farm_number();
  88. static void prusa_stat_temperatures();
  89. static void prusa_stat_printinfo();
  90. static void lcd_farm_no();
  91. static void lcd_menu_extruder_info();
  92. static void lcd_menu_xyz_y_min();
  93. static void lcd_menu_xyz_skew();
  94. static void lcd_menu_xyz_offset();
  95. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  96. static void lcd_menu_fails_stats();
  97. #endif //TMC2130 or FILAMENT_SENSOR
  98. static void lcd_selftest_v();
  99. #ifdef TMC2130
  100. static void reset_crash_det(unsigned char axis);
  101. static bool lcd_selfcheck_axis_sg(unsigned char axis);
  102. static bool lcd_selfcheck_axis(int _axis, int _travel);
  103. #else
  104. static bool lcd_selfcheck_endstops();
  105. static bool lcd_selfcheck_axis(int _axis, int _travel);
  106. static bool lcd_selfcheck_pulleys(int axis);
  107. #endif //TMC2130
  108. static bool lcd_selfcheck_check_heater(bool _isbed);
  109. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay);
  110. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator);
  111. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite);
  112. static bool lcd_selftest_fan_dialog(int _fan);
  113. static bool lcd_selftest_fsensor();
  114. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2);
  115. static void lcd_colorprint_change();
  116. #ifdef SNMM
  117. static int get_ext_nr();
  118. #endif //SNMM
  119. #if defined (SNMM) || defined(SNMM_V2)
  120. static void fil_load_menu();
  121. static void fil_unload_menu();
  122. #endif // SNMM || SNMM_V2
  123. static void lcd_disable_farm_mode();
  124. static void lcd_set_fan_check();
  125. static char snmm_stop_print_menu();
  126. #ifdef SDCARD_SORT_ALPHA
  127. static void lcd_sort_type_set();
  128. #endif
  129. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length);
  130. static void lcd_babystep_z();
  131. static void lcd_send_status();
  132. #ifdef FARM_CONNECT_MESSAGE
  133. static void lcd_connect_printer();
  134. #endif //FARM_CONNECT_MESSAGE
  135. void lcd_finishstatus();
  136. static void lcd_sdcard_menu();
  137. #ifdef DELTA_CALIBRATION_MENU
  138. static void lcd_delta_calibrate_menu();
  139. #endif // DELTA_CALIBRATION_MENU
  140. /* Different types of actions that can be used in menu items. */
  141. static void menu_action_sdfile(const char* filename);
  142. static void menu_action_sddirectory(const char* filename);
  143. #define ENCODER_FEEDRATE_DEADZONE 10
  144. /*
  145. #define MENU_ITEM(type, label, args...) do { \
  146. if (menu_item == menu_line) { \
  147. if (lcd_draw_update) { \
  148. const char* _label_pstr = (label); \
  149. if (lcd_encoder == menu_item) { \
  150. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  151. }else{\
  152. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  153. }\
  154. }\
  155. if (menu_clicked && (lcd_encoder == menu_item)) {\
  156. lcd_quick_feedback(); \
  157. menu_action_ ## type ( args ); \
  158. return;\
  159. }\
  160. }\
  161. menu_item++;\
  162. } while(0)
  163. */
  164. #if (SDCARDDETECT > 0)
  165. bool lcd_oldcardstatus;
  166. #endif
  167. bool ignore_click = false;
  168. bool wait_for_unclick;
  169. // place-holders for Ki and Kd edits
  170. #ifdef PIDTEMP
  171. // float raw_Ki, raw_Kd;
  172. #endif
  173. const char STR_SEPARATOR[] PROGMEM = "------------";
  174. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longFilename)
  175. {
  176. char c;
  177. int enc_dif = lcd_encoder_diff;
  178. uint8_t n = LCD_WIDTH - 1;
  179. for(int g = 0; g<4;g++){
  180. lcd_set_cursor(0, g);
  181. lcd_print(' ');
  182. }
  183. lcd_set_cursor(0, row);
  184. lcd_print('>');
  185. int i = 1;
  186. int j = 0;
  187. char* longFilenameTMP = longFilename;
  188. while((c = *longFilenameTMP) != '\0')
  189. {
  190. lcd_set_cursor(i, row);
  191. lcd_print(c);
  192. i++;
  193. longFilenameTMP++;
  194. if(i==LCD_WIDTH){
  195. i=1;
  196. j++;
  197. longFilenameTMP = longFilename + j;
  198. n = LCD_WIDTH - 1;
  199. for(int g = 0; g<300 ;g++){
  200. manage_heater();
  201. if(LCD_CLICKED || ( enc_dif != lcd_encoder_diff )){
  202. longFilenameTMP = longFilename;
  203. *(longFilenameTMP + LCD_WIDTH - 2) = '\0';
  204. i = 1;
  205. j = 0;
  206. break;
  207. }else{
  208. if (j == 1) delay(3); //wait around 1.2 s to start scrolling text
  209. delay(1); //then scroll with redrawing every 300 ms
  210. }
  211. }
  212. }
  213. }
  214. if(c!='\0'){
  215. lcd_set_cursor(i, row);
  216. lcd_print(c);
  217. i++;
  218. }
  219. n=n-i+1;
  220. while(n--)
  221. lcd_print(' ');
  222. }
  223. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* filename, char* longFilename)
  224. {
  225. char c;
  226. uint8_t n = LCD_WIDTH - 1;
  227. lcd_set_cursor(0, row);
  228. lcd_print(' ');
  229. if (longFilename[0] != '\0')
  230. {
  231. filename = longFilename;
  232. longFilename[LCD_WIDTH-1] = '\0';
  233. }
  234. while( ((c = *filename) != '\0') && (n>0) )
  235. {
  236. lcd_print(c);
  237. filename++;
  238. n--;
  239. }
  240. while(n--)
  241. lcd_print(' ');
  242. }
  243. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* filename, char* longFilename)
  244. {
  245. char c;
  246. uint8_t n = LCD_WIDTH - 2;
  247. lcd_set_cursor(0, row);
  248. lcd_print('>');
  249. lcd_print(LCD_STR_FOLDER[0]);
  250. if (longFilename[0] != '\0')
  251. {
  252. filename = longFilename;
  253. longFilename[LCD_WIDTH-2] = '\0';
  254. }
  255. while( ((c = *filename) != '\0') && (n>0) )
  256. {
  257. lcd_print(c);
  258. filename++;
  259. n--;
  260. }
  261. while(n--)
  262. lcd_print(' ');
  263. }
  264. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* filename, char* longFilename)
  265. {
  266. char c;
  267. uint8_t n = LCD_WIDTH - 2;
  268. lcd_set_cursor(0, row);
  269. lcd_print(' ');
  270. lcd_print(LCD_STR_FOLDER[0]);
  271. if (longFilename[0] != '\0')
  272. {
  273. filename = longFilename;
  274. longFilename[LCD_WIDTH-2] = '\0';
  275. }
  276. while( ((c = *filename) != '\0') && (n>0) )
  277. {
  278. lcd_print(c);
  279. filename++;
  280. n--;
  281. }
  282. while(n--)
  283. lcd_print(' ');
  284. }
  285. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  286. //#define MENU_ITEM_SDDIR(str, str_fn, str_fnl) MENU_ITEM(sddirectory, str, str_fn, str_fnl)
  287. //extern uint8_t menu_item_sddir(const char* str, const char* str_fn, char* str_fnl);
  288. #define MENU_ITEM_SDFILE(str, str_fn, str_fnl) do { if (menu_item_sdfile(str, str_fn, str_fnl)) return; } while (0)
  289. //#define MENU_ITEM_SDFILE(str, str_fn, str_fnl) MENU_ITEM(sdfile, str, str_fn, str_fnl)
  290. //extern uint8_t menu_item_sdfile(const char* str, const char* str_fn, char* str_fnl);
  291. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  292. {
  293. #ifdef NEW_SD_MENU
  294. // str_fnl[18] = 0;
  295. // printf_P(PSTR("menu dir %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  296. if (menu_item == menu_line)
  297. {
  298. if (lcd_draw_update)
  299. {
  300. lcd_set_cursor(0, menu_row);
  301. int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fnl[0]?str_fnl:str_fn);
  302. // int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fn);
  303. }
  304. if (menu_clicked && (lcd_encoder == menu_item))
  305. {
  306. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  307. strcpy(dir_names[depth], str_fn);
  308. // printf_P(PSTR("%s\n"), dir_names[depth]);
  309. card.chdir(str_fn);
  310. lcd_encoder = 0;
  311. return menu_item_ret();
  312. }
  313. }
  314. menu_item++;
  315. return 0;
  316. #else //NEW_SD_MENU
  317. if (menu_item == menu_line)
  318. {
  319. if (lcd_draw_update)
  320. {
  321. if (lcd_encoder == menu_item)
  322. lcd_implementation_drawmenu_sddirectory_selected(menu_row, str_fn, str_fnl);
  323. else
  324. lcd_implementation_drawmenu_sddirectory(menu_row, str_fn, str_fnl);
  325. }
  326. if (menu_clicked && (lcd_encoder == menu_item))
  327. {
  328. menu_clicked = false;
  329. lcd_update_enabled = 0;
  330. menu_action_sddirectory(str_fn);
  331. lcd_update_enabled = 1;
  332. return menu_item_ret();
  333. }
  334. }
  335. menu_item++;
  336. return 0;
  337. #endif //NEW_SD_MENU
  338. }
  339. static uint8_t menu_item_sdfile(const char*
  340. #ifdef NEW_SD_MENU
  341. str
  342. #endif //NEW_SD_MENU
  343. ,const char* str_fn, char* str_fnl)
  344. {
  345. #ifdef NEW_SD_MENU
  346. // printf_P(PSTR("menu sdfile\n"));
  347. // str_fnl[19] = 0;
  348. // printf_P(PSTR("menu file %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  349. if (menu_item == menu_line)
  350. {
  351. if (lcd_draw_update)
  352. {
  353. // printf_P(PSTR("menu file %d %d '%s'\n"), menu_row, menuData.sdcard_menu.viewState, str_fnl[0]?str_fnl:str_fn);
  354. lcd_set_cursor(0, menu_row);
  355. /* if (lcd_encoder == menu_item)
  356. {
  357. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  358. if (menuData.sdcard_menu.viewState == 0)
  359. {
  360. menuData.sdcard_menu.viewState++;
  361. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  362. }
  363. else if (menuData.sdcard_menu.viewState == 1)
  364. {
  365. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 2);
  366. }
  367. }
  368. else*/
  369. {
  370. str_fnl[19] = 0;
  371. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', str_fnl[0]?str_fnl:str_fn);
  372. }
  373. // int cnt = lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', str_fnl);
  374. // int cnt = lcd_printf_P(PSTR("%cTESTIK.gcode"), (lcd_encoder == menu_item)?'>':' ');
  375. }
  376. if (menu_clicked && (lcd_encoder == menu_item))
  377. {
  378. return menu_item_ret();
  379. }
  380. }
  381. menu_item++;
  382. return 0;
  383. #else //NEW_SD_MENU
  384. if (menu_item == menu_line)
  385. {
  386. if (lcd_draw_update)
  387. {
  388. if (lcd_encoder == menu_item)
  389. lcd_implementation_drawmenu_sdfile_selected(menu_row, str_fnl);
  390. else
  391. lcd_implementation_drawmenu_sdfile(menu_row, str_fn, str_fnl);
  392. }
  393. if (menu_clicked && (lcd_encoder == menu_item))
  394. {
  395. lcd_consume_click();
  396. menu_action_sdfile(str_fn);
  397. return menu_item_ret();
  398. }
  399. }
  400. menu_item++;
  401. return 0;
  402. #endif //NEW_SD_MENU
  403. }
  404. // Print temperature (nozzle/bed) (9 chars total)
  405. void lcdui_print_temp(char type, int val_current, int val_target)
  406. {
  407. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  408. lcd_space(9 - chars);
  409. }
  410. // Print Z-coordinate (8 chars total)
  411. void lcdui_print_Z_coord(void)
  412. {
  413. if (custom_message_type == CUSTOM_MSG_TYPE_MESHBL)
  414. lcd_puts_P(_N("Z --- "));
  415. else
  416. lcd_printf_P(_N("Z%6.2f "), current_position[Z_AXIS]);
  417. }
  418. #ifdef PLANNER_DIAGNOSTICS
  419. // Print planner diagnostics (8 chars total)
  420. void lcdui_print_planner_diag(void)
  421. {
  422. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  423. lcd_print(LCD_STR_FEEDRATE[0]);
  424. lcd_print(itostr3(feedmultiply));
  425. lcd_puts_P(PSTR("% Q"));
  426. {
  427. uint8_t queue = planner_queue_min();
  428. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  429. lcd_putc('!');
  430. else
  431. {
  432. lcd_putc((char)(queue / 10) + '0');
  433. queue %= 10;
  434. }
  435. lcd_putc((char)queue + '0');
  436. planner_queue_min_reset();
  437. }
  438. }
  439. #endif // PLANNER_DIAGNOSTICS
  440. // Print feedrate (8 chars total)
  441. void lcdui_print_feedrate(void)
  442. {
  443. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  444. lcd_space(8 - chars);
  445. }
  446. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  447. void lcdui_print_percent_done(void)
  448. {
  449. const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  450. char per[4];
  451. bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  452. sprintf_P(per, num?_N("%3hhd"):_N("---"), calc_percent_done());
  453. lcd_printf_P(_N("%3S%3s%%"), src, per);
  454. }
  455. // Print extruder status (5 chars total)
  456. void lcdui_print_extruder(void)
  457. {
  458. int chars = 0;
  459. if (mmu_extruder == tmp_extruder)
  460. chars = lcd_printf_P(_N(" F%u"), mmu_extruder+1);
  461. else
  462. chars = lcd_printf_P(_N(" %u>%u"), mmu_extruder+1, tmp_extruder+1);
  463. lcd_space(5 - chars);
  464. }
  465. // Print farm number (5 chars total)
  466. void lcdui_print_farm(void)
  467. {
  468. int chars = lcd_printf_P(_N(" F0 "));
  469. // lcd_space(5 - chars);
  470. /*
  471. // Farm number display
  472. if (farm_mode)
  473. {
  474. lcd_set_cursor(6, 2);
  475. lcd_puts_P(PSTR(" F"));
  476. lcd_print(farm_no);
  477. lcd_puts_P(PSTR(" "));
  478. // Beat display
  479. lcd_set_cursor(LCD_WIDTH - 1, 0);
  480. if ( (millis() - kicktime) < 60000 ) {
  481. lcd_puts_P(PSTR("L"));
  482. }else{
  483. lcd_puts_P(PSTR(" "));
  484. }
  485. }
  486. else {
  487. #ifdef SNMM
  488. lcd_puts_P(PSTR(" E"));
  489. lcd_print(get_ext_nr() + 1);
  490. #else
  491. lcd_set_cursor(LCD_WIDTH - 8 - 2, 2);
  492. lcd_puts_P(PSTR(" "));
  493. #endif
  494. }
  495. */
  496. }
  497. #ifdef CMD_DIAGNOSTICS
  498. // Print CMD queue diagnostic (8 chars total)
  499. void lcdui_print_cmd_diag(void)
  500. {
  501. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  502. lcd_puts_P(PSTR(" C"));
  503. lcd_print(buflen); // number of commands in cmd buffer
  504. if (buflen < 9) lcd_puts_P(" ");
  505. }
  506. #endif //CMD_DIAGNOSTICS
  507. // Print time (8 chars total)
  508. void lcdui_print_time(void)
  509. {
  510. //if remaining print time estimation is available print it else print elapsed time
  511. uint16_t print_t = 0;
  512. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  513. print_t = print_time_remaining();
  514. else if(starttime != 0)
  515. print_t = millis() / 60000 - starttime / 60000;
  516. int chars = 0;
  517. if ((PRINTER_ACTIVE) && ((print_time_remaining_normal != PRINT_TIME_REMAINING_INIT) || (starttime != 0)))
  518. {
  519. char suff = ' ';
  520. char suff_doubt = ' ';
  521. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  522. {
  523. suff = 'R';
  524. if (feedmultiply != 100)
  525. suff_doubt = '?';
  526. }
  527. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  528. }
  529. else
  530. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  531. lcd_space(8 - chars);
  532. }
  533. //Print status line on status screen
  534. void lcdui_print_status_line(void)
  535. {
  536. if (IS_SD_PRINTING)
  537. {
  538. if (strcmp(longFilenameOLD, card.longFilename) != 0)
  539. {
  540. memset(longFilenameOLD, '\0', strlen(longFilenameOLD));
  541. sprintf_P(longFilenameOLD, PSTR("%s"), card.longFilename);
  542. scrollstuff = 0;
  543. }
  544. }
  545. if (heating_status)
  546. { // If heating flag, show progress of heating
  547. heating_status_counter++;
  548. if (heating_status_counter > 13)
  549. {
  550. heating_status_counter = 0;
  551. }
  552. lcd_set_cursor(7, 3);
  553. lcd_puts_P(PSTR(" "));
  554. for (unsigned int dots = 0; dots < heating_status_counter; dots++)
  555. {
  556. lcd_set_cursor(7 + dots, 3);
  557. lcd_print('.');
  558. }
  559. switch (heating_status)
  560. {
  561. case 1:
  562. lcd_set_cursor(0, 3);
  563. lcd_puts_P(_T(MSG_HEATING));
  564. break;
  565. case 2:
  566. lcd_set_cursor(0, 3);
  567. lcd_puts_P(_T(MSG_HEATING_COMPLETE));
  568. heating_status = 0;
  569. heating_status_counter = 0;
  570. break;
  571. case 3:
  572. lcd_set_cursor(0, 3);
  573. lcd_puts_P(_T(MSG_BED_HEATING));
  574. break;
  575. case 4:
  576. lcd_set_cursor(0, 3);
  577. lcd_puts_P(_T(MSG_BED_DONE));
  578. heating_status = 0;
  579. heating_status_counter = 0;
  580. break;
  581. default:
  582. break;
  583. }
  584. }
  585. else if ((IS_SD_PRINTING) && (custom_message_type == CUSTOM_MSG_TYPE_STATUS))
  586. { // If printing from SD, show what we are printing
  587. if(strlen(card.longFilename) > LCD_WIDTH)
  588. {
  589. int inters = 0;
  590. int gh = scrollstuff;
  591. while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0))
  592. {
  593. if (card.longFilename[gh] == '\0')
  594. {
  595. lcd_set_cursor(gh - scrollstuff, 3);
  596. lcd_print(card.longFilename[gh - 1]);
  597. scrollstuff = 0;
  598. gh = scrollstuff;
  599. inters = 1;
  600. }
  601. else
  602. {
  603. lcd_set_cursor(gh - scrollstuff, 3);
  604. lcd_print(card.longFilename[gh - 1]);
  605. gh++;
  606. }
  607. }
  608. scrollstuff++;
  609. }
  610. else
  611. {
  612. lcd_print(longFilenameOLD);
  613. }
  614. }
  615. else
  616. { // Otherwise check for other special events
  617. switch (custom_message_type)
  618. {
  619. case CUSTOM_MSG_TYPE_STATUS: // Nothing special, print status message normally
  620. lcd_print(lcd_status_message);
  621. break;
  622. case CUSTOM_MSG_TYPE_MESHBL: // If mesh bed leveling in progress, show the status
  623. if (custom_message_state > 10)
  624. {
  625. lcd_set_cursor(0, 3);
  626. lcd_puts_P(PSTR(" "));
  627. lcd_set_cursor(0, 3);
  628. lcd_puts_P(_T(MSG_CALIBRATE_Z_AUTO));
  629. lcd_puts_P(PSTR(" : "));
  630. lcd_print(custom_message_state-10);
  631. }
  632. else
  633. {
  634. if (custom_message_state == 3)
  635. {
  636. lcd_puts_P(_T(WELCOME_MSG));
  637. lcd_setstatuspgm(_T(WELCOME_MSG));
  638. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  639. }
  640. if (custom_message_state > 3 && custom_message_state <= 10 )
  641. {
  642. lcd_set_cursor(0, 3);
  643. lcd_puts_P(PSTR(" "));
  644. lcd_set_cursor(0, 3);
  645. lcd_puts_P(_i("Calibration done"));////MSG_HOMEYZ_DONE c=0 r=0
  646. custom_message_state--;
  647. }
  648. }
  649. break;
  650. case CUSTOM_MSG_TYPE_F_LOAD: // If loading filament, print status
  651. lcd_print(lcd_status_message);
  652. break;
  653. case CUSTOM_MSG_TYPE_PIDCAL: // PID tuning in progress
  654. lcd_print(lcd_status_message);
  655. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0)
  656. {
  657. lcd_set_cursor(10, 3);
  658. lcd_print(itostr3(pid_cycle));
  659. lcd_print('/');
  660. lcd_print(itostr3left(pid_number_of_cycles));
  661. }
  662. break;
  663. case CUSTOM_MSG_TYPE_TEMCAL: // PINDA temp calibration in progress
  664. {
  665. char progress[4];
  666. lcd_set_cursor(0, 3);
  667. lcd_puts_P(_T(MSG_TEMP_CALIBRATION));
  668. lcd_set_cursor(12, 3);
  669. sprintf(progress, "%d/6", custom_message_state);
  670. lcd_print(progress);
  671. }
  672. break;
  673. case CUSTOM_MSG_TYPE_TEMPRE: // temp compensation preheat
  674. lcd_set_cursor(0, 3);
  675. lcd_puts_P(_i("PINDA Heating"));////MSG_PINDA_PREHEAT c=20 r=1
  676. if (custom_message_state <= PINDA_HEAT_T)
  677. {
  678. lcd_puts_P(PSTR(": "));
  679. lcd_print(custom_message_state); //seconds
  680. lcd_print(' ');
  681. }
  682. break;
  683. }
  684. }
  685. // Fill the rest of line to have nice and clean output
  686. for(int fillspace = 0; fillspace < 20; fillspace++)
  687. if ((lcd_status_message[fillspace] <= 31 ))
  688. lcd_print(' ');
  689. }
  690. void lcdui_print_status_screen(void)
  691. {
  692. //|01234567890123456789|
  693. //|N 000/000D Z000.0 |
  694. //|B 000/000D F100% |
  695. //|USB100% T0 t--:-- |
  696. //|Status line.........|
  697. //----------------------
  698. //N - nozzle temp symbol LCD_STR_THERMOMETER
  699. //B - bed temp symbol LCD_STR_BEDTEMP
  700. //F - feedrate symbol LCD_STR_FEEDRATE
  701. //t - clock symbol LCD_STR_THERMOMETER
  702. lcd_set_cursor(0, 0); //line 0
  703. //Print the hotend temperature (9 chars total)
  704. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  705. lcd_space(3); //3 spaces
  706. //Print Z-coordinate (8 chars total)
  707. lcdui_print_Z_coord();
  708. lcd_set_cursor(0, 1); //line 1
  709. //Print the Bed temperature (9 chars total)
  710. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  711. lcd_space(3); //3 spaces
  712. #ifdef PLANNER_DIAGNOSTICS
  713. //Print planner diagnostics (8 chars)
  714. lcdui_print_planner_diag();
  715. #else // PLANNER_DIAGNOSTICS
  716. //Print Feedrate (8 chars)
  717. lcdui_print_feedrate();
  718. #endif // PLANNER_DIAGNOSTICS
  719. lcd_set_cursor(0, 2); //line 2
  720. //Print SD status (7 chars)
  721. lcdui_print_percent_done();
  722. if (mmu_enabled)
  723. //Print extruder status (5 chars)
  724. lcdui_print_extruder();
  725. else if (farm_mode)
  726. //Print farm number (5 chars)
  727. lcdui_print_farm();
  728. else
  729. lcd_space(5); //5 spaces
  730. #ifdef CMD_DIAGNOSTICS
  731. //Print cmd queue diagnostics (8chars)
  732. lcdui_print_cmd_diag();
  733. #else
  734. //Print time (8chars)
  735. lcdui_print_time();
  736. #endif //CMD_DIAGNOSTICS
  737. lcd_set_cursor(0, 3); //line 3
  738. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  739. lcdui_print_status_line();
  740. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  741. }
  742. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  743. static void lcd_status_screen()
  744. {
  745. if (firstrun == 1)
  746. {
  747. firstrun = 0;
  748. if(lcd_status_message_level == 0)
  749. {
  750. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  751. lcd_finishstatus();
  752. }
  753. if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
  754. {
  755. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  756. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  757. }
  758. }
  759. if (lcd_status_update_delay)
  760. lcd_status_update_delay--;
  761. else
  762. lcd_draw_update = 1;
  763. if (lcd_draw_update)
  764. {
  765. ReInitLCD++;
  766. if (ReInitLCD == 30)
  767. {
  768. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  769. ReInitLCD = 0 ;
  770. }
  771. else
  772. {
  773. if ((ReInitLCD % 10) == 0)
  774. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  775. }
  776. lcdui_print_status_screen();
  777. if (farm_mode)
  778. {
  779. farm_timer--;
  780. if (farm_timer < 1)
  781. {
  782. farm_timer = 10;
  783. prusa_statistics(0);
  784. }
  785. switch (farm_timer)
  786. {
  787. case 8:
  788. prusa_statistics(21);
  789. break;
  790. case 5:
  791. if (IS_SD_PRINTING)
  792. prusa_statistics(20);
  793. break;
  794. }
  795. } // end of farm_mode
  796. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  797. if (lcd_commands_type != LCD_COMMAND_IDLE)
  798. lcd_commands();
  799. } // end of lcd_draw_update
  800. bool current_click = LCD_CLICKED;
  801. if (ignore_click)
  802. {
  803. if (wait_for_unclick)
  804. {
  805. if (!current_click)
  806. ignore_click = wait_for_unclick = false;
  807. else
  808. current_click = false;
  809. }
  810. else if (current_click)
  811. {
  812. lcd_quick_feedback();
  813. wait_for_unclick = true;
  814. current_click = false;
  815. }
  816. }
  817. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  818. {
  819. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  820. menu_submenu(lcd_main_menu);
  821. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  822. }
  823. #ifdef ULTIPANEL_FEEDMULTIPLY
  824. // Dead zone at 100% feedrate
  825. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  826. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  827. {
  828. lcd_encoder = 0;
  829. feedmultiply = 100;
  830. }
  831. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  832. {
  833. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  834. lcd_encoder = 0;
  835. }
  836. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  837. {
  838. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  839. lcd_encoder = 0;
  840. }
  841. else if (feedmultiply != 100)
  842. {
  843. feedmultiply += int(lcd_encoder);
  844. lcd_encoder = 0;
  845. }
  846. #endif //ULTIPANEL_FEEDMULTIPLY
  847. if (feedmultiply < 10)
  848. feedmultiply = 10;
  849. else if (feedmultiply > 999)
  850. feedmultiply = 999;
  851. }
  852. void lcd_commands()
  853. {
  854. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
  855. {
  856. if (!blocks_queued() && !homing_flag)
  857. {
  858. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20 r=1
  859. long_pause();
  860. lcd_commands_type = 0;
  861. lcd_commands_step = 0;
  862. }
  863. }
  864. #ifdef SNMM
  865. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  866. {
  867. char cmd1[30];
  868. float width = 0.4;
  869. float length = 20 - width;
  870. float extr = count_e(0.2, width, length);
  871. float extr_short_segment = count_e(0.2, width, width);
  872. 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
  873. if (lcd_commands_step == 0)
  874. {
  875. lcd_commands_step = 10;
  876. }
  877. if (lcd_commands_step == 10 && !blocks_queued() && cmd_buffer_empty())
  878. {
  879. enquecommand_P(PSTR("M107"));
  880. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  881. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  882. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  883. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  884. enquecommand_P(PSTR("T0"));
  885. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  886. enquecommand_P(PSTR("G87")); //sets calibration status
  887. enquecommand_P(PSTR("G28"));
  888. enquecommand_P(PSTR("G21")); //set units to millimeters
  889. enquecommand_P(PSTR("G90")); //use absolute coordinates
  890. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  891. enquecommand_P(PSTR("G92 E0"));
  892. enquecommand_P(PSTR("M203 E100"));
  893. enquecommand_P(PSTR("M92 E140"));
  894. lcd_commands_step = 9;
  895. }
  896. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  897. {
  898. lcd_timeoutToStatus.start();
  899. enquecommand_P(PSTR("G1 Z0.250 F7200.000"));
  900. enquecommand_P(PSTR("G1 X50.0 E80.0 F1000.0"));
  901. enquecommand_P(PSTR("G1 X160.0 E20.0 F1000.0"));
  902. enquecommand_P(PSTR("G1 Z0.200 F7200.000"));
  903. enquecommand_P(PSTR("G1 X220.0 E13 F1000.0"));
  904. enquecommand_P(PSTR("G1 X240.0 E0 F1000.0"));
  905. enquecommand_P(PSTR("G92 E0.0"));
  906. enquecommand_P(PSTR("G21"));
  907. enquecommand_P(PSTR("G90"));
  908. enquecommand_P(PSTR("M83"));
  909. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  910. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  911. enquecommand_P(PSTR("M204 S1000"));
  912. enquecommand_P(PSTR("G1 F4000"));
  913. lcd_clear();
  914. menu_goto(lcd_babystep_z, 0, false, true);
  915. lcd_commands_step = 8;
  916. }
  917. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  918. {
  919. lcd_timeoutToStatus.start();
  920. enquecommand_P(PSTR("G1 X50 Y155"));
  921. enquecommand_P(PSTR("G1 X60 Y155 E4"));
  922. enquecommand_P(PSTR("G1 F1080"));
  923. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  924. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  925. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  926. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  927. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  928. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  929. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  930. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  931. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  932. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  933. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  934. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  935. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  936. lcd_commands_step = 7;
  937. }
  938. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty())
  939. {
  940. lcd_timeoutToStatus.start();
  941. strcpy(cmd1, "G1 X50 Y35 E");
  942. strcat(cmd1, ftostr43(extr));
  943. enquecommand(cmd1);
  944. for (int i = 0; i < 4; i++) {
  945. strcpy(cmd1, "G1 X70 Y");
  946. strcat(cmd1, ftostr32(35 - i*width * 2));
  947. strcat(cmd1, " E");
  948. strcat(cmd1, ftostr43(extr));
  949. enquecommand(cmd1);
  950. strcpy(cmd1, "G1 Y");
  951. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  952. strcat(cmd1, " E");
  953. strcat(cmd1, ftostr43(extr_short_segment));
  954. enquecommand(cmd1);
  955. strcpy(cmd1, "G1 X50 Y");
  956. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  957. strcat(cmd1, " E");
  958. strcat(cmd1, ftostr43(extr));
  959. enquecommand(cmd1);
  960. strcpy(cmd1, "G1 Y");
  961. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  962. strcat(cmd1, " E");
  963. strcat(cmd1, ftostr43(extr_short_segment));
  964. enquecommand(cmd1);
  965. }
  966. lcd_commands_step = 6;
  967. }
  968. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  969. {
  970. lcd_timeoutToStatus.start();
  971. for (int i = 4; i < 8; i++) {
  972. strcpy(cmd1, "G1 X70 Y");
  973. strcat(cmd1, ftostr32(35 - i*width * 2));
  974. strcat(cmd1, " E");
  975. strcat(cmd1, ftostr43(extr));
  976. enquecommand(cmd1);
  977. strcpy(cmd1, "G1 Y");
  978. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  979. strcat(cmd1, " E");
  980. strcat(cmd1, ftostr43(extr_short_segment));
  981. enquecommand(cmd1);
  982. strcpy(cmd1, "G1 X50 Y");
  983. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  984. strcat(cmd1, " E");
  985. strcat(cmd1, ftostr43(extr));
  986. enquecommand(cmd1);
  987. strcpy(cmd1, "G1 Y");
  988. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  989. strcat(cmd1, " E");
  990. strcat(cmd1, ftostr43(extr_short_segment));
  991. enquecommand(cmd1);
  992. }
  993. lcd_commands_step = 5;
  994. }
  995. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  996. {
  997. lcd_timeoutToStatus.start();
  998. for (int i = 8; i < 12; i++) {
  999. strcpy(cmd1, "G1 X70 Y");
  1000. strcat(cmd1, ftostr32(35 - i*width * 2));
  1001. strcat(cmd1, " E");
  1002. strcat(cmd1, ftostr43(extr));
  1003. enquecommand(cmd1);
  1004. strcpy(cmd1, "G1 Y");
  1005. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1006. strcat(cmd1, " E");
  1007. strcat(cmd1, ftostr43(extr_short_segment));
  1008. enquecommand(cmd1);
  1009. strcpy(cmd1, "G1 X50 Y");
  1010. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1011. strcat(cmd1, " E");
  1012. strcat(cmd1, ftostr43(extr));
  1013. enquecommand(cmd1);
  1014. strcpy(cmd1, "G1 Y");
  1015. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1016. strcat(cmd1, " E");
  1017. strcat(cmd1, ftostr43(extr_short_segment));
  1018. enquecommand(cmd1);
  1019. }
  1020. lcd_commands_step = 4;
  1021. }
  1022. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  1023. {
  1024. lcd_timeoutToStatus.start();
  1025. for (int i = 12; i < 16; i++) {
  1026. strcpy(cmd1, "G1 X70 Y");
  1027. strcat(cmd1, ftostr32(35 - i*width * 2));
  1028. strcat(cmd1, " E");
  1029. strcat(cmd1, ftostr43(extr));
  1030. enquecommand(cmd1);
  1031. strcpy(cmd1, "G1 Y");
  1032. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1033. strcat(cmd1, " E");
  1034. strcat(cmd1, ftostr43(extr_short_segment));
  1035. enquecommand(cmd1);
  1036. strcpy(cmd1, "G1 X50 Y");
  1037. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1038. strcat(cmd1, " E");
  1039. strcat(cmd1, ftostr43(extr));
  1040. enquecommand(cmd1);
  1041. strcpy(cmd1, "G1 Y");
  1042. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1043. strcat(cmd1, " E");
  1044. strcat(cmd1, ftostr43(extr_short_segment));
  1045. enquecommand(cmd1);
  1046. }
  1047. lcd_commands_step = 3;
  1048. }
  1049. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  1050. {
  1051. lcd_timeoutToStatus.start();
  1052. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  1053. enquecommand_P(PSTR("G4 S0"));
  1054. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  1055. enquecommand_P(PSTR("G1 Z0.5 F7200.000"));
  1056. enquecommand_P(PSTR("G1 X245 Y1"));
  1057. enquecommand_P(PSTR("G1 X240 E4"));
  1058. enquecommand_P(PSTR("G1 F4000"));
  1059. enquecommand_P(PSTR("G1 X190 E2.7"));
  1060. enquecommand_P(PSTR("G1 F4600"));
  1061. enquecommand_P(PSTR("G1 X110 E2.8"));
  1062. enquecommand_P(PSTR("G1 F5200"));
  1063. enquecommand_P(PSTR("G1 X40 E3"));
  1064. enquecommand_P(PSTR("G1 E-15.0000 F5000"));
  1065. enquecommand_P(PSTR("G1 E-50.0000 F5400"));
  1066. enquecommand_P(PSTR("G1 E-15.0000 F3000"));
  1067. enquecommand_P(PSTR("G1 E-12.0000 F2000"));
  1068. enquecommand_P(PSTR("G1 F1600"));
  1069. lcd_commands_step = 2;
  1070. }
  1071. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1072. {
  1073. lcd_timeoutToStatus.start();
  1074. enquecommand_P(PSTR("G1 X0 Y1 E3.0000"));
  1075. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1076. enquecommand_P(PSTR("G1 F2000"));
  1077. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1078. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1079. enquecommand_P(PSTR("G1 F2400"));
  1080. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1081. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1082. enquecommand_P(PSTR("G1 F2400"));
  1083. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1084. enquecommand_P(PSTR("G1 X50 Y1 E-3.0000"));
  1085. enquecommand_P(PSTR("G4 S0"));
  1086. enquecommand_P(PSTR("M107"));
  1087. enquecommand_P(PSTR("M104 S0"));
  1088. enquecommand_P(PSTR("M140 S0"));
  1089. enquecommand_P(PSTR("G1 X10 Y180 F4000"));
  1090. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1091. enquecommand_P(PSTR("M84"));
  1092. lcd_commands_step = 1;
  1093. }
  1094. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1095. {
  1096. lcd_setstatuspgm(_T(WELCOME_MSG));
  1097. lcd_commands_step = 0;
  1098. lcd_commands_type = 0;
  1099. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1100. lcd_wizard(10);
  1101. }
  1102. }
  1103. }
  1104. #else //if not SNMM
  1105. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  1106. {
  1107. char cmd1[30];
  1108. uint8_t filament = 0;
  1109. float width = 0.4;
  1110. float length = 20 - width;
  1111. float extr = count_e(0.2, width, length);
  1112. float extr_short_segment = count_e(0.2, width, width);
  1113. 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
  1114. if (lcd_commands_step == 0 && !blocks_queued() && cmd_buffer_empty())
  1115. {
  1116. lcd_commands_step = 10;
  1117. }
  1118. if (lcd_commands_step == 20 && !blocks_queued() && cmd_buffer_empty())
  1119. {
  1120. filament = 0;
  1121. lcd_commands_step = 10;
  1122. }
  1123. if (lcd_commands_step == 21 && !blocks_queued() && cmd_buffer_empty())
  1124. {
  1125. filament = 1;
  1126. lcd_commands_step = 10;
  1127. }
  1128. if (lcd_commands_step == 22 && !blocks_queued() && cmd_buffer_empty())
  1129. {
  1130. filament = 2;
  1131. lcd_commands_step = 10;
  1132. }
  1133. if (lcd_commands_step == 23 && !blocks_queued() && cmd_buffer_empty())
  1134. {
  1135. filament = 3;
  1136. lcd_commands_step = 10;
  1137. }
  1138. if (lcd_commands_step == 24 && !blocks_queued() && cmd_buffer_empty())
  1139. {
  1140. filament = 4;
  1141. lcd_commands_step = 10;
  1142. }
  1143. if (lcd_commands_step == 10)
  1144. {
  1145. enquecommand_P(PSTR("M107"));
  1146. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1147. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1148. if (mmu_enabled)
  1149. {
  1150. strcpy(cmd1, "T");
  1151. strcat(cmd1, itostr3left(filament));
  1152. enquecommand(cmd1);
  1153. }
  1154. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1155. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1156. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  1157. enquecommand_P(PSTR("G28"));
  1158. enquecommand_P(PSTR("G92 E0.0"));
  1159. lcd_commands_step = 9;
  1160. }
  1161. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  1162. {
  1163. lcd_clear();
  1164. menu_depth = 0;
  1165. menu_submenu(lcd_babystep_z);
  1166. if (mmu_enabled)
  1167. {
  1168. enquecommand_P(PSTR("M83")); //intro line
  1169. enquecommand_P(PSTR("G1 Y-3.0 F1000.0")); //intro line
  1170. enquecommand_P(PSTR("G1 Z0.4 F1000.0")); //intro line
  1171. enquecommand_P(PSTR("G1 X55.0 E32.0 F1073.0")); //intro line
  1172. enquecommand_P(PSTR("G1 X5.0 E32.0 F1800.0")); //intro line
  1173. enquecommand_P(PSTR("G1 X55.0 E8.0 F2000.0")); //intro line
  1174. enquecommand_P(PSTR("G1 Z0.3 F1000.0")); //intro line
  1175. enquecommand_P(PSTR("G92 E0.0")); //intro line
  1176. enquecommand_P(PSTR("G1 X240.0 E25.0 F2200.0")); //intro line
  1177. enquecommand_P(PSTR("G1 Y-2.0 F1000.0")); //intro line
  1178. enquecommand_P(PSTR("G1 X55.0 E25 F1400.0")); //intro line
  1179. enquecommand_P(PSTR("G1 Z0.20 F1000.0")); //intro line
  1180. enquecommand_P(PSTR("G1 X5.0 E4.0 F1000.0")); //intro line
  1181. } else
  1182. {
  1183. enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); //intro line
  1184. enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); //intro line
  1185. }
  1186. lcd_commands_step = 8;
  1187. }
  1188. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty())
  1189. {
  1190. enquecommand_P(PSTR("G92 E0.0"));
  1191. enquecommand_P(PSTR("G21")); //set units to millimeters
  1192. enquecommand_P(PSTR("G90")); //use absolute coordinates
  1193. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  1194. enquecommand_P(PSTR("G1 E-1.50000 F2100.00000"));
  1195. enquecommand_P(PSTR("G1 Z5 F7200.000"));
  1196. enquecommand_P(PSTR("M204 S1000")); //set acceleration
  1197. enquecommand_P(PSTR("G1 F4000"));
  1198. lcd_commands_step = 7;
  1199. }
  1200. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  1201. {
  1202. lcd_timeoutToStatus.start();
  1203. //just opposite direction
  1204. /*enquecommand_P(PSTR("G1 X50 Y55"));
  1205. enquecommand_P(PSTR("G1 F1080"));
  1206. enquecommand_P(PSTR("G1 X200 Y55 E3.62773"));
  1207. enquecommand_P(PSTR("G1 X200 Y75 E0.49386"));
  1208. enquecommand_P(PSTR("G1 X50 Y75 E3.62773"));
  1209. enquecommand_P(PSTR("G1 X50 Y95 E0.49386"));
  1210. enquecommand_P(PSTR("G1 X200 Y95 E3.62773"));
  1211. enquecommand_P(PSTR("G1 X200 Y115 E0.49386"));
  1212. enquecommand_P(PSTR("G1 X50 Y115 E3.62773"));
  1213. enquecommand_P(PSTR("G1 X50 Y135 E0.49386"));
  1214. enquecommand_P(PSTR("G1 X200 Y135 E3.62773"));
  1215. enquecommand_P(PSTR("G1 X200 Y155 E0.66174"));
  1216. enquecommand_P(PSTR("G1 X100 Y155 E2.62773"));
  1217. enquecommand_P(PSTR("G1 X75 Y155 E2"));
  1218. enquecommand_P(PSTR("G1 X50 Y155 E2.5"));
  1219. enquecommand_P(PSTR("G1 E - 0.07500 F2100.00000"));*/
  1220. enquecommand_P(PSTR("G1 X50 Y155"));
  1221. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  1222. enquecommand_P(PSTR("G1 F1080"));
  1223. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  1224. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  1225. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  1226. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  1227. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  1228. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  1229. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  1230. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  1231. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  1232. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  1233. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  1234. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  1235. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  1236. strcpy(cmd1, "G1 X50 Y35 E");
  1237. strcat(cmd1, ftostr43(extr));
  1238. enquecommand(cmd1);
  1239. lcd_commands_step = 6;
  1240. }
  1241. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  1242. {
  1243. lcd_timeoutToStatus.start();
  1244. for (int i = 0; i < 4; i++) {
  1245. strcpy(cmd1, "G1 X70 Y");
  1246. strcat(cmd1, ftostr32(35 - i*width * 2));
  1247. strcat(cmd1, " E");
  1248. strcat(cmd1, ftostr43(extr));
  1249. enquecommand(cmd1);
  1250. strcpy(cmd1, "G1 Y");
  1251. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1252. strcat(cmd1, " E");
  1253. strcat(cmd1, ftostr43(extr_short_segment));
  1254. enquecommand(cmd1);
  1255. strcpy(cmd1, "G1 X50 Y");
  1256. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1257. strcat(cmd1, " E");
  1258. strcat(cmd1, ftostr43(extr));
  1259. enquecommand(cmd1);
  1260. strcpy(cmd1, "G1 Y");
  1261. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1262. strcat(cmd1, " E");
  1263. strcat(cmd1, ftostr43(extr_short_segment));
  1264. enquecommand(cmd1);
  1265. }
  1266. lcd_commands_step = 5;
  1267. }
  1268. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  1269. {
  1270. lcd_timeoutToStatus.start();
  1271. for (int i = 4; i < 8; i++) {
  1272. strcpy(cmd1, "G1 X70 Y");
  1273. strcat(cmd1, ftostr32(35 - i*width * 2));
  1274. strcat(cmd1, " E");
  1275. strcat(cmd1, ftostr43(extr));
  1276. enquecommand(cmd1);
  1277. strcpy(cmd1, "G1 Y");
  1278. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1279. strcat(cmd1, " E");
  1280. strcat(cmd1, ftostr43(extr_short_segment));
  1281. enquecommand(cmd1);
  1282. strcpy(cmd1, "G1 X50 Y");
  1283. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1284. strcat(cmd1, " E");
  1285. strcat(cmd1, ftostr43(extr));
  1286. enquecommand(cmd1);
  1287. strcpy(cmd1, "G1 Y");
  1288. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1289. strcat(cmd1, " E");
  1290. strcat(cmd1, ftostr43(extr_short_segment));
  1291. enquecommand(cmd1);
  1292. }
  1293. lcd_commands_step = 4;
  1294. }
  1295. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  1296. {
  1297. lcd_timeoutToStatus.start();
  1298. for (int i = 8; i < 12; i++) {
  1299. strcpy(cmd1, "G1 X70 Y");
  1300. strcat(cmd1, ftostr32(35 - i*width * 2));
  1301. strcat(cmd1, " E");
  1302. strcat(cmd1, ftostr43(extr));
  1303. enquecommand(cmd1);
  1304. strcpy(cmd1, "G1 Y");
  1305. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1306. strcat(cmd1, " E");
  1307. strcat(cmd1, ftostr43(extr_short_segment));
  1308. enquecommand(cmd1);
  1309. strcpy(cmd1, "G1 X50 Y");
  1310. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1311. strcat(cmd1, " E");
  1312. strcat(cmd1, ftostr43(extr));
  1313. enquecommand(cmd1);
  1314. strcpy(cmd1, "G1 Y");
  1315. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1316. strcat(cmd1, " E");
  1317. strcat(cmd1, ftostr43(extr_short_segment));
  1318. enquecommand(cmd1);
  1319. }
  1320. lcd_commands_step = 3;
  1321. }
  1322. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  1323. {
  1324. lcd_timeoutToStatus.start();
  1325. for (int i = 12; i < 16; i++) {
  1326. strcpy(cmd1, "G1 X70 Y");
  1327. strcat(cmd1, ftostr32(35 - i*width * 2));
  1328. strcat(cmd1, " E");
  1329. strcat(cmd1, ftostr43(extr));
  1330. enquecommand(cmd1);
  1331. strcpy(cmd1, "G1 Y");
  1332. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1333. strcat(cmd1, " E");
  1334. strcat(cmd1, ftostr43(extr_short_segment));
  1335. enquecommand(cmd1);
  1336. strcpy(cmd1, "G1 X50 Y");
  1337. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1338. strcat(cmd1, " E");
  1339. strcat(cmd1, ftostr43(extr));
  1340. enquecommand(cmd1);
  1341. strcpy(cmd1, "G1 Y");
  1342. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1343. strcat(cmd1, " E");
  1344. strcat(cmd1, ftostr43(extr_short_segment));
  1345. enquecommand(cmd1);
  1346. }
  1347. lcd_commands_step = 2;
  1348. }
  1349. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1350. {
  1351. lcd_timeoutToStatus.start();
  1352. enquecommand_P(PSTR("M107")); //turn off printer fan
  1353. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  1354. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  1355. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  1356. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  1357. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  1358. if (mmu_enabled) enquecommand_P(PSTR("M702 C")); //unload from nozzle
  1359. enquecommand_P(PSTR("M84"));// disable motors
  1360. forceMenuExpire = true; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1361. lcd_commands_step = 1;
  1362. }
  1363. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1364. {
  1365. lcd_setstatuspgm(_T(WELCOME_MSG));
  1366. lcd_commands_step = 0;
  1367. lcd_commands_type = 0;
  1368. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1369. lcd_wizard(10);
  1370. }
  1371. }
  1372. }
  1373. #endif // not SNMM
  1374. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  1375. {
  1376. if (lcd_commands_step == 0)
  1377. {
  1378. lcd_commands_step = 6;
  1379. }
  1380. if (lcd_commands_step == 1 && !blocks_queued())
  1381. {
  1382. lcd_commands_step = 0;
  1383. lcd_commands_type = 0;
  1384. lcd_setstatuspgm(_T(WELCOME_MSG));
  1385. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  1386. isPrintPaused = false;
  1387. }
  1388. if (lcd_commands_step == 2 && !blocks_queued())
  1389. {
  1390. setTargetBed(0);
  1391. enquecommand_P(PSTR("M104 S0")); //set hotend temp to 0
  1392. manage_heater();
  1393. lcd_setstatuspgm(_T(WELCOME_MSG));
  1394. cancel_heatup = false;
  1395. lcd_commands_step = 1;
  1396. }
  1397. if (lcd_commands_step == 3 && !blocks_queued())
  1398. {
  1399. // M84: Disable steppers.
  1400. enquecommand_P(PSTR("M84"));
  1401. autotempShutdown();
  1402. lcd_commands_step = 2;
  1403. }
  1404. if (lcd_commands_step == 4 && !blocks_queued())
  1405. {
  1406. lcd_setstatuspgm(_T(MSG_PLEASE_WAIT));
  1407. // G90: Absolute positioning.
  1408. enquecommand_P(PSTR("G90"));
  1409. // M83: Set extruder to relative mode.
  1410. enquecommand_P(PSTR("M83"));
  1411. #ifdef X_CANCEL_POS
  1412. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1413. #else
  1414. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  1415. #endif
  1416. lcd_ignore_click(false);
  1417. if (mmu_enabled)
  1418. lcd_commands_step = 8;
  1419. else
  1420. lcd_commands_step = 3;
  1421. }
  1422. if (lcd_commands_step == 5 && !blocks_queued())
  1423. {
  1424. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1425. // G91: Set to relative positioning.
  1426. enquecommand_P(PSTR("G91"));
  1427. // Lift up.
  1428. enquecommand_P(PSTR("G1 Z15 F1500"));
  1429. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  1430. else lcd_commands_step = 3;
  1431. }
  1432. if (lcd_commands_step == 6 && !blocks_queued())
  1433. {
  1434. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1435. cancel_heatup = true;
  1436. setTargetBed(0);
  1437. if (mmu_enabled)
  1438. setAllTargetHotends(0);
  1439. manage_heater();
  1440. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  1441. lcd_commands_step = 5;
  1442. }
  1443. if (lcd_commands_step == 7 && !blocks_queued())
  1444. {
  1445. if (mmu_enabled)
  1446. enquecommand_P(PSTR("M702 C")); //current
  1447. else
  1448. switch(snmm_stop_print_menu())
  1449. {
  1450. case 0: enquecommand_P(PSTR("M702")); break;//all
  1451. case 1: enquecommand_P(PSTR("M702 U")); break; //used
  1452. case 2: enquecommand_P(PSTR("M702 C")); break; //current
  1453. default: enquecommand_P(PSTR("M702")); break;
  1454. }
  1455. lcd_commands_step = 3;
  1456. }
  1457. if (lcd_commands_step == 8 && !blocks_queued()) { //step 8 is here for delay (going to next step after execution of all gcodes from step 4)
  1458. lcd_commands_step = 7;
  1459. }
  1460. }
  1461. if (lcd_commands_type == 3)
  1462. {
  1463. lcd_commands_type = 0;
  1464. }
  1465. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  1466. {
  1467. if (lcd_commands_step == 0) { lcd_commands_step = 6; }
  1468. if (lcd_commands_step == 1 && !blocks_queued())
  1469. {
  1470. lcd_confirm_print();
  1471. lcd_commands_step = 0;
  1472. lcd_commands_type = 0;
  1473. }
  1474. if (lcd_commands_step == 2 && !blocks_queued())
  1475. {
  1476. lcd_commands_step = 1;
  1477. }
  1478. if (lcd_commands_step == 3 && !blocks_queued())
  1479. {
  1480. lcd_commands_step = 2;
  1481. }
  1482. if (lcd_commands_step == 4 && !blocks_queued())
  1483. {
  1484. enquecommand_P(PSTR("G90"));
  1485. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1486. lcd_commands_step = 3;
  1487. }
  1488. if (lcd_commands_step == 5 && !blocks_queued())
  1489. {
  1490. lcd_commands_step = 4;
  1491. }
  1492. if (lcd_commands_step == 6 && !blocks_queued())
  1493. {
  1494. enquecommand_P(PSTR("G91"));
  1495. enquecommand_P(PSTR("G1 Z15 F1500"));
  1496. st_synchronize();
  1497. #ifdef SNMM
  1498. lcd_commands_step = 7;
  1499. #else
  1500. lcd_commands_step = 5;
  1501. #endif
  1502. }
  1503. }
  1504. if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) {
  1505. char cmd1[30];
  1506. if (lcd_commands_step == 0) {
  1507. custom_message_type = CUSTOM_MSG_TYPE_PIDCAL;
  1508. custom_message_state = 1;
  1509. lcd_draw_update = 3;
  1510. lcd_commands_step = 3;
  1511. }
  1512. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  1513. strcpy(cmd1, "M303 E0 S");
  1514. strcat(cmd1, ftostr3(pid_temp));
  1515. enquecommand(cmd1);
  1516. lcd_setstatuspgm(_i("PID cal. "));////MSG_PID_RUNNING c=20 r=1
  1517. lcd_commands_step = 2;
  1518. }
  1519. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  1520. pid_tuning_finished = false;
  1521. custom_message_state = 0;
  1522. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20 r=1
  1523. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  1524. strcpy(cmd1, "M301 P");
  1525. strcat(cmd1, ftostr32(_Kp));
  1526. strcat(cmd1, " I");
  1527. strcat(cmd1, ftostr32(_Ki));
  1528. strcat(cmd1, " D");
  1529. strcat(cmd1, ftostr32(_Kd));
  1530. enquecommand(cmd1);
  1531. enquecommand_P(PSTR("M500"));
  1532. }
  1533. else {
  1534. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  1535. }
  1536. display_time = millis();
  1537. lcd_commands_step = 1;
  1538. }
  1539. if ((lcd_commands_step == 1) && ((millis()- display_time)>2000)) { //calibration finished message
  1540. lcd_setstatuspgm(_T(WELCOME_MSG));
  1541. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  1542. pid_temp = DEFAULT_PID_TEMP;
  1543. lcd_commands_step = 0;
  1544. lcd_commands_type = 0;
  1545. }
  1546. }
  1547. }
  1548. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length) {
  1549. //returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions
  1550. float extr = extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4);
  1551. return extr;
  1552. }
  1553. void lcd_return_to_status()
  1554. {
  1555. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  1556. menu_goto(lcd_status_screen, 0, false, true);
  1557. menu_depth = 0;
  1558. }
  1559. //! @brief Pause print, disable nozzle heater, move to park position
  1560. void lcd_pause_print()
  1561. {
  1562. lcd_return_to_status();
  1563. stop_and_save_print_to_ram(0.0,0.0);
  1564. setAllTargetHotends(0);
  1565. isPrintPaused = true;
  1566. if (LCD_COMMAND_IDLE == lcd_commands_type)
  1567. {
  1568. lcd_commands_type = LCD_COMMAND_LONG_PAUSE;
  1569. }
  1570. }
  1571. float move_menu_scale;
  1572. static void lcd_move_menu_axis();
  1573. /* Menu implementation */
  1574. void lcd_preheat_farm()
  1575. {
  1576. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1577. setTargetBed(FARM_PREHEAT_HPB_TEMP);
  1578. fanSpeed = 0;
  1579. lcd_return_to_status();
  1580. setWatch(); // heater sanity check timer
  1581. }
  1582. void lcd_preheat_farm_nozzle()
  1583. {
  1584. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1585. setTargetBed(0);
  1586. fanSpeed = 0;
  1587. lcd_return_to_status();
  1588. setWatch(); // heater sanity check timer
  1589. }
  1590. void lcd_preheat_pla()
  1591. {
  1592. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  1593. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  1594. fanSpeed = 0;
  1595. lcd_return_to_status();
  1596. setWatch(); // heater sanity check timer
  1597. }
  1598. void lcd_preheat_abs()
  1599. {
  1600. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  1601. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  1602. fanSpeed = 0;
  1603. lcd_return_to_status();
  1604. setWatch(); // heater sanity check timer
  1605. }
  1606. void lcd_preheat_pp()
  1607. {
  1608. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  1609. setTargetBed(PP_PREHEAT_HPB_TEMP);
  1610. fanSpeed = 0;
  1611. lcd_return_to_status();
  1612. setWatch(); // heater sanity check timer
  1613. }
  1614. void lcd_preheat_pet()
  1615. {
  1616. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  1617. setTargetBed(PET_PREHEAT_HPB_TEMP);
  1618. fanSpeed = 0;
  1619. lcd_return_to_status();
  1620. setWatch(); // heater sanity check timer
  1621. }
  1622. void lcd_preheat_hips()
  1623. {
  1624. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  1625. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  1626. fanSpeed = 0;
  1627. lcd_return_to_status();
  1628. setWatch(); // heater sanity check timer
  1629. }
  1630. void lcd_preheat_flex()
  1631. {
  1632. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  1633. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  1634. fanSpeed = 0;
  1635. lcd_return_to_status();
  1636. setWatch(); // heater sanity check timer
  1637. }
  1638. void lcd_cooldown()
  1639. {
  1640. setAllTargetHotends(0);
  1641. setTargetBed(0);
  1642. fanSpeed = 0;
  1643. lcd_return_to_status();
  1644. }
  1645. static void lcd_menu_extruder_info()
  1646. {
  1647. //|01234567890123456789|
  1648. //|Nozzle FAN: RPM|
  1649. //|Print FAN: RPM|
  1650. //|Fil. Xd: Yd: |
  1651. //|Int: Shut: |
  1652. //----------------------
  1653. int fan_speed_RPM[2];
  1654. // Display Nozzle fan RPM
  1655. fan_speed_RPM[0] = 60*fan_speed[0];
  1656. fan_speed_RPM[1] = 60*fan_speed[1];
  1657. lcd_timeoutToStatus.stop(); //infinite timeout
  1658. lcd_printf_P(_N(
  1659. ESC_H(0,0)
  1660. "Nozzle FAN: %4d RPM\n"
  1661. "Print FAN: %4d RPM\n"
  1662. ),
  1663. fan_speed_RPM[0],
  1664. fan_speed_RPM[1]
  1665. );
  1666. #ifdef FILAMENT_SENSOR
  1667. // Display X and Y difference from Filament sensor
  1668. // Display Light intensity from Filament sensor
  1669. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  1670. // value ranges from 0(darkest) to 255(brightest).
  1671. // Display LASER shutter time from Filament sensor
  1672. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  1673. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  1674. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  1675. if (mmu_enabled == false)
  1676. {
  1677. if (!fsensor_enabled)
  1678. lcd_puts_P(_N("Filament sensor\n" "is disabled."));
  1679. else
  1680. {
  1681. if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  1682. pat9125_update();
  1683. lcd_printf_P(_N(
  1684. "Fil. Xd:%3d Yd:%3d\n"
  1685. "Int: %3d Shut: %3d"
  1686. ),
  1687. pat9125_x, pat9125_y,
  1688. pat9125_b, pat9125_s
  1689. );
  1690. }
  1691. }
  1692. #endif //FILAMENT_SENSOR
  1693. menu_back_if_clicked();
  1694. }
  1695. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1696. static void lcd_menu_fails_stats_total()
  1697. {
  1698. //01234567890123456789
  1699. //Total failures
  1700. // Power failures 000
  1701. // Filam. runouts 000
  1702. // Crash X 000 Y 000
  1703. //////////////////////
  1704. lcd_timeoutToStatus.stop(); //infinite timeout
  1705. uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
  1706. uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1707. uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
  1708. uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT);
  1709. lcd_printf_P(PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1710. menu_back_if_clicked_fb();
  1711. }
  1712. static void lcd_menu_fails_stats_print()
  1713. {
  1714. //01234567890123456789
  1715. //Last print failures
  1716. // Power failures 000
  1717. // Filam. runouts 000
  1718. // Crash X 000 Y 000
  1719. //////////////////////
  1720. lcd_timeoutToStatus.stop(); //infinite timeout
  1721. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1722. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1723. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1724. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1725. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1726. menu_back_if_clicked_fb();
  1727. }
  1728. /**
  1729. * @brief Open fail statistics menu
  1730. *
  1731. * This version of function is used, when there is filament sensor,
  1732. * power failure and crash detection.
  1733. * There are Last print and Total menu items.
  1734. */
  1735. static void lcd_menu_fails_stats()
  1736. {
  1737. MENU_BEGIN();
  1738. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1739. MENU_ITEM_SUBMENU_P(PSTR("Last print"), lcd_menu_fails_stats_print);
  1740. MENU_ITEM_SUBMENU_P(PSTR("Total"), lcd_menu_fails_stats_total);
  1741. MENU_END();
  1742. }
  1743. #elif defined(FILAMENT_SENSOR)
  1744. /**
  1745. * @brief Print last print and total filament run outs
  1746. *
  1747. * This version of function is used, when there is filament sensor,
  1748. * but no other sensors (e.g. power failure, crash detection).
  1749. *
  1750. * Example screen:
  1751. * @code
  1752. * 01234567890123456789
  1753. * Last print failures
  1754. * Filam. runouts 0
  1755. * Total failures
  1756. * Filam. runouts 5
  1757. * @endcode
  1758. */
  1759. static void lcd_menu_fails_stats()
  1760. {
  1761. lcd_timeoutToStatus.stop(); //infinite timeout
  1762. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1763. uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1764. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal);
  1765. menu_back_if_clicked();
  1766. }
  1767. #else
  1768. static void lcd_menu_fails_stats()
  1769. {
  1770. lcd_timeoutToStatus.stop(); //infinite timeout
  1771. MENU_BEGIN();
  1772. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1773. MENU_END();
  1774. }
  1775. #endif //TMC2130
  1776. #ifdef DEBUG_BUILD
  1777. #ifdef DEBUG_STACK_MONITOR
  1778. extern uint16_t SP_min;
  1779. extern char* __malloc_heap_start;
  1780. extern char* __malloc_heap_end;
  1781. #endif //DEBUG_STACK_MONITOR
  1782. static void lcd_menu_debug()
  1783. {
  1784. #ifdef DEBUG_STACK_MONITOR
  1785. lcd_printf_P(PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end);
  1786. #endif //DEBUG_STACK_MONITOR
  1787. menu_back_if_clicked_fb();
  1788. }
  1789. #endif /* DEBUG_BUILD */
  1790. static void lcd_menu_temperatures()
  1791. {
  1792. lcd_timeoutToStatus.stop(); //infinite timeout
  1793. lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01');
  1794. #ifdef AMBIENT_THERMISTOR
  1795. lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01');
  1796. #else //AMBIENT_THERMISTOR
  1797. lcd_printf_P(PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01');
  1798. #endif //AMBIENT_THERMISTOR
  1799. menu_back_if_clicked();
  1800. }
  1801. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1802. #define VOLT_DIV_R1 10000
  1803. #define VOLT_DIV_R2 2370
  1804. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1805. #define VOLT_DIV_REF 5
  1806. static void lcd_menu_voltages()
  1807. {
  1808. lcd_timeoutToStatus.stop(); //infinite timeout
  1809. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1810. // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1811. // lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
  1812. lcd_printf_P(PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
  1813. menu_back_if_clicked();
  1814. }
  1815. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1816. #ifdef TMC2130
  1817. static void lcd_menu_belt_status()
  1818. {
  1819. lcd_printf_P(PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1820. menu_back_if_clicked();
  1821. }
  1822. #endif //TMC2130
  1823. #ifdef RESUME_DEBUG
  1824. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1825. extern void restore_print_from_ram_and_continue(float e_move);
  1826. static void lcd_menu_test_save()
  1827. {
  1828. stop_and_save_print_to_ram(10, -0.8);
  1829. }
  1830. static void lcd_menu_test_restore()
  1831. {
  1832. restore_print_from_ram_and_continue(0.8);
  1833. }
  1834. #endif //RESUME_DEBUG
  1835. static void lcd_preheat_menu()
  1836. {
  1837. MENU_BEGIN();
  1838. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1839. if (farm_mode) {
  1840. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), lcd_preheat_farm);
  1841. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), lcd_preheat_farm_nozzle);
  1842. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1843. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1844. } else {
  1845. MENU_ITEM_FUNCTION_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  1846. MENU_ITEM_FUNCTION_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  1847. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1848. MENU_ITEM_FUNCTION_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  1849. MENU_ITEM_FUNCTION_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  1850. MENU_ITEM_FUNCTION_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  1851. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1852. }
  1853. MENU_END();
  1854. }
  1855. static void lcd_support_menu()
  1856. {
  1857. typedef struct
  1858. { // 22bytes total
  1859. int8_t status; // 1byte
  1860. bool is_flash_air; // 1byte
  1861. uint8_t ip[4]; // 4bytes
  1862. char ip_str[3*4+3+1]; // 16bytes
  1863. } _menu_data_t;
  1864. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1865. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1866. if (_md->status == 0 || lcd_draw_update == 2)
  1867. {
  1868. // Menu was entered or SD card status has changed (plugged in or removed).
  1869. // Initialize its status.
  1870. _md->status = 1;
  1871. _md->is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(_md->ip);
  1872. if (_md->is_flash_air)
  1873. sprintf_P(_md->ip_str, PSTR("%d.%d.%d.%d"),
  1874. _md->ip[0], _md->ip[1],
  1875. _md->ip[2], _md->ip[3]);
  1876. } else if (_md->is_flash_air &&
  1877. _md->ip[0] == 0 && _md->ip[1] == 0 &&
  1878. _md->ip[2] == 0 && _md->ip[3] == 0 &&
  1879. ++ _md->status == 16)
  1880. {
  1881. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1882. _md->status = 0;
  1883. }
  1884. MENU_BEGIN();
  1885. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1886. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1887. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1888. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1889. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1890. #endif
  1891. // Ideally this block would be optimized out by the compiler.
  1892. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1893. if (fw_string_len < 6) {
  1894. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1895. } else {
  1896. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1897. }*/
  1898. MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0
  1899. MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0
  1900. MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0
  1901. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1902. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1903. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1904. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1905. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1906. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1
  1907. MENU_ITEM_BACK_P(PSTR(__DATE__));
  1908. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1909. if (mmu_enabled)
  1910. {
  1911. MENU_ITEM_BACK_P(PSTR("MMU2 connected"));
  1912. MENU_ITEM_BACK_P(PSTR(" FW:"));
  1913. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1914. {
  1915. lcd_set_cursor(6, menu_row);
  1916. if ((mmu_version > 0) && (mmu_buildnr > 0))
  1917. lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr);
  1918. else
  1919. lcd_puts_P(PSTR("unknown"));
  1920. }
  1921. }
  1922. else
  1923. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1924. // Show the FlashAir IP address, if the card is available.
  1925. if (_md->is_flash_air) {
  1926. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1927. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:"));
  1928. ///! MENU_ITEM(back_RAM, _md->ip_str, 0);
  1929. }
  1930. #ifndef MK1BP
  1931. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1932. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1
  1933. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1
  1934. #ifdef TMC2130
  1935. MENU_ITEM_SUBMENU_P(_i("Belt status"), lcd_menu_belt_status);////MSG_MENU_BELT_STATUS c=15 r=1
  1936. #endif //TMC2130
  1937. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=15 r=1
  1938. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1939. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=15 r=1
  1940. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1941. #ifdef DEBUG_BUILD
  1942. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);
  1943. #endif /* DEBUG_BUILD */
  1944. #endif //MK1BP
  1945. MENU_END();
  1946. }
  1947. void lcd_set_fan_check() {
  1948. fans_check_enabled = !fans_check_enabled;
  1949. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1950. }
  1951. void lcd_set_filament_autoload() {
  1952. fsensor_autoload_set(!fsensor_autoload_enabled);
  1953. }
  1954. void lcd_unLoadFilament()
  1955. {
  1956. if (degHotend0() > EXTRUDE_MINTEMP) {
  1957. enquecommand_P(PSTR("M702")); //unload filament
  1958. } else {
  1959. lcd_clear();
  1960. lcd_set_cursor(0, 0);
  1961. lcd_puts_P(_T(MSG_ERROR));
  1962. lcd_set_cursor(0, 2);
  1963. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  1964. delay(2000);
  1965. lcd_clear();
  1966. }
  1967. menu_back();
  1968. }
  1969. void lcd_change_filament() {
  1970. lcd_clear();
  1971. lcd_set_cursor(0, 1);
  1972. lcd_puts_P(_i("Changing filament!"));////MSG_CHANGING_FILAMENT c=20 r=0
  1973. }
  1974. void lcd_wait_interact() {
  1975. lcd_clear();
  1976. lcd_set_cursor(0, 1);
  1977. #ifdef SNMM
  1978. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20 r=1
  1979. #else
  1980. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20 r=0
  1981. #endif
  1982. lcd_set_cursor(0, 2);
  1983. lcd_puts_P(_i("and press the knob"));////MSG_PRESS c=20 r=0
  1984. }
  1985. void lcd_change_success() {
  1986. lcd_clear();
  1987. lcd_set_cursor(0, 2);
  1988. lcd_puts_P(_i("Change success!"));////MSG_CHANGE_SUCCESS c=0 r=0
  1989. }
  1990. void lcd_loading_color() {
  1991. lcd_clear();
  1992. lcd_set_cursor(0, 0);
  1993. lcd_puts_P(_i("Loading color"));////MSG_LOADING_COLOR c=0 r=0
  1994. lcd_set_cursor(0, 2);
  1995. lcd_puts_P(_T(MSG_PLEASE_WAIT));
  1996. for (int i = 0; i < 20; i++) {
  1997. lcd_set_cursor(i, 3);
  1998. lcd_print(".");
  1999. for (int j = 0; j < 10 ; j++) {
  2000. manage_heater();
  2001. manage_inactivity(true);
  2002. delay(85);
  2003. }
  2004. }
  2005. }
  2006. void lcd_loading_filament() {
  2007. lcd_clear();
  2008. lcd_set_cursor(0, 0);
  2009. lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  2010. lcd_set_cursor(0, 2);
  2011. lcd_puts_P(_T(MSG_PLEASE_WAIT));
  2012. for (int i = 0; i < 20; i++) {
  2013. lcd_set_cursor(i, 3);
  2014. lcd_print(".");
  2015. for (int j = 0; j < 10 ; j++) {
  2016. manage_heater();
  2017. manage_inactivity(true);
  2018. #ifdef SNMM
  2019. delay(153);
  2020. #else
  2021. delay(137);
  2022. #endif
  2023. }
  2024. }
  2025. }
  2026. void lcd_alright() {
  2027. int enc_dif = 0;
  2028. int cursor_pos = 1;
  2029. lcd_clear();
  2030. lcd_set_cursor(0, 0);
  2031. lcd_puts_P(_i("Changed correctly?"));////MSG_CORRECTLY c=20 r=0
  2032. lcd_set_cursor(1, 1);
  2033. lcd_puts_P(_T(MSG_YES));
  2034. lcd_set_cursor(1, 2);
  2035. lcd_puts_P(_i("Filament not loaded"));////MSG_NOT_LOADED c=19 r=0
  2036. lcd_set_cursor(1, 3);
  2037. lcd_puts_P(_i("Color not correct"));////MSG_NOT_COLOR c=0 r=0
  2038. lcd_set_cursor(0, 1);
  2039. lcd_print(">");
  2040. enc_dif = lcd_encoder_diff;
  2041. while (lcd_change_fil_state == 0) {
  2042. manage_heater();
  2043. manage_inactivity(true);
  2044. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2045. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2046. if (enc_dif > lcd_encoder_diff ) {
  2047. cursor_pos --;
  2048. }
  2049. if (enc_dif < lcd_encoder_diff ) {
  2050. cursor_pos ++;
  2051. }
  2052. if (cursor_pos > 3) {
  2053. cursor_pos = 3;
  2054. }
  2055. if (cursor_pos < 1) {
  2056. cursor_pos = 1;
  2057. }
  2058. lcd_set_cursor(0, 1);
  2059. lcd_print(" ");
  2060. lcd_set_cursor(0, 2);
  2061. lcd_print(" ");
  2062. lcd_set_cursor(0, 3);
  2063. lcd_print(" ");
  2064. lcd_set_cursor(0, cursor_pos);
  2065. lcd_print(">");
  2066. enc_dif = lcd_encoder_diff;
  2067. delay(100);
  2068. }
  2069. }
  2070. if (lcd_clicked()) {
  2071. lcd_change_fil_state = cursor_pos;
  2072. delay(500);
  2073. }
  2074. };
  2075. lcd_clear();
  2076. lcd_return_to_status();
  2077. }
  2078. #ifdef FILAMENT_SENSOR
  2079. static void lcd_menu_AutoLoadFilament()
  2080. {
  2081. if (degHotend0() > EXTRUDE_MINTEMP)
  2082. {
  2083. uint8_t nlines;
  2084. 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
  2085. }
  2086. else
  2087. {
  2088. static_assert(sizeof(menu_data)>=sizeof(ShortTimer), "ShortTimer doesn't fit into menu_data");
  2089. ShortTimer* ptimer = (ShortTimer*)&(menu_data[0]);
  2090. if (!ptimer->running()) ptimer->start();
  2091. lcd_set_cursor(0, 0);
  2092. lcd_puts_P(_T(MSG_ERROR));
  2093. lcd_set_cursor(0, 2);
  2094. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2095. if (ptimer->expired(2000ul)) menu_back();
  2096. }
  2097. menu_back_if_clicked();
  2098. }
  2099. #endif //FILAMENT_SENSOR
  2100. static void lcd_LoadFilament()
  2101. {
  2102. if (degHotend0() > EXTRUDE_MINTEMP)
  2103. {
  2104. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  2105. loading_flag = true;
  2106. enquecommand_P(PSTR("M701")); //load filament
  2107. SERIAL_ECHOLN("Loading filament");
  2108. lcd_return_to_status();
  2109. }
  2110. else
  2111. {
  2112. lcd_clear();
  2113. lcd_set_cursor(0, 0);
  2114. lcd_puts_P(_T(MSG_ERROR));
  2115. lcd_set_cursor(0, 2);
  2116. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2117. delay(2000);
  2118. lcd_clear();
  2119. }
  2120. }
  2121. void lcd_menu_statistics()
  2122. {
  2123. if (IS_SD_PRINTING)
  2124. {
  2125. float _met = ((float)total_filament_used) / (100000.f);
  2126. int _t = (millis() - starttime) / 1000;
  2127. int _h = _t / 3600;
  2128. int _m = (_t - (_h * 3600)) / 60;
  2129. int _s = _t - ((_h * 3600) + (_m * 60));
  2130. //|01234567890123456789|
  2131. //|Filament used: |
  2132. //| 000m 00.000cm |
  2133. //|Print time: |
  2134. //| 00h 00m 00s |
  2135. //----------------------
  2136. lcd_printf_P(_N(
  2137. ESC_2J
  2138. "%S:"
  2139. ESC_H(6,1) "%8.2fm \n"
  2140. "%S :"
  2141. ESC_H(8,3) "%2dh %02dm %02d"
  2142. ),
  2143. _i("Filament used"),
  2144. _met,
  2145. _i("Print time"),
  2146. _h, _m, _s
  2147. );
  2148. menu_back_if_clicked_fb();
  2149. }
  2150. else
  2151. {
  2152. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2153. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2154. uint8_t _hours, _minutes;
  2155. uint32_t _days;
  2156. float _filament_m = (float)_filament/100;
  2157. // int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  2158. // if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  2159. _days = _time / 1440;
  2160. _hours = (_time - (_days * 1440)) / 60;
  2161. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2162. //|01234567890123456789|
  2163. //|Total filament : |
  2164. //| 000.00 m |
  2165. //|Total print time : |
  2166. //| 00d :00h :00 m |
  2167. //----------------------
  2168. lcd_printf_P(_N(
  2169. ESC_2J
  2170. "%S :"
  2171. ESC_H(9,1) "%8.2f m\n"
  2172. "%S :\n"
  2173. "%7ldd :%2hhdh :%02hhd m"
  2174. ),
  2175. _i("Total filament"),
  2176. _filament_m,
  2177. _i("Total print time"),
  2178. _days, _hours, _minutes
  2179. );
  2180. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2181. while (!lcd_clicked())
  2182. {
  2183. manage_heater();
  2184. manage_inactivity(true);
  2185. delay(100);
  2186. }
  2187. KEEPALIVE_STATE(NOT_BUSY);
  2188. lcd_quick_feedback();
  2189. menu_back();
  2190. }
  2191. }
  2192. static void _lcd_move(const char *name, int axis, int min, int max)
  2193. {
  2194. typedef struct
  2195. { // 2bytes total
  2196. bool initialized; // 1byte
  2197. bool endstopsEnabledPrevious; // 1byte
  2198. } _menu_data_t;
  2199. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2200. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2201. if (!_md->initialized)
  2202. {
  2203. _md->endstopsEnabledPrevious = enable_endstops(false);
  2204. _md->initialized = true;
  2205. }
  2206. if (lcd_encoder != 0)
  2207. {
  2208. refresh_cmd_timeout();
  2209. if (! planner_queue_full())
  2210. {
  2211. current_position[axis] += float((int)lcd_encoder) * move_menu_scale;
  2212. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2213. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2214. lcd_encoder = 0;
  2215. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2216. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  2217. lcd_draw_update = 1;
  2218. }
  2219. }
  2220. if (lcd_draw_update)
  2221. {
  2222. lcd_set_cursor(0, 1);
  2223. menu_draw_float31(' ', name, current_position[axis]);
  2224. }
  2225. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2226. if (LCD_CLICKED) menu_back();
  2227. }
  2228. static void lcd_move_e()
  2229. {
  2230. if (degHotend0() > EXTRUDE_MINTEMP)
  2231. {
  2232. if (lcd_encoder != 0)
  2233. {
  2234. refresh_cmd_timeout();
  2235. if (! planner_queue_full())
  2236. {
  2237. current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale;
  2238. lcd_encoder = 0;
  2239. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  2240. lcd_draw_update = 1;
  2241. }
  2242. }
  2243. if (lcd_draw_update)
  2244. {
  2245. lcd_set_cursor(0, 1);
  2246. menu_draw_float31(' ', PSTR("Extruder"), current_position[E_AXIS]);
  2247. }
  2248. if (LCD_CLICKED) menu_back();
  2249. }
  2250. else
  2251. {
  2252. lcd_clear();
  2253. lcd_set_cursor(0, 0);
  2254. lcd_puts_P(_T(MSG_ERROR));
  2255. lcd_set_cursor(0, 2);
  2256. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2257. delay(2000);
  2258. lcd_return_to_status();
  2259. }
  2260. }
  2261. //@brief Show measured Y distance of front calibration points from Y_MIN_POS
  2262. //If those points are detected too close to edge of reachable area, their confidence is lowered.
  2263. //This functionality is applied more often for MK2 printers.
  2264. static void lcd_menu_xyz_y_min()
  2265. {
  2266. //|01234567890123456789|
  2267. //|Y distance from min:|
  2268. //|--------------------|
  2269. //|Left: N/A |
  2270. //|Right: N/A |
  2271. //----------------------
  2272. float distanceMin[2];
  2273. count_xyz_details(distanceMin);
  2274. lcd_printf_P(_N(
  2275. ESC_H(0,0)
  2276. "%S:\n"
  2277. "%S\n"
  2278. "%S:\n"
  2279. "%S:"
  2280. ),
  2281. _i("Y distance from min"),
  2282. separator,
  2283. _i("Left"),
  2284. _i("Right")
  2285. );
  2286. for (uint8_t i = 0; i < 2; i++)
  2287. {
  2288. lcd_set_cursor(11,2+i);
  2289. if (distanceMin[i] >= 200) lcd_puts_P(_N("N/A"));
  2290. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2291. }
  2292. if (lcd_clicked())
  2293. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2294. }
  2295. //@brief Show measured axis skewness
  2296. float _deg(float rad)
  2297. {
  2298. return rad * 180 / M_PI;
  2299. }
  2300. static void lcd_menu_xyz_skew()
  2301. {
  2302. //|01234567890123456789|
  2303. //|Measured skew: N/A |
  2304. //|--------------------|
  2305. //|Slight skew: 0.12d|
  2306. //|Severe skew: 0.25d|
  2307. //----------------------
  2308. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2309. lcd_printf_P(_N(
  2310. ESC_H(0,0)
  2311. "%S:\n"
  2312. "%S\n"
  2313. "%S: %5.2f\x01\n"
  2314. "%S: %5.2f\x01"
  2315. ),
  2316. _i("Measured skew"),
  2317. separator,
  2318. _i("Slight skew"), _deg(bed_skew_angle_mild),
  2319. _i("Severe skew"), _deg(bed_skew_angle_extreme)
  2320. );
  2321. if (angleDiff < 100)
  2322. lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff));
  2323. else
  2324. lcd_puts_P(_N(ESC_H(15,0)"N/A"));
  2325. if (lcd_clicked())
  2326. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2327. }
  2328. /**
  2329. * @brief Show measured bed offset from expected position
  2330. */
  2331. static void lcd_menu_xyz_offset()
  2332. {
  2333. lcd_set_cursor(0,0);
  2334. lcd_puts_P(_i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=0 r=0
  2335. lcd_puts_at_P(0, 1, separator);
  2336. lcd_puts_at_P(0, 2, PSTR("X"));
  2337. lcd_puts_at_P(0, 3, PSTR("Y"));
  2338. float vec_x[2];
  2339. float vec_y[2];
  2340. float cntr[2];
  2341. world2machine_read_valid(vec_x, vec_y, cntr);
  2342. for (int i = 0; i < 2; i++)
  2343. {
  2344. lcd_puts_at_P(11, i + 2, PSTR(""));
  2345. lcd_print(cntr[i]);
  2346. lcd_puts_at_P((cntr[i] < 0) ? 17 : 16, i + 2, PSTR("mm"));
  2347. }
  2348. menu_back_if_clicked();
  2349. }
  2350. // Save a single axis babystep value.
  2351. void EEPROM_save_B(int pos, int* value)
  2352. {
  2353. eeprom_update_byte((unsigned char*)pos, (unsigned char)((*value) & 0xff));
  2354. eeprom_update_byte((unsigned char*)pos + 1, (unsigned char)((*value) >> 8));
  2355. }
  2356. // Read a single axis babystep value.
  2357. void EEPROM_read_B(int pos, int* value)
  2358. {
  2359. *value = (int)eeprom_read_byte((unsigned char*)pos) | (int)(eeprom_read_byte((unsigned char*)pos + 1) << 8);
  2360. }
  2361. static void lcd_move_x() {
  2362. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2363. }
  2364. static void lcd_move_y() {
  2365. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2366. }
  2367. static void lcd_move_z() {
  2368. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2369. }
  2370. /**
  2371. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2372. *
  2373. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2374. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2375. * Purpose of this function for other axis then Z is unknown.
  2376. *
  2377. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2378. * other value leads to storing Z_AXIS
  2379. * @param msg text to be displayed
  2380. */
  2381. static void _lcd_babystep(int axis, const char *msg)
  2382. {
  2383. typedef struct
  2384. { // 19bytes total
  2385. int8_t status; // 1byte
  2386. int babystepMem[3]; // 6bytes
  2387. float babystepMemMM[3]; // 12bytes
  2388. } _menu_data_t;
  2389. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2390. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2391. if (_md->status == 0)
  2392. {
  2393. // Menu was entered.
  2394. // Initialize its status.
  2395. _md->status = 1;
  2396. check_babystep();
  2397. EEPROM_read_B(EEPROM_BABYSTEP_X, &_md->babystepMem[0]);
  2398. EEPROM_read_B(EEPROM_BABYSTEP_Y, &_md->babystepMem[1]);
  2399. EEPROM_read_B(EEPROM_BABYSTEP_Z, &_md->babystepMem[2]);
  2400. // same logic as in babystep_load
  2401. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2402. _md->babystepMem[2] = 0;
  2403. _md->babystepMemMM[0] = _md->babystepMem[0]/axis_steps_per_unit[X_AXIS];
  2404. _md->babystepMemMM[1] = _md->babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  2405. _md->babystepMemMM[2] = _md->babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  2406. lcd_draw_update = 1;
  2407. //SERIAL_ECHO("Z baby step: ");
  2408. //SERIAL_ECHO(_md->babystepMem[2]);
  2409. // Wait 90 seconds before closing the live adjust dialog.
  2410. lcd_timeoutToStatus.start();
  2411. }
  2412. if (lcd_encoder != 0)
  2413. {
  2414. if (homing_flag) lcd_encoder = 0;
  2415. _md->babystepMem[axis] += (int)lcd_encoder;
  2416. if (axis == 2)
  2417. {
  2418. if (_md->babystepMem[axis] < Z_BABYSTEP_MIN) _md->babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2419. else if (_md->babystepMem[axis] > Z_BABYSTEP_MAX) _md->babystepMem[axis] = Z_BABYSTEP_MAX; //0
  2420. else
  2421. {
  2422. CRITICAL_SECTION_START
  2423. babystepsTodo[axis] += (int)lcd_encoder;
  2424. CRITICAL_SECTION_END
  2425. }
  2426. }
  2427. _md->babystepMemMM[axis] = _md->babystepMem[axis]/axis_steps_per_unit[axis];
  2428. delay(50);
  2429. lcd_encoder = 0;
  2430. lcd_draw_update = 1;
  2431. }
  2432. if (lcd_draw_update)
  2433. {
  2434. lcd_set_cursor(0, 1);
  2435. menu_draw_float13(' ', msg, _md->babystepMemMM[axis]);
  2436. }
  2437. if (LCD_CLICKED || menu_leaving)
  2438. {
  2439. // Only update the EEPROM when leaving the menu.
  2440. EEPROM_save_B(
  2441. (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  2442. &_md->babystepMem[axis]);
  2443. if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2444. }
  2445. if (LCD_CLICKED) menu_back();
  2446. }
  2447. static void lcd_babystep_z()
  2448. {
  2449. _lcd_babystep(Z_AXIS, (_i("Adjusting Z")));////MSG_BABYSTEPPING_Z c=20 r=0
  2450. }
  2451. typedef struct
  2452. { // 12bytes + 9bytes = 21bytes total
  2453. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2454. int8_t status; // 1byte
  2455. int16_t left; // 2byte
  2456. int16_t right; // 2byte
  2457. int16_t front; // 2byte
  2458. int16_t rear; // 2byte
  2459. } _menu_data_adjust_bed_t;
  2460. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2461. void lcd_adjust_bed_reset(void)
  2462. {
  2463. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2464. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2465. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2466. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2467. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2468. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2469. _md->status = 0;
  2470. }
  2471. #define BED_ADJUSTMENT_UM_MAX 50
  2472. void lcd_adjust_bed(void)
  2473. {
  2474. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2475. if (_md->status == 0)
  2476. {
  2477. // Menu was entered.
  2478. _md->left = 0;
  2479. _md->right = 0;
  2480. _md->front = 0;
  2481. _md->rear = 0;
  2482. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2483. {
  2484. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2485. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2486. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2487. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2488. }
  2489. _md->status = 1;
  2490. }
  2491. MENU_BEGIN();
  2492. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2493. if (((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving)
  2494. {
  2495. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2496. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2497. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2498. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2499. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2500. }
  2501. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2502. MENU_ITEM_EDIT_int3_P(_i("Left side [um]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1
  2503. MENU_ITEM_EDIT_int3_P(_i("Right side[um]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1
  2504. MENU_ITEM_EDIT_int3_P(_i("Front side[um]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1
  2505. MENU_ITEM_EDIT_int3_P(_i("Rear side [um]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1
  2506. MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0
  2507. MENU_END();
  2508. }
  2509. void pid_extruder()
  2510. {
  2511. lcd_clear();
  2512. lcd_set_cursor(1, 0);
  2513. lcd_puts_P(_i("Set temperature:"));////MSG_SET_TEMPERATURE c=19 r=1
  2514. pid_temp += int(lcd_encoder);
  2515. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2516. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2517. lcd_encoder = 0;
  2518. lcd_set_cursor(1, 2);
  2519. lcd_print(ftostr3(pid_temp));
  2520. if (lcd_clicked()) {
  2521. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2522. lcd_return_to_status();
  2523. lcd_update(2);
  2524. }
  2525. }
  2526. /*
  2527. void lcd_adjust_z() {
  2528. int enc_dif = 0;
  2529. int cursor_pos = 1;
  2530. int fsm = 0;
  2531. lcd_clear();
  2532. lcd_set_cursor(0, 0);
  2533. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ c=0 r=0
  2534. lcd_set_cursor(1, 1);
  2535. lcd_puts_P(_T(MSG_YES));
  2536. lcd_set_cursor(1, 2);
  2537. lcd_puts_P(_T(MSG_NO));
  2538. lcd_set_cursor(0, 1);
  2539. lcd_print(">");
  2540. enc_dif = lcd_encoder_diff;
  2541. while (fsm == 0) {
  2542. manage_heater();
  2543. manage_inactivity(true);
  2544. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2545. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2546. if (enc_dif > lcd_encoder_diff ) {
  2547. cursor_pos --;
  2548. }
  2549. if (enc_dif < lcd_encoder_diff ) {
  2550. cursor_pos ++;
  2551. }
  2552. if (cursor_pos > 2) {
  2553. cursor_pos = 2;
  2554. }
  2555. if (cursor_pos < 1) {
  2556. cursor_pos = 1;
  2557. }
  2558. lcd_set_cursor(0, 1);
  2559. lcd_print(" ");
  2560. lcd_set_cursor(0, 2);
  2561. lcd_print(" ");
  2562. lcd_set_cursor(0, cursor_pos);
  2563. lcd_print(">");
  2564. enc_dif = lcd_encoder_diff;
  2565. delay(100);
  2566. }
  2567. }
  2568. if (lcd_clicked()) {
  2569. fsm = cursor_pos;
  2570. if (fsm == 1) {
  2571. int babystepLoadZ = 0;
  2572. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2573. CRITICAL_SECTION_START
  2574. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2575. CRITICAL_SECTION_END
  2576. } else {
  2577. int zero = 0;
  2578. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2579. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2580. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2581. }
  2582. delay(500);
  2583. }
  2584. };
  2585. lcd_clear();
  2586. lcd_return_to_status();
  2587. }*/
  2588. bool lcd_wait_for_pinda(float temp) {
  2589. lcd_set_custom_characters_degree();
  2590. setAllTargetHotends(0);
  2591. setTargetBed(0);
  2592. LongTimer pinda_timeout;
  2593. pinda_timeout.start();
  2594. bool target_temp_reached = true;
  2595. while (current_temperature_pinda > temp){
  2596. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2597. lcd_set_cursor(0, 4);
  2598. lcd_print(LCD_STR_THERMOMETER[0]);
  2599. lcd_print(ftostr3(current_temperature_pinda));
  2600. lcd_print("/");
  2601. lcd_print(ftostr3(temp));
  2602. lcd_print(LCD_STR_DEGREE);
  2603. delay_keep_alive(1000);
  2604. serialecho_temperatures();
  2605. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2606. target_temp_reached = false;
  2607. break;
  2608. }
  2609. }
  2610. lcd_set_custom_characters_arrows();
  2611. lcd_update_enable(true);
  2612. return target_temp_reached;
  2613. }
  2614. void lcd_wait_for_heater() {
  2615. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2616. lcd_set_degree();
  2617. lcd_set_cursor(0, 4);
  2618. lcd_print(LCD_STR_THERMOMETER[0]);
  2619. lcd_print(ftostr3(degHotend(active_extruder)));
  2620. lcd_print("/");
  2621. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2622. lcd_print(LCD_STR_DEGREE);
  2623. }
  2624. void lcd_wait_for_cool_down() {
  2625. lcd_set_custom_characters_degree();
  2626. setAllTargetHotends(0);
  2627. setTargetBed(0);
  2628. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2629. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2630. lcd_set_cursor(0, 4);
  2631. lcd_print(LCD_STR_THERMOMETER[0]);
  2632. lcd_print(ftostr3(degHotend(0)));
  2633. lcd_print("/0");
  2634. lcd_print(LCD_STR_DEGREE);
  2635. lcd_set_cursor(9, 4);
  2636. lcd_print(LCD_STR_BEDTEMP[0]);
  2637. lcd_print(ftostr3(degBed()));
  2638. lcd_print("/0");
  2639. lcd_print(LCD_STR_DEGREE);
  2640. lcd_set_custom_characters();
  2641. delay_keep_alive(1000);
  2642. serialecho_temperatures();
  2643. }
  2644. lcd_set_custom_characters_arrows();
  2645. lcd_update_enable(true);
  2646. }
  2647. // Lets the user move the Z carriage up to the end stoppers.
  2648. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2649. // Otherwise the Z calibration is not changed and false is returned.
  2650. #ifndef TMC2130
  2651. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2652. {
  2653. bool clean_nozzle_asked = false;
  2654. // 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.
  2655. current_position[Z_AXIS] = 0;
  2656. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2657. // Until confirmed by the confirmation dialog.
  2658. for (;;) {
  2659. unsigned long previous_millis_cmd = millis();
  2660. const char *msg = only_z ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.") : _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////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2661. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2662. const bool multi_screen = msg_next != NULL;
  2663. unsigned long previous_millis_msg = millis();
  2664. // Until the user finishes the z up movement.
  2665. lcd_encoder_diff = 0;
  2666. lcd_encoder = 0;
  2667. for (;;) {
  2668. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2669. // goto canceled;
  2670. manage_heater();
  2671. manage_inactivity(true);
  2672. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2673. delay(50);
  2674. previous_millis_cmd = millis();
  2675. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2676. lcd_encoder_diff = 0;
  2677. if (! planner_queue_full()) {
  2678. // Only move up, whatever direction the user rotates the encoder.
  2679. current_position[Z_AXIS] += fabs(lcd_encoder);
  2680. lcd_encoder = 0;
  2681. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS] / 60, active_extruder);
  2682. }
  2683. }
  2684. if (lcd_clicked()) {
  2685. // Abort a move if in progress.
  2686. planner_abort_hard();
  2687. while (lcd_clicked()) ;
  2688. delay(10);
  2689. while (lcd_clicked()) ;
  2690. break;
  2691. }
  2692. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2693. if (msg_next == NULL)
  2694. msg_next = msg;
  2695. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2696. previous_millis_msg = millis();
  2697. }
  2698. }
  2699. if (! clean_nozzle_asked) {
  2700. lcd_show_fullscreen_message_and_wait_P(_T(MSG_CONFIRM_NOZZLE_CLEAN));
  2701. clean_nozzle_asked = true;
  2702. }
  2703. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2704. 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
  2705. if (result == -1)
  2706. goto canceled;
  2707. else if (result == 1)
  2708. goto calibrated;
  2709. // otherwise perform another round of the Z up dialog.
  2710. }
  2711. calibrated:
  2712. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2713. // during the search for the induction points.
  2714. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2715. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2716. if(only_z){
  2717. lcd_display_message_fullscreen_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1));
  2718. lcd_set_cursor(0, 3);
  2719. lcd_print(1);
  2720. lcd_puts_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2));
  2721. }else{
  2722. //lcd_show_fullscreen_message_and_wait_P(_T(MSG_PAPER));
  2723. lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1));
  2724. lcd_set_cursor(0, 2);
  2725. lcd_print(1);
  2726. lcd_puts_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2));
  2727. }
  2728. return true;
  2729. canceled:
  2730. return false;
  2731. }
  2732. #endif // TMC2130
  2733. static inline bool pgm_is_whitespace(const char *c_addr)
  2734. {
  2735. const char c = pgm_read_byte(c_addr);
  2736. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2737. }
  2738. static inline bool pgm_is_interpunction(const char *c_addr)
  2739. {
  2740. const char c = pgm_read_byte(c_addr);
  2741. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2742. }
  2743. /**
  2744. * @brief show full screen message
  2745. *
  2746. * This function is non-blocking
  2747. * @param msg message to be displayed from PROGMEM
  2748. * @param nlines
  2749. * @return rest of the text (to be displayed on next page)
  2750. */
  2751. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2752. {
  2753. lcd_set_cursor(0, 0);
  2754. const char *msgend = msg;
  2755. uint8_t row = 0;
  2756. bool multi_screen = false;
  2757. for (; row < 4; ++ row) {
  2758. while (pgm_is_whitespace(msg))
  2759. ++ msg;
  2760. if (pgm_read_byte(msg) == 0)
  2761. // End of the message.
  2762. break;
  2763. lcd_set_cursor(0, row);
  2764. uint8_t linelen = min(strlen_P(msg), 20);
  2765. const char *msgend2 = msg + linelen;
  2766. msgend = msgend2;
  2767. if (row == 3 && linelen == 20) {
  2768. // Last line of the display, full line shall be displayed.
  2769. // Find out, whether this message will be split into multiple screens.
  2770. while (pgm_is_whitespace(msgend))
  2771. ++ msgend;
  2772. multi_screen = pgm_read_byte(msgend) != 0;
  2773. if (multi_screen)
  2774. msgend = (msgend2 -= 2);
  2775. }
  2776. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2777. // Splitting a word. Find the start of the current word.
  2778. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2779. -- msgend;
  2780. if (msgend == msg)
  2781. // Found a single long word, which cannot be split. Just cut it.
  2782. msgend = msgend2;
  2783. }
  2784. for (; msg < msgend; ++ msg) {
  2785. char c = char(pgm_read_byte(msg));
  2786. if (c == '~')
  2787. c = ' ';
  2788. lcd_print(c);
  2789. }
  2790. }
  2791. if (multi_screen) {
  2792. // Display the "next screen" indicator character.
  2793. // lcd_set_custom_characters_arrows();
  2794. lcd_set_custom_characters_nextpage();
  2795. lcd_set_cursor(19, 3);
  2796. // Display the down arrow.
  2797. lcd_print(char(1));
  2798. }
  2799. nlines = row;
  2800. return multi_screen ? msgend : NULL;
  2801. }
  2802. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2803. {
  2804. // Disable update of the screen by the usual lcd_update(0) routine.
  2805. lcd_update_enable(false);
  2806. lcd_clear();
  2807. // uint8_t nlines;
  2808. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  2809. }
  2810. const char* lcd_display_message_fullscreen_P(const char *msg)
  2811. {
  2812. uint8_t nlines;
  2813. return lcd_display_message_fullscreen_P(msg, nlines);
  2814. }
  2815. /**
  2816. * @brief show full screen message and wait
  2817. *
  2818. * This function is blocking.
  2819. * @param msg message to be displayed from PROGMEM
  2820. */
  2821. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2822. {
  2823. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2824. bool multi_screen = msg_next != NULL;
  2825. lcd_set_custom_characters_nextpage();
  2826. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2827. // Until confirmed by a button click.
  2828. for (;;) {
  2829. if (!multi_screen) {
  2830. lcd_set_cursor(19, 3);
  2831. // Display the confirm char.
  2832. lcd_print(char(2));
  2833. }
  2834. // Wait for 5 seconds before displaying the next text.
  2835. for (uint8_t i = 0; i < 100; ++ i) {
  2836. delay_keep_alive(50);
  2837. if (lcd_clicked()) {
  2838. if (msg_next == NULL) {
  2839. KEEPALIVE_STATE(IN_HANDLER);
  2840. lcd_set_custom_characters();
  2841. lcd_update_enable(true);
  2842. lcd_update(2);
  2843. return;
  2844. }
  2845. else {
  2846. break;
  2847. }
  2848. }
  2849. }
  2850. if (multi_screen) {
  2851. if (msg_next == NULL)
  2852. msg_next = msg;
  2853. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2854. if (msg_next == NULL) {
  2855. lcd_set_cursor(19, 3);
  2856. // Display the confirm char.
  2857. lcd_print(char(2));
  2858. }
  2859. }
  2860. }
  2861. }
  2862. void lcd_wait_for_click()
  2863. {
  2864. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2865. for (;;) {
  2866. manage_heater();
  2867. manage_inactivity(true);
  2868. if (lcd_clicked()) {
  2869. KEEPALIVE_STATE(IN_HANDLER);
  2870. return;
  2871. }
  2872. }
  2873. }
  2874. 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)
  2875. {
  2876. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2877. bool multi_screen = msg_next != NULL;
  2878. bool yes = default_yes ? true : false;
  2879. // Wait for user confirmation or a timeout.
  2880. unsigned long previous_millis_cmd = millis();
  2881. int8_t enc_dif = lcd_encoder_diff;
  2882. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2883. for (;;) {
  2884. for (uint8_t i = 0; i < 100; ++i) {
  2885. delay_keep_alive(50);
  2886. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2887. return -1;
  2888. manage_heater();
  2889. manage_inactivity(true);
  2890. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2891. if (msg_next == NULL) {
  2892. lcd_set_cursor(0, 3);
  2893. if (enc_dif < lcd_encoder_diff && yes) {
  2894. lcd_puts_P((PSTR(" ")));
  2895. lcd_set_cursor(7, 3);
  2896. lcd_puts_P((PSTR(">")));
  2897. yes = false;
  2898. }
  2899. else if (enc_dif > lcd_encoder_diff && !yes) {
  2900. lcd_puts_P((PSTR(">")));
  2901. lcd_set_cursor(7, 3);
  2902. lcd_puts_P((PSTR(" ")));
  2903. yes = true;
  2904. }
  2905. enc_dif = lcd_encoder_diff;
  2906. }
  2907. else {
  2908. break; //turning knob skips waiting loop
  2909. }
  2910. }
  2911. if (lcd_clicked()) {
  2912. if (msg_next == NULL) {
  2913. //KEEPALIVE_STATE(IN_HANDLER);
  2914. lcd_set_custom_characters();
  2915. return yes;
  2916. }
  2917. else break;
  2918. }
  2919. }
  2920. if (multi_screen) {
  2921. if (msg_next == NULL) {
  2922. msg_next = msg;
  2923. }
  2924. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2925. }
  2926. if (msg_next == NULL) {
  2927. lcd_set_cursor(0, 3);
  2928. if (yes) lcd_puts_P(PSTR(">"));
  2929. lcd_set_cursor(1, 3);
  2930. lcd_puts_P(_T(MSG_YES));
  2931. lcd_set_cursor(7, 3);
  2932. if (!yes) lcd_puts_P(PSTR(">"));
  2933. lcd_set_cursor(8, 3);
  2934. lcd_puts_P(_T(MSG_NO));
  2935. }
  2936. }
  2937. }
  2938. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2939. {
  2940. lcd_display_message_fullscreen_P(msg);
  2941. if (default_yes) {
  2942. lcd_set_cursor(0, 2);
  2943. lcd_puts_P(PSTR(">"));
  2944. lcd_puts_P(_T(MSG_YES));
  2945. lcd_set_cursor(1, 3);
  2946. lcd_puts_P(_T(MSG_NO));
  2947. }
  2948. else {
  2949. lcd_set_cursor(1, 2);
  2950. lcd_puts_P(_T(MSG_YES));
  2951. lcd_set_cursor(0, 3);
  2952. lcd_puts_P(PSTR(">"));
  2953. lcd_puts_P(_T(MSG_NO));
  2954. }
  2955. bool yes = default_yes ? true : false;
  2956. // Wait for user confirmation or a timeout.
  2957. unsigned long previous_millis_cmd = millis();
  2958. int8_t enc_dif = lcd_encoder_diff;
  2959. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2960. for (;;) {
  2961. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2962. return -1;
  2963. manage_heater();
  2964. manage_inactivity(true);
  2965. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2966. lcd_set_cursor(0, 2);
  2967. if (enc_dif < lcd_encoder_diff && yes) {
  2968. lcd_puts_P((PSTR(" ")));
  2969. lcd_set_cursor(0, 3);
  2970. lcd_puts_P((PSTR(">")));
  2971. yes = false;
  2972. }
  2973. else if (enc_dif > lcd_encoder_diff && !yes) {
  2974. lcd_puts_P((PSTR(">")));
  2975. lcd_set_cursor(0, 3);
  2976. lcd_puts_P((PSTR(" ")));
  2977. yes = true;
  2978. }
  2979. enc_dif = lcd_encoder_diff;
  2980. }
  2981. if (lcd_clicked()) {
  2982. KEEPALIVE_STATE(IN_HANDLER);
  2983. return yes;
  2984. }
  2985. }
  2986. }
  2987. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2988. {
  2989. const char *msg = NULL;
  2990. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2991. 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=8
  2992. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2993. if (point_too_far_mask == 0)
  2994. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2995. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2996. // Only the center point or all the three front points.
  2997. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  2998. else if ((point_too_far_mask & 1) == 0)
  2999. // The right and maybe the center point out of reach.
  3000. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  3001. else
  3002. // The left and maybe the center point out of reach.
  3003. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3004. lcd_show_fullscreen_message_and_wait_P(msg);
  3005. } else {
  3006. if (point_too_far_mask != 0) {
  3007. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3008. // Only the center point or all the three front points.
  3009. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3010. else if ((point_too_far_mask & 1) == 0)
  3011. // The right and maybe the center point out of reach.
  3012. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3013. else
  3014. // The left and maybe the center point out of reach.
  3015. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3016. lcd_show_fullscreen_message_and_wait_P(msg);
  3017. }
  3018. if (point_too_far_mask == 0 || result > 0) {
  3019. switch (result) {
  3020. default:
  3021. // should not happen
  3022. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3023. break;
  3024. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3025. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3026. break;
  3027. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3028. 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
  3029. break;
  3030. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3031. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3032. break;
  3033. }
  3034. lcd_show_fullscreen_message_and_wait_P(msg);
  3035. }
  3036. }
  3037. }
  3038. void lcd_temp_cal_show_result(bool result) {
  3039. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  3040. disable_x();
  3041. disable_y();
  3042. disable_z();
  3043. disable_e0();
  3044. disable_e1();
  3045. disable_e2();
  3046. setTargetBed(0); //set bed target temperature back to 0
  3047. if (result == true) {
  3048. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3049. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3050. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3051. temp_cal_active = true;
  3052. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3053. }
  3054. else {
  3055. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3056. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3057. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3058. temp_cal_active = false;
  3059. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3060. }
  3061. lcd_update_enable(true);
  3062. lcd_update(2);
  3063. }
  3064. static void lcd_show_end_stops() {
  3065. lcd_set_cursor(0, 0);
  3066. lcd_puts_P((PSTR("End stops diag")));
  3067. lcd_set_cursor(0, 1);
  3068. lcd_puts_P((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3069. lcd_set_cursor(0, 2);
  3070. lcd_puts_P((READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3071. lcd_set_cursor(0, 3);
  3072. lcd_puts_P((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3073. }
  3074. #ifndef TMC2130
  3075. static void menu_show_end_stops() {
  3076. lcd_show_end_stops();
  3077. if (LCD_CLICKED) menu_back();
  3078. }
  3079. #endif // not defined TMC2130
  3080. // Lets the user move the Z carriage up to the end stoppers.
  3081. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3082. // Otherwise the Z calibration is not changed and false is returned.
  3083. void lcd_diag_show_end_stops()
  3084. {
  3085. lcd_clear();
  3086. for (;;) {
  3087. manage_heater();
  3088. manage_inactivity(true);
  3089. lcd_show_end_stops();
  3090. if (lcd_clicked()) {
  3091. break;
  3092. }
  3093. }
  3094. lcd_clear();
  3095. lcd_return_to_status();
  3096. }
  3097. #ifdef TMC2130
  3098. static void lcd_show_pinda_state()
  3099. {
  3100. lcd_set_cursor(0, 0);
  3101. lcd_puts_P((PSTR("P.I.N.D.A. state")));
  3102. lcd_set_cursor(0, 2);
  3103. lcd_puts_P(READ(Z_MIN_PIN)?(PSTR("Z1 (LED off)")):(PSTR("Z0 (LED on) "))); // !!! both strings must have same length (due to dynamic refreshing)
  3104. }
  3105. static void menu_show_pinda_state()
  3106. {
  3107. lcd_timeoutToStatus.stop();
  3108. lcd_show_pinda_state();
  3109. if(LCD_CLICKED)
  3110. {
  3111. lcd_timeoutToStatus.start();
  3112. menu_back();
  3113. }
  3114. }
  3115. #endif // defined TMC2130
  3116. void prusa_statistics(int _message, uint8_t _fil_nr) {
  3117. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3118. return;
  3119. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3120. switch (_message)
  3121. {
  3122. case 0: // default message
  3123. if (IS_SD_PRINTING)
  3124. {
  3125. SERIAL_ECHO("{");
  3126. prusa_stat_printerstatus(4);
  3127. prusa_stat_farm_number();
  3128. prusa_stat_printinfo();
  3129. SERIAL_ECHOLN("}");
  3130. status_number = 4;
  3131. }
  3132. else
  3133. {
  3134. SERIAL_ECHO("{");
  3135. prusa_stat_printerstatus(1);
  3136. prusa_stat_farm_number();
  3137. SERIAL_ECHOLN("}");
  3138. status_number = 1;
  3139. }
  3140. break;
  3141. case 1: // 1 heating
  3142. farm_status = 2;
  3143. SERIAL_ECHO("{");
  3144. prusa_stat_printerstatus(2);
  3145. prusa_stat_farm_number();
  3146. SERIAL_ECHOLN("}");
  3147. status_number = 2;
  3148. farm_timer = 1;
  3149. break;
  3150. case 2: // heating done
  3151. farm_status = 3;
  3152. SERIAL_ECHO("{");
  3153. prusa_stat_printerstatus(3);
  3154. prusa_stat_farm_number();
  3155. SERIAL_ECHOLN("}");
  3156. status_number = 3;
  3157. farm_timer = 1;
  3158. if (IS_SD_PRINTING)
  3159. {
  3160. farm_status = 4;
  3161. SERIAL_ECHO("{");
  3162. prusa_stat_printerstatus(4);
  3163. prusa_stat_farm_number();
  3164. SERIAL_ECHOLN("}");
  3165. status_number = 4;
  3166. }
  3167. else
  3168. {
  3169. SERIAL_ECHO("{");
  3170. prusa_stat_printerstatus(3);
  3171. prusa_stat_farm_number();
  3172. SERIAL_ECHOLN("}");
  3173. status_number = 3;
  3174. }
  3175. farm_timer = 1;
  3176. break;
  3177. case 3: // filament change
  3178. break;
  3179. case 4: // print succesfull
  3180. SERIAL_ECHO("{[RES:1][FIL:");
  3181. MYSERIAL.print(int(_fil_nr));
  3182. SERIAL_ECHO("]");
  3183. prusa_stat_printerstatus(status_number);
  3184. prusa_stat_farm_number();
  3185. SERIAL_ECHOLN("}");
  3186. farm_timer = 2;
  3187. break;
  3188. case 5: // print not succesfull
  3189. SERIAL_ECHO("{[RES:0][FIL:");
  3190. MYSERIAL.print(int(_fil_nr));
  3191. SERIAL_ECHO("]");
  3192. prusa_stat_printerstatus(status_number);
  3193. prusa_stat_farm_number();
  3194. SERIAL_ECHOLN("}");
  3195. farm_timer = 2;
  3196. break;
  3197. case 6: // print done
  3198. SERIAL_ECHO("{[PRN:8]");
  3199. prusa_stat_farm_number();
  3200. SERIAL_ECHOLN("}");
  3201. status_number = 8;
  3202. farm_timer = 2;
  3203. break;
  3204. case 7: // print done - stopped
  3205. SERIAL_ECHO("{[PRN:9]");
  3206. prusa_stat_farm_number();
  3207. SERIAL_ECHOLN("}");
  3208. status_number = 9;
  3209. farm_timer = 2;
  3210. break;
  3211. case 8: // printer started
  3212. SERIAL_ECHO("{[PRN:0][PFN:");
  3213. status_number = 0;
  3214. SERIAL_ECHO(farm_no);
  3215. SERIAL_ECHOLN("]}");
  3216. farm_timer = 2;
  3217. break;
  3218. case 20: // echo farm no
  3219. SERIAL_ECHO("{");
  3220. prusa_stat_printerstatus(status_number);
  3221. prusa_stat_farm_number();
  3222. SERIAL_ECHOLN("}");
  3223. farm_timer = 4;
  3224. break;
  3225. case 21: // temperatures
  3226. SERIAL_ECHO("{");
  3227. prusa_stat_temperatures();
  3228. prusa_stat_farm_number();
  3229. prusa_stat_printerstatus(status_number);
  3230. SERIAL_ECHOLN("}");
  3231. break;
  3232. case 22: // waiting for filament change
  3233. SERIAL_ECHO("{[PRN:5]");
  3234. prusa_stat_farm_number();
  3235. SERIAL_ECHOLN("}");
  3236. status_number = 5;
  3237. break;
  3238. case 90: // Error - Thermal Runaway
  3239. SERIAL_ECHO("{[ERR:1]");
  3240. prusa_stat_farm_number();
  3241. SERIAL_ECHOLN("}");
  3242. break;
  3243. case 91: // Error - Thermal Runaway Preheat
  3244. SERIAL_ECHO("{[ERR:2]");
  3245. prusa_stat_farm_number();
  3246. SERIAL_ECHOLN("}");
  3247. break;
  3248. case 92: // Error - Min temp
  3249. SERIAL_ECHO("{[ERR:3]");
  3250. prusa_stat_farm_number();
  3251. SERIAL_ECHOLN("}");
  3252. break;
  3253. case 93: // Error - Max temp
  3254. SERIAL_ECHO("{[ERR:4]");
  3255. prusa_stat_farm_number();
  3256. SERIAL_ECHOLN("}");
  3257. break;
  3258. case 99: // heartbeat
  3259. SERIAL_ECHO("{[PRN:99]");
  3260. prusa_stat_temperatures();
  3261. SERIAL_ECHO("[PFN:");
  3262. SERIAL_ECHO(farm_no);
  3263. SERIAL_ECHO("]");
  3264. SERIAL_ECHOLN("}");
  3265. break;
  3266. }
  3267. }
  3268. static void prusa_stat_printerstatus(int _status)
  3269. {
  3270. SERIAL_ECHO("[PRN:");
  3271. SERIAL_ECHO(_status);
  3272. SERIAL_ECHO("]");
  3273. }
  3274. static void prusa_stat_farm_number() {
  3275. SERIAL_ECHO("[PFN:");
  3276. SERIAL_ECHO(farm_no);
  3277. SERIAL_ECHO("]");
  3278. }
  3279. static void prusa_stat_temperatures()
  3280. {
  3281. SERIAL_ECHO("[ST0:");
  3282. SERIAL_ECHO(target_temperature[0]);
  3283. SERIAL_ECHO("][STB:");
  3284. SERIAL_ECHO(target_temperature_bed);
  3285. SERIAL_ECHO("][AT0:");
  3286. SERIAL_ECHO(current_temperature[0]);
  3287. SERIAL_ECHO("][ATB:");
  3288. SERIAL_ECHO(current_temperature_bed);
  3289. SERIAL_ECHO("]");
  3290. }
  3291. static void prusa_stat_printinfo()
  3292. {
  3293. SERIAL_ECHO("[TFU:");
  3294. SERIAL_ECHO(total_filament_used);
  3295. SERIAL_ECHO("][PCD:");
  3296. SERIAL_ECHO(itostr3(card.percentDone()));
  3297. SERIAL_ECHO("][FEM:");
  3298. SERIAL_ECHO(itostr3(feedmultiply));
  3299. SERIAL_ECHO("][FNM:");
  3300. SERIAL_ECHO(longFilenameOLD);
  3301. SERIAL_ECHO("][TIM:");
  3302. if (starttime != 0)
  3303. {
  3304. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  3305. }
  3306. else
  3307. {
  3308. SERIAL_ECHO(0);
  3309. }
  3310. SERIAL_ECHO("][FWR:");
  3311. SERIAL_ECHO(FW_VERSION);
  3312. SERIAL_ECHO("]");
  3313. }
  3314. /*
  3315. void lcd_pick_babystep(){
  3316. int enc_dif = 0;
  3317. int cursor_pos = 1;
  3318. int fsm = 0;
  3319. lcd_clear();
  3320. lcd_set_cursor(0, 0);
  3321. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z c=0 r=0
  3322. lcd_set_cursor(3, 2);
  3323. lcd_print("1");
  3324. lcd_set_cursor(3, 3);
  3325. lcd_print("2");
  3326. lcd_set_cursor(12, 2);
  3327. lcd_print("3");
  3328. lcd_set_cursor(12, 3);
  3329. lcd_print("4");
  3330. lcd_set_cursor(1, 2);
  3331. lcd_print(">");
  3332. enc_dif = lcd_encoder_diff;
  3333. while (fsm == 0) {
  3334. manage_heater();
  3335. manage_inactivity(true);
  3336. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3337. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3338. if (enc_dif > lcd_encoder_diff ) {
  3339. cursor_pos --;
  3340. }
  3341. if (enc_dif < lcd_encoder_diff ) {
  3342. cursor_pos ++;
  3343. }
  3344. if (cursor_pos > 4) {
  3345. cursor_pos = 4;
  3346. }
  3347. if (cursor_pos < 1) {
  3348. cursor_pos = 1;
  3349. }
  3350. lcd_set_cursor(1, 2);
  3351. lcd_print(" ");
  3352. lcd_set_cursor(1, 3);
  3353. lcd_print(" ");
  3354. lcd_set_cursor(10, 2);
  3355. lcd_print(" ");
  3356. lcd_set_cursor(10, 3);
  3357. lcd_print(" ");
  3358. if (cursor_pos < 3) {
  3359. lcd_set_cursor(1, cursor_pos+1);
  3360. lcd_print(">");
  3361. }else{
  3362. lcd_set_cursor(10, cursor_pos-1);
  3363. lcd_print(">");
  3364. }
  3365. enc_dif = lcd_encoder_diff;
  3366. delay(100);
  3367. }
  3368. }
  3369. if (lcd_clicked()) {
  3370. fsm = cursor_pos;
  3371. int babyStepZ;
  3372. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3373. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3374. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3375. delay(500);
  3376. }
  3377. };
  3378. lcd_clear();
  3379. lcd_return_to_status();
  3380. }
  3381. */
  3382. void lcd_move_menu_axis()
  3383. {
  3384. MENU_BEGIN();
  3385. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3386. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=0 r=0
  3387. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=0 r=0
  3388. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=0 r=0
  3389. MENU_ITEM_SUBMENU_P(_i("Extruder"), lcd_move_e);////MSG_MOVE_E c=0 r=0
  3390. MENU_END();
  3391. }
  3392. static void lcd_move_menu_1mm()
  3393. {
  3394. move_menu_scale = 1.0;
  3395. lcd_move_menu_axis();
  3396. }
  3397. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3398. {
  3399. do
  3400. {
  3401. eeprom_write_byte((unsigned char*)pos, *value);
  3402. pos++;
  3403. value++;
  3404. } while (--size);
  3405. }
  3406. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3407. {
  3408. do
  3409. {
  3410. *value = eeprom_read_byte((unsigned char*)pos);
  3411. pos++;
  3412. value++;
  3413. } while (--size);
  3414. }
  3415. #ifdef SDCARD_SORT_ALPHA
  3416. static void lcd_sort_type_set() {
  3417. uint8_t sdSort;
  3418. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3419. switch (sdSort) {
  3420. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3421. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3422. default: sdSort = SD_SORT_TIME;
  3423. }
  3424. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3425. presort_flag = true;
  3426. }
  3427. #endif //SDCARD_SORT_ALPHA
  3428. #ifdef TMC2130
  3429. static void lcd_crash_mode_info()
  3430. {
  3431. lcd_update_enable(true);
  3432. static uint32_t tim = 0;
  3433. if ((tim + 1000) < millis())
  3434. {
  3435. fputs_P(_i("\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3436. tim = millis();
  3437. }
  3438. menu_back_if_clicked();
  3439. }
  3440. static void lcd_crash_mode_info2()
  3441. {
  3442. lcd_update_enable(true);
  3443. static uint32_t tim = 0;
  3444. if ((tim + 1000) < millis())
  3445. {
  3446. fputs_P(_i("\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3447. tim = millis();
  3448. }
  3449. menu_back_if_clicked();
  3450. }
  3451. #endif //TMC2130
  3452. #ifdef FILAMENT_SENSOR
  3453. static void lcd_filament_autoload_info()
  3454. {
  3455. uint8_t nlines;
  3456. lcd_update_enable(true);
  3457. static uint32_t tim = 0;
  3458. if ((tim + 1000) < millis())
  3459. {
  3460. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament available only when filament sensor is turned on..."), nlines); ////MSG_AUTOLOADING_ONLY_IF_FSENS_ON c=20 r=4
  3461. tim = millis();
  3462. }
  3463. menu_back_if_clicked();
  3464. }
  3465. static void lcd_fsensor_fail()
  3466. {
  3467. uint8_t nlines;
  3468. lcd_update_enable(true);
  3469. static uint32_t tim = 0;
  3470. if ((tim + 1000) < millis())
  3471. {
  3472. lcd_display_message_fullscreen_nonBlocking_P(_i("ERROR: Filament sensor is not responding, please check connection."), nlines);////MSG_FSENS_NOT_RESPONDING c=20 r=4
  3473. tim = millis();
  3474. }
  3475. menu_back_if_clicked();
  3476. }
  3477. #endif //FILAMENT_SENSOR
  3478. //-//
  3479. static void lcd_sound_state_set(void)
  3480. {
  3481. Sound_CycleState();
  3482. }
  3483. static void lcd_silent_mode_set() {
  3484. switch (SilentModeMenu) {
  3485. #ifdef TMC2130
  3486. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3487. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3488. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3489. #else
  3490. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3491. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3492. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3493. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3494. #endif //TMC2130
  3495. }
  3496. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3497. #ifdef TMC2130
  3498. // Wait until the planner queue is drained and the stepper routine achieves
  3499. // an idle state.
  3500. st_synchronize();
  3501. if (tmc2130_wait_standstill_xy(1000)) {}
  3502. // MYSERIAL.print("standstill OK");
  3503. // else
  3504. // MYSERIAL.print("standstill NG!");
  3505. cli();
  3506. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3507. update_mode_profile();
  3508. tmc2130_init();
  3509. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3510. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3511. st_reset_timer();
  3512. sei();
  3513. #endif //TMC2130
  3514. st_current_init();
  3515. #ifdef TMC2130
  3516. if (CrashDetectMenu && (SilentModeMenu != SILENT_MODE_NORMAL))
  3517. menu_submenu(lcd_crash_mode_info2);
  3518. #endif //TMC2130
  3519. }
  3520. #ifdef TMC2130
  3521. static void lcd_crash_mode_set()
  3522. {
  3523. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  3524. if (CrashDetectMenu==0) {
  3525. crashdet_disable();
  3526. }else{
  3527. crashdet_enable();
  3528. }
  3529. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true);
  3530. else menu_goto(lcd_settings_menu, 9, true, true);
  3531. }
  3532. #endif //TMC2130
  3533. #ifdef FILAMENT_SENSOR
  3534. static void lcd_fsensor_state_set()
  3535. {
  3536. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3537. if (!FSensorStateMenu) {
  3538. fsensor_disable();
  3539. if (fsensor_autoload_enabled && !mmu_enabled)
  3540. menu_submenu(lcd_filament_autoload_info);
  3541. }
  3542. else {
  3543. fsensor_enable();
  3544. if (fsensor_not_responding && !mmu_enabled)
  3545. menu_submenu(lcd_fsensor_fail);
  3546. }
  3547. }
  3548. #endif //FILAMENT_SENSOR
  3549. #if !SDSORT_USES_RAM
  3550. void lcd_set_degree() {
  3551. lcd_set_custom_characters_degree();
  3552. }
  3553. void lcd_set_progress() {
  3554. lcd_set_custom_characters_progress();
  3555. }
  3556. #endif
  3557. #if (LANG_MODE != 0)
  3558. void menu_setlang(unsigned char lang)
  3559. {
  3560. if (!lang_select(lang))
  3561. {
  3562. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3563. lang_boot_update_start(lang);
  3564. lcd_update_enable(true);
  3565. lcd_clear();
  3566. menu_goto(lcd_language_menu, 0, true, true);
  3567. lcd_timeoutToStatus.stop(); //infinite timeout
  3568. lcd_draw_update = 2;
  3569. }
  3570. }
  3571. static void lcd_language_menu()
  3572. {
  3573. MENU_BEGIN();
  3574. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3575. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3576. {
  3577. menu_setlang(0);
  3578. return;
  3579. }
  3580. uint8_t cnt = lang_get_count();
  3581. #ifdef W25X20CL
  3582. if (cnt == 2) //display secondary language in case of clear xflash
  3583. {
  3584. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3585. {
  3586. menu_setlang(1);
  3587. return;
  3588. }
  3589. }
  3590. else
  3591. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3592. #else //W25X20CL
  3593. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3594. #endif //W25X20CL
  3595. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3596. {
  3597. menu_setlang(i);
  3598. return;
  3599. }
  3600. MENU_END();
  3601. }
  3602. #endif //(LANG_MODE != 0)
  3603. void lcd_mesh_bedleveling()
  3604. {
  3605. mesh_bed_run_from_menu = true;
  3606. enquecommand_P(PSTR("G80"));
  3607. lcd_return_to_status();
  3608. }
  3609. void lcd_mesh_calibration()
  3610. {
  3611. enquecommand_P(PSTR("M45"));
  3612. lcd_return_to_status();
  3613. }
  3614. void lcd_mesh_calibration_z()
  3615. {
  3616. enquecommand_P(PSTR("M45 Z"));
  3617. lcd_return_to_status();
  3618. }
  3619. void lcd_pinda_calibration_menu()
  3620. {
  3621. MENU_BEGIN();
  3622. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3623. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3624. MENU_END();
  3625. }
  3626. void lcd_temp_calibration_set() {
  3627. temp_cal_active = !temp_cal_active;
  3628. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3629. st_current_init();
  3630. }
  3631. #ifdef HAS_SECOND_SERIAL_PORT
  3632. void lcd_second_serial_set() {
  3633. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3634. else selectedSerialPort = 1;
  3635. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3636. MYSERIAL.begin(BAUDRATE);
  3637. }
  3638. #endif //HAS_SECOND_SERIAL_PORT
  3639. void lcd_calibrate_pinda() {
  3640. enquecommand_P(PSTR("G76"));
  3641. lcd_return_to_status();
  3642. }
  3643. #ifndef SNMM
  3644. /*void lcd_calibrate_extruder() {
  3645. if (degHotend0() > EXTRUDE_MINTEMP)
  3646. {
  3647. current_position[E_AXIS] = 0; //set initial position to zero
  3648. plan_set_e_position(current_position[E_AXIS]);
  3649. //long steps_start = st_get_position(E_AXIS);
  3650. long steps_final;
  3651. float e_steps_per_unit;
  3652. float feedrate = (180 / axis_steps_per_unit[E_AXIS]) * 1; //3 //initial automatic extrusion feedrate (depends on current value of axis_steps_per_unit to avoid too fast extrusion)
  3653. float e_shift_calibration = (axis_steps_per_unit[E_AXIS] > 180 ) ? ((180 / axis_steps_per_unit[E_AXIS]) * 70): 70; //length of initial automatic extrusion sequence
  3654. const char *msg_e_cal_knob = _i("Rotate knob until mark reaches extruder body. Click when done.");////MSG_E_CAL_KNOB c=20 r=8
  3655. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3656. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3657. unsigned long msg_millis;
  3658. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3659. lcd_clear();
  3660. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  3661. current_position[E_AXIS] += e_shift_calibration;
  3662. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3663. st_synchronize();
  3664. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3665. msg_millis = millis();
  3666. while (!LCD_CLICKED) {
  3667. if (multi_screen && millis() - msg_millis > 5000) {
  3668. if (msg_next_e_cal_knob == NULL)
  3669. msg_next_e_cal_knob = msg_e_cal_knob;
  3670. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3671. msg_millis = millis();
  3672. }
  3673. //manage_inactivity(true);
  3674. manage_heater();
  3675. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3676. delay_keep_alive(50);
  3677. //previous_millis_cmd = millis();
  3678. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  3679. lcd_encoder_diff = 0;
  3680. if (!planner_queue_full()) {
  3681. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  3682. lcd_encoder = 0;
  3683. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3684. }
  3685. }
  3686. }
  3687. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3688. //steps_final = st_get_position(E_AXIS);
  3689. lcd_draw_update = 1;
  3690. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3691. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3692. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3693. lcd_clear();
  3694. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3695. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3696. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3697. //delay_keep_alive(2000);
  3698. delay_keep_alive(500);
  3699. lcd_show_fullscreen_message_and_wait_P(_i("E calibration finished. Please clean the nozzle. Click when done."));////MSG_CLEAN_NOZZLE_E c=20 r=8
  3700. lcd_update_enable(true);
  3701. lcd_draw_update = 2;
  3702. }
  3703. else
  3704. {
  3705. lcd_clear();
  3706. lcd_set_cursor(0, 0);
  3707. lcd_puts_P(_T(MSG_ERROR));
  3708. lcd_set_cursor(0, 2);
  3709. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  3710. delay(2000);
  3711. lcd_clear();
  3712. }
  3713. lcd_return_to_status();
  3714. }
  3715. void lcd_extr_cal_reset() {
  3716. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3717. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3718. //extrudemultiply = 100;
  3719. enquecommand_P(PSTR("M500"));
  3720. }*/
  3721. #endif
  3722. void lcd_toshiba_flash_air_compatibility_toggle()
  3723. {
  3724. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3725. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3726. }
  3727. void lcd_v2_calibration()
  3728. {
  3729. if (mmu_enabled)
  3730. {
  3731. const uint8_t filament = choose_menu_P(_i("Select PLA filament:"),_T(MSG_FILAMENT),_i("Cancel")); ////c=20 r=1 ////c=19 r=1
  3732. if (filament < 5)
  3733. {
  3734. lcd_commands_step = 20 + filament;
  3735. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3736. }
  3737. }
  3738. else
  3739. {
  3740. bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is PLA filament loaded?"), false, true);////MSG_PLA_FILAMENT_LOADED c=20 r=2
  3741. if (loaded) {
  3742. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3743. }
  3744. else {
  3745. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3746. for (int i = 0; i < 20; i++) { //wait max. 2s
  3747. delay_keep_alive(100);
  3748. if (lcd_clicked()) {
  3749. break;
  3750. }
  3751. }
  3752. }
  3753. }
  3754. lcd_return_to_status();
  3755. lcd_update_enable(true);
  3756. }
  3757. void lcd_wizard() {
  3758. bool result = true;
  3759. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3760. 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
  3761. }
  3762. if (result) {
  3763. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3764. lcd_wizard(0);
  3765. }
  3766. else {
  3767. lcd_return_to_status();
  3768. lcd_update_enable(true);
  3769. lcd_update(2);
  3770. }
  3771. }
  3772. void lcd_language()
  3773. {
  3774. lcd_update_enable(true);
  3775. lcd_clear();
  3776. menu_goto(lcd_language_menu, 0, true, true);
  3777. lcd_timeoutToStatus.stop(); //infinite timeout
  3778. lcd_draw_update = 2;
  3779. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3780. {
  3781. delay(50);
  3782. lcd_update(0);
  3783. manage_heater();
  3784. manage_inactivity(true);
  3785. }
  3786. if (lang_is_selected())
  3787. lcd_return_to_status();
  3788. else
  3789. lang_select(LANG_ID_PRI);
  3790. }
  3791. void lcd_wizard(int state) {
  3792. bool end = false;
  3793. int wizard_event;
  3794. const char *msg = NULL;
  3795. while (!end) {
  3796. printf_P(PSTR("Wizard state: %d"), state);
  3797. switch (state) {
  3798. case 0: // run wizard?
  3799. wizard_active = true;
  3800. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Hi, I am your Original Prusa i3 printer. Would you like me to guide you through the setup process?"), false, true);////MSG_WIZARD_WELCOME c=20 r=7
  3801. if (wizard_event) {
  3802. state = 1;
  3803. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3804. }
  3805. else {
  3806. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3807. end = true;
  3808. }
  3809. break;
  3810. case 1: // restore calibration status
  3811. switch (calibration_status()) {
  3812. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3813. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3814. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3815. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3816. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3817. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3818. }
  3819. break;
  3820. case 2: //selftest
  3821. 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
  3822. wizard_event = lcd_selftest();
  3823. if (wizard_event) {
  3824. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3825. state = 3;
  3826. }
  3827. else end = true;
  3828. break;
  3829. case 3: //xyz cal.
  3830. 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
  3831. wizard_event = gcode_M45(false, 0);
  3832. if (wizard_event) state = 5;
  3833. else end = true;
  3834. break;
  3835. case 4: //z cal.
  3836. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3837. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3838. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3839. wizard_event = gcode_M45(true, 0);
  3840. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3841. else end = true;
  3842. break;
  3843. case 5: //is filament loaded?
  3844. //start to preheat nozzle and bed to save some time later
  3845. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3846. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3847. if (mmu_enabled)
  3848. {
  3849. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament 1 loaded?"), false);////c=20 r=2
  3850. } else
  3851. {
  3852. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3853. }
  3854. if (wizard_event) state = 8;
  3855. else
  3856. {
  3857. if(mmu_enabled) state = 7;
  3858. else state = 6;
  3859. }
  3860. break;
  3861. case 6: //waiting for preheat nozzle for PLA;
  3862. #ifndef SNMM
  3863. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3864. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3865. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 60, active_extruder);
  3866. delay_keep_alive(2000);
  3867. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3868. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3869. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3870. lcd_set_cursor(0, 4);
  3871. lcd_print(LCD_STR_THERMOMETER[0]);
  3872. lcd_print(ftostr3(degHotend(0)));
  3873. lcd_print("/");
  3874. lcd_print(PLA_PREHEAT_HOTEND_TEMP);
  3875. lcd_print(LCD_STR_DEGREE);
  3876. lcd_set_custom_characters();
  3877. delay_keep_alive(1000);
  3878. }
  3879. #endif //not SNMM
  3880. state = 7;
  3881. break;
  3882. case 7: //load filament
  3883. if (mmu_enabled)
  3884. {
  3885. lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the first tube of MMU, then press the knob to load it."));////c=20 r=8
  3886. } else
  3887. {
  3888. lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the extruder, then press knob to load it."));////MSG_WIZARD_LOAD_FILAMENT c=20 r=8
  3889. }
  3890. lcd_update_enable(false);
  3891. lcd_clear();
  3892. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3893. #ifdef SNMM
  3894. change_extr(0);
  3895. #endif
  3896. loading_flag = true;
  3897. gcode_M701();
  3898. state = 9;
  3899. break;
  3900. case 8:
  3901. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is it PLA filament?"), false, true);////MSG_WIZARD_PLA_FILAMENT c=20 r=2
  3902. if (wizard_event) state = 9;
  3903. else end = true;
  3904. break;
  3905. case 9:
  3906. lcd_show_fullscreen_message_and_wait_P(_i("Now I will calibrate distance between tip of the nozzle and heatbed surface."));////MSG_WIZARD_V2_CAL c=20 r=8
  3907. lcd_show_fullscreen_message_and_wait_P(_i("I will start to print line and you will gradually lower the nozzle by rotating the knob, until you reach optimal height. Check the pictures in our handbook in chapter Calibration."));////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3908. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3909. end = true;
  3910. break;
  3911. case 10: //repeat first layer cal.?
  3912. 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
  3913. if (wizard_event) {
  3914. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3915. state = 9;
  3916. }
  3917. else {
  3918. state = 11;
  3919. }
  3920. break;
  3921. case 11: //we are finished
  3922. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3923. end = true;
  3924. break;
  3925. default: break;
  3926. }
  3927. }
  3928. printf_P(_N("Wizard end state: %d\n"), state);
  3929. switch (state) { //final message
  3930. case 0: //user dont want to use wizard
  3931. msg = _T(MSG_WIZARD_QUIT);
  3932. break;
  3933. case 1: //printer was already calibrated
  3934. msg = _T(MSG_WIZARD_DONE);
  3935. break;
  3936. case 2: //selftest
  3937. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3938. break;
  3939. case 3: //xyz cal.
  3940. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3941. break;
  3942. case 4: //z cal.
  3943. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3944. break;
  3945. case 8:
  3946. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3947. break;
  3948. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3949. case 11: //we are finished
  3950. msg = _T(MSG_WIZARD_DONE);
  3951. lcd_reset_alert_level();
  3952. lcd_setstatuspgm(_T(WELCOME_MSG));
  3953. break;
  3954. default:
  3955. msg = _T(MSG_WIZARD_QUIT);
  3956. break;
  3957. }
  3958. if (state != 9) {
  3959. lcd_show_fullscreen_message_and_wait_P(msg);
  3960. wizard_active = false;
  3961. }
  3962. lcd_update_enable(true);
  3963. lcd_return_to_status();
  3964. lcd_update(2);
  3965. }
  3966. #ifdef TMC2130
  3967. void lcd_settings_linearity_correction_menu(void)
  3968. {
  3969. MENU_BEGIN();
  3970. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3971. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3972. //tmc2130_wave_fac[X_AXIS]
  3973. 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_EXTRUDER_CORRECTION c=9 r=0
  3974. 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_EXTRUDER_CORRECTION c=9 r=0
  3975. 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_EXTRUDER_CORRECTION c=9 r=0
  3976. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3977. 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=9 r=0
  3978. MENU_END();
  3979. if(menu_leaving)
  3980. {
  3981. lcd_settings_linearity_correction_menu_save();
  3982. }
  3983. }
  3984. #endif // TMC2130
  3985. #ifdef FILAMENT_SENSOR
  3986. #define SETTINGS_FILAMENT_SENSOR \
  3987. do\
  3988. {\
  3989. if (FSensorStateMenu == 0)\
  3990. {\
  3991. if (fsensor_not_responding)\
  3992. {\
  3993. /* Filament sensor not working*/\
  3994. MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);/*////MSG_FSENSOR_NA c=0 r=0*/\
  3995. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);\
  3996. }\
  3997. else\
  3998. {\
  3999. /* Filament sensor turned off, working, no problems*/\
  4000. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);\
  4001. if (mmu_enabled == false)if (mmu_enabled == false)\
  4002. {\
  4003. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);\
  4004. }\
  4005. }\
  4006. }\
  4007. else\
  4008. {\
  4009. /* Filament sensor turned on, working, no problems*/\
  4010. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);\
  4011. if (mmu_enabled == false)\
  4012. {\
  4013. if (fsensor_autoload_enabled)\
  4014. MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17 r=1*/\
  4015. else\
  4016. MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17 r=1*/\
  4017. }\
  4018. }\
  4019. }\
  4020. while(0)
  4021. #else //FILAMENT_SENSOR
  4022. #define SETTINGS_FILAMENT_SENSOR do{}while(0)
  4023. #endif //FILAMENT_SENSOR
  4024. #ifdef TMC2130
  4025. #define SETTINGS_SILENT_MODE \
  4026. do\
  4027. {\
  4028. if(!farm_mode)\
  4029. {\
  4030. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4031. {\
  4032. MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);\
  4033. }\
  4034. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);\
  4035. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4036. {\
  4037. if (CrashDetectMenu == 0)\
  4038. {\
  4039. MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);\
  4040. }\
  4041. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);\
  4042. }\
  4043. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);\
  4044. }\
  4045. }\
  4046. while (0)
  4047. #else //TMC2130
  4048. #define SETTINGS_SILENT_MODE \
  4049. do\
  4050. {\
  4051. if(!farm_mode)\
  4052. {\
  4053. switch (SilentModeMenu)\
  4054. {\
  4055. case SILENT_MODE_POWER:\
  4056. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);\
  4057. break;\
  4058. case SILENT_MODE_SILENT:\
  4059. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set);\
  4060. break;\
  4061. case SILENT_MODE_AUTO:\
  4062. MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set);\
  4063. break;\
  4064. default:\
  4065. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);\
  4066. break; /* (probably) not needed*/\
  4067. }\
  4068. }\
  4069. }\
  4070. while (0)
  4071. #endif //TMC2130
  4072. #ifdef SDCARD_SORT_ALPHA
  4073. #define SETTINGS_SD \
  4074. do\
  4075. {\
  4076. if (card.ToshibaFlashAir_isEnabled())\
  4077. MENU_ITEM_FUNCTION_P(_i("SD card [flshAir]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1*/\
  4078. else\
  4079. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1*/\
  4080. \
  4081. if (!farm_mode)\
  4082. {\
  4083. uint8_t sdSort;\
  4084. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));\
  4085. switch (sdSort)\
  4086. {\
  4087. case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [time]"), lcd_sort_type_set); break;/*////MSG_SORT_TIME c=17 r=1*/\
  4088. case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [alphabet]"), lcd_sort_type_set); break;/*////MSG_SORT_ALPHA c=17 r=1*/\
  4089. default: MENU_ITEM_FUNCTION_P(_i("Sort: [none]"), lcd_sort_type_set);/*////MSG_SORT_NONE c=17 r=1*/\
  4090. }\
  4091. }\
  4092. }\
  4093. while (0)
  4094. #else // SDCARD_SORT_ALPHA
  4095. #define SETTINGS_SD \
  4096. do\
  4097. {\
  4098. if (card.ToshibaFlashAir_isEnabled())\
  4099. MENU_ITEM_FUNCTION_P(_i("SD card [flshAir]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1*/\
  4100. else\
  4101. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1*/\
  4102. }\
  4103. while (0)
  4104. #endif // SDCARD_SORT_ALPHA
  4105. #define SETTINGS_SOUND \
  4106. do\
  4107. {\
  4108. switch(eSoundMode)\
  4109. {\
  4110. case e_SOUND_MODE_LOUD:\
  4111. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);\
  4112. break;\
  4113. case e_SOUND_MODE_ONCE:\
  4114. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);\
  4115. break;\
  4116. case e_SOUND_MODE_SILENT:\
  4117. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);\
  4118. break;\
  4119. case e_SOUND_MODE_MUTE:\
  4120. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);\
  4121. break;\
  4122. default:\
  4123. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);\
  4124. }\
  4125. }\
  4126. while (0)
  4127. static void auto_deplete_switch()
  4128. {
  4129. lcd_autoDeplete = !lcd_autoDeplete;
  4130. eeprom_update_byte((unsigned char *)EEPROM_AUTO_DEPLETE, lcd_autoDeplete);
  4131. }
  4132. static void lcd_settings_menu()
  4133. {
  4134. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4135. MENU_BEGIN();
  4136. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4137. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  4138. if (!homing_flag)
  4139. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  4140. if (!isPrintPaused)
  4141. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  4142. SETTINGS_FILAMENT_SENSOR;
  4143. if (mmu_enabled)
  4144. {
  4145. if (lcd_autoDeplete) MENU_ITEM_FUNCTION_P(_i("Auto deplete [on]"), auto_deplete_switch);
  4146. else MENU_ITEM_FUNCTION_P(_i("Auto deplete[off]"), auto_deplete_switch);
  4147. }
  4148. if (fans_check_enabled == true)
  4149. MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  4150. else
  4151. MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  4152. SETTINGS_SILENT_MODE;
  4153. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4154. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);
  4155. #endif //LINEARITY_CORRECTION && TMC2130
  4156. if (temp_cal_active == false)
  4157. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  4158. else
  4159. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  4160. #ifdef HAS_SECOND_SERIAL_PORT
  4161. if (selectedSerialPort == 0)
  4162. MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  4163. else
  4164. MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  4165. #endif //HAS_SECOND_SERIAL
  4166. if (!isPrintPaused && !homing_flag)
  4167. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4168. #if (LANG_MODE != 0)
  4169. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  4170. #endif //(LANG_MODE != 0)
  4171. SETTINGS_SD;
  4172. SETTINGS_SOUND;
  4173. if (farm_mode)
  4174. {
  4175. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4176. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4177. }
  4178. MENU_END();
  4179. }
  4180. #ifdef TMC2130
  4181. static void lcd_ustep_linearity_menu_save()
  4182. {
  4183. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4184. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4185. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4186. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4187. }
  4188. #endif //TMC2130
  4189. static void lcd_settings_linearity_correction_menu_save()
  4190. {
  4191. #ifdef TMC2130
  4192. bool changed = false;
  4193. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4194. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4195. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4196. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4197. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4198. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4199. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4200. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4201. lcd_ustep_linearity_menu_save();
  4202. if (changed) tmc2130_init();
  4203. #endif //TMC2130
  4204. }
  4205. static void lcd_calibration_menu()
  4206. {
  4207. MENU_BEGIN();
  4208. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4209. if (!isPrintPaused)
  4210. {
  4211. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  4212. MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  4213. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4214. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  4215. #ifdef MK1BP
  4216. // MK1
  4217. // "Calibrate Z"
  4218. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  4219. #else //MK1BP
  4220. // MK2
  4221. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  4222. // "Calibrate Z" with storing the reference values to EEPROM.
  4223. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4224. #ifndef SNMM
  4225. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  4226. #endif
  4227. // "Mesh Bed Leveling"
  4228. MENU_ITEM_SUBMENU_P(_i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  4229. #endif //MK1BP
  4230. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  4231. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  4232. #ifdef TMC2130
  4233. MENU_ITEM_SUBMENU_P(_i("Show pinda state"), menu_show_pinda_state);
  4234. #else
  4235. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  4236. #endif
  4237. #ifndef MK1BP
  4238. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  4239. #endif //MK1BP
  4240. #ifndef SNMM
  4241. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  4242. #endif
  4243. #ifndef MK1BP
  4244. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  4245. #endif //MK1BP
  4246. }
  4247. MENU_END();
  4248. }
  4249. void bowden_menu() {
  4250. int enc_dif = lcd_encoder_diff;
  4251. int cursor_pos = 0;
  4252. lcd_clear();
  4253. lcd_set_cursor(0, 0);
  4254. lcd_print(">");
  4255. for (int i = 0; i < 4; i++) {
  4256. lcd_set_cursor(1, i);
  4257. lcd_print("Extruder ");
  4258. lcd_print(i);
  4259. lcd_print(": ");
  4260. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4261. lcd_print(bowden_length[i] - 48);
  4262. }
  4263. enc_dif = lcd_encoder_diff;
  4264. while (1) {
  4265. manage_heater();
  4266. manage_inactivity(true);
  4267. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4268. if (enc_dif > lcd_encoder_diff) {
  4269. cursor_pos--;
  4270. }
  4271. if (enc_dif < lcd_encoder_diff) {
  4272. cursor_pos++;
  4273. }
  4274. if (cursor_pos > 3) {
  4275. cursor_pos = 3;
  4276. }
  4277. if (cursor_pos < 0) {
  4278. cursor_pos = 0;
  4279. }
  4280. lcd_set_cursor(0, 0);
  4281. lcd_print(" ");
  4282. lcd_set_cursor(0, 1);
  4283. lcd_print(" ");
  4284. lcd_set_cursor(0, 2);
  4285. lcd_print(" ");
  4286. lcd_set_cursor(0, 3);
  4287. lcd_print(" ");
  4288. lcd_set_cursor(0, cursor_pos);
  4289. lcd_print(">");
  4290. enc_dif = lcd_encoder_diff;
  4291. delay(100);
  4292. }
  4293. if (lcd_clicked()) {
  4294. lcd_clear();
  4295. while (1) {
  4296. manage_heater();
  4297. manage_inactivity(true);
  4298. lcd_set_cursor(1, 1);
  4299. lcd_print("Extruder ");
  4300. lcd_print(cursor_pos);
  4301. lcd_print(": ");
  4302. lcd_set_cursor(13, 1);
  4303. lcd_print(bowden_length[cursor_pos] - 48);
  4304. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4305. if (enc_dif > lcd_encoder_diff) {
  4306. bowden_length[cursor_pos]--;
  4307. lcd_set_cursor(13, 1);
  4308. lcd_print(bowden_length[cursor_pos] - 48);
  4309. enc_dif = lcd_encoder_diff;
  4310. }
  4311. if (enc_dif < lcd_encoder_diff) {
  4312. bowden_length[cursor_pos]++;
  4313. lcd_set_cursor(13, 1);
  4314. lcd_print(bowden_length[cursor_pos] - 48);
  4315. enc_dif = lcd_encoder_diff;
  4316. }
  4317. }
  4318. delay(100);
  4319. if (lcd_clicked()) {
  4320. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4321. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4322. lcd_update_enable(true);
  4323. lcd_clear();
  4324. enc_dif = lcd_encoder_diff;
  4325. lcd_set_cursor(0, cursor_pos);
  4326. lcd_print(">");
  4327. for (int i = 0; i < 4; i++) {
  4328. lcd_set_cursor(1, i);
  4329. lcd_print("Extruder ");
  4330. lcd_print(i);
  4331. lcd_print(": ");
  4332. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4333. lcd_print(bowden_length[i] - 48);
  4334. }
  4335. break;
  4336. }
  4337. else return;
  4338. }
  4339. }
  4340. }
  4341. }
  4342. }
  4343. //#ifdef SNMM
  4344. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4345. lcd_clear();
  4346. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(":");
  4347. lcd_set_cursor(0, 1); lcd_print(">");
  4348. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4349. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4350. char cursor_pos = 1;
  4351. int enc_dif = 0;
  4352. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4353. while (1) {
  4354. manage_heater();
  4355. manage_inactivity(true);
  4356. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4357. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4358. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  4359. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  4360. if (cursor_pos > 3) cursor_pos = 3;
  4361. if (cursor_pos < 1) cursor_pos = 1;
  4362. lcd_set_cursor(0, 1);
  4363. lcd_print(" ");
  4364. lcd_set_cursor(0, 2);
  4365. lcd_print(" ");
  4366. lcd_set_cursor(0, 3);
  4367. lcd_print(" ");
  4368. lcd_set_cursor(0, cursor_pos);
  4369. lcd_print(">");
  4370. enc_dif = lcd_encoder_diff;
  4371. delay(100);
  4372. }
  4373. }
  4374. if (lcd_clicked()) {
  4375. KEEPALIVE_STATE(IN_HANDLER);
  4376. return(cursor_pos - 1);
  4377. }
  4378. }
  4379. }
  4380. //! @brief Select one of numbered items
  4381. //!
  4382. //! Create list of items with header. Header can not be selected.
  4383. //! Each item has text description passed by function parameter and
  4384. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  4385. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  4386. //! There can be last item with different text and no number.
  4387. //!
  4388. //! @param header Header text
  4389. //! @param item Item text
  4390. //! @param last_item Last item text, or nullptr if there is no Last item
  4391. //! @return selected item index, first item index is 0
  4392. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  4393. {
  4394. //following code should handle 3 to 127 number of items well
  4395. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  4396. const uint8_t item_len = item?strlen_P(item):0;
  4397. int8_t first = 0;
  4398. int8_t enc_dif = lcd_encoder_diff;
  4399. int8_t cursor_pos = 1;
  4400. lcd_clear();
  4401. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4402. while (1)
  4403. {
  4404. manage_heater();
  4405. manage_inactivity(true);
  4406. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  4407. {
  4408. if (enc_dif > lcd_encoder_diff)
  4409. {
  4410. cursor_pos--;
  4411. }
  4412. if (enc_dif < lcd_encoder_diff)
  4413. {
  4414. cursor_pos++;
  4415. }
  4416. enc_dif = lcd_encoder_diff;
  4417. }
  4418. if (cursor_pos > 3)
  4419. {
  4420. cursor_pos = 3;
  4421. if (first < items_no - 3)
  4422. {
  4423. first++;
  4424. lcd_clear();
  4425. }
  4426. }
  4427. if (cursor_pos < 1)
  4428. {
  4429. cursor_pos = 1;
  4430. if (first > 0)
  4431. {
  4432. first--;
  4433. lcd_clear();
  4434. }
  4435. }
  4436. if (header) lcd_puts_at_P(0,0,header);
  4437. const bool last_visible = (first == items_no - 3);
  4438. const int8_t ordinary_items = (last_item&&last_visible)?2:3;
  4439. for (int i = 0; i < ordinary_items; i++)
  4440. {
  4441. if (item) lcd_puts_at_P(1, i + 1, item);
  4442. }
  4443. for (int i = 0; i < ordinary_items; i++)
  4444. {
  4445. lcd_set_cursor(2 + item_len, i+1);
  4446. lcd_print(first + i + 1);
  4447. }
  4448. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  4449. lcd_set_cursor(0, 1);
  4450. lcd_print(" ");
  4451. lcd_set_cursor(0, 2);
  4452. lcd_print(" ");
  4453. lcd_set_cursor(0, 3);
  4454. lcd_print(" ");
  4455. lcd_set_cursor(0, cursor_pos);
  4456. lcd_print(">");
  4457. delay(100);
  4458. if (lcd_clicked())
  4459. {
  4460. KEEPALIVE_STATE(IN_HANDLER);
  4461. return(cursor_pos + first - 1);
  4462. }
  4463. }
  4464. }
  4465. //#endif
  4466. char reset_menu() {
  4467. #ifdef SNMM
  4468. int items_no = 5;
  4469. #else
  4470. int items_no = 4;
  4471. #endif
  4472. static int first = 0;
  4473. int enc_dif = 0;
  4474. char cursor_pos = 0;
  4475. const char *item [items_no];
  4476. item[0] = "Language";
  4477. item[1] = "Statistics";
  4478. item[2] = "Shipping prep";
  4479. item[3] = "All Data";
  4480. #ifdef SNMM
  4481. item[4] = "Bowden length";
  4482. #endif // SNMM
  4483. enc_dif = lcd_encoder_diff;
  4484. lcd_clear();
  4485. lcd_set_cursor(0, 0);
  4486. lcd_print(">");
  4487. while (1) {
  4488. for (int i = 0; i < 4; i++) {
  4489. lcd_set_cursor(1, i);
  4490. lcd_print(item[first + i]);
  4491. }
  4492. manage_heater();
  4493. manage_inactivity(true);
  4494. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4495. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4496. if (enc_dif > lcd_encoder_diff) {
  4497. cursor_pos--;
  4498. }
  4499. if (enc_dif < lcd_encoder_diff) {
  4500. cursor_pos++;
  4501. }
  4502. if (cursor_pos > 3) {
  4503. cursor_pos = 3;
  4504. if (first < items_no - 4) {
  4505. first++;
  4506. lcd_clear();
  4507. }
  4508. }
  4509. if (cursor_pos < 0) {
  4510. cursor_pos = 0;
  4511. if (first > 0) {
  4512. first--;
  4513. lcd_clear();
  4514. }
  4515. }
  4516. lcd_set_cursor(0, 0);
  4517. lcd_print(" ");
  4518. lcd_set_cursor(0, 1);
  4519. lcd_print(" ");
  4520. lcd_set_cursor(0, 2);
  4521. lcd_print(" ");
  4522. lcd_set_cursor(0, 3);
  4523. lcd_print(" ");
  4524. lcd_set_cursor(0, cursor_pos);
  4525. lcd_print(">");
  4526. enc_dif = lcd_encoder_diff;
  4527. delay(100);
  4528. }
  4529. }
  4530. if (lcd_clicked()) {
  4531. return(cursor_pos + first);
  4532. }
  4533. }
  4534. }
  4535. static void lcd_disable_farm_mode()
  4536. {
  4537. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4538. if (disable)
  4539. {
  4540. enquecommand_P(PSTR("G99"));
  4541. lcd_return_to_status();
  4542. }
  4543. lcd_update_enable(true);
  4544. lcd_draw_update = 2;
  4545. }
  4546. static void fil_load_menu()
  4547. {
  4548. MENU_BEGIN();
  4549. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4550. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all);////MSG_LOAD_ALL c=17 r=0
  4551. MENU_ITEM_FUNCTION_P(_i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4552. MENU_ITEM_FUNCTION_P(_i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4553. MENU_ITEM_FUNCTION_P(_i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4554. MENU_ITEM_FUNCTION_P(_i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4555. if (mmu_enabled)
  4556. MENU_ITEM_FUNCTION_P(_i("Load filament 5"), extr_adj_4);
  4557. MENU_END();
  4558. }
  4559. static void mmu_fil_eject_menu()
  4560. {
  4561. MENU_BEGIN();
  4562. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4563. MENU_ITEM_FUNCTION_P(_i("Eject filament 1"), mmu_eject_fil_0);
  4564. MENU_ITEM_FUNCTION_P(_i("Eject filament 2"), mmu_eject_fil_1);
  4565. MENU_ITEM_FUNCTION_P(_i("Eject filament 3"), mmu_eject_fil_2);
  4566. MENU_ITEM_FUNCTION_P(_i("Eject filament 4"), mmu_eject_fil_3);
  4567. MENU_ITEM_FUNCTION_P(_i("Eject filament 5"), mmu_eject_fil_4);
  4568. MENU_END();
  4569. }
  4570. static void fil_unload_menu()
  4571. {
  4572. MENU_BEGIN();
  4573. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4574. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17 r=0
  4575. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4576. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4577. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4578. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4579. if (mmu_enabled)
  4580. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17 r=0
  4581. MENU_END();
  4582. }
  4583. static void change_extr_menu(){
  4584. MENU_BEGIN();
  4585. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4586. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4587. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4588. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4589. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4590. MENU_END();
  4591. }
  4592. //unload filament for single material printer (used in M702 gcode)
  4593. void unload_filament()
  4594. {
  4595. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  4596. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4597. // extr_unload2();
  4598. current_position[E_AXIS] -= 45;
  4599. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5200 / 60, active_extruder);
  4600. st_synchronize();
  4601. current_position[E_AXIS] -= 15;
  4602. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4603. st_synchronize();
  4604. current_position[E_AXIS] -= 20;
  4605. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4606. st_synchronize();
  4607. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4608. //disable extruder steppers so filament can be removed
  4609. disable_e0();
  4610. disable_e1();
  4611. disable_e2();
  4612. delay(100);
  4613. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  4614. uint8_t counterBeep = 0;
  4615. while (!lcd_clicked() && (counterBeep < 50)) {
  4616. delay_keep_alive(100);
  4617. counterBeep++;
  4618. }
  4619. st_synchronize();
  4620. while (lcd_clicked()) delay_keep_alive(100);
  4621. lcd_update_enable(true);
  4622. lcd_setstatuspgm(_T(WELCOME_MSG));
  4623. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  4624. }
  4625. static void lcd_farm_no()
  4626. {
  4627. char step = 0;
  4628. int enc_dif = 0;
  4629. int _farmno = farm_no;
  4630. int _ret = 0;
  4631. lcd_clear();
  4632. lcd_set_cursor(0, 0);
  4633. lcd_print("Farm no");
  4634. do
  4635. {
  4636. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4637. if (enc_dif > lcd_encoder_diff) {
  4638. switch (step) {
  4639. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4640. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4641. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4642. default: break;
  4643. }
  4644. }
  4645. if (enc_dif < lcd_encoder_diff) {
  4646. switch (step) {
  4647. case(0): if (_farmno < 900) _farmno += 100; break;
  4648. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4649. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4650. default: break;
  4651. }
  4652. }
  4653. enc_dif = 0;
  4654. lcd_encoder_diff = 0;
  4655. }
  4656. lcd_set_cursor(0, 2);
  4657. if (_farmno < 100) lcd_print("0");
  4658. if (_farmno < 10) lcd_print("0");
  4659. lcd_print(_farmno);
  4660. lcd_print(" ");
  4661. lcd_set_cursor(0, 3);
  4662. lcd_print(" ");
  4663. lcd_set_cursor(step, 3);
  4664. lcd_print("^");
  4665. delay(100);
  4666. if (lcd_clicked())
  4667. {
  4668. delay(200);
  4669. step++;
  4670. if(step == 3) {
  4671. _ret = 1;
  4672. farm_no = _farmno;
  4673. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4674. prusa_statistics(20);
  4675. lcd_return_to_status();
  4676. }
  4677. }
  4678. manage_heater();
  4679. } while (_ret == 0);
  4680. }
  4681. unsigned char lcd_choose_color() {
  4682. //function returns index of currently chosen item
  4683. //following part can be modified from 2 to 255 items:
  4684. //-----------------------------------------------------
  4685. unsigned char items_no = 2;
  4686. const char *item[items_no];
  4687. item[0] = "Orange";
  4688. item[1] = "Black";
  4689. //-----------------------------------------------------
  4690. unsigned char active_rows;
  4691. static int first = 0;
  4692. int enc_dif = 0;
  4693. unsigned char cursor_pos = 1;
  4694. enc_dif = lcd_encoder_diff;
  4695. lcd_clear();
  4696. lcd_set_cursor(0, 1);
  4697. lcd_print(">");
  4698. active_rows = items_no < 3 ? items_no : 3;
  4699. while (1) {
  4700. lcd_puts_at_P(0, 0, PSTR("Choose color:"));
  4701. for (int i = 0; i < active_rows; i++) {
  4702. lcd_set_cursor(1, i+1);
  4703. lcd_print(item[first + i]);
  4704. }
  4705. manage_heater();
  4706. manage_inactivity(true);
  4707. proc_commands();
  4708. if (abs((enc_dif - lcd_encoder_diff)) > 12) {
  4709. if (enc_dif > lcd_encoder_diff) {
  4710. cursor_pos--;
  4711. }
  4712. if (enc_dif < lcd_encoder_diff) {
  4713. cursor_pos++;
  4714. }
  4715. if (cursor_pos > active_rows) {
  4716. cursor_pos = active_rows;
  4717. if (first < items_no - active_rows) {
  4718. first++;
  4719. lcd_clear();
  4720. }
  4721. }
  4722. if (cursor_pos < 1) {
  4723. cursor_pos = 1;
  4724. if (first > 0) {
  4725. first--;
  4726. lcd_clear();
  4727. }
  4728. }
  4729. lcd_set_cursor(0, 1);
  4730. lcd_print(" ");
  4731. lcd_set_cursor(0, 2);
  4732. lcd_print(" ");
  4733. lcd_set_cursor(0, 3);
  4734. lcd_print(" ");
  4735. lcd_set_cursor(0, cursor_pos);
  4736. lcd_print(">");
  4737. enc_dif = lcd_encoder_diff;
  4738. delay(100);
  4739. }
  4740. if (lcd_clicked()) {
  4741. switch(cursor_pos + first - 1) {
  4742. case 0: return 1; break;
  4743. case 1: return 0; break;
  4744. default: return 99; break;
  4745. }
  4746. }
  4747. }
  4748. }
  4749. void lcd_confirm_print()
  4750. {
  4751. uint8_t filament_type;
  4752. int enc_dif = 0;
  4753. int cursor_pos = 1;
  4754. int _ret = 0;
  4755. int _t = 0;
  4756. enc_dif = lcd_encoder_diff;
  4757. lcd_clear();
  4758. lcd_set_cursor(0, 0);
  4759. lcd_print("Print ok ?");
  4760. do
  4761. {
  4762. if (abs(enc_dif - lcd_encoder_diff) > 12) {
  4763. if (enc_dif > lcd_encoder_diff) {
  4764. cursor_pos--;
  4765. }
  4766. if (enc_dif < lcd_encoder_diff) {
  4767. cursor_pos++;
  4768. }
  4769. enc_dif = lcd_encoder_diff;
  4770. }
  4771. if (cursor_pos > 2) { cursor_pos = 2; }
  4772. if (cursor_pos < 1) { cursor_pos = 1; }
  4773. lcd_set_cursor(0, 2); lcd_print(" ");
  4774. lcd_set_cursor(0, 3); lcd_print(" ");
  4775. lcd_set_cursor(2, 2);
  4776. lcd_puts_P(_T(MSG_YES));
  4777. lcd_set_cursor(2, 3);
  4778. lcd_puts_P(_T(MSG_NO));
  4779. lcd_set_cursor(0, 1 + cursor_pos);
  4780. lcd_print(">");
  4781. delay(100);
  4782. _t = _t + 1;
  4783. if (_t>100)
  4784. {
  4785. prusa_statistics(99);
  4786. _t = 0;
  4787. }
  4788. if (lcd_clicked())
  4789. {
  4790. if (cursor_pos == 1)
  4791. {
  4792. _ret = 1;
  4793. filament_type = lcd_choose_color();
  4794. prusa_statistics(4, filament_type);
  4795. no_response = true; //we need confirmation by recieving PRUSA thx
  4796. important_status = 4;
  4797. saved_filament_type = filament_type;
  4798. NcTime = millis();
  4799. }
  4800. if (cursor_pos == 2)
  4801. {
  4802. _ret = 2;
  4803. filament_type = lcd_choose_color();
  4804. prusa_statistics(5, filament_type);
  4805. no_response = true; //we need confirmation by recieving PRUSA thx
  4806. important_status = 5;
  4807. saved_filament_type = filament_type;
  4808. NcTime = millis();
  4809. }
  4810. }
  4811. manage_heater();
  4812. manage_inactivity();
  4813. proc_commands();
  4814. } while (_ret == 0);
  4815. }
  4816. #include "w25x20cl.h"
  4817. #ifdef LCD_TEST
  4818. static void lcd_test_menu()
  4819. {
  4820. W25X20CL_SPI_ENTER();
  4821. w25x20cl_enable_wr();
  4822. w25x20cl_chip_erase();
  4823. w25x20cl_disable_wr();
  4824. }
  4825. #endif //LCD_TEST
  4826. //! @brief Resume paused print
  4827. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  4828. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  4829. void lcd_resume_print()
  4830. {
  4831. lcd_return_to_status();
  4832. lcd_setstatuspgm(_T(MSG_RESUMING_PRINT));
  4833. lcd_reset_alert_level(); //for fan speed error
  4834. restore_print_from_ram_and_continue(0.0);
  4835. pause_time += (millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  4836. isPrintPaused = false;
  4837. }
  4838. static void lcd_main_menu()
  4839. {
  4840. MENU_BEGIN();
  4841. // Majkl superawesome menu
  4842. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  4843. #ifdef RESUME_DEBUG
  4844. if (!saved_printing)
  4845. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4846. else
  4847. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4848. #endif //RESUME_DEBUG
  4849. #ifdef TMC2130_DEBUG
  4850. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4851. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4852. #endif //TMC2130_DEBUG
  4853. /* if (farm_mode && !IS_SD_PRINTING )
  4854. {
  4855. int tempScrool = 0;
  4856. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  4857. //delay(100);
  4858. return; // nothing to do (so don't thrash the SD card)
  4859. uint16_t fileCnt = card.getnrfilenames();
  4860. card.getWorkDirName();
  4861. if (card.filename[0] == '/')
  4862. {
  4863. #if SDCARDDETECT == -1
  4864. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  4865. #endif
  4866. } else {
  4867. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4868. }
  4869. for (uint16_t i = 0; i < fileCnt; i++)
  4870. {
  4871. if (menu_item == menu_line)
  4872. {
  4873. #ifndef SDCARD_RATHERRECENTFIRST
  4874. card.getfilename(i);
  4875. #else
  4876. card.getfilename(fileCnt - 1 - i);
  4877. #endif
  4878. if (card.filenameIsDir)
  4879. {
  4880. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4881. } else {
  4882. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4883. }
  4884. } else {
  4885. MENU_ITEM_DUMMY();
  4886. }
  4887. }
  4888. MENU_ITEM_BACK_P(PSTR("- - - - - - - - -"));
  4889. }*/
  4890. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  4891. {
  4892. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4893. }
  4894. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4895. {
  4896. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4897. } else
  4898. {
  4899. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4900. }
  4901. #ifdef SDSUPPORT
  4902. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4903. {
  4904. if (card.isFileOpen())
  4905. {
  4906. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4907. if (card.sdprinting)
  4908. {
  4909. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_pause_print);////MSG_PAUSE_PRINT c=0 r=0
  4910. }
  4911. else
  4912. {
  4913. MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT c=0 r=0
  4914. }
  4915. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4916. }
  4917. }
  4918. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4919. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4920. }
  4921. else
  4922. {
  4923. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4924. {
  4925. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4926. /*else*/ MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4927. }
  4928. #if SDCARDDETECT < 1
  4929. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4930. #endif
  4931. }
  4932. } else
  4933. {
  4934. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4935. #if SDCARDDETECT < 1
  4936. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD c=0 r=0
  4937. #endif
  4938. }
  4939. #endif
  4940. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4941. {
  4942. if (farm_mode)
  4943. {
  4944. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4945. }
  4946. }
  4947. else
  4948. {
  4949. if (mmu_enabled)
  4950. {
  4951. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  4952. MENU_ITEM_SUBMENU_P(_i("Eject filament"), mmu_fil_eject_menu);
  4953. if (mmu_enabled)
  4954. MENU_ITEM_GCODE_P(_T(MSG_UNLOAD_FILAMENT), PSTR("M702 C"));
  4955. else
  4956. {
  4957. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4958. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4959. }
  4960. }
  4961. else
  4962. {
  4963. #ifdef FILAMENT_SENSOR
  4964. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  4965. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  4966. else
  4967. #endif //FILAMENT_SENSOR
  4968. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4969. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4970. }
  4971. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4972. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  4973. }
  4974. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4975. {
  4976. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  4977. }
  4978. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  4979. MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats);
  4980. #endif
  4981. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  4982. #ifdef LCD_TEST
  4983. MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  4984. #endif //LCD_TEST
  4985. MENU_END();
  4986. }
  4987. void stack_error() {
  4988. SET_OUTPUT(BEEPER);
  4989. if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
  4990. WRITE(BEEPER, HIGH);
  4991. delay(1000);
  4992. WRITE(BEEPER, LOW);
  4993. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  4994. //err_triggered = 1;
  4995. while (1) delay_keep_alive(1000);
  4996. }
  4997. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4998. bool stepper_timer_overflow_state = false;
  4999. uint16_t stepper_timer_overflow_max = 0;
  5000. uint16_t stepper_timer_overflow_last = 0;
  5001. uint16_t stepper_timer_overflow_cnt = 0;
  5002. void stepper_timer_overflow() {
  5003. char msg[28];
  5004. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5005. lcd_setstatus(msg);
  5006. stepper_timer_overflow_state = false;
  5007. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5008. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5009. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5010. MYSERIAL.print(msg);
  5011. SERIAL_ECHOLNPGM("");
  5012. WRITE(BEEPER, LOW);
  5013. }
  5014. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5015. static void lcd_colorprint_change() {
  5016. enquecommand_P(PSTR("M600"));
  5017. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; //just print status message
  5018. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5019. lcd_return_to_status();
  5020. lcd_draw_update = 3;
  5021. }
  5022. static void lcd_tune_menu()
  5023. {
  5024. typedef struct
  5025. {
  5026. menu_data_edit_t reserved; //!< reserved for number editing functions
  5027. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5028. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5029. //! it needs to be applied.
  5030. int16_t extrudemultiply;
  5031. } _menu_data_t;
  5032. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5033. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5034. if (_md->status == 0)
  5035. {
  5036. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5037. _md->status = 1;
  5038. _md->extrudemultiply = extrudemultiply;
  5039. }
  5040. else if (_md->extrudemultiply != extrudemultiply)
  5041. {
  5042. // extrudemultiply has been changed from the child menu. Apply the new value.
  5043. _md->extrudemultiply = extrudemultiply;
  5044. calculate_extruder_multipliers();
  5045. }
  5046. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5047. MENU_BEGIN();
  5048. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5049. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  5050. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5051. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5052. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5053. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  5054. #ifdef FILAMENTCHANGEENABLE
  5055. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  5056. #endif
  5057. #ifdef FILAMENT_SENSOR
  5058. if (FSensorStateMenu == 0) {
  5059. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  5060. }
  5061. else {
  5062. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  5063. }
  5064. #endif //FILAMENT_SENSOR
  5065. #ifdef TMC2130
  5066. if(!farm_mode)
  5067. {
  5068. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  5069. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  5070. if (SilentModeMenu == SILENT_MODE_NORMAL)
  5071. {
  5072. if (CrashDetectMenu == 0) MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  5073. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  5074. }
  5075. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  5076. }
  5077. #else //TMC2130
  5078. if (!farm_mode) { //dont show in menu if we are in farm mode
  5079. switch (SilentModeMenu) {
  5080. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  5081. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  5082. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  5083. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  5084. }
  5085. }
  5086. #endif //TMC2130
  5087. switch(eSoundMode)
  5088. {
  5089. case e_SOUND_MODE_LOUD:
  5090. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  5091. break;
  5092. case e_SOUND_MODE_ONCE:
  5093. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);
  5094. break;
  5095. case e_SOUND_MODE_SILENT:
  5096. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);
  5097. break;
  5098. case e_SOUND_MODE_MUTE:
  5099. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);
  5100. break;
  5101. default:
  5102. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  5103. }
  5104. MENU_END();
  5105. }
  5106. static void lcd_control_temperature_menu()
  5107. {
  5108. #ifdef PIDTEMP
  5109. // set up temp variables - undo the default scaling
  5110. // raw_Ki = unscalePID_i(Ki);
  5111. // raw_Kd = unscalePID_d(Kd);
  5112. #endif
  5113. MENU_BEGIN();
  5114. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5115. #if TEMP_SENSOR_0 != 0
  5116. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5117. #endif
  5118. #if TEMP_SENSOR_1 != 0
  5119. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  5120. #endif
  5121. #if TEMP_SENSOR_2 != 0
  5122. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  5123. #endif
  5124. #if TEMP_SENSOR_BED != 0
  5125. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5126. #endif
  5127. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5128. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5129. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5130. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5131. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  5132. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  5133. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5134. #endif
  5135. MENU_END();
  5136. }
  5137. #if SDCARDDETECT == -1
  5138. static void lcd_sd_refresh()
  5139. {
  5140. card.initsd();
  5141. menu_top = 0;
  5142. }
  5143. #endif
  5144. static void lcd_sd_updir()
  5145. {
  5146. card.updir();
  5147. menu_top = 0;
  5148. }
  5149. void lcd_print_stop()
  5150. {
  5151. cancel_heatup = true;
  5152. #ifdef MESH_BED_LEVELING
  5153. mbl.active = false;
  5154. #endif
  5155. // Stop the stoppers, update the position from the stoppers.
  5156. if (mesh_bed_leveling_flag == false && homing_flag == false)
  5157. {
  5158. planner_abort_hard();
  5159. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5160. // Z baystep is no more applied. Reset it.
  5161. babystep_reset();
  5162. }
  5163. // Clean the input command queue.
  5164. cmdqueue_reset();
  5165. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5166. card.sdprinting = false;
  5167. card.closefile();
  5168. stoptime = millis();
  5169. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5170. pause_time = 0;
  5171. save_statistics(total_filament_used, t);
  5172. lcd_return_to_status();
  5173. lcd_ignore_click(true);
  5174. lcd_commands_step = 0;
  5175. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5176. // Turn off the print fan
  5177. SET_OUTPUT(FAN_PIN);
  5178. WRITE(FAN_PIN, 0);
  5179. fanSpeed = 0;
  5180. }
  5181. void lcd_sdcard_stop()
  5182. {
  5183. lcd_set_cursor(0, 0);
  5184. lcd_puts_P(_T(MSG_STOP_PRINT));
  5185. lcd_set_cursor(2, 2);
  5186. lcd_puts_P(_T(MSG_NO));
  5187. lcd_set_cursor(2, 3);
  5188. lcd_puts_P(_T(MSG_YES));
  5189. lcd_set_cursor(0, 2); lcd_print(" ");
  5190. lcd_set_cursor(0, 3); lcd_print(" ");
  5191. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  5192. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  5193. lcd_set_cursor(0, 1 + lcd_encoder);
  5194. lcd_print(">");
  5195. if (lcd_clicked())
  5196. {
  5197. if ((int32_t)lcd_encoder == 1)
  5198. {
  5199. lcd_return_to_status();
  5200. }
  5201. if ((int32_t)lcd_encoder == 2)
  5202. {
  5203. lcd_print_stop();
  5204. }
  5205. }
  5206. }
  5207. void lcd_sdcard_menu()
  5208. {
  5209. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5210. if (presort_flag == true) {
  5211. presort_flag = false;
  5212. card.presort();
  5213. }
  5214. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  5215. //delay(100);
  5216. return; // nothing to do (so don't thrash the SD card)
  5217. uint16_t fileCnt = card.getnrfilenames();
  5218. MENU_BEGIN();
  5219. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5220. card.getWorkDirName();
  5221. if (card.filename[0] == '/')
  5222. {
  5223. #if SDCARDDETECT == -1
  5224. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5225. #endif
  5226. } else {
  5227. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5228. }
  5229. for (uint16_t i = 0; i < fileCnt; i++)
  5230. {
  5231. if (menu_item == menu_line)
  5232. {
  5233. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5234. /*#ifdef SDCARD_RATHERRECENTFIRST
  5235. #ifndef SDCARD_SORT_ALPHA
  5236. fileCnt - 1 -
  5237. #endif
  5238. #endif
  5239. i;*/
  5240. #ifdef SDCARD_SORT_ALPHA
  5241. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5242. else card.getfilename_sorted(nr);
  5243. #else
  5244. card.getfilename(nr);
  5245. #endif
  5246. if (card.filenameIsDir)
  5247. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  5248. else
  5249. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5250. } else {
  5251. MENU_ITEM_DUMMY();
  5252. }
  5253. }
  5254. MENU_END();
  5255. }
  5256. static void lcd_selftest_v()
  5257. {
  5258. (void)lcd_selftest();
  5259. }
  5260. bool lcd_selftest()
  5261. {
  5262. int _progress = 0;
  5263. bool _result = true;
  5264. lcd_wait_for_cool_down();
  5265. lcd_clear();
  5266. lcd_set_cursor(0, 0); lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5267. #ifdef TMC2130
  5268. FORCE_HIGH_POWER_START;
  5269. #endif // TMC2130
  5270. delay(2000);
  5271. KEEPALIVE_STATE(IN_HANDLER);
  5272. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5273. #if (defined(FANCHECK) && defined(TACH_0))
  5274. _result = lcd_selftest_fan_dialog(0);
  5275. #else //defined(TACH_0)
  5276. _result = lcd_selftest_manual_fan_check(0, false);
  5277. if (!_result)
  5278. {
  5279. const char *_err;
  5280. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5281. }
  5282. #endif //defined(TACH_0)
  5283. if (_result)
  5284. {
  5285. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5286. #if (defined(FANCHECK) && defined(TACH_1))
  5287. _result = lcd_selftest_fan_dialog(1);
  5288. #else //defined(TACH_1)
  5289. _result = lcd_selftest_manual_fan_check(1, false);
  5290. if (!_result)
  5291. {
  5292. const char *_err;
  5293. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5294. }
  5295. #endif //defined(TACH_1)
  5296. }
  5297. if (_result)
  5298. {
  5299. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5300. #ifndef TMC2130
  5301. _result = lcd_selfcheck_endstops();
  5302. #else
  5303. _result = true;
  5304. #endif
  5305. }
  5306. if (_result)
  5307. {
  5308. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5309. _result = lcd_selfcheck_check_heater(false);
  5310. }
  5311. if (_result)
  5312. {
  5313. //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
  5314. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5315. #ifdef TMC2130
  5316. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5317. #else
  5318. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5319. #endif //TMC2130
  5320. }
  5321. if (_result)
  5322. {
  5323. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5324. #ifndef TMC2130
  5325. _result = lcd_selfcheck_pulleys(X_AXIS);
  5326. #endif
  5327. }
  5328. if (_result)
  5329. {
  5330. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5331. #ifdef TMC2130
  5332. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5333. #else
  5334. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5335. #endif // TMC2130
  5336. }
  5337. if (_result)
  5338. {
  5339. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5340. #ifndef TMC2130
  5341. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5342. #endif // TMC2130
  5343. }
  5344. if (_result)
  5345. {
  5346. #ifdef TMC2130
  5347. tmc2130_home_exit();
  5348. enable_endstops(false);
  5349. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5350. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5351. #endif
  5352. //homeaxis(X_AXIS);
  5353. //homeaxis(Y_AXIS);
  5354. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5355. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5356. st_synchronize();
  5357. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5358. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5359. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5360. enquecommand_P(PSTR("G28 W"));
  5361. enquecommand_P(PSTR("G1 Z15 F1000"));
  5362. }
  5363. }
  5364. #ifdef TMC2130
  5365. if (_result)
  5366. {
  5367. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5368. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5369. st_synchronize();
  5370. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5371. bool bres = tmc2130_home_calibrate(X_AXIS);
  5372. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5373. bres &= tmc2130_home_calibrate(Y_AXIS);
  5374. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5375. if (bres)
  5376. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5377. _result = bres;
  5378. }
  5379. #endif //TMC2130
  5380. if (_result)
  5381. {
  5382. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5383. _result = lcd_selfcheck_check_heater(true);
  5384. }
  5385. if (_result)
  5386. {
  5387. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5388. #ifdef FILAMENT_SENSOR
  5389. if (mmu_enabled == false) {
  5390. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5391. _result = lcd_selftest_fsensor();
  5392. }
  5393. #endif // FILAMENT_SENSOR
  5394. }
  5395. if (_result)
  5396. {
  5397. #ifdef FILAMENT_SENSOR
  5398. if (mmu_enabled == false)
  5399. {
  5400. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5401. }
  5402. #endif // FILAMENT_SENSOR
  5403. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5404. }
  5405. else
  5406. {
  5407. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5408. }
  5409. lcd_reset_alert_level();
  5410. enquecommand_P(PSTR("M84"));
  5411. lcd_update_enable(true);
  5412. if (_result)
  5413. {
  5414. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5415. }
  5416. else
  5417. {
  5418. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5419. }
  5420. #ifdef TMC2130
  5421. FORCE_HIGH_POWER_END;
  5422. #endif // TMC2130
  5423. KEEPALIVE_STATE(NOT_BUSY);
  5424. return(_result);
  5425. }
  5426. #ifdef TMC2130
  5427. static void reset_crash_det(unsigned char axis) {
  5428. current_position[axis] += 10;
  5429. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5430. st_synchronize();
  5431. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5432. }
  5433. static bool lcd_selfcheck_axis_sg(unsigned char axis) {
  5434. // each axis length is measured twice
  5435. float axis_length, current_position_init, current_position_final;
  5436. float measured_axis_length[2];
  5437. float margin = 60;
  5438. float max_error_mm = 5;
  5439. switch (axis) {
  5440. case 0: axis_length = X_MAX_POS; break;
  5441. case 1: axis_length = Y_MAX_POS + 8; break;
  5442. default: axis_length = 210; break;
  5443. }
  5444. tmc2130_sg_stop_on_crash = false;
  5445. tmc2130_home_exit();
  5446. enable_endstops(true);
  5447. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5448. current_position[Z_AXIS] += 17;
  5449. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5450. tmc2130_home_enter(Z_AXIS_MASK);
  5451. st_synchronize();
  5452. tmc2130_home_exit();
  5453. }
  5454. // first axis length measurement begin
  5455. current_position[axis] -= (axis_length + margin);
  5456. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5457. st_synchronize();
  5458. tmc2130_sg_meassure_start(axis);
  5459. current_position_init = st_get_position_mm(axis);
  5460. current_position[axis] += 2 * margin;
  5461. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5462. st_synchronize();
  5463. current_position[axis] += axis_length;
  5464. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5465. st_synchronize();
  5466. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5467. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5468. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5469. current_position_final = st_get_position_mm(axis);
  5470. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5471. // first measurement end and second measurement begin
  5472. current_position[axis] -= margin;
  5473. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5474. st_synchronize();
  5475. current_position[axis] -= (axis_length + margin);
  5476. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5477. st_synchronize();
  5478. current_position_init = st_get_position_mm(axis);
  5479. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5480. //end of second measurement, now check for possible errors:
  5481. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5482. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5483. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5484. enable_endstops(false);
  5485. const char *_error_1;
  5486. if (axis == X_AXIS) _error_1 = "X";
  5487. if (axis == Y_AXIS) _error_1 = "Y";
  5488. if (axis == Z_AXIS) _error_1 = "Z";
  5489. lcd_selftest_error(9, _error_1, NULL);
  5490. current_position[axis] = 0;
  5491. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5492. reset_crash_det(axis);
  5493. return false;
  5494. }
  5495. }
  5496. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  5497. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5498. //loose pulleys
  5499. const char *_error_1;
  5500. if (axis == X_AXIS) _error_1 = "X";
  5501. if (axis == Y_AXIS) _error_1 = "Y";
  5502. if (axis == Z_AXIS) _error_1 = "Z";
  5503. lcd_selftest_error(8, _error_1, NULL);
  5504. current_position[axis] = 0;
  5505. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5506. reset_crash_det(axis);
  5507. return false;
  5508. }
  5509. current_position[axis] = 0;
  5510. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5511. reset_crash_det(axis);
  5512. return true;
  5513. }
  5514. #endif //TMC2130
  5515. //#ifndef TMC2130
  5516. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5517. {
  5518. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5519. bool _stepdone = false;
  5520. bool _stepresult = false;
  5521. int _progress = 0;
  5522. int _travel_done = 0;
  5523. int _err_endstop = 0;
  5524. int _lcd_refresh = 0;
  5525. _travel = _travel + (_travel / 10);
  5526. if (_axis == X_AXIS) {
  5527. current_position[Z_AXIS] += 17;
  5528. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5529. }
  5530. do {
  5531. current_position[_axis] = current_position[_axis] - 1;
  5532. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5533. st_synchronize();
  5534. #ifdef TMC2130
  5535. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5536. #else //TMC2130
  5537. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5538. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5539. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5540. #endif //TMC2130
  5541. {
  5542. if (_axis == 0)
  5543. {
  5544. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5545. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5546. }
  5547. if (_axis == 1)
  5548. {
  5549. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5550. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5551. }
  5552. if (_axis == 2)
  5553. {
  5554. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5555. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5556. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5557. /*disable_x();
  5558. disable_y();
  5559. disable_z();*/
  5560. }
  5561. _stepdone = true;
  5562. }
  5563. if (_lcd_refresh < 6)
  5564. {
  5565. _lcd_refresh++;
  5566. }
  5567. else
  5568. {
  5569. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5570. _lcd_refresh = 0;
  5571. }
  5572. manage_heater();
  5573. manage_inactivity(true);
  5574. //delay(100);
  5575. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5576. } while (!_stepdone);
  5577. //current_position[_axis] = current_position[_axis] + 15;
  5578. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5579. if (!_stepresult)
  5580. {
  5581. const char *_error_1;
  5582. const char *_error_2;
  5583. if (_axis == X_AXIS) _error_1 = "X";
  5584. if (_axis == Y_AXIS) _error_1 = "Y";
  5585. if (_axis == Z_AXIS) _error_1 = "Z";
  5586. if (_err_endstop == 0) _error_2 = "X";
  5587. if (_err_endstop == 1) _error_2 = "Y";
  5588. if (_err_endstop == 2) _error_2 = "Z";
  5589. if (_travel_done >= _travel)
  5590. {
  5591. lcd_selftest_error(5, _error_1, _error_2);
  5592. }
  5593. else
  5594. {
  5595. lcd_selftest_error(4, _error_1, _error_2);
  5596. }
  5597. }
  5598. return _stepresult;
  5599. }
  5600. #ifndef TMC2130
  5601. static bool lcd_selfcheck_pulleys(int axis)
  5602. {
  5603. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5604. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5605. float current_position_init;
  5606. float move;
  5607. bool endstop_triggered = false;
  5608. int i;
  5609. unsigned long timeout_counter;
  5610. refresh_cmd_timeout();
  5611. manage_inactivity(true);
  5612. if (axis == 0) move = 50; //X_AXIS
  5613. else move = 50; //Y_AXIS
  5614. current_position_init = current_position[axis];
  5615. current_position[axis] += 2;
  5616. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5617. for (i = 0; i < 5; i++) {
  5618. refresh_cmd_timeout();
  5619. current_position[axis] = current_position[axis] + move;
  5620. st_current_set(0, 850); //set motor current higher
  5621. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5622. st_synchronize();
  5623. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5624. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5625. current_position[axis] = current_position[axis] - move;
  5626. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5627. st_synchronize();
  5628. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5629. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5630. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5631. return(false);
  5632. }
  5633. }
  5634. timeout_counter = millis() + 2500;
  5635. endstop_triggered = false;
  5636. manage_inactivity(true);
  5637. while (!endstop_triggered) {
  5638. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5639. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5640. endstop_triggered = true;
  5641. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5642. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5643. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5644. st_synchronize();
  5645. return(true);
  5646. }
  5647. else {
  5648. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5649. return(false);
  5650. }
  5651. }
  5652. else {
  5653. current_position[axis] -= 1;
  5654. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5655. st_synchronize();
  5656. if (millis() > timeout_counter) {
  5657. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5658. return(false);
  5659. }
  5660. }
  5661. }
  5662. return(true);
  5663. }
  5664. static bool lcd_selfcheck_endstops()
  5665. {
  5666. bool _result = true;
  5667. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5668. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5669. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5670. {
  5671. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5672. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5673. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5674. }
  5675. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
  5676. delay(500);
  5677. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5678. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5679. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5680. {
  5681. _result = false;
  5682. char _error[4] = "";
  5683. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5684. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5685. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5686. lcd_selftest_error(3, _error, "");
  5687. }
  5688. manage_heater();
  5689. manage_inactivity(true);
  5690. return _result;
  5691. }
  5692. #endif //not defined TMC2130
  5693. static bool lcd_selfcheck_check_heater(bool _isbed)
  5694. {
  5695. int _counter = 0;
  5696. int _progress = 0;
  5697. bool _stepresult = false;
  5698. bool _docycle = true;
  5699. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5700. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5701. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5702. target_temperature[0] = (_isbed) ? 0 : 200;
  5703. target_temperature_bed = (_isbed) ? 100 : 0;
  5704. manage_heater();
  5705. manage_inactivity(true);
  5706. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5707. do {
  5708. _counter++;
  5709. _docycle = (_counter < _cycles) ? true : false;
  5710. manage_heater();
  5711. manage_inactivity(true);
  5712. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5713. /*if (_isbed) {
  5714. MYSERIAL.print("Bed temp:");
  5715. MYSERIAL.println(degBed());
  5716. }
  5717. else {
  5718. MYSERIAL.print("Hotend temp:");
  5719. MYSERIAL.println(degHotend(0));
  5720. }*/
  5721. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5722. } while (_docycle);
  5723. target_temperature[0] = 0;
  5724. target_temperature_bed = 0;
  5725. manage_heater();
  5726. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5727. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5728. /*
  5729. MYSERIAL.println("");
  5730. MYSERIAL.print("Checked result:");
  5731. MYSERIAL.println(_checked_result);
  5732. MYSERIAL.print("Opposite result:");
  5733. MYSERIAL.println(_opposite_result);
  5734. */
  5735. if (_opposite_result < ((_isbed) ? 10 : 3))
  5736. {
  5737. if (_checked_result >= ((_isbed) ? 3 : 10))
  5738. {
  5739. _stepresult = true;
  5740. }
  5741. else
  5742. {
  5743. lcd_selftest_error(1, "", "");
  5744. }
  5745. }
  5746. else
  5747. {
  5748. lcd_selftest_error(2, "", "");
  5749. }
  5750. manage_heater();
  5751. manage_inactivity(true);
  5752. KEEPALIVE_STATE(IN_HANDLER);
  5753. return _stepresult;
  5754. }
  5755. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5756. {
  5757. lcd_beeper_quick_feedback();
  5758. target_temperature[0] = 0;
  5759. target_temperature_bed = 0;
  5760. manage_heater();
  5761. manage_inactivity();
  5762. lcd_clear();
  5763. lcd_set_cursor(0, 0);
  5764. lcd_puts_P(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5765. lcd_set_cursor(0, 1);
  5766. lcd_puts_P(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5767. switch (_error_no)
  5768. {
  5769. case 1:
  5770. lcd_set_cursor(0, 2);
  5771. lcd_puts_P(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5772. lcd_set_cursor(0, 3);
  5773. lcd_puts_P(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5774. break;
  5775. case 2:
  5776. lcd_set_cursor(0, 2);
  5777. lcd_puts_P(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5778. lcd_set_cursor(0, 3);
  5779. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5780. break;
  5781. case 3:
  5782. lcd_set_cursor(0, 2);
  5783. lcd_puts_P(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5784. lcd_set_cursor(0, 3);
  5785. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5786. lcd_set_cursor(17, 3);
  5787. lcd_print(_error_1);
  5788. break;
  5789. case 4:
  5790. lcd_set_cursor(0, 2);
  5791. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5792. lcd_set_cursor(18, 2);
  5793. lcd_print(_error_1);
  5794. lcd_set_cursor(0, 3);
  5795. lcd_puts_P(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5796. lcd_set_cursor(18, 3);
  5797. lcd_print(_error_2);
  5798. break;
  5799. case 5:
  5800. lcd_set_cursor(0, 2);
  5801. lcd_puts_P(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  5802. lcd_set_cursor(0, 3);
  5803. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5804. lcd_set_cursor(18, 3);
  5805. lcd_print(_error_1);
  5806. break;
  5807. case 6:
  5808. lcd_set_cursor(0, 2);
  5809. lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5810. lcd_set_cursor(0, 3);
  5811. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5812. lcd_set_cursor(18, 3);
  5813. lcd_print(_error_1);
  5814. break;
  5815. case 7:
  5816. lcd_set_cursor(0, 2);
  5817. lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5818. lcd_set_cursor(0, 3);
  5819. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5820. lcd_set_cursor(18, 3);
  5821. lcd_print(_error_1);
  5822. break;
  5823. case 8:
  5824. lcd_set_cursor(0, 2);
  5825. lcd_puts_P(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  5826. lcd_set_cursor(0, 3);
  5827. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5828. lcd_set_cursor(18, 3);
  5829. lcd_print(_error_1);
  5830. break;
  5831. case 9:
  5832. lcd_set_cursor(0, 2);
  5833. lcd_puts_P(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  5834. lcd_set_cursor(0, 3);
  5835. lcd_puts_P(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  5836. lcd_set_cursor(18, 3);
  5837. lcd_print(_error_1);
  5838. break;
  5839. case 10:
  5840. lcd_set_cursor(0, 2);
  5841. lcd_puts_P(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  5842. lcd_set_cursor(0, 3);
  5843. lcd_puts_P(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  5844. lcd_set_cursor(18, 3);
  5845. lcd_print(_error_1);
  5846. break;
  5847. case 11:
  5848. lcd_set_cursor(0, 2);
  5849. lcd_puts_P(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  5850. lcd_set_cursor(0, 3);
  5851. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5852. break;
  5853. }
  5854. delay(1000);
  5855. lcd_beeper_quick_feedback();
  5856. do {
  5857. delay(100);
  5858. manage_heater();
  5859. manage_inactivity();
  5860. } while (!lcd_clicked());
  5861. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5862. lcd_return_to_status();
  5863. }
  5864. #ifdef FILAMENT_SENSOR
  5865. static bool lcd_selftest_fsensor(void)
  5866. {
  5867. fsensor_init();
  5868. if (fsensor_not_responding)
  5869. {
  5870. lcd_selftest_error(11, NULL, NULL);
  5871. }
  5872. return (!fsensor_not_responding);
  5873. }
  5874. #endif //FILAMENT_SENSOR
  5875. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5876. {
  5877. bool _result = check_opposite;
  5878. lcd_clear();
  5879. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5880. switch (_fan)
  5881. {
  5882. case 0:
  5883. // extruder cooling fan
  5884. lcd_set_cursor(0, 1);
  5885. if(check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5886. else lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5887. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5888. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5889. break;
  5890. case 1:
  5891. // object cooling fan
  5892. lcd_set_cursor(0, 1);
  5893. if (check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5894. else lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5895. SET_OUTPUT(FAN_PIN);
  5896. analogWrite(FAN_PIN, 255);
  5897. break;
  5898. }
  5899. delay(500);
  5900. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5901. lcd_set_cursor(0, 3); lcd_print(">");
  5902. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5903. int8_t enc_dif = 0;
  5904. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5905. lcd_button_pressed = false;
  5906. do
  5907. {
  5908. switch (_fan)
  5909. {
  5910. case 0:
  5911. // extruder cooling fan
  5912. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5913. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5914. break;
  5915. case 1:
  5916. // object cooling fan
  5917. SET_OUTPUT(FAN_PIN);
  5918. analogWrite(FAN_PIN, 255);
  5919. break;
  5920. }
  5921. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5922. if (enc_dif > lcd_encoder_diff) {
  5923. _result = !check_opposite;
  5924. lcd_set_cursor(0, 2); lcd_print(">");
  5925. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5926. lcd_set_cursor(0, 3); lcd_print(" ");
  5927. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5928. }
  5929. if (enc_dif < lcd_encoder_diff) {
  5930. _result = check_opposite;
  5931. lcd_set_cursor(0, 2); lcd_print(" ");
  5932. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5933. lcd_set_cursor(0, 3); lcd_print(">");
  5934. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5935. }
  5936. enc_dif = 0;
  5937. lcd_encoder_diff = 0;
  5938. }
  5939. manage_heater();
  5940. delay(100);
  5941. } while (!lcd_clicked());
  5942. KEEPALIVE_STATE(IN_HANDLER);
  5943. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5944. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5945. SET_OUTPUT(FAN_PIN);
  5946. analogWrite(FAN_PIN, 0);
  5947. fanSpeed = 0;
  5948. manage_heater();
  5949. return _result;
  5950. }
  5951. static bool lcd_selftest_fan_dialog(int _fan)
  5952. {
  5953. bool _result = true;
  5954. int _errno = 7;
  5955. switch (_fan) {
  5956. case 0:
  5957. fanSpeed = 0;
  5958. manage_heater(); //turn off fan
  5959. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5960. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5961. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5962. if (!fan_speed[0]) _result = false;
  5963. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5964. //MYSERIAL.println(fan_speed[0]);
  5965. //SERIAL_ECHOPGM("Print fan speed: ");
  5966. //MYSERIAL.print(fan_speed[1]);
  5967. break;
  5968. case 1:
  5969. //will it work with Thotend > 50 C ?
  5970. fanSpeed = 150; //print fan
  5971. for (uint8_t i = 0; i < 5; i++) {
  5972. delay_keep_alive(1000);
  5973. lcd_set_cursor(18, 3);
  5974. lcd_print("-");
  5975. delay_keep_alive(1000);
  5976. lcd_set_cursor(18, 3);
  5977. lcd_print("|");
  5978. }
  5979. fanSpeed = 0;
  5980. manage_heater(); //turn off fan
  5981. manage_inactivity(true); //to turn off print fan
  5982. if (!fan_speed[1]) {
  5983. _result = false; _errno = 6; //print fan not spinning
  5984. }
  5985. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5986. //check fans manually
  5987. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  5988. if (_result) {
  5989. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  5990. if (!_result) _errno = 6; //print fan not spinning
  5991. }
  5992. else {
  5993. _errno = 10; //swapped fans
  5994. }
  5995. }
  5996. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5997. //MYSERIAL.println(fan_speed[0]);
  5998. //SERIAL_ECHOPGM("Print fan speed: ");
  5999. //MYSERIAL.println(fan_speed[1]);
  6000. break;
  6001. }
  6002. if (!_result)
  6003. {
  6004. lcd_selftest_error(_errno, NULL, NULL);
  6005. }
  6006. return _result;
  6007. }
  6008. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  6009. {
  6010. lcd_update_enable(false);
  6011. int _step_block = 0;
  6012. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  6013. if (_clear) lcd_clear();
  6014. lcd_set_cursor(0, 0);
  6015. if (_step == -1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6016. if (_step == 0) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6017. if (_step == 1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6018. if (_step == 2) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  6019. if (_step == 3) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  6020. if (_step == 4) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  6021. if (_step == 5) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  6022. if (_step == 6) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  6023. if (_step == 7) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6024. if (_step == 8) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6025. if (_step == 9) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6026. if (_step == 10) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6027. if (_step == 11) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  6028. if (_step == 12) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  6029. if (_step == 13) lcd_puts_P(PSTR("Calibrating home"));
  6030. lcd_set_cursor(0, 1);
  6031. lcd_puts_P(separator);
  6032. if ((_step >= -1) && (_step <= 1))
  6033. {
  6034. //SERIAL_ECHOLNPGM("Fan test");
  6035. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  6036. lcd_set_cursor(18, 2);
  6037. (_step < 0) ? lcd_print(_indicator) : lcd_print("OK");
  6038. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  6039. lcd_set_cursor(18, 3);
  6040. (_step < 1) ? lcd_print(_indicator) : lcd_print("OK");
  6041. }
  6042. else if (_step >= 9 && _step <= 10)
  6043. {
  6044. lcd_puts_at_P(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  6045. lcd_set_cursor(18, 2);
  6046. (_step == 9) ? lcd_print(_indicator) : lcd_print("OK");
  6047. }
  6048. else if (_step < 9)
  6049. {
  6050. //SERIAL_ECHOLNPGM("Other tests");
  6051. _step_block = 3;
  6052. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  6053. _step_block = 4;
  6054. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  6055. _step_block = 5;
  6056. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  6057. _step_block = 6;
  6058. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  6059. _step_block = 7;
  6060. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  6061. }
  6062. if (_delay > 0) delay_keep_alive(_delay);
  6063. _progress++;
  6064. return (_progress > _progress_scale * 2) ? 0 : _progress;
  6065. }
  6066. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  6067. {
  6068. lcd_set_cursor(_col, _row);
  6069. switch (_state)
  6070. {
  6071. case 1:
  6072. lcd_print(_name);
  6073. lcd_set_cursor(_col + strlen(_name), _row);
  6074. lcd_print(":");
  6075. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  6076. lcd_print(_indicator);
  6077. break;
  6078. case 2:
  6079. lcd_print(_name);
  6080. lcd_set_cursor(_col + strlen(_name), _row);
  6081. lcd_print(":");
  6082. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  6083. lcd_print("OK");
  6084. break;
  6085. default:
  6086. lcd_print(_name);
  6087. }
  6088. }
  6089. /** End of menus **/
  6090. /** Menu action functions **/
  6091. static bool check_file(const char* filename) {
  6092. if (farm_mode) return true;
  6093. bool result = false;
  6094. uint32_t filesize;
  6095. card.openFile((char*)filename, true);
  6096. filesize = card.getFileSize();
  6097. if (filesize > END_FILE_SECTION) {
  6098. card.setIndex(filesize - END_FILE_SECTION);
  6099. }
  6100. while (!card.eof() && !result) {
  6101. card.sdprinting = true;
  6102. get_command();
  6103. result = check_commands();
  6104. }
  6105. card.printingHasFinished();
  6106. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6107. lcd_finishstatus();
  6108. return result;
  6109. }
  6110. static void menu_action_sdfile(const char* filename)
  6111. {
  6112. loading_flag = false;
  6113. char cmd[30];
  6114. char* c;
  6115. bool result = true;
  6116. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6117. for (c = &cmd[4]; *c; c++)
  6118. *c = tolower(*c);
  6119. const char end[5] = ".gco";
  6120. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6121. for (int i = 0; i < 8; i++) {
  6122. if (strcmp((cmd + i + 4), end) == 0) {
  6123. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6124. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6125. break;
  6126. }
  6127. else {
  6128. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6129. }
  6130. }
  6131. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6132. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6133. for (uint8_t i = 0; i < depth; i++) {
  6134. for (int j = 0; j < 8; j++) {
  6135. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6136. }
  6137. }
  6138. if (!check_file(filename)) {
  6139. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6140. lcd_update_enable(true);
  6141. }
  6142. if (result) {
  6143. enquecommand(cmd);
  6144. enquecommand_P(PSTR("M24"));
  6145. }
  6146. lcd_return_to_status();
  6147. }
  6148. void menu_action_sddirectory(const char* filename)
  6149. {
  6150. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6151. strcpy(dir_names[depth], filename);
  6152. MYSERIAL.println(dir_names[depth]);
  6153. card.chdir(filename);
  6154. lcd_encoder = 0;
  6155. }
  6156. /** LCD API **/
  6157. void ultralcd_init()
  6158. {
  6159. {
  6160. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  6161. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  6162. else lcd_autoDeplete = autoDepleteRaw;
  6163. }
  6164. lcd_init();
  6165. lcd_refresh();
  6166. lcd_longpress_func = menu_lcd_longpress_func;
  6167. lcd_charsetup_func = menu_lcd_charsetup_func;
  6168. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6169. menu_menu = lcd_status_screen;
  6170. menu_lcd_charsetup_func();
  6171. SET_INPUT(BTN_EN1);
  6172. SET_INPUT(BTN_EN2);
  6173. WRITE(BTN_EN1, HIGH);
  6174. WRITE(BTN_EN2, HIGH);
  6175. #if BTN_ENC > 0
  6176. SET_INPUT(BTN_ENC);
  6177. WRITE(BTN_ENC, HIGH);
  6178. #endif
  6179. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6180. pinMode(SDCARDDETECT, INPUT);
  6181. WRITE(SDCARDDETECT, HIGH);
  6182. lcd_oldcardstatus = IS_SD_INSERTED;
  6183. #endif//(SDCARDDETECT > 0)
  6184. lcd_encoder_diff = 0;
  6185. }
  6186. void lcd_printer_connected() {
  6187. printer_connected = true;
  6188. }
  6189. static void lcd_send_status() {
  6190. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6191. //send important status messages periodicaly
  6192. prusa_statistics(important_status, saved_filament_type);
  6193. NcTime = millis();
  6194. #ifdef FARM_CONNECT_MESSAGE
  6195. lcd_connect_printer();
  6196. #endif //FARM_CONNECT_MESSAGE
  6197. }
  6198. }
  6199. #ifdef FARM_CONNECT_MESSAGE
  6200. static void lcd_connect_printer() {
  6201. lcd_update_enable(false);
  6202. lcd_clear();
  6203. int i = 0;
  6204. int t = 0;
  6205. lcd_set_custom_characters_progress();
  6206. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  6207. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  6208. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  6209. while (no_response) {
  6210. i++;
  6211. t++;
  6212. delay_keep_alive(100);
  6213. proc_commands();
  6214. if (t == 10) {
  6215. prusa_statistics(important_status, saved_filament_type);
  6216. t = 0;
  6217. }
  6218. if (READ(BTN_ENC)) { //if button is not pressed
  6219. i = 0;
  6220. lcd_puts_at_P(0, 3, PSTR(" "));
  6221. }
  6222. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6223. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6224. no_response = false;
  6225. }
  6226. }
  6227. lcd_set_custom_characters_degree();
  6228. lcd_update_enable(true);
  6229. lcd_update(2);
  6230. }
  6231. #endif //FARM_CONNECT_MESSAGE
  6232. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6233. if (farm_mode) {
  6234. bool empty = is_buffer_empty();
  6235. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6236. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6237. //therefore longer period is used
  6238. printer_connected = false;
  6239. }
  6240. else {
  6241. lcd_printer_connected();
  6242. }
  6243. }
  6244. }
  6245. void lcd_ignore_click(bool b)
  6246. {
  6247. ignore_click = b;
  6248. wait_for_unclick = false;
  6249. }
  6250. void lcd_finishstatus() {
  6251. int len = strlen(lcd_status_message);
  6252. if (len > 0) {
  6253. while (len < LCD_WIDTH) {
  6254. lcd_status_message[len++] = ' ';
  6255. }
  6256. }
  6257. lcd_status_message[LCD_WIDTH] = '\0';
  6258. lcd_draw_update = 2;
  6259. }
  6260. void lcd_setstatus(const char* message)
  6261. {
  6262. if (lcd_status_message_level > 0)
  6263. return;
  6264. strncpy(lcd_status_message, message, LCD_WIDTH);
  6265. lcd_finishstatus();
  6266. }
  6267. void lcd_setstatuspgm(const char* message)
  6268. {
  6269. if (lcd_status_message_level > 0)
  6270. return;
  6271. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6272. lcd_status_message[LCD_WIDTH] = 0;
  6273. lcd_finishstatus();
  6274. }
  6275. void lcd_setalertstatuspgm(const char* message)
  6276. {
  6277. lcd_setstatuspgm(message);
  6278. lcd_status_message_level = 1;
  6279. lcd_return_to_status();
  6280. }
  6281. void lcd_reset_alert_level()
  6282. {
  6283. lcd_status_message_level = 0;
  6284. }
  6285. uint8_t get_message_level()
  6286. {
  6287. return lcd_status_message_level;
  6288. }
  6289. void menu_lcd_longpress_func(void)
  6290. {
  6291. move_menu_scale = 1.0;
  6292. menu_submenu(lcd_move_z);
  6293. }
  6294. void menu_lcd_charsetup_func(void)
  6295. {
  6296. if (menu_menu == lcd_status_screen)
  6297. lcd_set_custom_characters_degree();
  6298. else
  6299. lcd_set_custom_characters_arrows();
  6300. }
  6301. static inline bool z_menu_expired()
  6302. {
  6303. return (menu_menu == lcd_babystep_z
  6304. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6305. }
  6306. static inline bool other_menu_expired()
  6307. {
  6308. return (menu_menu != lcd_status_screen
  6309. && menu_menu != lcd_babystep_z
  6310. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6311. }
  6312. static inline bool forced_menu_expire()
  6313. {
  6314. bool retval = (menu_menu != lcd_status_screen
  6315. && forceMenuExpire);
  6316. forceMenuExpire = false;
  6317. return retval;
  6318. }
  6319. void menu_lcd_lcdupdate_func(void)
  6320. {
  6321. #if (SDCARDDETECT > 0)
  6322. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6323. {
  6324. lcd_draw_update = 2;
  6325. lcd_oldcardstatus = IS_SD_INSERTED;
  6326. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6327. if (lcd_oldcardstatus)
  6328. {
  6329. card.initsd();
  6330. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6331. //get_description();
  6332. }
  6333. else
  6334. {
  6335. card.release();
  6336. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6337. }
  6338. }
  6339. #endif//CARDINSERTED
  6340. if (lcd_next_update_millis < millis())
  6341. {
  6342. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6343. {
  6344. if (lcd_draw_update == 0)
  6345. lcd_draw_update = 1;
  6346. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6347. lcd_encoder_diff = 0;
  6348. lcd_timeoutToStatus.start();
  6349. }
  6350. if (LCD_CLICKED) lcd_timeoutToStatus.start();
  6351. (*menu_menu)();
  6352. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  6353. {
  6354. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  6355. // to give it a chance to save its state.
  6356. // This is useful for example, when the babystep value has to be written into EEPROM.
  6357. if (menu_menu != NULL)
  6358. {
  6359. menu_leaving = 1;
  6360. (*menu_menu)();
  6361. menu_leaving = 0;
  6362. }
  6363. lcd_clear();
  6364. lcd_return_to_status();
  6365. lcd_draw_update = 2;
  6366. }
  6367. if (lcd_draw_update == 2) lcd_clear();
  6368. if (lcd_draw_update) lcd_draw_update--;
  6369. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6370. }
  6371. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6372. lcd_ping(); //check that we have received ping command if we are in farm mode
  6373. lcd_send_status();
  6374. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6375. }