ultralcd.cpp 269 KB

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