ultralcd.cpp 205 KB

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