ultralcd.cpp 248 KB

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