ultralcd.cpp 206 KB

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