ultralcd.cpp 242 KB

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