ultralcd.cpp 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "MenuStack.h"
  5. #include "Marlin.h"
  6. #include "language.h"
  7. #include "cardreader.h"
  8. #include "temperature.h"
  9. #include "stepper.h"
  10. #include "ConfigurationStore.h"
  11. #include <string.h>
  12. #include "util.h"
  13. #include "mesh_bed_leveling.h"
  14. //#include "Configuration.h"
  15. #include "cmdqueue.h"
  16. #include "SdFatUtil.h"
  17. #ifdef PAT9125
  18. #include "pat9125.h"
  19. #endif //PAT9125
  20. #ifdef TMC2130
  21. #include "tmc2130.h"
  22. #endif //TMC2130
  23. #define _STRINGIFY(s) #s
  24. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  25. extern int lcd_change_fil_state;
  26. extern bool fans_check_enabled;
  27. extern bool filament_autoload_enabled;
  28. #ifdef PAT9125
  29. extern bool fsensor_not_responding;
  30. extern bool fsensor_enabled;
  31. #endif //PAT9125
  32. //Function pointer to menu functions.
  33. static void lcd_sd_updir();
  34. struct EditMenuParentState
  35. {
  36. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  37. menuFunc_t prevMenu;
  38. uint16_t prevEncoderPosition;
  39. //Variables used when editing values.
  40. const char* editLabel;
  41. void* editValue;
  42. int32_t minEditValue, maxEditValue;
  43. // menuFunc_t callbackFunc;
  44. };
  45. union MenuData
  46. {
  47. struct BabyStep
  48. {
  49. // 29B total
  50. int8_t status;
  51. int babystepMem[3];
  52. float babystepMemMM[3];
  53. } babyStep;
  54. struct SupportMenu
  55. {
  56. // 6B+16B=22B total
  57. int8_t status;
  58. bool is_flash_air;
  59. uint8_t ip[4];
  60. char ip_str[3*4+3+1];
  61. } supportMenu;
  62. struct AdjustBed
  63. {
  64. // 6+13+16=35B
  65. // editMenuParentState is used when an edit menu is entered, so it knows
  66. // the return menu and encoder state.
  67. struct EditMenuParentState editMenuParentState;
  68. int8_t status;
  69. int8_t left;
  70. int8_t right;
  71. int8_t front;
  72. int8_t rear;
  73. int left2;
  74. int right2;
  75. int front2;
  76. int rear2;
  77. } adjustBed;
  78. // editMenuParentState is used when an edit menu is entered, so it knows
  79. // the return menu and encoder state.
  80. struct EditMenuParentState editMenuParentState;
  81. };
  82. // State of the currently active menu.
  83. // C Union manages sharing of the static memory by all the menus.
  84. union MenuData menuData = { 0 };
  85. union Data
  86. {
  87. byte b[2];
  88. int value;
  89. };
  90. static MenuStack menuStack;
  91. int8_t ReInitLCD = 0;
  92. int8_t SDscrool = 0;
  93. int8_t SilentModeMenu = 0;
  94. int8_t FSensorStateMenu = 1;
  95. int8_t CrashDetectMenu = 1;
  96. extern void fsensor_block();
  97. extern void fsensor_unblock();
  98. extern bool fsensor_enable();
  99. extern void fsensor_disable();
  100. #ifdef TMC2130
  101. extern void crashdet_enable();
  102. extern void crashdet_disable();
  103. #endif //TMC2130
  104. #ifdef SNMM
  105. uint8_t snmm_extruder = 0;
  106. #endif
  107. #ifdef SDCARD_SORT_ALPHA
  108. bool presort_flag = false;
  109. #endif
  110. int lcd_commands_type=LCD_COMMAND_IDLE;
  111. int lcd_commands_step=0;
  112. bool isPrintPaused = false;
  113. uint8_t farm_mode = 0;
  114. int farm_no = 0;
  115. int farm_timer = 30;
  116. int farm_status = 0;
  117. unsigned long allert_timer = millis();
  118. bool printer_connected = true;
  119. unsigned long display_time; //just timer for showing pid finished message on lcd;
  120. float pid_temp = DEFAULT_PID_TEMP;
  121. bool long_press_active = false;
  122. long long_press_timer = millis();
  123. long button_blanking_time = millis();
  124. bool button_pressed = false;
  125. bool menuExiting = false;
  126. #ifdef FILAMENT_LCD_DISPLAY
  127. unsigned long message_millis = 0;
  128. #endif
  129. #ifdef ULTIPANEL
  130. static float manual_feedrate[] = MANUAL_FEEDRATE;
  131. #endif // ULTIPANEL
  132. /* !Configuration settings */
  133. uint8_t lcd_status_message_level;
  134. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  135. unsigned char firstrun = 1;
  136. #ifdef DOGLCD
  137. #include "dogm_lcd_implementation.h"
  138. #else
  139. #include "ultralcd_implementation_hitachi_HD44780.h"
  140. #endif
  141. /** forward declarations **/
  142. // void copy_and_scalePID_i();
  143. // void copy_and_scalePID_d();
  144. /* Different menus */
  145. static void lcd_status_screen();
  146. #ifdef ULTIPANEL
  147. extern bool powersupply;
  148. static void lcd_main_menu();
  149. static void lcd_tune_menu();
  150. static void lcd_prepare_menu();
  151. //static void lcd_move_menu();
  152. static void lcd_settings_menu();
  153. static void lcd_calibration_menu();
  154. static void lcd_language_menu();
  155. static void lcd_control_temperature_menu();
  156. static void lcd_control_temperature_preheat_pla_settings_menu();
  157. static void lcd_control_temperature_preheat_abs_settings_menu();
  158. static void lcd_control_motion_menu();
  159. static void lcd_control_volumetric_menu();
  160. static void prusa_stat_printerstatus(int _status);
  161. static void prusa_stat_farm_number();
  162. static void prusa_stat_temperatures();
  163. static void prusa_stat_printinfo();
  164. static void lcd_farm_no();
  165. static void lcd_menu_extruder_info();
  166. #if defined(TMC2130) || defined(PAT9125)
  167. static void lcd_menu_fails_stats();
  168. #endif //TMC2130 or PAT9125
  169. void lcd_finishstatus();
  170. #ifdef DOGLCD
  171. static void lcd_set_contrast();
  172. #endif
  173. static void lcd_control_retract_menu();
  174. static void lcd_sdcard_menu();
  175. #ifdef DELTA_CALIBRATION_MENU
  176. static void lcd_delta_calibrate_menu();
  177. #endif // DELTA_CALIBRATION_MENU
  178. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  179. /* Different types of actions that can be used in menu items. */
  180. static void menu_action_back(menuFunc_t data = 0);
  181. #define menu_action_back_RAM menu_action_back
  182. static void menu_action_submenu(menuFunc_t data);
  183. static void menu_action_gcode(const char* pgcode);
  184. static void menu_action_function(menuFunc_t data);
  185. static void menu_action_setlang(unsigned char lang);
  186. static void menu_action_sdfile(const char* filename, char* longFilename);
  187. static void menu_action_sddirectory(const char* filename, char* longFilename);
  188. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  189. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  190. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  191. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  192. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  193. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  194. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  195. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  196. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  197. /*
  198. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  199. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  200. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  201. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  202. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  203. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  204. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  205. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  206. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  207. */
  208. #define ENCODER_FEEDRATE_DEADZONE 10
  209. #if !defined(LCD_I2C_VIKI)
  210. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  211. #define ENCODER_STEPS_PER_MENU_ITEM 5
  212. #endif
  213. #ifndef ENCODER_PULSES_PER_STEP
  214. #define ENCODER_PULSES_PER_STEP 1
  215. #endif
  216. #else
  217. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  218. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  219. #endif
  220. #ifndef ENCODER_PULSES_PER_STEP
  221. #define ENCODER_PULSES_PER_STEP 1
  222. #endif
  223. #endif
  224. /* Helper macros for menus */
  225. #define START_MENU() do { \
  226. if (encoderPosition > 0x8000) encoderPosition = 0; \
  227. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  228. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  229. bool wasClicked = LCD_CLICKED;\
  230. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  231. _menuItemNr = 0;
  232. #define MENU_ITEM(type, label, args...) do { \
  233. if (_menuItemNr == _lineNr) { \
  234. if (lcdDrawUpdate) { \
  235. const char* _label_pstr = (label); \
  236. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  237. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  238. }else{\
  239. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  240. }\
  241. }\
  242. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  243. lcd_quick_feedback(); \
  244. menu_action_ ## type ( args ); \
  245. return;\
  246. }\
  247. }\
  248. _menuItemNr++;\
  249. } while(0)
  250. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  251. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  252. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  253. #define END_MENU() \
  254. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  255. if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
  256. } } while(0)
  257. /** Used variables to keep track of the menu */
  258. #ifndef REPRAPWORLD_KEYPAD
  259. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  260. #else
  261. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  262. #endif
  263. #ifdef LCD_HAS_SLOW_BUTTONS
  264. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  265. #endif
  266. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  267. uint8_t lastEncoderBits;
  268. uint16_t encoderPosition;
  269. #if (SDCARDDETECT > 0)
  270. bool lcd_oldcardstatus;
  271. #endif
  272. #endif //ULTIPANEL
  273. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  274. uint32_t lcd_next_update_millis;
  275. uint8_t lcd_status_update_delay;
  276. bool ignore_click = false;
  277. bool wait_for_unclick;
  278. uint8_t lcdDrawUpdate = 2; /* Set to none-zero when the LCD needs to draw, decreased after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial) */
  279. // place-holders for Ki and Kd edits
  280. #ifdef PIDTEMP
  281. // float raw_Ki, raw_Kd;
  282. #endif
  283. /**
  284. * @brief Go to menu
  285. *
  286. * This function should not be used directly, use
  287. * menu_action_back and menu_action_submenu instead.
  288. *
  289. * @param menu target menu
  290. * @param encoder position in target menu
  291. * @param feedback
  292. * * true sound feedback (click)
  293. * * false no feedback
  294. * @param reset_menu_state
  295. * * true reset menu state global union
  296. * * false do not reset menu state global union
  297. */
  298. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true)
  299. {
  300. asm("cli");
  301. if (currentMenu != menu)
  302. {
  303. currentMenu = menu;
  304. encoderPosition = encoder;
  305. asm("sei");
  306. if (reset_menu_state)
  307. {
  308. // Resets the global shared C union.
  309. // This ensures, that the menu entered will find out, that it shall initialize itself.
  310. memset(&menuData, 0, sizeof(menuData));
  311. }
  312. if (feedback) lcd_quick_feedback();
  313. // For LCD_PROGRESS_BAR re-initialize the custom characters
  314. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  315. lcd_set_custom_characters(menu == lcd_status_screen);
  316. #endif
  317. }
  318. else
  319. asm("sei");
  320. }
  321. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  322. // Language selection dialog not active.
  323. #define LANGSEL_OFF 0
  324. // Language selection dialog modal, entered from the info screen. This is the case on firmware boot up,
  325. // if the language index stored in the EEPROM is not valid.
  326. #define LANGSEL_MODAL 1
  327. // Language selection dialog entered from the Setup menu.
  328. #define LANGSEL_ACTIVE 2
  329. // Language selection dialog status
  330. unsigned char langsel = LANGSEL_OFF;
  331. void set_language_from_EEPROM() {
  332. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  333. if (eep < LANG_NUM)
  334. {
  335. lang_selected = eep;
  336. // Language is valid, no need to enter the language selection screen.
  337. langsel = LANGSEL_OFF;
  338. }
  339. else
  340. {
  341. lang_selected = LANG_ID_DEFAULT;
  342. // Invalid language, enter the language selection screen in a modal mode.
  343. langsel = LANGSEL_MODAL;
  344. }
  345. }
  346. static void lcd_status_screen()
  347. {
  348. if (firstrun == 1)
  349. {
  350. firstrun = 0;
  351. set_language_from_EEPROM();
  352. if(lcd_status_message_level == 0){
  353. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  354. lcd_finishstatus();
  355. }
  356. if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
  357. {
  358. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  359. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  360. }
  361. if (langsel) {
  362. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  363. // Entering the language selection screen in a modal mode.
  364. }
  365. }
  366. if (lcd_status_update_delay)
  367. lcd_status_update_delay--;
  368. else
  369. lcdDrawUpdate = 1;
  370. if (lcdDrawUpdate)
  371. {
  372. ReInitLCD++;
  373. if (ReInitLCD == 30) {
  374. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  375. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  376. currentMenu == lcd_status_screen
  377. #endif
  378. );
  379. ReInitLCD = 0 ;
  380. } else {
  381. if ((ReInitLCD % 10) == 0) {
  382. //lcd_implementation_nodisplay();
  383. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  384. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  385. currentMenu == lcd_status_screen
  386. #endif
  387. );
  388. }
  389. }
  390. //lcd_implementation_display();
  391. lcd_implementation_status_screen();
  392. //lcd_implementation_clear();
  393. if (farm_mode)
  394. {
  395. farm_timer--;
  396. if (farm_timer < 1)
  397. {
  398. farm_timer = 180;
  399. prusa_statistics(0);
  400. }
  401. switch (farm_timer)
  402. {
  403. case 45:
  404. prusa_statistics(21);
  405. break;
  406. case 10:
  407. if (IS_SD_PRINTING)
  408. {
  409. prusa_statistics(20);
  410. }
  411. break;
  412. }
  413. } // end of farm_mode
  414. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  415. if (lcd_commands_type != LCD_COMMAND_IDLE)
  416. {
  417. lcd_commands();
  418. }
  419. } // end of lcdDrawUpdate
  420. #ifdef ULTIPANEL
  421. bool current_click = LCD_CLICKED;
  422. if (ignore_click) {
  423. if (wait_for_unclick) {
  424. if (!current_click) {
  425. ignore_click = wait_for_unclick = false;
  426. }
  427. else {
  428. current_click = false;
  429. }
  430. }
  431. else if (current_click) {
  432. lcd_quick_feedback();
  433. wait_for_unclick = true;
  434. current_click = false;
  435. }
  436. }
  437. //if (--langsel ==0) {langsel=1;current_click=true;}
  438. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  439. {
  440. menuStack.reset();
  441. menu_action_submenu(lcd_main_menu);
  442. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  443. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  444. currentMenu == lcd_status_screen
  445. #endif
  446. );
  447. #ifdef FILAMENT_LCD_DISPLAY
  448. message_millis = millis(); // get status message to show up for a while
  449. #endif
  450. }
  451. #ifdef ULTIPANEL_FEEDMULTIPLY
  452. // Dead zone at 100% feedrate
  453. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  454. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  455. {
  456. encoderPosition = 0;
  457. feedmultiply = 100;
  458. }
  459. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  460. {
  461. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  462. encoderPosition = 0;
  463. }
  464. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  465. {
  466. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  467. encoderPosition = 0;
  468. }
  469. else if (feedmultiply != 100)
  470. {
  471. feedmultiply += int(encoderPosition);
  472. encoderPosition = 0;
  473. }
  474. #endif //ULTIPANEL_FEEDMULTIPLY
  475. if (feedmultiply < 10)
  476. feedmultiply = 10;
  477. else if (feedmultiply > 999)
  478. feedmultiply = 999;
  479. #endif //ULTIPANEL
  480. if (farm_mode && !printer_connected) {
  481. lcd.setCursor(0, 3);
  482. lcd_printPGM(MSG_PRINTER_DISCONNECTED);
  483. }
  484. //#define FSENS_FACTOR (2580.8/50) //filament sensor factor [steps / encoder counts]
  485. //#define FSENS_FACTOR (2580.8/45.3) //filament sensor factor [steps / encoder counts]
  486. //lcd.setCursor(0, 3);
  487. //lcd_implementation_print(" ");
  488. //lcd.setCursor(0, 3);
  489. //lcd_implementation_print(pat9125_x);
  490. //lcd.setCursor(6, 3);
  491. //lcd_implementation_print(pat9125_y);
  492. //lcd.setCursor(12, 3);
  493. //lcd_implementation_print(pat9125_b);
  494. }
  495. #ifdef ULTIPANEL
  496. void lcd_commands()
  497. {
  498. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
  499. {
  500. if(lcd_commands_step == 0) {
  501. if (card.sdprinting) {
  502. card.pauseSDPrint();
  503. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  504. lcdDrawUpdate = 3;
  505. lcd_commands_step = 1;
  506. }
  507. else {
  508. lcd_commands_type = 0;
  509. }
  510. }
  511. if (lcd_commands_step == 1 && !blocks_queued() && !homing_flag) {
  512. lcd_setstatuspgm(MSG_PRINT_PAUSED);
  513. isPrintPaused = true;
  514. long_pause();
  515. lcd_commands_type = 0;
  516. lcd_commands_step = 0;
  517. }
  518. }
  519. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE_RESUME) {
  520. char cmd1[30];
  521. if (lcd_commands_step == 0) {
  522. lcdDrawUpdate = 3;
  523. lcd_commands_step = 4;
  524. }
  525. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty()) { //recover feedmultiply; cmd_buffer_empty() ensures that card.sdprinting is synchronized with buffered commands and thus print cant be paused until resume is finished
  526. sprintf_P(cmd1, PSTR("M220 S%d"), saved_feedmultiply);
  527. enquecommand(cmd1);
  528. isPrintPaused = false;
  529. pause_time += (millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  530. card.startFileprint();
  531. lcd_commands_step = 0;
  532. lcd_commands_type = 0;
  533. }
  534. if (lcd_commands_step == 2 && !blocks_queued()) { //turn on fan, move Z and unretract
  535. sprintf_P(cmd1, PSTR("M106 S%d"), fanSpeedBckp);
  536. enquecommand(cmd1);
  537. strcpy(cmd1, "G1 Z");
  538. strcat(cmd1, ftostr32(pause_lastpos[Z_AXIS]));
  539. enquecommand(cmd1);
  540. if (axis_relative_modes[3] == false) {
  541. enquecommand_P(PSTR("M83")); // set extruder to relative mode
  542. enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION))); //unretract
  543. enquecommand_P(PSTR("M82")); // set extruder to absolute mode
  544. }
  545. else {
  546. enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION))); //unretract
  547. }
  548. lcd_commands_step = 1;
  549. }
  550. if (lcd_commands_step == 3 && !blocks_queued()) { //wait for nozzle to reach target temp
  551. strcpy(cmd1, "M109 S");
  552. strcat(cmd1, ftostr3(HotendTempBckp));
  553. enquecommand(cmd1);
  554. lcd_commands_step = 2;
  555. }
  556. if (lcd_commands_step == 4 && !blocks_queued()) { //set temperature back and move xy
  557. strcpy(cmd1, "M104 S");
  558. strcat(cmd1, ftostr3(HotendTempBckp));
  559. enquecommand(cmd1);
  560. enquecommand_P(PSTR("G90")); //absolute positioning
  561. strcpy(cmd1, "G1 X");
  562. strcat(cmd1, ftostr32(pause_lastpos[X_AXIS]));
  563. strcat(cmd1, " Y");
  564. strcat(cmd1, ftostr32(pause_lastpos[Y_AXIS]));
  565. enquecommand(cmd1);
  566. lcd_setstatuspgm(MSG_RESUMING_PRINT);
  567. lcd_commands_step = 3;
  568. }
  569. }
  570. #ifdef SNMM
  571. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  572. {
  573. char cmd1[30];
  574. float width = 0.4;
  575. float length = 20 - width;
  576. float extr = count_e(0.2, width, length);
  577. float extr_short_segment = count_e(0.2, width, width);
  578. if (lcd_commands_step>1) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  579. if (lcd_commands_step == 0)
  580. {
  581. lcd_commands_step = 10;
  582. }
  583. if (lcd_commands_step == 10 && !blocks_queued() && cmd_buffer_empty())
  584. {
  585. enquecommand_P(PSTR("M107"));
  586. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  587. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  588. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  589. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  590. enquecommand_P(PSTR("T0"));
  591. enquecommand_P(MSG_M117_V2_CALIBRATION);
  592. enquecommand_P(PSTR("G87")); //sets calibration status
  593. enquecommand_P(PSTR("G28"));
  594. enquecommand_P(PSTR("G21")); //set units to millimeters
  595. enquecommand_P(PSTR("G90")); //use absolute coordinates
  596. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  597. enquecommand_P(PSTR("G92 E0"));
  598. enquecommand_P(PSTR("M203 E100"));
  599. enquecommand_P(PSTR("M92 E140"));
  600. lcd_commands_step = 9;
  601. }
  602. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  603. {
  604. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  605. enquecommand_P(PSTR("G1 Z0.250 F7200.000"));
  606. enquecommand_P(PSTR("G1 X50.0 E80.0 F1000.0"));
  607. enquecommand_P(PSTR("G1 X160.0 E20.0 F1000.0"));
  608. enquecommand_P(PSTR("G1 Z0.200 F7200.000"));
  609. enquecommand_P(PSTR("G1 X220.0 E13 F1000.0"));
  610. enquecommand_P(PSTR("G1 X240.0 E0 F1000.0"));
  611. enquecommand_P(PSTR("G92 E0.0"));
  612. enquecommand_P(PSTR("G21"));
  613. enquecommand_P(PSTR("G90"));
  614. enquecommand_P(PSTR("M83"));
  615. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  616. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  617. enquecommand_P(PSTR("M204 S1000"));
  618. enquecommand_P(PSTR("G1 F4000"));
  619. lcd_implementation_clear();
  620. lcd_goto_menu(lcd_babystep_z, 0, false);
  621. lcd_commands_step = 8;
  622. }
  623. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  624. {
  625. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  626. enquecommand_P(PSTR("G1 X50 Y155"));
  627. enquecommand_P(PSTR("G1 X60 Y155 E4"));
  628. enquecommand_P(PSTR("G1 F1080"));
  629. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  630. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  631. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  632. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  633. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  634. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  635. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  636. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  637. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  638. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  639. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  640. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  641. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  642. lcd_commands_step = 7;
  643. }
  644. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty())
  645. {
  646. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  647. strcpy(cmd1, "G1 X50 Y35 E");
  648. strcat(cmd1, ftostr43(extr));
  649. enquecommand(cmd1);
  650. for (int i = 0; i < 4; i++) {
  651. strcpy(cmd1, "G1 X70 Y");
  652. strcat(cmd1, ftostr32(35 - i*width * 2));
  653. strcat(cmd1, " E");
  654. strcat(cmd1, ftostr43(extr));
  655. enquecommand(cmd1);
  656. strcpy(cmd1, "G1 Y");
  657. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  658. strcat(cmd1, " E");
  659. strcat(cmd1, ftostr43(extr_short_segment));
  660. enquecommand(cmd1);
  661. strcpy(cmd1, "G1 X50 Y");
  662. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  663. strcat(cmd1, " E");
  664. strcat(cmd1, ftostr43(extr));
  665. enquecommand(cmd1);
  666. strcpy(cmd1, "G1 Y");
  667. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  668. strcat(cmd1, " E");
  669. strcat(cmd1, ftostr43(extr_short_segment));
  670. enquecommand(cmd1);
  671. }
  672. lcd_commands_step = 6;
  673. }
  674. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  675. {
  676. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  677. for (int i = 4; i < 8; i++) {
  678. strcpy(cmd1, "G1 X70 Y");
  679. strcat(cmd1, ftostr32(35 - i*width * 2));
  680. strcat(cmd1, " E");
  681. strcat(cmd1, ftostr43(extr));
  682. enquecommand(cmd1);
  683. strcpy(cmd1, "G1 Y");
  684. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  685. strcat(cmd1, " E");
  686. strcat(cmd1, ftostr43(extr_short_segment));
  687. enquecommand(cmd1);
  688. strcpy(cmd1, "G1 X50 Y");
  689. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  690. strcat(cmd1, " E");
  691. strcat(cmd1, ftostr43(extr));
  692. enquecommand(cmd1);
  693. strcpy(cmd1, "G1 Y");
  694. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  695. strcat(cmd1, " E");
  696. strcat(cmd1, ftostr43(extr_short_segment));
  697. enquecommand(cmd1);
  698. }
  699. lcd_commands_step = 5;
  700. }
  701. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  702. {
  703. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  704. for (int i = 8; i < 12; i++) {
  705. strcpy(cmd1, "G1 X70 Y");
  706. strcat(cmd1, ftostr32(35 - i*width * 2));
  707. strcat(cmd1, " E");
  708. strcat(cmd1, ftostr43(extr));
  709. enquecommand(cmd1);
  710. strcpy(cmd1, "G1 Y");
  711. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  712. strcat(cmd1, " E");
  713. strcat(cmd1, ftostr43(extr_short_segment));
  714. enquecommand(cmd1);
  715. strcpy(cmd1, "G1 X50 Y");
  716. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  717. strcat(cmd1, " E");
  718. strcat(cmd1, ftostr43(extr));
  719. enquecommand(cmd1);
  720. strcpy(cmd1, "G1 Y");
  721. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  722. strcat(cmd1, " E");
  723. strcat(cmd1, ftostr43(extr_short_segment));
  724. enquecommand(cmd1);
  725. }
  726. lcd_commands_step = 4;
  727. }
  728. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  729. {
  730. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  731. for (int i = 12; i < 16; i++) {
  732. strcpy(cmd1, "G1 X70 Y");
  733. strcat(cmd1, ftostr32(35 - i*width * 2));
  734. strcat(cmd1, " E");
  735. strcat(cmd1, ftostr43(extr));
  736. enquecommand(cmd1);
  737. strcpy(cmd1, "G1 Y");
  738. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  739. strcat(cmd1, " E");
  740. strcat(cmd1, ftostr43(extr_short_segment));
  741. enquecommand(cmd1);
  742. strcpy(cmd1, "G1 X50 Y");
  743. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  744. strcat(cmd1, " E");
  745. strcat(cmd1, ftostr43(extr));
  746. enquecommand(cmd1);
  747. strcpy(cmd1, "G1 Y");
  748. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  749. strcat(cmd1, " E");
  750. strcat(cmd1, ftostr43(extr_short_segment));
  751. enquecommand(cmd1);
  752. }
  753. lcd_commands_step = 3;
  754. }
  755. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  756. {
  757. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  758. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  759. enquecommand_P(PSTR("G4 S0"));
  760. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  761. enquecommand_P(PSTR("G1 Z0.5 F7200.000"));
  762. enquecommand_P(PSTR("G1 X245 Y1"));
  763. enquecommand_P(PSTR("G1 X240 E4"));
  764. enquecommand_P(PSTR("G1 F4000"));
  765. enquecommand_P(PSTR("G1 X190 E2.7"));
  766. enquecommand_P(PSTR("G1 F4600"));
  767. enquecommand_P(PSTR("G1 X110 E2.8"));
  768. enquecommand_P(PSTR("G1 F5200"));
  769. enquecommand_P(PSTR("G1 X40 E3"));
  770. enquecommand_P(PSTR("G1 E-15.0000 F5000"));
  771. enquecommand_P(PSTR("G1 E-50.0000 F5400"));
  772. enquecommand_P(PSTR("G1 E-15.0000 F3000"));
  773. enquecommand_P(PSTR("G1 E-12.0000 F2000"));
  774. enquecommand_P(PSTR("G1 F1600"));
  775. lcd_commands_step = 2;
  776. }
  777. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  778. {
  779. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  780. enquecommand_P(PSTR("G1 X0 Y1 E3.0000"));
  781. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  782. enquecommand_P(PSTR("G1 F2000"));
  783. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  784. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  785. enquecommand_P(PSTR("G1 F2400"));
  786. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  787. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  788. enquecommand_P(PSTR("G1 F2400"));
  789. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  790. enquecommand_P(PSTR("G1 X50 Y1 E-3.0000"));
  791. enquecommand_P(PSTR("G4 S0"));
  792. enquecommand_P(PSTR("M107"));
  793. enquecommand_P(PSTR("M104 S0"));
  794. enquecommand_P(PSTR("M140 S0"));
  795. enquecommand_P(PSTR("G1 X10 Y180 F4000"));
  796. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  797. enquecommand_P(PSTR("M84"));
  798. lcd_commands_step = 1;
  799. }
  800. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  801. {
  802. lcd_setstatuspgm(WELCOME_MSG);
  803. lcd_commands_step = 0;
  804. lcd_commands_type = 0;
  805. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  806. lcd_wizard(10);
  807. }
  808. }
  809. }
  810. #else //if not SNMM
  811. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  812. {
  813. char cmd1[30];
  814. float width = 0.4;
  815. float length = 20 - width;
  816. float extr = count_e(0.2, width, length);
  817. float extr_short_segment = count_e(0.2, width, width);
  818. if(lcd_commands_step>1) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  819. if (lcd_commands_step == 0)
  820. {
  821. lcd_commands_step = 9;
  822. }
  823. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  824. {
  825. enquecommand_P(PSTR("M107"));
  826. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  827. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  828. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  829. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  830. enquecommand_P(MSG_M117_V2_CALIBRATION);
  831. enquecommand_P(PSTR("G87")); //sets calibration status
  832. enquecommand_P(PSTR("G28"));
  833. enquecommand_P(PSTR("G92 E0.0"));
  834. lcd_commands_step = 8;
  835. }
  836. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty())
  837. {
  838. lcd_implementation_clear();
  839. menuStack.reset();
  840. menu_action_submenu(lcd_babystep_z);
  841. enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); //intro line
  842. enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); //intro line
  843. enquecommand_P(PSTR("G92 E0.0"));
  844. enquecommand_P(PSTR("G21")); //set units to millimeters
  845. enquecommand_P(PSTR("G90")); //use absolute coordinates
  846. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  847. enquecommand_P(PSTR("G1 E-1.50000 F2100.00000"));
  848. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  849. enquecommand_P(PSTR("M204 S1000")); //set acceleration
  850. enquecommand_P(PSTR("G1 F4000"));
  851. lcd_commands_step = 7;
  852. }
  853. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  854. {
  855. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  856. //just opposite direction
  857. /*enquecommand_P(PSTR("G1 X50 Y55"));
  858. enquecommand_P(PSTR("G1 F1080"));
  859. enquecommand_P(PSTR("G1 X200 Y55 E3.62773"));
  860. enquecommand_P(PSTR("G1 X200 Y75 E0.49386"));
  861. enquecommand_P(PSTR("G1 X50 Y75 E3.62773"));
  862. enquecommand_P(PSTR("G1 X50 Y95 E0.49386"));
  863. enquecommand_P(PSTR("G1 X200 Y95 E3.62773"));
  864. enquecommand_P(PSTR("G1 X200 Y115 E0.49386"));
  865. enquecommand_P(PSTR("G1 X50 Y115 E3.62773"));
  866. enquecommand_P(PSTR("G1 X50 Y135 E0.49386"));
  867. enquecommand_P(PSTR("G1 X200 Y135 E3.62773"));
  868. enquecommand_P(PSTR("G1 X200 Y155 E0.66174"));
  869. enquecommand_P(PSTR("G1 X100 Y155 E2.62773"));
  870. enquecommand_P(PSTR("G1 X75 Y155 E2"));
  871. enquecommand_P(PSTR("G1 X50 Y155 E2.5"));
  872. enquecommand_P(PSTR("G1 E - 0.07500 F2100.00000"));*/
  873. enquecommand_P(PSTR("G1 X50 Y155"));
  874. enquecommand_P(PSTR("G1 F1080"));
  875. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  876. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  877. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  878. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  879. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  880. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  881. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  882. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  883. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  884. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  885. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  886. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  887. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  888. strcpy(cmd1, "G1 X50 Y35 E");
  889. strcat(cmd1, ftostr43(extr));
  890. enquecommand(cmd1);
  891. lcd_commands_step = 6;
  892. }
  893. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  894. {
  895. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  896. for (int i = 0; i < 4; i++) {
  897. strcpy(cmd1, "G1 X70 Y");
  898. strcat(cmd1, ftostr32(35 - i*width * 2));
  899. strcat(cmd1, " E");
  900. strcat(cmd1, ftostr43(extr));
  901. enquecommand(cmd1);
  902. strcpy(cmd1, "G1 Y");
  903. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  904. strcat(cmd1, " E");
  905. strcat(cmd1, ftostr43(extr_short_segment));
  906. enquecommand(cmd1);
  907. strcpy(cmd1, "G1 X50 Y");
  908. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  909. strcat(cmd1, " E");
  910. strcat(cmd1, ftostr43(extr));
  911. enquecommand(cmd1);
  912. strcpy(cmd1, "G1 Y");
  913. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  914. strcat(cmd1, " E");
  915. strcat(cmd1, ftostr43(extr_short_segment));
  916. enquecommand(cmd1);
  917. }
  918. lcd_commands_step = 5;
  919. }
  920. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  921. {
  922. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  923. for (int i = 4; i < 8; i++) {
  924. strcpy(cmd1, "G1 X70 Y");
  925. strcat(cmd1, ftostr32(35 - i*width * 2));
  926. strcat(cmd1, " E");
  927. strcat(cmd1, ftostr43(extr));
  928. enquecommand(cmd1);
  929. strcpy(cmd1, "G1 Y");
  930. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  931. strcat(cmd1, " E");
  932. strcat(cmd1, ftostr43(extr_short_segment));
  933. enquecommand(cmd1);
  934. strcpy(cmd1, "G1 X50 Y");
  935. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  936. strcat(cmd1, " E");
  937. strcat(cmd1, ftostr43(extr));
  938. enquecommand(cmd1);
  939. strcpy(cmd1, "G1 Y");
  940. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  941. strcat(cmd1, " E");
  942. strcat(cmd1, ftostr43(extr_short_segment));
  943. enquecommand(cmd1);
  944. }
  945. lcd_commands_step = 4;
  946. }
  947. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  948. {
  949. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  950. for (int i = 8; i < 12; i++) {
  951. strcpy(cmd1, "G1 X70 Y");
  952. strcat(cmd1, ftostr32(35 - i*width * 2));
  953. strcat(cmd1, " E");
  954. strcat(cmd1, ftostr43(extr));
  955. enquecommand(cmd1);
  956. strcpy(cmd1, "G1 Y");
  957. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  958. strcat(cmd1, " E");
  959. strcat(cmd1, ftostr43(extr_short_segment));
  960. enquecommand(cmd1);
  961. strcpy(cmd1, "G1 X50 Y");
  962. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  963. strcat(cmd1, " E");
  964. strcat(cmd1, ftostr43(extr));
  965. enquecommand(cmd1);
  966. strcpy(cmd1, "G1 Y");
  967. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  968. strcat(cmd1, " E");
  969. strcat(cmd1, ftostr43(extr_short_segment));
  970. enquecommand(cmd1);
  971. }
  972. lcd_commands_step = 3;
  973. }
  974. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  975. {
  976. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  977. for (int i = 12; i < 16; i++) {
  978. strcpy(cmd1, "G1 X70 Y");
  979. strcat(cmd1, ftostr32(35 - i*width * 2));
  980. strcat(cmd1, " E");
  981. strcat(cmd1, ftostr43(extr));
  982. enquecommand(cmd1);
  983. strcpy(cmd1, "G1 Y");
  984. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  985. strcat(cmd1, " E");
  986. strcat(cmd1, ftostr43(extr_short_segment));
  987. enquecommand(cmd1);
  988. strcpy(cmd1, "G1 X50 Y");
  989. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  990. strcat(cmd1, " E");
  991. strcat(cmd1, ftostr43(extr));
  992. enquecommand(cmd1);
  993. strcpy(cmd1, "G1 Y");
  994. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  995. strcat(cmd1, " E");
  996. strcat(cmd1, ftostr43(extr_short_segment));
  997. enquecommand(cmd1);
  998. }
  999. lcd_commands_step = 2;
  1000. }
  1001. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1002. {
  1003. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1004. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  1005. enquecommand_P(PSTR("M107")); //turn off printer fan
  1006. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  1007. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  1008. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1009. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //home X axis
  1010. enquecommand_P(PSTR("M84"));// disable motors
  1011. lcd_timeoutToStatus = millis() - 1; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1012. lcd_commands_step = 1;
  1013. }
  1014. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1015. {
  1016. lcd_setstatuspgm(WELCOME_MSG);
  1017. lcd_commands_step = 0;
  1018. lcd_commands_type = 0;
  1019. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1020. lcd_wizard(10);
  1021. }
  1022. }
  1023. }
  1024. #endif // not SNMM
  1025. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  1026. {
  1027. if (lcd_commands_step == 0)
  1028. {
  1029. lcd_commands_step = 6;
  1030. custom_message = true;
  1031. }
  1032. if (lcd_commands_step == 1 && !blocks_queued())
  1033. {
  1034. lcd_commands_step = 0;
  1035. lcd_commands_type = 0;
  1036. lcd_setstatuspgm(WELCOME_MSG);
  1037. custom_message_type = 0;
  1038. custom_message = false;
  1039. isPrintPaused = false;
  1040. }
  1041. if (lcd_commands_step == 2 && !blocks_queued())
  1042. {
  1043. setTargetBed(0);
  1044. enquecommand_P(PSTR("M104 S0")); //set hotend temp to 0
  1045. manage_heater();
  1046. lcd_setstatuspgm(WELCOME_MSG);
  1047. cancel_heatup = false;
  1048. lcd_commands_step = 1;
  1049. }
  1050. if (lcd_commands_step == 3 && !blocks_queued())
  1051. {
  1052. // M84: Disable steppers.
  1053. enquecommand_P(PSTR("M84"));
  1054. autotempShutdown();
  1055. lcd_commands_step = 2;
  1056. }
  1057. if (lcd_commands_step == 4 && !blocks_queued())
  1058. {
  1059. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  1060. // G90: Absolute positioning.
  1061. enquecommand_P(PSTR("G90"));
  1062. // M83: Set extruder to relative mode.
  1063. enquecommand_P(PSTR("M83"));
  1064. #ifdef X_CANCEL_POS
  1065. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1066. #else
  1067. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  1068. #endif
  1069. lcd_ignore_click(false);
  1070. #ifdef SNMM
  1071. lcd_commands_step = 8;
  1072. #else
  1073. lcd_commands_step = 3;
  1074. #endif
  1075. }
  1076. if (lcd_commands_step == 5 && !blocks_queued())
  1077. {
  1078. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  1079. // G91: Set to relative positioning.
  1080. enquecommand_P(PSTR("G91"));
  1081. // Lift up.
  1082. enquecommand_P(PSTR("G1 Z15 F1500"));
  1083. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  1084. else lcd_commands_step = 3;
  1085. }
  1086. if (lcd_commands_step == 6 && !blocks_queued())
  1087. {
  1088. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  1089. cancel_heatup = true;
  1090. setTargetBed(0);
  1091. #ifndef SNMM
  1092. setTargetHotend(0, 0); //heating when changing filament for multicolor
  1093. setTargetHotend(0, 1);
  1094. setTargetHotend(0, 2);
  1095. #endif
  1096. manage_heater();
  1097. custom_message = true;
  1098. custom_message_type = 2;
  1099. lcd_commands_step = 5;
  1100. }
  1101. if (lcd_commands_step == 7 && !blocks_queued()) {
  1102. switch(snmm_stop_print_menu()) {
  1103. case 0: enquecommand_P(PSTR("M702")); break;//all
  1104. case 1: enquecommand_P(PSTR("M702 U")); break; //used
  1105. case 2: enquecommand_P(PSTR("M702 C")); break; //current
  1106. default: enquecommand_P(PSTR("M702")); break;
  1107. }
  1108. lcd_commands_step = 3;
  1109. }
  1110. if (lcd_commands_step == 8 && !blocks_queued()) { //step 8 is here for delay (going to next step after execution of all gcodes from step 4)
  1111. lcd_commands_step = 7;
  1112. }
  1113. }
  1114. if (lcd_commands_type == 3)
  1115. {
  1116. lcd_commands_type = 0;
  1117. }
  1118. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  1119. {
  1120. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  1121. if (lcd_commands_step == 1 && !blocks_queued())
  1122. {
  1123. lcd_confirm_print();
  1124. lcd_commands_step = 0;
  1125. lcd_commands_type = 0;
  1126. }
  1127. if (lcd_commands_step == 2 && !blocks_queued())
  1128. {
  1129. lcd_commands_step = 1;
  1130. }
  1131. if (lcd_commands_step == 3 && !blocks_queued())
  1132. {
  1133. lcd_commands_step = 2;
  1134. }
  1135. if (lcd_commands_step == 4 && !blocks_queued())
  1136. {
  1137. enquecommand_P(PSTR("G90"));
  1138. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1139. lcd_commands_step = 3;
  1140. }
  1141. if (lcd_commands_step == 5 && !blocks_queued())
  1142. {
  1143. lcd_commands_step = 4;
  1144. }
  1145. if (lcd_commands_step == 6 && !blocks_queued())
  1146. {
  1147. enquecommand_P(PSTR("G91"));
  1148. enquecommand_P(PSTR("G1 Z15 F1500"));
  1149. st_synchronize();
  1150. #ifdef SNMM
  1151. lcd_commands_step = 7;
  1152. #else
  1153. lcd_commands_step = 5;
  1154. #endif
  1155. }
  1156. }
  1157. if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) {
  1158. char cmd1[30];
  1159. if (lcd_commands_step == 0) {
  1160. custom_message_type = 3;
  1161. custom_message_state = 1;
  1162. custom_message = true;
  1163. lcdDrawUpdate = 3;
  1164. lcd_commands_step = 3;
  1165. }
  1166. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  1167. strcpy(cmd1, "M303 E0 S");
  1168. strcat(cmd1, ftostr3(pid_temp));
  1169. enquecommand(cmd1);
  1170. lcd_setstatuspgm(MSG_PID_RUNNING);
  1171. lcd_commands_step = 2;
  1172. }
  1173. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  1174. pid_tuning_finished = false;
  1175. custom_message_state = 0;
  1176. lcd_setstatuspgm(MSG_PID_FINISHED);
  1177. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  1178. strcpy(cmd1, "M301 P");
  1179. strcat(cmd1, ftostr32(_Kp));
  1180. strcat(cmd1, " I");
  1181. strcat(cmd1, ftostr32(_Ki));
  1182. strcat(cmd1, " D");
  1183. strcat(cmd1, ftostr32(_Kd));
  1184. enquecommand(cmd1);
  1185. enquecommand_P(PSTR("M500"));
  1186. }
  1187. else {
  1188. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  1189. }
  1190. display_time = millis();
  1191. lcd_commands_step = 1;
  1192. }
  1193. if ((lcd_commands_step == 1) && ((millis()- display_time)>2000)) { //calibration finished message
  1194. lcd_setstatuspgm(WELCOME_MSG);
  1195. custom_message_type = 0;
  1196. custom_message = false;
  1197. pid_temp = DEFAULT_PID_TEMP;
  1198. lcd_commands_step = 0;
  1199. lcd_commands_type = 0;
  1200. }
  1201. }
  1202. }
  1203. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length) {
  1204. //returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions
  1205. float extr = extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4);
  1206. return extr;
  1207. }
  1208. static void lcd_return_to_status() {
  1209. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1210. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1211. currentMenu == lcd_status_screen
  1212. #endif
  1213. );
  1214. lcd_goto_menu(lcd_status_screen, 0, false);
  1215. }
  1216. void lcd_sdcard_pause() {
  1217. lcd_return_to_status();
  1218. lcd_commands_type = LCD_COMMAND_LONG_PAUSE;
  1219. }
  1220. static void lcd_sdcard_resume() {
  1221. lcd_return_to_status();
  1222. lcd_reset_alert_level(); //for fan speed error
  1223. lcd_commands_type = LCD_COMMAND_LONG_PAUSE_RESUME;
  1224. }
  1225. float move_menu_scale;
  1226. static void lcd_move_menu_axis();
  1227. /* Menu implementation */
  1228. void lcd_preheat_farm()
  1229. {
  1230. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1231. setTargetBed(FARM_PREHEAT_HPB_TEMP);
  1232. fanSpeed = 0;
  1233. lcd_return_to_status();
  1234. setWatch(); // heater sanity check timer
  1235. }
  1236. void lcd_preheat_pla()
  1237. {
  1238. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  1239. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  1240. fanSpeed = 0;
  1241. lcd_return_to_status();
  1242. setWatch(); // heater sanity check timer
  1243. }
  1244. void lcd_preheat_abs()
  1245. {
  1246. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  1247. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  1248. fanSpeed = 0;
  1249. lcd_return_to_status();
  1250. setWatch(); // heater sanity check timer
  1251. }
  1252. void lcd_preheat_pp()
  1253. {
  1254. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  1255. setTargetBed(PP_PREHEAT_HPB_TEMP);
  1256. fanSpeed = 0;
  1257. lcd_return_to_status();
  1258. setWatch(); // heater sanity check timer
  1259. }
  1260. void lcd_preheat_pet()
  1261. {
  1262. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  1263. setTargetBed(PET_PREHEAT_HPB_TEMP);
  1264. fanSpeed = 0;
  1265. lcd_return_to_status();
  1266. setWatch(); // heater sanity check timer
  1267. }
  1268. void lcd_preheat_hips()
  1269. {
  1270. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  1271. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  1272. fanSpeed = 0;
  1273. lcd_return_to_status();
  1274. setWatch(); // heater sanity check timer
  1275. }
  1276. void lcd_preheat_flex()
  1277. {
  1278. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  1279. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  1280. fanSpeed = 0;
  1281. lcd_return_to_status();
  1282. setWatch(); // heater sanity check timer
  1283. }
  1284. void lcd_cooldown()
  1285. {
  1286. setTargetHotend0(0);
  1287. setTargetHotend1(0);
  1288. setTargetHotend2(0);
  1289. setTargetBed(0);
  1290. fanSpeed = 0;
  1291. lcd_return_to_status();
  1292. }
  1293. static void lcd_menu_extruder_info()
  1294. {
  1295. int fan_speed_RPM[2];
  1296. #ifdef PAT9125
  1297. pat9125_update();
  1298. #endif //PAT9125
  1299. fan_speed_RPM[0] = 60*fan_speed[0];
  1300. fan_speed_RPM[1] = 60*fan_speed[1];
  1301. // Display Nozzle fan RPM
  1302. lcd.setCursor(0, 0);
  1303. lcd_printPGM(MSG_INFO_NOZZLE_FAN);
  1304. lcd.setCursor(11, 0);
  1305. lcd.print(" ");
  1306. lcd.setCursor(12, 0);
  1307. lcd.print(itostr4(fan_speed_RPM[0]));
  1308. lcd.print(" RPM");
  1309. // Display Nozzle fan RPM
  1310. #if (defined(TACH_1))
  1311. lcd.setCursor(0, 1);
  1312. lcd_printPGM(MSG_INFO_PRINT_FAN);
  1313. lcd.setCursor(11, 1);
  1314. lcd.print(" ");
  1315. lcd.setCursor(12, 1);
  1316. lcd.print(itostr4(fan_speed_RPM[1]));
  1317. lcd.print(" RPM");
  1318. #endif
  1319. #ifdef PAT9125
  1320. // Display X and Y difference from Filament sensor
  1321. lcd.setCursor(0, 2);
  1322. lcd.print("Fil. Xd:");
  1323. lcd.print(itostr3(pat9125_x));
  1324. lcd.print(" ");
  1325. lcd.setCursor(12, 2);
  1326. lcd.print("Yd:");
  1327. lcd.print(itostr3(pat9125_y));
  1328. // Display Light intensity from Filament sensor
  1329. /* Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  1330. value ranges from 0(darkest) to 255(brightest). */
  1331. lcd.setCursor(0, 3);
  1332. lcd.print("Int: ");
  1333. lcd.setCursor(5, 3);
  1334. lcd.print(itostr3(pat9125_b));
  1335. // Display LASER shutter time from Filament sensor
  1336. /* Shutter register is an index of LASER shutter time. It is automatically controlled by the chip�s internal
  1337. auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  1338. When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to
  1339. 46. */
  1340. lcd.setCursor(10, 3);
  1341. lcd.print("Shut: ");
  1342. lcd.setCursor(15, 3);
  1343. lcd.print(itostr3(pat9125_s));
  1344. #endif //PAT9125
  1345. if (lcd_clicked())
  1346. {
  1347. lcd_quick_feedback();
  1348. lcd_return_to_status();
  1349. }
  1350. }
  1351. #if defined(TMC2130) && defined(PAT9125)
  1352. static void lcd_menu_fails_stats_total()
  1353. {
  1354. //01234567890123456789
  1355. //Total failures
  1356. // Power failures 000
  1357. // Filam. runouts 000
  1358. // Crash X 000 Y 000
  1359. //////////////////////
  1360. uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
  1361. uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1362. uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
  1363. uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT);
  1364. fprintf_P(lcdout, PSTR(ESC_H(0,0)"Total failures"ESC_H(1,1)"Power failures %-3d"ESC_H(1,2)"Filam. runouts %-3d"ESC_H(1,3)"Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1365. if (lcd_clicked())
  1366. {
  1367. lcd_quick_feedback();
  1368. //lcd_return_to_status();
  1369. lcd_goto_menu(lcd_menu_fails_stats, 4);
  1370. }
  1371. }
  1372. static void lcd_menu_fails_stats_print()
  1373. {
  1374. //01234567890123456789
  1375. //Last print failures
  1376. // Power failures 000
  1377. // Filam. runouts 000
  1378. // Crash X 000 Y 000
  1379. //////////////////////
  1380. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1381. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1382. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1383. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1384. fprintf_P(lcdout, PSTR(ESC_H(0,0)"Last print failures"ESC_H(1,1)"Power failures %-3d"ESC_H(1,2)"Filam. runouts %-3d"ESC_H(1,3)"Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1385. if (lcd_clicked())
  1386. {
  1387. lcd_quick_feedback();
  1388. //lcd_return_to_status();
  1389. lcd_goto_menu(lcd_menu_fails_stats, 2);
  1390. }
  1391. }
  1392. /**
  1393. * @brief Open fail statistics menu
  1394. *
  1395. * This version of function is used, when there is filament sensor,
  1396. * power failure and crash detection.
  1397. * There are Last print and Total menu items.
  1398. */
  1399. static void lcd_menu_fails_stats()
  1400. {
  1401. START_MENU();
  1402. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1403. MENU_ITEM(submenu, PSTR("Last print"), lcd_menu_fails_stats_print);
  1404. MENU_ITEM(submenu, PSTR("Total"), lcd_menu_fails_stats_total);
  1405. END_MENU();
  1406. }
  1407. #else if defined(PAT9125)
  1408. /**
  1409. * @brief Print last print and total filament run outs
  1410. *
  1411. * This version of function is used, when there is filament sensor,
  1412. * but no other sensors (e.g. power failure, crash detection).
  1413. *
  1414. * Example screen:
  1415. * @code
  1416. * 01234567890123456789
  1417. * Last print failures
  1418. * Filam. runouts 0
  1419. * Total failures
  1420. * Filam. runouts 5
  1421. * @endcode
  1422. */
  1423. static void lcd_menu_fails_stats()
  1424. {
  1425. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1426. uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1427. fprintf_P(lcdout, PSTR(ESC_H(0,0)"Last print failures"ESC_H(1,1)"Filam. runouts %-3d"ESC_H(0,2)"Total failures"ESC_H(1,3)"Filam. runouts %-3d"), filamentLast, filamentTotal);
  1428. if (lcd_clicked())
  1429. {
  1430. menu_action_back();
  1431. }
  1432. }
  1433. #endif //TMC2130
  1434. #ifdef DEBUG_BUILD
  1435. extern uint16_t SP_min;
  1436. extern char* __malloc_heap_start;
  1437. extern char* __malloc_heap_end;
  1438. static void lcd_menu_debug()
  1439. {
  1440. fprintf_P(lcdout, PSTR(ESC_H(1,1)"RAM statistics"ESC_H(5,1)"SP_min: 0x%04x"ESC_H(1,2)"heap_start: 0x%04x"ESC_H(3,3)"heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end);
  1441. if (lcd_clicked())
  1442. {
  1443. lcd_quick_feedback();
  1444. lcd_return_to_status();
  1445. }
  1446. }
  1447. #endif /* DEBUG_BUILD */
  1448. static void lcd_menu_temperatures()
  1449. {
  1450. fprintf_P(lcdout, PSTR(ESC_H(1,0)"Nozzle: %d%c" ESC_H(1,1)"Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01');
  1451. #ifdef AMBIENT_THERMISTOR
  1452. fprintf_P(lcdout, PSTR(ESC_H(1,2)"Ambient: %d%c" ESC_H(1,3)"PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01');
  1453. #else //AMBIENT_THERMISTOR
  1454. fprintf_P(lcdout, PSTR(ESC_H(1,2)"PINDA: %d%c"), (int)current_temperature_pinda, '\x01');
  1455. #endif //AMBIENT_THERMISTOR
  1456. if (lcd_clicked())
  1457. {
  1458. lcd_quick_feedback();
  1459. lcd_return_to_status();
  1460. }
  1461. }
  1462. #ifdef defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
  1463. #define VOLT_DIV_R1 10000
  1464. #define VOLT_DIV_R2 2370
  1465. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1466. #define VOLT_DIV_REF 5
  1467. static void lcd_menu_voltages()
  1468. {
  1469. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1470. //float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1471. //fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
  1472. fprintf_P(lcdout, PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
  1473. if (lcd_clicked())
  1474. {
  1475. lcd_quick_feedback();
  1476. lcd_return_to_status();
  1477. }
  1478. }
  1479. #endif //defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
  1480. #ifdef TMC2130
  1481. static void lcd_menu_belt_status()
  1482. {
  1483. fprintf_P(lcdout, PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1484. if (lcd_clicked())
  1485. {
  1486. lcd_quick_feedback();
  1487. lcd_return_to_status();
  1488. }
  1489. }
  1490. #endif //TMC2130
  1491. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1492. extern void restore_print_from_ram_and_continue(float e_move);
  1493. static void lcd_menu_test_save()
  1494. {
  1495. stop_and_save_print_to_ram(10, -0.8);
  1496. }
  1497. static void lcd_menu_test_restore()
  1498. {
  1499. restore_print_from_ram_and_continue(0.8);
  1500. }
  1501. static void lcd_preheat_menu()
  1502. {
  1503. START_MENU();
  1504. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1505. if (farm_mode)
  1506. MENU_ITEM(function, PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), lcd_preheat_farm);
  1507. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  1508. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  1509. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1510. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  1511. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  1512. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  1513. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1514. END_MENU();
  1515. }
  1516. static void lcd_support_menu()
  1517. {
  1518. if (menuData.supportMenu.status == 0 || lcdDrawUpdate == 2) {
  1519. // Menu was entered or SD card status has changed (plugged in or removed).
  1520. // Initialize its status.
  1521. menuData.supportMenu.status = 1;
  1522. menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip);
  1523. if (menuData.supportMenu.is_flash_air)
  1524. sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"),
  1525. menuData.supportMenu.ip[0], menuData.supportMenu.ip[1],
  1526. menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]);
  1527. } else if (menuData.supportMenu.is_flash_air &&
  1528. menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
  1529. menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
  1530. ++ menuData.supportMenu.status == 16) {
  1531. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1532. menuData.supportMenu.status = 0;
  1533. }
  1534. START_MENU();
  1535. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1536. MENU_ITEM(back, PSTR("Firmware:"), lcd_main_menu);
  1537. MENU_ITEM(back, PSTR(" " FW_VERSION_FULL), lcd_main_menu);
  1538. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1539. MENU_ITEM(back, PSTR(" repo " FW_REPOSITORY), lcd_main_menu);
  1540. #endif
  1541. // Ideally this block would be optimized out by the compiler.
  1542. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1543. if (fw_string_len < 6) {
  1544. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  1545. } else {
  1546. MENU_ITEM(back, PSTR("FW - " FW_version), lcd_main_menu);
  1547. }*/
  1548. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  1549. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  1550. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  1551. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  1552. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  1553. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  1554. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  1555. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  1556. MENU_ITEM(back, MSG_DATE, lcd_main_menu);
  1557. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  1558. // Show the FlashAir IP address, if the card is available.
  1559. if (menuData.supportMenu.is_flash_air) {
  1560. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  1561. MENU_ITEM(back, PSTR("FlashAir IP Addr:"), lcd_main_menu);
  1562. MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, lcd_main_menu);
  1563. }
  1564. #ifndef MK1BP
  1565. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  1566. if (!IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) MENU_ITEM(function, MSG_XYZ_DETAILS, lcd_service_mode_show_result);
  1567. MENU_ITEM(submenu, MSG_INFO_EXTRUDER, lcd_menu_extruder_info);
  1568. #ifdef TMC2130
  1569. MENU_ITEM(submenu, MSG_MENU_BELT_STATUS, lcd_menu_belt_status);
  1570. #endif //TMC2130
  1571. MENU_ITEM(submenu, MSG_MENU_TEMPERATURES, lcd_menu_temperatures);
  1572. #ifdef defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
  1573. MENU_ITEM(submenu, MSG_MENU_VOLTAGES, lcd_menu_voltages);
  1574. #endif //defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
  1575. #ifdef DEBUG_BUILD
  1576. MENU_ITEM(submenu, PSTR("Debug"), lcd_menu_debug);
  1577. #endif /* DEBUG_BUILD */
  1578. #endif //MK1BP
  1579. END_MENU();
  1580. }
  1581. void lcd_set_fan_check() {
  1582. fans_check_enabled = !fans_check_enabled;
  1583. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1584. lcd_goto_menu(lcd_settings_menu, 8);
  1585. }
  1586. void lcd_set_filament_autoload() {
  1587. filament_autoload_enabled = !filament_autoload_enabled;
  1588. eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, filament_autoload_enabled);
  1589. lcd_goto_menu(lcd_settings_menu, 8);
  1590. }
  1591. void lcd_unLoadFilament()
  1592. {
  1593. if (degHotend0() > EXTRUDE_MINTEMP) {
  1594. enquecommand_P(PSTR("M702")); //unload filament
  1595. } else {
  1596. lcd_implementation_clear();
  1597. lcd.setCursor(0, 0);
  1598. lcd_printPGM(MSG_ERROR);
  1599. lcd.setCursor(0, 2);
  1600. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1601. delay(2000);
  1602. lcd_implementation_clear();
  1603. }
  1604. lcd_return_to_status();
  1605. }
  1606. void lcd_change_filament() {
  1607. lcd_implementation_clear();
  1608. lcd.setCursor(0, 1);
  1609. lcd_printPGM(MSG_CHANGING_FILAMENT);
  1610. }
  1611. void lcd_wait_interact() {
  1612. lcd_implementation_clear();
  1613. lcd.setCursor(0, 1);
  1614. #ifdef SNMM
  1615. lcd_printPGM(MSG_PREPARE_FILAMENT);
  1616. #else
  1617. lcd_printPGM(MSG_INSERT_FILAMENT);
  1618. #endif
  1619. lcd.setCursor(0, 2);
  1620. lcd_printPGM(MSG_PRESS);
  1621. }
  1622. void lcd_change_success() {
  1623. lcd_implementation_clear();
  1624. lcd.setCursor(0, 2);
  1625. lcd_printPGM(MSG_CHANGE_SUCCESS);
  1626. }
  1627. void lcd_loading_color() {
  1628. lcd_implementation_clear();
  1629. lcd.setCursor(0, 0);
  1630. lcd_printPGM(MSG_LOADING_COLOR);
  1631. lcd.setCursor(0, 2);
  1632. lcd_printPGM(MSG_PLEASE_WAIT);
  1633. for (int i = 0; i < 20; i++) {
  1634. lcd.setCursor(i, 3);
  1635. lcd.print(".");
  1636. for (int j = 0; j < 10 ; j++) {
  1637. manage_heater();
  1638. manage_inactivity(true);
  1639. delay(85);
  1640. }
  1641. }
  1642. }
  1643. void lcd_loading_filament() {
  1644. lcd_implementation_clear();
  1645. lcd.setCursor(0, 0);
  1646. lcd_printPGM(MSG_LOADING_FILAMENT);
  1647. lcd.setCursor(0, 2);
  1648. lcd_printPGM(MSG_PLEASE_WAIT);
  1649. for (int i = 0; i < 20; i++) {
  1650. lcd.setCursor(i, 3);
  1651. lcd.print(".");
  1652. for (int j = 0; j < 10 ; j++) {
  1653. manage_heater();
  1654. manage_inactivity(true);
  1655. #ifdef SNMM
  1656. delay(153);
  1657. #else
  1658. delay(137);
  1659. #endif
  1660. }
  1661. }
  1662. }
  1663. void lcd_alright() {
  1664. int enc_dif = 0;
  1665. int cursor_pos = 1;
  1666. lcd_implementation_clear();
  1667. lcd.setCursor(0, 0);
  1668. lcd_printPGM(MSG_CORRECTLY);
  1669. lcd.setCursor(1, 1);
  1670. lcd_printPGM(MSG_YES);
  1671. lcd.setCursor(1, 2);
  1672. lcd_printPGM(MSG_NOT_LOADED);
  1673. lcd.setCursor(1, 3);
  1674. lcd_printPGM(MSG_NOT_COLOR);
  1675. lcd.setCursor(0, 1);
  1676. lcd.print(">");
  1677. enc_dif = encoderDiff;
  1678. while (lcd_change_fil_state == 0) {
  1679. manage_heater();
  1680. manage_inactivity(true);
  1681. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1682. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1683. if (enc_dif > encoderDiff ) {
  1684. cursor_pos --;
  1685. }
  1686. if (enc_dif < encoderDiff ) {
  1687. cursor_pos ++;
  1688. }
  1689. if (cursor_pos > 3) {
  1690. cursor_pos = 3;
  1691. }
  1692. if (cursor_pos < 1) {
  1693. cursor_pos = 1;
  1694. }
  1695. lcd.setCursor(0, 1);
  1696. lcd.print(" ");
  1697. lcd.setCursor(0, 2);
  1698. lcd.print(" ");
  1699. lcd.setCursor(0, 3);
  1700. lcd.print(" ");
  1701. lcd.setCursor(0, cursor_pos);
  1702. lcd.print(">");
  1703. enc_dif = encoderDiff;
  1704. delay(100);
  1705. }
  1706. }
  1707. if (lcd_clicked()) {
  1708. lcd_change_fil_state = cursor_pos;
  1709. delay(500);
  1710. }
  1711. };
  1712. lcd_implementation_clear();
  1713. lcd_return_to_status();
  1714. }
  1715. void lcd_LoadFilament()
  1716. {
  1717. if (degHotend0() > EXTRUDE_MINTEMP)
  1718. {
  1719. #ifdef PAT9125
  1720. if (filament_autoload_enabled && fsensor_enabled)
  1721. {
  1722. lcd_show_fullscreen_message_and_wait_P(MSG_AUTOLOADING_ENABLED);
  1723. return;
  1724. }
  1725. #endif //PAT9125
  1726. custom_message = true;
  1727. loading_flag = true;
  1728. enquecommand_P(PSTR("M701")); //load filament
  1729. SERIAL_ECHOLN("Loading filament");
  1730. }
  1731. else
  1732. {
  1733. lcd_implementation_clear();
  1734. lcd.setCursor(0, 0);
  1735. lcd_printPGM(MSG_ERROR);
  1736. lcd.setCursor(0, 2);
  1737. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1738. delay(2000);
  1739. lcd_implementation_clear();
  1740. }
  1741. lcd_return_to_status();
  1742. }
  1743. void lcd_menu_statistics()
  1744. {
  1745. if (IS_SD_PRINTING)
  1746. {
  1747. int _met = total_filament_used / 100000;
  1748. int _cm = (total_filament_used - (_met * 100000))/10;
  1749. int _t = (millis() - starttime) / 1000;
  1750. int _h = _t / 3600;
  1751. int _m = (_t - (_h * 3600)) / 60;
  1752. int _s = _t - ((_h * 3600) + (_m * 60));
  1753. lcd.setCursor(0, 0);
  1754. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  1755. lcd.setCursor(6, 1);
  1756. lcd.print(itostr3(_met));
  1757. lcd.print("m ");
  1758. lcd.print(ftostr32ns(_cm));
  1759. lcd.print("cm");
  1760. lcd.setCursor(0, 2);
  1761. lcd_printPGM(MSG_STATS_PRINTTIME);
  1762. lcd.setCursor(8, 3);
  1763. lcd.print(itostr2(_h));
  1764. lcd.print("h ");
  1765. lcd.print(itostr2(_m));
  1766. lcd.print("m ");
  1767. lcd.print(itostr2(_s));
  1768. lcd.print("s");
  1769. if (lcd_clicked())
  1770. {
  1771. lcd_quick_feedback();
  1772. lcd_return_to_status();
  1773. }
  1774. }
  1775. else
  1776. {
  1777. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  1778. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  1779. uint8_t _hours, _minutes;
  1780. uint32_t _days;
  1781. float _filament_m = (float)_filament;
  1782. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  1783. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  1784. _days = _time / 1440;
  1785. _hours = (_time - (_days * 1440)) / 60;
  1786. _minutes = _time - ((_days * 1440) + (_hours * 60));
  1787. lcd_implementation_clear();
  1788. lcd.setCursor(0, 0);
  1789. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  1790. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  1791. lcd.print(ftostr32ns(_filament_m));
  1792. if (_filament_km > 0)
  1793. {
  1794. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  1795. lcd.print("km");
  1796. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  1797. lcd.print(itostr4(_filament_km));
  1798. }
  1799. lcd.setCursor(18, 1);
  1800. lcd.print("m");
  1801. lcd.setCursor(0, 2);
  1802. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  1803. lcd.setCursor(18, 3);
  1804. lcd.print("m");
  1805. lcd.setCursor(14, 3);
  1806. lcd.print(itostr3(_minutes));
  1807. lcd.setCursor(14, 3);
  1808. lcd.print(":");
  1809. lcd.setCursor(12, 3);
  1810. lcd.print("h");
  1811. lcd.setCursor(9, 3);
  1812. lcd.print(itostr3(_hours));
  1813. lcd.setCursor(9, 3);
  1814. lcd.print(":");
  1815. lcd.setCursor(7, 3);
  1816. lcd.print("d");
  1817. lcd.setCursor(4, 3);
  1818. lcd.print(itostr3(_days));
  1819. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1820. while (!lcd_clicked())
  1821. {
  1822. manage_heater();
  1823. manage_inactivity(true);
  1824. delay(100);
  1825. }
  1826. KEEPALIVE_STATE(NOT_BUSY);
  1827. lcd_quick_feedback();
  1828. lcd_return_to_status();
  1829. }
  1830. }
  1831. static void _lcd_move(const char *name, int axis, int min, int max) {
  1832. if (encoderPosition != 0) {
  1833. refresh_cmd_timeout();
  1834. if (! planner_queue_full()) {
  1835. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  1836. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  1837. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  1838. encoderPosition = 0;
  1839. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  1840. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  1841. lcdDrawUpdate = 1;
  1842. }
  1843. }
  1844. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  1845. if (LCD_CLICKED) menu_action_back(); {
  1846. }
  1847. }
  1848. static void lcd_move_e()
  1849. {
  1850. if (degHotend0() > EXTRUDE_MINTEMP) {
  1851. if (encoderPosition != 0)
  1852. {
  1853. refresh_cmd_timeout();
  1854. if (! planner_queue_full()) {
  1855. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  1856. encoderPosition = 0;
  1857. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  1858. lcdDrawUpdate = 1;
  1859. }
  1860. }
  1861. if (lcdDrawUpdate)
  1862. {
  1863. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  1864. }
  1865. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  1866. }
  1867. else {
  1868. lcd_implementation_clear();
  1869. lcd.setCursor(0, 0);
  1870. lcd_printPGM(MSG_ERROR);
  1871. lcd.setCursor(0, 2);
  1872. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1873. delay(2000);
  1874. lcd_return_to_status();
  1875. }
  1876. }
  1877. void lcd_service_mode_show_result() {
  1878. float angleDiff;
  1879. lcd_set_custom_characters_degree();
  1880. count_xyz_details();
  1881. angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  1882. lcd_update_enable(false);
  1883. lcd_implementation_clear();
  1884. lcd_printPGM(MSG_Y_DISTANCE_FROM_MIN);
  1885. lcd_print_at_PGM(0, 1, MSG_LEFT);
  1886. lcd_print_at_PGM(0, 2, MSG_RIGHT);
  1887. for (int i = 0; i < 2; i++) {
  1888. if(distance_from_min[i] < 200) {
  1889. lcd_print_at_PGM(11, i + 1, PSTR(""));
  1890. lcd.print(distance_from_min[i]);
  1891. lcd_print_at_PGM((distance_from_min[i] < 0) ? 17 : 16, i + 1, PSTR("mm"));
  1892. } else lcd_print_at_PGM(11, i + 1, PSTR("N/A"));
  1893. }
  1894. delay_keep_alive(500);
  1895. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1896. while (!lcd_clicked()) {
  1897. delay_keep_alive(100);
  1898. }
  1899. delay_keep_alive(500);
  1900. lcd_implementation_clear();
  1901. lcd_printPGM(MSG_MEASURED_SKEW);
  1902. if (angleDiff < 100) {
  1903. lcd.setCursor(15, 0);
  1904. lcd.print(angleDiff * 180 / M_PI);
  1905. lcd.print(LCD_STR_DEGREE);
  1906. }else lcd_print_at_PGM(16, 0, PSTR("N/A"));
  1907. lcd_print_at_PGM(0, 1, PSTR("--------------------"));
  1908. lcd_print_at_PGM(0, 2, MSG_SLIGHT_SKEW);
  1909. lcd_print_at_PGM(15, 2, PSTR(""));
  1910. lcd.print(bed_skew_angle_mild * 180 / M_PI);
  1911. lcd.print(LCD_STR_DEGREE);
  1912. lcd_print_at_PGM(0, 3, MSG_SEVERE_SKEW);
  1913. lcd_print_at_PGM(15, 3, PSTR(""));
  1914. lcd.print(bed_skew_angle_extreme * 180 / M_PI);
  1915. lcd.print(LCD_STR_DEGREE);
  1916. delay_keep_alive(500);
  1917. while (!lcd_clicked()) {
  1918. delay_keep_alive(100);
  1919. }
  1920. KEEPALIVE_STATE(NOT_BUSY);
  1921. delay_keep_alive(500);
  1922. lcd_set_custom_characters_arrows();
  1923. lcd_return_to_status();
  1924. lcd_update_enable(true);
  1925. lcd_update(2);
  1926. }
  1927. // Save a single axis babystep value.
  1928. void EEPROM_save_B(int pos, int* value)
  1929. {
  1930. union Data data;
  1931. data.value = *value;
  1932. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  1933. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  1934. }
  1935. // Read a single axis babystep value.
  1936. void EEPROM_read_B(int pos, int* value)
  1937. {
  1938. union Data data;
  1939. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  1940. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  1941. *value = data.value;
  1942. }
  1943. static void lcd_move_x() {
  1944. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  1945. }
  1946. static void lcd_move_y() {
  1947. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  1948. }
  1949. static void lcd_move_z() {
  1950. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  1951. }
  1952. static void _lcd_babystep(int axis, const char *msg)
  1953. {
  1954. if (menuData.babyStep.status == 0) {
  1955. // Menu was entered.
  1956. // Initialize its status.
  1957. menuData.babyStep.status = 1;
  1958. check_babystep();
  1959. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  1960. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  1961. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  1962. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  1963. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  1964. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1965. lcdDrawUpdate = 1;
  1966. //SERIAL_ECHO("Z baby step: ");
  1967. //SERIAL_ECHO(menuData.babyStep.babystepMem[2]);
  1968. // Wait 90 seconds before closing the live adjust dialog.
  1969. lcd_timeoutToStatus = millis() + 90000;
  1970. }
  1971. if (encoderPosition != 0)
  1972. {
  1973. if (homing_flag) encoderPosition = 0;
  1974. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  1975. if (axis == 2) {
  1976. if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  1977. else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
  1978. else {
  1979. CRITICAL_SECTION_START
  1980. babystepsTodo[axis] += (int)encoderPosition;
  1981. CRITICAL_SECTION_END
  1982. }
  1983. }
  1984. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis];
  1985. delay(50);
  1986. encoderPosition = 0;
  1987. lcdDrawUpdate = 1;
  1988. }
  1989. if (lcdDrawUpdate)
  1990. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  1991. if (LCD_CLICKED || menuExiting) {
  1992. // Only update the EEPROM when leaving the menu.
  1993. EEPROM_save_B(
  1994. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  1995. &menuData.babyStep.babystepMem[axis]);
  1996. }
  1997. if (LCD_CLICKED) menu_action_back();
  1998. }
  1999. static void lcd_babystep_x() {
  2000. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  2001. }
  2002. static void lcd_babystep_y() {
  2003. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  2004. }
  2005. static void lcd_babystep_z() {
  2006. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  2007. }
  2008. static void lcd_adjust_bed();
  2009. /**
  2010. * @brief adjust bed reset menu item function
  2011. *
  2012. * To be used as MENU_ITEM(function,...) inside lcd_adjust_bed submenu. In such case lcd_goto_menu usage
  2013. * is correct and doesn't break menuStack.
  2014. * Because we did not leave the menu, the menuData did not reset.
  2015. * Force refresh of the bed leveling data.
  2016. */
  2017. static void lcd_adjust_bed_reset()
  2018. {
  2019. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2020. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2021. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2022. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2023. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2024. lcd_goto_menu(lcd_adjust_bed, 0, false); //doesn't break menuStack
  2025. menuData.adjustBed.status = 0;
  2026. }
  2027. void adjust_bed_reset() {
  2028. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2029. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  2030. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2031. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2032. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  2033. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  2034. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  2035. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  2036. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  2037. }
  2038. #define BED_ADJUSTMENT_UM_MAX 50
  2039. static void lcd_adjust_bed()
  2040. {
  2041. if (menuData.adjustBed.status == 0) {
  2042. // Menu was entered.
  2043. // Initialize its status.
  2044. menuData.adjustBed.status = 1;
  2045. bool valid = false;
  2046. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2047. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2048. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2049. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2050. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  2051. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  2052. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  2053. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  2054. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  2055. valid = true;
  2056. if (! valid) {
  2057. // Reset the values: simulate an edit.
  2058. menuData.adjustBed.left2 = 0;
  2059. menuData.adjustBed.right2 = 0;
  2060. menuData.adjustBed.front2 = 0;
  2061. menuData.adjustBed.rear2 = 0;
  2062. }
  2063. lcdDrawUpdate = 1;
  2064. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2065. }
  2066. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  2067. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  2068. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  2069. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  2070. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  2071. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  2072. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  2073. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  2074. START_MENU();
  2075. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  2076. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2077. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2078. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2079. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2080. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  2081. END_MENU();
  2082. }
  2083. void pid_extruder() {
  2084. lcd_implementation_clear();
  2085. lcd.setCursor(1, 0);
  2086. lcd_printPGM(MSG_SET_TEMPERATURE);
  2087. pid_temp += int(encoderPosition);
  2088. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2089. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2090. encoderPosition = 0;
  2091. lcd.setCursor(1, 2);
  2092. lcd.print(ftostr3(pid_temp));
  2093. if (lcd_clicked()) {
  2094. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2095. lcd_return_to_status();
  2096. lcd_update(2);
  2097. }
  2098. }
  2099. void lcd_adjust_z() {
  2100. int enc_dif = 0;
  2101. int cursor_pos = 1;
  2102. int fsm = 0;
  2103. lcd_implementation_clear();
  2104. lcd.setCursor(0, 0);
  2105. lcd_printPGM(MSG_ADJUSTZ);
  2106. lcd.setCursor(1, 1);
  2107. lcd_printPGM(MSG_YES);
  2108. lcd.setCursor(1, 2);
  2109. lcd_printPGM(MSG_NO);
  2110. lcd.setCursor(0, 1);
  2111. lcd.print(">");
  2112. enc_dif = encoderDiff;
  2113. while (fsm == 0) {
  2114. manage_heater();
  2115. manage_inactivity(true);
  2116. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2117. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2118. if (enc_dif > encoderDiff ) {
  2119. cursor_pos --;
  2120. }
  2121. if (enc_dif < encoderDiff ) {
  2122. cursor_pos ++;
  2123. }
  2124. if (cursor_pos > 2) {
  2125. cursor_pos = 2;
  2126. }
  2127. if (cursor_pos < 1) {
  2128. cursor_pos = 1;
  2129. }
  2130. lcd.setCursor(0, 1);
  2131. lcd.print(" ");
  2132. lcd.setCursor(0, 2);
  2133. lcd.print(" ");
  2134. lcd.setCursor(0, cursor_pos);
  2135. lcd.print(">");
  2136. enc_dif = encoderDiff;
  2137. delay(100);
  2138. }
  2139. }
  2140. if (lcd_clicked()) {
  2141. fsm = cursor_pos;
  2142. if (fsm == 1) {
  2143. int babystepLoadZ = 0;
  2144. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2145. CRITICAL_SECTION_START
  2146. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2147. CRITICAL_SECTION_END
  2148. } else {
  2149. int zero = 0;
  2150. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2151. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2152. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2153. }
  2154. delay(500);
  2155. }
  2156. };
  2157. lcd_implementation_clear();
  2158. lcd_return_to_status();
  2159. }
  2160. void lcd_wait_for_heater() {
  2161. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  2162. lcd.setCursor(0, 4);
  2163. lcd.print(LCD_STR_THERMOMETER[0]);
  2164. lcd.print(ftostr3(degHotend(active_extruder)));
  2165. lcd.print("/");
  2166. lcd.print(ftostr3(degTargetHotend(active_extruder)));
  2167. lcd.print(LCD_STR_DEGREE);
  2168. }
  2169. void lcd_wait_for_cool_down() {
  2170. lcd_set_custom_characters_degree();
  2171. setTargetHotend(0,0);
  2172. setTargetBed(0);
  2173. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2174. lcd_display_message_fullscreen_P(MSG_WAITING_TEMP);
  2175. lcd.setCursor(0, 4);
  2176. lcd.print(LCD_STR_THERMOMETER[0]);
  2177. lcd.print(ftostr3(degHotend(0)));
  2178. lcd.print("/0");
  2179. lcd.print(LCD_STR_DEGREE);
  2180. lcd.setCursor(9, 4);
  2181. lcd.print(LCD_STR_BEDTEMP[0]);
  2182. lcd.print(ftostr3(degBed()));
  2183. lcd.print("/0");
  2184. lcd.print(LCD_STR_DEGREE);
  2185. lcd_set_custom_characters();
  2186. delay_keep_alive(1000);
  2187. serialecho_temperatures();
  2188. }
  2189. lcd_set_custom_characters_arrows();
  2190. lcd_update_enable(true);
  2191. }
  2192. // Lets the user move the Z carriage up to the end stoppers.
  2193. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2194. // Otherwise the Z calibration is not changed and false is returned.
  2195. #ifndef TMC2130
  2196. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2197. {
  2198. bool clean_nozzle_asked = false;
  2199. // 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.
  2200. current_position[Z_AXIS] = 0;
  2201. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2202. // Until confirmed by the confirmation dialog.
  2203. for (;;) {
  2204. unsigned long previous_millis_cmd = millis();
  2205. const char *msg = only_z ? MSG_MOVE_CARRIAGE_TO_THE_TOP_Z : MSG_MOVE_CARRIAGE_TO_THE_TOP;
  2206. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2207. const bool multi_screen = msg_next != NULL;
  2208. unsigned long previous_millis_msg = millis();
  2209. // Until the user finishes the z up movement.
  2210. encoderDiff = 0;
  2211. encoderPosition = 0;
  2212. for (;;) {
  2213. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2214. // goto canceled;
  2215. manage_heater();
  2216. manage_inactivity(true);
  2217. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  2218. delay(50);
  2219. previous_millis_cmd = millis();
  2220. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  2221. encoderDiff = 0;
  2222. if (! planner_queue_full()) {
  2223. // Only move up, whatever direction the user rotates the encoder.
  2224. current_position[Z_AXIS] += fabs(encoderPosition);
  2225. encoderPosition = 0;
  2226. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS] / 60, active_extruder);
  2227. }
  2228. }
  2229. if (lcd_clicked()) {
  2230. // Abort a move if in progress.
  2231. planner_abort_hard();
  2232. while (lcd_clicked()) ;
  2233. delay(10);
  2234. while (lcd_clicked()) ;
  2235. break;
  2236. }
  2237. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2238. if (msg_next == NULL)
  2239. msg_next = msg;
  2240. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2241. previous_millis_msg = millis();
  2242. }
  2243. }
  2244. if (! clean_nozzle_asked) {
  2245. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  2246. clean_nozzle_asked = true;
  2247. }
  2248. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2249. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP, false);
  2250. if (result == -1)
  2251. goto canceled;
  2252. else if (result == 1)
  2253. goto calibrated;
  2254. // otherwise perform another round of the Z up dialog.
  2255. }
  2256. calibrated:
  2257. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2258. // during the search for the induction points.
  2259. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2260. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2261. if(only_z){
  2262. lcd_display_message_fullscreen_P(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1);
  2263. lcd_implementation_print_at(0, 3, 1);
  2264. lcd_printPGM(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2);
  2265. }else{
  2266. //lcd_show_fullscreen_message_and_wait_P(MSG_PAPER);
  2267. lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1);
  2268. lcd_implementation_print_at(0, 2, 1);
  2269. lcd_printPGM(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2);
  2270. }
  2271. return true;
  2272. canceled:
  2273. return false;
  2274. }
  2275. #endif // TMC2130
  2276. static inline bool pgm_is_whitespace(const char *c_addr)
  2277. {
  2278. const char c = pgm_read_byte(c_addr);
  2279. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2280. }
  2281. static inline bool pgm_is_interpunction(const char *c_addr)
  2282. {
  2283. const char c = pgm_read_byte(c_addr);
  2284. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2285. }
  2286. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2287. {
  2288. // Disable update of the screen by the usual lcd_update() routine.
  2289. lcd_update_enable(false);
  2290. lcd_implementation_clear();
  2291. lcd.setCursor(0, 0);
  2292. const char *msgend = msg;
  2293. uint8_t row = 0;
  2294. bool multi_screen = false;
  2295. for (; row < 4; ++ row) {
  2296. while (pgm_is_whitespace(msg))
  2297. ++ msg;
  2298. if (pgm_read_byte(msg) == 0)
  2299. // End of the message.
  2300. break;
  2301. lcd.setCursor(0, row);
  2302. uint8_t linelen = min(strlen_P(msg), 20);
  2303. const char *msgend2 = msg + linelen;
  2304. msgend = msgend2;
  2305. if (row == 3 && linelen == 20) {
  2306. // Last line of the display, full line shall be displayed.
  2307. // Find out, whether this message will be split into multiple screens.
  2308. while (pgm_is_whitespace(msgend))
  2309. ++ msgend;
  2310. multi_screen = pgm_read_byte(msgend) != 0;
  2311. if (multi_screen)
  2312. msgend = (msgend2 -= 2);
  2313. }
  2314. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2315. // Splitting a word. Find the start of the current word.
  2316. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2317. -- msgend;
  2318. if (msgend == msg)
  2319. // Found a single long word, which cannot be split. Just cut it.
  2320. msgend = msgend2;
  2321. }
  2322. for (; msg < msgend; ++ msg) {
  2323. char c = char(pgm_read_byte(msg));
  2324. if (c == '~')
  2325. c = ' ';
  2326. lcd.print(c);
  2327. }
  2328. }
  2329. if (multi_screen) {
  2330. // Display the "next screen" indicator character.
  2331. // lcd_set_custom_characters_arrows();
  2332. lcd_set_custom_characters_nextpage();
  2333. lcd.setCursor(19, 3);
  2334. // Display the down arrow.
  2335. lcd.print(char(1));
  2336. }
  2337. nlines = row;
  2338. return multi_screen ? msgend : NULL;
  2339. }
  2340. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2341. {
  2342. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2343. bool multi_screen = msg_next != NULL;
  2344. lcd_set_custom_characters_nextpage();
  2345. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2346. // Until confirmed by a button click.
  2347. for (;;) {
  2348. if (!multi_screen) {
  2349. lcd.setCursor(19, 3);
  2350. // Display the confirm char.
  2351. lcd.print(char(2));
  2352. }
  2353. // Wait for 5 seconds before displaying the next text.
  2354. for (uint8_t i = 0; i < 100; ++ i) {
  2355. delay_keep_alive(50);
  2356. if (lcd_clicked()) {
  2357. while (lcd_clicked()) ;
  2358. delay(10);
  2359. while (lcd_clicked()) ;
  2360. if (msg_next == NULL) {
  2361. KEEPALIVE_STATE(IN_HANDLER);
  2362. lcd_set_custom_characters();
  2363. lcd_update_enable(true);
  2364. lcd_update(2);
  2365. return;
  2366. }
  2367. else {
  2368. break;
  2369. }
  2370. }
  2371. }
  2372. if (multi_screen) {
  2373. if (msg_next == NULL)
  2374. msg_next = msg;
  2375. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2376. if (msg_next == NULL) {
  2377. lcd.setCursor(19, 3);
  2378. // Display the confirm char.
  2379. lcd.print(char(2));
  2380. }
  2381. }
  2382. }
  2383. }
  2384. void lcd_wait_for_click()
  2385. {
  2386. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2387. for (;;) {
  2388. manage_heater();
  2389. manage_inactivity(true);
  2390. if (lcd_clicked()) {
  2391. while (lcd_clicked()) ;
  2392. delay(10);
  2393. while (lcd_clicked()) ;
  2394. KEEPALIVE_STATE(IN_HANDLER);
  2395. return;
  2396. }
  2397. }
  2398. }
  2399. 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)
  2400. {
  2401. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2402. bool multi_screen = msg_next != NULL;
  2403. bool yes = default_yes ? true : false;
  2404. // Wait for user confirmation or a timeout.
  2405. unsigned long previous_millis_cmd = millis();
  2406. int8_t enc_dif = encoderDiff;
  2407. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2408. for (;;) {
  2409. for (uint8_t i = 0; i < 100; ++i) {
  2410. delay_keep_alive(50);
  2411. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2412. return -1;
  2413. manage_heater();
  2414. manage_inactivity(true);
  2415. if (abs(enc_dif - encoderDiff) > 4) {
  2416. if (msg_next == NULL) {
  2417. lcd.setCursor(0, 3);
  2418. if (enc_dif < encoderDiff && yes) {
  2419. lcd_printPGM((PSTR(" ")));
  2420. lcd.setCursor(7, 3);
  2421. lcd_printPGM((PSTR(">")));
  2422. yes = false;
  2423. }
  2424. else if (enc_dif > encoderDiff && !yes) {
  2425. lcd_printPGM((PSTR(">")));
  2426. lcd.setCursor(7, 3);
  2427. lcd_printPGM((PSTR(" ")));
  2428. yes = true;
  2429. }
  2430. enc_dif = encoderDiff;
  2431. }
  2432. else {
  2433. break; //turning knob skips waiting loop
  2434. }
  2435. }
  2436. if (lcd_clicked()) {
  2437. while (lcd_clicked());
  2438. delay(10);
  2439. while (lcd_clicked());
  2440. if (msg_next == NULL) {
  2441. //KEEPALIVE_STATE(IN_HANDLER);
  2442. lcd_set_custom_characters();
  2443. return yes;
  2444. }
  2445. else break;
  2446. }
  2447. }
  2448. if (multi_screen) {
  2449. if (msg_next == NULL) {
  2450. msg_next = msg;
  2451. }
  2452. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2453. }
  2454. if (msg_next == NULL) {
  2455. lcd.setCursor(0, 3);
  2456. if (yes) lcd_printPGM(PSTR(">"));
  2457. lcd.setCursor(1, 3);
  2458. lcd_printPGM(MSG_YES);
  2459. lcd.setCursor(7, 3);
  2460. if (!yes) lcd_printPGM(PSTR(">"));
  2461. lcd.setCursor(8, 3);
  2462. lcd_printPGM(MSG_NO);
  2463. }
  2464. }
  2465. }
  2466. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2467. {
  2468. lcd_display_message_fullscreen_P(msg);
  2469. if (default_yes) {
  2470. lcd.setCursor(0, 2);
  2471. lcd_printPGM(PSTR(">"));
  2472. lcd_printPGM(MSG_YES);
  2473. lcd.setCursor(1, 3);
  2474. lcd_printPGM(MSG_NO);
  2475. }
  2476. else {
  2477. lcd.setCursor(1, 2);
  2478. lcd_printPGM(MSG_YES);
  2479. lcd.setCursor(0, 3);
  2480. lcd_printPGM(PSTR(">"));
  2481. lcd_printPGM(MSG_NO);
  2482. }
  2483. bool yes = default_yes ? true : false;
  2484. // Wait for user confirmation or a timeout.
  2485. unsigned long previous_millis_cmd = millis();
  2486. int8_t enc_dif = encoderDiff;
  2487. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2488. for (;;) {
  2489. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2490. return -1;
  2491. manage_heater();
  2492. manage_inactivity(true);
  2493. if (abs(enc_dif - encoderDiff) > 4) {
  2494. lcd.setCursor(0, 2);
  2495. if (enc_dif < encoderDiff && yes) {
  2496. lcd_printPGM((PSTR(" ")));
  2497. lcd.setCursor(0, 3);
  2498. lcd_printPGM((PSTR(">")));
  2499. yes = false;
  2500. }
  2501. else if (enc_dif > encoderDiff && !yes) {
  2502. lcd_printPGM((PSTR(">")));
  2503. lcd.setCursor(0, 3);
  2504. lcd_printPGM((PSTR(" ")));
  2505. yes = true;
  2506. }
  2507. enc_dif = encoderDiff;
  2508. }
  2509. if (lcd_clicked()) {
  2510. while (lcd_clicked());
  2511. delay(10);
  2512. while (lcd_clicked());
  2513. KEEPALIVE_STATE(IN_HANDLER);
  2514. return yes;
  2515. }
  2516. }
  2517. }
  2518. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2519. {
  2520. const char *msg = NULL;
  2521. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2522. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  2523. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2524. if (point_too_far_mask == 0)
  2525. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  2526. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2527. // Only the center point or all the three front points.
  2528. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  2529. else if (point_too_far_mask & 1 == 0)
  2530. // The right and maybe the center point out of reach.
  2531. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  2532. else
  2533. // The left and maybe the center point out of reach.
  2534. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  2535. lcd_show_fullscreen_message_and_wait_P(msg);
  2536. } else {
  2537. if (point_too_far_mask != 0) {
  2538. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2539. // Only the center point or all the three front points.
  2540. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  2541. else if (point_too_far_mask & 1 == 0)
  2542. // The right and maybe the center point out of reach.
  2543. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  2544. else
  2545. // The left and maybe the center point out of reach.
  2546. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  2547. lcd_show_fullscreen_message_and_wait_P(msg);
  2548. }
  2549. if (point_too_far_mask == 0 || result > 0) {
  2550. switch (result) {
  2551. default:
  2552. // should not happen
  2553. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  2554. break;
  2555. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2556. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  2557. break;
  2558. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2559. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  2560. break;
  2561. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2562. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  2563. break;
  2564. }
  2565. lcd_show_fullscreen_message_and_wait_P(msg);
  2566. }
  2567. }
  2568. }
  2569. static void lcd_show_end_stops() {
  2570. lcd.setCursor(0, 0);
  2571. lcd_printPGM((PSTR("End stops diag")));
  2572. lcd.setCursor(0, 1);
  2573. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  2574. lcd.setCursor(0, 2);
  2575. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  2576. lcd.setCursor(0, 3);
  2577. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  2578. }
  2579. static void menu_show_end_stops() {
  2580. lcd_show_end_stops();
  2581. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  2582. }
  2583. // Lets the user move the Z carriage up to the end stoppers.
  2584. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2585. // Otherwise the Z calibration is not changed and false is returned.
  2586. void lcd_diag_show_end_stops()
  2587. {
  2588. int enc_dif = encoderDiff;
  2589. lcd_implementation_clear();
  2590. for (;;) {
  2591. manage_heater();
  2592. manage_inactivity(true);
  2593. lcd_show_end_stops();
  2594. if (lcd_clicked()) {
  2595. while (lcd_clicked()) ;
  2596. delay(10);
  2597. while (lcd_clicked()) ;
  2598. break;
  2599. }
  2600. }
  2601. lcd_implementation_clear();
  2602. lcd_return_to_status();
  2603. }
  2604. void prusa_statistics(int _message) {
  2605. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  2606. return;
  2607. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  2608. switch (_message)
  2609. {
  2610. case 0: // default message
  2611. if (IS_SD_PRINTING)
  2612. {
  2613. SERIAL_ECHO("{");
  2614. prusa_stat_printerstatus(4);
  2615. prusa_stat_farm_number();
  2616. prusa_stat_printinfo();
  2617. SERIAL_ECHOLN("}");
  2618. status_number = 4;
  2619. }
  2620. else
  2621. {
  2622. SERIAL_ECHO("{");
  2623. prusa_stat_printerstatus(1);
  2624. prusa_stat_farm_number();
  2625. SERIAL_ECHOLN("}");
  2626. status_number = 1;
  2627. }
  2628. break;
  2629. case 1: // 1 heating
  2630. farm_status = 2;
  2631. SERIAL_ECHO("{");
  2632. prusa_stat_printerstatus(2);
  2633. prusa_stat_farm_number();
  2634. SERIAL_ECHOLN("}");
  2635. status_number = 2;
  2636. farm_timer = 1;
  2637. break;
  2638. case 2: // heating done
  2639. farm_status = 3;
  2640. SERIAL_ECHO("{");
  2641. prusa_stat_printerstatus(3);
  2642. prusa_stat_farm_number();
  2643. SERIAL_ECHOLN("}");
  2644. status_number = 3;
  2645. farm_timer = 1;
  2646. if (IS_SD_PRINTING)
  2647. {
  2648. farm_status = 4;
  2649. SERIAL_ECHO("{");
  2650. prusa_stat_printerstatus(4);
  2651. prusa_stat_farm_number();
  2652. SERIAL_ECHOLN("}");
  2653. status_number = 4;
  2654. }
  2655. else
  2656. {
  2657. SERIAL_ECHO("{");
  2658. prusa_stat_printerstatus(3);
  2659. prusa_stat_farm_number();
  2660. SERIAL_ECHOLN("}");
  2661. status_number = 3;
  2662. }
  2663. farm_timer = 1;
  2664. break;
  2665. case 3: // filament change
  2666. break;
  2667. case 4: // print succesfull
  2668. SERIAL_ECHOLN("{[RES:1]");
  2669. prusa_stat_printerstatus(status_number);
  2670. prusa_stat_farm_number();
  2671. SERIAL_ECHOLN("}");
  2672. farm_timer = 2;
  2673. break;
  2674. case 5: // print not succesfull
  2675. SERIAL_ECHOLN("{[RES:0]");
  2676. prusa_stat_printerstatus(status_number);
  2677. prusa_stat_farm_number();
  2678. SERIAL_ECHOLN("}");
  2679. farm_timer = 2;
  2680. break;
  2681. case 6: // print done
  2682. SERIAL_ECHOLN("{[PRN:8]");
  2683. prusa_stat_farm_number();
  2684. SERIAL_ECHOLN("}");
  2685. status_number = 8;
  2686. farm_timer = 2;
  2687. break;
  2688. case 7: // print done - stopped
  2689. SERIAL_ECHOLN("{[PRN:9]");
  2690. prusa_stat_farm_number();
  2691. SERIAL_ECHOLN("}");
  2692. status_number = 9;
  2693. farm_timer = 2;
  2694. break;
  2695. case 8: // printer started
  2696. SERIAL_ECHO("{[PRN:0][PFN:");
  2697. status_number = 0;
  2698. SERIAL_ECHO(farm_no);
  2699. SERIAL_ECHOLN("]}");
  2700. farm_timer = 2;
  2701. break;
  2702. case 20: // echo farm no
  2703. SERIAL_ECHOLN("{");
  2704. prusa_stat_printerstatus(status_number);
  2705. prusa_stat_farm_number();
  2706. SERIAL_ECHOLN("}");
  2707. farm_timer = 5;
  2708. break;
  2709. case 21: // temperatures
  2710. SERIAL_ECHO("{");
  2711. prusa_stat_temperatures();
  2712. prusa_stat_farm_number();
  2713. prusa_stat_printerstatus(status_number);
  2714. SERIAL_ECHOLN("}");
  2715. break;
  2716. case 22: // waiting for filament change
  2717. SERIAL_ECHOLN("{[PRN:5]");
  2718. prusa_stat_farm_number();
  2719. SERIAL_ECHOLN("}");
  2720. status_number = 5;
  2721. break;
  2722. case 90: // Error - Thermal Runaway
  2723. SERIAL_ECHOLN("{[ERR:1]");
  2724. prusa_stat_farm_number();
  2725. SERIAL_ECHOLN("}");
  2726. break;
  2727. case 91: // Error - Thermal Runaway Preheat
  2728. SERIAL_ECHOLN("{[ERR:2]");
  2729. prusa_stat_farm_number();
  2730. SERIAL_ECHOLN("}");
  2731. break;
  2732. case 92: // Error - Min temp
  2733. SERIAL_ECHOLN("{[ERR:3]");
  2734. prusa_stat_farm_number();
  2735. SERIAL_ECHOLN("}");
  2736. break;
  2737. case 93: // Error - Max temp
  2738. SERIAL_ECHOLN("{[ERR:4]");
  2739. prusa_stat_farm_number();
  2740. SERIAL_ECHOLN("}");
  2741. break;
  2742. case 99: // heartbeat
  2743. SERIAL_ECHO("{[PRN:99]");
  2744. prusa_stat_temperatures();
  2745. SERIAL_ECHO("[PFN:");
  2746. SERIAL_ECHO(farm_no);
  2747. SERIAL_ECHO("]");
  2748. SERIAL_ECHOLN("}");
  2749. break;
  2750. }
  2751. }
  2752. static void prusa_stat_printerstatus(int _status)
  2753. {
  2754. SERIAL_ECHO("[PRN:");
  2755. SERIAL_ECHO(_status);
  2756. SERIAL_ECHO("]");
  2757. }
  2758. static void prusa_stat_farm_number() {
  2759. SERIAL_ECHO("[PFN:");
  2760. SERIAL_ECHO(farm_no);
  2761. SERIAL_ECHO("]");
  2762. }
  2763. static void prusa_stat_temperatures()
  2764. {
  2765. SERIAL_ECHO("[ST0:");
  2766. SERIAL_ECHO(target_temperature[0]);
  2767. SERIAL_ECHO("][STB:");
  2768. SERIAL_ECHO(target_temperature_bed);
  2769. SERIAL_ECHO("][AT0:");
  2770. SERIAL_ECHO(current_temperature[0]);
  2771. SERIAL_ECHO("][ATB:");
  2772. SERIAL_ECHO(current_temperature_bed);
  2773. SERIAL_ECHO("]");
  2774. }
  2775. static void prusa_stat_printinfo()
  2776. {
  2777. SERIAL_ECHO("[TFU:");
  2778. SERIAL_ECHO(total_filament_used);
  2779. SERIAL_ECHO("][PCD:");
  2780. SERIAL_ECHO(itostr3(card.percentDone()));
  2781. SERIAL_ECHO("][FEM:");
  2782. SERIAL_ECHO(itostr3(feedmultiply));
  2783. SERIAL_ECHO("][FNM:");
  2784. SERIAL_ECHO(longFilenameOLD);
  2785. SERIAL_ECHO("][TIM:");
  2786. if (starttime != 0)
  2787. {
  2788. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  2789. }
  2790. else
  2791. {
  2792. SERIAL_ECHO(0);
  2793. }
  2794. SERIAL_ECHO("][FWR:");
  2795. SERIAL_ECHO(FW_VERSION);
  2796. SERIAL_ECHO("]");
  2797. }
  2798. /*
  2799. void lcd_pick_babystep(){
  2800. int enc_dif = 0;
  2801. int cursor_pos = 1;
  2802. int fsm = 0;
  2803. lcd_implementation_clear();
  2804. lcd.setCursor(0, 0);
  2805. lcd_printPGM(MSG_PICK_Z);
  2806. lcd.setCursor(3, 2);
  2807. lcd.print("1");
  2808. lcd.setCursor(3, 3);
  2809. lcd.print("2");
  2810. lcd.setCursor(12, 2);
  2811. lcd.print("3");
  2812. lcd.setCursor(12, 3);
  2813. lcd.print("4");
  2814. lcd.setCursor(1, 2);
  2815. lcd.print(">");
  2816. enc_dif = encoderDiff;
  2817. while (fsm == 0) {
  2818. manage_heater();
  2819. manage_inactivity(true);
  2820. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2821. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2822. if (enc_dif > encoderDiff ) {
  2823. cursor_pos --;
  2824. }
  2825. if (enc_dif < encoderDiff ) {
  2826. cursor_pos ++;
  2827. }
  2828. if (cursor_pos > 4) {
  2829. cursor_pos = 4;
  2830. }
  2831. if (cursor_pos < 1) {
  2832. cursor_pos = 1;
  2833. }
  2834. lcd.setCursor(1, 2);
  2835. lcd.print(" ");
  2836. lcd.setCursor(1, 3);
  2837. lcd.print(" ");
  2838. lcd.setCursor(10, 2);
  2839. lcd.print(" ");
  2840. lcd.setCursor(10, 3);
  2841. lcd.print(" ");
  2842. if (cursor_pos < 3) {
  2843. lcd.setCursor(1, cursor_pos+1);
  2844. lcd.print(">");
  2845. }else{
  2846. lcd.setCursor(10, cursor_pos-1);
  2847. lcd.print(">");
  2848. }
  2849. enc_dif = encoderDiff;
  2850. delay(100);
  2851. }
  2852. }
  2853. if (lcd_clicked()) {
  2854. fsm = cursor_pos;
  2855. int babyStepZ;
  2856. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  2857. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  2858. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2859. delay(500);
  2860. }
  2861. };
  2862. lcd_implementation_clear();
  2863. lcd_return_to_status();
  2864. }
  2865. */
  2866. void lcd_move_menu_axis()
  2867. {
  2868. START_MENU();
  2869. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2870. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  2871. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  2872. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  2873. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  2874. END_MENU();
  2875. }
  2876. static void lcd_move_menu_1mm()
  2877. {
  2878. move_menu_scale = 1.0;
  2879. lcd_move_menu_axis();
  2880. }
  2881. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  2882. {
  2883. do
  2884. {
  2885. eeprom_write_byte((unsigned char*)pos, *value);
  2886. pos++;
  2887. value++;
  2888. } while (--size);
  2889. }
  2890. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  2891. {
  2892. do
  2893. {
  2894. *value = eeprom_read_byte((unsigned char*)pos);
  2895. pos++;
  2896. value++;
  2897. } while (--size);
  2898. }
  2899. #ifdef SDCARD_SORT_ALPHA
  2900. static void lcd_sort_type_set() {
  2901. uint8_t sdSort;
  2902. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  2903. switch (sdSort) {
  2904. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  2905. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  2906. default: sdSort = SD_SORT_TIME;
  2907. }
  2908. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  2909. presort_flag = true;
  2910. lcd_goto_menu(lcd_settings_menu, 8);
  2911. }
  2912. #endif //SDCARD_SORT_ALPHA
  2913. #ifdef TMC2130
  2914. static void lcd_crash_mode_info()
  2915. {
  2916. lcd_update_enable(true);
  2917. static uint32_t tim = 0;
  2918. if ((tim + 1000) < millis())
  2919. {
  2920. fputs_P(MSG_CRASH_DET_ONLY_IN_NORMAL, lcdout);
  2921. tim = millis();
  2922. }
  2923. if (lcd_clicked())
  2924. {
  2925. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 18);
  2926. else lcd_goto_menu(lcd_settings_menu, 16, true, true);
  2927. }
  2928. }
  2929. static void lcd_crash_mode_info2()
  2930. {
  2931. lcd_update_enable(true);
  2932. static uint32_t tim = 0;
  2933. if ((tim + 1000) < millis())
  2934. {
  2935. fputs_P(MSG_CRASH_DET_STEALTH_FORCE_OFF, lcdout);
  2936. tim = millis();
  2937. }
  2938. if (lcd_clicked())
  2939. {
  2940. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 16);
  2941. else lcd_goto_menu(lcd_settings_menu, 14, true, true);
  2942. }
  2943. }
  2944. #endif //TMC2130
  2945. #ifdef PAT9125
  2946. static void lcd_filament_autoload_info()
  2947. {
  2948. lcd_show_fullscreen_message_and_wait_P(MSG_AUTOLOADING_ONLY_IF_FSENS_ON);
  2949. }
  2950. static void lcd_fsensor_fail()
  2951. {
  2952. lcd_show_fullscreen_message_and_wait_P(MSG_FSENS_NOT_RESPONDING);
  2953. }
  2954. #endif //PAT9125
  2955. static void lcd_silent_mode_set() {
  2956. switch (SilentModeMenu) {
  2957. case 0: SilentModeMenu = 1; break;
  2958. case 1: SilentModeMenu = 2; break;
  2959. case 2: SilentModeMenu = 0; break;
  2960. default: SilentModeMenu = 0; break;
  2961. }
  2962. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  2963. #ifdef TMC2130
  2964. // Wait until the planner queue is drained and the stepper routine achieves
  2965. // an idle state.
  2966. st_synchronize();
  2967. if (tmc2130_wait_standstill_xy(1000)) {}
  2968. // MYSERIAL.print("standstill OK");
  2969. // else
  2970. // MYSERIAL.print("standstill NG!");
  2971. cli();
  2972. tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  2973. tmc2130_init();
  2974. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  2975. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  2976. st_reset_timer();
  2977. sei();
  2978. #endif //TMC2130
  2979. digipot_init();
  2980. #ifdef TMC2130
  2981. if (CrashDetectMenu && SilentModeMenu)
  2982. lcd_goto_menu(lcd_crash_mode_info2);
  2983. #endif //TMC2130
  2984. }
  2985. #ifdef TMC2130
  2986. static void lcd_crash_mode_set()
  2987. {
  2988. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  2989. if (CrashDetectMenu==0) {
  2990. crashdet_disable();
  2991. }else{
  2992. crashdet_enable();
  2993. }
  2994. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 9);
  2995. else lcd_goto_menu(lcd_settings_menu, 9);
  2996. }
  2997. #endif //TMC2130
  2998. static void lcd_set_lang(unsigned char lang) {
  2999. lang_selected = lang;
  3000. firstrun = 1;
  3001. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  3002. /*langsel=0;*/
  3003. if (langsel == LANGSEL_MODAL)
  3004. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  3005. langsel = LANGSEL_ACTIVE;
  3006. }
  3007. #ifdef PAT9125
  3008. static void lcd_fsensor_state_set()
  3009. {
  3010. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3011. if (FSensorStateMenu==0) {
  3012. fsensor_disable();
  3013. if ((filament_autoload_enabled == true)){
  3014. lcd_filament_autoload_info();
  3015. }
  3016. }else{
  3017. fsensor_enable();
  3018. if (fsensor_not_responding)
  3019. {
  3020. lcd_fsensor_fail();
  3021. }
  3022. }
  3023. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 7);
  3024. else lcd_goto_menu(lcd_settings_menu, 7); //doesn't break menuStack
  3025. }
  3026. #endif //PAT9125
  3027. #if !SDSORT_USES_RAM
  3028. void lcd_set_degree() {
  3029. lcd_set_custom_characters_degree();
  3030. }
  3031. void lcd_set_progress() {
  3032. lcd_set_custom_characters_progress();
  3033. }
  3034. #endif
  3035. void lcd_force_language_selection() {
  3036. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  3037. }
  3038. static void lcd_language_menu()
  3039. {
  3040. START_MENU();
  3041. if (langsel == LANGSEL_OFF) {
  3042. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  3043. } else if (langsel == LANGSEL_ACTIVE) {
  3044. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  3045. }
  3046. for (int i=0;i<LANG_NUM;i++){
  3047. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  3048. }
  3049. END_MENU();
  3050. }
  3051. void lcd_mesh_bedleveling()
  3052. {
  3053. mesh_bed_run_from_menu = true;
  3054. enquecommand_P(PSTR("G80"));
  3055. lcd_return_to_status();
  3056. }
  3057. void lcd_mesh_calibration()
  3058. {
  3059. enquecommand_P(PSTR("M45"));
  3060. lcd_return_to_status();
  3061. }
  3062. void lcd_mesh_calibration_z()
  3063. {
  3064. enquecommand_P(PSTR("M45 Z"));
  3065. lcd_return_to_status();
  3066. }
  3067. void lcd_pinda_calibration_menu()
  3068. {
  3069. START_MENU();
  3070. MENU_ITEM(back, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  3071. MENU_ITEM(submenu, MSG_CALIBRATE_PINDA, lcd_calibrate_pinda);
  3072. END_MENU();
  3073. }
  3074. void lcd_temp_calibration_set() {
  3075. temp_cal_active = !temp_cal_active;
  3076. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3077. digipot_init();
  3078. lcd_goto_menu(lcd_settings_menu, 10);
  3079. }
  3080. void lcd_second_serial_set() {
  3081. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3082. else selectedSerialPort = 1;
  3083. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3084. MYSERIAL.begin(BAUDRATE);
  3085. lcd_goto_menu(lcd_settings_menu, 11);
  3086. }
  3087. void lcd_calibrate_pinda() {
  3088. enquecommand_P(PSTR("G76"));
  3089. lcd_return_to_status();
  3090. }
  3091. #ifndef SNMM
  3092. /*void lcd_calibrate_extruder() {
  3093. if (degHotend0() > EXTRUDE_MINTEMP)
  3094. {
  3095. current_position[E_AXIS] = 0; //set initial position to zero
  3096. plan_set_e_position(current_position[E_AXIS]);
  3097. //long steps_start = st_get_position(E_AXIS);
  3098. long steps_final;
  3099. float e_steps_per_unit;
  3100. float feedrate = (180 / axis_steps_per_unit[E_AXIS]) * 1; //3 //initial automatic extrusion feedrate (depends on current value of axis_steps_per_unit to avoid too fast extrusion)
  3101. float e_shift_calibration = (axis_steps_per_unit[E_AXIS] > 180 ) ? ((180 / axis_steps_per_unit[E_AXIS]) * 70): 70; //length of initial automatic extrusion sequence
  3102. const char *msg_e_cal_knob = MSG_E_CAL_KNOB;
  3103. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3104. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3105. unsigned long msg_millis;
  3106. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  3107. lcd_implementation_clear();
  3108. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  3109. current_position[E_AXIS] += e_shift_calibration;
  3110. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3111. st_synchronize();
  3112. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3113. msg_millis = millis();
  3114. while (!LCD_CLICKED) {
  3115. if (multi_screen && millis() - msg_millis > 5000) {
  3116. if (msg_next_e_cal_knob == NULL)
  3117. msg_next_e_cal_knob = msg_e_cal_knob;
  3118. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3119. msg_millis = millis();
  3120. }
  3121. //manage_inactivity(true);
  3122. manage_heater();
  3123. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3124. delay_keep_alive(50);
  3125. //previous_millis_cmd = millis();
  3126. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3127. encoderDiff = 0;
  3128. if (!planner_queue_full()) {
  3129. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3130. encoderPosition = 0;
  3131. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3132. }
  3133. }
  3134. }
  3135. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3136. //steps_final = st_get_position(E_AXIS);
  3137. lcdDrawUpdate = 1;
  3138. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3139. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3140. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3141. lcd_implementation_clear();
  3142. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3143. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3144. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3145. //delay_keep_alive(2000);
  3146. delay_keep_alive(500);
  3147. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  3148. lcd_update_enable(true);
  3149. lcdDrawUpdate = 2;
  3150. }
  3151. else
  3152. {
  3153. lcd_implementation_clear();
  3154. lcd.setCursor(0, 0);
  3155. lcd_printPGM(MSG_ERROR);
  3156. lcd.setCursor(0, 2);
  3157. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  3158. delay(2000);
  3159. lcd_implementation_clear();
  3160. }
  3161. lcd_return_to_status();
  3162. }
  3163. void lcd_extr_cal_reset() {
  3164. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3165. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3166. //extrudemultiply = 100;
  3167. enquecommand_P(PSTR("M500"));
  3168. }*/
  3169. #endif
  3170. void lcd_toshiba_flash_air_compatibility_toggle()
  3171. {
  3172. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3173. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3174. }
  3175. void lcd_v2_calibration() {
  3176. bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_PLA_FILAMENT_LOADED, false, true);
  3177. if (loaded) {
  3178. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3179. }
  3180. else {
  3181. lcd_display_message_fullscreen_P(MSG_PLEASE_LOAD_PLA);
  3182. for (int i = 0; i < 20; i++) { //wait max. 2s
  3183. delay_keep_alive(100);
  3184. if (lcd_clicked()) {
  3185. while (lcd_clicked());
  3186. delay(10);
  3187. while (lcd_clicked());
  3188. break;
  3189. }
  3190. }
  3191. }
  3192. lcd_return_to_status();
  3193. lcd_update_enable(true);
  3194. }
  3195. void lcd_wizard() {
  3196. bool result = true;
  3197. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3198. result = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_RERUN, false, false);
  3199. }
  3200. if (result) {
  3201. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3202. lcd_wizard(0);
  3203. }
  3204. else {
  3205. lcd_return_to_status();
  3206. lcd_update_enable(true);
  3207. lcd_update(2);
  3208. }
  3209. }
  3210. void lcd_wizard(int state) {
  3211. bool end = false;
  3212. int wizard_event;
  3213. const char *msg = NULL;
  3214. while (!end) {
  3215. switch (state) {
  3216. case 0: // run wizard?
  3217. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_WELCOME, false, true);
  3218. if (wizard_event) {
  3219. state = 1;
  3220. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3221. }
  3222. else {
  3223. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3224. end = true;
  3225. }
  3226. break;
  3227. case 1: // restore calibration status
  3228. switch (calibration_status()) {
  3229. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3230. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3231. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3232. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3233. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3234. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3235. }
  3236. break;
  3237. case 2: //selftest
  3238. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_SELFTEST);
  3239. wizard_event = lcd_selftest();
  3240. if (wizard_event) {
  3241. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3242. state = 3;
  3243. }
  3244. else end = true;
  3245. break;
  3246. case 3: //xyz cal.
  3247. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_XYZ_CAL);
  3248. wizard_event = gcode_M45(false, 0);
  3249. if (wizard_event) state = 5;
  3250. else end = true;
  3251. break;
  3252. case 4: //z cal.
  3253. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_Z_CAL);
  3254. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_STEEL_SHEET_CHECK, false, false);
  3255. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(MSG_PLACE_STEEL_SHEET);
  3256. wizard_event = gcode_M45(true, 0);
  3257. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3258. else end = true;
  3259. break;
  3260. case 5: //is filament loaded?
  3261. //start to preheat nozzle and bed to save some time later
  3262. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3263. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3264. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_WIZARD_FILAMENT_LOADED, false);
  3265. if (wizard_event) state = 8;
  3266. else state = 6;
  3267. break;
  3268. case 6: //waiting for preheat nozzle for PLA;
  3269. #ifndef SNMM
  3270. lcd_display_message_fullscreen_P(MSG_WIZARD_WILL_PREHEAT);
  3271. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3272. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 60, active_extruder);
  3273. delay_keep_alive(2000);
  3274. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  3275. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3276. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  3277. lcd.setCursor(0, 4);
  3278. lcd.print(LCD_STR_THERMOMETER[0]);
  3279. lcd.print(ftostr3(degHotend(0)));
  3280. lcd.print("/");
  3281. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3282. lcd.print(LCD_STR_DEGREE);
  3283. lcd_set_custom_characters();
  3284. delay_keep_alive(1000);
  3285. }
  3286. #endif //not SNMM
  3287. state = 7;
  3288. break;
  3289. case 7: //load filament
  3290. #ifdef PAT9125
  3291. fsensor_block();
  3292. #endif //PAT9125
  3293. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_LOAD_FILAMENT);
  3294. lcd_update_enable(false);
  3295. lcd_implementation_clear();
  3296. lcd_print_at_PGM(0, 2, MSG_LOADING_FILAMENT);
  3297. #ifdef SNMM
  3298. change_extr(0);
  3299. #endif
  3300. gcode_M701();
  3301. #ifdef PAT9125
  3302. fsensor_unblock();
  3303. #endif //PAT9125
  3304. state = 9;
  3305. break;
  3306. case 8:
  3307. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_WIZARD_PLA_FILAMENT, false, true);
  3308. if (wizard_event) state = 9;
  3309. else end = true;
  3310. break;
  3311. case 9:
  3312. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_V2_CAL);
  3313. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_V2_CAL_2);
  3314. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3315. end = true;
  3316. break;
  3317. case 10: //repeat first layer cal.?
  3318. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_REPEAT_V2_CAL, false);
  3319. if (wizard_event) {
  3320. //reset status and live adjust z value in eeprom
  3321. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  3322. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_CLEAN_HEATBED);
  3323. state = 9;
  3324. }
  3325. else {
  3326. state = 11;
  3327. }
  3328. break;
  3329. case 11: //we are finished
  3330. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3331. end = true;
  3332. break;
  3333. default: break;
  3334. }
  3335. }
  3336. SERIAL_ECHOPGM("State: ");
  3337. MYSERIAL.println(state);
  3338. switch (state) { //final message
  3339. case 0: //user dont want to use wizard
  3340. msg = MSG_WIZARD_QUIT;
  3341. break;
  3342. case 1: //printer was already calibrated
  3343. msg = MSG_WIZARD_DONE;
  3344. break;
  3345. case 2: //selftest
  3346. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3347. break;
  3348. case 3: //xyz cal.
  3349. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3350. break;
  3351. case 4: //z cal.
  3352. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3353. break;
  3354. case 8:
  3355. msg = MSG_WIZARD_INSERT_CORRECT_FILAMENT;
  3356. break;
  3357. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3358. case 11: //we are finished
  3359. msg = MSG_WIZARD_DONE;
  3360. lcd_reset_alert_level();
  3361. lcd_setstatuspgm(WELCOME_MSG);
  3362. break;
  3363. default:
  3364. msg = MSG_WIZARD_QUIT;
  3365. break;
  3366. }
  3367. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3368. lcd_update_enable(true);
  3369. lcd_return_to_status();
  3370. lcd_update(2);
  3371. }
  3372. static void lcd_settings_menu()
  3373. {
  3374. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3375. START_MENU();
  3376. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3377. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  3378. if (!homing_flag)
  3379. {
  3380. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  3381. }
  3382. if (!isPrintPaused)
  3383. {
  3384. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  3385. }
  3386. if (!farm_mode) { //dont show in menu if we are in farm mode
  3387. switch (SilentModeMenu) {
  3388. case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  3389. case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
  3390. case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
  3391. default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  3392. }
  3393. }
  3394. #ifdef PAT9125
  3395. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3396. if (FSensorStateMenu == 0) {
  3397. if (fsensor_not_responding){
  3398. // Filament sensor not working
  3399. MENU_ITEM(function, MSG_FSENSOR_NA, lcd_fsensor_state_set);
  3400. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_NA, lcd_fsensor_fail);
  3401. }
  3402. else{
  3403. // Filament sensor turned off, working, no problems
  3404. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  3405. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_NA, lcd_filament_autoload_info);
  3406. }
  3407. } else {
  3408. // Filament sensor turned on, working, no problems
  3409. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  3410. if ((filament_autoload_enabled == true)) {
  3411. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_ON, lcd_set_filament_autoload);
  3412. }
  3413. else {
  3414. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_OFF, lcd_set_filament_autoload);
  3415. }
  3416. }
  3417. #endif //DEBUG_DISABLE_FSENSORCHECK
  3418. #endif //PAT9125
  3419. if (fans_check_enabled == true) {
  3420. MENU_ITEM(function, MSG_FANS_CHECK_ON, lcd_set_fan_check);
  3421. }
  3422. else {
  3423. MENU_ITEM(function, MSG_FANS_CHECK_OFF, lcd_set_fan_check);
  3424. }
  3425. #ifdef TMC2130
  3426. if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  3427. else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  3428. if (SilentModeMenu == 0)
  3429. {
  3430. if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  3431. else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  3432. }
  3433. else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
  3434. #endif //TMC2130
  3435. if (temp_cal_active == false) {
  3436. MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set);
  3437. }
  3438. else {
  3439. MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
  3440. }
  3441. #ifdef HAS_SECOND_SERIAL_PORT
  3442. if (selectedSerialPort == 0) {
  3443. MENU_ITEM(function, MSG_SECOND_SERIAL_OFF, lcd_second_serial_set);
  3444. }
  3445. else {
  3446. MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set);
  3447. }
  3448. #endif //HAS_SECOND_SERIAL
  3449. if (!isPrintPaused && !homing_flag)
  3450. {
  3451. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  3452. }
  3453. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  3454. if (card.ToshibaFlashAir_isEnabled()) {
  3455. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  3456. } else {
  3457. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  3458. }
  3459. #ifdef SDCARD_SORT_ALPHA
  3460. if (!farm_mode) {
  3461. uint8_t sdSort;
  3462. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3463. switch (sdSort) {
  3464. case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
  3465. case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
  3466. default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
  3467. }
  3468. }
  3469. #endif // SDCARD_SORT_ALPHA
  3470. if (farm_mode)
  3471. {
  3472. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3473. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3474. }
  3475. END_MENU();
  3476. }
  3477. static void lcd_selftest_()
  3478. {
  3479. lcd_selftest();
  3480. }
  3481. static void lcd_calibration_menu()
  3482. {
  3483. START_MENU();
  3484. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3485. if (!isPrintPaused)
  3486. {
  3487. MENU_ITEM(function, MSG_WIZARD, lcd_wizard);
  3488. MENU_ITEM(submenu, MSG_V2_CALIBRATION, lcd_v2_calibration);
  3489. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  3490. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest_v);
  3491. #ifdef MK1BP
  3492. // MK1
  3493. // "Calibrate Z"
  3494. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  3495. #else //MK1BP
  3496. // MK2
  3497. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  3498. // "Calibrate Z" with storing the reference values to EEPROM.
  3499. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  3500. #ifndef SNMM
  3501. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  3502. #endif
  3503. // "Mesh Bed Leveling"
  3504. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  3505. #endif //MK1BP
  3506. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  3507. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  3508. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  3509. #ifndef MK1BP
  3510. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  3511. #endif //MK1BP
  3512. #ifndef SNMM
  3513. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3514. #endif
  3515. #ifndef MK1BP
  3516. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  3517. #endif //MK1BP
  3518. }
  3519. END_MENU();
  3520. }
  3521. /*
  3522. void lcd_mylang_top(int hlaska) {
  3523. lcd.setCursor(0,0);
  3524. lcd.print(" ");
  3525. lcd.setCursor(0,0);
  3526. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  3527. }
  3528. void lcd_mylang_drawmenu(int cursor) {
  3529. int first = 0;
  3530. if (cursor>2) first = cursor-2;
  3531. if (cursor==LANG_NUM) first = LANG_NUM-3;
  3532. lcd.setCursor(0, 1);
  3533. lcd.print(" ");
  3534. lcd.setCursor(1, 1);
  3535. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  3536. lcd.setCursor(0, 2);
  3537. lcd.print(" ");
  3538. lcd.setCursor(1, 2);
  3539. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  3540. lcd.setCursor(0, 3);
  3541. lcd.print(" ");
  3542. lcd.setCursor(1, 3);
  3543. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  3544. if (cursor==1) lcd.setCursor(0, 1);
  3545. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3546. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3547. lcd.print(">");
  3548. if (cursor<LANG_NUM-1) {
  3549. lcd.setCursor(19,3);
  3550. lcd.print("\x01");
  3551. }
  3552. if (cursor>2) {
  3553. lcd.setCursor(19,1);
  3554. lcd.print("^");
  3555. }
  3556. }
  3557. */
  3558. void lcd_mylang_drawmenu(int cursor) {
  3559. int first = 0;
  3560. if (cursor>3) first = cursor-3;
  3561. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  3562. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  3563. lcd.setCursor(0, 0);
  3564. lcd.print(" ");
  3565. lcd.setCursor(1, 0);
  3566. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  3567. lcd.setCursor(0, 1);
  3568. lcd.print(" ");
  3569. lcd.setCursor(1, 1);
  3570. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  3571. lcd.setCursor(0, 2);
  3572. lcd.print(" ");
  3573. if (LANG_NUM > 2){
  3574. lcd.setCursor(1, 2);
  3575. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  3576. }
  3577. lcd.setCursor(0, 3);
  3578. lcd.print(" ");
  3579. if (LANG_NUM>3) {
  3580. lcd.setCursor(1, 3);
  3581. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  3582. }
  3583. if (cursor==1) lcd.setCursor(0, 0);
  3584. if (cursor==2) lcd.setCursor(0, 1);
  3585. if (cursor>2) lcd.setCursor(0, 2);
  3586. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  3587. lcd.print(">");
  3588. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  3589. lcd.setCursor(19,3);
  3590. lcd.print("\x01");
  3591. }
  3592. if (cursor>3 && LANG_NUM>4) {
  3593. lcd.setCursor(19,0);
  3594. lcd.print("^");
  3595. }
  3596. }
  3597. void lcd_mylang_drawcursor(int cursor) {
  3598. if (cursor==1) lcd.setCursor(0, 1);
  3599. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3600. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3601. lcd.print(">");
  3602. }
  3603. void lcd_mylang() {
  3604. int enc_dif = 0;
  3605. int cursor_pos = 1;
  3606. lang_selected=255;
  3607. int hlaska=1;
  3608. int counter=0;
  3609. lcd_set_custom_characters_arrows();
  3610. lcd_implementation_clear();
  3611. //lcd_mylang_top(hlaska);
  3612. lcd_mylang_drawmenu(cursor_pos);
  3613. enc_dif = encoderDiff;
  3614. while ( (lang_selected == 255) ) {
  3615. manage_heater();
  3616. manage_inactivity(true);
  3617. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  3618. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  3619. if (enc_dif > encoderDiff ) {
  3620. cursor_pos --;
  3621. }
  3622. if (enc_dif < encoderDiff ) {
  3623. cursor_pos ++;
  3624. }
  3625. if (cursor_pos > LANG_NUM) {
  3626. cursor_pos = LANG_NUM;
  3627. }
  3628. if (cursor_pos < 1) {
  3629. cursor_pos = 1;
  3630. }
  3631. lcd_mylang_drawmenu(cursor_pos);
  3632. enc_dif = encoderDiff;
  3633. delay(100);
  3634. //}
  3635. } else delay(20);
  3636. if (lcd_clicked()) {
  3637. lcd_set_lang(cursor_pos-1);
  3638. delay(500);
  3639. }
  3640. /*
  3641. if (++counter == 80) {
  3642. hlaska++;
  3643. if(hlaska>LANG_NUM) hlaska=1;
  3644. lcd_mylang_top(hlaska);
  3645. lcd_mylang_drawcursor(cursor_pos);
  3646. counter=0;
  3647. }
  3648. */
  3649. };
  3650. if(MYSERIAL.available() > 1){
  3651. lang_selected = 0;
  3652. firstrun = 0;
  3653. }
  3654. lcd_set_custom_characters_degree();
  3655. lcd_implementation_clear();
  3656. lcd_return_to_status();
  3657. }
  3658. void bowden_menu() {
  3659. int enc_dif = encoderDiff;
  3660. int cursor_pos = 0;
  3661. lcd_implementation_clear();
  3662. lcd.setCursor(0, 0);
  3663. lcd.print(">");
  3664. for (int i = 0; i < 4; i++) {
  3665. lcd.setCursor(1, i);
  3666. lcd.print("Extruder ");
  3667. lcd.print(i);
  3668. lcd.print(": ");
  3669. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3670. lcd.print(bowden_length[i] - 48);
  3671. }
  3672. enc_dif = encoderDiff;
  3673. while (1) {
  3674. manage_heater();
  3675. manage_inactivity(true);
  3676. if (abs((enc_dif - encoderDiff)) > 2) {
  3677. if (enc_dif > encoderDiff) {
  3678. cursor_pos--;
  3679. }
  3680. if (enc_dif < encoderDiff) {
  3681. cursor_pos++;
  3682. }
  3683. if (cursor_pos > 3) {
  3684. cursor_pos = 3;
  3685. }
  3686. if (cursor_pos < 0) {
  3687. cursor_pos = 0;
  3688. }
  3689. lcd.setCursor(0, 0);
  3690. lcd.print(" ");
  3691. lcd.setCursor(0, 1);
  3692. lcd.print(" ");
  3693. lcd.setCursor(0, 2);
  3694. lcd.print(" ");
  3695. lcd.setCursor(0, 3);
  3696. lcd.print(" ");
  3697. lcd.setCursor(0, cursor_pos);
  3698. lcd.print(">");
  3699. enc_dif = encoderDiff;
  3700. delay(100);
  3701. }
  3702. if (lcd_clicked()) {
  3703. while (lcd_clicked());
  3704. delay(10);
  3705. while (lcd_clicked());
  3706. lcd_implementation_clear();
  3707. while (1) {
  3708. manage_heater();
  3709. manage_inactivity(true);
  3710. lcd.setCursor(1, 1);
  3711. lcd.print("Extruder ");
  3712. lcd.print(cursor_pos);
  3713. lcd.print(": ");
  3714. lcd.setCursor(13, 1);
  3715. lcd.print(bowden_length[cursor_pos] - 48);
  3716. if (abs((enc_dif - encoderDiff)) > 2) {
  3717. if (enc_dif > encoderDiff) {
  3718. bowden_length[cursor_pos]--;
  3719. lcd.setCursor(13, 1);
  3720. lcd.print(bowden_length[cursor_pos] - 48);
  3721. enc_dif = encoderDiff;
  3722. }
  3723. if (enc_dif < encoderDiff) {
  3724. bowden_length[cursor_pos]++;
  3725. lcd.setCursor(13, 1);
  3726. lcd.print(bowden_length[cursor_pos] - 48);
  3727. enc_dif = encoderDiff;
  3728. }
  3729. }
  3730. delay(100);
  3731. if (lcd_clicked()) {
  3732. while (lcd_clicked());
  3733. delay(10);
  3734. while (lcd_clicked());
  3735. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  3736. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  3737. lcd_update_enable(true);
  3738. lcd_implementation_clear();
  3739. enc_dif = encoderDiff;
  3740. lcd.setCursor(0, cursor_pos);
  3741. lcd.print(">");
  3742. for (int i = 0; i < 4; i++) {
  3743. lcd.setCursor(1, i);
  3744. lcd.print("Extruder ");
  3745. lcd.print(i);
  3746. lcd.print(": ");
  3747. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3748. lcd.print(bowden_length[i] - 48);
  3749. }
  3750. break;
  3751. }
  3752. else return;
  3753. }
  3754. }
  3755. }
  3756. }
  3757. }
  3758. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  3759. lcd_implementation_clear();
  3760. lcd_print_at_PGM(0,0,MSG_UNLOAD_FILAMENT); lcd.print(":");
  3761. lcd.setCursor(0, 1); lcd.print(">");
  3762. lcd_print_at_PGM(1,1,MSG_ALL);
  3763. lcd_print_at_PGM(1,2,MSG_USED);
  3764. lcd_print_at_PGM(1,3,MSG_CURRENT);
  3765. char cursor_pos = 1;
  3766. int enc_dif = 0;
  3767. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3768. while (1) {
  3769. manage_heater();
  3770. manage_inactivity(true);
  3771. if (abs((enc_dif - encoderDiff)) > 4) {
  3772. if ((abs(enc_dif - encoderDiff)) > 1) {
  3773. if (enc_dif > encoderDiff) cursor_pos--;
  3774. if (enc_dif < encoderDiff) cursor_pos++;
  3775. if (cursor_pos > 3) cursor_pos = 3;
  3776. if (cursor_pos < 1) cursor_pos = 1;
  3777. lcd.setCursor(0, 1);
  3778. lcd.print(" ");
  3779. lcd.setCursor(0, 2);
  3780. lcd.print(" ");
  3781. lcd.setCursor(0, 3);
  3782. lcd.print(" ");
  3783. lcd.setCursor(0, cursor_pos);
  3784. lcd.print(">");
  3785. enc_dif = encoderDiff;
  3786. delay(100);
  3787. }
  3788. }
  3789. if (lcd_clicked()) {
  3790. while (lcd_clicked());
  3791. delay(10);
  3792. while (lcd_clicked());
  3793. KEEPALIVE_STATE(IN_HANDLER);
  3794. return(cursor_pos - 1);
  3795. }
  3796. }
  3797. }
  3798. char choose_extruder_menu() {
  3799. int items_no = 4;
  3800. int first = 0;
  3801. int enc_dif = 0;
  3802. char cursor_pos = 1;
  3803. enc_dif = encoderDiff;
  3804. lcd_implementation_clear();
  3805. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3806. lcd.setCursor(0, 1);
  3807. lcd.print(">");
  3808. for (int i = 0; i < 3; i++) {
  3809. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3810. }
  3811. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3812. while (1) {
  3813. for (int i = 0; i < 3; i++) {
  3814. lcd.setCursor(2 + strlen_P(MSG_EXTRUDER), i+1);
  3815. lcd.print(first + i + 1);
  3816. }
  3817. manage_heater();
  3818. manage_inactivity(true);
  3819. if (abs((enc_dif - encoderDiff)) > 4) {
  3820. if ((abs(enc_dif - encoderDiff)) > 1) {
  3821. if (enc_dif > encoderDiff) {
  3822. cursor_pos--;
  3823. }
  3824. if (enc_dif < encoderDiff) {
  3825. cursor_pos++;
  3826. }
  3827. if (cursor_pos > 3) {
  3828. cursor_pos = 3;
  3829. if (first < items_no - 3) {
  3830. first++;
  3831. lcd_implementation_clear();
  3832. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3833. for (int i = 0; i < 3; i++) {
  3834. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3835. }
  3836. }
  3837. }
  3838. if (cursor_pos < 1) {
  3839. cursor_pos = 1;
  3840. if (first > 0) {
  3841. first--;
  3842. lcd_implementation_clear();
  3843. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3844. for (int i = 0; i < 3; i++) {
  3845. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3846. }
  3847. }
  3848. }
  3849. lcd.setCursor(0, 1);
  3850. lcd.print(" ");
  3851. lcd.setCursor(0, 2);
  3852. lcd.print(" ");
  3853. lcd.setCursor(0, 3);
  3854. lcd.print(" ");
  3855. lcd.setCursor(0, cursor_pos);
  3856. lcd.print(">");
  3857. enc_dif = encoderDiff;
  3858. delay(100);
  3859. }
  3860. }
  3861. if (lcd_clicked()) {
  3862. lcd_update(2);
  3863. while (lcd_clicked());
  3864. delay(10);
  3865. while (lcd_clicked());
  3866. KEEPALIVE_STATE(IN_HANDLER);
  3867. return(cursor_pos + first - 1);
  3868. }
  3869. }
  3870. }
  3871. char reset_menu() {
  3872. #ifdef SNMM
  3873. int items_no = 5;
  3874. #else
  3875. int items_no = 4;
  3876. #endif
  3877. static int first = 0;
  3878. int enc_dif = 0;
  3879. char cursor_pos = 0;
  3880. const char *item [items_no];
  3881. item[0] = "Language";
  3882. item[1] = "Statistics";
  3883. item[2] = "Shipping prep";
  3884. item[3] = "All Data";
  3885. #ifdef SNMM
  3886. item[4] = "Bowden length";
  3887. #endif // SNMM
  3888. enc_dif = encoderDiff;
  3889. lcd_implementation_clear();
  3890. lcd.setCursor(0, 0);
  3891. lcd.print(">");
  3892. while (1) {
  3893. for (int i = 0; i < 4; i++) {
  3894. lcd.setCursor(1, i);
  3895. lcd.print(item[first + i]);
  3896. }
  3897. manage_heater();
  3898. manage_inactivity(true);
  3899. if (abs((enc_dif - encoderDiff)) > 4) {
  3900. if ((abs(enc_dif - encoderDiff)) > 1) {
  3901. if (enc_dif > encoderDiff) {
  3902. cursor_pos--;
  3903. }
  3904. if (enc_dif < encoderDiff) {
  3905. cursor_pos++;
  3906. }
  3907. if (cursor_pos > 3) {
  3908. cursor_pos = 3;
  3909. if (first < items_no - 4) {
  3910. first++;
  3911. lcd_implementation_clear();
  3912. }
  3913. }
  3914. if (cursor_pos < 0) {
  3915. cursor_pos = 0;
  3916. if (first > 0) {
  3917. first--;
  3918. lcd_implementation_clear();
  3919. }
  3920. }
  3921. lcd.setCursor(0, 0);
  3922. lcd.print(" ");
  3923. lcd.setCursor(0, 1);
  3924. lcd.print(" ");
  3925. lcd.setCursor(0, 2);
  3926. lcd.print(" ");
  3927. lcd.setCursor(0, 3);
  3928. lcd.print(" ");
  3929. lcd.setCursor(0, cursor_pos);
  3930. lcd.print(">");
  3931. enc_dif = encoderDiff;
  3932. delay(100);
  3933. }
  3934. }
  3935. if (lcd_clicked()) {
  3936. while (lcd_clicked());
  3937. delay(10);
  3938. while (lcd_clicked());
  3939. return(cursor_pos + first);
  3940. }
  3941. }
  3942. }
  3943. static void lcd_disable_farm_mode() {
  3944. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  3945. if (disable) {
  3946. enquecommand_P(PSTR("G99"));
  3947. lcd_return_to_status();
  3948. }
  3949. else {
  3950. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  3951. }
  3952. lcd_update_enable(true);
  3953. lcdDrawUpdate = 2;
  3954. }
  3955. static void lcd_ping_allert() {
  3956. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  3957. allert_timer = millis();
  3958. SET_OUTPUT(BEEPER);
  3959. for (int i = 0; i < 2; i++) {
  3960. WRITE(BEEPER, HIGH);
  3961. delay(50);
  3962. WRITE(BEEPER, LOW);
  3963. delay(100);
  3964. }
  3965. }
  3966. };
  3967. #ifdef SNMM
  3968. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  3969. set_extrude_min_temp(.0);
  3970. current_position[E_AXIS] += shift;
  3971. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  3972. set_extrude_min_temp(EXTRUDE_MINTEMP);
  3973. }
  3974. void change_extr(int extr) { //switches multiplexer for extruders
  3975. st_synchronize();
  3976. delay(100);
  3977. disable_e0();
  3978. disable_e1();
  3979. disable_e2();
  3980. #ifdef SNMM
  3981. snmm_extruder = extr;
  3982. #endif
  3983. pinMode(E_MUX0_PIN, OUTPUT);
  3984. pinMode(E_MUX1_PIN, OUTPUT);
  3985. pinMode(E_MUX2_PIN, OUTPUT);
  3986. switch (extr) {
  3987. case 1:
  3988. WRITE(E_MUX0_PIN, HIGH);
  3989. WRITE(E_MUX1_PIN, LOW);
  3990. WRITE(E_MUX2_PIN, LOW);
  3991. break;
  3992. case 2:
  3993. WRITE(E_MUX0_PIN, LOW);
  3994. WRITE(E_MUX1_PIN, HIGH);
  3995. WRITE(E_MUX2_PIN, LOW);
  3996. break;
  3997. case 3:
  3998. WRITE(E_MUX0_PIN, HIGH);
  3999. WRITE(E_MUX1_PIN, HIGH);
  4000. WRITE(E_MUX2_PIN, LOW);
  4001. break;
  4002. default:
  4003. WRITE(E_MUX0_PIN, LOW);
  4004. WRITE(E_MUX1_PIN, LOW);
  4005. WRITE(E_MUX2_PIN, LOW);
  4006. break;
  4007. }
  4008. delay(100);
  4009. }
  4010. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4011. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4012. }
  4013. void display_loading() {
  4014. switch (snmm_extruder) {
  4015. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4016. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4017. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4018. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4019. }
  4020. }
  4021. static void extr_adj(int extruder) //loading filament for SNMM
  4022. {
  4023. bool correct;
  4024. max_feedrate[E_AXIS] =80;
  4025. //max_feedrate[E_AXIS] = 50;
  4026. START:
  4027. lcd_implementation_clear();
  4028. lcd.setCursor(0, 0);
  4029. switch (extruder) {
  4030. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4031. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4032. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4033. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4034. }
  4035. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4036. do{
  4037. extr_mov(0.001,1000);
  4038. delay_keep_alive(2);
  4039. } while (!lcd_clicked());
  4040. //delay_keep_alive(500);
  4041. KEEPALIVE_STATE(IN_HANDLER);
  4042. st_synchronize();
  4043. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4044. //if (!correct) goto START;
  4045. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4046. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4047. extr_mov(bowden_length[extruder], 500);
  4048. lcd_implementation_clear();
  4049. lcd.setCursor(0, 0); lcd_printPGM(MSG_LOADING_FILAMENT);
  4050. if(strlen(MSG_LOADING_FILAMENT)>18) lcd.setCursor(0, 1);
  4051. else lcd.print(" ");
  4052. lcd.print(snmm_extruder + 1);
  4053. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4054. st_synchronize();
  4055. max_feedrate[E_AXIS] = 50;
  4056. lcd_update_enable(true);
  4057. lcd_return_to_status();
  4058. lcdDrawUpdate = 2;
  4059. }
  4060. void extr_unload() { //unloads filament
  4061. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4062. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4063. int8_t SilentMode;
  4064. if (degHotend0() > EXTRUDE_MINTEMP) {
  4065. lcd_implementation_clear();
  4066. lcd_display_message_fullscreen_P(PSTR(""));
  4067. max_feedrate[E_AXIS] = 50;
  4068. lcd.setCursor(0, 0); lcd_printPGM(MSG_UNLOADING_FILAMENT);
  4069. lcd.print(" ");
  4070. lcd.print(snmm_extruder + 1);
  4071. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4072. if (current_position[Z_AXIS] < 15) {
  4073. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4074. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4075. }
  4076. current_position[E_AXIS] += 10; //extrusion
  4077. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4078. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  4079. if (current_temperature[0] < 230) { //PLA & all other filaments
  4080. current_position[E_AXIS] += 5.4;
  4081. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4082. current_position[E_AXIS] += 3.2;
  4083. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4084. current_position[E_AXIS] += 3;
  4085. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4086. }
  4087. else { //ABS
  4088. current_position[E_AXIS] += 3.1;
  4089. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4090. current_position[E_AXIS] += 3.1;
  4091. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4092. current_position[E_AXIS] += 4;
  4093. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4094. /*current_position[X_AXIS] += 23; //delay
  4095. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4096. current_position[X_AXIS] -= 23; //delay
  4097. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4098. delay_keep_alive(4700);
  4099. }
  4100. max_feedrate[E_AXIS] = 80;
  4101. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4102. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4103. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4104. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4105. st_synchronize();
  4106. //digipot_init();
  4107. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  4108. else digipot_current(2, tmp_motor_loud[2]);
  4109. lcd_update_enable(true);
  4110. lcd_return_to_status();
  4111. max_feedrate[E_AXIS] = 50;
  4112. }
  4113. else {
  4114. lcd_implementation_clear();
  4115. lcd.setCursor(0, 0);
  4116. lcd_printPGM(MSG_ERROR);
  4117. lcd.setCursor(0, 2);
  4118. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4119. delay(2000);
  4120. lcd_implementation_clear();
  4121. }
  4122. lcd_return_to_status();
  4123. }
  4124. //wrapper functions for loading filament
  4125. static void extr_adj_0(){
  4126. change_extr(0);
  4127. extr_adj(0);
  4128. }
  4129. static void extr_adj_1() {
  4130. change_extr(1);
  4131. extr_adj(1);
  4132. }
  4133. static void extr_adj_2() {
  4134. change_extr(2);
  4135. extr_adj(2);
  4136. }
  4137. static void extr_adj_3() {
  4138. change_extr(3);
  4139. extr_adj(3);
  4140. }
  4141. static void load_all() {
  4142. for (int i = 0; i < 4; i++) {
  4143. change_extr(i);
  4144. extr_adj(i);
  4145. }
  4146. }
  4147. //wrapper functions for changing extruders
  4148. static void extr_change_0() {
  4149. change_extr(0);
  4150. lcd_return_to_status();
  4151. }
  4152. static void extr_change_1() {
  4153. change_extr(1);
  4154. lcd_return_to_status();
  4155. }
  4156. static void extr_change_2() {
  4157. change_extr(2);
  4158. lcd_return_to_status();
  4159. }
  4160. static void extr_change_3() {
  4161. change_extr(3);
  4162. lcd_return_to_status();
  4163. }
  4164. //wrapper functions for unloading filament
  4165. void extr_unload_all() {
  4166. if (degHotend0() > EXTRUDE_MINTEMP) {
  4167. for (int i = 0; i < 4; i++) {
  4168. change_extr(i);
  4169. extr_unload();
  4170. }
  4171. }
  4172. else {
  4173. lcd_implementation_clear();
  4174. lcd.setCursor(0, 0);
  4175. lcd_printPGM(MSG_ERROR);
  4176. lcd.setCursor(0, 2);
  4177. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4178. delay(2000);
  4179. lcd_implementation_clear();
  4180. lcd_return_to_status();
  4181. }
  4182. }
  4183. //unloading just used filament (for snmm)
  4184. void extr_unload_used() {
  4185. if (degHotend0() > EXTRUDE_MINTEMP) {
  4186. for (int i = 0; i < 4; i++) {
  4187. if (snmm_filaments_used & (1 << i)) {
  4188. change_extr(i);
  4189. extr_unload();
  4190. }
  4191. }
  4192. snmm_filaments_used = 0;
  4193. }
  4194. else {
  4195. lcd_implementation_clear();
  4196. lcd.setCursor(0, 0);
  4197. lcd_printPGM(MSG_ERROR);
  4198. lcd.setCursor(0, 2);
  4199. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4200. delay(2000);
  4201. lcd_implementation_clear();
  4202. lcd_return_to_status();
  4203. }
  4204. }
  4205. static void extr_unload_0() {
  4206. change_extr(0);
  4207. extr_unload();
  4208. }
  4209. static void extr_unload_1() {
  4210. change_extr(1);
  4211. extr_unload();
  4212. }
  4213. static void extr_unload_2() {
  4214. change_extr(2);
  4215. extr_unload();
  4216. }
  4217. static void extr_unload_3() {
  4218. change_extr(3);
  4219. extr_unload();
  4220. }
  4221. static void fil_load_menu()
  4222. {
  4223. START_MENU();
  4224. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4225. MENU_ITEM(function, MSG_LOAD_ALL, load_all);
  4226. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  4227. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  4228. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  4229. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  4230. END_MENU();
  4231. }
  4232. static void fil_unload_menu()
  4233. {
  4234. START_MENU();
  4235. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4236. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  4237. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  4238. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  4239. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  4240. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  4241. END_MENU();
  4242. }
  4243. static void change_extr_menu(){
  4244. START_MENU();
  4245. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4246. MENU_ITEM(function, MSG_EXTRUDER_1, extr_change_0);
  4247. MENU_ITEM(function, MSG_EXTRUDER_2, extr_change_1);
  4248. MENU_ITEM(function, MSG_EXTRUDER_3, extr_change_2);
  4249. MENU_ITEM(function, MSG_EXTRUDER_4, extr_change_3);
  4250. END_MENU();
  4251. }
  4252. #endif
  4253. static void lcd_farm_no()
  4254. {
  4255. char step = 0;
  4256. int enc_dif = 0;
  4257. int _farmno = farm_no;
  4258. int _ret = 0;
  4259. lcd_implementation_clear();
  4260. lcd.setCursor(0, 0);
  4261. lcd.print("Farm no");
  4262. do
  4263. {
  4264. if (abs((enc_dif - encoderDiff)) > 2) {
  4265. if (enc_dif > encoderDiff) {
  4266. switch (step) {
  4267. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4268. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4269. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4270. default: break;
  4271. }
  4272. }
  4273. if (enc_dif < encoderDiff) {
  4274. switch (step) {
  4275. case(0): if (_farmno < 900) _farmno += 100; break;
  4276. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4277. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4278. default: break;
  4279. }
  4280. }
  4281. enc_dif = 0;
  4282. encoderDiff = 0;
  4283. }
  4284. lcd.setCursor(0, 2);
  4285. if (_farmno < 100) lcd.print("0");
  4286. if (_farmno < 10) lcd.print("0");
  4287. lcd.print(_farmno);
  4288. lcd.print(" ");
  4289. lcd.setCursor(0, 3);
  4290. lcd.print(" ");
  4291. lcd.setCursor(step, 3);
  4292. lcd.print("^");
  4293. delay(100);
  4294. if (lcd_clicked())
  4295. {
  4296. delay(200);
  4297. step++;
  4298. if(step == 3) {
  4299. _ret = 1;
  4300. farm_no = _farmno;
  4301. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4302. prusa_statistics(20);
  4303. lcd_return_to_status();
  4304. }
  4305. }
  4306. manage_heater();
  4307. } while (_ret == 0);
  4308. }
  4309. void lcd_confirm_print()
  4310. {
  4311. int enc_dif = 0;
  4312. int cursor_pos = 1;
  4313. int _ret = 0;
  4314. int _t = 0;
  4315. lcd_implementation_clear();
  4316. lcd.setCursor(0, 0);
  4317. lcd.print("Print ok ?");
  4318. do
  4319. {
  4320. if (abs((enc_dif - encoderDiff)) > 2) {
  4321. if (enc_dif > encoderDiff) {
  4322. cursor_pos--;
  4323. }
  4324. if (enc_dif < encoderDiff) {
  4325. cursor_pos++;
  4326. }
  4327. }
  4328. if (cursor_pos > 2) { cursor_pos = 2; }
  4329. if (cursor_pos < 1) { cursor_pos = 1; }
  4330. lcd.setCursor(0, 2); lcd.print(" ");
  4331. lcd.setCursor(0, 3); lcd.print(" ");
  4332. lcd.setCursor(2, 2);
  4333. lcd_printPGM(MSG_YES);
  4334. lcd.setCursor(2, 3);
  4335. lcd_printPGM(MSG_NO);
  4336. lcd.setCursor(0, 1 + cursor_pos);
  4337. lcd.print(">");
  4338. delay(100);
  4339. _t = _t + 1;
  4340. if (_t>100)
  4341. {
  4342. prusa_statistics(99);
  4343. _t = 0;
  4344. }
  4345. if (lcd_clicked())
  4346. {
  4347. if (cursor_pos == 1)
  4348. {
  4349. _ret = 1;
  4350. prusa_statistics(20);
  4351. prusa_statistics(4);
  4352. }
  4353. if (cursor_pos == 2)
  4354. {
  4355. _ret = 2;
  4356. prusa_statistics(20);
  4357. prusa_statistics(5);
  4358. }
  4359. }
  4360. manage_heater();
  4361. manage_inactivity();
  4362. } while (_ret == 0);
  4363. }
  4364. extern bool saved_printing;
  4365. static void lcd_main_menu()
  4366. {
  4367. SDscrool = 0;
  4368. START_MENU();
  4369. // Majkl superawesome menu
  4370. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  4371. #ifdef RESUME_DEBUG
  4372. if (!saved_printing)
  4373. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  4374. else
  4375. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  4376. #endif //RESUME_DEBUG
  4377. #ifdef TMC2130_DEBUG
  4378. MENU_ITEM(function, PSTR("recover print"), recover_print);
  4379. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  4380. #endif //TMC2130_DEBUG
  4381. /* if (farm_mode && !IS_SD_PRINTING )
  4382. {
  4383. int tempScrool = 0;
  4384. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4385. //delay(100);
  4386. return; // nothing to do (so don't thrash the SD card)
  4387. uint16_t fileCnt = card.getnrfilenames();
  4388. card.getWorkDirName();
  4389. if (card.filename[0] == '/')
  4390. {
  4391. #if SDCARDDETECT == -1
  4392. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4393. #endif
  4394. } else {
  4395. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4396. }
  4397. for (uint16_t i = 0; i < fileCnt; i++)
  4398. {
  4399. if (_menuItemNr == _lineNr)
  4400. {
  4401. #ifndef SDCARD_RATHERRECENTFIRST
  4402. card.getfilename(i);
  4403. #else
  4404. card.getfilename(fileCnt - 1 - i);
  4405. #endif
  4406. if (card.filenameIsDir)
  4407. {
  4408. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4409. } else {
  4410. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4411. }
  4412. } else {
  4413. MENU_ITEM_DUMMY();
  4414. }
  4415. }
  4416. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  4417. }*/
  4418. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  4419. {
  4420. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  4421. }
  4422. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4423. {
  4424. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  4425. } else
  4426. {
  4427. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  4428. }
  4429. #ifdef SDSUPPORT
  4430. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4431. {
  4432. if (card.isFileOpen())
  4433. {
  4434. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4435. if (card.sdprinting)
  4436. {
  4437. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  4438. }
  4439. else
  4440. {
  4441. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  4442. }
  4443. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4444. }
  4445. }
  4446. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4447. //MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4448. }
  4449. else
  4450. {
  4451. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4452. {
  4453. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4454. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  4455. }
  4456. #if SDCARDDETECT < 1
  4457. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  4458. #endif
  4459. }
  4460. } else
  4461. {
  4462. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  4463. #if SDCARDDETECT < 1
  4464. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  4465. #endif
  4466. }
  4467. #endif
  4468. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4469. {
  4470. if (farm_mode)
  4471. {
  4472. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  4473. }
  4474. }
  4475. else
  4476. {
  4477. #ifndef SNMM
  4478. #ifdef PAT9125
  4479. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4480. MENU_ITEM(function, MSG_AUTOLOAD_FILAMENT, lcd_LoadFilament);
  4481. else
  4482. #endif //PAT9125
  4483. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  4484. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  4485. #endif
  4486. #ifdef SNMM
  4487. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  4488. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  4489. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  4490. #endif
  4491. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  4492. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  4493. }
  4494. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4495. {
  4496. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  4497. }
  4498. #if defined(TMC2130) || defined(PAT9125)
  4499. MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats);
  4500. #endif
  4501. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  4502. END_MENU();
  4503. }
  4504. void stack_error() {
  4505. SET_OUTPUT(BEEPER);
  4506. WRITE(BEEPER, HIGH);
  4507. delay(1000);
  4508. WRITE(BEEPER, LOW);
  4509. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  4510. //err_triggered = 1;
  4511. while (1) delay_keep_alive(1000);
  4512. }
  4513. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4514. bool stepper_timer_overflow_state = false;
  4515. void stepper_timer_overflow() {
  4516. SET_OUTPUT(BEEPER);
  4517. WRITE(BEEPER, HIGH);
  4518. delay(1000);
  4519. WRITE(BEEPER, LOW);
  4520. lcd_display_message_fullscreen_P(MSG_STEPPER_TIMER_OVERFLOW_ERROR);
  4521. //err_triggered = 1;
  4522. while (1) delay_keep_alive(1000);
  4523. }
  4524. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4525. #ifdef SDSUPPORT
  4526. static void lcd_autostart_sd()
  4527. {
  4528. card.lastnr = 0;
  4529. card.setroot();
  4530. card.checkautostart(true);
  4531. }
  4532. #endif
  4533. static void lcd_silent_mode_set_tune() {
  4534. switch (SilentModeMenu) {
  4535. case 0: SilentModeMenu = 1; break;
  4536. case 1: SilentModeMenu = 2; break;
  4537. case 2: SilentModeMenu = 0; break;
  4538. default: SilentModeMenu = 0; break;
  4539. }
  4540. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  4541. digipot_init();
  4542. lcd_goto_menu(lcd_tune_menu, 9);
  4543. }
  4544. static void lcd_colorprint_change() {
  4545. enquecommand_P(PSTR("M600"));
  4546. custom_message = true;
  4547. custom_message_type = 2; //just print status message
  4548. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  4549. lcd_return_to_status();
  4550. lcdDrawUpdate = 3;
  4551. }
  4552. static void lcd_tune_menu()
  4553. {
  4554. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4555. START_MENU();
  4556. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  4557. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  4558. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4559. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4560. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  4561. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  4562. #ifdef FILAMENTCHANGEENABLE
  4563. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
  4564. #endif
  4565. #ifndef DEBUG_DISABLE_FSENSORCHECK
  4566. if (FSensorStateMenu == 0) {
  4567. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  4568. }
  4569. else {
  4570. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  4571. }
  4572. #endif //DEBUG_DISABLE_FSENSORCHECK
  4573. #ifdef TMC2130
  4574. if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  4575. else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  4576. if (SilentModeMenu == 0)
  4577. {
  4578. if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  4579. else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  4580. }
  4581. else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
  4582. #else //TMC2130
  4583. if (!farm_mode) { //dont show in menu if we are in farm mode
  4584. switch (SilentModeMenu) {
  4585. case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  4586. case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
  4587. case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
  4588. default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  4589. }
  4590. }
  4591. #endif //TMC2130
  4592. END_MENU();
  4593. }
  4594. static void lcd_move_menu_01mm()
  4595. {
  4596. move_menu_scale = 0.1;
  4597. lcd_move_menu_axis();
  4598. }
  4599. static void lcd_control_temperature_menu()
  4600. {
  4601. #ifdef PIDTEMP
  4602. // set up temp variables - undo the default scaling
  4603. // raw_Ki = unscalePID_i(Ki);
  4604. // raw_Kd = unscalePID_d(Kd);
  4605. #endif
  4606. START_MENU();
  4607. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  4608. #if TEMP_SENSOR_0 != 0
  4609. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  4610. #endif
  4611. #if TEMP_SENSOR_1 != 0
  4612. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  4613. #endif
  4614. #if TEMP_SENSOR_2 != 0
  4615. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  4616. #endif
  4617. #if TEMP_SENSOR_BED != 0
  4618. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  4619. #endif
  4620. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  4621. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  4622. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  4623. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  4624. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  4625. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  4626. #endif
  4627. END_MENU();
  4628. }
  4629. #if SDCARDDETECT == -1
  4630. static void lcd_sd_refresh()
  4631. {
  4632. card.initsd();
  4633. currentMenuViewOffset = 0;
  4634. }
  4635. #endif
  4636. static void lcd_sd_updir()
  4637. {
  4638. SDscrool = 0;
  4639. card.updir();
  4640. currentMenuViewOffset = 0;
  4641. }
  4642. void lcd_print_stop() {
  4643. cancel_heatup = true;
  4644. #ifdef MESH_BED_LEVELING
  4645. mbl.active = false;
  4646. #endif
  4647. // Stop the stoppers, update the position from the stoppers.
  4648. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4649. planner_abort_hard();
  4650. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  4651. // Z baystep is no more applied. Reset it.
  4652. babystep_reset();
  4653. }
  4654. // Clean the input command queue.
  4655. cmdqueue_reset();
  4656. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  4657. lcd_update(2);
  4658. card.sdprinting = false;
  4659. card.closefile();
  4660. stoptime = millis();
  4661. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  4662. pause_time = 0;
  4663. save_statistics(total_filament_used, t);
  4664. lcd_return_to_status();
  4665. lcd_ignore_click(true);
  4666. lcd_commands_step = 0;
  4667. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  4668. // Turn off the print fan
  4669. SET_OUTPUT(FAN_PIN);
  4670. WRITE(FAN_PIN, 0);
  4671. fanSpeed = 0;
  4672. }
  4673. void lcd_sdcard_stop()
  4674. {
  4675. lcd.setCursor(0, 0);
  4676. lcd_printPGM(MSG_STOP_PRINT);
  4677. lcd.setCursor(2, 2);
  4678. lcd_printPGM(MSG_NO);
  4679. lcd.setCursor(2, 3);
  4680. lcd_printPGM(MSG_YES);
  4681. lcd.setCursor(0, 2); lcd.print(" ");
  4682. lcd.setCursor(0, 3); lcd.print(" ");
  4683. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  4684. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  4685. lcd.setCursor(0, 1 + encoderPosition);
  4686. lcd.print(">");
  4687. if (lcd_clicked())
  4688. {
  4689. if ((int32_t)encoderPosition == 1)
  4690. {
  4691. lcd_return_to_status();
  4692. }
  4693. if ((int32_t)encoderPosition == 2)
  4694. {
  4695. lcd_print_stop();
  4696. }
  4697. }
  4698. }
  4699. /*
  4700. void getFileDescription(char *name, char *description) {
  4701. // get file description, ie the REAL filenam, ie the second line
  4702. card.openFile(name, true);
  4703. int i = 0;
  4704. // skip the first line (which is the version line)
  4705. while (true) {
  4706. uint16_t readByte = card.get();
  4707. if (readByte == '\n') {
  4708. break;
  4709. }
  4710. }
  4711. // read the second line (which is the description line)
  4712. while (true) {
  4713. uint16_t readByte = card.get();
  4714. if (i == 0) {
  4715. // skip the first '^'
  4716. readByte = card.get();
  4717. }
  4718. description[i] = readByte;
  4719. i++;
  4720. if (readByte == '\n') {
  4721. break;
  4722. }
  4723. }
  4724. card.closefile();
  4725. description[i-1] = 0;
  4726. }
  4727. */
  4728. void lcd_sdcard_menu()
  4729. {
  4730. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  4731. int tempScrool = 0;
  4732. if (presort_flag == true) {
  4733. presort_flag = false;
  4734. card.presort();
  4735. }
  4736. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4737. //delay(100);
  4738. return; // nothing to do (so don't thrash the SD card)
  4739. uint16_t fileCnt = card.getnrfilenames();
  4740. START_MENU();
  4741. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4742. card.getWorkDirName();
  4743. if (card.filename[0] == '/')
  4744. {
  4745. #if SDCARDDETECT == -1
  4746. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4747. #endif
  4748. } else {
  4749. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4750. }
  4751. for (uint16_t i = 0; i < fileCnt; i++)
  4752. {
  4753. if (_menuItemNr == _lineNr)
  4754. {
  4755. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  4756. /*#ifdef SDCARD_RATHERRECENTFIRST
  4757. #ifndef SDCARD_SORT_ALPHA
  4758. fileCnt - 1 -
  4759. #endif
  4760. #endif
  4761. i;*/
  4762. #ifdef SDCARD_SORT_ALPHA
  4763. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  4764. else card.getfilename_sorted(nr);
  4765. #else
  4766. card.getfilename(nr);
  4767. #endif
  4768. if (card.filenameIsDir)
  4769. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4770. else
  4771. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4772. } else {
  4773. MENU_ITEM_DUMMY();
  4774. }
  4775. }
  4776. END_MENU();
  4777. }
  4778. //char description [10] [31];
  4779. /*void get_description() {
  4780. uint16_t fileCnt = card.getnrfilenames();
  4781. for (uint16_t i = 0; i < fileCnt; i++)
  4782. {
  4783. card.getfilename(fileCnt - 1 - i);
  4784. getFileDescription(card.filename, description[i]);
  4785. }
  4786. }*/
  4787. /*void lcd_farm_sdcard_menu()
  4788. {
  4789. static int i = 0;
  4790. if (i == 0) {
  4791. get_description();
  4792. i++;
  4793. }
  4794. //int j;
  4795. //char description[31];
  4796. int tempScrool = 0;
  4797. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4798. //delay(100);
  4799. return; // nothing to do (so don't thrash the SD card)
  4800. uint16_t fileCnt = card.getnrfilenames();
  4801. START_MENU();
  4802. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4803. card.getWorkDirName();
  4804. if (card.filename[0] == '/')
  4805. {
  4806. #if SDCARDDETECT == -1
  4807. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4808. #endif
  4809. }
  4810. else {
  4811. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4812. }
  4813. for (uint16_t i = 0; i < fileCnt; i++)
  4814. {
  4815. if (_menuItemNr == _lineNr)
  4816. {
  4817. #ifndef SDCARD_RATHERRECENTFIRST
  4818. card.getfilename(i);
  4819. #else
  4820. card.getfilename(fileCnt - 1 - i);
  4821. #endif
  4822. if (card.filenameIsDir)
  4823. {
  4824. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4825. }
  4826. else {
  4827. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  4828. }
  4829. }
  4830. else {
  4831. MENU_ITEM_DUMMY();
  4832. }
  4833. }
  4834. END_MENU();
  4835. }*/
  4836. #define menu_edit_type(_type, _name, _strFunc, scale) \
  4837. void menu_edit_ ## _name () \
  4838. { \
  4839. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  4840. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  4841. if (lcdDrawUpdate) \
  4842. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  4843. if (LCD_CLICKED) \
  4844. { \
  4845. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  4846. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  4847. } \
  4848. } \
  4849. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  4850. { \
  4851. asm("cli"); \
  4852. menuData.editMenuParentState.prevMenu = currentMenu; \
  4853. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4854. asm("sei"); \
  4855. \
  4856. lcdDrawUpdate = 2; \
  4857. menuData.editMenuParentState.editLabel = pstr; \
  4858. menuData.editMenuParentState.editValue = ptr; \
  4859. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4860. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4861. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4862. \
  4863. }\
  4864. /*
  4865. void menu_edit_callback_ ## _name () { \
  4866. menu_edit_ ## _name (); \
  4867. if (LCD_CLICKED) (*callbackFunc)(); \
  4868. } \
  4869. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  4870. { \
  4871. menuData.editMenuParentState.prevMenu = currentMenu; \
  4872. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4873. \
  4874. lcdDrawUpdate = 2; \
  4875. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4876. \
  4877. menuData.editMenuParentState.editLabel = pstr; \
  4878. menuData.editMenuParentState.editValue = ptr; \
  4879. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4880. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4881. callbackFunc = callback;\
  4882. }
  4883. */
  4884. menu_edit_type(int, int3, itostr3, 1)
  4885. menu_edit_type(float, float3, ftostr3, 1)
  4886. menu_edit_type(float, float32, ftostr32, 100)
  4887. menu_edit_type(float, float43, ftostr43, 1000)
  4888. menu_edit_type(float, float5, ftostr5, 0.01)
  4889. menu_edit_type(float, float51, ftostr51, 10)
  4890. menu_edit_type(float, float52, ftostr52, 100)
  4891. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  4892. static void lcd_selftest_v()
  4893. {
  4894. (void)lcd_selftest();
  4895. }
  4896. static bool lcd_selftest()
  4897. {
  4898. int _progress = 0;
  4899. bool _result = false;
  4900. lcd_wait_for_cool_down();
  4901. lcd_implementation_clear();
  4902. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  4903. #ifdef TMC2130
  4904. FORCE_HIGH_POWER_START;
  4905. #endif // TMC2130
  4906. delay(2000);
  4907. KEEPALIVE_STATE(IN_HANDLER);
  4908. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  4909. #if (defined(FANCHECK) && defined(TACH_0))
  4910. _result = lcd_selftest_fan_dialog(0);
  4911. #else //defined(TACH_0)
  4912. _result = lcd_selftest_manual_fan_check(0, false);
  4913. #endif //defined(TACH_0)
  4914. if (_result)
  4915. {
  4916. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  4917. #if (defined(FANCHECK) && defined(TACH_1))
  4918. _result = lcd_selftest_fan_dialog(1);
  4919. #else //defined(TACH_1)
  4920. _result = lcd_selftest_manual_fan_check(1, false);
  4921. #endif //defined(TACH_1)
  4922. }
  4923. if (_result)
  4924. {
  4925. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  4926. #ifndef TMC2130
  4927. _result = lcd_selfcheck_endstops();
  4928. #else
  4929. _result = true;
  4930. #endif
  4931. }
  4932. if (_result)
  4933. {
  4934. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  4935. _result = lcd_selfcheck_check_heater(false);
  4936. }
  4937. if (_result)
  4938. {
  4939. //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
  4940. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  4941. #ifdef TMC2130
  4942. _result = lcd_selfcheck_axis_sg(X_AXIS);
  4943. #else
  4944. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  4945. #endif //TMC2130
  4946. }
  4947. if (_result)
  4948. {
  4949. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  4950. #ifndef TMC2130
  4951. _result = lcd_selfcheck_pulleys(X_AXIS);
  4952. #endif
  4953. }
  4954. if (_result)
  4955. {
  4956. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  4957. #ifdef TMC2130
  4958. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  4959. #else
  4960. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  4961. #endif // TMC2130
  4962. }
  4963. if (_result)
  4964. {
  4965. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  4966. #ifndef TMC2130
  4967. _result = lcd_selfcheck_pulleys(Y_AXIS);
  4968. #endif // TMC2130
  4969. }
  4970. if (_result)
  4971. {
  4972. #ifdef TMC2130
  4973. tmc2130_home_exit();
  4974. enable_endstops(false);
  4975. #endif
  4976. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  4977. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  4978. //homeaxis(X_AXIS);
  4979. //homeaxis(Y_AXIS);
  4980. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  4981. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  4982. st_synchronize();
  4983. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  4984. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  4985. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  4986. enquecommand_P(PSTR("G28 W"));
  4987. enquecommand_P(PSTR("G1 Z15"));
  4988. }
  4989. }
  4990. if (_result)
  4991. {
  4992. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  4993. _result = lcd_selfcheck_check_heater(true);
  4994. }
  4995. if (_result)
  4996. {
  4997. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  4998. #ifdef PAT9125
  4999. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5000. _result = lcd_selftest_fsensor();
  5001. #endif // PAT9125
  5002. }
  5003. if (_result)
  5004. {
  5005. #ifdef PAT9125
  5006. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5007. #endif // PAT9125
  5008. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5009. }
  5010. else
  5011. {
  5012. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5013. }
  5014. lcd_reset_alert_level();
  5015. enquecommand_P(PSTR("M84"));
  5016. lcd_implementation_clear();
  5017. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5018. if (_result)
  5019. {
  5020. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  5021. }
  5022. else
  5023. {
  5024. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5025. }
  5026. #ifdef TMC2130
  5027. FORCE_HIGH_POWER_END;
  5028. #endif // TMC2130
  5029. KEEPALIVE_STATE(NOT_BUSY);
  5030. return(_result);
  5031. }
  5032. #ifdef TMC2130
  5033. static void reset_crash_det(char axis) {
  5034. current_position[axis] += 10;
  5035. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5036. st_synchronize();
  5037. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5038. }
  5039. static bool lcd_selfcheck_axis_sg(char axis) {
  5040. // each axis length is measured twice
  5041. float axis_length, current_position_init, current_position_final;
  5042. float measured_axis_length[2];
  5043. float margin = 60;
  5044. float max_error_mm = 5;
  5045. switch (axis) {
  5046. case 0: axis_length = X_MAX_POS; break;
  5047. case 1: axis_length = Y_MAX_POS + 8; break;
  5048. default: axis_length = 210; break;
  5049. }
  5050. tmc2130_sg_stop_on_crash = false;
  5051. tmc2130_home_exit();
  5052. enable_endstops(true);
  5053. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5054. current_position[Z_AXIS] += 17;
  5055. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5056. tmc2130_home_enter(Z_AXIS_MASK);
  5057. st_synchronize();
  5058. tmc2130_home_exit();
  5059. }
  5060. // first axis length measurement begin
  5061. tmc2130_home_enter(X_AXIS_MASK << axis);
  5062. current_position[axis] -= (axis_length + margin);
  5063. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5064. st_synchronize();
  5065. tmc2130_home_exit();
  5066. tmc2130_sg_meassure_start(axis);
  5067. current_position_init = st_get_position_mm(axis);
  5068. current_position[axis] += 2 * margin;
  5069. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5070. st_synchronize();
  5071. current_position[axis] += axis_length;
  5072. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5073. tmc2130_home_enter(X_AXIS_MASK << axis);
  5074. st_synchronize();
  5075. tmc2130_home_exit();
  5076. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5077. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5078. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5079. current_position_final = st_get_position_mm(axis);
  5080. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5081. // first measurement end and second measurement begin
  5082. current_position[axis] -= margin;
  5083. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5084. st_synchronize();
  5085. tmc2130_home_enter(X_AXIS_MASK << axis);
  5086. current_position[axis] -= (axis_length + margin);
  5087. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5088. st_synchronize();
  5089. tmc2130_home_exit();
  5090. current_position_init = st_get_position_mm(axis);
  5091. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5092. //end of second measurement, now check for possible errors:
  5093. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5094. SERIAL_ECHOPGM("Measured axis length:");
  5095. MYSERIAL.println(measured_axis_length[i]);
  5096. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5097. enable_endstops(false);
  5098. const char *_error_1;
  5099. const char *_error_2;
  5100. if (axis == X_AXIS) _error_1 = "X";
  5101. if (axis == Y_AXIS) _error_1 = "Y";
  5102. if (axis == Z_AXIS) _error_1 = "Z";
  5103. lcd_selftest_error(9, _error_1, _error_2);
  5104. current_position[axis] = 0;
  5105. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5106. reset_crash_det(axis);
  5107. return false;
  5108. }
  5109. }
  5110. SERIAL_ECHOPGM("Axis length difference:");
  5111. MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1]));
  5112. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5113. //loose pulleys
  5114. const char *_error_1;
  5115. const char *_error_2;
  5116. if (axis == X_AXIS) _error_1 = "X";
  5117. if (axis == Y_AXIS) _error_1 = "Y";
  5118. if (axis == Z_AXIS) _error_1 = "Z";
  5119. lcd_selftest_error(8, _error_1, _error_2);
  5120. current_position[axis] = 0;
  5121. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5122. reset_crash_det(axis);
  5123. return false;
  5124. }
  5125. current_position[axis] = 0;
  5126. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5127. reset_crash_det(axis);
  5128. return true;
  5129. }
  5130. #endif //TMC2130
  5131. //#ifndef TMC2130
  5132. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5133. {
  5134. bool _stepdone = false;
  5135. bool _stepresult = false;
  5136. int _progress = 0;
  5137. int _travel_done = 0;
  5138. int _err_endstop = 0;
  5139. int _lcd_refresh = 0;
  5140. _travel = _travel + (_travel / 10);
  5141. do {
  5142. current_position[_axis] = current_position[_axis] - 1;
  5143. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5144. st_synchronize();
  5145. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5146. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5147. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5148. {
  5149. if (_axis == 0)
  5150. {
  5151. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5152. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5153. }
  5154. if (_axis == 1)
  5155. {
  5156. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5157. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5158. }
  5159. if (_axis == 2)
  5160. {
  5161. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5162. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5163. /*disable_x();
  5164. disable_y();
  5165. disable_z();*/
  5166. }
  5167. _stepdone = true;
  5168. }
  5169. if (_lcd_refresh < 6)
  5170. {
  5171. _lcd_refresh++;
  5172. }
  5173. else
  5174. {
  5175. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  5176. _lcd_refresh = 0;
  5177. }
  5178. manage_heater();
  5179. manage_inactivity(true);
  5180. //delay(100);
  5181. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5182. } while (!_stepdone);
  5183. //current_position[_axis] = current_position[_axis] + 15;
  5184. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5185. if (!_stepresult)
  5186. {
  5187. const char *_error_1;
  5188. const char *_error_2;
  5189. if (_axis == X_AXIS) _error_1 = "X";
  5190. if (_axis == Y_AXIS) _error_1 = "Y";
  5191. if (_axis == Z_AXIS) _error_1 = "Z";
  5192. if (_err_endstop == 0) _error_2 = "X";
  5193. if (_err_endstop == 1) _error_2 = "Y";
  5194. if (_err_endstop == 2) _error_2 = "Z";
  5195. if (_travel_done >= _travel)
  5196. {
  5197. lcd_selftest_error(5, _error_1, _error_2);
  5198. }
  5199. else
  5200. {
  5201. lcd_selftest_error(4, _error_1, _error_2);
  5202. }
  5203. }
  5204. return _stepresult;
  5205. }
  5206. static bool lcd_selfcheck_pulleys(int axis)
  5207. {
  5208. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5209. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5210. float current_position_init;
  5211. float move;
  5212. bool endstop_triggered = false;
  5213. int i;
  5214. unsigned long timeout_counter;
  5215. refresh_cmd_timeout();
  5216. manage_inactivity(true);
  5217. if (axis == 0) move = 50; //X_AXIS
  5218. else move = 50; //Y_AXIS
  5219. current_position_init = current_position[axis];
  5220. current_position[axis] += 2;
  5221. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5222. for (i = 0; i < 5; i++) {
  5223. refresh_cmd_timeout();
  5224. current_position[axis] = current_position[axis] + move;
  5225. digipot_current(0, 850); //set motor current higher
  5226. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5227. st_synchronize();
  5228. if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  5229. else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  5230. current_position[axis] = current_position[axis] - move;
  5231. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5232. st_synchronize();
  5233. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5234. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5235. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5236. return(false);
  5237. }
  5238. }
  5239. timeout_counter = millis() + 2500;
  5240. endstop_triggered = false;
  5241. manage_inactivity(true);
  5242. while (!endstop_triggered) {
  5243. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5244. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5245. endstop_triggered = true;
  5246. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5247. current_position[axis] += 15;
  5248. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5249. st_synchronize();
  5250. return(true);
  5251. }
  5252. else {
  5253. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5254. return(false);
  5255. }
  5256. }
  5257. else {
  5258. current_position[axis] -= 1;
  5259. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5260. st_synchronize();
  5261. if (millis() > timeout_counter) {
  5262. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5263. return(false);
  5264. }
  5265. }
  5266. }
  5267. return(true);
  5268. }
  5269. static bool lcd_selfcheck_endstops()
  5270. {
  5271. bool _result = true;
  5272. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5273. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5274. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5275. {
  5276. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5277. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5278. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5279. }
  5280. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
  5281. delay(500);
  5282. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5283. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5284. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5285. {
  5286. _result = false;
  5287. char _error[4] = "";
  5288. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5289. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5290. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5291. lcd_selftest_error(3, _error, "");
  5292. }
  5293. manage_heater();
  5294. manage_inactivity(true);
  5295. return _result;
  5296. }
  5297. //#endif //not defined TMC2130
  5298. static bool lcd_selfcheck_check_heater(bool _isbed)
  5299. {
  5300. int _counter = 0;
  5301. int _progress = 0;
  5302. bool _stepresult = false;
  5303. bool _docycle = true;
  5304. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5305. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5306. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5307. target_temperature[0] = (_isbed) ? 0 : 200;
  5308. target_temperature_bed = (_isbed) ? 100 : 0;
  5309. manage_heater();
  5310. manage_inactivity(true);
  5311. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5312. do {
  5313. _counter++;
  5314. _docycle = (_counter < _cycles) ? true : false;
  5315. manage_heater();
  5316. manage_inactivity(true);
  5317. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5318. /*if (_isbed) {
  5319. MYSERIAL.print("Bed temp:");
  5320. MYSERIAL.println(degBed());
  5321. }
  5322. else {
  5323. MYSERIAL.print("Hotend temp:");
  5324. MYSERIAL.println(degHotend(0));
  5325. }*/
  5326. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5327. } while (_docycle);
  5328. target_temperature[0] = 0;
  5329. target_temperature_bed = 0;
  5330. manage_heater();
  5331. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5332. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5333. /*
  5334. MYSERIAL.println("");
  5335. MYSERIAL.print("Checked result:");
  5336. MYSERIAL.println(_checked_result);
  5337. MYSERIAL.print("Opposite result:");
  5338. MYSERIAL.println(_opposite_result);
  5339. */
  5340. if (_opposite_result < ((_isbed) ? 10 : 3))
  5341. {
  5342. if (_checked_result >= ((_isbed) ? 3 : 10))
  5343. {
  5344. _stepresult = true;
  5345. }
  5346. else
  5347. {
  5348. lcd_selftest_error(1, "", "");
  5349. }
  5350. }
  5351. else
  5352. {
  5353. lcd_selftest_error(2, "", "");
  5354. }
  5355. manage_heater();
  5356. manage_inactivity(true);
  5357. KEEPALIVE_STATE(IN_HANDLER);
  5358. return _stepresult;
  5359. }
  5360. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5361. {
  5362. lcd_implementation_quick_feedback();
  5363. target_temperature[0] = 0;
  5364. target_temperature_bed = 0;
  5365. manage_heater();
  5366. manage_inactivity();
  5367. lcd_implementation_clear();
  5368. lcd.setCursor(0, 0);
  5369. lcd_printPGM(MSG_SELFTEST_ERROR);
  5370. lcd.setCursor(0, 1);
  5371. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  5372. switch (_error_no)
  5373. {
  5374. case 1:
  5375. lcd.setCursor(0, 2);
  5376. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  5377. lcd.setCursor(0, 3);
  5378. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  5379. break;
  5380. case 2:
  5381. lcd.setCursor(0, 2);
  5382. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  5383. lcd.setCursor(0, 3);
  5384. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5385. break;
  5386. case 3:
  5387. lcd.setCursor(0, 2);
  5388. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  5389. lcd.setCursor(0, 3);
  5390. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5391. lcd.setCursor(17, 3);
  5392. lcd.print(_error_1);
  5393. break;
  5394. case 4:
  5395. lcd.setCursor(0, 2);
  5396. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5397. lcd.setCursor(18, 2);
  5398. lcd.print(_error_1);
  5399. lcd.setCursor(0, 3);
  5400. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  5401. lcd.setCursor(18, 3);
  5402. lcd.print(_error_2);
  5403. break;
  5404. case 5:
  5405. lcd.setCursor(0, 2);
  5406. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  5407. lcd.setCursor(0, 3);
  5408. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5409. lcd.setCursor(18, 3);
  5410. lcd.print(_error_1);
  5411. break;
  5412. case 6:
  5413. lcd.setCursor(0, 2);
  5414. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5415. lcd.setCursor(0, 3);
  5416. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5417. lcd.setCursor(18, 3);
  5418. lcd.print(_error_1);
  5419. break;
  5420. case 7:
  5421. lcd.setCursor(0, 2);
  5422. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5423. lcd.setCursor(0, 3);
  5424. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5425. lcd.setCursor(18, 3);
  5426. lcd.print(_error_1);
  5427. break;
  5428. case 8:
  5429. lcd.setCursor(0, 2);
  5430. lcd_printPGM(MSG_LOOSE_PULLEY);
  5431. lcd.setCursor(0, 3);
  5432. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5433. lcd.setCursor(18, 3);
  5434. lcd.print(_error_1);
  5435. break;
  5436. case 9:
  5437. lcd.setCursor(0, 2);
  5438. lcd_printPGM(MSG_SELFTEST_AXIS_LENGTH);
  5439. lcd.setCursor(0, 3);
  5440. lcd_printPGM(MSG_SELFTEST_AXIS);
  5441. lcd.setCursor(18, 3);
  5442. lcd.print(_error_1);
  5443. break;
  5444. case 10:
  5445. lcd.setCursor(0, 2);
  5446. lcd_printPGM(MSG_SELFTEST_FANS);
  5447. lcd.setCursor(0, 3);
  5448. lcd_printPGM(MSG_SELFTEST_SWAPPED);
  5449. lcd.setCursor(18, 3);
  5450. lcd.print(_error_1);
  5451. break;
  5452. case 11:
  5453. lcd.setCursor(0, 2);
  5454. lcd_printPGM(MSG_FILAMENT_SENSOR);
  5455. lcd.setCursor(0, 3);
  5456. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5457. break;
  5458. }
  5459. delay(1000);
  5460. lcd_implementation_quick_feedback();
  5461. do {
  5462. delay(100);
  5463. manage_heater();
  5464. manage_inactivity();
  5465. } while (!lcd_clicked());
  5466. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5467. lcd_return_to_status();
  5468. }
  5469. #ifdef PAT9125
  5470. static bool lcd_selftest_fsensor() {
  5471. fsensor_init();
  5472. if (fsensor_not_responding)
  5473. {
  5474. const char *_err;
  5475. lcd_selftest_error(11, _err, _err);
  5476. }
  5477. return(!fsensor_not_responding);
  5478. }
  5479. #endif //PAT9125
  5480. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5481. {
  5482. bool _result = check_opposite;
  5483. lcd_implementation_clear();
  5484. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  5485. switch (_fan)
  5486. {
  5487. case 0:
  5488. // extruder cooling fan
  5489. lcd.setCursor(0, 1);
  5490. if(check_opposite == true) lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5491. else lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5492. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5493. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5494. break;
  5495. case 1:
  5496. // object cooling fan
  5497. lcd.setCursor(0, 1);
  5498. if (check_opposite == true) lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5499. else lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5500. SET_OUTPUT(FAN_PIN);
  5501. analogWrite(FAN_PIN, 255);
  5502. break;
  5503. }
  5504. delay(500);
  5505. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5506. lcd.setCursor(0, 3); lcd.print(">");
  5507. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5508. int8_t enc_dif = 0;
  5509. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5510. do
  5511. {
  5512. switch (_fan)
  5513. {
  5514. case 0:
  5515. // extruder cooling fan
  5516. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5517. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5518. break;
  5519. case 1:
  5520. // object cooling fan
  5521. SET_OUTPUT(FAN_PIN);
  5522. analogWrite(FAN_PIN, 255);
  5523. break;
  5524. }
  5525. if (abs((enc_dif - encoderDiff)) > 2) {
  5526. if (enc_dif > encoderDiff) {
  5527. _result = !check_opposite;
  5528. lcd.setCursor(0, 2); lcd.print(">");
  5529. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5530. lcd.setCursor(0, 3); lcd.print(" ");
  5531. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5532. }
  5533. if (enc_dif < encoderDiff) {
  5534. _result = check_opposite;
  5535. lcd.setCursor(0, 2); lcd.print(" ");
  5536. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5537. lcd.setCursor(0, 3); lcd.print(">");
  5538. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5539. }
  5540. enc_dif = 0;
  5541. encoderDiff = 0;
  5542. }
  5543. manage_heater();
  5544. delay(100);
  5545. } while (!lcd_clicked());
  5546. KEEPALIVE_STATE(IN_HANDLER);
  5547. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5548. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5549. SET_OUTPUT(FAN_PIN);
  5550. analogWrite(FAN_PIN, 0);
  5551. fanSpeed = 0;
  5552. manage_heater();
  5553. return _result;
  5554. }
  5555. static bool lcd_selftest_fan_dialog(int _fan)
  5556. {
  5557. bool _result = true;
  5558. int _errno = 7;
  5559. switch (_fan) {
  5560. case 0:
  5561. fanSpeed = 0;
  5562. manage_heater(); //turn off fan
  5563. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5564. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5565. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5566. if (!fan_speed[0]) _result = false;
  5567. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5568. //MYSERIAL.println(fan_speed[0]);
  5569. //SERIAL_ECHOPGM("Print fan speed: ");
  5570. //MYSERIAL.print(fan_speed[1]);
  5571. break;
  5572. case 1:
  5573. //will it work with Thotend > 50 C ?
  5574. fanSpeed = 150; //print fan
  5575. for (uint8_t i = 0; i < 5; i++) {
  5576. delay_keep_alive(1000);
  5577. lcd.setCursor(18, 3);
  5578. lcd.print("-");
  5579. delay_keep_alive(1000);
  5580. lcd.setCursor(18, 3);
  5581. lcd.print("|");
  5582. }
  5583. fanSpeed = 0;
  5584. manage_heater(); //turn off fan
  5585. manage_inactivity(true); //to turn off print fan
  5586. if (!fan_speed[1]) {
  5587. _result = false; _errno = 6; //print fan not spinning
  5588. }
  5589. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5590. //check fans manually
  5591. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  5592. if (_result) {
  5593. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  5594. if (!_result) _errno = 6; //print fan not spinning
  5595. }
  5596. else {
  5597. _errno = 10; //swapped fans
  5598. }
  5599. }
  5600. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5601. //MYSERIAL.println(fan_speed[0]);
  5602. //SERIAL_ECHOPGM("Print fan speed: ");
  5603. //MYSERIAL.println(fan_speed[1]);
  5604. break;
  5605. }
  5606. if (!_result)
  5607. {
  5608. const char *_err;
  5609. lcd_selftest_error(_errno, _err, _err);
  5610. }
  5611. return _result;
  5612. }
  5613. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  5614. {
  5615. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  5616. int _step_block = 0;
  5617. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  5618. if (_clear) lcd_implementation_clear();
  5619. lcd.setCursor(0, 0);
  5620. if (_step == -1) lcd_printPGM(MSG_SELFTEST_FAN);
  5621. if (_step == 0) lcd_printPGM(MSG_SELFTEST_FAN);
  5622. if (_step == 1) lcd_printPGM(MSG_SELFTEST_FAN);
  5623. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  5624. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  5625. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  5626. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  5627. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  5628. if (_step == 7) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5629. if (_step == 8) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5630. if (_step == 9) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5631. if (_step == 10) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5632. if (_step == 11) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  5633. if (_step == 12) lcd_printPGM(MSG_SELFTEST_FAILED);
  5634. lcd.setCursor(0, 1);
  5635. lcd.print("--------------------");
  5636. if ((_step >= -1) && (_step <= 1))
  5637. {
  5638. //SERIAL_ECHOLNPGM("Fan test");
  5639. lcd_print_at_PGM(0, 2, MSG_SELFTEST_EXTRUDER_FAN_SPEED);
  5640. lcd.setCursor(18, 2);
  5641. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  5642. lcd_print_at_PGM(0, 3, MSG_SELFTEST_PRINT_FAN_SPEED);
  5643. lcd.setCursor(18, 3);
  5644. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  5645. }
  5646. else if (_step >= 9 && _step <= 10)
  5647. {
  5648. lcd_print_at_PGM(0, 2, MSG_SELFTEST_FILAMENT_SENSOR);
  5649. lcd.setCursor(18, 2);
  5650. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  5651. }
  5652. else if (_step < 9)
  5653. {
  5654. //SERIAL_ECHOLNPGM("Other tests");
  5655. _step_block = 3;
  5656. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  5657. _step_block = 4;
  5658. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  5659. _step_block = 5;
  5660. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  5661. _step_block = 6;
  5662. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  5663. _step_block = 7;
  5664. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  5665. }
  5666. if (_delay > 0) delay_keep_alive(_delay);
  5667. _progress++;
  5668. return (_progress > _progress_scale * 2) ? 0 : _progress;
  5669. }
  5670. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  5671. {
  5672. lcd.setCursor(_col, _row);
  5673. switch (_state)
  5674. {
  5675. case 1:
  5676. lcd.print(_name);
  5677. lcd.setCursor(_col + strlen(_name), _row);
  5678. lcd.print(":");
  5679. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5680. lcd.print(_indicator);
  5681. break;
  5682. case 2:
  5683. lcd.print(_name);
  5684. lcd.setCursor(_col + strlen(_name), _row);
  5685. lcd.print(":");
  5686. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5687. lcd.print("OK");
  5688. break;
  5689. default:
  5690. lcd.print(_name);
  5691. }
  5692. }
  5693. /** End of menus **/
  5694. static void lcd_quick_feedback()
  5695. {
  5696. lcdDrawUpdate = 2;
  5697. button_pressed = false;
  5698. lcd_implementation_quick_feedback();
  5699. }
  5700. /** Menu action functions **/
  5701. /**
  5702. * @brief Go up in menu structure
  5703. * @param data unused parameter
  5704. */
  5705. static void menu_action_back(menuFunc_t data)
  5706. {
  5707. MenuStack::Record record = menuStack.pop();
  5708. lcd_goto_menu(record.menu);
  5709. encoderPosition = record.position;
  5710. }
  5711. /**
  5712. * @brief Go deeper into menu structure
  5713. * @param data nested menu
  5714. */
  5715. static void menu_action_submenu(menuFunc_t data) {
  5716. menuStack.push(currentMenu, encoderPosition);
  5717. lcd_goto_menu(data);
  5718. }
  5719. static void menu_action_gcode(const char* pgcode) {
  5720. enquecommand_P(pgcode);
  5721. }
  5722. static void menu_action_setlang(unsigned char lang) {
  5723. lcd_set_lang(lang);
  5724. }
  5725. static void menu_action_function(menuFunc_t data) {
  5726. (*data)();
  5727. }
  5728. static bool check_file(const char* filename) {
  5729. bool result = false;
  5730. uint32_t filesize;
  5731. card.openFile((char*)filename, true);
  5732. filesize = card.getFileSize();
  5733. if (filesize > END_FILE_SECTION) {
  5734. card.setIndex(filesize - END_FILE_SECTION);
  5735. }
  5736. while (!card.eof() && !result) {
  5737. card.sdprinting = true;
  5738. get_command();
  5739. result = check_commands();
  5740. }
  5741. card.printingHasFinished();
  5742. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  5743. lcd_finishstatus();
  5744. return result;
  5745. }
  5746. static void menu_action_sdfile(const char* filename, char* longFilename)
  5747. {
  5748. loading_flag = false;
  5749. char cmd[30];
  5750. char* c;
  5751. bool result = true;
  5752. sprintf_P(cmd, PSTR("M23 %s"), filename);
  5753. for (c = &cmd[4]; *c; c++)
  5754. *c = tolower(*c);
  5755. for (int i = 0; i < 8; i++) {
  5756. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]);
  5757. }
  5758. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5759. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  5760. for (uint8_t i = 0; i < depth; i++) {
  5761. for (int j = 0; j < 8; j++) {
  5762. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  5763. }
  5764. }
  5765. if (!check_file(filename)) {
  5766. result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FILE_INCOMPLETE, false, false);
  5767. lcd_update_enable(true);
  5768. }
  5769. if (result) {
  5770. enquecommand(cmd);
  5771. enquecommand_P(PSTR("M24"));
  5772. }
  5773. lcd_return_to_status();
  5774. }
  5775. static void menu_action_sddirectory(const char* filename, char* longFilename)
  5776. {
  5777. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5778. strcpy(dir_names[depth], filename);
  5779. MYSERIAL.println(dir_names[depth]);
  5780. card.chdir(filename);
  5781. encoderPosition = 0;
  5782. }
  5783. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  5784. {
  5785. *ptr = !(*ptr);
  5786. }
  5787. /*
  5788. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  5789. {
  5790. menu_action_setting_edit_bool(pstr, ptr);
  5791. (*callback)();
  5792. }
  5793. */
  5794. #endif//ULTIPANEL
  5795. /** LCD API **/
  5796. void lcd_init()
  5797. {
  5798. lcd_implementation_init();
  5799. #ifdef NEWPANEL
  5800. SET_INPUT(BTN_EN1);
  5801. SET_INPUT(BTN_EN2);
  5802. WRITE(BTN_EN1, HIGH);
  5803. WRITE(BTN_EN2, HIGH);
  5804. #if BTN_ENC > 0
  5805. SET_INPUT(BTN_ENC);
  5806. WRITE(BTN_ENC, HIGH);
  5807. #endif
  5808. #ifdef REPRAPWORLD_KEYPAD
  5809. pinMode(SHIFT_CLK, OUTPUT);
  5810. pinMode(SHIFT_LD, OUTPUT);
  5811. pinMode(SHIFT_OUT, INPUT);
  5812. WRITE(SHIFT_OUT, HIGH);
  5813. WRITE(SHIFT_LD, HIGH);
  5814. #endif
  5815. #else // Not NEWPANEL
  5816. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  5817. pinMode (SR_DATA_PIN, OUTPUT);
  5818. pinMode (SR_CLK_PIN, OUTPUT);
  5819. #elif defined(SHIFT_CLK)
  5820. pinMode(SHIFT_CLK, OUTPUT);
  5821. pinMode(SHIFT_LD, OUTPUT);
  5822. pinMode(SHIFT_EN, OUTPUT);
  5823. pinMode(SHIFT_OUT, INPUT);
  5824. WRITE(SHIFT_OUT, HIGH);
  5825. WRITE(SHIFT_LD, HIGH);
  5826. WRITE(SHIFT_EN, LOW);
  5827. #else
  5828. #ifdef ULTIPANEL
  5829. #error ULTIPANEL requires an encoder
  5830. #endif
  5831. #endif // SR_LCD_2W_NL
  5832. #endif//!NEWPANEL
  5833. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  5834. pinMode(SDCARDDETECT, INPUT);
  5835. WRITE(SDCARDDETECT, HIGH);
  5836. lcd_oldcardstatus = IS_SD_INSERTED;
  5837. #endif//(SDCARDDETECT > 0)
  5838. #ifdef LCD_HAS_SLOW_BUTTONS
  5839. slow_buttons = 0;
  5840. #endif
  5841. lcd_buttons_update();
  5842. #ifdef ULTIPANEL
  5843. encoderDiff = 0;
  5844. #endif
  5845. }
  5846. //#include <avr/pgmspace.h>
  5847. static volatile bool lcd_update_enabled = true;
  5848. unsigned long lcd_timeoutToStatus = 0;
  5849. void lcd_update_enable(bool enabled)
  5850. {
  5851. if (lcd_update_enabled != enabled) {
  5852. lcd_update_enabled = enabled;
  5853. if (enabled) {
  5854. // Reset encoder position. This is equivalent to re-entering a menu.
  5855. encoderPosition = 0;
  5856. encoderDiff = 0;
  5857. // Enabling the normal LCD update procedure.
  5858. // Reset the timeout interval.
  5859. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5860. // Force the keypad update now.
  5861. lcd_next_update_millis = millis() - 1;
  5862. // Full update.
  5863. lcd_implementation_clear();
  5864. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  5865. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  5866. #else
  5867. if (currentMenu == lcd_status_screen)
  5868. lcd_set_custom_characters_degree();
  5869. else
  5870. lcd_set_custom_characters_arrows();
  5871. #endif
  5872. lcd_update(2);
  5873. } else {
  5874. // Clear the LCD always, or let it to the caller?
  5875. }
  5876. }
  5877. }
  5878. void lcd_update(uint8_t lcdDrawUpdateOverride)
  5879. {
  5880. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  5881. lcdDrawUpdate = lcdDrawUpdateOverride;
  5882. if (!lcd_update_enabled)
  5883. return;
  5884. #ifdef LCD_HAS_SLOW_BUTTONS
  5885. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  5886. #endif
  5887. lcd_buttons_update();
  5888. #if (SDCARDDETECT > 0)
  5889. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  5890. {
  5891. lcdDrawUpdate = 2;
  5892. lcd_oldcardstatus = IS_SD_INSERTED;
  5893. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  5894. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  5895. currentMenu == lcd_status_screen
  5896. #endif
  5897. );
  5898. if (lcd_oldcardstatus)
  5899. {
  5900. card.initsd();
  5901. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  5902. //get_description();
  5903. }
  5904. else
  5905. {
  5906. card.release();
  5907. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  5908. }
  5909. }
  5910. #endif//CARDINSERTED
  5911. if (lcd_next_update_millis < millis())
  5912. {
  5913. #ifdef DEBUG_BLINK_ACTIVE
  5914. static bool active_led = false;
  5915. active_led = !active_led;
  5916. pinMode(LED_PIN, OUTPUT);
  5917. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  5918. #endif //DEBUG_BLINK_ACTIVE
  5919. #ifdef ULTIPANEL
  5920. #ifdef REPRAPWORLD_KEYPAD
  5921. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  5922. reprapworld_keypad_move_z_up();
  5923. }
  5924. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  5925. reprapworld_keypad_move_z_down();
  5926. }
  5927. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  5928. reprapworld_keypad_move_x_left();
  5929. }
  5930. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  5931. reprapworld_keypad_move_x_right();
  5932. }
  5933. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  5934. reprapworld_keypad_move_y_down();
  5935. }
  5936. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  5937. reprapworld_keypad_move_y_up();
  5938. }
  5939. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  5940. reprapworld_keypad_move_home();
  5941. }
  5942. #endif
  5943. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  5944. {
  5945. if (lcdDrawUpdate == 0)
  5946. lcdDrawUpdate = 1;
  5947. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  5948. encoderDiff = 0;
  5949. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5950. }
  5951. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5952. #endif//ULTIPANEL
  5953. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  5954. blink++; // Variable for fan animation and alive dot
  5955. u8g.firstPage();
  5956. do
  5957. {
  5958. u8g.setFont(u8g_font_6x10_marlin);
  5959. u8g.setPrintPos(125, 0);
  5960. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  5961. u8g.drawPixel(127, 63); // draw alive dot
  5962. u8g.setColorIndex(1); // black on white
  5963. (*currentMenu)();
  5964. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  5965. } while (u8g.nextPage());
  5966. #else
  5967. (*currentMenu)();
  5968. #endif
  5969. #ifdef LCD_HAS_STATUS_INDICATORS
  5970. lcd_implementation_update_indicators();
  5971. #endif
  5972. #ifdef ULTIPANEL
  5973. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  5974. {
  5975. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  5976. // to give it a chance to save its state.
  5977. // This is useful for example, when the babystep value has to be written into EEPROM.
  5978. if (currentMenu != NULL) {
  5979. menuExiting = true;
  5980. (*currentMenu)();
  5981. menuExiting = false;
  5982. }
  5983. lcd_implementation_clear();
  5984. lcd_return_to_status();
  5985. lcdDrawUpdate = 2;
  5986. }
  5987. #endif//ULTIPANEL
  5988. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  5989. if (lcdDrawUpdate) lcdDrawUpdate--;
  5990. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5991. }
  5992. if (!SdFatUtil::test_stack_integrity()) stack_error();
  5993. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5994. if (stepper_timer_overflow_state) stepper_timer_overflow();
  5995. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5996. lcd_ping(); //check that we have received ping command if we are in farm mode
  5997. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  5998. }
  5999. void lcd_printer_connected() {
  6000. printer_connected = true;
  6001. }
  6002. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6003. if (farm_mode) {
  6004. bool empty = is_buffer_empty();
  6005. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6006. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6007. //therefore longer period is used
  6008. printer_connected = false;
  6009. //lcd_ping_allert(); //acustic signals
  6010. }
  6011. else {
  6012. lcd_printer_connected();
  6013. }
  6014. }
  6015. }
  6016. void lcd_ignore_click(bool b)
  6017. {
  6018. ignore_click = b;
  6019. wait_for_unclick = false;
  6020. }
  6021. void lcd_finishstatus() {
  6022. int len = strlen(lcd_status_message);
  6023. if (len > 0) {
  6024. while (len < LCD_WIDTH) {
  6025. lcd_status_message[len++] = ' ';
  6026. }
  6027. }
  6028. lcd_status_message[LCD_WIDTH] = '\0';
  6029. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6030. #if PROGRESS_MSG_EXPIRE > 0
  6031. messageTick =
  6032. #endif
  6033. progressBarTick = millis();
  6034. #endif
  6035. lcdDrawUpdate = 2;
  6036. #ifdef FILAMENT_LCD_DISPLAY
  6037. message_millis = millis(); //get status message to show up for a while
  6038. #endif
  6039. }
  6040. void lcd_setstatus(const char* message)
  6041. {
  6042. if (lcd_status_message_level > 0)
  6043. return;
  6044. strncpy(lcd_status_message, message, LCD_WIDTH);
  6045. lcd_finishstatus();
  6046. }
  6047. void lcd_setstatuspgm(const char* message)
  6048. {
  6049. if (lcd_status_message_level > 0)
  6050. return;
  6051. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6052. lcd_status_message[LCD_WIDTH] = 0;
  6053. lcd_finishstatus();
  6054. }
  6055. void lcd_setalertstatuspgm(const char* message)
  6056. {
  6057. lcd_setstatuspgm(message);
  6058. lcd_status_message_level = 1;
  6059. #ifdef ULTIPANEL
  6060. lcd_return_to_status();
  6061. #endif//ULTIPANEL
  6062. }
  6063. void lcd_reset_alert_level()
  6064. {
  6065. lcd_status_message_level = 0;
  6066. }
  6067. uint8_t get_message_level()
  6068. {
  6069. return lcd_status_message_level;
  6070. }
  6071. #ifdef DOGLCD
  6072. void lcd_setcontrast(uint8_t value)
  6073. {
  6074. lcd_contrast = value & 63;
  6075. u8g.setContrast(lcd_contrast);
  6076. }
  6077. #endif
  6078. #ifdef ULTIPANEL
  6079. /* Warning: This function is called from interrupt context */
  6080. void lcd_buttons_update()
  6081. {
  6082. static bool _lock = false;
  6083. if (_lock) return;
  6084. _lock = true;
  6085. #ifdef NEWPANEL
  6086. uint8_t newbutton = 0;
  6087. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6088. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6089. #if BTN_ENC > 0
  6090. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6091. if (READ(BTN_ENC) == 0) { //button is pressed
  6092. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6093. if (millis() > button_blanking_time) {
  6094. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6095. if (button_pressed == false && long_press_active == false) {
  6096. long_press_timer = millis();
  6097. button_pressed = true;
  6098. }
  6099. else {
  6100. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  6101. long_press_active = true;
  6102. move_menu_scale = 1.0;
  6103. menu_action_submenu(lcd_move_z);
  6104. }
  6105. }
  6106. }
  6107. }
  6108. else { //button not pressed
  6109. if (button_pressed) { //button was released
  6110. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6111. if (long_press_active == false) { //button released before long press gets activated
  6112. newbutton |= EN_C;
  6113. }
  6114. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  6115. //button_pressed is set back to false via lcd_quick_feedback function
  6116. }
  6117. else {
  6118. long_press_active = false;
  6119. }
  6120. }
  6121. }
  6122. else { //we are in modal mode
  6123. if (READ(BTN_ENC) == 0)
  6124. newbutton |= EN_C;
  6125. }
  6126. #endif
  6127. buttons = newbutton;
  6128. #ifdef LCD_HAS_SLOW_BUTTONS
  6129. buttons |= slow_buttons;
  6130. #endif
  6131. #ifdef REPRAPWORLD_KEYPAD
  6132. // for the reprapworld_keypad
  6133. uint8_t newbutton_reprapworld_keypad = 0;
  6134. WRITE(SHIFT_LD, LOW);
  6135. WRITE(SHIFT_LD, HIGH);
  6136. for (int8_t i = 0; i < 8; i++) {
  6137. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6138. if (READ(SHIFT_OUT))
  6139. newbutton_reprapworld_keypad |= (1 << 7);
  6140. WRITE(SHIFT_CLK, HIGH);
  6141. WRITE(SHIFT_CLK, LOW);
  6142. }
  6143. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6144. #endif
  6145. #else //read it from the shift register
  6146. uint8_t newbutton = 0;
  6147. WRITE(SHIFT_LD, LOW);
  6148. WRITE(SHIFT_LD, HIGH);
  6149. unsigned char tmp_buttons = 0;
  6150. for (int8_t i = 0; i < 8; i++)
  6151. {
  6152. newbutton = newbutton >> 1;
  6153. if (READ(SHIFT_OUT))
  6154. newbutton |= (1 << 7);
  6155. WRITE(SHIFT_CLK, HIGH);
  6156. WRITE(SHIFT_CLK, LOW);
  6157. }
  6158. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6159. #endif//!NEWPANEL
  6160. //manage encoder rotation
  6161. uint8_t enc = 0;
  6162. if (buttons & EN_A) enc |= B01;
  6163. if (buttons & EN_B) enc |= B10;
  6164. if (enc != lastEncoderBits)
  6165. {
  6166. switch (enc)
  6167. {
  6168. case encrot0:
  6169. if (lastEncoderBits == encrot3)
  6170. encoderDiff++;
  6171. else if (lastEncoderBits == encrot1)
  6172. encoderDiff--;
  6173. break;
  6174. case encrot1:
  6175. if (lastEncoderBits == encrot0)
  6176. encoderDiff++;
  6177. else if (lastEncoderBits == encrot2)
  6178. encoderDiff--;
  6179. break;
  6180. case encrot2:
  6181. if (lastEncoderBits == encrot1)
  6182. encoderDiff++;
  6183. else if (lastEncoderBits == encrot3)
  6184. encoderDiff--;
  6185. break;
  6186. case encrot3:
  6187. if (lastEncoderBits == encrot2)
  6188. encoderDiff++;
  6189. else if (lastEncoderBits == encrot0)
  6190. encoderDiff--;
  6191. break;
  6192. }
  6193. }
  6194. lastEncoderBits = enc;
  6195. _lock = false;
  6196. }
  6197. bool lcd_detected(void)
  6198. {
  6199. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6200. return lcd.LcdDetected() == 1;
  6201. #else
  6202. return true;
  6203. #endif
  6204. }
  6205. void lcd_buzz(long duration, uint16_t freq)
  6206. {
  6207. #ifdef LCD_USE_I2C_BUZZER
  6208. lcd.buzz(duration, freq);
  6209. #endif
  6210. }
  6211. bool lcd_clicked()
  6212. {
  6213. bool clicked = LCD_CLICKED;
  6214. if(clicked) button_pressed = false;
  6215. return clicked;
  6216. }
  6217. #endif//ULTIPANEL
  6218. /********************************/
  6219. /** Float conversion utilities **/
  6220. /********************************/
  6221. // convert float to string with +123.4 format
  6222. char conv[8];
  6223. char *ftostr3(const float &x)
  6224. {
  6225. return itostr3((int)x);
  6226. }
  6227. char *itostr2(const uint8_t &x)
  6228. {
  6229. //sprintf(conv,"%5.1f",x);
  6230. int xx = x;
  6231. conv[0] = (xx / 10) % 10 + '0';
  6232. conv[1] = (xx) % 10 + '0';
  6233. conv[2] = 0;
  6234. return conv;
  6235. }
  6236. // Convert float to string with 123.4 format, dropping sign
  6237. char *ftostr31(const float &x)
  6238. {
  6239. int xx = x * 10;
  6240. conv[0] = (xx >= 0) ? '+' : '-';
  6241. xx = abs(xx);
  6242. conv[1] = (xx / 1000) % 10 + '0';
  6243. conv[2] = (xx / 100) % 10 + '0';
  6244. conv[3] = (xx / 10) % 10 + '0';
  6245. conv[4] = '.';
  6246. conv[5] = (xx) % 10 + '0';
  6247. conv[6] = 0;
  6248. return conv;
  6249. }
  6250. // Convert float to string with 123.4 format
  6251. char *ftostr31ns(const float &x)
  6252. {
  6253. int xx = x * 10;
  6254. //conv[0]=(xx>=0)?'+':'-';
  6255. xx = abs(xx);
  6256. conv[0] = (xx / 1000) % 10 + '0';
  6257. conv[1] = (xx / 100) % 10 + '0';
  6258. conv[2] = (xx / 10) % 10 + '0';
  6259. conv[3] = '.';
  6260. conv[4] = (xx) % 10 + '0';
  6261. conv[5] = 0;
  6262. return conv;
  6263. }
  6264. char *ftostr32(const float &x)
  6265. {
  6266. long xx = x * 100;
  6267. if (xx >= 0)
  6268. conv[0] = (xx / 10000) % 10 + '0';
  6269. else
  6270. conv[0] = '-';
  6271. xx = abs(xx);
  6272. conv[1] = (xx / 1000) % 10 + '0';
  6273. conv[2] = (xx / 100) % 10 + '0';
  6274. conv[3] = '.';
  6275. conv[4] = (xx / 10) % 10 + '0';
  6276. conv[5] = (xx) % 10 + '0';
  6277. conv[6] = 0;
  6278. return conv;
  6279. }
  6280. //// Convert float to rj string with 123.45 format
  6281. char *ftostr32ns(const float &x) {
  6282. long xx = abs(x);
  6283. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6284. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6285. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6286. conv[3] = '.';
  6287. conv[4] = (xx / 10) % 10 + '0';
  6288. conv[5] = xx % 10 + '0';
  6289. return conv;
  6290. }
  6291. // Convert float to string with 1.234 format
  6292. char *ftostr43(const float &x)
  6293. {
  6294. long xx = x * 1000;
  6295. if (xx >= 0)
  6296. conv[0] = (xx / 1000) % 10 + '0';
  6297. else
  6298. conv[0] = '-';
  6299. xx = abs(xx);
  6300. conv[1] = '.';
  6301. conv[2] = (xx / 100) % 10 + '0';
  6302. conv[3] = (xx / 10) % 10 + '0';
  6303. conv[4] = (xx) % 10 + '0';
  6304. conv[5] = 0;
  6305. return conv;
  6306. }
  6307. //Float to string with 1.23 format
  6308. char *ftostr12ns(const float &x)
  6309. {
  6310. long xx = x * 100;
  6311. xx = abs(xx);
  6312. conv[0] = (xx / 100) % 10 + '0';
  6313. conv[1] = '.';
  6314. conv[2] = (xx / 10) % 10 + '0';
  6315. conv[3] = (xx) % 10 + '0';
  6316. conv[4] = 0;
  6317. return conv;
  6318. }
  6319. //Float to string with 1.234 format
  6320. char *ftostr13ns(const float &x)
  6321. {
  6322. long xx = x * 1000;
  6323. if (xx >= 0)
  6324. conv[0] = ' ';
  6325. else
  6326. conv[0] = '-';
  6327. xx = abs(xx);
  6328. conv[1] = (xx / 1000) % 10 + '0';
  6329. conv[2] = '.';
  6330. conv[3] = (xx / 100) % 10 + '0';
  6331. conv[4] = (xx / 10) % 10 + '0';
  6332. conv[5] = (xx) % 10 + '0';
  6333. conv[6] = 0;
  6334. return conv;
  6335. }
  6336. // convert float to space-padded string with -_23.4_ format
  6337. char *ftostr32sp(const float &x) {
  6338. long xx = abs(x * 100);
  6339. uint8_t dig;
  6340. if (x < 0) { // negative val = -_0
  6341. conv[0] = '-';
  6342. dig = (xx / 1000) % 10;
  6343. conv[1] = dig ? '0' + dig : ' ';
  6344. }
  6345. else { // positive val = __0
  6346. dig = (xx / 10000) % 10;
  6347. if (dig) {
  6348. conv[0] = '0' + dig;
  6349. conv[1] = '0' + (xx / 1000) % 10;
  6350. }
  6351. else {
  6352. conv[0] = ' ';
  6353. dig = (xx / 1000) % 10;
  6354. conv[1] = dig ? '0' + dig : ' ';
  6355. }
  6356. }
  6357. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6358. dig = xx % 10;
  6359. if (dig) { // 2 decimal places
  6360. conv[5] = '0' + dig;
  6361. conv[4] = '0' + (xx / 10) % 10;
  6362. conv[3] = '.';
  6363. }
  6364. else { // 1 or 0 decimal place
  6365. dig = (xx / 10) % 10;
  6366. if (dig) {
  6367. conv[4] = '0' + dig;
  6368. conv[3] = '.';
  6369. }
  6370. else {
  6371. conv[3] = conv[4] = ' ';
  6372. }
  6373. conv[5] = ' ';
  6374. }
  6375. conv[6] = '\0';
  6376. return conv;
  6377. }
  6378. char *itostr31(const int &xx)
  6379. {
  6380. conv[0] = (xx >= 0) ? '+' : '-';
  6381. conv[1] = (xx / 1000) % 10 + '0';
  6382. conv[2] = (xx / 100) % 10 + '0';
  6383. conv[3] = (xx / 10) % 10 + '0';
  6384. conv[4] = '.';
  6385. conv[5] = (xx) % 10 + '0';
  6386. conv[6] = 0;
  6387. return conv;
  6388. }
  6389. // Convert int to rj string with 123 or -12 format
  6390. char *itostr3(const int &x)
  6391. {
  6392. int xx = x;
  6393. if (xx < 0) {
  6394. conv[0] = '-';
  6395. xx = -xx;
  6396. } else if (xx >= 100)
  6397. conv[0] = (xx / 100) % 10 + '0';
  6398. else
  6399. conv[0] = ' ';
  6400. if (xx >= 10)
  6401. conv[1] = (xx / 10) % 10 + '0';
  6402. else
  6403. conv[1] = ' ';
  6404. conv[2] = (xx) % 10 + '0';
  6405. conv[3] = 0;
  6406. return conv;
  6407. }
  6408. // Convert int to lj string with 123 format
  6409. char *itostr3left(const int &xx)
  6410. {
  6411. if (xx >= 100)
  6412. {
  6413. conv[0] = (xx / 100) % 10 + '0';
  6414. conv[1] = (xx / 10) % 10 + '0';
  6415. conv[2] = (xx) % 10 + '0';
  6416. conv[3] = 0;
  6417. }
  6418. else if (xx >= 10)
  6419. {
  6420. conv[0] = (xx / 10) % 10 + '0';
  6421. conv[1] = (xx) % 10 + '0';
  6422. conv[2] = 0;
  6423. }
  6424. else
  6425. {
  6426. conv[0] = (xx) % 10 + '0';
  6427. conv[1] = 0;
  6428. }
  6429. return conv;
  6430. }
  6431. // Convert int to rj string with 1234 format
  6432. char *itostr4(const int &xx) {
  6433. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6434. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6435. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6436. conv[3] = xx % 10 + '0';
  6437. conv[4] = 0;
  6438. return conv;
  6439. }
  6440. // Convert float to rj string with 12345 format
  6441. char *ftostr5(const float &x) {
  6442. long xx = abs(x);
  6443. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6444. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6445. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6446. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6447. conv[4] = xx % 10 + '0';
  6448. conv[5] = 0;
  6449. return conv;
  6450. }
  6451. // Convert float to string with +1234.5 format
  6452. char *ftostr51(const float &x)
  6453. {
  6454. long xx = x * 10;
  6455. conv[0] = (xx >= 0) ? '+' : '-';
  6456. xx = abs(xx);
  6457. conv[1] = (xx / 10000) % 10 + '0';
  6458. conv[2] = (xx / 1000) % 10 + '0';
  6459. conv[3] = (xx / 100) % 10 + '0';
  6460. conv[4] = (xx / 10) % 10 + '0';
  6461. conv[5] = '.';
  6462. conv[6] = (xx) % 10 + '0';
  6463. conv[7] = 0;
  6464. return conv;
  6465. }
  6466. // Convert float to string with +123.45 format
  6467. char *ftostr52(const float &x)
  6468. {
  6469. long xx = x * 100;
  6470. conv[0] = (xx >= 0) ? '+' : '-';
  6471. xx = abs(xx);
  6472. conv[1] = (xx / 10000) % 10 + '0';
  6473. conv[2] = (xx / 1000) % 10 + '0';
  6474. conv[3] = (xx / 100) % 10 + '0';
  6475. conv[4] = '.';
  6476. conv[5] = (xx / 10) % 10 + '0';
  6477. conv[6] = (xx) % 10 + '0';
  6478. conv[7] = 0;
  6479. return conv;
  6480. }
  6481. /*
  6482. // Callback for after editing PID i value
  6483. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  6484. void copy_and_scalePID_i()
  6485. {
  6486. #ifdef PIDTEMP
  6487. Ki = scalePID_i(raw_Ki);
  6488. updatePID();
  6489. #endif
  6490. }
  6491. // Callback for after editing PID d value
  6492. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  6493. void copy_and_scalePID_d()
  6494. {
  6495. #ifdef PIDTEMP
  6496. Kd = scalePID_d(raw_Kd);
  6497. updatePID();
  6498. #endif
  6499. }
  6500. */
  6501. #endif //ULTRA_LCD