ultralcd.cpp 262 KB

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