ultralcd.cpp 242 KB

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