ultralcd.cpp 251 KB

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