ultralcd.cpp 211 KB

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