ultralcd.cpp 268 KB

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