ultralcd.cpp 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922
  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 = is_usb_printing?_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. #ifndef MK1BP
  1801. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1802. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1803. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1804. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1805. #ifdef TMC2130
  1806. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);////MSG_BELT_STATUS c=18
  1807. #endif //TMC2130
  1808. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1809. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1810. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1811. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1812. #ifdef MENU_DUMP
  1813. MENU_ITEM_FUNCTION_P(_i("Dump memory"), lcd_dump_memory);
  1814. #endif //MENU_DUMP
  1815. #ifdef MENU_SERIAL_DUMP
  1816. if (emergency_serial_dump)
  1817. MENU_ITEM_FUNCTION_P(_i("Dump to serial"), lcd_serial_dump);
  1818. #endif
  1819. #ifdef DEBUG_BUILD
  1820. #ifdef EMERGENCY_HANDLERS
  1821. #ifdef WATCHDOG
  1822. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1823. #endif //WATCHDOG
  1824. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1825. #endif //EMERGENCY_HANDLERS
  1826. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1827. #endif /* DEBUG_BUILD */
  1828. #endif //MK1BP
  1829. MENU_END();
  1830. }
  1831. void lcd_set_fan_check() {
  1832. fans_check_enabled = !fans_check_enabled;
  1833. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1834. #ifdef FANCHECK
  1835. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1836. #endif //FANCHECK
  1837. }
  1838. #ifdef MMU_HAS_CUTTER
  1839. void lcd_cutter_enabled()
  1840. {
  1841. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1842. {
  1843. #ifndef MMU_ALWAYS_CUT
  1844. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1845. }
  1846. #else //MMU_ALWAYS_CUT
  1847. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1848. }
  1849. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1850. {
  1851. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1852. }
  1853. #endif //MMU_ALWAYS_CUT
  1854. else
  1855. {
  1856. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1857. }
  1858. }
  1859. #endif //MMU_HAS_CUTTER
  1860. void lcd_set_filament_autoload() {
  1861. fsensor_autoload_set(!fsensor_autoload_enabled);
  1862. }
  1863. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1864. void lcd_set_filament_oq_meass()
  1865. {
  1866. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1867. }
  1868. #endif
  1869. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1870. bool bFilamentFirstRun;
  1871. bool bFilamentPreheatState;
  1872. bool bFilamentAction=false;
  1873. static bool bFilamentWaitingFlag=false;
  1874. static void mFilamentPrompt()
  1875. {
  1876. uint8_t nLevel;
  1877. lcd_set_cursor(0,0);
  1878. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1879. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1880. lcd_set_cursor(0,2);
  1881. switch(eFilamentAction)
  1882. {
  1883. case FilamentAction::Load:
  1884. case FilamentAction::AutoLoad:
  1885. case FilamentAction::MmuLoad:
  1886. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1887. break;
  1888. case FilamentAction::UnLoad:
  1889. case FilamentAction::MmuUnLoad:
  1890. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1891. break;
  1892. case FilamentAction::MmuEject:
  1893. case FilamentAction::MmuCut:
  1894. case FilamentAction::None:
  1895. case FilamentAction::Preheat:
  1896. case FilamentAction::Lay1Cal:
  1897. break;
  1898. }
  1899. if(lcd_clicked())
  1900. {
  1901. nLevel=2;
  1902. if(!bFilamentPreheatState)
  1903. {
  1904. nLevel++;
  1905. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1906. }
  1907. menu_back(nLevel);
  1908. switch(eFilamentAction)
  1909. {
  1910. case FilamentAction::AutoLoad:
  1911. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1912. // FALLTHRU
  1913. case FilamentAction::Load:
  1914. loading_flag=true;
  1915. enquecommand_P(PSTR("M701")); // load filament
  1916. break;
  1917. case FilamentAction::UnLoad:
  1918. enquecommand_P(PSTR("M702")); // unload filament
  1919. break;
  1920. case FilamentAction::MmuLoad:
  1921. case FilamentAction::MmuUnLoad:
  1922. case FilamentAction::MmuEject:
  1923. case FilamentAction::MmuCut:
  1924. case FilamentAction::None:
  1925. case FilamentAction::Preheat:
  1926. case FilamentAction::Lay1Cal:
  1927. break;
  1928. }
  1929. }
  1930. }
  1931. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1932. {
  1933. static int nTargetOld;
  1934. static int nTargetBedOld;
  1935. uint8_t nLevel;
  1936. nTargetOld = target_temperature[0];
  1937. nTargetBedOld = target_temperature_bed;
  1938. setTargetHotend0((float )nTemp);
  1939. setTargetBed((float) nTempBed);
  1940. {
  1941. const FilamentAction action = eFilamentAction;
  1942. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1943. {
  1944. lcd_return_to_status();
  1945. if (action == FilamentAction::Lay1Cal)
  1946. {
  1947. lcd_commands_type = LcdCommands::Layer1Cal;
  1948. }
  1949. else
  1950. {
  1951. raise_z_above(MIN_Z_FOR_PREHEAT);
  1952. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1953. lcd_wizard(WizState::LoadFilHot);
  1954. }
  1955. return;
  1956. }
  1957. }
  1958. lcd_timeoutToStatus.stop();
  1959. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1960. {
  1961. switch (eFilamentAction)
  1962. {
  1963. case FilamentAction::Load:
  1964. case FilamentAction::AutoLoad:
  1965. case FilamentAction::UnLoad:
  1966. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1967. else
  1968. {
  1969. nLevel = bFilamentPreheatState ? 1 : 2;
  1970. menu_back(nLevel);
  1971. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1972. {
  1973. loading_flag = true;
  1974. enquecommand_P(PSTR("M701")); // load filament
  1975. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1976. }
  1977. if (eFilamentAction == FilamentAction::UnLoad)
  1978. enquecommand_P(PSTR("M702")); // unload filament
  1979. }
  1980. break;
  1981. case FilamentAction::MmuLoad:
  1982. nLevel = bFilamentPreheatState ? 1 : 2;
  1983. bFilamentAction = true;
  1984. menu_back(nLevel);
  1985. menu_submenu(mmu_load_to_nozzle_menu);
  1986. break;
  1987. case FilamentAction::MmuUnLoad:
  1988. nLevel = bFilamentPreheatState ? 1 : 2;
  1989. bFilamentAction = true;
  1990. menu_back(nLevel);
  1991. extr_unload();
  1992. break;
  1993. case FilamentAction::MmuEject:
  1994. nLevel = bFilamentPreheatState ? 1 : 2;
  1995. bFilamentAction = true;
  1996. menu_back(nLevel);
  1997. menu_submenu(mmu_fil_eject_menu);
  1998. break;
  1999. case FilamentAction::MmuCut:
  2000. #ifdef MMU_HAS_CUTTER
  2001. nLevel=bFilamentPreheatState?1:2;
  2002. bFilamentAction=true;
  2003. menu_back(nLevel);
  2004. menu_submenu(mmu_cut_filament_menu);
  2005. #endif //MMU_HAS_CUTTER
  2006. break;
  2007. case FilamentAction::None:
  2008. case FilamentAction::Preheat:
  2009. case FilamentAction::Lay1Cal:
  2010. // handled earlier
  2011. break;
  2012. }
  2013. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  2014. bFilamentWaitingFlag = false;
  2015. }
  2016. else
  2017. {
  2018. if (!bFilamentWaitingFlag || lcd_draw_update)
  2019. {
  2020. // First entry from another menu OR first run after the filament preheat selection. Use
  2021. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  2022. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  2023. // modified elsewhere and needs to be redrawn in full.
  2024. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  2025. bool once = !bFilamentWaitingFlag;
  2026. bFilamentWaitingFlag = true;
  2027. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  2028. lcd_draw_update = 1;
  2029. lcd_clear();
  2030. lcd_puts_at_P(0, 3, _T(MSG_CANCEL)); ////MSG_CANCEL
  2031. lcd_set_cursor(0, 1);
  2032. switch (eFilamentAction)
  2033. {
  2034. case FilamentAction::Load:
  2035. case FilamentAction::AutoLoad:
  2036. case FilamentAction::MmuLoad:
  2037. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  2038. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  2039. break;
  2040. case FilamentAction::UnLoad:
  2041. case FilamentAction::MmuUnLoad:
  2042. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  2043. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  2044. break;
  2045. case FilamentAction::MmuEject:
  2046. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  2047. break;
  2048. case FilamentAction::MmuCut:
  2049. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  2050. break;
  2051. case FilamentAction::None:
  2052. case FilamentAction::Preheat:
  2053. case FilamentAction::Lay1Cal:
  2054. // handled earlier
  2055. break;
  2056. }
  2057. }
  2058. if (bFilamentWaitingFlag) {
  2059. lcd_set_cursor(0, 0);
  2060. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  2061. }
  2062. if (lcd_clicked())
  2063. {
  2064. bFilamentWaitingFlag = false;
  2065. if (!bFilamentPreheatState)
  2066. {
  2067. setTargetHotend0(0.0);
  2068. setTargetBed(0.0);
  2069. menu_back();
  2070. }
  2071. else
  2072. {
  2073. setTargetHotend0((float )nTargetOld);
  2074. setTargetBed((float) nTargetBedOld);
  2075. }
  2076. menu_back();
  2077. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2078. }
  2079. }
  2080. }
  2081. static void mFilamentItem_farm()
  2082. {
  2083. bFilamentPreheatState = false;
  2084. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  2085. }
  2086. static void mFilamentItem_farm_nozzle()
  2087. {
  2088. bFilamentPreheatState = false;
  2089. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  2090. }
  2091. static void mFilamentItem_PLA()
  2092. {
  2093. bFilamentPreheatState = false;
  2094. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  2095. }
  2096. static void mFilamentItem_PET()
  2097. {
  2098. bFilamentPreheatState = false;
  2099. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  2100. }
  2101. static void mFilamentItem_ASA()
  2102. {
  2103. bFilamentPreheatState = false;
  2104. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  2105. }
  2106. static void mFilamentItem_PC()
  2107. {
  2108. bFilamentPreheatState = false;
  2109. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  2110. }
  2111. static void mFilamentItem_ABS()
  2112. {
  2113. bFilamentPreheatState = false;
  2114. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  2115. }
  2116. static void mFilamentItem_HIPS()
  2117. {
  2118. bFilamentPreheatState = false;
  2119. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  2120. }
  2121. static void mFilamentItem_PP()
  2122. {
  2123. bFilamentPreheatState = false;
  2124. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  2125. }
  2126. static void mFilamentItem_FLEX()
  2127. {
  2128. bFilamentPreheatState = false;
  2129. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  2130. }
  2131. static void mFilamentItem_PVB()
  2132. {
  2133. bFilamentPreheatState = false;
  2134. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  2135. }
  2136. void mFilamentBack()
  2137. {
  2138. menu_back();
  2139. if (eFilamentAction == FilamentAction::AutoLoad ||
  2140. eFilamentAction == FilamentAction::Preheat ||
  2141. eFilamentAction == FilamentAction::Lay1Cal)
  2142. {
  2143. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2144. }
  2145. }
  2146. void lcd_generic_preheat_menu()
  2147. {
  2148. MENU_BEGIN();
  2149. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  2150. {
  2151. if (eFilamentAction == FilamentAction::Lay1Cal)
  2152. {
  2153. MENU_ITEM_FUNCTION_P(_T(MSG_BACK), mFilamentBack);
  2154. }
  2155. else
  2156. {
  2157. MENU_ITEM_FUNCTION_P(_T(MSG_MAIN), mFilamentBack);
  2158. }
  2159. }
  2160. if (farm_mode)
  2161. {
  2162. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  2163. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  2164. }
  2165. else
  2166. {
  2167. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  2168. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  2169. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  2170. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  2171. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  2172. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  2173. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  2174. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  2175. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  2176. }
  2177. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  2178. MENU_END();
  2179. }
  2180. void mFilamentItemForce()
  2181. {
  2182. mFilamentItem(target_temperature[0],target_temperature_bed);
  2183. }
  2184. void lcd_unLoadFilament()
  2185. {
  2186. eFilamentAction=FilamentAction::UnLoad;
  2187. preheat_or_continue();
  2188. }
  2189. static void mmu_unload_filament()
  2190. {
  2191. eFilamentAction = FilamentAction::MmuUnLoad;
  2192. preheat_or_continue();
  2193. }
  2194. void lcd_wait_interact() {
  2195. lcd_clear();
  2196. lcd_set_cursor(0, 1);
  2197. #ifdef SNMM
  2198. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20
  2199. #else
  2200. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  2201. #endif
  2202. if (!fsensor_autoload_enabled) {
  2203. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  2204. }
  2205. }
  2206. void lcd_change_success() {
  2207. lcd_clear();
  2208. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  2209. }
  2210. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  2211. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  2212. lcd_putc_at(i, 3, '.');
  2213. //loading_time_ms/20 delay
  2214. for (uint_least8_t j = 0; j < 5; j++) {
  2215. delay_keep_alive(loading_time_ms / 100);
  2216. }
  2217. }
  2218. }
  2219. void lcd_loading_color() {
  2220. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  2221. lcd_clear();
  2222. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  2223. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2224. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  2225. }
  2226. void lcd_loading_filament() {
  2227. lcd_clear();
  2228. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  2229. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2230. #ifdef SNMM
  2231. for (int i = 0; i < 20; i++) {
  2232. lcd_set_cursor(i, 3);
  2233. lcd_print('.');
  2234. for (int j = 0; j < 10 ; j++) {
  2235. manage_heater();
  2236. manage_inactivity(true);
  2237. _delay(153);
  2238. }
  2239. }
  2240. #else //SNMM
  2241. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  2242. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  2243. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  2244. #endif //SNMM
  2245. }
  2246. void lcd_alright() {
  2247. int enc_dif = 0;
  2248. int cursor_pos = 1;
  2249. lcd_clear();
  2250. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  2251. lcd_puts_at_P(1, 1, _T(MSG_YES));
  2252. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  2253. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  2254. lcd_putc_at(0, 1, '>');
  2255. enc_dif = lcd_encoder_diff;
  2256. lcd_consume_click();
  2257. while (lcd_change_fil_state == 0) {
  2258. manage_heater();
  2259. manage_inactivity(true);
  2260. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2261. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2262. if (enc_dif > lcd_encoder_diff ) {
  2263. cursor_pos --;
  2264. }
  2265. if (enc_dif < lcd_encoder_diff ) {
  2266. cursor_pos ++;
  2267. }
  2268. if (cursor_pos > 3) {
  2269. cursor_pos = 3;
  2270. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2271. }
  2272. if (cursor_pos < 1) {
  2273. cursor_pos = 1;
  2274. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2275. }
  2276. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  2277. lcd_putc_at(0, cursor_pos, '>');
  2278. enc_dif = lcd_encoder_diff;
  2279. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2280. _delay(100);
  2281. }
  2282. }
  2283. if (lcd_clicked()) {
  2284. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2285. lcd_change_fil_state = cursor_pos;
  2286. _delay(500);
  2287. }
  2288. };
  2289. lcd_clear();
  2290. lcd_return_to_status();
  2291. }
  2292. void show_preheat_nozzle_warning()
  2293. {
  2294. lcd_clear();
  2295. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2296. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2297. _delay(2000);
  2298. lcd_clear();
  2299. }
  2300. void lcd_load_filament_color_check()
  2301. {
  2302. bool clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2303. while (!clean) {
  2304. lcd_update_enable(true);
  2305. lcd_update(2);
  2306. load_filament_final_feed();
  2307. st_synchronize();
  2308. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2309. }
  2310. }
  2311. #ifdef FILAMENT_SENSOR
  2312. static void lcd_menu_AutoLoadFilament()
  2313. {
  2314. uint8_t nlines;
  2315. 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
  2316. menu_back_if_clicked();
  2317. }
  2318. #endif //FILAMENT_SENSOR
  2319. static void preheat_or_continue()
  2320. {
  2321. bFilamentFirstRun = false;
  2322. if (target_temperature[0] >= EXTRUDE_MINTEMP)
  2323. {
  2324. bFilamentPreheatState = true;
  2325. mFilamentItem(target_temperature[0], target_temperature_bed);
  2326. }
  2327. else lcd_generic_preheat_menu();
  2328. }
  2329. static void lcd_LoadFilament()
  2330. {
  2331. eFilamentAction = FilamentAction::Load;
  2332. preheat_or_continue();
  2333. }
  2334. //! @brief Show filament used a print time
  2335. //!
  2336. //! If printing current print statistics are shown
  2337. //!
  2338. //! @code{.unparsed}
  2339. //! |01234567890123456789|
  2340. //! |Filament used: | MSG_FILAMENT_USED c=19
  2341. //! | 0000.00m |
  2342. //! |Print time: | MSG_PRINT_TIME c=19
  2343. //! | 00h 00m 00s |
  2344. //! ----------------------
  2345. //! @endcode
  2346. //!
  2347. //! If not printing, total statistics are shown
  2348. //!
  2349. //! @code{.unparsed}
  2350. //! |01234567890123456789|
  2351. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2352. //! | 0000.00m |
  2353. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2354. //! | 00d 00h 00m |
  2355. //! ----------------------
  2356. //! @endcode
  2357. //! @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".
  2358. void lcd_menu_statistics()
  2359. {
  2360. lcd_timeoutToStatus.stop(); //infinite timeout
  2361. if (IS_SD_PRINTING)
  2362. {
  2363. const float _met = ((float)total_filament_used) / (100000.f);
  2364. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2365. const uint32_t _h = _t / 3600;
  2366. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2367. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2368. lcd_home();
  2369. lcd_printf_P(_N(
  2370. "%S:\n"
  2371. "%18.2fm \n"
  2372. "%S:\n"
  2373. "%10ldh %02dm %02ds"
  2374. ),
  2375. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2376. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2377. menu_back_if_clicked_fb();
  2378. }
  2379. else
  2380. {
  2381. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2382. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2383. uint8_t _hours, _minutes;
  2384. uint32_t _days;
  2385. float _filament_m = (float)_filament/100;
  2386. _days = _time / 1440;
  2387. _hours = (_time - (_days * 1440)) / 60;
  2388. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2389. lcd_home();
  2390. lcd_printf_P(_N(
  2391. "%S:\n"
  2392. "%18.2fm \n"
  2393. "%S:\n"
  2394. "%10ldd %02dh %02dm"
  2395. ),
  2396. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2397. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2398. menu_back_if_clicked_fb();
  2399. }
  2400. }
  2401. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2402. {
  2403. if (homing_flag || mesh_bed_leveling_flag)
  2404. {
  2405. // printer entered a new state where axis move is forbidden
  2406. menu_back();
  2407. return;
  2408. }
  2409. typedef struct
  2410. { // 2bytes total
  2411. bool initialized; // 1byte
  2412. bool endstopsEnabledPrevious; // 1byte
  2413. } _menu_data_t;
  2414. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2415. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2416. if (!_md->initialized)
  2417. {
  2418. _md->endstopsEnabledPrevious = enable_endstops(false);
  2419. _md->initialized = true;
  2420. }
  2421. if (lcd_encoder != 0)
  2422. {
  2423. refresh_cmd_timeout();
  2424. if (! planner_queue_full())
  2425. {
  2426. current_position[axis] += float((int)lcd_encoder);
  2427. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2428. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2429. lcd_encoder = 0;
  2430. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2431. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2432. lcd_draw_update = 1;
  2433. }
  2434. }
  2435. if (lcd_draw_update)
  2436. {
  2437. lcd_set_cursor(0, 1);
  2438. menu_draw_float31(name, current_position[axis]);
  2439. }
  2440. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2441. if (LCD_CLICKED) menu_back();
  2442. }
  2443. void lcd_move_e()
  2444. {
  2445. if (degHotend0() > EXTRUDE_MINTEMP)
  2446. {
  2447. if (lcd_encoder != 0)
  2448. {
  2449. refresh_cmd_timeout();
  2450. if (! planner_queue_full())
  2451. {
  2452. current_position[E_AXIS] += float((int)lcd_encoder);
  2453. lcd_encoder = 0;
  2454. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2455. lcd_draw_update = 1;
  2456. }
  2457. }
  2458. if (lcd_draw_update)
  2459. {
  2460. lcd_set_cursor(0, 1);
  2461. // Note: the colon behind the text is necessary to greatly shorten
  2462. // the implementation of menu_draw_float31
  2463. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2464. }
  2465. if (LCD_CLICKED) menu_back();
  2466. }
  2467. else
  2468. {
  2469. show_preheat_nozzle_warning();
  2470. lcd_return_to_status();
  2471. }
  2472. }
  2473. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2474. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2475. //! This functionality is applied more often for MK2 printers.
  2476. //! @code{.unparsed}
  2477. //! |01234567890123456789|
  2478. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2479. //! | -------------- | STR_SEPARATOR
  2480. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2481. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2482. //! ----------------------
  2483. //! @endcode
  2484. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2485. static void lcd_menu_xyz_y_min()
  2486. {
  2487. float distanceMin[2];
  2488. count_xyz_details(distanceMin);
  2489. lcd_home();
  2490. lcd_printf_P(_N(
  2491. "%S\n"
  2492. "%S\n"
  2493. "%S:\n"
  2494. "%S:"
  2495. ),
  2496. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2497. separator,
  2498. _i("Left"), ////MSG_LEFT c=10
  2499. _i("Right") ////MSG_RIGHT c=10
  2500. );
  2501. for (uint8_t i = 0; i < 2; i++)
  2502. {
  2503. lcd_set_cursor(11,2+i);
  2504. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2505. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2506. }
  2507. if (lcd_clicked())
  2508. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2509. }
  2510. //@brief Show measured axis skewness
  2511. float _deg(float rad)
  2512. {
  2513. return rad * 180 / M_PI;
  2514. }
  2515. //! @brief Show Measured XYZ Skew
  2516. //!
  2517. //! @code{.unparsed}
  2518. //! |01234567890123456789|
  2519. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14, c=4
  2520. //! | -------------- | STR_SEPARATOR
  2521. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14, c=4
  2522. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14, c=4
  2523. //! ----------------------
  2524. //! D - Degree sysmbol LCD_STR_DEGREE
  2525. //! @endcode
  2526. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2527. static void lcd_menu_xyz_skew()
  2528. {
  2529. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2530. lcd_home();
  2531. lcd_printf_P(_N(
  2532. "%-14.14S:\n"
  2533. "%S\n"
  2534. "%-14.14S:%3.2f\x01\n"
  2535. "%-14.14S:%3.2f\x01"
  2536. ),
  2537. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2538. separator,
  2539. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14, c=4
  2540. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14, c=4
  2541. );
  2542. if (angleDiff < 100){
  2543. lcd_set_cursor(15,0);
  2544. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2545. }
  2546. else{
  2547. lcd_puts_at_P(15,0, _T(MSG_NA));
  2548. }
  2549. if (lcd_clicked())
  2550. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2551. }
  2552. //! @brief Show measured bed offset from expected position
  2553. //!
  2554. //! @code{.unparsed}
  2555. //! |01234567890123456789|
  2556. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2557. //! | -------------- | STR_SEPARATOR
  2558. //! |X 00.00mm| c=10
  2559. //! |Y 00.00mm| c=10
  2560. //! ----------------------
  2561. //! @endcode
  2562. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2563. static void lcd_menu_xyz_offset()
  2564. {
  2565. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2566. lcd_puts_at_P(0, 1, separator);
  2567. lcd_puts_at_P(0, 2, PSTR("X"));
  2568. lcd_puts_at_P(0, 3, PSTR("Y"));
  2569. float vec_x[2];
  2570. float vec_y[2];
  2571. float cntr[2];
  2572. world2machine_read_valid(vec_x, vec_y, cntr);
  2573. for (uint_least8_t i = 0; i < 2; i++)
  2574. {
  2575. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2576. lcd_print(cntr[i]);
  2577. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2578. }
  2579. menu_back_if_clicked();
  2580. }
  2581. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2582. // the implementation of menu_draw_float31
  2583. static void lcd_move_x() {
  2584. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2585. }
  2586. static void lcd_move_y() {
  2587. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2588. }
  2589. static void lcd_move_z() {
  2590. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2591. }
  2592. /**
  2593. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2594. *
  2595. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2596. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2597. * Purpose of this function for other axis then Z is unknown.
  2598. *
  2599. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2600. * other value leads to storing Z_AXIS
  2601. * @param msg text to be displayed
  2602. */
  2603. static void lcd_babystep_z()
  2604. {
  2605. if (homing_flag || mesh_bed_leveling_flag)
  2606. {
  2607. // printer changed to a new state where live Z is forbidden
  2608. menu_back();
  2609. return;
  2610. }
  2611. typedef struct
  2612. {
  2613. int8_t status;
  2614. int16_t babystepMemZ;
  2615. float babystepMemMMZ;
  2616. } _menu_data_t;
  2617. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2618. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2619. if (_md->status == 0)
  2620. {
  2621. // Menu was entered.
  2622. // Initialize its status.
  2623. _md->status = 1;
  2624. check_babystep();
  2625. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2626. _md->babystepMemZ = 0;
  2627. }
  2628. else{
  2629. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2630. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2631. }
  2632. // same logic as in babystep_load
  2633. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2634. _md->babystepMemZ = 0;
  2635. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2636. lcd_draw_update = 1;
  2637. //SERIAL_ECHO("Z baby step: ");
  2638. //SERIAL_ECHO(_md->babystepMem[2]);
  2639. // Wait 90 seconds before closing the live adjust dialog.
  2640. lcd_timeoutToStatus.start();
  2641. }
  2642. if (lcd_encoder != 0)
  2643. {
  2644. _md->babystepMemZ += (int)lcd_encoder;
  2645. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2646. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2647. else babystepsTodoZadd(lcd_encoder);
  2648. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2649. _delay(50);
  2650. lcd_encoder = 0;
  2651. lcd_draw_update = 1;
  2652. }
  2653. if (lcd_draw_update)
  2654. {
  2655. SheetFormatBuffer buffer;
  2656. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2657. lcd_set_cursor(0, 0);
  2658. lcd_print(buffer.c);
  2659. lcd_set_cursor(0, 1);
  2660. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character
  2661. }
  2662. if (LCD_CLICKED || menu_leaving)
  2663. {
  2664. // Only update the EEPROM when leaving the menu.
  2665. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2666. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2667. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2668. #ifdef PINDA_THERMISTOR
  2669. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2670. #endif //PINDA_THERMISTOR
  2671. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2672. }
  2673. if (LCD_CLICKED) menu_back();
  2674. }
  2675. typedef struct
  2676. { // 12bytes + 9bytes = 21bytes total
  2677. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2678. int8_t status; // 1byte
  2679. int16_t left; // 2byte
  2680. int16_t right; // 2byte
  2681. int16_t front; // 2byte
  2682. int16_t rear; // 2byte
  2683. } _menu_data_adjust_bed_t;
  2684. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2685. void lcd_adjust_bed_reset(void)
  2686. {
  2687. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2688. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2689. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2690. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2691. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2692. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2693. _md->status = 0;
  2694. }
  2695. //! @brief Show Bed level correct
  2696. //!
  2697. //! @code{.unparsed}
  2698. //! |01234567890123456789|
  2699. //! |Settings: | MSG_SETTINGS
  2700. //! |Left side [um]: | MSG_BED_CORRECTION_LEFT
  2701. //! |Right side[um]: | MSG_BED_CORRECTION_RIGHT
  2702. //! |Front side[um]: | MSG_BED_CORRECTION_FRONT
  2703. //! |Rear side [um]: | MSG_BED_CORRECTION_REAR
  2704. //! |Reset | MSG_BED_CORRECTION_RESET
  2705. //! ----------------------
  2706. //! @endcode
  2707. void lcd_adjust_bed(void)
  2708. {
  2709. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2710. if (_md->status == 0)
  2711. {
  2712. // Menu was entered.
  2713. _md->left = 0;
  2714. _md->right = 0;
  2715. _md->front = 0;
  2716. _md->rear = 0;
  2717. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2718. {
  2719. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2720. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2721. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2722. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2723. }
  2724. _md->status = 1;
  2725. }
  2726. MENU_BEGIN();
  2727. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2728. ON_MENU_LEAVE(
  2729. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2730. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2731. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2732. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2733. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2734. );
  2735. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2736. 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
  2737. 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
  2738. 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
  2739. 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
  2740. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);////MSG_RESET c=14
  2741. MENU_END();
  2742. }
  2743. //! @brief Show PID Extruder
  2744. //!
  2745. //! @code{.unparsed}
  2746. //! |01234567890123456789|
  2747. //! |Set temperature: | MSG_SET_TEMPERATURE c=20
  2748. //! | |
  2749. //! | 210 |
  2750. //! | |
  2751. //! ----------------------
  2752. //! @endcode
  2753. void pid_extruder()
  2754. {
  2755. lcd_clear();
  2756. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE
  2757. pid_temp += int(lcd_encoder);
  2758. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2759. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2760. lcd_encoder = 0;
  2761. lcd_set_cursor(1, 2);
  2762. lcd_print(ftostr3(pid_temp));
  2763. if (lcd_clicked()) {
  2764. lcd_commands_type = LcdCommands::PidExtruder;
  2765. lcd_return_to_status();
  2766. lcd_update(2);
  2767. }
  2768. }
  2769. /*
  2770. void lcd_adjust_z() {
  2771. int enc_dif = 0;
  2772. int cursor_pos = 1;
  2773. int fsm = 0;
  2774. lcd_clear();
  2775. lcd_set_cursor(0, 0);
  2776. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ
  2777. lcd_set_cursor(1, 1);
  2778. lcd_puts_P(_T(MSG_YES));
  2779. lcd_set_cursor(1, 2);
  2780. lcd_puts_P(_T(MSG_NO));
  2781. lcd_set_cursor(0, 1);
  2782. lcd_print('>');
  2783. enc_dif = lcd_encoder_diff;
  2784. while (fsm == 0) {
  2785. manage_heater();
  2786. manage_inactivity(true);
  2787. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2788. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2789. if (enc_dif > lcd_encoder_diff ) {
  2790. cursor_pos --;
  2791. }
  2792. if (enc_dif < lcd_encoder_diff ) {
  2793. cursor_pos ++;
  2794. }
  2795. if (cursor_pos > 2) {
  2796. cursor_pos = 2;
  2797. }
  2798. if (cursor_pos < 1) {
  2799. cursor_pos = 1;
  2800. }
  2801. lcd_set_cursor(0, 1);
  2802. lcd_print(' ');
  2803. lcd_set_cursor(0, 2);
  2804. lcd_print(' ');
  2805. lcd_set_cursor(0, cursor_pos);
  2806. lcd_print('>');
  2807. enc_dif = lcd_encoder_diff;
  2808. _delay(100);
  2809. }
  2810. }
  2811. if (lcd_clicked()) {
  2812. fsm = cursor_pos;
  2813. if (fsm == 1) {
  2814. int babystepLoadZ = 0;
  2815. babystepLoadZ = eeprom_read_word((uint16_t*)EEPROM_BABYSTEP_Z);
  2816. CRITICAL_SECTION_START
  2817. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2818. CRITICAL_SECTION_END
  2819. } else {
  2820. int zero = 0;
  2821. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_X, zero);
  2822. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Y, zero);
  2823. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, zero);
  2824. }
  2825. _delay(500);
  2826. }
  2827. };
  2828. lcd_clear();
  2829. lcd_return_to_status();
  2830. }*/
  2831. #ifdef PINDA_THERMISTOR
  2832. bool lcd_wait_for_pinda(float temp) {
  2833. setAllTargetHotends(0);
  2834. setTargetBed(0);
  2835. LongTimer pinda_timeout;
  2836. pinda_timeout.start();
  2837. bool target_temp_reached = true;
  2838. while (current_temperature_pinda > temp){
  2839. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2840. lcd_set_cursor(0, 4);
  2841. lcd_print(LCD_STR_THERMOMETER[0]);
  2842. lcd_print(ftostr3(current_temperature_pinda));
  2843. lcd_print('/');
  2844. lcd_print(ftostr3(temp));
  2845. lcd_print(LCD_STR_DEGREE[0]);
  2846. delay_keep_alive(1000);
  2847. serialecho_temperatures();
  2848. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2849. target_temp_reached = false;
  2850. break;
  2851. }
  2852. }
  2853. lcd_update_enable(true);
  2854. return target_temp_reached;
  2855. }
  2856. #endif //PINDA_THERMISTOR
  2857. void lcd_wait_for_heater() {
  2858. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2859. lcd_set_cursor(0, 4);
  2860. lcd_print(LCD_STR_THERMOMETER[0]);
  2861. lcd_print(ftostr3(degHotend(active_extruder)));
  2862. lcd_print('/');
  2863. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2864. lcd_print(LCD_STR_DEGREE[0]);
  2865. }
  2866. void lcd_wait_for_cool_down() {
  2867. setAllTargetHotends(0);
  2868. setTargetBed(0);
  2869. int fanSpeedBckp = fanSpeed;
  2870. fanSpeed = 255;
  2871. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2872. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2873. lcd_set_cursor(0, 4);
  2874. lcd_print(LCD_STR_THERMOMETER[0]);
  2875. lcd_print(ftostr3(degHotend(0)));
  2876. lcd_print("/0");
  2877. lcd_print(LCD_STR_DEGREE[0]);
  2878. lcd_set_cursor(9, 4);
  2879. lcd_print(LCD_STR_BEDTEMP[0]);
  2880. lcd_print(ftostr3(degBed()));
  2881. lcd_print("/0");
  2882. lcd_print(LCD_STR_DEGREE[0]);
  2883. delay_keep_alive(1000);
  2884. serialecho_temperatures();
  2885. }
  2886. fanSpeed = fanSpeedBckp;
  2887. lcd_update_enable(true);
  2888. }
  2889. // Lets the user move the Z carriage up to the end stoppers.
  2890. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2891. // Otherwise the Z calibration is not changed and false is returned.
  2892. #ifndef TMC2130
  2893. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2894. {
  2895. // 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.
  2896. current_position[Z_AXIS] = 0;
  2897. plan_set_position_curposXYZE();
  2898. // Until confirmed by the confirmation dialog.
  2899. for (;;) {
  2900. 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
  2901. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2902. const bool multi_screen = msg_next != NULL;
  2903. unsigned long previous_millis_msg = _millis();
  2904. // Until the user finishes the z up movement.
  2905. lcd_encoder_diff = 0;
  2906. lcd_encoder = 0;
  2907. for (;;) {
  2908. manage_heater();
  2909. manage_inactivity(true);
  2910. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2911. _delay(50);
  2912. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2913. lcd_encoder_diff = 0;
  2914. if (! planner_queue_full()) {
  2915. // Only move up, whatever direction the user rotates the encoder.
  2916. current_position[Z_AXIS] += fabs(lcd_encoder);
  2917. lcd_encoder = 0;
  2918. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2919. }
  2920. }
  2921. if (lcd_clicked()) {
  2922. // Abort a move if in progress.
  2923. planner_abort_hard();
  2924. while (lcd_clicked()) ;
  2925. _delay(10);
  2926. while (lcd_clicked()) ;
  2927. break;
  2928. }
  2929. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2930. if (msg_next == NULL)
  2931. msg_next = msg;
  2932. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2933. previous_millis_msg = _millis();
  2934. }
  2935. }
  2936. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2937. 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
  2938. if (result == -1)
  2939. goto canceled;
  2940. else if (result == 1)
  2941. goto calibrated;
  2942. // otherwise perform another round of the Z up dialog.
  2943. }
  2944. calibrated:
  2945. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2946. // during the search for the induction points.
  2947. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2948. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2949. }
  2950. else {
  2951. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2952. }
  2953. plan_set_position_curposXYZE();
  2954. return true;
  2955. canceled:
  2956. return false;
  2957. }
  2958. #endif // TMC2130
  2959. static inline bool pgm_is_whitespace(const char *c_addr)
  2960. {
  2961. const char c = pgm_read_byte(c_addr);
  2962. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2963. }
  2964. static inline bool pgm_is_interpunction(const char *c_addr)
  2965. {
  2966. const char c = pgm_read_byte(c_addr);
  2967. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2968. }
  2969. /**
  2970. * @brief show full screen message
  2971. *
  2972. * This function is non-blocking
  2973. * @param msg message to be displayed from PROGMEM
  2974. * @param nlines
  2975. * @return rest of the text (to be displayed on next page)
  2976. */
  2977. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2978. {
  2979. lcd_set_cursor(0, 0);
  2980. const char *msgend = msg;
  2981. uint8_t row = 0;
  2982. bool multi_screen = false;
  2983. for (; row < 4; ++ row) {
  2984. while (pgm_is_whitespace(msg))
  2985. ++ msg;
  2986. if (pgm_read_byte(msg) == 0)
  2987. // End of the message.
  2988. break;
  2989. lcd_set_cursor(0, row);
  2990. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  2991. const char *msgend2 = msg + linelen;
  2992. msgend = msgend2;
  2993. if (row == 3 && linelen == LCD_WIDTH) {
  2994. // Last line of the display, full line shall be displayed.
  2995. // Find out, whether this message will be split into multiple screens.
  2996. while (pgm_is_whitespace(msgend))
  2997. ++ msgend;
  2998. multi_screen = pgm_read_byte(msgend) != 0;
  2999. if (multi_screen)
  3000. msgend = (msgend2 -= 2);
  3001. }
  3002. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  3003. // Splitting a word. Find the start of the current word.
  3004. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  3005. -- msgend;
  3006. if (msgend == msg)
  3007. // Found a single long word, which cannot be split. Just cut it.
  3008. msgend = msgend2;
  3009. }
  3010. for (; msg < msgend; ++ msg) {
  3011. char c = char(pgm_read_byte(msg));
  3012. if (c == '~')
  3013. c = ' ';
  3014. lcd_print(c);
  3015. }
  3016. }
  3017. if (multi_screen) {
  3018. // Display the "next screen" indicator character.
  3019. lcd_set_custom_characters_nextpage();
  3020. lcd_set_cursor(19, 3);
  3021. // Display the double down arrow.
  3022. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  3023. }
  3024. nlines = row;
  3025. return multi_screen ? msgend : NULL;
  3026. }
  3027. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  3028. {
  3029. // Disable update of the screen by the usual lcd_update(0) routine.
  3030. lcd_update_enable(false);
  3031. lcd_clear();
  3032. // uint8_t nlines;
  3033. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  3034. }
  3035. const char* lcd_display_message_fullscreen_P(const char *msg)
  3036. {
  3037. uint8_t nlines;
  3038. return lcd_display_message_fullscreen_P(msg, nlines);
  3039. }
  3040. /**
  3041. * @brief show full screen message and wait
  3042. *
  3043. * This function is blocking.
  3044. * @param msg message to be displayed from PROGMEM
  3045. */
  3046. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  3047. {
  3048. LcdUpdateDisabler lcdUpdateDisabler;
  3049. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3050. bool multi_screen = msg_next != NULL;
  3051. lcd_set_custom_characters_nextpage();
  3052. lcd_consume_click();
  3053. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3054. // Until confirmed by a button click.
  3055. for (;;) {
  3056. if (!multi_screen) {
  3057. lcd_set_cursor(19, 3);
  3058. // Display the confirm char.
  3059. lcd_print(LCD_STR_CONFIRM[0]);
  3060. }
  3061. // Wait for 5 seconds before displaying the next text.
  3062. for (uint8_t i = 0; i < 100; ++ i) {
  3063. delay_keep_alive(50);
  3064. if (lcd_clicked()) {
  3065. if (msg_next == NULL) {
  3066. KEEPALIVE_STATE(IN_HANDLER);
  3067. lcd_set_custom_characters();
  3068. lcd_update_enable(true);
  3069. lcd_update(2);
  3070. return;
  3071. }
  3072. else {
  3073. break;
  3074. }
  3075. }
  3076. }
  3077. if (multi_screen) {
  3078. if (msg_next == NULL)
  3079. msg_next = msg;
  3080. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3081. if (msg_next == NULL) {
  3082. lcd_set_cursor(19, 3);
  3083. // Display the confirm char.
  3084. lcd_print(LCD_STR_CONFIRM[0]);
  3085. }
  3086. }
  3087. }
  3088. }
  3089. bool lcd_wait_for_click_delay(uint16_t nDelay)
  3090. // nDelay :: timeout [s] (0 ~ no timeout)
  3091. // true ~ clicked, false ~ delayed
  3092. {
  3093. bool bDelayed;
  3094. long nTime0 = _millis()/1000;
  3095. lcd_consume_click();
  3096. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3097. for (;;) {
  3098. manage_heater();
  3099. manage_inactivity(true);
  3100. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  3101. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  3102. if (lcd_clicked() || bDelayed) {
  3103. KEEPALIVE_STATE(IN_HANDLER);
  3104. return(!bDelayed);
  3105. }
  3106. }
  3107. }
  3108. void lcd_wait_for_click()
  3109. {
  3110. lcd_wait_for_click_delay(0);
  3111. }
  3112. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  3113. //! @param msg Message to show
  3114. //! @param allow_timeouting if true, allows time outing of the screen
  3115. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3116. //! @retval 1 yes choice selected by user
  3117. //! @retval 0 no choice selected by user
  3118. //! @retval -1 screen timed out
  3119. 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)
  3120. {
  3121. return lcd_show_multiscreen_message_two_choices_and_wait_P(msg, allow_timeouting, default_yes, _T(MSG_YES), _T(MSG_NO));
  3122. }
  3123. //! @brief Show multiple screen message with two possible choices and wait with possible timeout
  3124. //! @param msg Message to show
  3125. //! @param allow_timeouting if true, allows time outing of the screen
  3126. //! @param default_first if true, fist choice is selected by default, otherwise second choice is preselected
  3127. //! @param first_choice text caption of first possible choice
  3128. //! @param second_choice text caption of second possible choice
  3129. //! @retval 1 first choice selected by user
  3130. //! @retval 0 second choice selected by user
  3131. //! @retval -1 screen timed out
  3132. int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_first,
  3133. const char *first_choice, const char *second_choice)
  3134. {
  3135. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3136. bool multi_screen = msg_next != NULL;
  3137. bool yes = default_first ? true : false;
  3138. // Wait for user confirmation or a timeout.
  3139. unsigned long previous_millis_cmd = _millis();
  3140. int8_t enc_dif = lcd_encoder_diff;
  3141. lcd_consume_click();
  3142. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  3143. for (;;) {
  3144. for (uint8_t i = 0; i < 100; ++i) {
  3145. delay_keep_alive(50);
  3146. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3147. return -1;
  3148. manage_heater();
  3149. manage_inactivity(true);
  3150. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3151. if (msg_next == NULL) {
  3152. lcd_set_cursor(0, 3);
  3153. if (enc_dif < lcd_encoder_diff && yes) {
  3154. lcd_print(' ');
  3155. lcd_putc_at(7, 3, '>');
  3156. yes = false;
  3157. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3158. }
  3159. else if (enc_dif > lcd_encoder_diff && !yes) {
  3160. lcd_print('>');
  3161. lcd_putc_at(7, 3, ' ');
  3162. yes = true;
  3163. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3164. }
  3165. enc_dif = lcd_encoder_diff;
  3166. }
  3167. else {
  3168. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  3169. break; //turning knob skips waiting loop
  3170. }
  3171. }
  3172. if (lcd_clicked()) {
  3173. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3174. if (msg_next == NULL) {
  3175. //KEEPALIVE_STATE(IN_HANDLER);
  3176. lcd_set_custom_characters();
  3177. return yes;
  3178. }
  3179. else break;
  3180. }
  3181. }
  3182. if (multi_screen) {
  3183. if (msg_next == NULL) {
  3184. msg_next = msg;
  3185. }
  3186. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3187. }
  3188. if (msg_next == NULL) {
  3189. lcd_set_cursor(0, 3);
  3190. if (yes) lcd_print('>');
  3191. lcd_puts_at_P(1, 3, first_choice);
  3192. lcd_set_cursor(7, 3);
  3193. if (!yes) lcd_print('>');
  3194. lcd_puts_at_P(8, 3, second_choice);
  3195. }
  3196. }
  3197. }
  3198. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  3199. //! @param msg Message to show
  3200. //! @param allow_timeouting if true, allows time outing of the screen
  3201. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3202. //! @retval 1 yes choice selected by user
  3203. //! @retval 0 no choice selected by user
  3204. //! @retval -1 screen timed out
  3205. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  3206. {
  3207. lcd_display_message_fullscreen_P(msg);
  3208. if (default_yes) {
  3209. lcd_putc_at(0, 2, '>');
  3210. lcd_puts_P(_T(MSG_YES));
  3211. lcd_puts_at_P(1, 3, _T(MSG_NO));
  3212. }
  3213. else {
  3214. lcd_puts_at_P(1, 2, _T(MSG_YES));
  3215. lcd_putc_at(0, 3, '>');
  3216. lcd_puts_P(_T(MSG_NO));
  3217. }
  3218. int8_t retval = default_yes ? true : false;
  3219. // Wait for user confirmation or a timeout.
  3220. unsigned long previous_millis_cmd = _millis();
  3221. int8_t enc_dif = lcd_encoder_diff;
  3222. lcd_consume_click();
  3223. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3224. for (;;) {
  3225. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3226. {
  3227. retval = -1;
  3228. break;
  3229. }
  3230. manage_heater();
  3231. manage_inactivity(true);
  3232. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3233. lcd_set_cursor(0, 2);
  3234. if (enc_dif < lcd_encoder_diff && retval) {
  3235. lcd_print(' ');
  3236. lcd_putc_at(0, 3, '>');
  3237. retval = 0;
  3238. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3239. }
  3240. else if (enc_dif > lcd_encoder_diff && !retval) {
  3241. lcd_print('>');
  3242. lcd_putc_at(0, 3, ' ');
  3243. retval = 1;
  3244. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3245. }
  3246. enc_dif = lcd_encoder_diff;
  3247. }
  3248. if (lcd_clicked()) {
  3249. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3250. KEEPALIVE_STATE(IN_HANDLER);
  3251. break;
  3252. }
  3253. }
  3254. lcd_encoder_diff = 0;
  3255. return retval;
  3256. }
  3257. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  3258. {
  3259. const char *msg = NULL;
  3260. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3261. 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
  3262. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3263. if (point_too_far_mask == 0)
  3264. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3265. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3266. // Only the center point or all the three front points.
  3267. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  3268. else if ((point_too_far_mask & 1) == 0)
  3269. // The right and maybe the center point out of reach.
  3270. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  3271. else
  3272. // The left and maybe the center point out of reach.
  3273. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3274. lcd_show_fullscreen_message_and_wait_P(msg);
  3275. } else {
  3276. if (point_too_far_mask != 0) {
  3277. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3278. // Only the center point or all the three front points.
  3279. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3280. else if ((point_too_far_mask & 1) == 0)
  3281. // The right and maybe the center point out of reach.
  3282. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3283. else
  3284. // The left and maybe the center point out of reach.
  3285. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3286. lcd_show_fullscreen_message_and_wait_P(msg);
  3287. }
  3288. if (point_too_far_mask == 0 || result > 0) {
  3289. switch (result) {
  3290. default:
  3291. // should not happen
  3292. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3293. break;
  3294. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3295. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3296. break;
  3297. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3298. 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
  3299. break;
  3300. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3301. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3302. break;
  3303. }
  3304. lcd_show_fullscreen_message_and_wait_P(msg);
  3305. }
  3306. }
  3307. }
  3308. void lcd_temp_cal_show_result(bool result) {
  3309. custom_message_type = CustomMsg::Status;
  3310. disable_x();
  3311. disable_y();
  3312. disable_z();
  3313. disable_e0();
  3314. disable_e1();
  3315. disable_e2();
  3316. setTargetBed(0); //set bed target temperature back to 0
  3317. if (result == true) {
  3318. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3319. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3320. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3321. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3322. }
  3323. else {
  3324. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3325. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3326. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3327. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3328. }
  3329. lcd_update_enable(true);
  3330. lcd_update(2);
  3331. }
  3332. static void lcd_show_end_stops() {
  3333. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3334. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3335. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3336. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3337. }
  3338. #ifndef TMC2130
  3339. static void menu_show_end_stops() {
  3340. lcd_show_end_stops();
  3341. if (LCD_CLICKED) menu_back();
  3342. }
  3343. #endif // not defined TMC2130
  3344. // Lets the user move the Z carriage up to the end stoppers.
  3345. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3346. // Otherwise the Z calibration is not changed and false is returned.
  3347. void lcd_diag_show_end_stops()
  3348. {
  3349. lcd_clear();
  3350. lcd_consume_click();
  3351. for (;;) {
  3352. manage_heater();
  3353. manage_inactivity(true);
  3354. lcd_show_end_stops();
  3355. if (lcd_clicked()) {
  3356. break;
  3357. }
  3358. }
  3359. lcd_clear();
  3360. lcd_return_to_status();
  3361. }
  3362. static void lcd_print_state(uint8_t state)
  3363. {
  3364. switch (state) {
  3365. case STATE_ON:
  3366. lcd_puts_P(_N(" 1"));
  3367. break;
  3368. case STATE_OFF:
  3369. lcd_puts_P(_N(" 0"));
  3370. break;
  3371. default:
  3372. lcd_puts_P(_T(MSG_NA));
  3373. break;
  3374. }
  3375. }
  3376. //! @brief Show sensor state
  3377. //!
  3378. //! @code{.unparsed}
  3379. //! |01234567890123456789|
  3380. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  3381. //! |Fil. sensor N/A| MSG_FSENSOR
  3382. //! |Xd 000 Yd 000| MSG_XD
  3383. //! |Int 000 Shut 000|
  3384. //! ----------------------
  3385. //! @endcode
  3386. static void lcd_show_sensors_state()
  3387. {
  3388. //0: N/A; 1: OFF; 2: ON
  3389. uint8_t pinda_state = STATE_NA;
  3390. uint8_t finda_state = STATE_NA;
  3391. uint8_t idler_state = STATE_NA;
  3392. pinda_state = READ(Z_MIN_PIN);
  3393. if (mmu_enabled && mmu_last_finda_response.expired(1000))
  3394. {
  3395. finda_state = mmu_finda;
  3396. }
  3397. //lcd_puts_at_P(0, 0, _i("Sensor state"));
  3398. lcd_puts_at_P(0, 0, _T(MSG_PINDA));
  3399. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3400. lcd_print_state(pinda_state);
  3401. if (mmu_enabled == true)
  3402. {
  3403. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3404. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3405. lcd_print_state(finda_state);
  3406. }
  3407. if (ir_sensor_detected) {
  3408. idler_state = !READ(IR_SENSOR_PIN);
  3409. lcd_puts_at_P(0, 1, _i("Fil. sensor"));
  3410. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3411. lcd_print_state(idler_state);
  3412. }
  3413. #ifdef PAT9125
  3414. // Display X and Y difference from Filament sensor
  3415. // Display Light intensity from Filament sensor
  3416. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3417. // value ranges from 0(darkest) to 255(brightest).
  3418. // Display LASER shutter time from Filament sensor
  3419. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3420. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  3421. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  3422. if (mmu_enabled == false)
  3423. {
  3424. //if (!fsensor_enabled)
  3425. // lcd_puts_P(_N("Filament sensor\n" "is disabled."));
  3426. //else
  3427. //{
  3428. if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  3429. pat9125_update();
  3430. lcd_set_cursor(0, 2);
  3431. lcd_printf_P(_N(
  3432. "Xd: %3d "
  3433. "Yd: %3d\n" ////c=4
  3434. "Int: %3d " ////c=4
  3435. "Shut: %3d" ////c=4
  3436. ),
  3437. pat9125_x, pat9125_y,
  3438. pat9125_b, pat9125_s
  3439. );
  3440. //}
  3441. }
  3442. #endif //PAT9125
  3443. }
  3444. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3445. {
  3446. lcd_timeoutToStatus.stop();
  3447. lcd_show_sensors_state();
  3448. if(LCD_CLICKED)
  3449. {
  3450. lcd_timeoutToStatus.start();
  3451. menu_back();
  3452. }
  3453. }
  3454. void prusa_statistics_err(char c){
  3455. SERIAL_ECHOPGM("{[ERR:");
  3456. SERIAL_ECHO(c);
  3457. SERIAL_ECHO(']');
  3458. prusa_stat_farm_number();
  3459. }
  3460. static void prusa_statistics_case0(uint8_t statnr){
  3461. SERIAL_ECHO('{');
  3462. prusa_stat_printerstatus(statnr);
  3463. prusa_stat_farm_number();
  3464. prusa_stat_printinfo();
  3465. }
  3466. void prusa_statistics(uint8_t _message, uint8_t _fil_nr) {
  3467. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3468. return;
  3469. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3470. switch (_message)
  3471. {
  3472. case 0: // default message
  3473. if (busy_state == PAUSED_FOR_USER)
  3474. {
  3475. prusa_statistics_case0(15);
  3476. }
  3477. else if (isPrintPaused)
  3478. {
  3479. prusa_statistics_case0(14);
  3480. }
  3481. else if (IS_SD_PRINTING || loading_flag)
  3482. {
  3483. prusa_statistics_case0(4);
  3484. }
  3485. else
  3486. {
  3487. SERIAL_ECHO('{');
  3488. prusa_stat_printerstatus(1);
  3489. prusa_stat_farm_number();
  3490. prusa_stat_diameter();
  3491. status_number = 1;
  3492. }
  3493. break;
  3494. case 1: // 1 heating
  3495. SERIAL_ECHO('{');
  3496. prusa_stat_printerstatus(2);
  3497. prusa_stat_farm_number();
  3498. status_number = 2;
  3499. farm_timer = 1;
  3500. break;
  3501. case 2: // heating done
  3502. SERIAL_ECHO('{');
  3503. prusa_stat_printerstatus(3);
  3504. prusa_stat_farm_number();
  3505. SERIAL_ECHOLN('}');
  3506. status_number = 3;
  3507. farm_timer = 1;
  3508. if (IS_SD_PRINTING || loading_flag)
  3509. {
  3510. SERIAL_ECHO('{');
  3511. prusa_stat_printerstatus(4);
  3512. prusa_stat_farm_number();
  3513. status_number = 4;
  3514. }
  3515. else
  3516. {
  3517. SERIAL_ECHO('{');
  3518. prusa_stat_printerstatus(3);
  3519. prusa_stat_farm_number();
  3520. status_number = 3;
  3521. }
  3522. farm_timer = 1;
  3523. break;
  3524. case 3: // filament change
  3525. // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function
  3526. // saved a considerable amount of FLASH
  3527. return;
  3528. break;
  3529. case 4: // print succesfull
  3530. SERIAL_ECHOPGM("{[RES:1][FIL:");
  3531. MYSERIAL.print(int(_fil_nr));
  3532. SERIAL_ECHO(']');
  3533. prusa_stat_printerstatus(status_number);
  3534. prusa_stat_farm_number();
  3535. farm_timer = 2;
  3536. break;
  3537. case 5: // print not succesfull
  3538. SERIAL_ECHOPGM("{[RES:0][FIL:");
  3539. MYSERIAL.print(int(_fil_nr));
  3540. SERIAL_ECHO(']');
  3541. prusa_stat_printerstatus(status_number);
  3542. prusa_stat_farm_number();
  3543. farm_timer = 2;
  3544. break;
  3545. case 6: // print done
  3546. SERIAL_ECHOPGM("{[PRN:8]");
  3547. prusa_stat_farm_number();
  3548. status_number = 8;
  3549. farm_timer = 2;
  3550. break;
  3551. case 7: // print done - stopped
  3552. SERIAL_ECHOPGM("{[PRN:9]");
  3553. prusa_stat_farm_number();
  3554. status_number = 9;
  3555. farm_timer = 2;
  3556. break;
  3557. case 8: // printer started
  3558. SERIAL_ECHOPGM("{[PRN:0]");
  3559. prusa_stat_farm_number();
  3560. status_number = 0;
  3561. farm_timer = 2;
  3562. break;
  3563. case 20: // echo farm no
  3564. SERIAL_ECHO('{');
  3565. prusa_stat_printerstatus(status_number);
  3566. prusa_stat_farm_number();
  3567. farm_timer = 4;
  3568. break;
  3569. case 21: // temperatures
  3570. SERIAL_ECHO('{');
  3571. prusa_stat_temperatures();
  3572. prusa_stat_farm_number();
  3573. prusa_stat_printerstatus(status_number);
  3574. break;
  3575. case 22: // waiting for filament change
  3576. SERIAL_ECHOPGM("{[PRN:5]");
  3577. prusa_stat_farm_number();
  3578. status_number = 5;
  3579. break;
  3580. case 90: // Error - Thermal Runaway
  3581. prusa_statistics_err('1');
  3582. break;
  3583. case 91: // Error - Thermal Runaway Preheat
  3584. prusa_statistics_err('2');
  3585. break;
  3586. case 92: // Error - Min temp
  3587. prusa_statistics_err('3');
  3588. break;
  3589. case 93: // Error - Max temp
  3590. prusa_statistics_err('4');
  3591. break;
  3592. case 99: // heartbeat
  3593. SERIAL_ECHOPGM("{[PRN:99]");
  3594. prusa_stat_temperatures();
  3595. prusa_stat_farm_number();
  3596. break;
  3597. }
  3598. SERIAL_ECHOLN('}');
  3599. }
  3600. static void prusa_stat_printerstatus(uint8_t _status)
  3601. {
  3602. SERIAL_ECHOPGM("[PRN:");
  3603. SERIAL_ECHO(_status);
  3604. SERIAL_ECHO(']');
  3605. }
  3606. static void prusa_stat_farm_number() {
  3607. SERIAL_ECHOPGM("[PFN:0]");
  3608. }
  3609. static void prusa_stat_diameter() {
  3610. SERIAL_ECHOPGM("[DIA:");
  3611. SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
  3612. SERIAL_ECHO(']');
  3613. }
  3614. static void prusa_stat_temperatures()
  3615. {
  3616. SERIAL_ECHOPGM("[ST0:");
  3617. SERIAL_ECHO(target_temperature[0]);
  3618. SERIAL_ECHOPGM("][STB:");
  3619. SERIAL_ECHO(target_temperature_bed);
  3620. SERIAL_ECHOPGM("][AT0:");
  3621. SERIAL_ECHO(current_temperature[0]);
  3622. SERIAL_ECHOPGM("][ATB:");
  3623. SERIAL_ECHO(current_temperature_bed);
  3624. SERIAL_ECHO(']');
  3625. }
  3626. static void prusa_stat_printinfo()
  3627. {
  3628. SERIAL_ECHOPGM("[TFU:");
  3629. SERIAL_ECHO(total_filament_used);
  3630. SERIAL_ECHOPGM("][PCD:");
  3631. SERIAL_ECHO(itostr3(card.percentDone()));
  3632. SERIAL_ECHOPGM("][FEM:");
  3633. SERIAL_ECHO(itostr3(feedmultiply));
  3634. SERIAL_ECHOPGM("][FNM:");
  3635. SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename);
  3636. SERIAL_ECHOPGM("][TIM:");
  3637. if (starttime != 0)
  3638. {
  3639. SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
  3640. }
  3641. else
  3642. {
  3643. SERIAL_ECHO(0);
  3644. }
  3645. SERIAL_ECHOPGM("][FWR:");
  3646. SERIAL_ECHORPGM(FW_VERSION_STR_P());
  3647. SERIAL_ECHO(']');
  3648. prusa_stat_diameter();
  3649. }
  3650. /*
  3651. void lcd_pick_babystep(){
  3652. int enc_dif = 0;
  3653. int cursor_pos = 1;
  3654. int fsm = 0;
  3655. lcd_clear();
  3656. lcd_set_cursor(0, 0);
  3657. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z
  3658. lcd_set_cursor(3, 2);
  3659. lcd_print('1');
  3660. lcd_set_cursor(3, 3);
  3661. lcd_print('2');
  3662. lcd_set_cursor(12, 2);
  3663. lcd_print('3');
  3664. lcd_set_cursor(12, 3);
  3665. lcd_print('4');
  3666. lcd_set_cursor(1, 2);
  3667. lcd_print('>');
  3668. enc_dif = lcd_encoder_diff;
  3669. while (fsm == 0) {
  3670. manage_heater();
  3671. manage_inactivity(true);
  3672. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3673. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3674. if (enc_dif > lcd_encoder_diff ) {
  3675. cursor_pos --;
  3676. }
  3677. if (enc_dif < lcd_encoder_diff ) {
  3678. cursor_pos ++;
  3679. }
  3680. if (cursor_pos > 4) {
  3681. cursor_pos = 4;
  3682. }
  3683. if (cursor_pos < 1) {
  3684. cursor_pos = 1;
  3685. }
  3686. lcd_set_cursor(1, 2);
  3687. lcd_print(' ');
  3688. lcd_set_cursor(1, 3);
  3689. lcd_print(' ');
  3690. lcd_set_cursor(10, 2);
  3691. lcd_print(' ');
  3692. lcd_set_cursor(10, 3);
  3693. lcd_print(' ');
  3694. if (cursor_pos < 3) {
  3695. lcd_set_cursor(1, cursor_pos+1);
  3696. lcd_print('>');
  3697. }else{
  3698. lcd_set_cursor(10, cursor_pos-1);
  3699. lcd_print('>');
  3700. }
  3701. enc_dif = lcd_encoder_diff;
  3702. _delay(100);
  3703. }
  3704. }
  3705. if (lcd_clicked()) {
  3706. fsm = cursor_pos;
  3707. int babyStepZ;
  3708. babyStepZ = eeprom_read_word((uint16_t*)EEPROM_BABYSTEP_Z0+(fsm-1));
  3709. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, babyStepZ);
  3710. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3711. _delay(500);
  3712. }
  3713. };
  3714. lcd_clear();
  3715. lcd_return_to_status();
  3716. }
  3717. */
  3718. void lcd_move_menu_axis()
  3719. {
  3720. MENU_BEGIN();
  3721. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3722. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=18
  3723. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=18
  3724. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=18
  3725. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);
  3726. MENU_END();
  3727. }
  3728. #ifdef SDCARD_SORT_ALPHA
  3729. static void lcd_sort_type_set() {
  3730. uint8_t sdSort;
  3731. sdSort = eeprom_read_byte((uint8_t*) EEPROM_SD_SORT);
  3732. switch (sdSort) {
  3733. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3734. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3735. default: sdSort = SD_SORT_TIME;
  3736. }
  3737. eeprom_update_byte((uint8_t*)EEPROM_SD_SORT, sdSort);
  3738. card.presort_flag = true;
  3739. }
  3740. #endif //SDCARD_SORT_ALPHA
  3741. #ifdef TMC2130
  3742. static void lcd_crash_mode_info()
  3743. {
  3744. lcd_update_enable(true);
  3745. static uint32_t tim = 0;
  3746. if ((tim + 1000) < _millis())
  3747. {
  3748. lcd_clear();
  3749. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3750. tim = _millis();
  3751. }
  3752. menu_back_if_clicked();
  3753. }
  3754. static void lcd_crash_mode_info2()
  3755. {
  3756. lcd_update_enable(true);
  3757. static uint32_t tim = 0;
  3758. if ((tim + 1000) < _millis())
  3759. {
  3760. lcd_clear();
  3761. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3762. tim = _millis();
  3763. }
  3764. menu_back_if_clicked();
  3765. }
  3766. #endif //TMC2130
  3767. #ifdef FILAMENT_SENSOR
  3768. static void lcd_filament_autoload_info()
  3769. {
  3770. uint8_t nlines;
  3771. lcd_update_enable(true);
  3772. static uint32_t tim = 0;
  3773. if ((tim + 1000) < _millis())
  3774. {
  3775. 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
  3776. tim = _millis();
  3777. }
  3778. menu_back_if_clicked();
  3779. }
  3780. static void lcd_fsensor_fail()
  3781. {
  3782. uint8_t nlines;
  3783. lcd_update_enable(true);
  3784. static uint32_t tim = 0;
  3785. if ((tim + 1000) < _millis())
  3786. {
  3787. 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
  3788. tim = _millis();
  3789. }
  3790. menu_back_if_clicked();
  3791. }
  3792. #endif //FILAMENT_SENSOR
  3793. //-//
  3794. static void lcd_sound_state_set(void)
  3795. {
  3796. Sound_CycleState();
  3797. }
  3798. #ifndef MMU_FORCE_STEALTH_MODE
  3799. static void lcd_silent_mode_mmu_set() {
  3800. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3801. else SilentModeMenu_MMU = 1;
  3802. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3803. }
  3804. #endif //MMU_FORCE_STEALTH_MODE
  3805. static void lcd_silent_mode_set() {
  3806. switch (SilentModeMenu) {
  3807. #ifdef TMC2130
  3808. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3809. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3810. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3811. #else
  3812. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3813. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3814. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3815. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3816. #endif //TMC2130
  3817. }
  3818. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3819. #ifdef TMC2130
  3820. lcd_display_message_fullscreen_P(_i("Mode change in progress..."));////MSG_MODE_CHANGE_IN_PROGRESS c=20 r=3
  3821. // Wait until the planner queue is drained and the stepper routine achieves
  3822. // an idle state.
  3823. st_synchronize();
  3824. if (tmc2130_wait_standstill_xy(1000)) {}
  3825. // MYSERIAL.print("standstill OK");
  3826. // else
  3827. // MYSERIAL.print("standstill NG!");
  3828. cli();
  3829. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3830. update_mode_profile();
  3831. tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  3832. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3833. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3834. st_reset_timer();
  3835. sei();
  3836. #endif //TMC2130
  3837. st_current_init();
  3838. #ifdef TMC2130
  3839. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3840. menu_submenu(lcd_crash_mode_info2);
  3841. lcd_encoder_diff=0; // reset 'encoder buffer'
  3842. #endif //TMC2130
  3843. }
  3844. #ifdef TMC2130
  3845. static void crash_mode_switch()
  3846. {
  3847. if (lcd_crash_detect_enabled())
  3848. {
  3849. lcd_crash_detect_disable();
  3850. }
  3851. else
  3852. {
  3853. lcd_crash_detect_enable();
  3854. }
  3855. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3856. else menu_goto(lcd_settings_menu, 9, true, true);
  3857. }
  3858. #endif //TMC2130
  3859. #ifdef FILAMENT_SENSOR
  3860. static void lcd_fsensor_state_set()
  3861. {
  3862. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3863. if (!FSensorStateMenu) {
  3864. fsensor_disable();
  3865. if (fsensor_autoload_enabled && !mmu_enabled)
  3866. menu_submenu(lcd_filament_autoload_info);
  3867. }
  3868. else {
  3869. fsensor_enable();
  3870. if (fsensor_not_responding && !mmu_enabled)
  3871. menu_submenu(lcd_fsensor_fail);
  3872. }
  3873. }
  3874. #endif //FILAMENT_SENSOR
  3875. #if (LANG_MODE != 0)
  3876. void menu_setlang(unsigned char lang)
  3877. {
  3878. if (!lang_select(lang))
  3879. {
  3880. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, true))////MSG_COPY_SEL_LANG c=20 r=3
  3881. lang_boot_update_start(lang);
  3882. lcd_update_enable(true);
  3883. lcd_clear();
  3884. menu_goto(lcd_language_menu, 0, true, true);
  3885. lcd_timeoutToStatus.stop(); //infinite timeout
  3886. lcd_draw_update = 2;
  3887. }
  3888. }
  3889. #ifdef COMMUNITY_LANG_SUPPORT
  3890. #ifdef XFLASH
  3891. static void lcd_community_language_menu()
  3892. {
  3893. MENU_BEGIN();
  3894. uint8_t cnt = lang_get_count();
  3895. MENU_ITEM_BACK_P(_i("Select language")); //Back to previous Menu
  3896. for (int i = 8; i < cnt; i++) //all community languages
  3897. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3898. {
  3899. menu_setlang(i);
  3900. return;
  3901. }
  3902. MENU_END();
  3903. }
  3904. #endif //XFLASH
  3905. #endif //COMMUNITY_LANG_SUPPORT && W52X20CL
  3906. static void lcd_language_menu()
  3907. {
  3908. MENU_BEGIN();
  3909. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3910. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3911. {
  3912. menu_setlang(0);
  3913. return;
  3914. }
  3915. uint8_t cnt = lang_get_count();
  3916. #ifdef XFLASH
  3917. if (cnt == 2) //display secondary language in case of clear xflash
  3918. {
  3919. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3920. {
  3921. menu_setlang(1);
  3922. return;
  3923. }
  3924. }
  3925. else
  3926. for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
  3927. #else //XFLASH
  3928. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3929. #endif //XFLASH
  3930. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3931. {
  3932. menu_setlang(i);
  3933. return;
  3934. }
  3935. #ifdef COMMUNITY_LANG_SUPPORT
  3936. #ifdef XFLASH
  3937. MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu); ////MSG_COMMUNITY_MADE c=18
  3938. #endif //XFLASH
  3939. #endif //COMMUNITY_LANG_SUPPORT && W52X20CL
  3940. MENU_END();
  3941. }
  3942. #endif //(LANG_MODE != 0)
  3943. void lcd_mesh_bedleveling()
  3944. {
  3945. enquecommand_P(PSTR("G80"));
  3946. lcd_return_to_status();
  3947. }
  3948. void lcd_mesh_calibration()
  3949. {
  3950. enquecommand_P(PSTR("M45"));
  3951. lcd_return_to_status();
  3952. }
  3953. void lcd_mesh_calibration_z()
  3954. {
  3955. enquecommand_P(PSTR("M45 Z"));
  3956. lcd_return_to_status();
  3957. }
  3958. void lcd_pinda_calibration_menu()
  3959. {
  3960. MENU_BEGIN();
  3961. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3962. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17
  3963. MENU_END();
  3964. }
  3965. void lcd_temp_calibration_set() {
  3966. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3967. temp_cal_active = !temp_cal_active;
  3968. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3969. }
  3970. #ifdef HAS_SECOND_SERIAL_PORT
  3971. void lcd_second_serial_set() {
  3972. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3973. else selectedSerialPort = 1;
  3974. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3975. MYSERIAL.begin(BAUDRATE);
  3976. }
  3977. #endif //HAS_SECOND_SERIAL_PORT
  3978. void lcd_calibrate_pinda() {
  3979. enquecommand_P(PSTR("G76"));
  3980. lcd_return_to_status();
  3981. }
  3982. #ifndef SNMM
  3983. /*void lcd_calibrate_extruder() {
  3984. if (degHotend0() > EXTRUDE_MINTEMP)
  3985. {
  3986. current_position[E_AXIS] = 0; //set initial position to zero
  3987. plan_set_e_position(current_position[E_AXIS]);
  3988. //long steps_start = st_get_position(E_AXIS);
  3989. long steps_final;
  3990. float e_steps_per_unit;
  3991. 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)
  3992. 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
  3993. 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
  3994. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3995. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3996. unsigned long msg_millis;
  3997. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3998. lcd_clear();
  3999. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  4000. current_position[E_AXIS] += e_shift_calibration;
  4001. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  4002. st_synchronize();
  4003. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  4004. msg_millis = _millis();
  4005. while (!LCD_CLICKED) {
  4006. if (multi_screen && _millis() - msg_millis > 5000) {
  4007. if (msg_next_e_cal_knob == NULL)
  4008. msg_next_e_cal_knob = msg_e_cal_knob;
  4009. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  4010. msg_millis = _millis();
  4011. }
  4012. //manage_inactivity(true);
  4013. manage_heater();
  4014. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  4015. delay_keep_alive(50);
  4016. //previous_millis_cmd = _millis();
  4017. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  4018. lcd_encoder_diff = 0;
  4019. if (!planner_queue_full()) {
  4020. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  4021. lcd_encoder = 0;
  4022. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  4023. }
  4024. }
  4025. }
  4026. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  4027. //steps_final = st_get_position(E_AXIS);
  4028. lcd_draw_update = 1;
  4029. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  4030. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  4031. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  4032. lcd_clear();
  4033. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  4034. enquecommand_P(PSTR("M500")); //store settings to eeprom
  4035. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  4036. //delay_keep_alive(2000);
  4037. delay_keep_alive(500);
  4038. 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
  4039. lcd_update_enable(true);
  4040. lcd_draw_update = 2;
  4041. }
  4042. else
  4043. {
  4044. show_preheat_nozzle_warning();
  4045. }
  4046. lcd_return_to_status();
  4047. }
  4048. void lcd_extr_cal_reset() {
  4049. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  4050. axis_steps_per_unit[E_AXIS] = tmp1[3];
  4051. //extrudemultiply = 100;
  4052. enquecommand_P(PSTR("M500"));
  4053. }*/
  4054. #endif
  4055. void lcd_toshiba_flash_air_compatibility_toggle()
  4056. {
  4057. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  4058. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  4059. }
  4060. //! @brief Continue first layer calibration with previous value or start from zero?
  4061. //!
  4062. //! @code{.unparsed}
  4063. //! |01234567890123456789|
  4064. //! |Sheet Smooth1 actual| c=a, c=b, a+b = 13
  4065. //! |Z offset: -1.480 mm | c=a, c=b, a+b = 14
  4066. //! |>Continue | c=19
  4067. //! | Start from zero | c=19
  4068. //! ----------------------
  4069. //! @endcode
  4070. void lcd_first_layer_calibration_reset()
  4071. {
  4072. typedef struct
  4073. {
  4074. bool reset;
  4075. } MenuData;
  4076. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  4077. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4078. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  4079. (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) ||
  4080. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  4081. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  4082. {
  4083. if (menuData->reset)
  4084. {
  4085. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  4086. }
  4087. menu_goto(lcd_v2_calibration,0,true,true);
  4088. }
  4089. if (lcd_encoder > 0)
  4090. {
  4091. menuData->reset = true;
  4092. lcd_encoder = 1;
  4093. }
  4094. else if (lcd_encoder < 1)
  4095. {
  4096. menuData->reset = false;
  4097. lcd_encoder = 0;
  4098. }
  4099. char sheet_name[sizeof(Sheet::name)];
  4100. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  4101. lcd_set_cursor(0, 0);
  4102. 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];
  4103. 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
  4104. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');
  4105. }
  4106. void lcd_v2_calibration()
  4107. {
  4108. if (mmu_enabled)
  4109. {
  4110. const uint8_t filament = choose_menu_P(
  4111. _i("Select filament:"), ////MSG_SELECT_FILAMENT c=20
  4112. _T(MSG_FILAMENT),(_T(MSG_CANCEL)+1)); //Hack to reuse MSG but strip 1st char off
  4113. if (filament < 5)
  4114. {
  4115. lay1cal_filament = filament;
  4116. }
  4117. else
  4118. {
  4119. menu_back();
  4120. return;
  4121. }
  4122. }
  4123. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  4124. {
  4125. bool loaded = false;
  4126. if (fsensor_enabled && ir_sensor_detected)
  4127. {
  4128. loaded = !READ(IR_SENSOR_PIN);
  4129. }
  4130. else
  4131. {
  4132. loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, true);
  4133. lcd_update_enabled = true;
  4134. }
  4135. if (!loaded)
  4136. {
  4137. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  4138. lcd_consume_click();
  4139. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  4140. delay_keep_alive(100);
  4141. if (lcd_clicked()) {
  4142. break;
  4143. }
  4144. }
  4145. lcd_update_enabled = true;
  4146. menu_back();
  4147. return;
  4148. }
  4149. }
  4150. eFilamentAction = FilamentAction::Lay1Cal;
  4151. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  4152. }
  4153. void lcd_wizard() {
  4154. bool result = true;
  4155. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  4156. 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
  4157. }
  4158. if (result) {
  4159. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  4160. lcd_wizard(WizState::Run);
  4161. }
  4162. else {
  4163. lcd_return_to_status();
  4164. lcd_update_enable(true);
  4165. lcd_update(2);
  4166. }
  4167. }
  4168. #if (LANG_MODE != 0)
  4169. void lcd_language()
  4170. {
  4171. lcd_update_enable(true);
  4172. lcd_clear();
  4173. menu_goto(lcd_language_menu, 0, true, true);
  4174. lcd_timeoutToStatus.stop(); //infinite timeout
  4175. lcd_draw_update = 2;
  4176. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  4177. {
  4178. _delay(50);
  4179. lcd_update(0);
  4180. manage_heater();
  4181. manage_inactivity(true);
  4182. }
  4183. if (lang_is_selected())
  4184. lcd_return_to_status();
  4185. else
  4186. lang_select(LANG_ID_PRI);
  4187. }
  4188. #endif
  4189. static void wait_preheat()
  4190. {
  4191. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  4192. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  4193. delay_keep_alive(2000);
  4194. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4195. while (fabs(degHotend(0) - degTargetHotend(0)) > 3) {
  4196. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4197. lcd_set_cursor(0, 4);
  4198. //Print the hotend temperature (9 chars total)
  4199. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  4200. delay_keep_alive(1000);
  4201. }
  4202. }
  4203. static void lcd_wizard_load()
  4204. {
  4205. if (mmu_enabled)
  4206. {
  4207. 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
  4208. tmp_extruder = 0;
  4209. }
  4210. else
  4211. {
  4212. 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
  4213. }
  4214. lcd_update_enable(false);
  4215. lcd_clear();
  4216. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  4217. #ifdef SNMM
  4218. change_extr(0);
  4219. #endif
  4220. loading_flag = true;
  4221. gcode_M701();
  4222. }
  4223. bool lcd_autoDepleteEnabled()
  4224. {
  4225. return (lcd_autoDeplete && fsensor_enabled);
  4226. }
  4227. static void wizard_lay1cal_message(bool cold)
  4228. {
  4229. lcd_show_fullscreen_message_and_wait_P(
  4230. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  4231. if (mmu_enabled)
  4232. {
  4233. lcd_show_fullscreen_message_and_wait_P(
  4234. _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
  4235. }
  4236. else if (cold)
  4237. {
  4238. lcd_show_fullscreen_message_and_wait_P(
  4239. _i("Select temperature which matches your material."));////MSG_SELECT_TEMP_MATCHES_MATERIAL c=20 r=4
  4240. }
  4241. lcd_show_fullscreen_message_and_wait_P(
  4242. _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
  4243. }
  4244. //! @brief Printer first run wizard (Selftest and calibration)
  4245. //!
  4246. //!
  4247. //! First layer calibration with MMU state diagram
  4248. //!
  4249. //! @startuml
  4250. //! [*] --> IsFil
  4251. //! IsFil : Is any filament loaded?
  4252. //! LoadFilCold : Push the button to start loading Filament 1
  4253. //!
  4254. //! IsFil --> Lay1CalCold : yes
  4255. //! IsFil --> LoadFilCold : no
  4256. //! LoadFilCold --> Lay1CalCold : click
  4257. //! @enduml
  4258. //!
  4259. //! First layer calibration without MMU state diagram
  4260. //!
  4261. //! @startuml
  4262. //! [*] --> IsFil
  4263. //! IsFil : Is filament loaded?
  4264. //! Preheat : Select nozle temperature which matches your material.
  4265. //! LoadFilHot : Insert filament to extruder and press the knob.
  4266. //!
  4267. //! IsFil --> Lay1CalCold : yes
  4268. //! IsFil --> Preheat : no
  4269. //! Preheat --> LoadFilHot : select
  4270. //! LoadFilHot --> Lay1CalHot : click
  4271. //! @enduml
  4272. //!
  4273. //! @param state Entry point of the wizard
  4274. //!
  4275. //! state | description
  4276. //! ---------------------- | ----------------
  4277. //! WizState::Run | Main entry point
  4278. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  4279. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  4280. void lcd_wizard(WizState state)
  4281. {
  4282. using S = WizState;
  4283. bool end = false;
  4284. int8_t wizard_event;
  4285. const char *msg = NULL;
  4286. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  4287. // other than WizState::Run - it is useful for debugging wizard.
  4288. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4289. FORCE_BL_ON_START;
  4290. while (!end) {
  4291. printf_P(PSTR("Wizard state: %d\n"), state);
  4292. switch (state) {
  4293. case S::Run: //Run wizard?
  4294. // 2019-08-07 brutal hack - solving the "viper" situation.
  4295. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  4296. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  4297. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  4298. // which results in distorted print.
  4299. // This primarily happens when the printer is new and parked in 0,0
  4300. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  4301. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  4302. // 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.
  4303. saved_printing = false;
  4304. if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){
  4305. lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING));
  4306. state = S::Restore;
  4307. } else {
  4308. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, true);
  4309. if (wizard_event) {
  4310. state = S::Restore;
  4311. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4312. } else {
  4313. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4314. end = true;
  4315. }
  4316. }
  4317. break;
  4318. case S::Restore:
  4319. switch (calibration_status()) {
  4320. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  4321. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  4322. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  4323. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  4324. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  4325. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  4326. }
  4327. break;
  4328. case S::Selftest:
  4329. 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
  4330. wizard_event = lcd_selftest();
  4331. if (wizard_event) {
  4332. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  4333. state = S::Xyz;
  4334. }
  4335. else end = true;
  4336. break;
  4337. case S::Xyz:
  4338. 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
  4339. wizard_event = gcode_M45(false, 0);
  4340. if (wizard_event) state = S::IsFil;
  4341. else end = true;
  4342. break;
  4343. case S::Z:
  4344. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));////MSG_REMOVE_SHIPPING_HELPERS c=20 r=3
  4345. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));////MSG_REMOVE_TEST_PRINT c=20 r=4
  4346. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  4347. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  4348. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  4349. wizard_event = gcode_M45(true, 0);
  4350. if (wizard_event) {
  4351. //current filament needs to be unloaded and then new filament should be loaded
  4352. //start to preheat nozzle for unloading remaining PLA filament
  4353. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4354. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));
  4355. wait_preheat();
  4356. //unload current filament
  4357. unload_filament(true);
  4358. //load filament
  4359. lcd_wizard_load();
  4360. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  4361. state = S::Finish; //shipped, no need to set first layer, go to final message directly
  4362. }
  4363. else end = true;
  4364. break;
  4365. case S::IsFil:
  4366. //start to preheat nozzle and bed to save some time later
  4367. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4368. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  4369. if (mmu_enabled)
  4370. {
  4371. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4372. } else
  4373. {
  4374. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4375. }
  4376. if (wizard_event) state = S::Lay1CalCold;
  4377. else
  4378. {
  4379. if(mmu_enabled) state = S::LoadFilCold;
  4380. else state = S::Preheat;
  4381. }
  4382. break;
  4383. case S::Preheat:
  4384. menu_goto(lcd_preheat_menu,0,false,true);
  4385. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));////MSG_SEL_PREHEAT_TEMP c=20 r=6
  4386. end = true; // Leave wizard temporarily for lcd_preheat_menu
  4387. break;
  4388. case S::LoadFilHot:
  4389. wait_preheat();
  4390. lcd_wizard_load();
  4391. state = S::Lay1CalHot;
  4392. break;
  4393. case S::LoadFilCold:
  4394. lcd_wizard_load();
  4395. state = S::Lay1CalCold;
  4396. break;
  4397. case S::Lay1CalCold:
  4398. wizard_lay1cal_message(true);
  4399. menu_goto(lcd_v2_calibration,0,false,true);
  4400. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4401. break;
  4402. case S::Lay1CalHot:
  4403. wizard_lay1cal_message(false);
  4404. lcd_commands_type = LcdCommands::Layer1Cal;
  4405. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4406. break;
  4407. case S::RepeatLay1Cal:
  4408. 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
  4409. if (wizard_event)
  4410. {
  4411. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  4412. state = S::Lay1CalCold;
  4413. }
  4414. else
  4415. {
  4416. 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
  4417. state = S::Finish;
  4418. }
  4419. break;
  4420. case S::Finish:
  4421. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4422. end = true;
  4423. break;
  4424. default: break;
  4425. }
  4426. }
  4427. FORCE_BL_ON_END;
  4428. printf_P(_N("Wizard end state: %d\n"), state);
  4429. switch (state) { //final message
  4430. case S::Restore: //printer was already calibrated
  4431. msg = _T(MSG_WIZARD_DONE);
  4432. break;
  4433. case S::Selftest: //selftest
  4434. case S::Xyz: //xyz cal.
  4435. case S::Z: //z cal.
  4436. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  4437. break;
  4438. case S::Finish: //we are finished
  4439. msg = _T(MSG_WIZARD_DONE);
  4440. lcd_reset_alert_level();
  4441. lcd_setstatuspgm(MSG_WELCOME);
  4442. lcd_return_to_status();
  4443. break;
  4444. default:
  4445. msg = _T(MSG_WIZARD_QUIT);
  4446. break;
  4447. }
  4448. if (!((S::Lay1CalCold == state) || (S::Lay1CalHot == state) || (S::Preheat == state)))
  4449. {
  4450. lcd_show_fullscreen_message_and_wait_P(msg);
  4451. }
  4452. lcd_update_enable(true);
  4453. lcd_update(2);
  4454. }
  4455. #ifdef TMC2130
  4456. void lcd_settings_linearity_correction_menu(void)
  4457. {
  4458. MENU_BEGIN();
  4459. ON_MENU_LEAVE(
  4460. lcd_settings_linearity_correction_menu_save();
  4461. );
  4462. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  4463. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  4464. //tmc2130_wave_fac[X_AXIS]
  4465. 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
  4466. 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
  4467. 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
  4468. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  4469. 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
  4470. MENU_END();
  4471. }
  4472. #endif // TMC2130
  4473. #ifdef FILAMENT_SENSOR
  4474. #define SETTINGS_FILAMENT_SENSOR \
  4475. do\
  4476. {\
  4477. if (FSensorStateMenu == 0)\
  4478. {\
  4479. if (fsensor_not_responding && (mmu_enabled == false))\
  4480. {\
  4481. /* Filament sensor not working*/\
  4482. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);/*////MSG_FSENSOR_NA*/\
  4483. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_fsensor_fail);\
  4484. }\
  4485. else\
  4486. {\
  4487. /* Filament sensor turned off, working, no problems*/\
  4488. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);\
  4489. if (mmu_enabled == false)\
  4490. {\
  4491. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_filament_autoload_info);\
  4492. }\
  4493. }\
  4494. }\
  4495. else\
  4496. {\
  4497. /* Filament sensor turned on, working, no problems*/\
  4498. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);\
  4499. if (mmu_enabled == false)\
  4500. {\
  4501. if (fsensor_autoload_enabled)\
  4502. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_ON), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17*/\
  4503. else\
  4504. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17*/\
  4505. /*if (fsensor_oq_meassure_enabled)*/\
  4506. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass. [on]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_ON c=17*/\
  4507. /*else*/\
  4508. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass.[off]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_OFF c=17*/\
  4509. }\
  4510. }\
  4511. }\
  4512. while(0)
  4513. #else //FILAMENT_SENSOR
  4514. #define SETTINGS_FILAMENT_SENSOR do{}while(0)
  4515. #endif //FILAMENT_SENSOR
  4516. static void auto_deplete_switch()
  4517. {
  4518. lcd_autoDeplete = !lcd_autoDeplete;
  4519. eeprom_update_byte((unsigned char *)EEPROM_AUTO_DEPLETE, lcd_autoDeplete);
  4520. }
  4521. static void settingsAutoDeplete()
  4522. {
  4523. if (mmu_enabled)
  4524. {
  4525. if (!fsensor_enabled)
  4526. {
  4527. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_NA), NULL);
  4528. }
  4529. else if (lcd_autoDeplete)
  4530. {
  4531. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_ON), auto_deplete_switch);
  4532. }
  4533. else
  4534. {
  4535. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_OFF), auto_deplete_switch);
  4536. }
  4537. }
  4538. }
  4539. #define SETTINGS_AUTO_DEPLETE \
  4540. do\
  4541. {\
  4542. settingsAutoDeplete();\
  4543. }\
  4544. while(0)\
  4545. #ifdef MMU_HAS_CUTTER
  4546. static void settingsCutter()
  4547. {
  4548. if (mmu_enabled)
  4549. {
  4550. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4551. {
  4552. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  4553. }
  4554. #ifdef MMU_ALWAYS_CUT
  4555. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4556. {
  4557. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _i("Always"), lcd_cutter_enabled);
  4558. }
  4559. #endif
  4560. else
  4561. {
  4562. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  4563. }
  4564. }
  4565. }
  4566. #define SETTINGS_CUTTER \
  4567. do\
  4568. {\
  4569. settingsCutter();\
  4570. }\
  4571. while(0)
  4572. #else
  4573. #define SETTINGS_CUTTER
  4574. #endif //MMU_HAS_CUTTER
  4575. #ifdef TMC2130
  4576. #define SETTINGS_SILENT_MODE \
  4577. do\
  4578. {\
  4579. if(!farm_mode)\
  4580. {\
  4581. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4582. {\
  4583. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  4584. }\
  4585. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  4586. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4587. {\
  4588. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  4589. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  4590. }\
  4591. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  4592. }\
  4593. }\
  4594. while (0)
  4595. #else //TMC2130
  4596. #define SETTINGS_SILENT_MODE \
  4597. do\
  4598. {\
  4599. if(!farm_mode)\
  4600. {\
  4601. switch (SilentModeMenu)\
  4602. {\
  4603. case SILENT_MODE_POWER:\
  4604. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4605. break;\
  4606. case SILENT_MODE_SILENT:\
  4607. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  4608. break;\
  4609. case SILENT_MODE_AUTO:\
  4610. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  4611. break;\
  4612. default:\
  4613. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4614. break; /* (probably) not needed*/\
  4615. }\
  4616. }\
  4617. }\
  4618. while (0)
  4619. #endif //TMC2130
  4620. #ifndef MMU_FORCE_STEALTH_MODE
  4621. #define SETTINGS_MMU_MODE \
  4622. do\
  4623. {\
  4624. if (mmu_enabled)\
  4625. {\
  4626. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  4627. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  4628. }\
  4629. }\
  4630. while (0)
  4631. #else //MMU_FORCE_STEALTH_MODE
  4632. #define SETTINGS_MMU_MODE
  4633. #endif //MMU_FORCE_STEALTH_MODE
  4634. #ifdef SDCARD_SORT_ALPHA
  4635. #define SETTINGS_SD \
  4636. do\
  4637. {\
  4638. if (card.ToshibaFlashAir_isEnabled())\
  4639. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4640. else\
  4641. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4642. \
  4643. uint8_t sdSort;\
  4644. sdSort = eeprom_read_byte((uint8_t*) EEPROM_SD_SORT);\
  4645. switch (sdSort)\
  4646. {\
  4647. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;\
  4648. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;\
  4649. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);\
  4650. }\
  4651. }\
  4652. while (0)
  4653. #else // SDCARD_SORT_ALPHA
  4654. #define SETTINGS_SD \
  4655. do\
  4656. {\
  4657. if (card.ToshibaFlashAir_isEnabled())\
  4658. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4659. else\
  4660. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4661. }\
  4662. while (0)
  4663. #endif // SDCARD_SORT_ALPHA
  4664. /*
  4665. #define SETTINGS_MBL_MODE \
  4666. do\
  4667. {\
  4668. switch(e_mbl_type)\
  4669. {\
  4670. case e_MBL_FAST:\
  4671. MENU_ITEM_FUNCTION_P(_i("Mode [Fast]"),mbl_mode_set);\
  4672. break; \
  4673. case e_MBL_OPTIMAL:\
  4674. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4675. break; \
  4676. case e_MBL_PREC:\
  4677. MENU_ITEM_FUNCTION_P(_i("Mode [Precise]"), mbl_mode_set); \
  4678. break; \
  4679. default:\
  4680. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4681. break; \
  4682. }\
  4683. }\
  4684. while (0)
  4685. */
  4686. #define SETTINGS_SOUND \
  4687. do\
  4688. {\
  4689. switch(eSoundMode)\
  4690. {\
  4691. case e_SOUND_MODE_LOUD:\
  4692. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4693. break;\
  4694. case e_SOUND_MODE_ONCE:\
  4695. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  4696. break;\
  4697. case e_SOUND_MODE_SILENT:\
  4698. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  4699. break;\
  4700. case e_SOUND_MODE_BLIND:\
  4701. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  4702. break;\
  4703. default:\
  4704. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4705. }\
  4706. }\
  4707. while (0)
  4708. //-//
  4709. static void lcd_check_mode_set(void)
  4710. {
  4711. switch(oCheckMode)
  4712. {
  4713. case ClCheckMode::_None:
  4714. oCheckMode=ClCheckMode::_Warn;
  4715. break;
  4716. case ClCheckMode::_Warn:
  4717. oCheckMode=ClCheckMode::_Strict;
  4718. break;
  4719. case ClCheckMode::_Strict:
  4720. oCheckMode=ClCheckMode::_None;
  4721. break;
  4722. default:
  4723. oCheckMode=ClCheckMode::_None;
  4724. }
  4725. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  4726. }
  4727. #define SETTINGS_MODE \
  4728. do\
  4729. {\
  4730. switch(oCheckMode)\
  4731. {\
  4732. case ClCheckMode::_None:\
  4733. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4734. break;\
  4735. case ClCheckMode::_Warn:\
  4736. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  4737. break;\
  4738. case ClCheckMode::_Strict:\
  4739. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  4740. break;\
  4741. default:\
  4742. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4743. }\
  4744. }\
  4745. while (0)
  4746. static void lcd_nozzle_diameter_cycle(void) {
  4747. uint16_t nDiameter;
  4748. switch(oNozzleDiameter){
  4749. case ClNozzleDiameter::_Diameter_250:
  4750. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4751. nDiameter=400;
  4752. break;
  4753. case ClNozzleDiameter::_Diameter_400:
  4754. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  4755. nDiameter=600;
  4756. break;
  4757. case ClNozzleDiameter::_Diameter_600:
  4758. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  4759. nDiameter=800;
  4760. break;
  4761. case ClNozzleDiameter::_Diameter_800:
  4762. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  4763. nDiameter=250;
  4764. break;
  4765. default:
  4766. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4767. nDiameter=400;
  4768. }
  4769. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  4770. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  4771. }
  4772. #define SETTINGS_NOZZLE \
  4773. do\
  4774. {\
  4775. float fNozzleDiam;\
  4776. switch(oNozzleDiameter)\
  4777. {\
  4778. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  4779. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  4780. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  4781. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  4782. default: fNozzleDiam = 0.4f; break;\
  4783. }\
  4784. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  4785. }\
  4786. while (0)
  4787. static void lcd_check_model_set(void)
  4788. {
  4789. switch(oCheckModel)
  4790. {
  4791. case ClCheckModel::_None:
  4792. oCheckModel=ClCheckModel::_Warn;
  4793. break;
  4794. case ClCheckModel::_Warn:
  4795. oCheckModel=ClCheckModel::_Strict;
  4796. break;
  4797. case ClCheckModel::_Strict:
  4798. oCheckModel=ClCheckModel::_None;
  4799. break;
  4800. default:
  4801. oCheckModel=ClCheckModel::_None;
  4802. }
  4803. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4804. }
  4805. #define SETTINGS_MODEL \
  4806. do\
  4807. {\
  4808. switch(oCheckModel)\
  4809. {\
  4810. case ClCheckModel::_None:\
  4811. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4812. break;\
  4813. case ClCheckModel::_Warn:\
  4814. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4815. break;\
  4816. case ClCheckModel::_Strict:\
  4817. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4818. break;\
  4819. default:\
  4820. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4821. }\
  4822. }\
  4823. while (0)
  4824. static void lcd_check_version_set(void)
  4825. {
  4826. switch(oCheckVersion)
  4827. {
  4828. case ClCheckVersion::_None:
  4829. oCheckVersion=ClCheckVersion::_Warn;
  4830. break;
  4831. case ClCheckVersion::_Warn:
  4832. oCheckVersion=ClCheckVersion::_Strict;
  4833. break;
  4834. case ClCheckVersion::_Strict:
  4835. oCheckVersion=ClCheckVersion::_None;
  4836. break;
  4837. default:
  4838. oCheckVersion=ClCheckVersion::_None;
  4839. }
  4840. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4841. }
  4842. #define SETTINGS_VERSION \
  4843. do\
  4844. {\
  4845. switch(oCheckVersion)\
  4846. {\
  4847. case ClCheckVersion::_None:\
  4848. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4849. break;\
  4850. case ClCheckVersion::_Warn:\
  4851. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_WARN), lcd_check_version_set);\
  4852. break;\
  4853. case ClCheckVersion::_Strict:\
  4854. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_STRICT), lcd_check_version_set);\
  4855. break;\
  4856. default:\
  4857. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4858. }\
  4859. }\
  4860. while (0)
  4861. #if 0 // temporarily unused
  4862. static void lcd_check_gcode_set(void)
  4863. {
  4864. switch(oCheckGcode)
  4865. {
  4866. case ClCheckGcode::_None:
  4867. oCheckGcode=ClCheckGcode::_Warn;
  4868. break;
  4869. case ClCheckGcode::_Warn:
  4870. oCheckGcode=ClCheckGcode::_Strict;
  4871. break;
  4872. case ClCheckGcode::_Strict:
  4873. oCheckGcode=ClCheckGcode::_None;
  4874. break;
  4875. default:
  4876. oCheckGcode=ClCheckGcode::_None;
  4877. }
  4878. eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode);
  4879. }
  4880. #endif
  4881. #define SETTINGS_GCODE \
  4882. do\
  4883. {\
  4884. switch(oCheckGcode)\
  4885. {\
  4886. case ClCheckGcode::_None:\
  4887. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4888. break;\
  4889. case ClCheckGcode::_Warn:\
  4890. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_WARN), lcd_check_gcode_set);\
  4891. break;\
  4892. case ClCheckGcode::_Strict:\
  4893. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_STRICT), lcd_check_gcode_set);\
  4894. break;\
  4895. default:\
  4896. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4897. }\
  4898. }\
  4899. while (0)
  4900. static void lcd_checking_menu(void)
  4901. {
  4902. MENU_BEGIN();
  4903. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4904. SETTINGS_MODE;
  4905. SETTINGS_MODEL;
  4906. SETTINGS_VERSION;
  4907. //-// temporarily disabled
  4908. //SETTINGS_GCODE;
  4909. MENU_END();
  4910. }
  4911. #ifdef IR_SENSOR_ANALOG
  4912. static void lcd_fsensor_actionNA_set(void)
  4913. {
  4914. switch(oFsensorActionNA)
  4915. {
  4916. case ClFsensorActionNA::_Continue:
  4917. oFsensorActionNA=ClFsensorActionNA::_Pause;
  4918. break;
  4919. case ClFsensorActionNA::_Pause:
  4920. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4921. break;
  4922. default:
  4923. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4924. }
  4925. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_ACTION_NA,(uint8_t)oFsensorActionNA);
  4926. }
  4927. #define FSENSOR_ACTION_NA \
  4928. do\
  4929. {\
  4930. switch(oFsensorActionNA)\
  4931. {\
  4932. case ClFsensorActionNA::_Continue:\
  4933. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set);\
  4934. break;\
  4935. case ClFsensorActionNA::_Pause:\
  4936. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set);\
  4937. break;\
  4938. default:\
  4939. oFsensorActionNA=ClFsensorActionNA::_Continue;\
  4940. }\
  4941. }\
  4942. while (0)
  4943. #endif //IR_SENSOR_ANALOG
  4944. template <uint8_t number>
  4945. static void select_sheet_menu()
  4946. {
  4947. selected_sheet = number;
  4948. lcd_sheet_menu();
  4949. }
  4950. static void sheets_menu()
  4951. {
  4952. MENU_BEGIN();
  4953. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4954. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4955. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4956. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4957. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4958. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4959. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4960. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4961. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4962. MENU_END();
  4963. }
  4964. void lcd_hw_setup_menu(void) // can not be "static"
  4965. {
  4966. typedef struct
  4967. {// 2bytes total
  4968. int8_t status;
  4969. uint8_t experimental_menu_visibility;
  4970. } _menu_data_t;
  4971. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4972. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4973. if (_md->status == 0 || lcd_draw_update)
  4974. {
  4975. _md->status = 1;
  4976. _md->experimental_menu_visibility = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  4977. if (_md->experimental_menu_visibility == EEPROM_EMPTY_VALUE)
  4978. {
  4979. _md->experimental_menu_visibility = 0;
  4980. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, _md->experimental_menu_visibility);
  4981. }
  4982. }
  4983. MENU_BEGIN();
  4984. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  4985. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  4986. SETTINGS_NOZZLE;
  4987. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); ////MSG_CHECKS c=18
  4988. #ifdef IR_SENSOR_ANALOG
  4989. FSENSOR_ACTION_NA;
  4990. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  4991. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  4992. if(!mmu_enabled) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  4993. #endif //IR_SENSOR_ANALOG
  4994. if (_md->experimental_menu_visibility)
  4995. {
  4996. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  4997. }
  4998. #ifdef PINDA_TEMP_COMP
  4999. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  5000. //! This works well on the EINSY board but not on the miniRAMBo board as
  5001. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  5002. //!
  5003. //! This menu allows the user to en-/disable the SuperPINDA manualy
  5004. 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);
  5005. #endif //PINDA_TEMP_COMP
  5006. MENU_END();
  5007. }
  5008. static void lcd_settings_menu()
  5009. {
  5010. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  5011. MENU_BEGIN();
  5012. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5013. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=18
  5014. if (!PRINTER_ACTIVE || isPrintPaused)
  5015. {
  5016. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
  5017. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
  5018. }
  5019. SETTINGS_FILAMENT_SENSOR;
  5020. SETTINGS_AUTO_DEPLETE;
  5021. SETTINGS_CUTTER;
  5022. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  5023. SETTINGS_SILENT_MODE;
  5024. if(!farm_mode)
  5025. {
  5026. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  5027. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  5028. }
  5029. SETTINGS_MMU_MODE;
  5030. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  5031. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  5032. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);////MSG_LIN_CORRECTION c=18
  5033. #endif //LINEARITY_CORRECTION && TMC2130
  5034. if(has_temperature_compensation())
  5035. {
  5036. 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);
  5037. }
  5038. #ifdef HAS_SECOND_SERIAL_PORT
  5039. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  5040. #endif //HAS_SECOND_SERIAL
  5041. if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag)
  5042. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  5043. #if (LANG_MODE != 0)
  5044. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=18
  5045. #endif //(LANG_MODE != 0)
  5046. SETTINGS_SD;
  5047. SETTINGS_SOUND;
  5048. #ifdef LCD_BL_PIN
  5049. if (backlightSupport)
  5050. {
  5051. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  5052. }
  5053. #endif //LCD_BL_PIN
  5054. if (farm_mode)
  5055. {
  5056. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  5057. }
  5058. MENU_END();
  5059. }
  5060. #ifdef TMC2130
  5061. static void lcd_ustep_linearity_menu_save()
  5062. {
  5063. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  5064. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  5065. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  5066. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  5067. }
  5068. #endif //TMC2130
  5069. #ifdef TMC2130
  5070. static void lcd_settings_linearity_correction_menu_save()
  5071. {
  5072. bool changed = false;
  5073. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  5074. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  5075. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  5076. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  5077. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  5078. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  5079. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  5080. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  5081. lcd_ustep_linearity_menu_save();
  5082. if (changed) tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  5083. }
  5084. #endif //TMC2130
  5085. static void lcd_calibration_menu()
  5086. {
  5087. MENU_BEGIN();
  5088. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5089. if (!isPrintPaused)
  5090. {
  5091. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17
  5092. if (lcd_commands_type == LcdCommands::Idle)
  5093. {
  5094. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);////MSG_V2_CALIBRATION c=18
  5095. }
  5096. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  5097. #ifdef TMC2130
  5098. MENU_ITEM_FUNCTION_P(_i("Belt test"), lcd_belttest_v);////MSG_BELTTEST c=18
  5099. #endif //TMC2130
  5100. MENU_ITEM_FUNCTION_P(_i("Selftest"), lcd_selftest_v);////MSG_SELFTEST c=18
  5101. #ifdef MK1BP
  5102. // MK1
  5103. // "Calibrate Z"
  5104. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  5105. #else //MK1BP
  5106. // MK2
  5107. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  5108. // "Calibrate Z" with storing the reference values to EEPROM.
  5109. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  5110. #ifndef SNMM
  5111. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20
  5112. #endif
  5113. // "Mesh Bed Leveling"
  5114. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling);
  5115. #endif //MK1BP
  5116. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  5117. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  5118. #ifndef TMC2130
  5119. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  5120. #endif
  5121. #ifndef MK1BP
  5122. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  5123. #endif //MK1BP
  5124. #ifndef SNMM
  5125. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  5126. #endif
  5127. #ifndef MK1BP
  5128. if(has_temperature_compensation())
  5129. {
  5130. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17
  5131. }
  5132. #endif //MK1BP
  5133. }
  5134. MENU_END();
  5135. }
  5136. void bowden_menu() {
  5137. int enc_dif = lcd_encoder_diff;
  5138. int cursor_pos = 0;
  5139. lcd_clear();
  5140. lcd_putc_at(0, 0, '>');
  5141. for (uint_least8_t i = 0; i < 4; i++) {
  5142. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5143. lcd_print(i);
  5144. lcd_print(": ");
  5145. bowden_length[i] = eeprom_read_word((uint16_t*)EEPROM_BOWDEN_LENGTH + i);
  5146. lcd_print(bowden_length[i] - 48);
  5147. }
  5148. enc_dif = lcd_encoder_diff;
  5149. lcd_consume_click();
  5150. while (1) {
  5151. manage_heater();
  5152. manage_inactivity(true);
  5153. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5154. if (enc_dif > lcd_encoder_diff) {
  5155. cursor_pos--;
  5156. }
  5157. if (enc_dif < lcd_encoder_diff) {
  5158. cursor_pos++;
  5159. }
  5160. if (cursor_pos > 3) {
  5161. cursor_pos = 3;
  5162. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5163. }
  5164. if (cursor_pos < 0) {
  5165. cursor_pos = 0;
  5166. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5167. }
  5168. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5169. lcd_putc_at(0, cursor_pos, '>');
  5170. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5171. enc_dif = lcd_encoder_diff;
  5172. _delay(100);
  5173. }
  5174. if (lcd_clicked()) {
  5175. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5176. lcd_clear();
  5177. while (1) {
  5178. manage_heater();
  5179. manage_inactivity(true);
  5180. lcd_puts_at_P(1, 1, PSTR("Extruder "));
  5181. lcd_print(cursor_pos);
  5182. lcd_print(": ");
  5183. lcd_set_cursor(13, 1);
  5184. lcd_print(bowden_length[cursor_pos] - 48);
  5185. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5186. if (enc_dif > lcd_encoder_diff) {
  5187. bowden_length[cursor_pos]--;
  5188. lcd_set_cursor(13, 1);
  5189. lcd_print(bowden_length[cursor_pos] - 48);
  5190. enc_dif = lcd_encoder_diff;
  5191. }
  5192. if (enc_dif < lcd_encoder_diff) {
  5193. bowden_length[cursor_pos]++;
  5194. lcd_set_cursor(13, 1);
  5195. lcd_print(bowden_length[cursor_pos] - 48);
  5196. enc_dif = lcd_encoder_diff;
  5197. }
  5198. }
  5199. _delay(100);
  5200. if (lcd_clicked()) {
  5201. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5202. eeprom_update_word((uint16_t*)EEPROM_BOWDEN_LENGTH + cursor_pos, bowden_length[cursor_pos]);
  5203. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  5204. lcd_update_enable(true);
  5205. lcd_clear();
  5206. enc_dif = lcd_encoder_diff;
  5207. lcd_putc_at(0, cursor_pos, '>');
  5208. for (uint_least8_t i = 0; i < 4; i++) {
  5209. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5210. lcd_print(i);
  5211. lcd_print(": ");
  5212. bowden_length[i] = eeprom_read_word((uint16_t*)EEPROM_BOWDEN_LENGTH + i);
  5213. lcd_print(bowden_length[i] - 48);
  5214. }
  5215. break;
  5216. }
  5217. else return;
  5218. }
  5219. }
  5220. }
  5221. }
  5222. }
  5223. #ifdef SNMM
  5224. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  5225. lcd_clear();
  5226. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(':');
  5227. lcd_set_cursor(0, 1); lcd_print('>');
  5228. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19
  5229. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19
  5230. char cursor_pos = 1;
  5231. int enc_dif = 0;
  5232. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5233. lcd_consume_click();
  5234. while (1) {
  5235. manage_heater();
  5236. manage_inactivity(true);
  5237. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5238. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5239. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  5240. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  5241. if (cursor_pos > 3) {
  5242. cursor_pos = 3;
  5243. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5244. }
  5245. if (cursor_pos < 1){
  5246. cursor_pos = 1;
  5247. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5248. }
  5249. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5250. lcd_set_cursor(0, cursor_pos);
  5251. lcd_print('>');
  5252. enc_dif = lcd_encoder_diff;
  5253. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5254. _delay(100);
  5255. }
  5256. }
  5257. if (lcd_clicked()) {
  5258. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5259. KEEPALIVE_STATE(IN_HANDLER);
  5260. return(cursor_pos - 1);
  5261. }
  5262. }
  5263. }
  5264. #endif //SNMM
  5265. //! @brief Select one of numbered items
  5266. //!
  5267. //! Create list of items with header. Header can not be selected.
  5268. //! Each item has text description passed by function parameter and
  5269. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  5270. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  5271. //! There can be last item with different text and no number.
  5272. //!
  5273. //! @param header Header text
  5274. //! @param item Item text
  5275. //! @param last_item Last item text, or nullptr if there is no Last item
  5276. //! @return selected item index, first item index is 0
  5277. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  5278. {
  5279. //following code should handle 3 to 127 number of items well
  5280. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  5281. const uint8_t item_len = item?strlen_P(item):0;
  5282. int8_t first = 0;
  5283. int8_t enc_dif = lcd_encoder_diff;
  5284. int8_t cursor_pos = 1;
  5285. lcd_clear();
  5286. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5287. while (1)
  5288. {
  5289. manage_heater();
  5290. manage_inactivity(true);
  5291. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  5292. {
  5293. if (enc_dif > lcd_encoder_diff)
  5294. {
  5295. cursor_pos--;
  5296. }
  5297. if (enc_dif < lcd_encoder_diff)
  5298. {
  5299. cursor_pos++;
  5300. }
  5301. enc_dif = lcd_encoder_diff;
  5302. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5303. }
  5304. if (cursor_pos > 3)
  5305. {
  5306. cursor_pos = 3;
  5307. if (first < items_no - 3)
  5308. {
  5309. first++;
  5310. lcd_clear();
  5311. } else { // here we are at the very end of the list
  5312. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5313. }
  5314. }
  5315. if (cursor_pos < 1)
  5316. {
  5317. cursor_pos = 1;
  5318. if (first > 0)
  5319. {
  5320. first--;
  5321. lcd_clear();
  5322. } else { // here we are at the very end of the list
  5323. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5324. }
  5325. }
  5326. if (header) lcd_puts_at_P(0,0,header);
  5327. const bool last_visible = (first == items_no - 3);
  5328. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  5329. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5330. {
  5331. if (item) lcd_puts_at_P(1, i + 1, item);
  5332. }
  5333. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5334. {
  5335. lcd_set_cursor(2 + item_len, i+1);
  5336. lcd_print(first + i + 1);
  5337. }
  5338. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  5339. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5340. lcd_putc_at(0, cursor_pos, '>');
  5341. _delay(100);
  5342. if (lcd_clicked())
  5343. {
  5344. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5345. KEEPALIVE_STATE(IN_HANDLER);
  5346. lcd_encoder_diff = 0;
  5347. return(cursor_pos + first - 1);
  5348. }
  5349. }
  5350. }
  5351. char reset_menu() {
  5352. const uint8_t items_no =
  5353. #ifdef SNMM
  5354. 6;
  5355. #else
  5356. 5;
  5357. #endif
  5358. static int8_t first = 0;
  5359. int8_t enc_dif = 0;
  5360. char cursor_pos = 0;
  5361. const char *const item[items_no] = {PSTR("Language"), PSTR("Statistics"), PSTR("Shipping prep"), PSTR("Service prep"), PSTR("All Data")
  5362. #ifdef SNMM
  5363. , PSTR("Bowden length")
  5364. #endif
  5365. };
  5366. enc_dif = lcd_encoder_diff;
  5367. lcd_clear();
  5368. lcd_set_cursor(0, 0);
  5369. lcd_putc('>');
  5370. lcd_consume_click();
  5371. while (1) {
  5372. for (uint_least8_t i = 0; i < 4; i++) {
  5373. lcd_puts_at_P(1, i, item[first + i]);
  5374. }
  5375. manage_heater();
  5376. manage_inactivity(true);
  5377. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5378. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5379. if (enc_dif > lcd_encoder_diff) {
  5380. cursor_pos--;
  5381. }
  5382. if (enc_dif < lcd_encoder_diff) {
  5383. cursor_pos++;
  5384. }
  5385. if (cursor_pos > 3) {
  5386. cursor_pos = 3;
  5387. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5388. if (first < items_no - 4) {
  5389. first++;
  5390. lcd_clear();
  5391. }
  5392. }
  5393. if (cursor_pos < 0) {
  5394. cursor_pos = 0;
  5395. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5396. if (first > 0) {
  5397. first--;
  5398. lcd_clear();
  5399. }
  5400. }
  5401. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5402. lcd_set_cursor(0, cursor_pos);
  5403. lcd_putc('>');
  5404. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5405. enc_dif = lcd_encoder_diff;
  5406. _delay(100);
  5407. }
  5408. }
  5409. if (lcd_clicked()) {
  5410. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5411. return(cursor_pos + first);
  5412. }
  5413. }
  5414. }
  5415. static void lcd_disable_farm_mode()
  5416. {
  5417. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  5418. if (disable)
  5419. {
  5420. enquecommand_P(PSTR("G99"));
  5421. lcd_return_to_status();
  5422. }
  5423. lcd_update_enable(true);
  5424. lcd_draw_update = 2;
  5425. }
  5426. static void fil_load_menu()
  5427. {
  5428. MENU_BEGIN();
  5429. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5430. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all); ////MSG_LOAD_ALL c=17
  5431. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', extr_adj, 0); ////MSG_LOAD_FILAMENT_1 c=16
  5432. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', extr_adj, 1); ////MSG_LOAD_FILAMENT_2 c=17
  5433. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', extr_adj, 2); ////MSG_LOAD_FILAMENT_3 c=17
  5434. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', extr_adj, 3); ////MSG_LOAD_FILAMENT_4 c=17
  5435. if (mmu_enabled)
  5436. {
  5437. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', extr_adj, 4);
  5438. }
  5439. MENU_END();
  5440. }
  5441. static void mmu_load_to_nozzle_menu()
  5442. {
  5443. if (bFilamentAction)
  5444. {
  5445. MENU_BEGIN();
  5446. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5447. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', lcd_mmu_load_to_nozzle, 0);
  5448. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', lcd_mmu_load_to_nozzle, 1);
  5449. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', lcd_mmu_load_to_nozzle, 2);
  5450. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', lcd_mmu_load_to_nozzle, 3);
  5451. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', lcd_mmu_load_to_nozzle, 4);
  5452. MENU_END();
  5453. }
  5454. else
  5455. {
  5456. eFilamentAction = FilamentAction::MmuLoad;
  5457. preheat_or_continue();
  5458. }
  5459. }
  5460. static void mmu_eject_filament(uint8_t filament)
  5461. {
  5462. menu_back();
  5463. mmu_eject_filament(filament, true);
  5464. }
  5465. static void mmu_fil_eject_menu()
  5466. {
  5467. if (bFilamentAction)
  5468. {
  5469. MENU_BEGIN();
  5470. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5471. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '1', mmu_eject_filament, 0);
  5472. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '2', mmu_eject_filament, 1);
  5473. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '3', mmu_eject_filament, 2);
  5474. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '4', mmu_eject_filament, 3);
  5475. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '5', mmu_eject_filament, 4);
  5476. MENU_END();
  5477. }
  5478. else
  5479. {
  5480. eFilamentAction = FilamentAction::MmuEject;
  5481. preheat_or_continue();
  5482. }
  5483. }
  5484. #ifdef MMU_HAS_CUTTER
  5485. static void mmu_cut_filament_menu()
  5486. {
  5487. if(bFilamentAction)
  5488. {
  5489. MENU_BEGIN();
  5490. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5491. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '1', mmu_cut_filament, 0);
  5492. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '2', mmu_cut_filament, 1);
  5493. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '3', mmu_cut_filament, 2);
  5494. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '4', mmu_cut_filament, 3);
  5495. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '5', mmu_cut_filament, 4);
  5496. MENU_END();
  5497. }
  5498. else
  5499. {
  5500. eFilamentAction=FilamentAction::MmuCut;
  5501. bFilamentFirstRun=false;
  5502. if(target_temperature[0]>=EXTRUDE_MINTEMP)
  5503. {
  5504. bFilamentPreheatState=true;
  5505. mFilamentItem(target_temperature[0],target_temperature_bed);
  5506. }
  5507. else lcd_generic_preheat_menu();
  5508. }
  5509. }
  5510. #endif //MMU_HAS_CUTTER
  5511. #ifdef SNMM
  5512. static void fil_unload_menu()
  5513. {
  5514. MENU_BEGIN();
  5515. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5516. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17
  5517. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17
  5518. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17
  5519. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17
  5520. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17
  5521. if (mmu_enabled)
  5522. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17
  5523. MENU_END();
  5524. }
  5525. static void change_extr_menu(){
  5526. MENU_BEGIN();
  5527. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5528. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17
  5529. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17
  5530. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17
  5531. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17
  5532. MENU_END();
  5533. }
  5534. #endif //SNMM
  5535. // unload filament for single material printer (used in M702 gcode)
  5536. // @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
  5537. void unload_filament(bool automatic)
  5538. {
  5539. custom_message_type = CustomMsg::FilamentLoading;
  5540. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  5541. raise_z_above(automatic? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);
  5542. // extr_unload2();
  5543. current_position[E_AXIS] -= 45;
  5544. plan_buffer_line_curposXYZE(5200 / 60);
  5545. st_synchronize();
  5546. current_position[E_AXIS] -= 15;
  5547. plan_buffer_line_curposXYZE(1000 / 60);
  5548. st_synchronize();
  5549. current_position[E_AXIS] -= 20;
  5550. plan_buffer_line_curposXYZE(1000 / 60);
  5551. st_synchronize();
  5552. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  5553. //disable extruder steppers so filament can be removed
  5554. disable_e0();
  5555. disable_e1();
  5556. disable_e2();
  5557. _delay(100);
  5558. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  5559. uint8_t counterBeep = 0;
  5560. while (!lcd_clicked() && (counterBeep < 50)) {
  5561. delay_keep_alive(100);
  5562. counterBeep++;
  5563. }
  5564. st_synchronize();
  5565. while (lcd_clicked()) delay_keep_alive(100);
  5566. lcd_update_enable(true);
  5567. lcd_setstatuspgm(MSG_WELCOME);
  5568. custom_message_type = CustomMsg::Status;
  5569. }
  5570. #include "xflash.h"
  5571. #ifdef LCD_TEST
  5572. static void lcd_test_menu()
  5573. {
  5574. XFLASH_SPI_ENTER();
  5575. xflash_enable_wr();
  5576. xflash_chip_erase();
  5577. xflash_disable_wr();
  5578. }
  5579. #endif //LCD_TEST
  5580. static bool fan_error_selftest()
  5581. {
  5582. #ifdef FANCHECK
  5583. if (!fans_check_enabled) return 0;
  5584. fanSpeed = 255;
  5585. #ifdef FAN_SOFT_PWM
  5586. fanSpeedSoftPwm = 255;
  5587. #endif //FAN_SOFT_PWM
  5588. manage_heater(); //enables print fan
  5589. setExtruderAutoFanState(3); //force enables the extruder fan
  5590. #ifdef FAN_SOFT_PWM
  5591. extruder_autofan_last_check = _millis();
  5592. fan_measuring = true;
  5593. #endif //FAN_SOFT_PWM
  5594. _delay(1000); //delay_keep_alive would turn off extruder fan, because temerature is too low (maybe)
  5595. manage_heater();
  5596. fanSpeed = 0;
  5597. setExtruderAutoFanState(1); //releases lock on the extruder fan
  5598. #ifdef FAN_SOFT_PWM
  5599. fanSpeedSoftPwm = 0;
  5600. #endif //FAN_SOFT_PWM
  5601. manage_heater();
  5602. #ifdef TACH_0
  5603. if (fan_speed[0] <= 20) { //extruder fan error
  5604. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_EXTRUDER);
  5605. return 1;
  5606. }
  5607. #endif
  5608. #ifdef TACH_1
  5609. if (fan_speed[1] <= 20) { //print fan error
  5610. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  5611. return 1;
  5612. }
  5613. #endif
  5614. #endif //FANCHECK
  5615. return 0;
  5616. }
  5617. //! @brief Resume paused print, send host action "resumed"
  5618. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  5619. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  5620. void lcd_resume_print()
  5621. {
  5622. lcd_return_to_status();
  5623. lcd_reset_alert_level(); //for fan speed error
  5624. if (fan_error_selftest()) {
  5625. if (is_usb_printing) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
  5626. return; //abort if error persists
  5627. }
  5628. cmdqueue_serial_disabled = false;
  5629. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5630. st_synchronize();
  5631. custom_message_type = CustomMsg::Resuming;
  5632. isPrintPaused = false;
  5633. restore_print_from_ram_and_continue(default_retraction);
  5634. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  5635. refresh_cmd_timeout();
  5636. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  5637. custom_message_type = CustomMsg::Status;
  5638. }
  5639. //! @brief Resume paused USB/host print, send host action "resume"
  5640. void lcd_resume_usb_print()
  5641. {
  5642. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUME); //resume octoprint
  5643. }
  5644. static void change_sheet()
  5645. {
  5646. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5647. menu_back(3);
  5648. }
  5649. static void lcd_rename_sheet_menu()
  5650. {
  5651. struct MenuData
  5652. {
  5653. bool initialized;
  5654. uint8_t selected;
  5655. char name[sizeof(Sheet::name)];
  5656. };
  5657. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  5658. MenuData* menuData = (MenuData*)&(menu_data[0]);
  5659. if (!menuData->initialized)
  5660. {
  5661. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  5662. lcd_encoder = menuData->name[0];
  5663. menuData->initialized = true;
  5664. }
  5665. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  5666. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  5667. menuData->name[menuData->selected] = lcd_encoder;
  5668. lcd_set_cursor(0,0);
  5669. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  5670. {
  5671. lcd_putc(menuData->name[i]);
  5672. }
  5673. lcd_set_cursor(menuData->selected, 1);
  5674. lcd_putc('^');
  5675. if (lcd_clicked())
  5676. {
  5677. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  5678. {
  5679. lcd_encoder = menuData->name[++(menuData->selected)];
  5680. }
  5681. else
  5682. {
  5683. eeprom_update_block(menuData->name,
  5684. EEPROM_Sheets_base->s[selected_sheet].name,
  5685. sizeof(Sheet::name));
  5686. menu_back();
  5687. }
  5688. }
  5689. }
  5690. static void lcd_reset_sheet()
  5691. {
  5692. SheetName sheetName;
  5693. eeprom_default_sheet_name(selected_sheet, sheetName);
  5694. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  5695. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  5696. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  5697. {
  5698. eeprom_switch_to_next_sheet();
  5699. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  5700. {
  5701. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  5702. }
  5703. }
  5704. menu_back();
  5705. }
  5706. //! @brief Activate selected_sheet and run first layer calibration
  5707. static void activate_calibrate_sheet()
  5708. {
  5709. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5710. lcd_first_layer_calibration_reset();
  5711. }
  5712. static void lcd_sheet_menu()
  5713. {
  5714. MENU_BEGIN();
  5715. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  5716. if(eeprom_is_sheet_initialized(selected_sheet)){
  5717. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  5718. }
  5719. if (lcd_commands_type == LcdCommands::Idle)
  5720. {
  5721. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);////MSG_V2_CALIBRATION c=18
  5722. }
  5723. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  5724. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet); ////MSG_RESET c=14
  5725. MENU_END();
  5726. }
  5727. //! @brief Show Main Menu
  5728. //!
  5729. //! @code{.unparsed}
  5730. //! |01234567890123456789|
  5731. //! | Info screen | allways
  5732. //!
  5733. //! | tst - Save | ifdef RESUME_DEBUG
  5734. //! | tst - Restore | ifdef RESUME_DEBUG
  5735. //!
  5736. //! | recover print | ifdef TMC2130_DEBUG
  5737. //! | power panic | ifdef TMC2130_DEBUG
  5738. //!
  5739. //! | Live adjust Z | printing + Z low
  5740. //!
  5741. //! | Change filament | farm mode
  5742. //!
  5743. //! | Tune | printing + paused
  5744. //! | Pause print | printing + not paused
  5745. //! | Resume print | printing + paused
  5746. //! | Stop print | printing or paused + NOT MBL
  5747. //! | Preheat | not printing + not paused
  5748. //! | Print from SD | not printing or paused
  5749. //!
  5750. //! | Switch sheet | farm mode
  5751. //!
  5752. //! | AutoLoad filament | not printing + not mmu or paused
  5753. //! | Load filament | not printing + mmu or paused
  5754. //! | Load to nozzle | not printing + mmu or paused
  5755. //! | Unload filament | not printing or paused
  5756. //! | Eject filament | not printing + mmu or paused
  5757. //! | Cut filament | not printing + mmu or paused + cut atctive
  5758. //! | Settings | not printing or paused
  5759. //! | Calibration | not printing
  5760. //! | Statistics | not printing
  5761. //! | Fail stats | allways
  5762. //! | Fail stats MMU | mmu
  5763. //! | Support | allways
  5764. //! @endcode
  5765. static void lcd_main_menu()
  5766. {
  5767. MENU_BEGIN();
  5768. // Majkl superawesome menu
  5769. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  5770. #ifdef RESUME_DEBUG
  5771. if (!saved_printing)
  5772. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  5773. else
  5774. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  5775. #endif //RESUME_DEBUG
  5776. #ifdef TMC2130_DEBUG
  5777. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  5778. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  5779. #endif //TMC2130_DEBUG
  5780. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
  5781. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  5782. }
  5783. if (farm_mode)
  5784. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5785. if ( moves_planned() || PRINTER_ACTIVE ) {
  5786. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  5787. } else {
  5788. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  5789. }
  5790. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  5791. if (is_usb_printing) {
  5792. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);////MSG_PAUSE_PRINT c=18
  5793. } else if (IS_SD_PRINTING) {
  5794. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);////MSG_PAUSE_PRINT c=18
  5795. }
  5796. }
  5797. if(isPrintPaused)
  5798. {
  5799. #ifdef FANCHECK
  5800. if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  5801. #endif //FANCHECK
  5802. {
  5803. if (is_usb_printing) {
  5804. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);////MSG_RESUME_PRINT c=18
  5805. } else {
  5806. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5807. }
  5808. }
  5809. }
  5810. if((IS_SD_PRINTING || is_usb_printing || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  5811. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5812. }
  5813. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  5814. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  5815. if (!card.isFileOpen()) {
  5816. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5817. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  5818. /*else*/{
  5819. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  5820. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  5821. }
  5822. }
  5823. #if SDCARDDETECT < 1
  5824. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD
  5825. #endif //SDCARDDETECT
  5826. }
  5827. } else {
  5828. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  5829. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=18
  5830. #if SDCARDDETECT < 1
  5831. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD
  5832. #endif //SDCARDDETECT
  5833. }
  5834. #endif //SDSUPPORT
  5835. if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5836. if (!farm_mode) {
  5837. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  5838. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  5839. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  5840. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  5841. }
  5842. }
  5843. }
  5844. if ( ! ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
  5845. if (mmu_enabled) {
  5846. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  5847. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  5848. //-// MENU_ITEM_FUNCTION_P(_T(MSG_UNLOAD_FILAMENT), extr_unload);
  5849. //bFilamentFirstRun=true;
  5850. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  5851. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  5852. #ifdef MMU_HAS_CUTTER
  5853. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  5854. #endif //MMU_HAS_CUTTER
  5855. } else {
  5856. #ifdef SNMM
  5857. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  5858. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20
  5859. #endif
  5860. #ifdef FILAMENT_SENSOR
  5861. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  5862. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  5863. else
  5864. #endif //FILAMENT_SENSOR
  5865. {
  5866. bFilamentFirstRun=true;
  5867. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5868. }
  5869. bFilamentFirstRun=true;
  5870. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5871. }
  5872. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5873. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5874. }
  5875. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5876. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  5877. }
  5878. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  5879. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  5880. #endif
  5881. if (mmu_enabled) {
  5882. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  5883. }
  5884. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  5885. #ifdef LCD_TEST
  5886. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_SUPPORT
  5887. #endif //LCD_TEST
  5888. MENU_END();
  5889. }
  5890. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5891. bool stepper_timer_overflow_state = false;
  5892. uint16_t stepper_timer_overflow_max = 0;
  5893. uint16_t stepper_timer_overflow_last = 0;
  5894. uint16_t stepper_timer_overflow_cnt = 0;
  5895. void stepper_timer_overflow() {
  5896. char msg[28];
  5897. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5898. lcd_setstatus(msg);
  5899. stepper_timer_overflow_state = false;
  5900. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5901. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5902. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5903. MYSERIAL.print(msg);
  5904. SERIAL_ECHOLNPGM("");
  5905. WRITE(BEEPER, LOW);
  5906. }
  5907. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5908. static void lcd_colorprint_change() {
  5909. enquecommand_P(PSTR("M600"));
  5910. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  5911. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5912. lcd_return_to_status();
  5913. lcd_draw_update = 3;
  5914. }
  5915. #ifdef LA_LIVE_K
  5916. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  5917. // redefine our custom handling functions to mimick other tunables
  5918. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  5919. static void lcd_advance_draw_K(char chr, float val)
  5920. {
  5921. if (val <= 0)
  5922. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  5923. else
  5924. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  5925. }
  5926. static void lcd_advance_edit_K(void)
  5927. {
  5928. if (lcd_draw_update)
  5929. {
  5930. if (lcd_encoder < 0) lcd_encoder = 0;
  5931. if (lcd_encoder > 999) lcd_encoder = 999;
  5932. lcd_set_cursor(0, 1);
  5933. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  5934. }
  5935. if (LCD_CLICKED)
  5936. {
  5937. extruder_advance_K = 0.01 * lcd_encoder;
  5938. menu_back_no_reset();
  5939. }
  5940. }
  5941. static uint8_t lcd_advance_K()
  5942. {
  5943. if (menu_item == menu_line)
  5944. {
  5945. if (lcd_draw_update)
  5946. {
  5947. lcd_set_cursor(0, menu_row);
  5948. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5949. }
  5950. if (menu_clicked && (lcd_encoder == menu_item))
  5951. {
  5952. menu_submenu_no_reset(lcd_advance_edit_K);
  5953. lcd_encoder = 100. * extruder_advance_K;
  5954. return menu_item_ret();
  5955. }
  5956. }
  5957. menu_item++;
  5958. return 0;
  5959. }
  5960. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5961. #endif
  5962. static void lcd_tune_menu()
  5963. {
  5964. typedef struct
  5965. {
  5966. menu_data_edit_t reserved; //!< reserved for number editing functions
  5967. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5968. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5969. //! it needs to be applied.
  5970. int16_t extrudemultiply;
  5971. } _menu_data_t;
  5972. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5973. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5974. if (_md->status == 0)
  5975. {
  5976. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5977. _md->status = 1;
  5978. _md->extrudemultiply = extrudemultiply;
  5979. }
  5980. else if (_md->extrudemultiply != extrudemultiply)
  5981. {
  5982. // extrudemultiply has been changed from the child menu. Apply the new value.
  5983. _md->extrudemultiply = extrudemultiply;
  5984. calculate_extruder_multipliers();
  5985. }
  5986. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  5987. MENU_BEGIN();
  5988. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5989. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  5990. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5991. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5992. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5993. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  5994. #ifdef LA_LIVE_K
  5995. MENU_ITEM_EDIT_advance_K();//7
  5996. #endif
  5997. #ifdef FILAMENTCHANGEENABLE
  5998. if (!farm_mode)
  5999. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  6000. #endif
  6001. #ifdef FILAMENT_SENSOR
  6002. if (FSensorStateMenu == 0) {
  6003. if (fsensor_not_responding && (mmu_enabled == false)) {
  6004. /* Filament sensor not working*/
  6005. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);
  6006. }
  6007. else {
  6008. /* Filament sensor turned off, working, no problems*/
  6009. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);
  6010. }
  6011. }
  6012. else {
  6013. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);
  6014. }
  6015. #ifdef IR_SENSOR_ANALOG
  6016. FSENSOR_ACTION_NA;
  6017. #endif //IR_SENSOR_ANALOG
  6018. #endif //FILAMENT_SENSOR
  6019. SETTINGS_AUTO_DEPLETE;
  6020. SETTINGS_CUTTER;
  6021. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  6022. #ifdef TMC2130
  6023. if(!farm_mode)
  6024. {
  6025. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  6026. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  6027. if (SilentModeMenu == SILENT_MODE_NORMAL)
  6028. {
  6029. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  6030. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  6031. }
  6032. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  6033. }
  6034. #else //TMC2130
  6035. if (!farm_mode) { //dont show in menu if we are in farm mode
  6036. switch (SilentModeMenu) {
  6037. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  6038. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  6039. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  6040. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  6041. }
  6042. }
  6043. #endif //TMC2130
  6044. SETTINGS_MMU_MODE;
  6045. SETTINGS_SOUND;
  6046. #ifdef LCD_BL_PIN
  6047. if (backlightSupport)
  6048. {
  6049. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  6050. }
  6051. #endif //LCD_BL_PIN
  6052. MENU_END();
  6053. }
  6054. static void mbl_magnets_elimination_toggle() {
  6055. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6056. magnet_elimination = !magnet_elimination;
  6057. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  6058. }
  6059. static void mbl_mesh_toggle() {
  6060. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6061. if(mesh_nr == 3) mesh_nr = 7;
  6062. else mesh_nr = 3;
  6063. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  6064. }
  6065. static void mbl_probe_nr_toggle() {
  6066. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  6067. switch (mbl_z_probe_nr) {
  6068. case 1: mbl_z_probe_nr = 3; break;
  6069. case 3: mbl_z_probe_nr = 5; break;
  6070. case 5: mbl_z_probe_nr = 1; break;
  6071. default: mbl_z_probe_nr = 3; break;
  6072. }
  6073. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  6074. }
  6075. static void lcd_mesh_bed_leveling_settings()
  6076. {
  6077. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6078. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6079. char sToggle[4]; //enough for nxn format
  6080. MENU_BEGIN();
  6081. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6082. sToggle[0] = points_nr + '0';
  6083. sToggle[1] = 'x';
  6084. sToggle[2] = points_nr + '0';
  6085. sToggle[3] = 0;
  6086. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  6087. sToggle[0] = mbl_z_probe_nr + '0';
  6088. sToggle[1] = 0;
  6089. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  6090. 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);
  6091. MENU_END();
  6092. //SETTINGS_MBL_MODE;
  6093. }
  6094. #ifdef LCD_BL_PIN
  6095. static void backlight_mode_toggle()
  6096. {
  6097. switch (backlightMode)
  6098. {
  6099. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  6100. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  6101. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6102. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6103. }
  6104. backlight_save();
  6105. }
  6106. static void lcd_backlight_menu()
  6107. {
  6108. MENU_BEGIN();
  6109. ON_MENU_LEAVE(
  6110. backlight_save();
  6111. );
  6112. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6113. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  6114. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  6115. 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);
  6116. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  6117. MENU_END();
  6118. }
  6119. #endif //LCD_BL_PIN
  6120. static void lcd_control_temperature_menu()
  6121. {
  6122. #ifdef PIDTEMP
  6123. // set up temp variables - undo the default scaling
  6124. // raw_Ki = unscalePID_i(Ki);
  6125. // raw_Kd = unscalePID_d(Kd);
  6126. #endif
  6127. MENU_BEGIN();
  6128. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6129. #if TEMP_SENSOR_0 != 0
  6130. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  6131. #endif
  6132. #if TEMP_SENSOR_1 != 0
  6133. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1
  6134. #endif
  6135. #if TEMP_SENSOR_2 != 0
  6136. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2
  6137. #endif
  6138. #if TEMP_SENSOR_BED != 0
  6139. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  6140. #endif
  6141. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  6142. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  6143. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  6144. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  6145. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN
  6146. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX
  6147. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR
  6148. #endif
  6149. MENU_END();
  6150. }
  6151. static void lcd_sd_refresh()
  6152. {
  6153. #if SDCARDDETECT == -1
  6154. card.initsd();
  6155. #else
  6156. card.presort();
  6157. #endif
  6158. menu_top = 0;
  6159. lcd_encoder = 0;
  6160. menu_data_reset(); //Forces reloading of cached variables.
  6161. }
  6162. static void lcd_sd_updir()
  6163. {
  6164. card.updir();
  6165. menu_top = 0;
  6166. lcd_encoder = 0;
  6167. menu_data_reset(); //Forces reloading of cached variables.
  6168. }
  6169. void lcd_print_stop()
  6170. {
  6171. if (!card.sdprinting) {
  6172. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  6173. }
  6174. UnconditionalStop();
  6175. // TODO: all the following should be moved in the main marlin loop!
  6176. #ifdef MESH_BED_LEVELING
  6177. mbl.active = false; //also prevents undoing the mbl compensation a second time in the second planner_abort_hard()
  6178. #endif
  6179. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  6180. stoptime = _millis();
  6181. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  6182. pause_time = 0;
  6183. save_statistics(total_filament_used, t);
  6184. // reset current command
  6185. lcd_commands_step = 0;
  6186. lcd_commands_type = LcdCommands::Idle;
  6187. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  6188. current_position[Z_AXIS] += 10; //lift Z.
  6189. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  6190. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) //if axis are homed, move to parked position.
  6191. {
  6192. current_position[X_AXIS] = X_CANCEL_POS;
  6193. current_position[Y_AXIS] = Y_CANCEL_POS;
  6194. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6195. }
  6196. st_synchronize();
  6197. if (mmu_enabled) extr_unload(); //M702 C
  6198. finishAndDisableSteppers(); //M84
  6199. lcd_setstatuspgm(MSG_WELCOME);
  6200. custom_message_type = CustomMsg::Status;
  6201. 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.
  6202. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  6203. isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario.
  6204. }
  6205. void lcd_sdcard_stop()
  6206. {
  6207. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  6208. lcd_puts_at_P(2, 2, _T(MSG_NO));
  6209. lcd_puts_at_P(2, 3, _T(MSG_YES));
  6210. lcd_putc_at(0, 2, ' ');
  6211. lcd_putc_at(0, 3, ' ');
  6212. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  6213. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  6214. lcd_putc_at(0, 1 + lcd_encoder, '>');
  6215. if (lcd_clicked())
  6216. {
  6217. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  6218. if ((int32_t)lcd_encoder == 1)
  6219. {
  6220. lcd_return_to_status();
  6221. }
  6222. if ((int32_t)lcd_encoder == 2)
  6223. {
  6224. lcd_print_stop();
  6225. }
  6226. }
  6227. }
  6228. void lcd_sdcard_menu()
  6229. {
  6230. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  6231. typedef struct
  6232. {
  6233. menuState_t menuState = _uninitialized;
  6234. uint8_t offset;
  6235. bool isDir;
  6236. const char* scrollPointer;
  6237. uint16_t selectedFileID;
  6238. uint16_t fileCnt;
  6239. int8_t row;
  6240. uint8_t sdSort;
  6241. ShortTimer lcd_scrollTimer;
  6242. } _menu_data_sdcard_t;
  6243. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  6244. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  6245. switch(_md->menuState)
  6246. {
  6247. case _uninitialized: //Initialize menu data
  6248. {
  6249. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  6250. {
  6251. card.presort_flag = false;
  6252. card.presort();
  6253. }
  6254. _md->fileCnt = card.getnrfilenames();
  6255. _md->sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  6256. _md->menuState = _standard;
  6257. }
  6258. // FALLTHRU
  6259. case _standard: //normal menu structure.
  6260. {
  6261. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  6262. {
  6263. _md->lcd_scrollTimer.start();
  6264. lcd_draw_update = 1;
  6265. }
  6266. if (_md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  6267. {
  6268. _md->menuState = _scrolling;
  6269. _md->offset = 0;
  6270. _md->scrollPointer = NULL;
  6271. _md->lcd_scrollTimer.start();
  6272. lcd_draw_update = 1; //forces last load before switching to scrolling.
  6273. }
  6274. if (lcd_draw_update == 0 && !LCD_CLICKED)
  6275. return; // nothing to do (so don't thrash the SD card)
  6276. _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.
  6277. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  6278. _md->lcd_scrollTimer.start();
  6279. MENU_BEGIN();
  6280. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  6281. card.getWorkDirName();
  6282. if (card.filename[0] == '/')
  6283. {
  6284. #if SDCARDDETECT == -1
  6285. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  6286. #else
  6287. if (card.ToshibaFlashAir_isEnabled())
  6288. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  6289. #endif
  6290. }
  6291. else
  6292. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  6293. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  6294. {
  6295. if (menu_item == menu_line) //If the file is on the screen.
  6296. {
  6297. //load filename to memory.
  6298. #ifdef SDCARD_SORT_ALPHA
  6299. if (_md->sdSort == SD_SORT_NONE)
  6300. card.getfilename(i);
  6301. else
  6302. card.getfilename_sorted(i, _md->sdSort);
  6303. #else
  6304. card.getfilename(i);
  6305. #endif
  6306. if (lcd_encoder == menu_item) //If the file is selected.
  6307. {
  6308. _md->selectedFileID = i;
  6309. _md->isDir = card.filenameIsDir;
  6310. _md->row = menu_row;
  6311. }
  6312. if (card.filenameIsDir)
  6313. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  6314. else
  6315. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  6316. }
  6317. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  6318. }
  6319. MENU_END();
  6320. } break;
  6321. case _scrolling: //scrolling filename
  6322. {
  6323. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  6324. if (_md->scrollPointer == NULL)
  6325. {
  6326. //load filename to memory.
  6327. #ifdef SDCARD_SORT_ALPHA
  6328. if (_md->sdSort == SD_SORT_NONE)
  6329. card.getfilename(_md->selectedFileID);
  6330. else
  6331. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  6332. #else
  6333. card.getfilename(_md->selectedFileID);
  6334. #endif
  6335. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  6336. }
  6337. if (rewindFlag == 1)
  6338. _md->offset = 0; //redraw once again from the beginning.
  6339. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  6340. {
  6341. uint8_t i = LCD_WIDTH - ((_md->isDir)?2:1);
  6342. lcd_set_cursor(0, _md->row);
  6343. lcd_print('>');
  6344. if (_md->isDir)
  6345. lcd_print(LCD_STR_FOLDER[0]);
  6346. for (; i != 0; i--)
  6347. {
  6348. const char* c = (_md->scrollPointer + _md->offset + ((LCD_WIDTH - ((_md->isDir)?2:1)) - i));
  6349. lcd_print(c[0]);
  6350. if (c[1])
  6351. _md->lcd_scrollTimer.start();
  6352. else
  6353. {
  6354. _md->lcd_scrollTimer.stop();
  6355. break; //stop at the end of the string
  6356. }
  6357. }
  6358. if (i != 0) //adds spaces if string is incomplete or at the end (instead of null).
  6359. {
  6360. lcd_space(i);
  6361. }
  6362. _md->offset++;
  6363. }
  6364. if (rewindFlag) //go back to sd_menu.
  6365. {
  6366. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  6367. _md->menuState = _standard;
  6368. }
  6369. } break;
  6370. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  6371. }
  6372. }
  6373. #ifdef TMC2130
  6374. static void lcd_belttest_v()
  6375. {
  6376. lcd_belttest();
  6377. menu_back_if_clicked();
  6378. }
  6379. void lcd_belttest()
  6380. {
  6381. lcd_clear();
  6382. // Belttest requires high power mode. Enable it.
  6383. FORCE_HIGH_POWER_START;
  6384. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6385. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6386. lcd_printf_P(_T(MSG_CHECKING_X));
  6387. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  6388. KEEPALIVE_STATE(IN_HANDLER);
  6389. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  6390. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  6391. if (lcd_selfcheck_axis_sg(X_AXIS)){
  6392. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6393. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  6394. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  6395. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  6396. if (lcd_selfcheck_axis_sg(Y_AXIS))
  6397. {
  6398. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6399. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  6400. lcd_set_cursor(19, 3);
  6401. lcd_print(LCD_STR_UPLEVEL[0]);
  6402. lcd_wait_for_click_delay(10);
  6403. }
  6404. }
  6405. FORCE_HIGH_POWER_END;
  6406. KEEPALIVE_STATE(NOT_BUSY);
  6407. }
  6408. #endif //TMC2130
  6409. #ifdef IR_SENSOR_ANALOG
  6410. // called also from marlin_main.cpp
  6411. void printf_IRSensorAnalogBoardChange(){
  6412. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), FsensorIRVersionText());
  6413. }
  6414. static bool lcd_selftest_IRsensor(bool bStandalone)
  6415. {
  6416. bool bPCBrev04;
  6417. uint16_t volt_IR_int;
  6418. volt_IR_int = current_voltage_raw_IR;
  6419. bPCBrev04=(volt_IR_int < IRsensor_Hopen_TRESHOLD);
  6420. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  6421. if(volt_IR_int < IRsensor_Hmin_TRESHOLD){
  6422. if(!bStandalone)
  6423. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  6424. return(false);
  6425. }
  6426. 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
  6427. volt_IR_int = current_voltage_raw_IR;
  6428. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  6429. if(volt_IR_int > (IRsensor_Lmax_TRESHOLD)){
  6430. if(!bStandalone)
  6431. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  6432. return(false);
  6433. }
  6434. if((bPCBrev04 ? 1 : 0) != (uint8_t)oFsensorPCB){ // safer then "(uint8_t)bPCBrev04"
  6435. oFsensorPCB=bPCBrev04 ? ClFsensorPCB::_Rev04 : ClFsensorPCB::_Old;
  6436. printf_IRSensorAnalogBoardChange();
  6437. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB);
  6438. }
  6439. return(true);
  6440. }
  6441. static void lcd_detect_IRsensor(){
  6442. bool bAction;
  6443. bool loaded;
  6444. bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()"
  6445. /// Check if filament is loaded. If it is loaded stop detection.
  6446. /// @todo Add autodetection with MMU2s
  6447. loaded = ! READ(IR_SENSOR_PIN);
  6448. if(loaded ){
  6449. 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
  6450. return;
  6451. } else {
  6452. 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
  6453. bAction = lcd_selftest_IRsensor(true);
  6454. }
  6455. if(bAction){
  6456. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  6457. // the fsensor board has been successfully identified, any previous "not responding" may be cleared now
  6458. fsensor_not_responding = false;
  6459. } else {
  6460. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  6461. // here it is unclear what to to with the fsensor_not_responding flag
  6462. }
  6463. bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()"
  6464. }
  6465. #endif //IR_SENSOR_ANALOG
  6466. static void lcd_selftest_v()
  6467. {
  6468. (void)lcd_selftest();
  6469. }
  6470. bool lcd_selftest()
  6471. {
  6472. uint8_t _progress = 0;
  6473. bool _result = true;
  6474. bool _swapped_fan = false;
  6475. #ifdef IR_SENSOR_ANALOG
  6476. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  6477. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  6478. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  6479. if( oFsensorPCB == ClFsensorPCB::_Undef) {
  6480. if (!mmu_enabled) {
  6481. lcd_detect_IRsensor();
  6482. }
  6483. else {
  6484. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,0);
  6485. }
  6486. }
  6487. #endif //IR_SENSOR_ANALOG
  6488. lcd_wait_for_cool_down();
  6489. lcd_clear();
  6490. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  6491. #ifdef TMC2130
  6492. FORCE_HIGH_POWER_START;
  6493. #endif // TMC2130
  6494. FORCE_BL_ON_START;
  6495. _delay(2000);
  6496. KEEPALIVE_STATE(IN_HANDLER);
  6497. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  6498. #if (defined(FANCHECK) && defined(TACH_0))
  6499. switch (lcd_selftest_fan_auto(0)){ // check extruder Fan
  6500. case FanCheck::ExtruderFan:
  6501. _result = false;
  6502. break;
  6503. case FanCheck::SwappedFan:
  6504. _swapped_fan = true;
  6505. // FALLTHRU
  6506. default:
  6507. _result = true;
  6508. break;
  6509. }
  6510. #else //defined(TACH_0)
  6511. _result = lcd_selftest_manual_fan_check(0, false);
  6512. #endif //defined(TACH_0)
  6513. if (!_result)
  6514. {
  6515. lcd_selftest_error(TestError::ExtruderFan, "", "");
  6516. }
  6517. if (_result)
  6518. {
  6519. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  6520. #if (defined(FANCHECK) && defined(TACH_1))
  6521. switch (lcd_selftest_fan_auto(1)){ // check print fan
  6522. case FanCheck::PrintFan:
  6523. _result = false;
  6524. break;
  6525. case FanCheck::SwappedFan:
  6526. _swapped_fan = true;
  6527. // FALLTHRU
  6528. default:
  6529. _result = true;
  6530. break;
  6531. }
  6532. #else //defined(TACH_1)
  6533. _result = lcd_selftest_manual_fan_check(1, false);
  6534. #endif //defined(TACH_1)
  6535. if (!_result)
  6536. {
  6537. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  6538. }
  6539. }
  6540. if (_swapped_fan) {
  6541. //turn on print fan and check that left extruder fan is not spinning
  6542. _result = lcd_selftest_manual_fan_check(1, true);
  6543. if (_result) {
  6544. //print fan is stil turned on; check that it is spinning
  6545. _result = lcd_selftest_manual_fan_check(1, false, true);
  6546. if (!_result){
  6547. lcd_selftest_error(TestError::PrintFan, "", "");
  6548. }
  6549. }
  6550. else {
  6551. // fans are swapped
  6552. lcd_selftest_error(TestError::SwappedFan, "", "");
  6553. }
  6554. }
  6555. if (_result)
  6556. {
  6557. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  6558. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  6559. }
  6560. if (_result)
  6561. {
  6562. //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
  6563. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  6564. #ifdef TMC2130
  6565. _result = lcd_selfcheck_axis_sg(X_AXIS);
  6566. #else
  6567. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  6568. #endif //TMC2130
  6569. }
  6570. if (_result)
  6571. {
  6572. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  6573. #ifndef TMC2130
  6574. _result = lcd_selfcheck_pulleys(X_AXIS);
  6575. #endif
  6576. }
  6577. if (_result)
  6578. {
  6579. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  6580. #ifdef TMC2130
  6581. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  6582. #else
  6583. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  6584. #endif // TMC2130
  6585. }
  6586. if (_result)
  6587. {
  6588. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  6589. #ifndef TMC2130
  6590. _result = lcd_selfcheck_pulleys(Y_AXIS);
  6591. #endif // TMC2130
  6592. }
  6593. if (_result)
  6594. {
  6595. #ifdef TMC2130
  6596. tmc2130_home_exit();
  6597. enable_endstops(false);
  6598. #endif
  6599. //homeaxis(X_AXIS);
  6600. //homeaxis(Y_AXIS);
  6601. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  6602. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  6603. #ifdef TMC2130
  6604. //current_position[X_AXIS] += 0;
  6605. current_position[Y_AXIS] += 4;
  6606. #endif //TMC2130
  6607. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6608. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6609. st_synchronize();
  6610. set_destination_to_current();
  6611. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  6612. #ifdef TMC2130
  6613. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  6614. #else
  6615. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  6616. #endif //TMC2130
  6617. //raise Z to not damage the bed during and hotend testing
  6618. current_position[Z_AXIS] += 20;
  6619. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6620. st_synchronize();
  6621. }
  6622. #ifdef TMC2130
  6623. if (_result)
  6624. {
  6625. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6626. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6627. st_synchronize();
  6628. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  6629. bool bres = tmc2130_home_calibrate(X_AXIS);
  6630. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  6631. bres &= tmc2130_home_calibrate(Y_AXIS);
  6632. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  6633. if (bres)
  6634. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  6635. _result = bres;
  6636. }
  6637. #endif //TMC2130
  6638. if (_result)
  6639. {
  6640. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  6641. _result = lcd_selfcheck_check_heater(true);
  6642. }
  6643. if (_result)
  6644. {
  6645. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  6646. _result = lcd_selfcheck_check_heater(false);
  6647. }
  6648. if (_result)
  6649. {
  6650. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  6651. }
  6652. #ifdef FILAMENT_SENSOR
  6653. if (_result)
  6654. {
  6655. if (mmu_enabled)
  6656. {
  6657. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6658. _result = selftest_irsensor();
  6659. if (_result)
  6660. {
  6661. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6662. }
  6663. } else
  6664. {
  6665. #ifdef PAT9125
  6666. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6667. _result = lcd_selftest_fsensor();
  6668. if (_result)
  6669. {
  6670. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6671. }
  6672. #endif //PAT9125
  6673. #if 0
  6674. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  6675. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  6676. //def IR_SENSOR_ANALOG
  6677. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  6678. _result = lcd_selftest_IRsensor();
  6679. if (_result)
  6680. {
  6681. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  6682. }
  6683. #endif //IR_SENSOR_ANALOG
  6684. }
  6685. }
  6686. #endif //FILAMENT_SENSOR
  6687. if (_result)
  6688. {
  6689. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  6690. }
  6691. else
  6692. {
  6693. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  6694. }
  6695. lcd_reset_alert_level();
  6696. enquecommand_P(PSTR("M84"));
  6697. lcd_update_enable(true);
  6698. if (_result)
  6699. {
  6700. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  6701. }
  6702. else
  6703. {
  6704. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6705. }
  6706. #ifdef TMC2130
  6707. FORCE_HIGH_POWER_END;
  6708. #endif // TMC2130
  6709. FORCE_BL_ON_END;
  6710. KEEPALIVE_STATE(NOT_BUSY);
  6711. return(_result);
  6712. }
  6713. #ifdef TMC2130
  6714. static void reset_crash_det(uint8_t axis) {
  6715. current_position[axis] += 10;
  6716. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6717. st_synchronize();
  6718. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  6719. }
  6720. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  6721. // each axis length is measured twice
  6722. float axis_length, current_position_init, current_position_final;
  6723. float measured_axis_length[2];
  6724. float margin = 60;
  6725. float max_error_mm = 5;
  6726. switch (axis) {
  6727. case 0: axis_length = X_MAX_POS; break;
  6728. case 1: axis_length = Y_MAX_POS + 8; break;
  6729. default: axis_length = 210; break;
  6730. }
  6731. tmc2130_sg_stop_on_crash = false;
  6732. tmc2130_home_exit();
  6733. enable_endstops(true);
  6734. raise_z_above(MESH_HOME_Z_SEARCH);
  6735. st_synchronize();
  6736. tmc2130_home_enter(1 << axis);
  6737. // first axis length measurement begin
  6738. current_position[axis] -= (axis_length + margin);
  6739. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6740. st_synchronize();
  6741. tmc2130_sg_meassure_start(axis);
  6742. current_position_init = st_get_position_mm(axis);
  6743. current_position[axis] += 2 * margin;
  6744. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6745. st_synchronize();
  6746. current_position[axis] += axis_length;
  6747. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6748. st_synchronize();
  6749. uint16_t sg1 = tmc2130_sg_meassure_stop();
  6750. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  6751. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  6752. current_position_final = st_get_position_mm(axis);
  6753. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  6754. // first measurement end and second measurement begin
  6755. current_position[axis] -= margin;
  6756. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6757. st_synchronize();
  6758. current_position[axis] -= (axis_length + margin);
  6759. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6760. st_synchronize();
  6761. current_position_init = st_get_position_mm(axis);
  6762. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  6763. tmc2130_home_exit();
  6764. //end of second measurement, now check for possible errors:
  6765. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  6766. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  6767. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  6768. enable_endstops(false);
  6769. const char *_error_1;
  6770. if (axis == X_AXIS) _error_1 = "X";
  6771. if (axis == Y_AXIS) _error_1 = "Y";
  6772. if (axis == Z_AXIS) _error_1 = "Z";
  6773. lcd_selftest_error(TestError::Axis, _error_1, "");
  6774. current_position[axis] = 0;
  6775. plan_set_position_curposXYZE();
  6776. reset_crash_det(axis);
  6777. enable_endstops(true);
  6778. endstops_hit_on_purpose();
  6779. return false;
  6780. }
  6781. }
  6782. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  6783. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  6784. //loose pulleys
  6785. const char *_error_1;
  6786. if (axis == X_AXIS) _error_1 = "X";
  6787. if (axis == Y_AXIS) _error_1 = "Y";
  6788. if (axis == Z_AXIS) _error_1 = "Z";
  6789. lcd_selftest_error(TestError::Pulley, _error_1, "");
  6790. current_position[axis] = 0;
  6791. plan_set_position_curposXYZE();
  6792. reset_crash_det(axis);
  6793. endstops_hit_on_purpose();
  6794. return false;
  6795. }
  6796. current_position[axis] = 0;
  6797. plan_set_position_curposXYZE();
  6798. reset_crash_det(axis);
  6799. endstops_hit_on_purpose();
  6800. return true;
  6801. }
  6802. #endif //TMC2130
  6803. #ifndef TMC2130
  6804. static bool lcd_selfcheck_axis(int _axis, int _travel)
  6805. {
  6806. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  6807. bool _stepdone = false;
  6808. bool _stepresult = false;
  6809. uint8_t _progress = 0;
  6810. int _travel_done = 0;
  6811. int _err_endstop = 0;
  6812. int _lcd_refresh = 0;
  6813. _travel = _travel + (_travel / 10);
  6814. if (_axis == X_AXIS) {
  6815. current_position[Z_AXIS] += 17;
  6816. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6817. }
  6818. do {
  6819. current_position[_axis] = current_position[_axis] - 1;
  6820. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6821. st_synchronize();
  6822. #ifdef TMC2130
  6823. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6824. #else //TMC2130
  6825. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  6826. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  6827. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6828. #endif //TMC2130
  6829. {
  6830. if (_axis == 0)
  6831. {
  6832. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6833. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  6834. }
  6835. if (_axis == 1)
  6836. {
  6837. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6838. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  6839. }
  6840. if (_axis == 2)
  6841. {
  6842. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6843. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  6844. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  6845. /*disable_x();
  6846. disable_y();
  6847. disable_z();*/
  6848. }
  6849. _stepdone = true;
  6850. }
  6851. if (_lcd_refresh < 6)
  6852. {
  6853. _lcd_refresh++;
  6854. }
  6855. else
  6856. {
  6857. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  6858. _lcd_refresh = 0;
  6859. }
  6860. manage_heater();
  6861. manage_inactivity(true);
  6862. //_delay(100);
  6863. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  6864. } while (!_stepdone);
  6865. //current_position[_axis] = current_position[_axis] + 15;
  6866. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  6867. if (!_stepresult)
  6868. {
  6869. const char *_error_1;
  6870. const char *_error_2;
  6871. if (_axis == X_AXIS) _error_1 = "X";
  6872. if (_axis == Y_AXIS) _error_1 = "Y";
  6873. if (_axis == Z_AXIS) _error_1 = "Z";
  6874. if (_err_endstop == 0) _error_2 = "X";
  6875. if (_err_endstop == 1) _error_2 = "Y";
  6876. if (_err_endstop == 2) _error_2 = "Z";
  6877. if (_travel_done >= _travel)
  6878. {
  6879. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  6880. }
  6881. else
  6882. {
  6883. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  6884. }
  6885. }
  6886. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  6887. plan_set_position_curposXYZE();
  6888. return _stepresult;
  6889. }
  6890. static bool lcd_selfcheck_pulleys(int axis)
  6891. {
  6892. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  6893. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  6894. float current_position_init;
  6895. float move;
  6896. bool endstop_triggered = false;
  6897. int i;
  6898. unsigned long timeout_counter;
  6899. refresh_cmd_timeout();
  6900. manage_inactivity(true);
  6901. if (axis == 0) move = 50; //X_AXIS
  6902. else move = 50; //Y_AXIS
  6903. current_position_init = current_position[axis];
  6904. current_position[axis] += 2;
  6905. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6906. for (i = 0; i < 5; i++) {
  6907. refresh_cmd_timeout();
  6908. current_position[axis] = current_position[axis] + move;
  6909. st_current_set(0, 850); //set motor current higher
  6910. plan_buffer_line_curposXYZE(200);
  6911. st_synchronize();
  6912. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  6913. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  6914. current_position[axis] = current_position[axis] - move;
  6915. plan_buffer_line_curposXYZE(50);
  6916. st_synchronize();
  6917. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6918. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6919. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6920. return(false);
  6921. }
  6922. }
  6923. timeout_counter = _millis() + 2500;
  6924. endstop_triggered = false;
  6925. manage_inactivity(true);
  6926. while (!endstop_triggered) {
  6927. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6928. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6929. endstop_triggered = true;
  6930. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  6931. current_position[axis] += 10;
  6932. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6933. st_synchronize();
  6934. return(true);
  6935. }
  6936. else {
  6937. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6938. return(false);
  6939. }
  6940. }
  6941. else {
  6942. current_position[axis] -= 1;
  6943. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6944. st_synchronize();
  6945. if (_millis() > timeout_counter) {
  6946. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6947. return(false);
  6948. }
  6949. }
  6950. }
  6951. return(true);
  6952. }
  6953. #endif //not defined TMC2130
  6954. static bool lcd_selfcheck_endstops()
  6955. {
  6956. bool _result = true;
  6957. if (
  6958. #ifndef TMC2130
  6959. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6960. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6961. #endif //!TMC2130
  6962. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6963. {
  6964. #ifndef TMC2130
  6965. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6966. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6967. #endif //!TMC2130
  6968. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  6969. }
  6970. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6971. st_synchronize();
  6972. if (
  6973. #ifndef TMC2130
  6974. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6975. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6976. #endif //!TMC2130
  6977. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6978. {
  6979. _result = false;
  6980. char _error[4] = "";
  6981. #ifndef TMC2130
  6982. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  6983. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  6984. #endif //!TMC2130
  6985. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  6986. lcd_selftest_error(TestError::Endstops, _error, "");
  6987. }
  6988. manage_heater();
  6989. manage_inactivity(true);
  6990. return _result;
  6991. }
  6992. static bool lcd_selfcheck_check_heater(bool _isbed)
  6993. {
  6994. uint8_t _counter = 0;
  6995. uint8_t _progress = 0;
  6996. bool _stepresult = false;
  6997. bool _docycle = true;
  6998. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  6999. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  7000. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  7001. target_temperature[0] = (_isbed) ? 0 : 200;
  7002. target_temperature_bed = (_isbed) ? 100 : 0;
  7003. manage_heater();
  7004. manage_inactivity(true);
  7005. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  7006. do {
  7007. _counter++;
  7008. _docycle = (_counter < _cycles) ? true : false;
  7009. manage_heater();
  7010. manage_inactivity(true);
  7011. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  7012. /*if (_isbed) {
  7013. MYSERIAL.print("Bed temp:");
  7014. MYSERIAL.println(degBed());
  7015. }
  7016. else {
  7017. MYSERIAL.print("Hotend temp:");
  7018. MYSERIAL.println(degHotend(0));
  7019. }*/
  7020. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  7021. } while (_docycle);
  7022. target_temperature[0] = 0;
  7023. target_temperature_bed = 0;
  7024. manage_heater();
  7025. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  7026. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  7027. /*
  7028. MYSERIAL.println("");
  7029. MYSERIAL.print("Checked result:");
  7030. MYSERIAL.println(_checked_result);
  7031. MYSERIAL.print("Opposite result:");
  7032. MYSERIAL.println(_opposite_result);
  7033. */
  7034. if (_opposite_result < ((_isbed) ? 30 : 9))
  7035. {
  7036. if (_checked_result >= ((_isbed) ? 9 : 30))
  7037. {
  7038. _stepresult = true;
  7039. }
  7040. else
  7041. {
  7042. lcd_selftest_error(TestError::Heater, "", "");
  7043. }
  7044. }
  7045. else
  7046. {
  7047. lcd_selftest_error(TestError::Bed, "", "");
  7048. }
  7049. manage_heater();
  7050. manage_inactivity(true);
  7051. KEEPALIVE_STATE(IN_HANDLER);
  7052. return _stepresult;
  7053. }
  7054. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  7055. {
  7056. lcd_beeper_quick_feedback();
  7057. FORCE_BL_ON_END;
  7058. target_temperature[0] = 0;
  7059. target_temperature_bed = 0;
  7060. manage_heater();
  7061. manage_inactivity();
  7062. lcd_clear();
  7063. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  7064. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  7065. switch (testError)
  7066. {
  7067. case TestError::Heater:
  7068. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  7069. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  7070. break;
  7071. case TestError::Bed:
  7072. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  7073. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7074. break;
  7075. case TestError::Endstops:
  7076. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  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::Motor:
  7082. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  7083. lcd_set_cursor(18, 2);
  7084. lcd_print(_error_1);
  7085. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  7086. lcd_set_cursor(18, 3);
  7087. lcd_print(_error_2);
  7088. break;
  7089. case TestError::Endstop:
  7090. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  7091. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7092. lcd_set_cursor(18, 3);
  7093. lcd_print(_error_1);
  7094. break;
  7095. case TestError::PrintFan:
  7096. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_COOLING_FAN));
  7097. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7098. lcd_set_cursor(18, 3);
  7099. lcd_print(_error_1);
  7100. break;
  7101. case TestError::ExtruderFan:
  7102. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_EXTRUDER_FAN));
  7103. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7104. lcd_set_cursor(18, 3);
  7105. lcd_print(_error_1);
  7106. break;
  7107. case TestError::Pulley:
  7108. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  7109. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7110. lcd_set_cursor(18, 3);
  7111. lcd_print(_error_1);
  7112. break;
  7113. case TestError::Axis:
  7114. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  7115. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  7116. lcd_set_cursor(18, 3);
  7117. lcd_print(_error_1);
  7118. break;
  7119. case TestError::SwappedFan:
  7120. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  7121. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  7122. lcd_set_cursor(18, 3);
  7123. lcd_print(_error_1);
  7124. break;
  7125. case TestError::WiringFsensor:
  7126. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7127. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7128. break;
  7129. case TestError::TriggeringFsensor:
  7130. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7131. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  7132. break;
  7133. case TestError::FsensorLevel:
  7134. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7135. lcd_set_cursor(0, 3);
  7136. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  7137. break;
  7138. }
  7139. _delay(1000);
  7140. lcd_beeper_quick_feedback();
  7141. do {
  7142. _delay(100);
  7143. manage_heater();
  7144. manage_inactivity();
  7145. } while (!lcd_clicked());
  7146. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  7147. lcd_return_to_status();
  7148. }
  7149. #ifdef FILAMENT_SENSOR
  7150. #ifdef PAT9125
  7151. static bool lcd_selftest_fsensor(void)
  7152. {
  7153. fsensor_init();
  7154. if (fsensor_not_responding)
  7155. {
  7156. lcd_selftest_error(TestError::WiringFsensor, "", "");
  7157. }
  7158. return (!fsensor_not_responding);
  7159. }
  7160. #endif //PAT9125
  7161. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  7162. //!
  7163. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  7164. //!
  7165. //! Steps:
  7166. //! * Backup current active extruder temperature
  7167. //! * Pre-heat to PLA extrude temperature.
  7168. //! * Unload filament possibly present.
  7169. //! * Move extruder idler same way as during filament load
  7170. //! and sample IR_SENSOR_PIN.
  7171. //! * Check that pin doesn't go low.
  7172. //!
  7173. //! @retval true passed
  7174. //! @retval false failed
  7175. static bool selftest_irsensor()
  7176. {
  7177. class TempBackup
  7178. {
  7179. public:
  7180. TempBackup():
  7181. m_temp(degTargetHotend(active_extruder)),
  7182. m_extruder(active_extruder){}
  7183. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  7184. private:
  7185. float m_temp;
  7186. uint8_t m_extruder;
  7187. };
  7188. uint8_t progress;
  7189. {
  7190. TempBackup tempBackup;
  7191. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  7192. mmu_wait_for_heater_blocking();
  7193. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  7194. mmu_filament_ramming();
  7195. }
  7196. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7197. mmu_command(MmuCmd::U0);
  7198. manage_response(false, false);
  7199. for(uint_least8_t i = 0; i < 200; ++i)
  7200. {
  7201. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7202. mmu_load_step(false);
  7203. while (blocks_queued())
  7204. {
  7205. if (READ(IR_SENSOR_PIN) == 0)
  7206. {
  7207. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  7208. return false;
  7209. }
  7210. #ifdef TMC2130
  7211. manage_heater();
  7212. // Vojtech: Don't disable motors inside the planner!
  7213. if (!tmc2130_update_sg())
  7214. {
  7215. manage_inactivity(true);
  7216. }
  7217. #else //TMC2130
  7218. manage_heater();
  7219. // Vojtech: Don't disable motors inside the planner!
  7220. manage_inactivity(true);
  7221. #endif //TMC2130
  7222. }
  7223. }
  7224. return true;
  7225. }
  7226. #endif //FILAMENT_SENSOR
  7227. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  7228. bool _default)
  7229. {
  7230. bool _result = check_opposite;
  7231. lcd_clear();
  7232. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  7233. switch (_fan)
  7234. {
  7235. case 0:
  7236. // extruder cooling fan
  7237. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_COOLING_FAN) : _T(MSG_SELFTEST_EXTRUDER_FAN));
  7238. setExtruderAutoFanState(3);
  7239. break;
  7240. case 1:
  7241. // object cooling fan
  7242. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_EXTRUDER_FAN) : _T(MSG_SELFTEST_COOLING_FAN));
  7243. SET_OUTPUT(FAN_PIN);
  7244. #ifdef FAN_SOFT_PWM
  7245. fanSpeedSoftPwm = 255;
  7246. #else //FAN_SOFT_PWM
  7247. analogWrite(FAN_PIN, 255);
  7248. #endif //FAN_SOFT_PWM
  7249. break;
  7250. }
  7251. _delay(500);
  7252. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7253. lcd_putc_at(0, 3, '>');
  7254. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7255. int8_t enc_dif = int(_default)*3;
  7256. KEEPALIVE_STATE(PAUSED_FOR_USER);
  7257. lcd_button_pressed = false;
  7258. do
  7259. {
  7260. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  7261. if (enc_dif > lcd_encoder_diff) {
  7262. _result = !check_opposite;
  7263. lcd_putc_at(0, 2, '>');
  7264. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7265. lcd_putc_at(0, 3, ' ');
  7266. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7267. }
  7268. if (enc_dif < lcd_encoder_diff) {
  7269. _result = check_opposite;
  7270. lcd_putc_at(0, 2, ' ');
  7271. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7272. lcd_putc_at(0, 3, '>');
  7273. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7274. }
  7275. enc_dif = 0;
  7276. lcd_encoder_diff = 0;
  7277. }
  7278. manage_heater();
  7279. _delay(100);
  7280. } while (!lcd_clicked());
  7281. KEEPALIVE_STATE(IN_HANDLER);
  7282. setExtruderAutoFanState(0);
  7283. SET_OUTPUT(FAN_PIN);
  7284. #ifdef FAN_SOFT_PWM
  7285. fanSpeedSoftPwm = 0;
  7286. #else //FAN_SOFT_PWM
  7287. analogWrite(FAN_PIN, 0);
  7288. #endif //FAN_SOFT_PWM
  7289. fanSpeed = 0;
  7290. manage_heater();
  7291. return _result;
  7292. }
  7293. #ifdef FANCHECK
  7294. static FanCheck lcd_selftest_fan_auto(int _fan)
  7295. {
  7296. switch (_fan) {
  7297. case 0:
  7298. fanSpeed = 0;
  7299. manage_heater(); //turn off fan
  7300. setExtruderAutoFanState(3); //extruder fan
  7301. #ifdef FAN_SOFT_PWM
  7302. extruder_autofan_last_check = _millis();
  7303. fan_measuring = true;
  7304. #endif //FAN_SOFT_PWM
  7305. _delay(2000);
  7306. setExtruderAutoFanState(0); //extruder fan
  7307. manage_heater(); //count average fan speed from 2s delay and turn off fans
  7308. puts_P(PSTR("Test 1:"));
  7309. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7310. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7311. if (fan_speed[0] < 20) { // < 1200 RPM would mean either a faulty Noctua or Altfan
  7312. return FanCheck::ExtruderFan;
  7313. }
  7314. #ifdef FAN_SOFT_PWM
  7315. else if (fan_speed[0] > 50 ) { // printerFan is faster
  7316. return FanCheck::SwappedFan;
  7317. }
  7318. break;
  7319. #endif
  7320. case 1:
  7321. //will it work with Thotend > 50 C ?
  7322. #ifdef FAN_SOFT_PWM
  7323. fanSpeed = 255;
  7324. fanSpeedSoftPwm = 255;
  7325. extruder_autofan_last_check = _millis(); //store time when measurement starts
  7326. fan_measuring = true; //start fan measuring, rest is on manage_heater
  7327. #else //FAN_SOFT_PWM
  7328. fanSpeed = 150; //print fan
  7329. #endif //FAN_SOFT_PWM
  7330. for (uint8_t i = 0; i < 5; i++) {
  7331. delay_keep_alive(1000);
  7332. lcd_putc_at(18, 3, '-');
  7333. delay_keep_alive(1000);
  7334. lcd_putc_at(18, 3, '|');
  7335. }
  7336. fanSpeed = 0;
  7337. #ifdef FAN_SOFT_PWM
  7338. fanSpeedSoftPwm = 0;
  7339. #else //FAN_SOFT_PWM
  7340. manage_heater(); //turn off fan
  7341. manage_inactivity(true); //to turn off print fan
  7342. #endif //FAN_SOFT_PWM
  7343. puts_P(PSTR("Test 2:"));
  7344. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7345. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7346. if (!fan_speed[1]) {
  7347. return FanCheck::PrintFan;
  7348. }
  7349. #ifdef FAN_SOFT_PWM
  7350. fanSpeed = 80;
  7351. fanSpeedSoftPwm = 80;
  7352. for (uint8_t i = 0; i < 5; i++) {
  7353. delay_keep_alive(1000);
  7354. lcd_putc_at(18, 3, '-');
  7355. delay_keep_alive(1000);
  7356. lcd_putc_at(18, 3, '|');
  7357. }
  7358. fanSpeed = 0;
  7359. // noctua speed is between 17 and 24, turbine more then 30
  7360. if (fan_speed[1] < 30) {
  7361. return FanCheck::SwappedFan;
  7362. }
  7363. #else
  7364. // fan is spinning, but measured RPM are too low for print fan, it must
  7365. // be left extruder fan
  7366. else if (fan_speed[1] < 34) {
  7367. return FanCheck::SwappedFan;
  7368. }
  7369. #endif //FAN_SOFT_PWM
  7370. break;
  7371. }
  7372. return FanCheck::Success;
  7373. }
  7374. #endif //FANCHECK
  7375. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  7376. {
  7377. lcd_update_enable(false);
  7378. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  7379. if (_clear) lcd_clear();
  7380. lcd_set_cursor(0, 0);
  7381. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7382. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7383. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7384. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  7385. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  7386. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  7387. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  7388. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  7389. if (screen == TestScreen::Hotend
  7390. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  7391. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7392. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7393. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  7394. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  7395. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  7396. lcd_puts_at_P(0, 1, separator);
  7397. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  7398. {
  7399. //SERIAL_ECHOLNPGM("Fan test");
  7400. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18
  7401. lcd_set_cursor(18, 2);
  7402. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  7403. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18
  7404. lcd_set_cursor(18, 3);
  7405. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  7406. }
  7407. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  7408. {
  7409. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7410. lcd_putc(':');
  7411. lcd_set_cursor(18, 2);
  7412. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  7413. }
  7414. else if (screen < TestScreen::Fsensor)
  7415. {
  7416. //SERIAL_ECHOLNPGM("Other tests");
  7417. TestScreen _step_block = TestScreen::AxisX;
  7418. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  7419. _step_block = TestScreen::AxisY;
  7420. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  7421. _step_block = TestScreen::AxisZ;
  7422. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  7423. _step_block = TestScreen::Bed;
  7424. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  7425. _step_block = TestScreen::Hotend;
  7426. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  7427. }
  7428. if (_delay > 0) delay_keep_alive(_delay);
  7429. _progress++;
  7430. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  7431. }
  7432. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  7433. {
  7434. lcd_set_cursor(_col, _row);
  7435. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  7436. switch (_state)
  7437. {
  7438. case 1:
  7439. lcd_puts_P(_name_PROGMEM);
  7440. lcd_putc_at(_col + strlenNameP, _row, ':');
  7441. lcd_set_cursor(_col + strlenNameP + 1, _row);
  7442. lcd_print(_indicator);
  7443. break;
  7444. case 2:
  7445. lcd_puts_P(_name_PROGMEM);
  7446. lcd_putc_at(_col + strlenNameP, _row, ':');
  7447. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  7448. break;
  7449. default:
  7450. lcd_puts_P(_name_PROGMEM);
  7451. }
  7452. }
  7453. /** End of menus **/
  7454. /** Menu action functions **/
  7455. static bool check_file(const char* filename) {
  7456. if (farm_mode) return true;
  7457. card.openFileReadFilteredGcode(filename, true);
  7458. bool result = false;
  7459. const uint32_t filesize = card.getFileSize();
  7460. uint32_t startPos = 0;
  7461. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  7462. if (filesize > END_FILE_SECTION) {
  7463. startPos = filesize - END_FILE_SECTION;
  7464. card.setIndex(startPos);
  7465. }
  7466. cmdqueue_reset();
  7467. cmdqueue_serial_disabled = true;
  7468. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  7469. while (!card.eof() && !result) {
  7470. menu_progressbar_update(card.get_sdpos() - startPos);
  7471. card.sdprinting = true;
  7472. get_command();
  7473. result = check_commands();
  7474. }
  7475. menu_progressbar_finish();
  7476. cmdqueue_serial_disabled = false;
  7477. card.printingHasFinished();
  7478. lcd_setstatuspgm(MSG_WELCOME);
  7479. lcd_finishstatus();
  7480. return result;
  7481. }
  7482. static void menu_action_sdfile(const char* filename)
  7483. {
  7484. loading_flag = false;
  7485. char cmd[30];
  7486. char* c;
  7487. bool result = true;
  7488. sprintf_P(cmd, PSTR("M23 %s"), filename);
  7489. for (c = &cmd[4]; *c; c++)
  7490. *c = tolower(*c);
  7491. const char end[5] = ".gco";
  7492. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  7493. for (uint_least8_t i = 0; i < 8; i++) {
  7494. if (strcmp((cmd + i + 4), end) == 0) {
  7495. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  7496. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  7497. break;
  7498. }
  7499. else {
  7500. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  7501. }
  7502. }
  7503. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  7504. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  7505. for (uint_least8_t i = 0; i < depth; i++) {
  7506. for (uint_least8_t j = 0; j < 8; j++) {
  7507. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  7508. }
  7509. }
  7510. //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
  7511. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  7512. if (!check_file(cmd + 4)) {
  7513. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=3
  7514. lcd_update_enable(true);
  7515. }
  7516. if (result) {
  7517. enquecommand(cmd);
  7518. enquecommand_P(PSTR("M24"));
  7519. }
  7520. lcd_return_to_status();
  7521. }
  7522. void menu_action_sddirectory(const char* filename)
  7523. {
  7524. card.chdir(filename, true);
  7525. lcd_encoder = 0;
  7526. menu_data_reset(); //Forces reloading of cached variables.
  7527. }
  7528. /** LCD API **/
  7529. void ultralcd_init()
  7530. {
  7531. {
  7532. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  7533. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  7534. else lcd_autoDeplete = autoDepleteRaw;
  7535. }
  7536. backlight_init();
  7537. lcd_init();
  7538. lcd_refresh();
  7539. lcd_longpress_func = menu_lcd_longpress_func;
  7540. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  7541. menu_menu = lcd_status_screen;
  7542. SET_INPUT(BTN_EN1);
  7543. SET_INPUT(BTN_EN2);
  7544. WRITE(BTN_EN1, HIGH);
  7545. WRITE(BTN_EN2, HIGH);
  7546. #if BTN_ENC > 0
  7547. SET_INPUT(BTN_ENC);
  7548. WRITE(BTN_ENC, HIGH);
  7549. #endif
  7550. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  7551. SET_INPUT(SDCARDDETECT);
  7552. WRITE(SDCARDDETECT, HIGH);
  7553. lcd_oldcardstatus = IS_SD_INSERTED;
  7554. #endif//(SDCARDDETECT > 0)
  7555. lcd_encoder_diff = 0;
  7556. }
  7557. void lcd_printer_connected() {
  7558. printer_connected = true;
  7559. }
  7560. static void lcd_send_status() {
  7561. if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
  7562. //send important status messages periodicaly
  7563. prusa_statistics(important_status, saved_filament_type);
  7564. NcTime.start();
  7565. #ifdef FARM_CONNECT_MESSAGE
  7566. lcd_connect_printer();
  7567. #endif //FARM_CONNECT_MESSAGE
  7568. }
  7569. }
  7570. #ifdef FARM_CONNECT_MESSAGE
  7571. static void lcd_connect_printer() {
  7572. lcd_update_enable(false);
  7573. lcd_clear();
  7574. int i = 0;
  7575. int t = 0;
  7576. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  7577. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  7578. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  7579. while (no_response) {
  7580. i++;
  7581. t++;
  7582. delay_keep_alive(100);
  7583. proc_commands();
  7584. if (t == 10) {
  7585. prusa_statistics(important_status, saved_filament_type);
  7586. t = 0;
  7587. }
  7588. if (READ(BTN_ENC)) { //if button is not pressed
  7589. i = 0;
  7590. lcd_puts_at_P(0, 3, PSTR(" "));
  7591. }
  7592. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, LCD_STR_SOLID_BLOCK[0]);
  7593. if (i == NC_BUTTON_LONG_PRESS * 10) {
  7594. no_response = false;
  7595. }
  7596. }
  7597. lcd_update_enable(true);
  7598. lcd_update(2);
  7599. }
  7600. #endif //FARM_CONNECT_MESSAGE
  7601. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  7602. if (farm_mode) {
  7603. bool empty = cmd_buffer_empty();
  7604. if ((_millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  7605. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  7606. //therefore longer period is used
  7607. printer_connected = false;
  7608. }
  7609. else {
  7610. lcd_printer_connected();
  7611. }
  7612. }
  7613. }
  7614. void lcd_ignore_click(bool b)
  7615. {
  7616. ignore_click = b;
  7617. wait_for_unclick = false;
  7618. }
  7619. void lcd_finishstatus() {
  7620. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  7621. int len = strlen(lcd_status_message);
  7622. if (len > 0) {
  7623. while (len < LCD_WIDTH) {
  7624. lcd_status_message[len++] = ' ';
  7625. }
  7626. }
  7627. lcd_status_message[LCD_WIDTH] = '\0';
  7628. lcd_draw_update = 2;
  7629. }
  7630. void lcd_setstatus(const char* message)
  7631. {
  7632. if (lcd_status_message_level > 0)
  7633. return;
  7634. lcd_updatestatus(message);
  7635. }
  7636. void lcd_updatestatuspgm(const char *message){
  7637. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  7638. lcd_status_message[LCD_WIDTH] = 0;
  7639. lcd_finishstatus();
  7640. // hack lcd_draw_update to 1, i.e. without clear
  7641. lcd_draw_update = 1;
  7642. }
  7643. void lcd_setstatuspgm(const char* message)
  7644. {
  7645. if (lcd_status_message_level > 0)
  7646. return;
  7647. lcd_updatestatuspgm(message);
  7648. }
  7649. void lcd_updatestatus(const char *message){
  7650. strncpy(lcd_status_message, message, LCD_WIDTH);
  7651. lcd_status_message[LCD_WIDTH] = 0;
  7652. lcd_finishstatus();
  7653. // hack lcd_draw_update to 1, i.e. without clear
  7654. lcd_draw_update = 1;
  7655. }
  7656. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  7657. {
  7658. if (severity > lcd_status_message_level) {
  7659. lcd_updatestatuspgm(message);
  7660. lcd_status_message_level = severity;
  7661. lcd_return_to_status();
  7662. }
  7663. }
  7664. void lcd_setalertstatus(const char* message, uint8_t severity)
  7665. {
  7666. if (severity > lcd_status_message_level) {
  7667. lcd_updatestatus(message);
  7668. lcd_status_message_level = severity;
  7669. lcd_return_to_status();
  7670. }
  7671. }
  7672. void lcd_reset_alert_level()
  7673. {
  7674. lcd_status_message_level = 0;
  7675. }
  7676. uint8_t get_message_level()
  7677. {
  7678. return lcd_status_message_level;
  7679. }
  7680. void menu_lcd_longpress_func(void)
  7681. {
  7682. backlight_wake();
  7683. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z)
  7684. {
  7685. // disable longpress during re-entry, while homing or calibration
  7686. lcd_quick_feedback();
  7687. return;
  7688. }
  7689. if (menu_menu == lcd_hw_setup_menu)
  7690. {
  7691. // only toggle the experimental menu visibility flag
  7692. lcd_quick_feedback();
  7693. lcd_experimental_toggle();
  7694. return;
  7695. }
  7696. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  7697. // The lists are not the same for both functions, so first decide which function is to be performed
  7698. if ( (moves_planned() || IS_SD_PRINTING || is_usb_printing )){ // long press as live-adj-z
  7699. if(( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  7700. && ( menu_menu == lcd_status_screen // and in listed menus...
  7701. || menu_menu == lcd_main_menu
  7702. || menu_menu == lcd_tune_menu
  7703. || menu_menu == lcd_support_menu
  7704. )
  7705. ){
  7706. lcd_clear();
  7707. menu_submenu(lcd_babystep_z);
  7708. } else {
  7709. // otherwise consume the long press as normal click
  7710. if( menu_menu != lcd_status_screen )
  7711. menu_back();
  7712. }
  7713. } else { // long press as move-z
  7714. if(menu_menu == lcd_status_screen
  7715. || menu_menu == lcd_main_menu
  7716. || menu_menu == lcd_preheat_menu
  7717. || menu_menu == lcd_sdcard_menu
  7718. || menu_menu == lcd_settings_menu
  7719. || menu_menu == lcd_control_temperature_menu
  7720. #if (LANG_MODE != 0)
  7721. || menu_menu == lcd_language
  7722. #endif
  7723. || menu_menu == lcd_support_menu
  7724. ){
  7725. menu_submenu(lcd_move_z);
  7726. } else {
  7727. // otherwise consume the long press as normal click
  7728. if( menu_menu != lcd_status_screen )
  7729. menu_back();
  7730. }
  7731. }
  7732. }
  7733. static inline bool z_menu_expired()
  7734. {
  7735. return (menu_menu == lcd_babystep_z
  7736. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  7737. }
  7738. static inline bool other_menu_expired()
  7739. {
  7740. return (menu_menu != lcd_status_screen
  7741. && menu_menu != lcd_babystep_z
  7742. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  7743. }
  7744. static inline bool forced_menu_expire()
  7745. {
  7746. bool retval = (menu_menu != lcd_status_screen
  7747. && forceMenuExpire);
  7748. forceMenuExpire = false;
  7749. return retval;
  7750. }
  7751. void menu_lcd_lcdupdate_func(void)
  7752. {
  7753. #if (SDCARDDETECT > 0)
  7754. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  7755. {
  7756. if(menu_menu == lcd_sdcard_menu) {
  7757. // If the user is either inside the submenus
  7758. // 1. 'Print from SD' --> and SD card is removed
  7759. // 2. 'No SD card' --> and SD card is inserted
  7760. //
  7761. // 1. 'Print from SD': We want to back out of this submenu
  7762. // and instead show the submenu title 'No SD card'.
  7763. //
  7764. // 2. 'No SD card': When the user inserts the SD card we want
  7765. // to back out of this submenu. Not only to show
  7766. // 'Print from SD' submenu title but also because the user
  7767. // will be prompted with another menu with the sorted list of files.
  7768. // Without backing out of the menu, the list will appear empty and
  7769. // The user will need to back out of two nested submenus.
  7770. menu_back();
  7771. }
  7772. lcd_draw_update = 2;
  7773. lcd_oldcardstatus = IS_SD_INSERTED;
  7774. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  7775. backlight_wake();
  7776. if (lcd_oldcardstatus)
  7777. {
  7778. if (!card.cardOK)
  7779. {
  7780. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  7781. card.presort_flag = true; //force sorting of the SD menu
  7782. }
  7783. LCD_MESSAGERPGM(MSG_WELCOME);
  7784. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  7785. menu_submenu(lcd_sdcard_menu);
  7786. lcd_timeoutToStatus.start();
  7787. }
  7788. else
  7789. {
  7790. card.release();
  7791. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  7792. }
  7793. }
  7794. #endif//CARDINSERTED
  7795. backlight_update();
  7796. if (lcd_next_update_millis < _millis())
  7797. {
  7798. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  7799. {
  7800. if (lcd_draw_update == 0)
  7801. lcd_draw_update = 1;
  7802. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  7803. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  7804. lcd_encoder_diff = 0;
  7805. lcd_timeoutToStatus.start();
  7806. backlight_wake();
  7807. }
  7808. if (LCD_CLICKED)
  7809. {
  7810. lcd_timeoutToStatus.start();
  7811. backlight_wake();
  7812. }
  7813. (*menu_menu)();
  7814. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  7815. {
  7816. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  7817. // to give it a chance to save its state.
  7818. // This is useful for example, when the babystep value has to be written into EEPROM.
  7819. if (menu_menu != NULL)
  7820. {
  7821. menu_leaving = 1;
  7822. (*menu_menu)();
  7823. menu_leaving = 0;
  7824. }
  7825. lcd_clear();
  7826. lcd_return_to_status();
  7827. lcd_draw_update = 2;
  7828. }
  7829. if (lcd_draw_update == 2) lcd_clear();
  7830. if (lcd_draw_update) lcd_draw_update--;
  7831. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  7832. }
  7833. lcd_ping(); //check that we have received ping command if we are in farm mode
  7834. lcd_send_status();
  7835. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  7836. }
  7837. #ifdef TMC2130
  7838. //! @brief Is crash detection enabled?
  7839. //!
  7840. //! @retval true crash detection enabled
  7841. //! @retval false crash detection disabled
  7842. bool lcd_crash_detect_enabled()
  7843. {
  7844. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  7845. }
  7846. void lcd_crash_detect_enable()
  7847. {
  7848. tmc2130_sg_stop_on_crash = true;
  7849. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  7850. }
  7851. void lcd_crash_detect_disable()
  7852. {
  7853. tmc2130_sg_stop_on_crash = false;
  7854. tmc2130_sg_crash = 0;
  7855. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  7856. }
  7857. #endif
  7858. void lcd_experimental_toggle()
  7859. {
  7860. uint8_t oldVal = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  7861. if (oldVal == EEPROM_EMPTY_VALUE)
  7862. oldVal = 0;
  7863. else
  7864. oldVal = !oldVal;
  7865. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, oldVal);
  7866. }
  7867. #ifdef TMC2130
  7868. void UserECool_toggle(){
  7869. // 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
  7870. // 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)
  7871. bool enable = ! UserECoolEnabled();
  7872. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  7873. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  7874. // 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.
  7875. tmc2130_init(TMCInitParams(enable));
  7876. }
  7877. #endif
  7878. /// Enable experimental support for cooler operation of the extruder motor
  7879. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  7880. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  7881. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  7882. /// (which would be obviously too late for an improperly sized motor)
  7883. /// For farm printing, the cooler E-motor is enabled by default.
  7884. bool UserECoolEnabled(){
  7885. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  7886. // a value of the universal answer to all problems of the universe
  7887. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  7888. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  7889. }
  7890. bool FarmOrUserECool(){
  7891. return farm_mode || UserECoolEnabled();
  7892. }
  7893. void lcd_experimental_menu()
  7894. {
  7895. MENU_BEGIN();
  7896. MENU_ITEM_BACK_P(_T(MSG_BACK));
  7897. #ifdef EXTRUDER_ALTFAN_DETECT
  7898. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  7899. #endif //EXTRUDER_ALTFAN_DETECT
  7900. #ifdef TMC2130
  7901. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  7902. #endif
  7903. MENU_END();
  7904. }
  7905. #ifdef PINDA_TEMP_COMP
  7906. void lcd_pinda_temp_compensation_toggle()
  7907. {
  7908. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  7909. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  7910. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  7911. else
  7912. pinda_temp_compensation = !pinda_temp_compensation;
  7913. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  7914. SERIAL_ECHOLNPGM("SuperPINDA:");
  7915. SERIAL_ECHOLN(pinda_temp_compensation);
  7916. }
  7917. #endif //PINDA_TEMP_COMP