ultralcd.cpp 206 KB

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