ultralcd.cpp 205 KB

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