ultralcd.cpp 243 KB

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