ultralcd.cpp 199 KB

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