ultralcd.cpp 203 KB

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