ultralcd.cpp 260 KB

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