ultralcd.cpp 253 KB

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