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