ultralcd.cpp 201 KB

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