ultralcd.cpp 202 KB

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