ultralcd.cpp 243 KB

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