ultralcd.cpp 209 KB

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