ultralcd.cpp 242 KB

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