ultralcd.cpp 259 KB

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