ultralcd.cpp 217 KB

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