ultralcd.cpp 212 KB

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