ultralcd.cpp 243 KB

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