ultralcd.cpp 241 KB

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