ultralcd.cpp 248 KB

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