ultralcd.cpp 270 KB

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