ultralcd.cpp 204 KB

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