ultralcd.cpp 212 KB

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