ultralcd.cpp 255 KB

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