ultralcd.cpp 205 KB

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