ultralcd.cpp 256 KB

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