ultralcd.cpp 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557
  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. /**
  2012. * @brief adjust bed reset menu item function
  2013. *
  2014. * To be used as MENU_ITEM(function,...) inside lcd_adjust_bed submenu. In such case lcd_goto_menu usage
  2015. * is correct and doesn't break menuStack.
  2016. * Because we did not leave the menu, the menuData did not reset.
  2017. * Force refresh of the bed leveling data.
  2018. */
  2019. static void lcd_adjust_bed_reset()
  2020. {
  2021. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2022. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2023. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2024. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2025. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2026. lcd_goto_menu(lcd_adjust_bed, 0, false); //doesn't break menuStack
  2027. menuData.adjustBed.status = 0;
  2028. }
  2029. void adjust_bed_reset() {
  2030. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2031. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  2032. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2033. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2034. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  2035. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  2036. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  2037. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  2038. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  2039. }
  2040. #define BED_ADJUSTMENT_UM_MAX 50
  2041. static void lcd_adjust_bed()
  2042. {
  2043. if (menuData.adjustBed.status == 0) {
  2044. // Menu was entered.
  2045. // Initialize its status.
  2046. menuData.adjustBed.status = 1;
  2047. bool valid = false;
  2048. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2049. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2050. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2051. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2052. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  2053. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  2054. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  2055. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  2056. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  2057. valid = true;
  2058. if (! valid) {
  2059. // Reset the values: simulate an edit.
  2060. menuData.adjustBed.left2 = 0;
  2061. menuData.adjustBed.right2 = 0;
  2062. menuData.adjustBed.front2 = 0;
  2063. menuData.adjustBed.rear2 = 0;
  2064. }
  2065. lcdDrawUpdate = 1;
  2066. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2067. }
  2068. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  2069. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  2070. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  2071. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  2072. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  2073. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  2074. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  2075. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  2076. START_MENU();
  2077. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  2078. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2079. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2080. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2081. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  2082. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  2083. END_MENU();
  2084. }
  2085. void pid_extruder() {
  2086. lcd_implementation_clear();
  2087. lcd.setCursor(1, 0);
  2088. lcd_printPGM(MSG_SET_TEMPERATURE);
  2089. pid_temp += int(encoderPosition);
  2090. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2091. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2092. encoderPosition = 0;
  2093. lcd.setCursor(1, 2);
  2094. lcd.print(ftostr3(pid_temp));
  2095. if (lcd_clicked()) {
  2096. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2097. lcd_return_to_status();
  2098. lcd_update(2);
  2099. }
  2100. }
  2101. void lcd_adjust_z() {
  2102. int enc_dif = 0;
  2103. int cursor_pos = 1;
  2104. int fsm = 0;
  2105. lcd_implementation_clear();
  2106. lcd.setCursor(0, 0);
  2107. lcd_printPGM(MSG_ADJUSTZ);
  2108. lcd.setCursor(1, 1);
  2109. lcd_printPGM(MSG_YES);
  2110. lcd.setCursor(1, 2);
  2111. lcd_printPGM(MSG_NO);
  2112. lcd.setCursor(0, 1);
  2113. lcd.print(">");
  2114. enc_dif = encoderDiff;
  2115. while (fsm == 0) {
  2116. manage_heater();
  2117. manage_inactivity(true);
  2118. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2119. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2120. if (enc_dif > encoderDiff ) {
  2121. cursor_pos --;
  2122. }
  2123. if (enc_dif < encoderDiff ) {
  2124. cursor_pos ++;
  2125. }
  2126. if (cursor_pos > 2) {
  2127. cursor_pos = 2;
  2128. }
  2129. if (cursor_pos < 1) {
  2130. cursor_pos = 1;
  2131. }
  2132. lcd.setCursor(0, 1);
  2133. lcd.print(" ");
  2134. lcd.setCursor(0, 2);
  2135. lcd.print(" ");
  2136. lcd.setCursor(0, cursor_pos);
  2137. lcd.print(">");
  2138. enc_dif = encoderDiff;
  2139. delay(100);
  2140. }
  2141. }
  2142. if (lcd_clicked()) {
  2143. fsm = cursor_pos;
  2144. if (fsm == 1) {
  2145. int babystepLoadZ = 0;
  2146. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2147. CRITICAL_SECTION_START
  2148. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2149. CRITICAL_SECTION_END
  2150. } else {
  2151. int zero = 0;
  2152. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2153. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2154. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2155. }
  2156. delay(500);
  2157. }
  2158. };
  2159. lcd_implementation_clear();
  2160. lcd_return_to_status();
  2161. }
  2162. void lcd_wait_for_heater() {
  2163. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  2164. lcd.setCursor(0, 4);
  2165. lcd.print(LCD_STR_THERMOMETER[0]);
  2166. lcd.print(ftostr3(degHotend(active_extruder)));
  2167. lcd.print("/");
  2168. lcd.print(ftostr3(degTargetHotend(active_extruder)));
  2169. lcd.print(LCD_STR_DEGREE);
  2170. }
  2171. void lcd_wait_for_cool_down() {
  2172. lcd_set_custom_characters_degree();
  2173. setTargetHotend(0,0);
  2174. setTargetBed(0);
  2175. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2176. lcd_display_message_fullscreen_P(MSG_WAITING_TEMP);
  2177. lcd.setCursor(0, 4);
  2178. lcd.print(LCD_STR_THERMOMETER[0]);
  2179. lcd.print(ftostr3(degHotend(0)));
  2180. lcd.print("/0");
  2181. lcd.print(LCD_STR_DEGREE);
  2182. lcd.setCursor(9, 4);
  2183. lcd.print(LCD_STR_BEDTEMP[0]);
  2184. lcd.print(ftostr3(degBed()));
  2185. lcd.print("/0");
  2186. lcd.print(LCD_STR_DEGREE);
  2187. lcd_set_custom_characters();
  2188. delay_keep_alive(1000);
  2189. serialecho_temperatures();
  2190. }
  2191. lcd_set_custom_characters_arrows();
  2192. lcd_update_enable(true);
  2193. }
  2194. // Lets the user move the Z carriage up to the end stoppers.
  2195. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2196. // Otherwise the Z calibration is not changed and false is returned.
  2197. #ifndef TMC2130
  2198. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2199. {
  2200. bool clean_nozzle_asked = false;
  2201. // 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.
  2202. current_position[Z_AXIS] = 0;
  2203. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2204. // Until confirmed by the confirmation dialog.
  2205. for (;;) {
  2206. unsigned long previous_millis_cmd = millis();
  2207. const char *msg = only_z ? MSG_MOVE_CARRIAGE_TO_THE_TOP_Z : MSG_MOVE_CARRIAGE_TO_THE_TOP;
  2208. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2209. const bool multi_screen = msg_next != NULL;
  2210. unsigned long previous_millis_msg = millis();
  2211. // Until the user finishes the z up movement.
  2212. encoderDiff = 0;
  2213. encoderPosition = 0;
  2214. for (;;) {
  2215. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2216. // goto canceled;
  2217. manage_heater();
  2218. manage_inactivity(true);
  2219. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  2220. delay(50);
  2221. previous_millis_cmd = millis();
  2222. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  2223. encoderDiff = 0;
  2224. if (! planner_queue_full()) {
  2225. // Only move up, whatever direction the user rotates the encoder.
  2226. current_position[Z_AXIS] += fabs(encoderPosition);
  2227. encoderPosition = 0;
  2228. 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);
  2229. }
  2230. }
  2231. if (lcd_clicked()) {
  2232. // Abort a move if in progress.
  2233. planner_abort_hard();
  2234. while (lcd_clicked()) ;
  2235. delay(10);
  2236. while (lcd_clicked()) ;
  2237. break;
  2238. }
  2239. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2240. if (msg_next == NULL)
  2241. msg_next = msg;
  2242. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2243. previous_millis_msg = millis();
  2244. }
  2245. }
  2246. if (! clean_nozzle_asked) {
  2247. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  2248. clean_nozzle_asked = true;
  2249. }
  2250. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2251. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP, false);
  2252. if (result == -1)
  2253. goto canceled;
  2254. else if (result == 1)
  2255. goto calibrated;
  2256. // otherwise perform another round of the Z up dialog.
  2257. }
  2258. calibrated:
  2259. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2260. // during the search for the induction points.
  2261. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2262. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2263. if(only_z){
  2264. lcd_display_message_fullscreen_P(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1);
  2265. lcd_implementation_print_at(0, 3, 1);
  2266. lcd_printPGM(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2);
  2267. }else{
  2268. //lcd_show_fullscreen_message_and_wait_P(MSG_PAPER);
  2269. lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1);
  2270. lcd_implementation_print_at(0, 2, 1);
  2271. lcd_printPGM(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2);
  2272. }
  2273. return true;
  2274. canceled:
  2275. return false;
  2276. }
  2277. #endif // TMC2130
  2278. static inline bool pgm_is_whitespace(const char *c_addr)
  2279. {
  2280. const char c = pgm_read_byte(c_addr);
  2281. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2282. }
  2283. static inline bool pgm_is_interpunction(const char *c_addr)
  2284. {
  2285. const char c = pgm_read_byte(c_addr);
  2286. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2287. }
  2288. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2289. {
  2290. // Disable update of the screen by the usual lcd_update() routine.
  2291. lcd_update_enable(false);
  2292. lcd_implementation_clear();
  2293. lcd.setCursor(0, 0);
  2294. const char *msgend = msg;
  2295. uint8_t row = 0;
  2296. bool multi_screen = false;
  2297. for (; row < 4; ++ row) {
  2298. while (pgm_is_whitespace(msg))
  2299. ++ msg;
  2300. if (pgm_read_byte(msg) == 0)
  2301. // End of the message.
  2302. break;
  2303. lcd.setCursor(0, row);
  2304. uint8_t linelen = min(strlen_P(msg), 20);
  2305. const char *msgend2 = msg + linelen;
  2306. msgend = msgend2;
  2307. if (row == 3 && linelen == 20) {
  2308. // Last line of the display, full line shall be displayed.
  2309. // Find out, whether this message will be split into multiple screens.
  2310. while (pgm_is_whitespace(msgend))
  2311. ++ msgend;
  2312. multi_screen = pgm_read_byte(msgend) != 0;
  2313. if (multi_screen)
  2314. msgend = (msgend2 -= 2);
  2315. }
  2316. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2317. // Splitting a word. Find the start of the current word.
  2318. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2319. -- msgend;
  2320. if (msgend == msg)
  2321. // Found a single long word, which cannot be split. Just cut it.
  2322. msgend = msgend2;
  2323. }
  2324. for (; msg < msgend; ++ msg) {
  2325. char c = char(pgm_read_byte(msg));
  2326. if (c == '~')
  2327. c = ' ';
  2328. lcd.print(c);
  2329. }
  2330. }
  2331. if (multi_screen) {
  2332. // Display the "next screen" indicator character.
  2333. // lcd_set_custom_characters_arrows();
  2334. lcd_set_custom_characters_nextpage();
  2335. lcd.setCursor(19, 3);
  2336. // Display the down arrow.
  2337. lcd.print(char(1));
  2338. }
  2339. nlines = row;
  2340. return multi_screen ? msgend : NULL;
  2341. }
  2342. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2343. {
  2344. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2345. bool multi_screen = msg_next != NULL;
  2346. lcd_set_custom_characters_nextpage();
  2347. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2348. // Until confirmed by a button click.
  2349. for (;;) {
  2350. if (!multi_screen) {
  2351. lcd.setCursor(19, 3);
  2352. // Display the confirm char.
  2353. lcd.print(char(2));
  2354. }
  2355. // Wait for 5 seconds before displaying the next text.
  2356. for (uint8_t i = 0; i < 100; ++ i) {
  2357. delay_keep_alive(50);
  2358. if (lcd_clicked()) {
  2359. while (lcd_clicked()) ;
  2360. delay(10);
  2361. while (lcd_clicked()) ;
  2362. if (msg_next == NULL) {
  2363. KEEPALIVE_STATE(IN_HANDLER);
  2364. lcd_set_custom_characters();
  2365. lcd_update_enable(true);
  2366. lcd_update(2);
  2367. return;
  2368. }
  2369. else {
  2370. break;
  2371. }
  2372. }
  2373. }
  2374. if (multi_screen) {
  2375. if (msg_next == NULL)
  2376. msg_next = msg;
  2377. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2378. if (msg_next == NULL) {
  2379. lcd.setCursor(19, 3);
  2380. // Display the confirm char.
  2381. lcd.print(char(2));
  2382. }
  2383. }
  2384. }
  2385. }
  2386. void lcd_wait_for_click()
  2387. {
  2388. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2389. for (;;) {
  2390. manage_heater();
  2391. manage_inactivity(true);
  2392. if (lcd_clicked()) {
  2393. while (lcd_clicked()) ;
  2394. delay(10);
  2395. while (lcd_clicked()) ;
  2396. KEEPALIVE_STATE(IN_HANDLER);
  2397. return;
  2398. }
  2399. }
  2400. }
  2401. 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)
  2402. {
  2403. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2404. bool multi_screen = msg_next != NULL;
  2405. bool yes = default_yes ? true : false;
  2406. // Wait for user confirmation or a timeout.
  2407. unsigned long previous_millis_cmd = millis();
  2408. int8_t enc_dif = encoderDiff;
  2409. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2410. for (;;) {
  2411. for (uint8_t i = 0; i < 100; ++i) {
  2412. delay_keep_alive(50);
  2413. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2414. return -1;
  2415. manage_heater();
  2416. manage_inactivity(true);
  2417. if (abs(enc_dif - encoderDiff) > 4) {
  2418. if (msg_next == NULL) {
  2419. lcd.setCursor(0, 3);
  2420. if (enc_dif < encoderDiff && yes) {
  2421. lcd_printPGM((PSTR(" ")));
  2422. lcd.setCursor(7, 3);
  2423. lcd_printPGM((PSTR(">")));
  2424. yes = false;
  2425. }
  2426. else if (enc_dif > encoderDiff && !yes) {
  2427. lcd_printPGM((PSTR(">")));
  2428. lcd.setCursor(7, 3);
  2429. lcd_printPGM((PSTR(" ")));
  2430. yes = true;
  2431. }
  2432. enc_dif = encoderDiff;
  2433. }
  2434. else {
  2435. break; //turning knob skips waiting loop
  2436. }
  2437. }
  2438. if (lcd_clicked()) {
  2439. while (lcd_clicked());
  2440. delay(10);
  2441. while (lcd_clicked());
  2442. if (msg_next == NULL) {
  2443. //KEEPALIVE_STATE(IN_HANDLER);
  2444. lcd_set_custom_characters();
  2445. return yes;
  2446. }
  2447. else break;
  2448. }
  2449. }
  2450. if (multi_screen) {
  2451. if (msg_next == NULL) {
  2452. msg_next = msg;
  2453. }
  2454. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2455. }
  2456. if (msg_next == NULL) {
  2457. lcd.setCursor(0, 3);
  2458. if (yes) lcd_printPGM(PSTR(">"));
  2459. lcd.setCursor(1, 3);
  2460. lcd_printPGM(MSG_YES);
  2461. lcd.setCursor(7, 3);
  2462. if (!yes) lcd_printPGM(PSTR(">"));
  2463. lcd.setCursor(8, 3);
  2464. lcd_printPGM(MSG_NO);
  2465. }
  2466. }
  2467. }
  2468. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2469. {
  2470. lcd_display_message_fullscreen_P(msg);
  2471. if (default_yes) {
  2472. lcd.setCursor(0, 2);
  2473. lcd_printPGM(PSTR(">"));
  2474. lcd_printPGM(MSG_YES);
  2475. lcd.setCursor(1, 3);
  2476. lcd_printPGM(MSG_NO);
  2477. }
  2478. else {
  2479. lcd.setCursor(1, 2);
  2480. lcd_printPGM(MSG_YES);
  2481. lcd.setCursor(0, 3);
  2482. lcd_printPGM(PSTR(">"));
  2483. lcd_printPGM(MSG_NO);
  2484. }
  2485. bool yes = default_yes ? true : false;
  2486. // Wait for user confirmation or a timeout.
  2487. unsigned long previous_millis_cmd = millis();
  2488. int8_t enc_dif = encoderDiff;
  2489. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2490. for (;;) {
  2491. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2492. return -1;
  2493. manage_heater();
  2494. manage_inactivity(true);
  2495. if (abs(enc_dif - encoderDiff) > 4) {
  2496. lcd.setCursor(0, 2);
  2497. if (enc_dif < encoderDiff && yes) {
  2498. lcd_printPGM((PSTR(" ")));
  2499. lcd.setCursor(0, 3);
  2500. lcd_printPGM((PSTR(">")));
  2501. yes = false;
  2502. }
  2503. else if (enc_dif > encoderDiff && !yes) {
  2504. lcd_printPGM((PSTR(">")));
  2505. lcd.setCursor(0, 3);
  2506. lcd_printPGM((PSTR(" ")));
  2507. yes = true;
  2508. }
  2509. enc_dif = encoderDiff;
  2510. }
  2511. if (lcd_clicked()) {
  2512. while (lcd_clicked());
  2513. delay(10);
  2514. while (lcd_clicked());
  2515. KEEPALIVE_STATE(IN_HANDLER);
  2516. return yes;
  2517. }
  2518. }
  2519. }
  2520. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2521. {
  2522. const char *msg = NULL;
  2523. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2524. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  2525. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2526. if (point_too_far_mask == 0)
  2527. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  2528. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2529. // Only the center point or all the three front points.
  2530. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  2531. else if (point_too_far_mask & 1 == 0)
  2532. // The right and maybe the center point out of reach.
  2533. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  2534. else
  2535. // The left and maybe the center point out of reach.
  2536. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  2537. lcd_show_fullscreen_message_and_wait_P(msg);
  2538. } else {
  2539. if (point_too_far_mask != 0) {
  2540. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2541. // Only the center point or all the three front points.
  2542. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  2543. else if (point_too_far_mask & 1 == 0)
  2544. // The right and maybe the center point out of reach.
  2545. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  2546. else
  2547. // The left and maybe the center point out of reach.
  2548. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  2549. lcd_show_fullscreen_message_and_wait_P(msg);
  2550. }
  2551. if (point_too_far_mask == 0 || result > 0) {
  2552. switch (result) {
  2553. default:
  2554. // should not happen
  2555. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  2556. break;
  2557. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2558. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  2559. break;
  2560. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2561. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  2562. break;
  2563. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2564. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  2565. break;
  2566. }
  2567. lcd_show_fullscreen_message_and_wait_P(msg);
  2568. }
  2569. }
  2570. }
  2571. static void lcd_show_end_stops() {
  2572. lcd.setCursor(0, 0);
  2573. lcd_printPGM((PSTR("End stops diag")));
  2574. lcd.setCursor(0, 1);
  2575. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  2576. lcd.setCursor(0, 2);
  2577. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  2578. lcd.setCursor(0, 3);
  2579. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  2580. }
  2581. static void menu_show_end_stops() {
  2582. lcd_show_end_stops();
  2583. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  2584. }
  2585. // Lets the user move the Z carriage up to the end stoppers.
  2586. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2587. // Otherwise the Z calibration is not changed and false is returned.
  2588. void lcd_diag_show_end_stops()
  2589. {
  2590. int enc_dif = encoderDiff;
  2591. lcd_implementation_clear();
  2592. for (;;) {
  2593. manage_heater();
  2594. manage_inactivity(true);
  2595. lcd_show_end_stops();
  2596. if (lcd_clicked()) {
  2597. while (lcd_clicked()) ;
  2598. delay(10);
  2599. while (lcd_clicked()) ;
  2600. break;
  2601. }
  2602. }
  2603. lcd_implementation_clear();
  2604. lcd_return_to_status();
  2605. }
  2606. void prusa_statistics(int _message) {
  2607. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  2608. return;
  2609. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  2610. switch (_message)
  2611. {
  2612. case 0: // default message
  2613. if (IS_SD_PRINTING)
  2614. {
  2615. SERIAL_ECHO("{");
  2616. prusa_stat_printerstatus(4);
  2617. prusa_stat_farm_number();
  2618. prusa_stat_printinfo();
  2619. SERIAL_ECHOLN("}");
  2620. status_number = 4;
  2621. }
  2622. else
  2623. {
  2624. SERIAL_ECHO("{");
  2625. prusa_stat_printerstatus(1);
  2626. prusa_stat_farm_number();
  2627. SERIAL_ECHOLN("}");
  2628. status_number = 1;
  2629. }
  2630. break;
  2631. case 1: // 1 heating
  2632. farm_status = 2;
  2633. SERIAL_ECHO("{");
  2634. prusa_stat_printerstatus(2);
  2635. prusa_stat_farm_number();
  2636. SERIAL_ECHOLN("}");
  2637. status_number = 2;
  2638. farm_timer = 1;
  2639. break;
  2640. case 2: // heating done
  2641. farm_status = 3;
  2642. SERIAL_ECHO("{");
  2643. prusa_stat_printerstatus(3);
  2644. prusa_stat_farm_number();
  2645. SERIAL_ECHOLN("}");
  2646. status_number = 3;
  2647. farm_timer = 1;
  2648. if (IS_SD_PRINTING)
  2649. {
  2650. farm_status = 4;
  2651. SERIAL_ECHO("{");
  2652. prusa_stat_printerstatus(4);
  2653. prusa_stat_farm_number();
  2654. SERIAL_ECHOLN("}");
  2655. status_number = 4;
  2656. }
  2657. else
  2658. {
  2659. SERIAL_ECHO("{");
  2660. prusa_stat_printerstatus(3);
  2661. prusa_stat_farm_number();
  2662. SERIAL_ECHOLN("}");
  2663. status_number = 3;
  2664. }
  2665. farm_timer = 1;
  2666. break;
  2667. case 3: // filament change
  2668. break;
  2669. case 4: // print succesfull
  2670. SERIAL_ECHOLN("{[RES:1]");
  2671. prusa_stat_printerstatus(status_number);
  2672. prusa_stat_farm_number();
  2673. SERIAL_ECHOLN("}");
  2674. farm_timer = 2;
  2675. break;
  2676. case 5: // print not succesfull
  2677. SERIAL_ECHOLN("{[RES:0]");
  2678. prusa_stat_printerstatus(status_number);
  2679. prusa_stat_farm_number();
  2680. SERIAL_ECHOLN("}");
  2681. farm_timer = 2;
  2682. break;
  2683. case 6: // print done
  2684. SERIAL_ECHOLN("{[PRN:8]");
  2685. prusa_stat_farm_number();
  2686. SERIAL_ECHOLN("}");
  2687. status_number = 8;
  2688. farm_timer = 2;
  2689. break;
  2690. case 7: // print done - stopped
  2691. SERIAL_ECHOLN("{[PRN:9]");
  2692. prusa_stat_farm_number();
  2693. SERIAL_ECHOLN("}");
  2694. status_number = 9;
  2695. farm_timer = 2;
  2696. break;
  2697. case 8: // printer started
  2698. SERIAL_ECHO("{[PRN:0][PFN:");
  2699. status_number = 0;
  2700. SERIAL_ECHO(farm_no);
  2701. SERIAL_ECHOLN("]}");
  2702. farm_timer = 2;
  2703. break;
  2704. case 20: // echo farm no
  2705. SERIAL_ECHOLN("{");
  2706. prusa_stat_printerstatus(status_number);
  2707. prusa_stat_farm_number();
  2708. SERIAL_ECHOLN("}");
  2709. farm_timer = 5;
  2710. break;
  2711. case 21: // temperatures
  2712. SERIAL_ECHO("{");
  2713. prusa_stat_temperatures();
  2714. prusa_stat_farm_number();
  2715. prusa_stat_printerstatus(status_number);
  2716. SERIAL_ECHOLN("}");
  2717. break;
  2718. case 22: // waiting for filament change
  2719. SERIAL_ECHOLN("{[PRN:5]");
  2720. prusa_stat_farm_number();
  2721. SERIAL_ECHOLN("}");
  2722. status_number = 5;
  2723. break;
  2724. case 90: // Error - Thermal Runaway
  2725. SERIAL_ECHOLN("{[ERR:1]");
  2726. prusa_stat_farm_number();
  2727. SERIAL_ECHOLN("}");
  2728. break;
  2729. case 91: // Error - Thermal Runaway Preheat
  2730. SERIAL_ECHOLN("{[ERR:2]");
  2731. prusa_stat_farm_number();
  2732. SERIAL_ECHOLN("}");
  2733. break;
  2734. case 92: // Error - Min temp
  2735. SERIAL_ECHOLN("{[ERR:3]");
  2736. prusa_stat_farm_number();
  2737. SERIAL_ECHOLN("}");
  2738. break;
  2739. case 93: // Error - Max temp
  2740. SERIAL_ECHOLN("{[ERR:4]");
  2741. prusa_stat_farm_number();
  2742. SERIAL_ECHOLN("}");
  2743. break;
  2744. case 99: // heartbeat
  2745. SERIAL_ECHO("{[PRN:99]");
  2746. prusa_stat_temperatures();
  2747. SERIAL_ECHO("[PFN:");
  2748. SERIAL_ECHO(farm_no);
  2749. SERIAL_ECHO("]");
  2750. SERIAL_ECHOLN("}");
  2751. break;
  2752. }
  2753. }
  2754. static void prusa_stat_printerstatus(int _status)
  2755. {
  2756. SERIAL_ECHO("[PRN:");
  2757. SERIAL_ECHO(_status);
  2758. SERIAL_ECHO("]");
  2759. }
  2760. static void prusa_stat_farm_number() {
  2761. SERIAL_ECHO("[PFN:");
  2762. SERIAL_ECHO(farm_no);
  2763. SERIAL_ECHO("]");
  2764. }
  2765. static void prusa_stat_temperatures()
  2766. {
  2767. SERIAL_ECHO("[ST0:");
  2768. SERIAL_ECHO(target_temperature[0]);
  2769. SERIAL_ECHO("][STB:");
  2770. SERIAL_ECHO(target_temperature_bed);
  2771. SERIAL_ECHO("][AT0:");
  2772. SERIAL_ECHO(current_temperature[0]);
  2773. SERIAL_ECHO("][ATB:");
  2774. SERIAL_ECHO(current_temperature_bed);
  2775. SERIAL_ECHO("]");
  2776. }
  2777. static void prusa_stat_printinfo()
  2778. {
  2779. SERIAL_ECHO("[TFU:");
  2780. SERIAL_ECHO(total_filament_used);
  2781. SERIAL_ECHO("][PCD:");
  2782. SERIAL_ECHO(itostr3(card.percentDone()));
  2783. SERIAL_ECHO("][FEM:");
  2784. SERIAL_ECHO(itostr3(feedmultiply));
  2785. SERIAL_ECHO("][FNM:");
  2786. SERIAL_ECHO(longFilenameOLD);
  2787. SERIAL_ECHO("][TIM:");
  2788. if (starttime != 0)
  2789. {
  2790. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  2791. }
  2792. else
  2793. {
  2794. SERIAL_ECHO(0);
  2795. }
  2796. SERIAL_ECHO("][FWR:");
  2797. SERIAL_ECHO(FW_VERSION);
  2798. SERIAL_ECHO("]");
  2799. }
  2800. /*
  2801. void lcd_pick_babystep(){
  2802. int enc_dif = 0;
  2803. int cursor_pos = 1;
  2804. int fsm = 0;
  2805. lcd_implementation_clear();
  2806. lcd.setCursor(0, 0);
  2807. lcd_printPGM(MSG_PICK_Z);
  2808. lcd.setCursor(3, 2);
  2809. lcd.print("1");
  2810. lcd.setCursor(3, 3);
  2811. lcd.print("2");
  2812. lcd.setCursor(12, 2);
  2813. lcd.print("3");
  2814. lcd.setCursor(12, 3);
  2815. lcd.print("4");
  2816. lcd.setCursor(1, 2);
  2817. lcd.print(">");
  2818. enc_dif = encoderDiff;
  2819. while (fsm == 0) {
  2820. manage_heater();
  2821. manage_inactivity(true);
  2822. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2823. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2824. if (enc_dif > encoderDiff ) {
  2825. cursor_pos --;
  2826. }
  2827. if (enc_dif < encoderDiff ) {
  2828. cursor_pos ++;
  2829. }
  2830. if (cursor_pos > 4) {
  2831. cursor_pos = 4;
  2832. }
  2833. if (cursor_pos < 1) {
  2834. cursor_pos = 1;
  2835. }
  2836. lcd.setCursor(1, 2);
  2837. lcd.print(" ");
  2838. lcd.setCursor(1, 3);
  2839. lcd.print(" ");
  2840. lcd.setCursor(10, 2);
  2841. lcd.print(" ");
  2842. lcd.setCursor(10, 3);
  2843. lcd.print(" ");
  2844. if (cursor_pos < 3) {
  2845. lcd.setCursor(1, cursor_pos+1);
  2846. lcd.print(">");
  2847. }else{
  2848. lcd.setCursor(10, cursor_pos-1);
  2849. lcd.print(">");
  2850. }
  2851. enc_dif = encoderDiff;
  2852. delay(100);
  2853. }
  2854. }
  2855. if (lcd_clicked()) {
  2856. fsm = cursor_pos;
  2857. int babyStepZ;
  2858. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  2859. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  2860. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2861. delay(500);
  2862. }
  2863. };
  2864. lcd_implementation_clear();
  2865. lcd_return_to_status();
  2866. }
  2867. */
  2868. void lcd_move_menu_axis()
  2869. {
  2870. START_MENU();
  2871. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2872. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  2873. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  2874. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  2875. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  2876. END_MENU();
  2877. }
  2878. static void lcd_move_menu_1mm()
  2879. {
  2880. move_menu_scale = 1.0;
  2881. lcd_move_menu_axis();
  2882. }
  2883. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  2884. {
  2885. do
  2886. {
  2887. eeprom_write_byte((unsigned char*)pos, *value);
  2888. pos++;
  2889. value++;
  2890. } while (--size);
  2891. }
  2892. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  2893. {
  2894. do
  2895. {
  2896. *value = eeprom_read_byte((unsigned char*)pos);
  2897. pos++;
  2898. value++;
  2899. } while (--size);
  2900. }
  2901. #ifdef SDCARD_SORT_ALPHA
  2902. static void lcd_sort_type_set() {
  2903. uint8_t sdSort;
  2904. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  2905. switch (sdSort) {
  2906. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  2907. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  2908. default: sdSort = SD_SORT_TIME;
  2909. }
  2910. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  2911. presort_flag = true;
  2912. lcd_goto_menu(lcd_settings_menu, 8);
  2913. }
  2914. #endif //SDCARD_SORT_ALPHA
  2915. #ifdef TMC2130
  2916. static void lcd_crash_mode_info()
  2917. {
  2918. lcd_update_enable(true);
  2919. static uint32_t tim = 0;
  2920. if ((tim + 1000) < millis())
  2921. {
  2922. fputs_P(MSG_CRASH_DET_ONLY_IN_NORMAL, lcdout);
  2923. tim = millis();
  2924. }
  2925. if (lcd_clicked())
  2926. {
  2927. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 18);
  2928. else lcd_goto_menu(lcd_settings_menu, 16, true, true);
  2929. }
  2930. }
  2931. static void lcd_crash_mode_info2()
  2932. {
  2933. lcd_update_enable(true);
  2934. static uint32_t tim = 0;
  2935. if ((tim + 1000) < millis())
  2936. {
  2937. fputs_P(MSG_CRASH_DET_STEALTH_FORCE_OFF, lcdout);
  2938. tim = millis();
  2939. }
  2940. if (lcd_clicked())
  2941. {
  2942. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 16);
  2943. else lcd_goto_menu(lcd_settings_menu, 14, true, true);
  2944. }
  2945. }
  2946. #endif //TMC2130
  2947. #ifdef PAT9125
  2948. static void lcd_filament_autoload_info()
  2949. {
  2950. lcd_show_fullscreen_message_and_wait_P(MSG_AUTOLOADING_ONLY_IF_FSENS_ON);
  2951. }
  2952. static void lcd_fsensor_fail()
  2953. {
  2954. lcd_show_fullscreen_message_and_wait_P(MSG_FSENS_NOT_RESPONDING);
  2955. }
  2956. #endif //PAT9125
  2957. static void lcd_silent_mode_set() {
  2958. switch (SilentModeMenu) {
  2959. case 0: SilentModeMenu = 1; break;
  2960. case 1: SilentModeMenu = 2; break;
  2961. case 2: SilentModeMenu = 0; break;
  2962. default: SilentModeMenu = 0; break;
  2963. }
  2964. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  2965. #ifdef TMC2130
  2966. // Wait until the planner queue is drained and the stepper routine achieves
  2967. // an idle state.
  2968. st_synchronize();
  2969. if (tmc2130_wait_standstill_xy(1000)) {}
  2970. // MYSERIAL.print("standstill OK");
  2971. // else
  2972. // MYSERIAL.print("standstill NG!");
  2973. cli();
  2974. tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  2975. tmc2130_init();
  2976. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  2977. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  2978. st_reset_timer();
  2979. sei();
  2980. #endif //TMC2130
  2981. digipot_init();
  2982. #ifdef TMC2130
  2983. if (CrashDetectMenu && SilentModeMenu)
  2984. lcd_goto_menu(lcd_crash_mode_info2);
  2985. #endif //TMC2130
  2986. }
  2987. #ifdef TMC2130
  2988. static void lcd_crash_mode_set()
  2989. {
  2990. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  2991. if (CrashDetectMenu==0) {
  2992. crashdet_disable();
  2993. }else{
  2994. crashdet_enable();
  2995. }
  2996. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 9);
  2997. else lcd_goto_menu(lcd_settings_menu, 9);
  2998. }
  2999. #endif //TMC2130
  3000. static void lcd_set_lang(unsigned char lang) {
  3001. lang_selected = lang;
  3002. firstrun = 1;
  3003. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  3004. /*langsel=0;*/
  3005. if (langsel == LANGSEL_MODAL)
  3006. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  3007. langsel = LANGSEL_ACTIVE;
  3008. }
  3009. #ifdef PAT9125
  3010. static void lcd_fsensor_state_set()
  3011. {
  3012. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3013. if (FSensorStateMenu==0) {
  3014. fsensor_disable();
  3015. if ((filament_autoload_enabled == true)){
  3016. lcd_filament_autoload_info();
  3017. }
  3018. }else{
  3019. fsensor_enable();
  3020. if (fsensor_not_responding)
  3021. {
  3022. lcd_fsensor_fail();
  3023. }
  3024. }
  3025. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 7);
  3026. else lcd_goto_menu(lcd_settings_menu, 7);
  3027. }
  3028. #endif //PAT9125
  3029. #if !SDSORT_USES_RAM
  3030. void lcd_set_degree() {
  3031. lcd_set_custom_characters_degree();
  3032. }
  3033. void lcd_set_progress() {
  3034. lcd_set_custom_characters_progress();
  3035. }
  3036. #endif
  3037. void lcd_force_language_selection() {
  3038. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  3039. }
  3040. static void lcd_language_menu()
  3041. {
  3042. START_MENU();
  3043. if (langsel == LANGSEL_OFF) {
  3044. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  3045. } else if (langsel == LANGSEL_ACTIVE) {
  3046. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  3047. }
  3048. for (int i=0;i<LANG_NUM;i++){
  3049. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  3050. }
  3051. END_MENU();
  3052. }
  3053. void lcd_mesh_bedleveling()
  3054. {
  3055. mesh_bed_run_from_menu = true;
  3056. enquecommand_P(PSTR("G80"));
  3057. lcd_return_to_status();
  3058. }
  3059. void lcd_mesh_calibration()
  3060. {
  3061. enquecommand_P(PSTR("M45"));
  3062. lcd_return_to_status();
  3063. }
  3064. void lcd_mesh_calibration_z()
  3065. {
  3066. enquecommand_P(PSTR("M45 Z"));
  3067. lcd_return_to_status();
  3068. }
  3069. void lcd_pinda_calibration_menu()
  3070. {
  3071. START_MENU();
  3072. MENU_ITEM(back, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  3073. MENU_ITEM(submenu, MSG_CALIBRATE_PINDA, lcd_calibrate_pinda);
  3074. END_MENU();
  3075. }
  3076. void lcd_temp_calibration_set() {
  3077. temp_cal_active = !temp_cal_active;
  3078. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3079. digipot_init();
  3080. lcd_goto_menu(lcd_settings_menu, 10);
  3081. }
  3082. void lcd_second_serial_set() {
  3083. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3084. else selectedSerialPort = 1;
  3085. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3086. MYSERIAL.begin(BAUDRATE);
  3087. lcd_goto_menu(lcd_settings_menu, 11);
  3088. }
  3089. void lcd_calibrate_pinda() {
  3090. enquecommand_P(PSTR("G76"));
  3091. lcd_return_to_status();
  3092. }
  3093. #ifndef SNMM
  3094. /*void lcd_calibrate_extruder() {
  3095. if (degHotend0() > EXTRUDE_MINTEMP)
  3096. {
  3097. current_position[E_AXIS] = 0; //set initial position to zero
  3098. plan_set_e_position(current_position[E_AXIS]);
  3099. //long steps_start = st_get_position(E_AXIS);
  3100. long steps_final;
  3101. float e_steps_per_unit;
  3102. 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)
  3103. 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
  3104. const char *msg_e_cal_knob = MSG_E_CAL_KNOB;
  3105. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3106. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3107. unsigned long msg_millis;
  3108. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  3109. lcd_implementation_clear();
  3110. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  3111. current_position[E_AXIS] += e_shift_calibration;
  3112. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3113. st_synchronize();
  3114. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3115. msg_millis = millis();
  3116. while (!LCD_CLICKED) {
  3117. if (multi_screen && millis() - msg_millis > 5000) {
  3118. if (msg_next_e_cal_knob == NULL)
  3119. msg_next_e_cal_knob = msg_e_cal_knob;
  3120. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3121. msg_millis = millis();
  3122. }
  3123. //manage_inactivity(true);
  3124. manage_heater();
  3125. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3126. delay_keep_alive(50);
  3127. //previous_millis_cmd = millis();
  3128. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3129. encoderDiff = 0;
  3130. if (!planner_queue_full()) {
  3131. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3132. encoderPosition = 0;
  3133. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3134. }
  3135. }
  3136. }
  3137. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3138. //steps_final = st_get_position(E_AXIS);
  3139. lcdDrawUpdate = 1;
  3140. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3141. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3142. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3143. lcd_implementation_clear();
  3144. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3145. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3146. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3147. //delay_keep_alive(2000);
  3148. delay_keep_alive(500);
  3149. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  3150. lcd_update_enable(true);
  3151. lcdDrawUpdate = 2;
  3152. }
  3153. else
  3154. {
  3155. lcd_implementation_clear();
  3156. lcd.setCursor(0, 0);
  3157. lcd_printPGM(MSG_ERROR);
  3158. lcd.setCursor(0, 2);
  3159. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  3160. delay(2000);
  3161. lcd_implementation_clear();
  3162. }
  3163. lcd_return_to_status();
  3164. }
  3165. void lcd_extr_cal_reset() {
  3166. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3167. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3168. //extrudemultiply = 100;
  3169. enquecommand_P(PSTR("M500"));
  3170. }*/
  3171. #endif
  3172. void lcd_toshiba_flash_air_compatibility_toggle()
  3173. {
  3174. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3175. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3176. }
  3177. void lcd_v2_calibration() {
  3178. bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_PLA_FILAMENT_LOADED, false, true);
  3179. if (loaded) {
  3180. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3181. }
  3182. else {
  3183. lcd_display_message_fullscreen_P(MSG_PLEASE_LOAD_PLA);
  3184. for (int i = 0; i < 20; i++) { //wait max. 2s
  3185. delay_keep_alive(100);
  3186. if (lcd_clicked()) {
  3187. while (lcd_clicked());
  3188. delay(10);
  3189. while (lcd_clicked());
  3190. break;
  3191. }
  3192. }
  3193. }
  3194. lcd_return_to_status();
  3195. lcd_update_enable(true);
  3196. }
  3197. void lcd_wizard() {
  3198. bool result = true;
  3199. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3200. result = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_RERUN, false, false);
  3201. }
  3202. if (result) {
  3203. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3204. lcd_wizard(0);
  3205. }
  3206. else {
  3207. lcd_return_to_status();
  3208. lcd_update_enable(true);
  3209. lcd_update(2);
  3210. }
  3211. }
  3212. void lcd_wizard(int state) {
  3213. bool end = false;
  3214. int wizard_event;
  3215. const char *msg = NULL;
  3216. while (!end) {
  3217. switch (state) {
  3218. case 0: // run wizard?
  3219. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_WELCOME, false, true);
  3220. if (wizard_event) {
  3221. state = 1;
  3222. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3223. }
  3224. else {
  3225. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3226. end = true;
  3227. }
  3228. break;
  3229. case 1: // restore calibration status
  3230. switch (calibration_status()) {
  3231. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3232. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3233. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3234. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3235. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3236. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3237. }
  3238. break;
  3239. case 2: //selftest
  3240. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_SELFTEST);
  3241. wizard_event = lcd_selftest();
  3242. if (wizard_event) {
  3243. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3244. state = 3;
  3245. }
  3246. else end = true;
  3247. break;
  3248. case 3: //xyz cal.
  3249. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_XYZ_CAL);
  3250. wizard_event = gcode_M45(false, 0);
  3251. if (wizard_event) state = 5;
  3252. else end = true;
  3253. break;
  3254. case 4: //z cal.
  3255. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_Z_CAL);
  3256. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_STEEL_SHEET_CHECK, false, false);
  3257. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(MSG_PLACE_STEEL_SHEET);
  3258. wizard_event = gcode_M45(true, 0);
  3259. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3260. else end = true;
  3261. break;
  3262. case 5: //is filament loaded?
  3263. //start to preheat nozzle and bed to save some time later
  3264. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3265. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3266. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_WIZARD_FILAMENT_LOADED, false);
  3267. if (wizard_event) state = 8;
  3268. else state = 6;
  3269. break;
  3270. case 6: //waiting for preheat nozzle for PLA;
  3271. #ifndef SNMM
  3272. lcd_display_message_fullscreen_P(MSG_WIZARD_WILL_PREHEAT);
  3273. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3274. 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);
  3275. delay_keep_alive(2000);
  3276. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  3277. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3278. lcd_display_message_fullscreen_P(MSG_WIZARD_HEATING);
  3279. lcd.setCursor(0, 4);
  3280. lcd.print(LCD_STR_THERMOMETER[0]);
  3281. lcd.print(ftostr3(degHotend(0)));
  3282. lcd.print("/");
  3283. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3284. lcd.print(LCD_STR_DEGREE);
  3285. lcd_set_custom_characters();
  3286. delay_keep_alive(1000);
  3287. }
  3288. #endif //not SNMM
  3289. state = 7;
  3290. break;
  3291. case 7: //load filament
  3292. #ifdef PAT9125
  3293. fsensor_block();
  3294. #endif //PAT9125
  3295. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_LOAD_FILAMENT);
  3296. lcd_update_enable(false);
  3297. lcd_implementation_clear();
  3298. lcd_print_at_PGM(0, 2, MSG_LOADING_FILAMENT);
  3299. #ifdef SNMM
  3300. change_extr(0);
  3301. #endif
  3302. gcode_M701();
  3303. #ifdef PAT9125
  3304. fsensor_unblock();
  3305. #endif //PAT9125
  3306. state = 9;
  3307. break;
  3308. case 8:
  3309. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_WIZARD_PLA_FILAMENT, false, true);
  3310. if (wizard_event) state = 9;
  3311. else end = true;
  3312. break;
  3313. case 9:
  3314. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_V2_CAL);
  3315. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_V2_CAL_2);
  3316. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3317. end = true;
  3318. break;
  3319. case 10: //repeat first layer cal.?
  3320. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_WIZARD_REPEAT_V2_CAL, false);
  3321. if (wizard_event) {
  3322. //reset status and live adjust z value in eeprom
  3323. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  3324. lcd_show_fullscreen_message_and_wait_P(MSG_WIZARD_CLEAN_HEATBED);
  3325. state = 9;
  3326. }
  3327. else {
  3328. state = 11;
  3329. }
  3330. break;
  3331. case 11: //we are finished
  3332. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3333. end = true;
  3334. break;
  3335. default: break;
  3336. }
  3337. }
  3338. SERIAL_ECHOPGM("State: ");
  3339. MYSERIAL.println(state);
  3340. switch (state) { //final message
  3341. case 0: //user dont want to use wizard
  3342. msg = MSG_WIZARD_QUIT;
  3343. break;
  3344. case 1: //printer was already calibrated
  3345. msg = MSG_WIZARD_DONE;
  3346. break;
  3347. case 2: //selftest
  3348. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3349. break;
  3350. case 3: //xyz cal.
  3351. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3352. break;
  3353. case 4: //z cal.
  3354. msg = MSG_WIZARD_CALIBRATION_FAILED;
  3355. break;
  3356. case 8:
  3357. msg = MSG_WIZARD_INSERT_CORRECT_FILAMENT;
  3358. break;
  3359. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3360. case 11: //we are finished
  3361. msg = MSG_WIZARD_DONE;
  3362. lcd_reset_alert_level();
  3363. lcd_setstatuspgm(WELCOME_MSG);
  3364. break;
  3365. default:
  3366. msg = MSG_WIZARD_QUIT;
  3367. break;
  3368. }
  3369. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3370. lcd_update_enable(true);
  3371. lcd_return_to_status();
  3372. lcd_update(2);
  3373. }
  3374. static void lcd_settings_menu()
  3375. {
  3376. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3377. START_MENU();
  3378. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3379. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  3380. if (!homing_flag)
  3381. {
  3382. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  3383. }
  3384. if (!isPrintPaused)
  3385. {
  3386. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  3387. }
  3388. if (!farm_mode) { //dont show in menu if we are in farm mode
  3389. switch (SilentModeMenu) {
  3390. case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  3391. case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
  3392. case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
  3393. default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  3394. }
  3395. }
  3396. #ifdef PAT9125
  3397. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3398. if (FSensorStateMenu == 0) {
  3399. if (fsensor_not_responding){
  3400. // Filament sensor not working
  3401. MENU_ITEM(function, MSG_FSENSOR_NA, lcd_fsensor_state_set);
  3402. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_NA, lcd_fsensor_fail);
  3403. }
  3404. else{
  3405. // Filament sensor turned off, working, no problems
  3406. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  3407. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_NA, lcd_filament_autoload_info);
  3408. }
  3409. } else {
  3410. // Filament sensor turned on, working, no problems
  3411. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  3412. if ((filament_autoload_enabled == true)) {
  3413. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_ON, lcd_set_filament_autoload);
  3414. }
  3415. else {
  3416. MENU_ITEM(function, MSG_FSENS_AUTOLOAD_OFF, lcd_set_filament_autoload);
  3417. }
  3418. }
  3419. #endif //DEBUG_DISABLE_FSENSORCHECK
  3420. #endif //PAT9125
  3421. if (fans_check_enabled == true) {
  3422. MENU_ITEM(function, MSG_FANS_CHECK_ON, lcd_set_fan_check);
  3423. }
  3424. else {
  3425. MENU_ITEM(function, MSG_FANS_CHECK_OFF, lcd_set_fan_check);
  3426. }
  3427. #ifdef TMC2130
  3428. if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  3429. else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  3430. if (SilentModeMenu == 0)
  3431. {
  3432. if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  3433. else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  3434. }
  3435. else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
  3436. #endif //TMC2130
  3437. if (temp_cal_active == false) {
  3438. MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set);
  3439. }
  3440. else {
  3441. MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
  3442. }
  3443. #ifdef HAS_SECOND_SERIAL_PORT
  3444. if (selectedSerialPort == 0) {
  3445. MENU_ITEM(function, MSG_SECOND_SERIAL_OFF, lcd_second_serial_set);
  3446. }
  3447. else {
  3448. MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set);
  3449. }
  3450. #endif //HAS_SECOND_SERIAL
  3451. if (!isPrintPaused && !homing_flag)
  3452. {
  3453. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  3454. }
  3455. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  3456. if (card.ToshibaFlashAir_isEnabled()) {
  3457. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  3458. } else {
  3459. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  3460. }
  3461. #ifdef SDCARD_SORT_ALPHA
  3462. if (!farm_mode) {
  3463. uint8_t sdSort;
  3464. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3465. switch (sdSort) {
  3466. case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
  3467. case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
  3468. default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
  3469. }
  3470. }
  3471. #endif // SDCARD_SORT_ALPHA
  3472. if (farm_mode)
  3473. {
  3474. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3475. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3476. }
  3477. END_MENU();
  3478. }
  3479. static void lcd_selftest_()
  3480. {
  3481. lcd_selftest();
  3482. }
  3483. static void lcd_calibration_menu()
  3484. {
  3485. START_MENU();
  3486. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3487. if (!isPrintPaused)
  3488. {
  3489. MENU_ITEM(function, MSG_WIZARD, lcd_wizard);
  3490. MENU_ITEM(submenu, MSG_V2_CALIBRATION, lcd_v2_calibration);
  3491. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  3492. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest_v);
  3493. #ifdef MK1BP
  3494. // MK1
  3495. // "Calibrate Z"
  3496. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  3497. #else //MK1BP
  3498. // MK2
  3499. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  3500. // "Calibrate Z" with storing the reference values to EEPROM.
  3501. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  3502. #ifndef SNMM
  3503. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  3504. #endif
  3505. // "Mesh Bed Leveling"
  3506. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  3507. #endif //MK1BP
  3508. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  3509. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  3510. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  3511. #ifndef MK1BP
  3512. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  3513. #endif //MK1BP
  3514. #ifndef SNMM
  3515. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3516. #endif
  3517. #ifndef MK1BP
  3518. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  3519. #endif //MK1BP
  3520. }
  3521. END_MENU();
  3522. }
  3523. /*
  3524. void lcd_mylang_top(int hlaska) {
  3525. lcd.setCursor(0,0);
  3526. lcd.print(" ");
  3527. lcd.setCursor(0,0);
  3528. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  3529. }
  3530. void lcd_mylang_drawmenu(int cursor) {
  3531. int first = 0;
  3532. if (cursor>2) first = cursor-2;
  3533. if (cursor==LANG_NUM) first = LANG_NUM-3;
  3534. lcd.setCursor(0, 1);
  3535. lcd.print(" ");
  3536. lcd.setCursor(1, 1);
  3537. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  3538. lcd.setCursor(0, 2);
  3539. lcd.print(" ");
  3540. lcd.setCursor(1, 2);
  3541. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  3542. lcd.setCursor(0, 3);
  3543. lcd.print(" ");
  3544. lcd.setCursor(1, 3);
  3545. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  3546. if (cursor==1) lcd.setCursor(0, 1);
  3547. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3548. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3549. lcd.print(">");
  3550. if (cursor<LANG_NUM-1) {
  3551. lcd.setCursor(19,3);
  3552. lcd.print("\x01");
  3553. }
  3554. if (cursor>2) {
  3555. lcd.setCursor(19,1);
  3556. lcd.print("^");
  3557. }
  3558. }
  3559. */
  3560. void lcd_mylang_drawmenu(int cursor) {
  3561. int first = 0;
  3562. if (cursor>3) first = cursor-3;
  3563. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  3564. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  3565. lcd.setCursor(0, 0);
  3566. lcd.print(" ");
  3567. lcd.setCursor(1, 0);
  3568. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  3569. lcd.setCursor(0, 1);
  3570. lcd.print(" ");
  3571. lcd.setCursor(1, 1);
  3572. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  3573. lcd.setCursor(0, 2);
  3574. lcd.print(" ");
  3575. if (LANG_NUM > 2){
  3576. lcd.setCursor(1, 2);
  3577. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  3578. }
  3579. lcd.setCursor(0, 3);
  3580. lcd.print(" ");
  3581. if (LANG_NUM>3) {
  3582. lcd.setCursor(1, 3);
  3583. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  3584. }
  3585. if (cursor==1) lcd.setCursor(0, 0);
  3586. if (cursor==2) lcd.setCursor(0, 1);
  3587. if (cursor>2) lcd.setCursor(0, 2);
  3588. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  3589. lcd.print(">");
  3590. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  3591. lcd.setCursor(19,3);
  3592. lcd.print("\x01");
  3593. }
  3594. if (cursor>3 && LANG_NUM>4) {
  3595. lcd.setCursor(19,0);
  3596. lcd.print("^");
  3597. }
  3598. }
  3599. void lcd_mylang_drawcursor(int cursor) {
  3600. if (cursor==1) lcd.setCursor(0, 1);
  3601. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3602. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3603. lcd.print(">");
  3604. }
  3605. void lcd_mylang() {
  3606. int enc_dif = 0;
  3607. int cursor_pos = 1;
  3608. lang_selected=255;
  3609. int hlaska=1;
  3610. int counter=0;
  3611. lcd_set_custom_characters_arrows();
  3612. lcd_implementation_clear();
  3613. //lcd_mylang_top(hlaska);
  3614. lcd_mylang_drawmenu(cursor_pos);
  3615. enc_dif = encoderDiff;
  3616. while ( (lang_selected == 255) ) {
  3617. manage_heater();
  3618. manage_inactivity(true);
  3619. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  3620. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  3621. if (enc_dif > encoderDiff ) {
  3622. cursor_pos --;
  3623. }
  3624. if (enc_dif < encoderDiff ) {
  3625. cursor_pos ++;
  3626. }
  3627. if (cursor_pos > LANG_NUM) {
  3628. cursor_pos = LANG_NUM;
  3629. }
  3630. if (cursor_pos < 1) {
  3631. cursor_pos = 1;
  3632. }
  3633. lcd_mylang_drawmenu(cursor_pos);
  3634. enc_dif = encoderDiff;
  3635. delay(100);
  3636. //}
  3637. } else delay(20);
  3638. if (lcd_clicked()) {
  3639. lcd_set_lang(cursor_pos-1);
  3640. delay(500);
  3641. }
  3642. /*
  3643. if (++counter == 80) {
  3644. hlaska++;
  3645. if(hlaska>LANG_NUM) hlaska=1;
  3646. lcd_mylang_top(hlaska);
  3647. lcd_mylang_drawcursor(cursor_pos);
  3648. counter=0;
  3649. }
  3650. */
  3651. };
  3652. if(MYSERIAL.available() > 1){
  3653. lang_selected = 0;
  3654. firstrun = 0;
  3655. }
  3656. lcd_set_custom_characters_degree();
  3657. lcd_implementation_clear();
  3658. lcd_return_to_status();
  3659. }
  3660. void bowden_menu() {
  3661. int enc_dif = encoderDiff;
  3662. int cursor_pos = 0;
  3663. lcd_implementation_clear();
  3664. lcd.setCursor(0, 0);
  3665. lcd.print(">");
  3666. for (int i = 0; i < 4; i++) {
  3667. lcd.setCursor(1, i);
  3668. lcd.print("Extruder ");
  3669. lcd.print(i);
  3670. lcd.print(": ");
  3671. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3672. lcd.print(bowden_length[i] - 48);
  3673. }
  3674. enc_dif = encoderDiff;
  3675. while (1) {
  3676. manage_heater();
  3677. manage_inactivity(true);
  3678. if (abs((enc_dif - encoderDiff)) > 2) {
  3679. if (enc_dif > encoderDiff) {
  3680. cursor_pos--;
  3681. }
  3682. if (enc_dif < encoderDiff) {
  3683. cursor_pos++;
  3684. }
  3685. if (cursor_pos > 3) {
  3686. cursor_pos = 3;
  3687. }
  3688. if (cursor_pos < 0) {
  3689. cursor_pos = 0;
  3690. }
  3691. lcd.setCursor(0, 0);
  3692. lcd.print(" ");
  3693. lcd.setCursor(0, 1);
  3694. lcd.print(" ");
  3695. lcd.setCursor(0, 2);
  3696. lcd.print(" ");
  3697. lcd.setCursor(0, 3);
  3698. lcd.print(" ");
  3699. lcd.setCursor(0, cursor_pos);
  3700. lcd.print(">");
  3701. enc_dif = encoderDiff;
  3702. delay(100);
  3703. }
  3704. if (lcd_clicked()) {
  3705. while (lcd_clicked());
  3706. delay(10);
  3707. while (lcd_clicked());
  3708. lcd_implementation_clear();
  3709. while (1) {
  3710. manage_heater();
  3711. manage_inactivity(true);
  3712. lcd.setCursor(1, 1);
  3713. lcd.print("Extruder ");
  3714. lcd.print(cursor_pos);
  3715. lcd.print(": ");
  3716. lcd.setCursor(13, 1);
  3717. lcd.print(bowden_length[cursor_pos] - 48);
  3718. if (abs((enc_dif - encoderDiff)) > 2) {
  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. if (enc_dif < encoderDiff) {
  3726. bowden_length[cursor_pos]++;
  3727. lcd.setCursor(13, 1);
  3728. lcd.print(bowden_length[cursor_pos] - 48);
  3729. enc_dif = encoderDiff;
  3730. }
  3731. }
  3732. delay(100);
  3733. if (lcd_clicked()) {
  3734. while (lcd_clicked());
  3735. delay(10);
  3736. while (lcd_clicked());
  3737. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  3738. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  3739. lcd_update_enable(true);
  3740. lcd_implementation_clear();
  3741. enc_dif = encoderDiff;
  3742. lcd.setCursor(0, cursor_pos);
  3743. lcd.print(">");
  3744. for (int i = 0; i < 4; i++) {
  3745. lcd.setCursor(1, i);
  3746. lcd.print("Extruder ");
  3747. lcd.print(i);
  3748. lcd.print(": ");
  3749. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3750. lcd.print(bowden_length[i] - 48);
  3751. }
  3752. break;
  3753. }
  3754. else return;
  3755. }
  3756. }
  3757. }
  3758. }
  3759. }
  3760. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  3761. lcd_implementation_clear();
  3762. lcd_print_at_PGM(0,0,MSG_UNLOAD_FILAMENT); lcd.print(":");
  3763. lcd.setCursor(0, 1); lcd.print(">");
  3764. lcd_print_at_PGM(1,1,MSG_ALL);
  3765. lcd_print_at_PGM(1,2,MSG_USED);
  3766. lcd_print_at_PGM(1,3,MSG_CURRENT);
  3767. char cursor_pos = 1;
  3768. int enc_dif = 0;
  3769. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3770. while (1) {
  3771. manage_heater();
  3772. manage_inactivity(true);
  3773. if (abs((enc_dif - encoderDiff)) > 4) {
  3774. if ((abs(enc_dif - encoderDiff)) > 1) {
  3775. if (enc_dif > encoderDiff) cursor_pos--;
  3776. if (enc_dif < encoderDiff) cursor_pos++;
  3777. if (cursor_pos > 3) cursor_pos = 3;
  3778. if (cursor_pos < 1) cursor_pos = 1;
  3779. lcd.setCursor(0, 1);
  3780. lcd.print(" ");
  3781. lcd.setCursor(0, 2);
  3782. lcd.print(" ");
  3783. lcd.setCursor(0, 3);
  3784. lcd.print(" ");
  3785. lcd.setCursor(0, cursor_pos);
  3786. lcd.print(">");
  3787. enc_dif = encoderDiff;
  3788. delay(100);
  3789. }
  3790. }
  3791. if (lcd_clicked()) {
  3792. while (lcd_clicked());
  3793. delay(10);
  3794. while (lcd_clicked());
  3795. KEEPALIVE_STATE(IN_HANDLER);
  3796. return(cursor_pos - 1);
  3797. }
  3798. }
  3799. }
  3800. char choose_extruder_menu() {
  3801. int items_no = 4;
  3802. int first = 0;
  3803. int enc_dif = 0;
  3804. char cursor_pos = 1;
  3805. enc_dif = encoderDiff;
  3806. lcd_implementation_clear();
  3807. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3808. lcd.setCursor(0, 1);
  3809. lcd.print(">");
  3810. for (int i = 0; i < 3; i++) {
  3811. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3812. }
  3813. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3814. while (1) {
  3815. for (int i = 0; i < 3; i++) {
  3816. lcd.setCursor(2 + strlen_P(MSG_EXTRUDER), i+1);
  3817. lcd.print(first + i + 1);
  3818. }
  3819. manage_heater();
  3820. manage_inactivity(true);
  3821. if (abs((enc_dif - encoderDiff)) > 4) {
  3822. if ((abs(enc_dif - encoderDiff)) > 1) {
  3823. if (enc_dif > encoderDiff) {
  3824. cursor_pos--;
  3825. }
  3826. if (enc_dif < encoderDiff) {
  3827. cursor_pos++;
  3828. }
  3829. if (cursor_pos > 3) {
  3830. cursor_pos = 3;
  3831. if (first < items_no - 3) {
  3832. first++;
  3833. lcd_implementation_clear();
  3834. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3835. for (int i = 0; i < 3; i++) {
  3836. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3837. }
  3838. }
  3839. }
  3840. if (cursor_pos < 1) {
  3841. cursor_pos = 1;
  3842. if (first > 0) {
  3843. first--;
  3844. lcd_implementation_clear();
  3845. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3846. for (int i = 0; i < 3; i++) {
  3847. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3848. }
  3849. }
  3850. }
  3851. lcd.setCursor(0, 1);
  3852. lcd.print(" ");
  3853. lcd.setCursor(0, 2);
  3854. lcd.print(" ");
  3855. lcd.setCursor(0, 3);
  3856. lcd.print(" ");
  3857. lcd.setCursor(0, cursor_pos);
  3858. lcd.print(">");
  3859. enc_dif = encoderDiff;
  3860. delay(100);
  3861. }
  3862. }
  3863. if (lcd_clicked()) {
  3864. lcd_update(2);
  3865. while (lcd_clicked());
  3866. delay(10);
  3867. while (lcd_clicked());
  3868. KEEPALIVE_STATE(IN_HANDLER);
  3869. return(cursor_pos + first - 1);
  3870. }
  3871. }
  3872. }
  3873. char reset_menu() {
  3874. #ifdef SNMM
  3875. int items_no = 5;
  3876. #else
  3877. int items_no = 4;
  3878. #endif
  3879. static int first = 0;
  3880. int enc_dif = 0;
  3881. char cursor_pos = 0;
  3882. const char *item [items_no];
  3883. item[0] = "Language";
  3884. item[1] = "Statistics";
  3885. item[2] = "Shipping prep";
  3886. item[3] = "All Data";
  3887. #ifdef SNMM
  3888. item[4] = "Bowden length";
  3889. #endif // SNMM
  3890. enc_dif = encoderDiff;
  3891. lcd_implementation_clear();
  3892. lcd.setCursor(0, 0);
  3893. lcd.print(">");
  3894. while (1) {
  3895. for (int i = 0; i < 4; i++) {
  3896. lcd.setCursor(1, i);
  3897. lcd.print(item[first + i]);
  3898. }
  3899. manage_heater();
  3900. manage_inactivity(true);
  3901. if (abs((enc_dif - encoderDiff)) > 4) {
  3902. if ((abs(enc_dif - encoderDiff)) > 1) {
  3903. if (enc_dif > encoderDiff) {
  3904. cursor_pos--;
  3905. }
  3906. if (enc_dif < encoderDiff) {
  3907. cursor_pos++;
  3908. }
  3909. if (cursor_pos > 3) {
  3910. cursor_pos = 3;
  3911. if (first < items_no - 4) {
  3912. first++;
  3913. lcd_implementation_clear();
  3914. }
  3915. }
  3916. if (cursor_pos < 0) {
  3917. cursor_pos = 0;
  3918. if (first > 0) {
  3919. first--;
  3920. lcd_implementation_clear();
  3921. }
  3922. }
  3923. lcd.setCursor(0, 0);
  3924. lcd.print(" ");
  3925. lcd.setCursor(0, 1);
  3926. lcd.print(" ");
  3927. lcd.setCursor(0, 2);
  3928. lcd.print(" ");
  3929. lcd.setCursor(0, 3);
  3930. lcd.print(" ");
  3931. lcd.setCursor(0, cursor_pos);
  3932. lcd.print(">");
  3933. enc_dif = encoderDiff;
  3934. delay(100);
  3935. }
  3936. }
  3937. if (lcd_clicked()) {
  3938. while (lcd_clicked());
  3939. delay(10);
  3940. while (lcd_clicked());
  3941. return(cursor_pos + first);
  3942. }
  3943. }
  3944. }
  3945. static void lcd_disable_farm_mode() {
  3946. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  3947. if (disable) {
  3948. enquecommand_P(PSTR("G99"));
  3949. lcd_return_to_status();
  3950. }
  3951. else {
  3952. lcd_goto_menu(lcd_settings_menu);
  3953. }
  3954. lcd_update_enable(true);
  3955. lcdDrawUpdate = 2;
  3956. }
  3957. static void lcd_ping_allert() {
  3958. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  3959. allert_timer = millis();
  3960. SET_OUTPUT(BEEPER);
  3961. for (int i = 0; i < 2; i++) {
  3962. WRITE(BEEPER, HIGH);
  3963. delay(50);
  3964. WRITE(BEEPER, LOW);
  3965. delay(100);
  3966. }
  3967. }
  3968. };
  3969. #ifdef SNMM
  3970. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  3971. set_extrude_min_temp(.0);
  3972. current_position[E_AXIS] += shift;
  3973. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  3974. set_extrude_min_temp(EXTRUDE_MINTEMP);
  3975. }
  3976. void change_extr(int extr) { //switches multiplexer for extruders
  3977. st_synchronize();
  3978. delay(100);
  3979. disable_e0();
  3980. disable_e1();
  3981. disable_e2();
  3982. #ifdef SNMM
  3983. snmm_extruder = extr;
  3984. #endif
  3985. pinMode(E_MUX0_PIN, OUTPUT);
  3986. pinMode(E_MUX1_PIN, OUTPUT);
  3987. pinMode(E_MUX2_PIN, OUTPUT);
  3988. switch (extr) {
  3989. case 1:
  3990. WRITE(E_MUX0_PIN, HIGH);
  3991. WRITE(E_MUX1_PIN, LOW);
  3992. WRITE(E_MUX2_PIN, LOW);
  3993. break;
  3994. case 2:
  3995. WRITE(E_MUX0_PIN, LOW);
  3996. WRITE(E_MUX1_PIN, HIGH);
  3997. WRITE(E_MUX2_PIN, LOW);
  3998. break;
  3999. case 3:
  4000. WRITE(E_MUX0_PIN, HIGH);
  4001. WRITE(E_MUX1_PIN, HIGH);
  4002. WRITE(E_MUX2_PIN, LOW);
  4003. break;
  4004. default:
  4005. WRITE(E_MUX0_PIN, LOW);
  4006. WRITE(E_MUX1_PIN, LOW);
  4007. WRITE(E_MUX2_PIN, LOW);
  4008. break;
  4009. }
  4010. delay(100);
  4011. }
  4012. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4013. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4014. }
  4015. void display_loading() {
  4016. switch (snmm_extruder) {
  4017. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4018. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4019. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4020. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4021. }
  4022. }
  4023. static void extr_adj(int extruder) //loading filament for SNMM
  4024. {
  4025. bool correct;
  4026. max_feedrate[E_AXIS] =80;
  4027. //max_feedrate[E_AXIS] = 50;
  4028. START:
  4029. lcd_implementation_clear();
  4030. lcd.setCursor(0, 0);
  4031. switch (extruder) {
  4032. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4033. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4034. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4035. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4036. }
  4037. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4038. do{
  4039. extr_mov(0.001,1000);
  4040. delay_keep_alive(2);
  4041. } while (!lcd_clicked());
  4042. //delay_keep_alive(500);
  4043. KEEPALIVE_STATE(IN_HANDLER);
  4044. st_synchronize();
  4045. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4046. //if (!correct) goto START;
  4047. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4048. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4049. extr_mov(bowden_length[extruder], 500);
  4050. lcd_implementation_clear();
  4051. lcd.setCursor(0, 0); lcd_printPGM(MSG_LOADING_FILAMENT);
  4052. if(strlen(MSG_LOADING_FILAMENT)>18) lcd.setCursor(0, 1);
  4053. else lcd.print(" ");
  4054. lcd.print(snmm_extruder + 1);
  4055. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4056. st_synchronize();
  4057. max_feedrate[E_AXIS] = 50;
  4058. lcd_update_enable(true);
  4059. lcd_return_to_status();
  4060. lcdDrawUpdate = 2;
  4061. }
  4062. void extr_unload() { //unloads filament
  4063. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4064. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4065. int8_t SilentMode;
  4066. if (degHotend0() > EXTRUDE_MINTEMP) {
  4067. lcd_implementation_clear();
  4068. lcd_display_message_fullscreen_P(PSTR(""));
  4069. max_feedrate[E_AXIS] = 50;
  4070. lcd.setCursor(0, 0); lcd_printPGM(MSG_UNLOADING_FILAMENT);
  4071. lcd.print(" ");
  4072. lcd.print(snmm_extruder + 1);
  4073. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4074. if (current_position[Z_AXIS] < 15) {
  4075. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4076. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4077. }
  4078. current_position[E_AXIS] += 10; //extrusion
  4079. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4080. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  4081. if (current_temperature[0] < 230) { //PLA & all other filaments
  4082. current_position[E_AXIS] += 5.4;
  4083. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4084. current_position[E_AXIS] += 3.2;
  4085. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4086. current_position[E_AXIS] += 3;
  4087. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4088. }
  4089. else { //ABS
  4090. current_position[E_AXIS] += 3.1;
  4091. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4092. current_position[E_AXIS] += 3.1;
  4093. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4094. current_position[E_AXIS] += 4;
  4095. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4096. /*current_position[X_AXIS] += 23; //delay
  4097. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4098. current_position[X_AXIS] -= 23; //delay
  4099. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4100. delay_keep_alive(4700);
  4101. }
  4102. max_feedrate[E_AXIS] = 80;
  4103. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4104. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4105. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4106. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4107. st_synchronize();
  4108. //digipot_init();
  4109. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  4110. else digipot_current(2, tmp_motor_loud[2]);
  4111. lcd_update_enable(true);
  4112. lcd_return_to_status();
  4113. max_feedrate[E_AXIS] = 50;
  4114. }
  4115. else {
  4116. lcd_implementation_clear();
  4117. lcd.setCursor(0, 0);
  4118. lcd_printPGM(MSG_ERROR);
  4119. lcd.setCursor(0, 2);
  4120. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4121. delay(2000);
  4122. lcd_implementation_clear();
  4123. }
  4124. lcd_return_to_status();
  4125. }
  4126. //wrapper functions for loading filament
  4127. static void extr_adj_0(){
  4128. change_extr(0);
  4129. extr_adj(0);
  4130. }
  4131. static void extr_adj_1() {
  4132. change_extr(1);
  4133. extr_adj(1);
  4134. }
  4135. static void extr_adj_2() {
  4136. change_extr(2);
  4137. extr_adj(2);
  4138. }
  4139. static void extr_adj_3() {
  4140. change_extr(3);
  4141. extr_adj(3);
  4142. }
  4143. static void load_all() {
  4144. for (int i = 0; i < 4; i++) {
  4145. change_extr(i);
  4146. extr_adj(i);
  4147. }
  4148. }
  4149. //wrapper functions for changing extruders
  4150. static void extr_change_0() {
  4151. change_extr(0);
  4152. lcd_return_to_status();
  4153. }
  4154. static void extr_change_1() {
  4155. change_extr(1);
  4156. lcd_return_to_status();
  4157. }
  4158. static void extr_change_2() {
  4159. change_extr(2);
  4160. lcd_return_to_status();
  4161. }
  4162. static void extr_change_3() {
  4163. change_extr(3);
  4164. lcd_return_to_status();
  4165. }
  4166. //wrapper functions for unloading filament
  4167. void extr_unload_all() {
  4168. if (degHotend0() > EXTRUDE_MINTEMP) {
  4169. for (int i = 0; i < 4; i++) {
  4170. change_extr(i);
  4171. extr_unload();
  4172. }
  4173. }
  4174. else {
  4175. lcd_implementation_clear();
  4176. lcd.setCursor(0, 0);
  4177. lcd_printPGM(MSG_ERROR);
  4178. lcd.setCursor(0, 2);
  4179. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4180. delay(2000);
  4181. lcd_implementation_clear();
  4182. lcd_return_to_status();
  4183. }
  4184. }
  4185. //unloading just used filament (for snmm)
  4186. void extr_unload_used() {
  4187. if (degHotend0() > EXTRUDE_MINTEMP) {
  4188. for (int i = 0; i < 4; i++) {
  4189. if (snmm_filaments_used & (1 << i)) {
  4190. change_extr(i);
  4191. extr_unload();
  4192. }
  4193. }
  4194. snmm_filaments_used = 0;
  4195. }
  4196. else {
  4197. lcd_implementation_clear();
  4198. lcd.setCursor(0, 0);
  4199. lcd_printPGM(MSG_ERROR);
  4200. lcd.setCursor(0, 2);
  4201. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4202. delay(2000);
  4203. lcd_implementation_clear();
  4204. lcd_return_to_status();
  4205. }
  4206. }
  4207. static void extr_unload_0() {
  4208. change_extr(0);
  4209. extr_unload();
  4210. }
  4211. static void extr_unload_1() {
  4212. change_extr(1);
  4213. extr_unload();
  4214. }
  4215. static void extr_unload_2() {
  4216. change_extr(2);
  4217. extr_unload();
  4218. }
  4219. static void extr_unload_3() {
  4220. change_extr(3);
  4221. extr_unload();
  4222. }
  4223. static void fil_load_menu()
  4224. {
  4225. START_MENU();
  4226. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4227. MENU_ITEM(function, MSG_LOAD_ALL, load_all);
  4228. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  4229. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  4230. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  4231. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  4232. END_MENU();
  4233. }
  4234. static void fil_unload_menu()
  4235. {
  4236. START_MENU();
  4237. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4238. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  4239. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  4240. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  4241. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  4242. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  4243. END_MENU();
  4244. }
  4245. static void change_extr_menu(){
  4246. START_MENU();
  4247. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4248. MENU_ITEM(function, MSG_EXTRUDER_1, extr_change_0);
  4249. MENU_ITEM(function, MSG_EXTRUDER_2, extr_change_1);
  4250. MENU_ITEM(function, MSG_EXTRUDER_3, extr_change_2);
  4251. MENU_ITEM(function, MSG_EXTRUDER_4, extr_change_3);
  4252. END_MENU();
  4253. }
  4254. #endif
  4255. static void lcd_farm_no()
  4256. {
  4257. char step = 0;
  4258. int enc_dif = 0;
  4259. int _farmno = farm_no;
  4260. int _ret = 0;
  4261. lcd_implementation_clear();
  4262. lcd.setCursor(0, 0);
  4263. lcd.print("Farm no");
  4264. do
  4265. {
  4266. if (abs((enc_dif - encoderDiff)) > 2) {
  4267. if (enc_dif > encoderDiff) {
  4268. switch (step) {
  4269. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4270. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4271. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4272. default: break;
  4273. }
  4274. }
  4275. if (enc_dif < encoderDiff) {
  4276. switch (step) {
  4277. case(0): if (_farmno < 900) _farmno += 100; break;
  4278. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4279. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4280. default: break;
  4281. }
  4282. }
  4283. enc_dif = 0;
  4284. encoderDiff = 0;
  4285. }
  4286. lcd.setCursor(0, 2);
  4287. if (_farmno < 100) lcd.print("0");
  4288. if (_farmno < 10) lcd.print("0");
  4289. lcd.print(_farmno);
  4290. lcd.print(" ");
  4291. lcd.setCursor(0, 3);
  4292. lcd.print(" ");
  4293. lcd.setCursor(step, 3);
  4294. lcd.print("^");
  4295. delay(100);
  4296. if (lcd_clicked())
  4297. {
  4298. delay(200);
  4299. step++;
  4300. if(step == 3) {
  4301. _ret = 1;
  4302. farm_no = _farmno;
  4303. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4304. prusa_statistics(20);
  4305. lcd_return_to_status();
  4306. }
  4307. }
  4308. manage_heater();
  4309. } while (_ret == 0);
  4310. }
  4311. void lcd_confirm_print()
  4312. {
  4313. int enc_dif = 0;
  4314. int cursor_pos = 1;
  4315. int _ret = 0;
  4316. int _t = 0;
  4317. lcd_implementation_clear();
  4318. lcd.setCursor(0, 0);
  4319. lcd.print("Print ok ?");
  4320. do
  4321. {
  4322. if (abs((enc_dif - encoderDiff)) > 2) {
  4323. if (enc_dif > encoderDiff) {
  4324. cursor_pos--;
  4325. }
  4326. if (enc_dif < encoderDiff) {
  4327. cursor_pos++;
  4328. }
  4329. }
  4330. if (cursor_pos > 2) { cursor_pos = 2; }
  4331. if (cursor_pos < 1) { cursor_pos = 1; }
  4332. lcd.setCursor(0, 2); lcd.print(" ");
  4333. lcd.setCursor(0, 3); lcd.print(" ");
  4334. lcd.setCursor(2, 2);
  4335. lcd_printPGM(MSG_YES);
  4336. lcd.setCursor(2, 3);
  4337. lcd_printPGM(MSG_NO);
  4338. lcd.setCursor(0, 1 + cursor_pos);
  4339. lcd.print(">");
  4340. delay(100);
  4341. _t = _t + 1;
  4342. if (_t>100)
  4343. {
  4344. prusa_statistics(99);
  4345. _t = 0;
  4346. }
  4347. if (lcd_clicked())
  4348. {
  4349. if (cursor_pos == 1)
  4350. {
  4351. _ret = 1;
  4352. prusa_statistics(20);
  4353. prusa_statistics(4);
  4354. }
  4355. if (cursor_pos == 2)
  4356. {
  4357. _ret = 2;
  4358. prusa_statistics(20);
  4359. prusa_statistics(5);
  4360. }
  4361. }
  4362. manage_heater();
  4363. manage_inactivity();
  4364. } while (_ret == 0);
  4365. }
  4366. extern bool saved_printing;
  4367. static void lcd_main_menu()
  4368. {
  4369. SDscrool = 0;
  4370. START_MENU();
  4371. // Majkl superawesome menu
  4372. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  4373. #ifdef RESUME_DEBUG
  4374. if (!saved_printing)
  4375. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  4376. else
  4377. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  4378. #endif //RESUME_DEBUG
  4379. #ifdef TMC2130_DEBUG
  4380. MENU_ITEM(function, PSTR("recover print"), recover_print);
  4381. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  4382. #endif //TMC2130_DEBUG
  4383. /* if (farm_mode && !IS_SD_PRINTING )
  4384. {
  4385. int tempScrool = 0;
  4386. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4387. //delay(100);
  4388. return; // nothing to do (so don't thrash the SD card)
  4389. uint16_t fileCnt = card.getnrfilenames();
  4390. card.getWorkDirName();
  4391. if (card.filename[0] == '/')
  4392. {
  4393. #if SDCARDDETECT == -1
  4394. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4395. #endif
  4396. } else {
  4397. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4398. }
  4399. for (uint16_t i = 0; i < fileCnt; i++)
  4400. {
  4401. if (_menuItemNr == _lineNr)
  4402. {
  4403. #ifndef SDCARD_RATHERRECENTFIRST
  4404. card.getfilename(i);
  4405. #else
  4406. card.getfilename(fileCnt - 1 - i);
  4407. #endif
  4408. if (card.filenameIsDir)
  4409. {
  4410. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4411. } else {
  4412. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4413. }
  4414. } else {
  4415. MENU_ITEM_DUMMY();
  4416. }
  4417. }
  4418. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  4419. }*/
  4420. 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)
  4421. {
  4422. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  4423. }
  4424. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4425. {
  4426. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  4427. } else
  4428. {
  4429. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  4430. }
  4431. #ifdef SDSUPPORT
  4432. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4433. {
  4434. if (card.isFileOpen())
  4435. {
  4436. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4437. if (card.sdprinting)
  4438. {
  4439. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  4440. }
  4441. else
  4442. {
  4443. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  4444. }
  4445. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4446. }
  4447. }
  4448. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4449. //MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4450. }
  4451. else
  4452. {
  4453. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4454. {
  4455. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4456. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  4457. }
  4458. #if SDCARDDETECT < 1
  4459. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  4460. #endif
  4461. }
  4462. } else
  4463. {
  4464. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  4465. #if SDCARDDETECT < 1
  4466. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  4467. #endif
  4468. }
  4469. #endif
  4470. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4471. {
  4472. if (farm_mode)
  4473. {
  4474. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  4475. }
  4476. }
  4477. else
  4478. {
  4479. #ifndef SNMM
  4480. #ifdef PAT9125
  4481. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4482. MENU_ITEM(function, MSG_AUTOLOAD_FILAMENT, lcd_LoadFilament);
  4483. else
  4484. #endif //PAT9125
  4485. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  4486. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  4487. #endif
  4488. #ifdef SNMM
  4489. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  4490. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  4491. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  4492. #endif
  4493. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  4494. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  4495. }
  4496. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4497. {
  4498. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  4499. }
  4500. #if defined(TMC2130) || defined(PAT9125)
  4501. MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats);
  4502. #endif
  4503. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  4504. END_MENU();
  4505. }
  4506. void stack_error() {
  4507. SET_OUTPUT(BEEPER);
  4508. WRITE(BEEPER, HIGH);
  4509. delay(1000);
  4510. WRITE(BEEPER, LOW);
  4511. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  4512. //err_triggered = 1;
  4513. while (1) delay_keep_alive(1000);
  4514. }
  4515. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4516. bool stepper_timer_overflow_state = false;
  4517. void stepper_timer_overflow() {
  4518. SET_OUTPUT(BEEPER);
  4519. WRITE(BEEPER, HIGH);
  4520. delay(1000);
  4521. WRITE(BEEPER, LOW);
  4522. lcd_display_message_fullscreen_P(MSG_STEPPER_TIMER_OVERFLOW_ERROR);
  4523. //err_triggered = 1;
  4524. while (1) delay_keep_alive(1000);
  4525. }
  4526. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4527. #ifdef SDSUPPORT
  4528. static void lcd_autostart_sd()
  4529. {
  4530. card.lastnr = 0;
  4531. card.setroot();
  4532. card.checkautostart(true);
  4533. }
  4534. #endif
  4535. static void lcd_silent_mode_set_tune() {
  4536. switch (SilentModeMenu) {
  4537. case 0: SilentModeMenu = 1; break;
  4538. case 1: SilentModeMenu = 2; break;
  4539. case 2: SilentModeMenu = 0; break;
  4540. default: SilentModeMenu = 0; break;
  4541. }
  4542. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  4543. digipot_init();
  4544. lcd_goto_menu(lcd_tune_menu, 9);
  4545. }
  4546. static void lcd_colorprint_change() {
  4547. enquecommand_P(PSTR("M600"));
  4548. custom_message = true;
  4549. custom_message_type = 2; //just print status message
  4550. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  4551. lcd_return_to_status();
  4552. lcdDrawUpdate = 3;
  4553. }
  4554. static void lcd_tune_menu()
  4555. {
  4556. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4557. START_MENU();
  4558. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  4559. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  4560. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4561. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4562. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  4563. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  4564. #ifdef FILAMENTCHANGEENABLE
  4565. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
  4566. #endif
  4567. #ifndef DEBUG_DISABLE_FSENSORCHECK
  4568. if (FSensorStateMenu == 0) {
  4569. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  4570. }
  4571. else {
  4572. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  4573. }
  4574. #endif //DEBUG_DISABLE_FSENSORCHECK
  4575. #ifdef TMC2130
  4576. if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  4577. else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  4578. if (SilentModeMenu == 0)
  4579. {
  4580. if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  4581. else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  4582. }
  4583. else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
  4584. #else //TMC2130
  4585. if (!farm_mode) { //dont show in menu if we are in farm mode
  4586. switch (SilentModeMenu) {
  4587. case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  4588. case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
  4589. case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
  4590. default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
  4591. }
  4592. }
  4593. #endif //TMC2130
  4594. END_MENU();
  4595. }
  4596. static void lcd_move_menu_01mm()
  4597. {
  4598. move_menu_scale = 0.1;
  4599. lcd_move_menu_axis();
  4600. }
  4601. static void lcd_control_temperature_menu()
  4602. {
  4603. #ifdef PIDTEMP
  4604. // set up temp variables - undo the default scaling
  4605. // raw_Ki = unscalePID_i(Ki);
  4606. // raw_Kd = unscalePID_d(Kd);
  4607. #endif
  4608. START_MENU();
  4609. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  4610. #if TEMP_SENSOR_0 != 0
  4611. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  4612. #endif
  4613. #if TEMP_SENSOR_1 != 0
  4614. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  4615. #endif
  4616. #if TEMP_SENSOR_2 != 0
  4617. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  4618. #endif
  4619. #if TEMP_SENSOR_BED != 0
  4620. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  4621. #endif
  4622. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  4623. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  4624. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  4625. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  4626. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  4627. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  4628. #endif
  4629. END_MENU();
  4630. }
  4631. #if SDCARDDETECT == -1
  4632. static void lcd_sd_refresh()
  4633. {
  4634. card.initsd();
  4635. currentMenuViewOffset = 0;
  4636. }
  4637. #endif
  4638. static void lcd_sd_updir()
  4639. {
  4640. SDscrool = 0;
  4641. card.updir();
  4642. currentMenuViewOffset = 0;
  4643. }
  4644. void lcd_print_stop() {
  4645. cancel_heatup = true;
  4646. #ifdef MESH_BED_LEVELING
  4647. mbl.active = false;
  4648. #endif
  4649. // Stop the stoppers, update the position from the stoppers.
  4650. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4651. planner_abort_hard();
  4652. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  4653. // Z baystep is no more applied. Reset it.
  4654. babystep_reset();
  4655. }
  4656. // Clean the input command queue.
  4657. cmdqueue_reset();
  4658. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  4659. lcd_update(2);
  4660. card.sdprinting = false;
  4661. card.closefile();
  4662. stoptime = millis();
  4663. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  4664. pause_time = 0;
  4665. save_statistics(total_filament_used, t);
  4666. lcd_return_to_status();
  4667. lcd_ignore_click(true);
  4668. lcd_commands_step = 0;
  4669. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  4670. // Turn off the print fan
  4671. SET_OUTPUT(FAN_PIN);
  4672. WRITE(FAN_PIN, 0);
  4673. fanSpeed = 0;
  4674. }
  4675. void lcd_sdcard_stop()
  4676. {
  4677. lcd.setCursor(0, 0);
  4678. lcd_printPGM(MSG_STOP_PRINT);
  4679. lcd.setCursor(2, 2);
  4680. lcd_printPGM(MSG_NO);
  4681. lcd.setCursor(2, 3);
  4682. lcd_printPGM(MSG_YES);
  4683. lcd.setCursor(0, 2); lcd.print(" ");
  4684. lcd.setCursor(0, 3); lcd.print(" ");
  4685. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  4686. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  4687. lcd.setCursor(0, 1 + encoderPosition);
  4688. lcd.print(">");
  4689. if (lcd_clicked())
  4690. {
  4691. if ((int32_t)encoderPosition == 1)
  4692. {
  4693. lcd_return_to_status();
  4694. }
  4695. if ((int32_t)encoderPosition == 2)
  4696. {
  4697. lcd_print_stop();
  4698. }
  4699. }
  4700. }
  4701. /*
  4702. void getFileDescription(char *name, char *description) {
  4703. // get file description, ie the REAL filenam, ie the second line
  4704. card.openFile(name, true);
  4705. int i = 0;
  4706. // skip the first line (which is the version line)
  4707. while (true) {
  4708. uint16_t readByte = card.get();
  4709. if (readByte == '\n') {
  4710. break;
  4711. }
  4712. }
  4713. // read the second line (which is the description line)
  4714. while (true) {
  4715. uint16_t readByte = card.get();
  4716. if (i == 0) {
  4717. // skip the first '^'
  4718. readByte = card.get();
  4719. }
  4720. description[i] = readByte;
  4721. i++;
  4722. if (readByte == '\n') {
  4723. break;
  4724. }
  4725. }
  4726. card.closefile();
  4727. description[i-1] = 0;
  4728. }
  4729. */
  4730. void lcd_sdcard_menu()
  4731. {
  4732. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  4733. int tempScrool = 0;
  4734. if (presort_flag == true) {
  4735. presort_flag = false;
  4736. card.presort();
  4737. }
  4738. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4739. //delay(100);
  4740. return; // nothing to do (so don't thrash the SD card)
  4741. uint16_t fileCnt = card.getnrfilenames();
  4742. START_MENU();
  4743. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4744. card.getWorkDirName();
  4745. if (card.filename[0] == '/')
  4746. {
  4747. #if SDCARDDETECT == -1
  4748. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4749. #endif
  4750. } else {
  4751. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4752. }
  4753. for (uint16_t i = 0; i < fileCnt; i++)
  4754. {
  4755. if (_menuItemNr == _lineNr)
  4756. {
  4757. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  4758. /*#ifdef SDCARD_RATHERRECENTFIRST
  4759. #ifndef SDCARD_SORT_ALPHA
  4760. fileCnt - 1 -
  4761. #endif
  4762. #endif
  4763. i;*/
  4764. #ifdef SDCARD_SORT_ALPHA
  4765. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  4766. else card.getfilename_sorted(nr);
  4767. #else
  4768. card.getfilename(nr);
  4769. #endif
  4770. if (card.filenameIsDir)
  4771. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4772. else
  4773. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4774. } else {
  4775. MENU_ITEM_DUMMY();
  4776. }
  4777. }
  4778. END_MENU();
  4779. }
  4780. //char description [10] [31];
  4781. /*void get_description() {
  4782. uint16_t fileCnt = card.getnrfilenames();
  4783. for (uint16_t i = 0; i < fileCnt; i++)
  4784. {
  4785. card.getfilename(fileCnt - 1 - i);
  4786. getFileDescription(card.filename, description[i]);
  4787. }
  4788. }*/
  4789. /*void lcd_farm_sdcard_menu()
  4790. {
  4791. static int i = 0;
  4792. if (i == 0) {
  4793. get_description();
  4794. i++;
  4795. }
  4796. //int j;
  4797. //char description[31];
  4798. int tempScrool = 0;
  4799. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4800. //delay(100);
  4801. return; // nothing to do (so don't thrash the SD card)
  4802. uint16_t fileCnt = card.getnrfilenames();
  4803. START_MENU();
  4804. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4805. card.getWorkDirName();
  4806. if (card.filename[0] == '/')
  4807. {
  4808. #if SDCARDDETECT == -1
  4809. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4810. #endif
  4811. }
  4812. else {
  4813. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4814. }
  4815. for (uint16_t i = 0; i < fileCnt; i++)
  4816. {
  4817. if (_menuItemNr == _lineNr)
  4818. {
  4819. #ifndef SDCARD_RATHERRECENTFIRST
  4820. card.getfilename(i);
  4821. #else
  4822. card.getfilename(fileCnt - 1 - i);
  4823. #endif
  4824. if (card.filenameIsDir)
  4825. {
  4826. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4827. }
  4828. else {
  4829. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  4830. }
  4831. }
  4832. else {
  4833. MENU_ITEM_DUMMY();
  4834. }
  4835. }
  4836. END_MENU();
  4837. }*/
  4838. #define menu_edit_type(_type, _name, _strFunc, scale) \
  4839. void menu_edit_ ## _name () \
  4840. { \
  4841. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  4842. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  4843. if (lcdDrawUpdate) \
  4844. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  4845. if (LCD_CLICKED) \
  4846. { \
  4847. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  4848. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  4849. } \
  4850. } \
  4851. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  4852. { \
  4853. asm("cli"); \
  4854. menuData.editMenuParentState.prevMenu = currentMenu; \
  4855. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4856. asm("sei"); \
  4857. \
  4858. lcdDrawUpdate = 2; \
  4859. menuData.editMenuParentState.editLabel = pstr; \
  4860. menuData.editMenuParentState.editValue = ptr; \
  4861. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4862. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4863. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4864. \
  4865. }\
  4866. /*
  4867. void menu_edit_callback_ ## _name () { \
  4868. menu_edit_ ## _name (); \
  4869. if (LCD_CLICKED) (*callbackFunc)(); \
  4870. } \
  4871. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  4872. { \
  4873. menuData.editMenuParentState.prevMenu = currentMenu; \
  4874. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4875. \
  4876. lcdDrawUpdate = 2; \
  4877. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4878. \
  4879. menuData.editMenuParentState.editLabel = pstr; \
  4880. menuData.editMenuParentState.editValue = ptr; \
  4881. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4882. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4883. callbackFunc = callback;\
  4884. }
  4885. */
  4886. menu_edit_type(int, int3, itostr3, 1)
  4887. menu_edit_type(float, float3, ftostr3, 1)
  4888. menu_edit_type(float, float32, ftostr32, 100)
  4889. menu_edit_type(float, float43, ftostr43, 1000)
  4890. menu_edit_type(float, float5, ftostr5, 0.01)
  4891. menu_edit_type(float, float51, ftostr51, 10)
  4892. menu_edit_type(float, float52, ftostr52, 100)
  4893. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  4894. static void lcd_selftest_v()
  4895. {
  4896. (void)lcd_selftest();
  4897. }
  4898. static bool lcd_selftest()
  4899. {
  4900. int _progress = 0;
  4901. bool _result = false;
  4902. lcd_wait_for_cool_down();
  4903. lcd_implementation_clear();
  4904. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  4905. #ifdef TMC2130
  4906. FORCE_HIGH_POWER_START;
  4907. #endif // TMC2130
  4908. delay(2000);
  4909. KEEPALIVE_STATE(IN_HANDLER);
  4910. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  4911. #if (defined(FANCHECK) && defined(TACH_0))
  4912. _result = lcd_selftest_fan_dialog(0);
  4913. #else //defined(TACH_0)
  4914. _result = lcd_selftest_manual_fan_check(0, false);
  4915. #endif //defined(TACH_0)
  4916. if (_result)
  4917. {
  4918. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  4919. #if (defined(FANCHECK) && defined(TACH_1))
  4920. _result = lcd_selftest_fan_dialog(1);
  4921. #else //defined(TACH_1)
  4922. _result = lcd_selftest_manual_fan_check(1, false);
  4923. #endif //defined(TACH_1)
  4924. }
  4925. if (_result)
  4926. {
  4927. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  4928. #ifndef TMC2130
  4929. _result = lcd_selfcheck_endstops();
  4930. #else
  4931. _result = true;
  4932. #endif
  4933. }
  4934. if (_result)
  4935. {
  4936. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  4937. _result = lcd_selfcheck_check_heater(false);
  4938. }
  4939. if (_result)
  4940. {
  4941. //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
  4942. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  4943. #ifdef TMC2130
  4944. _result = lcd_selfcheck_axis_sg(X_AXIS);
  4945. #else
  4946. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  4947. #endif //TMC2130
  4948. }
  4949. if (_result)
  4950. {
  4951. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  4952. #ifndef TMC2130
  4953. _result = lcd_selfcheck_pulleys(X_AXIS);
  4954. #endif
  4955. }
  4956. if (_result)
  4957. {
  4958. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  4959. #ifdef TMC2130
  4960. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  4961. #else
  4962. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  4963. #endif // TMC2130
  4964. }
  4965. if (_result)
  4966. {
  4967. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  4968. #ifndef TMC2130
  4969. _result = lcd_selfcheck_pulleys(Y_AXIS);
  4970. #endif // TMC2130
  4971. }
  4972. if (_result)
  4973. {
  4974. #ifdef TMC2130
  4975. tmc2130_home_exit();
  4976. enable_endstops(false);
  4977. #endif
  4978. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  4979. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  4980. //homeaxis(X_AXIS);
  4981. //homeaxis(Y_AXIS);
  4982. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  4983. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  4984. st_synchronize();
  4985. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  4986. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  4987. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  4988. enquecommand_P(PSTR("G28 W"));
  4989. enquecommand_P(PSTR("G1 Z15"));
  4990. }
  4991. }
  4992. if (_result)
  4993. {
  4994. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  4995. _result = lcd_selfcheck_check_heater(true);
  4996. }
  4997. if (_result)
  4998. {
  4999. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5000. #ifdef PAT9125
  5001. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5002. _result = lcd_selftest_fsensor();
  5003. #endif // PAT9125
  5004. }
  5005. if (_result)
  5006. {
  5007. #ifdef PAT9125
  5008. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5009. #endif // PAT9125
  5010. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5011. }
  5012. else
  5013. {
  5014. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5015. }
  5016. lcd_reset_alert_level();
  5017. enquecommand_P(PSTR("M84"));
  5018. lcd_implementation_clear();
  5019. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5020. if (_result)
  5021. {
  5022. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  5023. }
  5024. else
  5025. {
  5026. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5027. }
  5028. #ifdef TMC2130
  5029. FORCE_HIGH_POWER_END;
  5030. #endif // TMC2130
  5031. KEEPALIVE_STATE(NOT_BUSY);
  5032. return(_result);
  5033. }
  5034. #ifdef TMC2130
  5035. static void reset_crash_det(char axis) {
  5036. current_position[axis] += 10;
  5037. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5038. st_synchronize();
  5039. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5040. }
  5041. static bool lcd_selfcheck_axis_sg(char axis) {
  5042. // each axis length is measured twice
  5043. float axis_length, current_position_init, current_position_final;
  5044. float measured_axis_length[2];
  5045. float margin = 60;
  5046. float max_error_mm = 5;
  5047. switch (axis) {
  5048. case 0: axis_length = X_MAX_POS; break;
  5049. case 1: axis_length = Y_MAX_POS + 8; break;
  5050. default: axis_length = 210; break;
  5051. }
  5052. tmc2130_sg_stop_on_crash = false;
  5053. tmc2130_home_exit();
  5054. enable_endstops(true);
  5055. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5056. current_position[Z_AXIS] += 17;
  5057. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5058. tmc2130_home_enter(Z_AXIS_MASK);
  5059. st_synchronize();
  5060. tmc2130_home_exit();
  5061. }
  5062. // first axis length measurement begin
  5063. tmc2130_home_enter(X_AXIS_MASK << axis);
  5064. current_position[axis] -= (axis_length + 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. tmc2130_home_exit();
  5068. tmc2130_sg_meassure_start(axis);
  5069. current_position_init = st_get_position_mm(axis);
  5070. current_position[axis] += 2 * margin;
  5071. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5072. st_synchronize();
  5073. current_position[axis] += axis_length;
  5074. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5075. tmc2130_home_enter(X_AXIS_MASK << axis);
  5076. st_synchronize();
  5077. tmc2130_home_exit();
  5078. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5079. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5080. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5081. current_position_final = st_get_position_mm(axis);
  5082. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5083. // first measurement end and second measurement begin
  5084. current_position[axis] -= margin;
  5085. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5086. st_synchronize();
  5087. tmc2130_home_enter(X_AXIS_MASK << axis);
  5088. current_position[axis] -= (axis_length + margin);
  5089. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5090. st_synchronize();
  5091. tmc2130_home_exit();
  5092. current_position_init = st_get_position_mm(axis);
  5093. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5094. //end of second measurement, now check for possible errors:
  5095. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5096. SERIAL_ECHOPGM("Measured axis length:");
  5097. MYSERIAL.println(measured_axis_length[i]);
  5098. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5099. enable_endstops(false);
  5100. const char *_error_1;
  5101. const char *_error_2;
  5102. if (axis == X_AXIS) _error_1 = "X";
  5103. if (axis == Y_AXIS) _error_1 = "Y";
  5104. if (axis == Z_AXIS) _error_1 = "Z";
  5105. lcd_selftest_error(9, _error_1, _error_2);
  5106. current_position[axis] = 0;
  5107. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5108. reset_crash_det(axis);
  5109. return false;
  5110. }
  5111. }
  5112. SERIAL_ECHOPGM("Axis length difference:");
  5113. MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1]));
  5114. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5115. //loose pulleys
  5116. const char *_error_1;
  5117. const char *_error_2;
  5118. if (axis == X_AXIS) _error_1 = "X";
  5119. if (axis == Y_AXIS) _error_1 = "Y";
  5120. if (axis == Z_AXIS) _error_1 = "Z";
  5121. lcd_selftest_error(8, _error_1, _error_2);
  5122. current_position[axis] = 0;
  5123. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5124. reset_crash_det(axis);
  5125. return false;
  5126. }
  5127. current_position[axis] = 0;
  5128. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5129. reset_crash_det(axis);
  5130. return true;
  5131. }
  5132. #endif //TMC2130
  5133. //#ifndef TMC2130
  5134. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5135. {
  5136. bool _stepdone = false;
  5137. bool _stepresult = false;
  5138. int _progress = 0;
  5139. int _travel_done = 0;
  5140. int _err_endstop = 0;
  5141. int _lcd_refresh = 0;
  5142. _travel = _travel + (_travel / 10);
  5143. do {
  5144. current_position[_axis] = current_position[_axis] - 1;
  5145. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5146. st_synchronize();
  5147. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5148. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5149. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5150. {
  5151. if (_axis == 0)
  5152. {
  5153. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5154. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5155. }
  5156. if (_axis == 1)
  5157. {
  5158. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5159. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5160. }
  5161. if (_axis == 2)
  5162. {
  5163. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5164. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5165. /*disable_x();
  5166. disable_y();
  5167. disable_z();*/
  5168. }
  5169. _stepdone = true;
  5170. }
  5171. if (_lcd_refresh < 6)
  5172. {
  5173. _lcd_refresh++;
  5174. }
  5175. else
  5176. {
  5177. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  5178. _lcd_refresh = 0;
  5179. }
  5180. manage_heater();
  5181. manage_inactivity(true);
  5182. //delay(100);
  5183. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5184. } while (!_stepdone);
  5185. //current_position[_axis] = current_position[_axis] + 15;
  5186. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5187. if (!_stepresult)
  5188. {
  5189. const char *_error_1;
  5190. const char *_error_2;
  5191. if (_axis == X_AXIS) _error_1 = "X";
  5192. if (_axis == Y_AXIS) _error_1 = "Y";
  5193. if (_axis == Z_AXIS) _error_1 = "Z";
  5194. if (_err_endstop == 0) _error_2 = "X";
  5195. if (_err_endstop == 1) _error_2 = "Y";
  5196. if (_err_endstop == 2) _error_2 = "Z";
  5197. if (_travel_done >= _travel)
  5198. {
  5199. lcd_selftest_error(5, _error_1, _error_2);
  5200. }
  5201. else
  5202. {
  5203. lcd_selftest_error(4, _error_1, _error_2);
  5204. }
  5205. }
  5206. return _stepresult;
  5207. }
  5208. static bool lcd_selfcheck_pulleys(int axis)
  5209. {
  5210. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5211. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5212. float current_position_init;
  5213. float move;
  5214. bool endstop_triggered = false;
  5215. int i;
  5216. unsigned long timeout_counter;
  5217. refresh_cmd_timeout();
  5218. manage_inactivity(true);
  5219. if (axis == 0) move = 50; //X_AXIS
  5220. else move = 50; //Y_AXIS
  5221. current_position_init = current_position[axis];
  5222. current_position[axis] += 2;
  5223. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5224. for (i = 0; i < 5; i++) {
  5225. refresh_cmd_timeout();
  5226. current_position[axis] = current_position[axis] + move;
  5227. digipot_current(0, 850); //set motor current higher
  5228. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5229. st_synchronize();
  5230. if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  5231. else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  5232. current_position[axis] = current_position[axis] - move;
  5233. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5234. st_synchronize();
  5235. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5236. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5237. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5238. return(false);
  5239. }
  5240. }
  5241. timeout_counter = millis() + 2500;
  5242. endstop_triggered = false;
  5243. manage_inactivity(true);
  5244. while (!endstop_triggered) {
  5245. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5246. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5247. endstop_triggered = true;
  5248. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5249. current_position[axis] += 15;
  5250. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5251. st_synchronize();
  5252. return(true);
  5253. }
  5254. else {
  5255. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5256. return(false);
  5257. }
  5258. }
  5259. else {
  5260. current_position[axis] -= 1;
  5261. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5262. st_synchronize();
  5263. if (millis() > timeout_counter) {
  5264. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5265. return(false);
  5266. }
  5267. }
  5268. }
  5269. return(true);
  5270. }
  5271. static bool lcd_selfcheck_endstops()
  5272. {
  5273. bool _result = true;
  5274. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5275. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5276. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5277. {
  5278. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5279. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5280. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5281. }
  5282. 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);
  5283. delay(500);
  5284. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5285. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5286. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5287. {
  5288. _result = false;
  5289. char _error[4] = "";
  5290. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5291. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5292. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5293. lcd_selftest_error(3, _error, "");
  5294. }
  5295. manage_heater();
  5296. manage_inactivity(true);
  5297. return _result;
  5298. }
  5299. //#endif //not defined TMC2130
  5300. static bool lcd_selfcheck_check_heater(bool _isbed)
  5301. {
  5302. int _counter = 0;
  5303. int _progress = 0;
  5304. bool _stepresult = false;
  5305. bool _docycle = true;
  5306. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5307. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5308. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5309. target_temperature[0] = (_isbed) ? 0 : 200;
  5310. target_temperature_bed = (_isbed) ? 100 : 0;
  5311. manage_heater();
  5312. manage_inactivity(true);
  5313. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5314. do {
  5315. _counter++;
  5316. _docycle = (_counter < _cycles) ? true : false;
  5317. manage_heater();
  5318. manage_inactivity(true);
  5319. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5320. /*if (_isbed) {
  5321. MYSERIAL.print("Bed temp:");
  5322. MYSERIAL.println(degBed());
  5323. }
  5324. else {
  5325. MYSERIAL.print("Hotend temp:");
  5326. MYSERIAL.println(degHotend(0));
  5327. }*/
  5328. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5329. } while (_docycle);
  5330. target_temperature[0] = 0;
  5331. target_temperature_bed = 0;
  5332. manage_heater();
  5333. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5334. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5335. /*
  5336. MYSERIAL.println("");
  5337. MYSERIAL.print("Checked result:");
  5338. MYSERIAL.println(_checked_result);
  5339. MYSERIAL.print("Opposite result:");
  5340. MYSERIAL.println(_opposite_result);
  5341. */
  5342. if (_opposite_result < ((_isbed) ? 10 : 3))
  5343. {
  5344. if (_checked_result >= ((_isbed) ? 3 : 10))
  5345. {
  5346. _stepresult = true;
  5347. }
  5348. else
  5349. {
  5350. lcd_selftest_error(1, "", "");
  5351. }
  5352. }
  5353. else
  5354. {
  5355. lcd_selftest_error(2, "", "");
  5356. }
  5357. manage_heater();
  5358. manage_inactivity(true);
  5359. KEEPALIVE_STATE(IN_HANDLER);
  5360. return _stepresult;
  5361. }
  5362. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5363. {
  5364. lcd_implementation_quick_feedback();
  5365. target_temperature[0] = 0;
  5366. target_temperature_bed = 0;
  5367. manage_heater();
  5368. manage_inactivity();
  5369. lcd_implementation_clear();
  5370. lcd.setCursor(0, 0);
  5371. lcd_printPGM(MSG_SELFTEST_ERROR);
  5372. lcd.setCursor(0, 1);
  5373. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  5374. switch (_error_no)
  5375. {
  5376. case 1:
  5377. lcd.setCursor(0, 2);
  5378. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  5379. lcd.setCursor(0, 3);
  5380. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  5381. break;
  5382. case 2:
  5383. lcd.setCursor(0, 2);
  5384. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  5385. lcd.setCursor(0, 3);
  5386. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5387. break;
  5388. case 3:
  5389. lcd.setCursor(0, 2);
  5390. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  5391. lcd.setCursor(0, 3);
  5392. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5393. lcd.setCursor(17, 3);
  5394. lcd.print(_error_1);
  5395. break;
  5396. case 4:
  5397. lcd.setCursor(0, 2);
  5398. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5399. lcd.setCursor(18, 2);
  5400. lcd.print(_error_1);
  5401. lcd.setCursor(0, 3);
  5402. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  5403. lcd.setCursor(18, 3);
  5404. lcd.print(_error_2);
  5405. break;
  5406. case 5:
  5407. lcd.setCursor(0, 2);
  5408. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  5409. lcd.setCursor(0, 3);
  5410. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5411. lcd.setCursor(18, 3);
  5412. lcd.print(_error_1);
  5413. break;
  5414. case 6:
  5415. lcd.setCursor(0, 2);
  5416. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5417. lcd.setCursor(0, 3);
  5418. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5419. lcd.setCursor(18, 3);
  5420. lcd.print(_error_1);
  5421. break;
  5422. case 7:
  5423. lcd.setCursor(0, 2);
  5424. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5425. lcd.setCursor(0, 3);
  5426. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5427. lcd.setCursor(18, 3);
  5428. lcd.print(_error_1);
  5429. break;
  5430. case 8:
  5431. lcd.setCursor(0, 2);
  5432. lcd_printPGM(MSG_LOOSE_PULLEY);
  5433. lcd.setCursor(0, 3);
  5434. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5435. lcd.setCursor(18, 3);
  5436. lcd.print(_error_1);
  5437. break;
  5438. case 9:
  5439. lcd.setCursor(0, 2);
  5440. lcd_printPGM(MSG_SELFTEST_AXIS_LENGTH);
  5441. lcd.setCursor(0, 3);
  5442. lcd_printPGM(MSG_SELFTEST_AXIS);
  5443. lcd.setCursor(18, 3);
  5444. lcd.print(_error_1);
  5445. break;
  5446. case 10:
  5447. lcd.setCursor(0, 2);
  5448. lcd_printPGM(MSG_SELFTEST_FANS);
  5449. lcd.setCursor(0, 3);
  5450. lcd_printPGM(MSG_SELFTEST_SWAPPED);
  5451. lcd.setCursor(18, 3);
  5452. lcd.print(_error_1);
  5453. break;
  5454. case 11:
  5455. lcd.setCursor(0, 2);
  5456. lcd_printPGM(MSG_FILAMENT_SENSOR);
  5457. lcd.setCursor(0, 3);
  5458. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5459. break;
  5460. }
  5461. delay(1000);
  5462. lcd_implementation_quick_feedback();
  5463. do {
  5464. delay(100);
  5465. manage_heater();
  5466. manage_inactivity();
  5467. } while (!lcd_clicked());
  5468. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5469. lcd_return_to_status();
  5470. }
  5471. #ifdef PAT9125
  5472. static bool lcd_selftest_fsensor() {
  5473. fsensor_init();
  5474. if (fsensor_not_responding)
  5475. {
  5476. const char *_err;
  5477. lcd_selftest_error(11, _err, _err);
  5478. }
  5479. return(!fsensor_not_responding);
  5480. }
  5481. #endif //PAT9125
  5482. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5483. {
  5484. bool _result = check_opposite;
  5485. lcd_implementation_clear();
  5486. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  5487. switch (_fan)
  5488. {
  5489. case 0:
  5490. // extruder cooling fan
  5491. lcd.setCursor(0, 1);
  5492. if(check_opposite == true) lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5493. else lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5494. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5495. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5496. break;
  5497. case 1:
  5498. // object cooling fan
  5499. lcd.setCursor(0, 1);
  5500. if (check_opposite == true) lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5501. else lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5502. SET_OUTPUT(FAN_PIN);
  5503. analogWrite(FAN_PIN, 255);
  5504. break;
  5505. }
  5506. delay(500);
  5507. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5508. lcd.setCursor(0, 3); lcd.print(">");
  5509. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5510. int8_t enc_dif = 0;
  5511. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5512. do
  5513. {
  5514. switch (_fan)
  5515. {
  5516. case 0:
  5517. // extruder cooling fan
  5518. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5519. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5520. break;
  5521. case 1:
  5522. // object cooling fan
  5523. SET_OUTPUT(FAN_PIN);
  5524. analogWrite(FAN_PIN, 255);
  5525. break;
  5526. }
  5527. if (abs((enc_dif - encoderDiff)) > 2) {
  5528. if (enc_dif > encoderDiff) {
  5529. _result = !check_opposite;
  5530. lcd.setCursor(0, 2); lcd.print(">");
  5531. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5532. lcd.setCursor(0, 3); lcd.print(" ");
  5533. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5534. }
  5535. if (enc_dif < encoderDiff) {
  5536. _result = check_opposite;
  5537. lcd.setCursor(0, 2); lcd.print(" ");
  5538. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5539. lcd.setCursor(0, 3); lcd.print(">");
  5540. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5541. }
  5542. enc_dif = 0;
  5543. encoderDiff = 0;
  5544. }
  5545. manage_heater();
  5546. delay(100);
  5547. } while (!lcd_clicked());
  5548. KEEPALIVE_STATE(IN_HANDLER);
  5549. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5550. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5551. SET_OUTPUT(FAN_PIN);
  5552. analogWrite(FAN_PIN, 0);
  5553. fanSpeed = 0;
  5554. manage_heater();
  5555. return _result;
  5556. }
  5557. static bool lcd_selftest_fan_dialog(int _fan)
  5558. {
  5559. bool _result = true;
  5560. int _errno = 7;
  5561. switch (_fan) {
  5562. case 0:
  5563. fanSpeed = 0;
  5564. manage_heater(); //turn off fan
  5565. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5566. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5567. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5568. if (!fan_speed[0]) _result = false;
  5569. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5570. //MYSERIAL.println(fan_speed[0]);
  5571. //SERIAL_ECHOPGM("Print fan speed: ");
  5572. //MYSERIAL.print(fan_speed[1]);
  5573. break;
  5574. case 1:
  5575. //will it work with Thotend > 50 C ?
  5576. fanSpeed = 150; //print fan
  5577. for (uint8_t i = 0; i < 5; i++) {
  5578. delay_keep_alive(1000);
  5579. lcd.setCursor(18, 3);
  5580. lcd.print("-");
  5581. delay_keep_alive(1000);
  5582. lcd.setCursor(18, 3);
  5583. lcd.print("|");
  5584. }
  5585. fanSpeed = 0;
  5586. manage_heater(); //turn off fan
  5587. manage_inactivity(true); //to turn off print fan
  5588. if (!fan_speed[1]) {
  5589. _result = false; _errno = 6; //print fan not spinning
  5590. }
  5591. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5592. //check fans manually
  5593. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  5594. if (_result) {
  5595. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  5596. if (!_result) _errno = 6; //print fan not spinning
  5597. }
  5598. else {
  5599. _errno = 10; //swapped fans
  5600. }
  5601. }
  5602. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5603. //MYSERIAL.println(fan_speed[0]);
  5604. //SERIAL_ECHOPGM("Print fan speed: ");
  5605. //MYSERIAL.println(fan_speed[1]);
  5606. break;
  5607. }
  5608. if (!_result)
  5609. {
  5610. const char *_err;
  5611. lcd_selftest_error(_errno, _err, _err);
  5612. }
  5613. return _result;
  5614. }
  5615. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  5616. {
  5617. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  5618. int _step_block = 0;
  5619. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  5620. if (_clear) lcd_implementation_clear();
  5621. lcd.setCursor(0, 0);
  5622. if (_step == -1) lcd_printPGM(MSG_SELFTEST_FAN);
  5623. if (_step == 0) lcd_printPGM(MSG_SELFTEST_FAN);
  5624. if (_step == 1) lcd_printPGM(MSG_SELFTEST_FAN);
  5625. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  5626. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  5627. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  5628. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  5629. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  5630. if (_step == 7) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5631. if (_step == 8) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5632. if (_step == 9) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5633. if (_step == 10) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5634. if (_step == 11) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  5635. if (_step == 12) lcd_printPGM(MSG_SELFTEST_FAILED);
  5636. lcd.setCursor(0, 1);
  5637. lcd.print("--------------------");
  5638. if ((_step >= -1) && (_step <= 1))
  5639. {
  5640. //SERIAL_ECHOLNPGM("Fan test");
  5641. lcd_print_at_PGM(0, 2, MSG_SELFTEST_EXTRUDER_FAN_SPEED);
  5642. lcd.setCursor(18, 2);
  5643. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  5644. lcd_print_at_PGM(0, 3, MSG_SELFTEST_PRINT_FAN_SPEED);
  5645. lcd.setCursor(18, 3);
  5646. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  5647. }
  5648. else if (_step >= 9 && _step <= 10)
  5649. {
  5650. lcd_print_at_PGM(0, 2, MSG_SELFTEST_FILAMENT_SENSOR);
  5651. lcd.setCursor(18, 2);
  5652. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  5653. }
  5654. else if (_step < 9)
  5655. {
  5656. //SERIAL_ECHOLNPGM("Other tests");
  5657. _step_block = 3;
  5658. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  5659. _step_block = 4;
  5660. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  5661. _step_block = 5;
  5662. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  5663. _step_block = 6;
  5664. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  5665. _step_block = 7;
  5666. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  5667. }
  5668. if (_delay > 0) delay_keep_alive(_delay);
  5669. _progress++;
  5670. return (_progress > _progress_scale * 2) ? 0 : _progress;
  5671. }
  5672. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  5673. {
  5674. lcd.setCursor(_col, _row);
  5675. switch (_state)
  5676. {
  5677. case 1:
  5678. lcd.print(_name);
  5679. lcd.setCursor(_col + strlen(_name), _row);
  5680. lcd.print(":");
  5681. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5682. lcd.print(_indicator);
  5683. break;
  5684. case 2:
  5685. lcd.print(_name);
  5686. lcd.setCursor(_col + strlen(_name), _row);
  5687. lcd.print(":");
  5688. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5689. lcd.print("OK");
  5690. break;
  5691. default:
  5692. lcd.print(_name);
  5693. }
  5694. }
  5695. /** End of menus **/
  5696. static void lcd_quick_feedback()
  5697. {
  5698. lcdDrawUpdate = 2;
  5699. button_pressed = false;
  5700. lcd_implementation_quick_feedback();
  5701. }
  5702. /** Menu action functions **/
  5703. /**
  5704. * @brief Go up in menu structure
  5705. * @param data unused parameter
  5706. */
  5707. static void menu_action_back(menuFunc_t data)
  5708. {
  5709. MenuStack::Record record = menuStack.pop();
  5710. lcd_goto_menu(record.menu);
  5711. encoderPosition = record.position;
  5712. }
  5713. /**
  5714. * @brief Go deeper into menu structure
  5715. * @param data nested menu
  5716. */
  5717. static void menu_action_submenu(menuFunc_t data) {
  5718. menuStack.push(currentMenu, encoderPosition);
  5719. lcd_goto_menu(data);
  5720. }
  5721. static void menu_action_gcode(const char* pgcode) {
  5722. enquecommand_P(pgcode);
  5723. }
  5724. static void menu_action_setlang(unsigned char lang) {
  5725. lcd_set_lang(lang);
  5726. }
  5727. static void menu_action_function(menuFunc_t data) {
  5728. (*data)();
  5729. }
  5730. static bool check_file(const char* filename) {
  5731. bool result = false;
  5732. uint32_t filesize;
  5733. card.openFile((char*)filename, true);
  5734. filesize = card.getFileSize();
  5735. if (filesize > END_FILE_SECTION) {
  5736. card.setIndex(filesize - END_FILE_SECTION);
  5737. }
  5738. while (!card.eof() && !result) {
  5739. card.sdprinting = true;
  5740. get_command();
  5741. result = check_commands();
  5742. }
  5743. card.printingHasFinished();
  5744. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  5745. lcd_finishstatus();
  5746. return result;
  5747. }
  5748. static void menu_action_sdfile(const char* filename, char* longFilename)
  5749. {
  5750. loading_flag = false;
  5751. char cmd[30];
  5752. char* c;
  5753. bool result = true;
  5754. sprintf_P(cmd, PSTR("M23 %s"), filename);
  5755. for (c = &cmd[4]; *c; c++)
  5756. *c = tolower(*c);
  5757. for (int i = 0; i < 8; i++) {
  5758. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]);
  5759. }
  5760. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5761. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  5762. for (uint8_t i = 0; i < depth; i++) {
  5763. for (int j = 0; j < 8; j++) {
  5764. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  5765. }
  5766. }
  5767. if (!check_file(filename)) {
  5768. result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FILE_INCOMPLETE, false, false);
  5769. lcd_update_enable(true);
  5770. }
  5771. if (result) {
  5772. enquecommand(cmd);
  5773. enquecommand_P(PSTR("M24"));
  5774. }
  5775. lcd_return_to_status();
  5776. }
  5777. static void menu_action_sddirectory(const char* filename, char* longFilename)
  5778. {
  5779. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5780. strcpy(dir_names[depth], filename);
  5781. MYSERIAL.println(dir_names[depth]);
  5782. card.chdir(filename);
  5783. encoderPosition = 0;
  5784. }
  5785. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  5786. {
  5787. *ptr = !(*ptr);
  5788. }
  5789. /*
  5790. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  5791. {
  5792. menu_action_setting_edit_bool(pstr, ptr);
  5793. (*callback)();
  5794. }
  5795. */
  5796. #endif//ULTIPANEL
  5797. /** LCD API **/
  5798. void lcd_init()
  5799. {
  5800. lcd_implementation_init();
  5801. #ifdef NEWPANEL
  5802. SET_INPUT(BTN_EN1);
  5803. SET_INPUT(BTN_EN2);
  5804. WRITE(BTN_EN1, HIGH);
  5805. WRITE(BTN_EN2, HIGH);
  5806. #if BTN_ENC > 0
  5807. SET_INPUT(BTN_ENC);
  5808. WRITE(BTN_ENC, HIGH);
  5809. #endif
  5810. #ifdef REPRAPWORLD_KEYPAD
  5811. pinMode(SHIFT_CLK, OUTPUT);
  5812. pinMode(SHIFT_LD, OUTPUT);
  5813. pinMode(SHIFT_OUT, INPUT);
  5814. WRITE(SHIFT_OUT, HIGH);
  5815. WRITE(SHIFT_LD, HIGH);
  5816. #endif
  5817. #else // Not NEWPANEL
  5818. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  5819. pinMode (SR_DATA_PIN, OUTPUT);
  5820. pinMode (SR_CLK_PIN, OUTPUT);
  5821. #elif defined(SHIFT_CLK)
  5822. pinMode(SHIFT_CLK, OUTPUT);
  5823. pinMode(SHIFT_LD, OUTPUT);
  5824. pinMode(SHIFT_EN, OUTPUT);
  5825. pinMode(SHIFT_OUT, INPUT);
  5826. WRITE(SHIFT_OUT, HIGH);
  5827. WRITE(SHIFT_LD, HIGH);
  5828. WRITE(SHIFT_EN, LOW);
  5829. #else
  5830. #ifdef ULTIPANEL
  5831. #error ULTIPANEL requires an encoder
  5832. #endif
  5833. #endif // SR_LCD_2W_NL
  5834. #endif//!NEWPANEL
  5835. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  5836. pinMode(SDCARDDETECT, INPUT);
  5837. WRITE(SDCARDDETECT, HIGH);
  5838. lcd_oldcardstatus = IS_SD_INSERTED;
  5839. #endif//(SDCARDDETECT > 0)
  5840. #ifdef LCD_HAS_SLOW_BUTTONS
  5841. slow_buttons = 0;
  5842. #endif
  5843. lcd_buttons_update();
  5844. #ifdef ULTIPANEL
  5845. encoderDiff = 0;
  5846. #endif
  5847. }
  5848. //#include <avr/pgmspace.h>
  5849. static volatile bool lcd_update_enabled = true;
  5850. unsigned long lcd_timeoutToStatus = 0;
  5851. void lcd_update_enable(bool enabled)
  5852. {
  5853. if (lcd_update_enabled != enabled) {
  5854. lcd_update_enabled = enabled;
  5855. if (enabled) {
  5856. // Reset encoder position. This is equivalent to re-entering a menu.
  5857. encoderPosition = 0;
  5858. encoderDiff = 0;
  5859. // Enabling the normal LCD update procedure.
  5860. // Reset the timeout interval.
  5861. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5862. // Force the keypad update now.
  5863. lcd_next_update_millis = millis() - 1;
  5864. // Full update.
  5865. lcd_implementation_clear();
  5866. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  5867. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  5868. #else
  5869. if (currentMenu == lcd_status_screen)
  5870. lcd_set_custom_characters_degree();
  5871. else
  5872. lcd_set_custom_characters_arrows();
  5873. #endif
  5874. lcd_update(2);
  5875. } else {
  5876. // Clear the LCD always, or let it to the caller?
  5877. }
  5878. }
  5879. }
  5880. void lcd_update(uint8_t lcdDrawUpdateOverride)
  5881. {
  5882. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  5883. lcdDrawUpdate = lcdDrawUpdateOverride;
  5884. if (!lcd_update_enabled)
  5885. return;
  5886. #ifdef LCD_HAS_SLOW_BUTTONS
  5887. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  5888. #endif
  5889. lcd_buttons_update();
  5890. #if (SDCARDDETECT > 0)
  5891. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  5892. {
  5893. lcdDrawUpdate = 2;
  5894. lcd_oldcardstatus = IS_SD_INSERTED;
  5895. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  5896. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  5897. currentMenu == lcd_status_screen
  5898. #endif
  5899. );
  5900. if (lcd_oldcardstatus)
  5901. {
  5902. card.initsd();
  5903. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  5904. //get_description();
  5905. }
  5906. else
  5907. {
  5908. card.release();
  5909. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  5910. }
  5911. }
  5912. #endif//CARDINSERTED
  5913. if (lcd_next_update_millis < millis())
  5914. {
  5915. #ifdef DEBUG_BLINK_ACTIVE
  5916. static bool active_led = false;
  5917. active_led = !active_led;
  5918. pinMode(LED_PIN, OUTPUT);
  5919. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  5920. #endif //DEBUG_BLINK_ACTIVE
  5921. #ifdef ULTIPANEL
  5922. #ifdef REPRAPWORLD_KEYPAD
  5923. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  5924. reprapworld_keypad_move_z_up();
  5925. }
  5926. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  5927. reprapworld_keypad_move_z_down();
  5928. }
  5929. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  5930. reprapworld_keypad_move_x_left();
  5931. }
  5932. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  5933. reprapworld_keypad_move_x_right();
  5934. }
  5935. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  5936. reprapworld_keypad_move_y_down();
  5937. }
  5938. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  5939. reprapworld_keypad_move_y_up();
  5940. }
  5941. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  5942. reprapworld_keypad_move_home();
  5943. }
  5944. #endif
  5945. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  5946. {
  5947. if (lcdDrawUpdate == 0)
  5948. lcdDrawUpdate = 1;
  5949. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  5950. encoderDiff = 0;
  5951. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5952. }
  5953. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5954. #endif//ULTIPANEL
  5955. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  5956. blink++; // Variable for fan animation and alive dot
  5957. u8g.firstPage();
  5958. do
  5959. {
  5960. u8g.setFont(u8g_font_6x10_marlin);
  5961. u8g.setPrintPos(125, 0);
  5962. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  5963. u8g.drawPixel(127, 63); // draw alive dot
  5964. u8g.setColorIndex(1); // black on white
  5965. (*currentMenu)();
  5966. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  5967. } while (u8g.nextPage());
  5968. #else
  5969. (*currentMenu)();
  5970. #endif
  5971. #ifdef LCD_HAS_STATUS_INDICATORS
  5972. lcd_implementation_update_indicators();
  5973. #endif
  5974. #ifdef ULTIPANEL
  5975. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  5976. {
  5977. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  5978. // to give it a chance to save its state.
  5979. // This is useful for example, when the babystep value has to be written into EEPROM.
  5980. if (currentMenu != NULL) {
  5981. menuExiting = true;
  5982. (*currentMenu)();
  5983. menuExiting = false;
  5984. }
  5985. lcd_implementation_clear();
  5986. lcd_return_to_status();
  5987. lcdDrawUpdate = 2;
  5988. }
  5989. #endif//ULTIPANEL
  5990. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  5991. if (lcdDrawUpdate) lcdDrawUpdate--;
  5992. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5993. }
  5994. if (!SdFatUtil::test_stack_integrity()) stack_error();
  5995. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5996. if (stepper_timer_overflow_state) stepper_timer_overflow();
  5997. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5998. lcd_ping(); //check that we have received ping command if we are in farm mode
  5999. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6000. }
  6001. void lcd_printer_connected() {
  6002. printer_connected = true;
  6003. }
  6004. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6005. if (farm_mode) {
  6006. bool empty = is_buffer_empty();
  6007. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6008. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6009. //therefore longer period is used
  6010. printer_connected = false;
  6011. //lcd_ping_allert(); //acustic signals
  6012. }
  6013. else {
  6014. lcd_printer_connected();
  6015. }
  6016. }
  6017. }
  6018. void lcd_ignore_click(bool b)
  6019. {
  6020. ignore_click = b;
  6021. wait_for_unclick = false;
  6022. }
  6023. void lcd_finishstatus() {
  6024. int len = strlen(lcd_status_message);
  6025. if (len > 0) {
  6026. while (len < LCD_WIDTH) {
  6027. lcd_status_message[len++] = ' ';
  6028. }
  6029. }
  6030. lcd_status_message[LCD_WIDTH] = '\0';
  6031. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6032. #if PROGRESS_MSG_EXPIRE > 0
  6033. messageTick =
  6034. #endif
  6035. progressBarTick = millis();
  6036. #endif
  6037. lcdDrawUpdate = 2;
  6038. #ifdef FILAMENT_LCD_DISPLAY
  6039. message_millis = millis(); //get status message to show up for a while
  6040. #endif
  6041. }
  6042. void lcd_setstatus(const char* message)
  6043. {
  6044. if (lcd_status_message_level > 0)
  6045. return;
  6046. strncpy(lcd_status_message, message, LCD_WIDTH);
  6047. lcd_finishstatus();
  6048. }
  6049. void lcd_setstatuspgm(const char* message)
  6050. {
  6051. if (lcd_status_message_level > 0)
  6052. return;
  6053. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6054. lcd_status_message[LCD_WIDTH] = 0;
  6055. lcd_finishstatus();
  6056. }
  6057. void lcd_setalertstatuspgm(const char* message)
  6058. {
  6059. lcd_setstatuspgm(message);
  6060. lcd_status_message_level = 1;
  6061. #ifdef ULTIPANEL
  6062. lcd_return_to_status();
  6063. #endif//ULTIPANEL
  6064. }
  6065. void lcd_reset_alert_level()
  6066. {
  6067. lcd_status_message_level = 0;
  6068. }
  6069. uint8_t get_message_level()
  6070. {
  6071. return lcd_status_message_level;
  6072. }
  6073. #ifdef DOGLCD
  6074. void lcd_setcontrast(uint8_t value)
  6075. {
  6076. lcd_contrast = value & 63;
  6077. u8g.setContrast(lcd_contrast);
  6078. }
  6079. #endif
  6080. #ifdef ULTIPANEL
  6081. /* Warning: This function is called from interrupt context */
  6082. void lcd_buttons_update()
  6083. {
  6084. static bool _lock = false;
  6085. if (_lock) return;
  6086. _lock = true;
  6087. #ifdef NEWPANEL
  6088. uint8_t newbutton = 0;
  6089. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6090. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6091. #if BTN_ENC > 0
  6092. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6093. if (READ(BTN_ENC) == 0) { //button is pressed
  6094. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6095. if (millis() > button_blanking_time) {
  6096. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6097. if (button_pressed == false && long_press_active == false) {
  6098. if (currentMenu != lcd_move_z) {
  6099. savedMenu = currentMenu;
  6100. savedEncoderPosition = encoderPosition;
  6101. }
  6102. long_press_timer = millis();
  6103. button_pressed = true;
  6104. }
  6105. else {
  6106. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  6107. long_press_active = true;
  6108. move_menu_scale = 1.0;
  6109. lcd_goto_menu(lcd_move_z);
  6110. }
  6111. }
  6112. }
  6113. }
  6114. else { //button not pressed
  6115. if (button_pressed) { //button was released
  6116. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6117. if (long_press_active == false) { //button released before long press gets activated
  6118. if (currentMenu == lcd_move_z) {
  6119. //return to previously active menu and previous encoder position
  6120. lcd_goto_menu(savedMenu, savedEncoderPosition);
  6121. }
  6122. else {
  6123. newbutton |= EN_C;
  6124. }
  6125. }
  6126. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  6127. //button_pressed is set back to false via lcd_quick_feedback function
  6128. }
  6129. else {
  6130. long_press_active = false;
  6131. }
  6132. }
  6133. }
  6134. else { //we are in modal mode
  6135. if (READ(BTN_ENC) == 0)
  6136. newbutton |= EN_C;
  6137. }
  6138. #endif
  6139. buttons = newbutton;
  6140. #ifdef LCD_HAS_SLOW_BUTTONS
  6141. buttons |= slow_buttons;
  6142. #endif
  6143. #ifdef REPRAPWORLD_KEYPAD
  6144. // for the reprapworld_keypad
  6145. uint8_t newbutton_reprapworld_keypad = 0;
  6146. WRITE(SHIFT_LD, LOW);
  6147. WRITE(SHIFT_LD, HIGH);
  6148. for (int8_t i = 0; i < 8; i++) {
  6149. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6150. if (READ(SHIFT_OUT))
  6151. newbutton_reprapworld_keypad |= (1 << 7);
  6152. WRITE(SHIFT_CLK, HIGH);
  6153. WRITE(SHIFT_CLK, LOW);
  6154. }
  6155. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6156. #endif
  6157. #else //read it from the shift register
  6158. uint8_t newbutton = 0;
  6159. WRITE(SHIFT_LD, LOW);
  6160. WRITE(SHIFT_LD, HIGH);
  6161. unsigned char tmp_buttons = 0;
  6162. for (int8_t i = 0; i < 8; i++)
  6163. {
  6164. newbutton = newbutton >> 1;
  6165. if (READ(SHIFT_OUT))
  6166. newbutton |= (1 << 7);
  6167. WRITE(SHIFT_CLK, HIGH);
  6168. WRITE(SHIFT_CLK, LOW);
  6169. }
  6170. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6171. #endif//!NEWPANEL
  6172. //manage encoder rotation
  6173. uint8_t enc = 0;
  6174. if (buttons & EN_A) enc |= B01;
  6175. if (buttons & EN_B) enc |= B10;
  6176. if (enc != lastEncoderBits)
  6177. {
  6178. switch (enc)
  6179. {
  6180. case encrot0:
  6181. if (lastEncoderBits == encrot3)
  6182. encoderDiff++;
  6183. else if (lastEncoderBits == encrot1)
  6184. encoderDiff--;
  6185. break;
  6186. case encrot1:
  6187. if (lastEncoderBits == encrot0)
  6188. encoderDiff++;
  6189. else if (lastEncoderBits == encrot2)
  6190. encoderDiff--;
  6191. break;
  6192. case encrot2:
  6193. if (lastEncoderBits == encrot1)
  6194. encoderDiff++;
  6195. else if (lastEncoderBits == encrot3)
  6196. encoderDiff--;
  6197. break;
  6198. case encrot3:
  6199. if (lastEncoderBits == encrot2)
  6200. encoderDiff++;
  6201. else if (lastEncoderBits == encrot0)
  6202. encoderDiff--;
  6203. break;
  6204. }
  6205. }
  6206. lastEncoderBits = enc;
  6207. _lock = false;
  6208. }
  6209. bool lcd_detected(void)
  6210. {
  6211. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6212. return lcd.LcdDetected() == 1;
  6213. #else
  6214. return true;
  6215. #endif
  6216. }
  6217. void lcd_buzz(long duration, uint16_t freq)
  6218. {
  6219. #ifdef LCD_USE_I2C_BUZZER
  6220. lcd.buzz(duration, freq);
  6221. #endif
  6222. }
  6223. bool lcd_clicked()
  6224. {
  6225. bool clicked = LCD_CLICKED;
  6226. if(clicked) button_pressed = false;
  6227. return clicked;
  6228. }
  6229. #endif//ULTIPANEL
  6230. /********************************/
  6231. /** Float conversion utilities **/
  6232. /********************************/
  6233. // convert float to string with +123.4 format
  6234. char conv[8];
  6235. char *ftostr3(const float &x)
  6236. {
  6237. return itostr3((int)x);
  6238. }
  6239. char *itostr2(const uint8_t &x)
  6240. {
  6241. //sprintf(conv,"%5.1f",x);
  6242. int xx = x;
  6243. conv[0] = (xx / 10) % 10 + '0';
  6244. conv[1] = (xx) % 10 + '0';
  6245. conv[2] = 0;
  6246. return conv;
  6247. }
  6248. // Convert float to string with 123.4 format, dropping sign
  6249. char *ftostr31(const float &x)
  6250. {
  6251. int xx = x * 10;
  6252. conv[0] = (xx >= 0) ? '+' : '-';
  6253. xx = abs(xx);
  6254. conv[1] = (xx / 1000) % 10 + '0';
  6255. conv[2] = (xx / 100) % 10 + '0';
  6256. conv[3] = (xx / 10) % 10 + '0';
  6257. conv[4] = '.';
  6258. conv[5] = (xx) % 10 + '0';
  6259. conv[6] = 0;
  6260. return conv;
  6261. }
  6262. // Convert float to string with 123.4 format
  6263. char *ftostr31ns(const float &x)
  6264. {
  6265. int xx = x * 10;
  6266. //conv[0]=(xx>=0)?'+':'-';
  6267. xx = abs(xx);
  6268. conv[0] = (xx / 1000) % 10 + '0';
  6269. conv[1] = (xx / 100) % 10 + '0';
  6270. conv[2] = (xx / 10) % 10 + '0';
  6271. conv[3] = '.';
  6272. conv[4] = (xx) % 10 + '0';
  6273. conv[5] = 0;
  6274. return conv;
  6275. }
  6276. char *ftostr32(const float &x)
  6277. {
  6278. long xx = x * 100;
  6279. if (xx >= 0)
  6280. conv[0] = (xx / 10000) % 10 + '0';
  6281. else
  6282. conv[0] = '-';
  6283. xx = abs(xx);
  6284. conv[1] = (xx / 1000) % 10 + '0';
  6285. conv[2] = (xx / 100) % 10 + '0';
  6286. conv[3] = '.';
  6287. conv[4] = (xx / 10) % 10 + '0';
  6288. conv[5] = (xx) % 10 + '0';
  6289. conv[6] = 0;
  6290. return conv;
  6291. }
  6292. //// Convert float to rj string with 123.45 format
  6293. char *ftostr32ns(const float &x) {
  6294. long xx = abs(x);
  6295. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6296. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6297. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6298. conv[3] = '.';
  6299. conv[4] = (xx / 10) % 10 + '0';
  6300. conv[5] = xx % 10 + '0';
  6301. return conv;
  6302. }
  6303. // Convert float to string with 1.234 format
  6304. char *ftostr43(const float &x)
  6305. {
  6306. long xx = x * 1000;
  6307. if (xx >= 0)
  6308. conv[0] = (xx / 1000) % 10 + '0';
  6309. else
  6310. conv[0] = '-';
  6311. xx = abs(xx);
  6312. conv[1] = '.';
  6313. conv[2] = (xx / 100) % 10 + '0';
  6314. conv[3] = (xx / 10) % 10 + '0';
  6315. conv[4] = (xx) % 10 + '0';
  6316. conv[5] = 0;
  6317. return conv;
  6318. }
  6319. //Float to string with 1.23 format
  6320. char *ftostr12ns(const float &x)
  6321. {
  6322. long xx = x * 100;
  6323. xx = abs(xx);
  6324. conv[0] = (xx / 100) % 10 + '0';
  6325. conv[1] = '.';
  6326. conv[2] = (xx / 10) % 10 + '0';
  6327. conv[3] = (xx) % 10 + '0';
  6328. conv[4] = 0;
  6329. return conv;
  6330. }
  6331. //Float to string with 1.234 format
  6332. char *ftostr13ns(const float &x)
  6333. {
  6334. long xx = x * 1000;
  6335. if (xx >= 0)
  6336. conv[0] = ' ';
  6337. else
  6338. conv[0] = '-';
  6339. xx = abs(xx);
  6340. conv[1] = (xx / 1000) % 10 + '0';
  6341. conv[2] = '.';
  6342. conv[3] = (xx / 100) % 10 + '0';
  6343. conv[4] = (xx / 10) % 10 + '0';
  6344. conv[5] = (xx) % 10 + '0';
  6345. conv[6] = 0;
  6346. return conv;
  6347. }
  6348. // convert float to space-padded string with -_23.4_ format
  6349. char *ftostr32sp(const float &x) {
  6350. long xx = abs(x * 100);
  6351. uint8_t dig;
  6352. if (x < 0) { // negative val = -_0
  6353. conv[0] = '-';
  6354. dig = (xx / 1000) % 10;
  6355. conv[1] = dig ? '0' + dig : ' ';
  6356. }
  6357. else { // positive val = __0
  6358. dig = (xx / 10000) % 10;
  6359. if (dig) {
  6360. conv[0] = '0' + dig;
  6361. conv[1] = '0' + (xx / 1000) % 10;
  6362. }
  6363. else {
  6364. conv[0] = ' ';
  6365. dig = (xx / 1000) % 10;
  6366. conv[1] = dig ? '0' + dig : ' ';
  6367. }
  6368. }
  6369. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6370. dig = xx % 10;
  6371. if (dig) { // 2 decimal places
  6372. conv[5] = '0' + dig;
  6373. conv[4] = '0' + (xx / 10) % 10;
  6374. conv[3] = '.';
  6375. }
  6376. else { // 1 or 0 decimal place
  6377. dig = (xx / 10) % 10;
  6378. if (dig) {
  6379. conv[4] = '0' + dig;
  6380. conv[3] = '.';
  6381. }
  6382. else {
  6383. conv[3] = conv[4] = ' ';
  6384. }
  6385. conv[5] = ' ';
  6386. }
  6387. conv[6] = '\0';
  6388. return conv;
  6389. }
  6390. char *itostr31(const int &xx)
  6391. {
  6392. conv[0] = (xx >= 0) ? '+' : '-';
  6393. conv[1] = (xx / 1000) % 10 + '0';
  6394. conv[2] = (xx / 100) % 10 + '0';
  6395. conv[3] = (xx / 10) % 10 + '0';
  6396. conv[4] = '.';
  6397. conv[5] = (xx) % 10 + '0';
  6398. conv[6] = 0;
  6399. return conv;
  6400. }
  6401. // Convert int to rj string with 123 or -12 format
  6402. char *itostr3(const int &x)
  6403. {
  6404. int xx = x;
  6405. if (xx < 0) {
  6406. conv[0] = '-';
  6407. xx = -xx;
  6408. } else if (xx >= 100)
  6409. conv[0] = (xx / 100) % 10 + '0';
  6410. else
  6411. conv[0] = ' ';
  6412. if (xx >= 10)
  6413. conv[1] = (xx / 10) % 10 + '0';
  6414. else
  6415. conv[1] = ' ';
  6416. conv[2] = (xx) % 10 + '0';
  6417. conv[3] = 0;
  6418. return conv;
  6419. }
  6420. // Convert int to lj string with 123 format
  6421. char *itostr3left(const int &xx)
  6422. {
  6423. if (xx >= 100)
  6424. {
  6425. conv[0] = (xx / 100) % 10 + '0';
  6426. conv[1] = (xx / 10) % 10 + '0';
  6427. conv[2] = (xx) % 10 + '0';
  6428. conv[3] = 0;
  6429. }
  6430. else if (xx >= 10)
  6431. {
  6432. conv[0] = (xx / 10) % 10 + '0';
  6433. conv[1] = (xx) % 10 + '0';
  6434. conv[2] = 0;
  6435. }
  6436. else
  6437. {
  6438. conv[0] = (xx) % 10 + '0';
  6439. conv[1] = 0;
  6440. }
  6441. return conv;
  6442. }
  6443. // Convert int to rj string with 1234 format
  6444. char *itostr4(const int &xx) {
  6445. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6446. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6447. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6448. conv[3] = xx % 10 + '0';
  6449. conv[4] = 0;
  6450. return conv;
  6451. }
  6452. // Convert float to rj string with 12345 format
  6453. char *ftostr5(const float &x) {
  6454. long xx = abs(x);
  6455. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6456. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6457. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6458. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6459. conv[4] = xx % 10 + '0';
  6460. conv[5] = 0;
  6461. return conv;
  6462. }
  6463. // Convert float to string with +1234.5 format
  6464. char *ftostr51(const float &x)
  6465. {
  6466. long xx = x * 10;
  6467. conv[0] = (xx >= 0) ? '+' : '-';
  6468. xx = abs(xx);
  6469. conv[1] = (xx / 10000) % 10 + '0';
  6470. conv[2] = (xx / 1000) % 10 + '0';
  6471. conv[3] = (xx / 100) % 10 + '0';
  6472. conv[4] = (xx / 10) % 10 + '0';
  6473. conv[5] = '.';
  6474. conv[6] = (xx) % 10 + '0';
  6475. conv[7] = 0;
  6476. return conv;
  6477. }
  6478. // Convert float to string with +123.45 format
  6479. char *ftostr52(const float &x)
  6480. {
  6481. long xx = x * 100;
  6482. conv[0] = (xx >= 0) ? '+' : '-';
  6483. xx = abs(xx);
  6484. conv[1] = (xx / 10000) % 10 + '0';
  6485. conv[2] = (xx / 1000) % 10 + '0';
  6486. conv[3] = (xx / 100) % 10 + '0';
  6487. conv[4] = '.';
  6488. conv[5] = (xx / 10) % 10 + '0';
  6489. conv[6] = (xx) % 10 + '0';
  6490. conv[7] = 0;
  6491. return conv;
  6492. }
  6493. /*
  6494. // Callback for after editing PID i value
  6495. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  6496. void copy_and_scalePID_i()
  6497. {
  6498. #ifdef PIDTEMP
  6499. Ki = scalePID_i(raw_Ki);
  6500. updatePID();
  6501. #endif
  6502. }
  6503. // Callback for after editing PID d value
  6504. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  6505. void copy_and_scalePID_d()
  6506. {
  6507. #ifdef PIDTEMP
  6508. Kd = scalePID_d(raw_Kd);
  6509. updatePID();
  6510. #endif
  6511. }
  6512. */
  6513. #endif //ULTRA_LCD